Klasse TwitchChat

java.lang.Object
com.github.twitch4j.chat.TwitchChat
Alle implementierten Schnittstellen:
ITwitchChat, AutoCloseable

public class TwitchChat extends Object implements ITwitchChat
  • Felddetails

    • REQUIRED_THREAD_COUNT

      public static final int REQUIRED_THREAD_COUNT
      Siehe auch:
    • TWITCH_WEB_SOCKET_SERVER

      public static final String TWITCH_WEB_SOCKET_SERVER
      Twitch's official WebSocket Server
      Siehe auch:
    • FDGT_TEST_SOCKET_SERVER

      public static final String FDGT_TEST_SOCKET_SERVER
      ThirdParty WebSocket Server for Testing
      Siehe auch:
    • sendCredentialToThirdPartyHost

      protected final boolean sendCredentialToThirdPartyHost
      Whether the OAuth2Credential password should be sent when the baseUrl does not match the official twitch websocket server, thus bypassing a security check in the library.
    • currentChannels

      protected final Set<String> currentChannels
      Current Channels
    • channelIdToChannelName

      protected final Map<String,String> channelIdToChannelName
      Cache: ChannelId to ChannelName
    • channelNameToChannelId

      protected final Map<String,String> channelNameToChannelId
      Cache: ChannelName to ChannelId
    • ircMessageBucket

      protected final Bucket ircMessageBucket
      IRC Message Bucket
    • ircWhisperBucket

      protected final Bucket ircWhisperBucket
      IRC Whisper Bucket
    • ircJoinBucket

      protected final Bucket ircJoinBucket
      IRC Join Bucket
    • ircAuthBucket

      protected final Bucket ircAuthBucket
      IRC Auth Bucket
    • perChannelRateLimit

      protected final Bandwidth perChannelRateLimit
      IRC Per-Channel Message Limit
    • ircCommandQueue

      protected final BlockingQueue<String> ircCommandQueue
      IRC Command Queue
    • queueThread

      protected final ScheduledFuture<?> queueThread
      IRC Command Queue Thread
    • stopQueueThread

      protected volatile boolean stopQueueThread
      Command Queue Thread stop flag
    • botOwnerIds

      protected final Collection<String> botOwnerIds
      Bot Owner IDs
    • commandPrefixes

      protected final List<String> commandPrefixes
      IRC Command Handlers
    • taskExecutor

      protected final ScheduledExecutorService taskExecutor
      Thread Pool Executor
    • chatQueueTimeout

      protected final long chatQueueTimeout
      Time to wait for an item on the chat queue before continuing to next iteration If set too high your thread will be late check to shutdown
    • autoJoinOwnChannel

      protected final boolean autoJoinOwnChannel
      Whether one's own channel should automatically be joined
    • removeChannelOnJoinFailure

      protected final boolean removeChannelOnJoinFailure
      Whether join failures should result in removal from current channels
    • enableMembershipEvents

      protected final boolean enableMembershipEvents
      Whether JOIN/PART events should be enabled
    • maxJoinRetries

      protected final int maxJoinRetries
      The maximum number of attempts to make for joining each channel
    • chatJoinTimeout

      protected final long chatJoinTimeout
      Minimum milliseconds to wait after a join attempt
    • joinAttemptsByChannelName

      protected final io.github.xanthic.cache.api.Cache<String,Integer> joinAttemptsByChannelName
      Cache of recent number of join attempts for each channel
    • bucketByChannelName

      protected final io.github.xanthic.cache.api.Cache<String,Bucket> bucketByChannelName
      Cache of per-channel message buckets
    • identityProvider

      protected final TwitchIdentityProvider identityProvider
      Twitch Identity Provider
    • validateOnConnect

      protected final boolean validateOnConnect
      Whether OAuth token status should be checked on reconnect
  • Konstruktordetails

    • TwitchChat

      public TwitchChat(WebsocketConnection websocketConnection, EventManager eventManager, CredentialManager credentialManager, OAuth2Credential chatCredential, String baseUrl, boolean sendCredentialToThirdPartyHost, Collection<String> commandPrefixes, Integer chatQueueSize, Bucket ircMessageBucket, Bucket ircWhisperBucket, Bucket ircJoinBucket, Bucket ircAuthBucket, ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, Collection<String> botOwnerIds, boolean removeChannelOnJoinFailure, int maxJoinRetries, long chatJoinTimeout, int wsPingPeriod, IBackoffStrategy connectionBackoffStrategy, Bandwidth perChannelRateLimit, boolean validateOnConnect, int wsCloseDelay, BiPredicate<TwitchChat,String> outboundCommandFilter)
      Constructor
      Parameter:
      websocketConnection - WebsocketConnection
      eventManager - EventManager
      credentialManager - CredentialManager
      chatCredential - Chat Credential
      baseUrl - The websocket url for the chat client to connect to
      sendCredentialToThirdPartyHost - Whether the password should be sent when the baseUrl is not official
      commandPrefixes - Command Prefixes
      chatQueueSize - Chat Queue Size
      ircMessageBucket - Bucket for chat
      ircWhisperBucket - Bucket for whispers
      ircJoinBucket - Bucket for joins
      ircAuthBucket - Bucket for auths
      taskExecutor - ScheduledThreadPoolExecutor
      chatQueueTimeout - Timeout to wait for events in Chat Queue
      proxyConfig - Proxy Configuration
      autoJoinOwnChannel - Whether one's own channel should automatically be joined
      enableMembershipEvents - Whether JOIN/PART events should be enabled
      botOwnerIds - Bot Owner IDs
      removeChannelOnJoinFailure - Whether channels should be removed after a join failure
      maxJoinRetries - Maximum join retries per channel
      chatJoinTimeout - Minimum milliseconds to wait after a join attempt
      wsPingPeriod - WebSocket Ping Period
      connectionBackoffStrategy - WebSocket Connection Backoff Strategy
      perChannelRateLimit - Per channel message limit
      validateOnConnect - Whether token should be validated on connect
      wsCloseDelay - Websocket Close Delay
      outboundCommandFilter - Outbound Command Filter
  • Methodendetails

    • onConnected

      protected void onConnected()
    • onTextMessage

      protected void onTextMessage(String text)
    • onDisconnecting

      protected void onDisconnecting()
    • connect

      public void connect()
      Connecting to IRC-WS
    • disconnect

      public void disconnect()
      Disconnecting from IRC-WS
    • reconnect

      public void reconnect()
      Reconnecting to IRC-WS
    • sendCommand

      protected void sendCommand(String command, String... args)
      Send IRC Command
      Parameter:
      command - IRC Command
      args - command arguments
    • sendRaw

      public boolean sendRaw(String command)
      Send raw irc command

      Note: perChannelRateLimit does not apply when directly using this method

      Parameter:
      command - raw irc command
    • joinChannel

      public void joinChannel(String channelName)
      Joining the channel
      Angegeben von:
      joinChannel in Schnittstelle ITwitchChat
      Parameter:
      channelName - channel name
    • issueJoin

      protected void issueJoin(String channelName, int attempts)
    • leaveChannel

      public boolean leaveChannel(String channelName)
      leaving the channel
      Angegeben von:
      leaveChannel in Schnittstelle ITwitchChat
      Parameter:
      channelName - channel name
      Gibt zurück:
      whether the channel was previously joined
    • sendMessage

      public boolean sendMessage(String channel, String message, Map<String,Object> tags)
      Beschreibung aus Schnittstelle kopiert: ITwitchChat
      Sends a message to the channel while including the specified message tags.
      Angegeben von:
      sendMessage in Schnittstelle ITwitchChat
      Parameter:
      channel - the name of the channel to send the message to.
      message - the message to be sent.
      tags - the message tags.
      Gibt zurück:
      whether the message was added to the queue
    • sendPrivateMessage

      @Deprecated public void sendPrivateMessage(String targetUser, String message)
      Veraltet.
      Twitch will decommission this method on February 18, 2023; migrate to TwitchHelix#sendWhisper
      Sends a user a private message
      Parameter:
      targetUser - username
      message - message
    • close

      public void close()
      Close
      Angegeben von:
      close in Schnittstelle AutoCloseable
      Angegeben von:
      close in Schnittstelle ITwitchChat
    • isChannelJoined

      public boolean isChannelJoined(String channelName)
      Beschreibung aus Schnittstelle kopiert: ITwitchChat
      Check if Chat is currently in a channel
      Angegeben von:
      isChannelJoined in Schnittstelle ITwitchChat
      Parameter:
      channelName - channel to check (without # prefix)
      Gibt zurück:
      boolean
    • getCurrentChannels

      @Deprecated public List<String> getCurrentChannels()
      Veraltet.
      use getChannels() instead
      Returns a set of all currently joined channels (without # prefix)
      Gibt zurück:
      a set of channel names
    • getChannels

      public Set<String> getChannels()
      Beschreibung aus Schnittstelle kopiert: ITwitchChat
      Returns a set of all currently joined channels (without # prefix)
      Angegeben von:
      getChannels in Schnittstelle ITwitchChat
      Gibt zurück:
      a set of channel names
    • getChannelIdToChannelName

      public Map<String,String> getChannelIdToChannelName()
      Angegeben von:
      getChannelIdToChannelName in Schnittstelle ITwitchChat
      Gibt zurück:
      the cached map used for channel id to name mapping
    • getChannelNameToChannelId

      public Map<String,String> getChannelNameToChannelId()
      Angegeben von:
      getChannelNameToChannelId in Schnittstelle ITwitchChat
      Gibt zurück:
      the cached map used for channel name to id mapping
    • getLatency

      public long getLatency()
      Angegeben von:
      getLatency in Schnittstelle ITwitchChat
      Gibt zurück:
      the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
    • getState

      public WebsocketConnectionState getState()
      Gibt zurück:
      the connection state
    • getConnectionState

      @Deprecated public TMIConnectionState getConnectionState()
      Veraltet.
      use getState() instead
      Gibt zurück:
      the connection state
    • getEventManager

      public EventManager getEventManager()
      EventManager
      Angegeben von:
      getEventManager in Schnittstelle ITwitchChat
    • getCredentialManager

      public CredentialManager getCredentialManager()
      CredentialManager