Class TwitchChatBuilder

java.lang.Object
com.github.twitch4j.chat.TwitchChatBuilder

public class TwitchChatBuilder extends Object
Twitch Chat

Documentation: https://dev.twitch.tv/docs/irc

  • Field Details

    • botOwnerIds

      protected Collection<String> botOwnerIds
      User IDs of Bot Owners for applying CommandPermission.OWNER
    • commandPrefixes

      protected Set<String> commandPrefixes
      IRC Command Handlers
    • chatQueueSize

      protected Integer chatQueueSize
      Size of the ChatQueue
    • chatRateLimit

      protected io.github.bucket4j.Bandwidth chatRateLimit
      Custom RateLimit for ChatMessages
    • whisperRateLimit

      @Deprecated protected io.github.bucket4j.Bandwidth[] whisperRateLimit
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Custom RateLimit for Whispers
    • joinRateLimit

      protected io.github.bucket4j.Bandwidth joinRateLimit
      Custom RateLimit for JOIN/PART
    • authRateLimit

      protected io.github.bucket4j.Bandwidth authRateLimit
      Custom RateLimit for AUTH
    • perChannelRateLimit

      protected io.github.bucket4j.Bandwidth perChannelRateLimit
      Custom RateLimit for Messages per Channel

      For example, this can restrict messages per channel at 100/30 (for a verified bot that has a global 7500/30 message limit).

    • ircMessageBucket

      protected io.github.bucket4j.Bucket ircMessageBucket
      Shared bucket for messages
    • ircWhisperBucket

      @Deprecated protected io.github.bucket4j.Bucket ircWhisperBucket
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Shared bucket for whispers
    • ircJoinBucket

      protected io.github.bucket4j.Bucket ircJoinBucket
      Shared bucket for joins
    • ircAuthBucket

      protected io.github.bucket4j.Bucket ircAuthBucket
      Shared bucket for auths
  • Method Details

    • builder

      public static TwitchChatBuilder builder()
      Initialize the builder
      Returns:
      Twitch Chat Builder
    • build

      public TwitchChat build()
      Twitch API Client (Helix)
      Returns:
      TwitchHelix
    • withCommandTrigger

      public TwitchChatBuilder withCommandTrigger(String commandTrigger)
      With a CommandTrigger
      Parameters:
      commandTrigger - Command Trigger (Prefix)
      Returns:
      TwitchChatBuilder
    • withCommandTriggers

      public TwitchChatBuilder withCommandTriggers(Collection<String> commandTrigger)
      With multiple CommandTriggers
      Parameters:
      commandTrigger - Command Trigger (Prefix)
      Returns:
      TwitchChatBuilder
    • withBotOwnerId

      public TwitchChatBuilder withBotOwnerId(String userId)
      With a Bot Owner's User ID
      Parameters:
      userId - the user id
      Returns:
      TwitchChatBuilder
    • withBotOwnerIds

      public TwitchChatBuilder withBotOwnerIds(Collection<String> botOwnerIds)
      With multiple Bot Owner User IDs
      Parameters:
      botOwnerIds - the user ids
      Returns:
      TwitchChatBuilder
    • getWebsocketConnection

      public WebsocketConnection getWebsocketConnection()
      WebsocketConnection

      can be used to inject a mocked connection into the TwitchChat instance

    • getClientId

      public String getClientId()
      Client Id
    • getClientSecret

      public String getClientSecret()
      Client Secret
    • getRequestQueueSize

      public Integer getRequestQueueSize()
      HTTP Request Queue Size
    • getEventManager

      public com.github.philippheuer.events4j.core.EventManager getEventManager()
      Event Manager
    • getDefaultEventHandler

      public Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> getDefaultEventHandler()
      EventManager
    • getCredentialManager

      public com.github.philippheuer.credentialmanager.CredentialManager getCredentialManager()
      Credential Manager
    • getChatAccount

      public com.github.philippheuer.credentialmanager.domain.OAuth2Credential getChatAccount()
      IRC User Id
    • getBaseUrl

      public String getBaseUrl()
      A custom websocket url for TwitchChat to connect to. Must include the scheme (e.g. ws:// or wss://).
    • isSendCredentialToThirdPartyHost

      public boolean isSendCredentialToThirdPartyHost()
      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.

      Do not depart from the default false value unless you understand the consequences.

    • getBotOwnerIds

      public Collection<String> getBotOwnerIds()
      User IDs of Bot Owners for applying CommandPermission.OWNER
    • getCommandPrefixes

      public Set<String> getCommandPrefixes()
      IRC Command Handlers
    • getChatQueueSize

      public Integer getChatQueueSize()
      Size of the ChatQueue
    • getChatRateLimit

      public io.github.bucket4j.Bandwidth getChatRateLimit()
      Custom RateLimit for ChatMessages
    • getWhisperRateLimit

      @Deprecated public io.github.bucket4j.Bandwidth[] getWhisperRateLimit()
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Custom RateLimit for Whispers
    • getJoinRateLimit

      public io.github.bucket4j.Bandwidth getJoinRateLimit()
      Custom RateLimit for JOIN/PART
    • getAuthRateLimit

      public io.github.bucket4j.Bandwidth getAuthRateLimit()
      Custom RateLimit for AUTH
    • getPerChannelRateLimit

      public io.github.bucket4j.Bandwidth getPerChannelRateLimit()
      Custom RateLimit for Messages per Channel

      For example, this can restrict messages per channel at 100/30 (for a verified bot that has a global 7500/30 message limit).

    • getIrcMessageBucket

      public io.github.bucket4j.Bucket getIrcMessageBucket()
      Shared bucket for messages
    • getIrcWhisperBucket

      @Deprecated public io.github.bucket4j.Bucket getIrcWhisperBucket()
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Shared bucket for whispers
    • getIrcJoinBucket

      public io.github.bucket4j.Bucket getIrcJoinBucket()
      Shared bucket for joins
    • getIrcAuthBucket

      public io.github.bucket4j.Bucket getIrcAuthBucket()
      Shared bucket for auths
    • getScheduledThreadPoolExecutor

      public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
      Scheduler Thread Pool Executor
    • getChatQueueTimeout

      public long getChatQueueTimeout()
      Millisecond wait time for taking items off chat queue. Default recommended
    • getProxyConfig

      public ProxyConfig getProxyConfig()
      Proxy Configuration
    • isAutoJoinOwnChannel

      public boolean isAutoJoinOwnChannel()
      Whether one's own channel should automatically be joined
    • isEnableMembershipEvents

      public boolean isEnableMembershipEvents()
      Whether JOIN/PART events should be enabled for the TwitchChat instance.
    • isRemoveChannelOnJoinFailure

      public boolean isRemoveChannelOnJoinFailure()
      Whether join failures should result in removal from current channels.
      See Also:
    • getMaxJoinRetries

      public int getMaxJoinRetries()
      The maximum number of retries to make for joining each channel, with exponential backoff. Set to zero or a negative value to disable this feature.
    • getChatJoinTimeout

      public long getChatJoinTimeout()
      The amount of milliseconds to wait after queuing a JOIN before classifying the attempt as a failure.

      If this value is configured too low, the chat instance could mistake a successfully joined channel for a failure. This can be especially problematic when removeChannelOnJoinFailure has been set to true.

    • getWsPingPeriod

      public int getWsPingPeriod()
      WebSocket RFC Ping Period in ms (0 = disabled)
    • getWsCloseDelay

      public int getWsCloseDelay()
      Websocket Close Delay in ms (0 = minimum)
      See Also:
    • getConnectionBackoffStrategy

      public IBackoffStrategy getConnectionBackoffStrategy()
      WebSocket Connection Backoff Strategy
    • isVerifyChatAccountOnReconnect

      public boolean isVerifyChatAccountOnReconnect()
      Whether the getChatAccount() should be validated on reconnection failures.

      If enabled and the token has expired, chat will connect in read-only mode instead.

      If the network connection is too slow, you may want to disable this setting to avoid disconnects while waiting for the result of the validate endpoint.

    • withWebsocketConnection

      protected TwitchChatBuilder withWebsocketConnection(WebsocketConnection websocketConnection)
      WebsocketConnection

      can be used to inject a mocked connection into the TwitchChat instance

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withClientId

      public TwitchChatBuilder withClientId(String clientId)
      Client Id
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withClientSecret

      public TwitchChatBuilder withClientSecret(String clientSecret)
      Client Secret
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withRequestQueueSize

      public TwitchChatBuilder withRequestQueueSize(Integer requestQueueSize)
      HTTP Request Queue Size
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEventManager

      public TwitchChatBuilder withEventManager(com.github.philippheuer.events4j.core.EventManager eventManager)
      Event Manager
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withDefaultEventHandler

      public TwitchChatBuilder withDefaultEventHandler(Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> defaultEventHandler)
      EventManager
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withCredentialManager

      public TwitchChatBuilder withCredentialManager(com.github.philippheuer.credentialmanager.CredentialManager credentialManager)
      Credential Manager
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withChatAccount

      public TwitchChatBuilder withChatAccount(com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatAccount)
      IRC User Id
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withBaseUrl

      public TwitchChatBuilder withBaseUrl(String baseUrl)
      A custom websocket url for TwitchChat to connect to. Must include the scheme (e.g. ws:// or wss://).
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withSendCredentialToThirdPartyHost

      public TwitchChatBuilder withSendCredentialToThirdPartyHost(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.

      Do not depart from the default false value unless you understand the consequences.

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • setBotOwnerIds

      public TwitchChatBuilder setBotOwnerIds(Collection<String> botOwnerIds)
      User IDs of Bot Owners for applying CommandPermission.OWNER
      Returns:
      this.
    • setCommandPrefixes

      public TwitchChatBuilder setCommandPrefixes(Set<String> commandPrefixes)
      IRC Command Handlers
      Returns:
      this.
    • withChatQueueSize

      public TwitchChatBuilder withChatQueueSize(Integer chatQueueSize)
      Size of the ChatQueue
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withChatRateLimit

      public TwitchChatBuilder withChatRateLimit(io.github.bucket4j.Bandwidth chatRateLimit)
      Custom RateLimit for ChatMessages
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withWhisperRateLimit

      @Deprecated public TwitchChatBuilder withWhisperRateLimit(io.github.bucket4j.Bandwidth[] whisperRateLimit)
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Custom RateLimit for Whispers
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withJoinRateLimit

      public TwitchChatBuilder withJoinRateLimit(io.github.bucket4j.Bandwidth joinRateLimit)
      Custom RateLimit for JOIN/PART
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withAuthRateLimit

      public TwitchChatBuilder withAuthRateLimit(io.github.bucket4j.Bandwidth authRateLimit)
      Custom RateLimit for AUTH
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withPerChannelRateLimit

      public TwitchChatBuilder withPerChannelRateLimit(io.github.bucket4j.Bandwidth perChannelRateLimit)
      Custom RateLimit for Messages per Channel

      For example, this can restrict messages per channel at 100/30 (for a verified bot that has a global 7500/30 message limit).

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withIrcMessageBucket

      public TwitchChatBuilder withIrcMessageBucket(io.github.bucket4j.Bucket ircMessageBucket)
      Shared bucket for messages
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withIrcWhisperBucket

      @Deprecated public TwitchChatBuilder withIrcWhisperBucket(io.github.bucket4j.Bucket ircWhisperBucket)
      Deprecated.
      Twitch will decommission whispers over IRC on February 18, 2023; please migrate to TwitchHelix#sendWhisper and TwitchLimitRegistry#setLimit
      Shared bucket for whispers
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withIrcJoinBucket

      public TwitchChatBuilder withIrcJoinBucket(io.github.bucket4j.Bucket ircJoinBucket)
      Shared bucket for joins
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withIrcAuthBucket

      public TwitchChatBuilder withIrcAuthBucket(io.github.bucket4j.Bucket ircAuthBucket)
      Shared bucket for auths
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withScheduledThreadPoolExecutor

      public TwitchChatBuilder withScheduledThreadPoolExecutor(ScheduledThreadPoolExecutor scheduledThreadPoolExecutor)
      Scheduler Thread Pool Executor
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withChatQueueTimeout

      public TwitchChatBuilder withChatQueueTimeout(long chatQueueTimeout)
      Millisecond wait time for taking items off chat queue. Default recommended
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withProxyConfig

      public TwitchChatBuilder withProxyConfig(ProxyConfig proxyConfig)
      Proxy Configuration
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withAutoJoinOwnChannel

      public TwitchChatBuilder withAutoJoinOwnChannel(boolean autoJoinOwnChannel)
      Whether one's own channel should automatically be joined
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableMembershipEvents

      public TwitchChatBuilder withEnableMembershipEvents(boolean enableMembershipEvents)
      Whether JOIN/PART events should be enabled for the TwitchChat instance.
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withRemoveChannelOnJoinFailure

      public TwitchChatBuilder withRemoveChannelOnJoinFailure(boolean removeChannelOnJoinFailure)
      Whether join failures should result in removal from current channels.
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
      See Also:
    • withMaxJoinRetries

      public TwitchChatBuilder withMaxJoinRetries(int maxJoinRetries)
      The maximum number of retries to make for joining each channel, with exponential backoff. Set to zero or a negative value to disable this feature.
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withChatJoinTimeout

      public TwitchChatBuilder withChatJoinTimeout(long chatJoinTimeout)
      The amount of milliseconds to wait after queuing a JOIN before classifying the attempt as a failure.

      If this value is configured too low, the chat instance could mistake a successfully joined channel for a failure. This can be especially problematic when removeChannelOnJoinFailure has been set to true.

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withWsPingPeriod

      public TwitchChatBuilder withWsPingPeriod(int wsPingPeriod)
      WebSocket RFC Ping Period in ms (0 = disabled)
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withWsCloseDelay

      public TwitchChatBuilder withWsCloseDelay(int wsCloseDelay)
      Websocket Close Delay in ms (0 = minimum)
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
      See Also:
    • withConnectionBackoffStrategy

      public TwitchChatBuilder withConnectionBackoffStrategy(IBackoffStrategy connectionBackoffStrategy)
      WebSocket Connection Backoff Strategy
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withVerifyChatAccountOnReconnect

      public TwitchChatBuilder withVerifyChatAccountOnReconnect(boolean verifyChatAccountOnReconnect)
      Whether the getChatAccount() should be validated on reconnection failures.

      If enabled and the token has expired, chat will connect in read-only mode instead.

      If the network connection is too slow, you may want to disable this setting to avoid disconnects while waiting for the result of the validate endpoint.

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withOutboundCommandFilter

      @Deprecated @Internal public TwitchChatBuilder withOutboundCommandFilter(BiPredicate<TwitchChat,String> outboundCommandFilter)
      Deprecated.
      Filter for outbound messages. The command will not be sent to the IRC server if the predicate yields true.

      Only intended for internal use by twitch4j.

      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).