Class TwitchClientBuilder

java.lang.Object
com.github.twitch4j.TwitchClientBuilder

public class TwitchClientBuilder extends Object
Builder to get a TwitchClient Instance by provided various options, to provide the user with a lot of customizable options.
  • 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
    • chatWhisperLimit

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

      protected io.github.bucket4j.Bandwidth chatJoinLimit
      Custom RateLimit for JOIN/PART
    • chatAuthLimit

      protected io.github.bucket4j.Bandwidth chatAuthLimit
      Custom RateLimit for AUTH
    • chatChannelMessageLimit

      protected io.github.bucket4j.Bandwidth chatChannelMessageLimit
      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).

  • Method Details

    • withBotOwnerId

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

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

      @Deprecated @ScheduledForRemoval(inVersion="2.0.0") public TwitchClientBuilder withHelperThreadRate(long helperThreadDelay)
      Deprecated.
      in favor of withHelperThreadDelay
      With a base thread delay for API calls by TwitchClientHelper

      Note: the method name has been a misnomer as it has always set the delay rather than a rate. One can change the rate at any time via IClientHelper.setThreadRate(long).

      Parameters:
      helperThreadDelay - TwitchClientHelper Base Thread Delay
      Returns:
      TwitchClientBuilder
    • builder

      public static TwitchClientBuilder builder()
      Initialize the builder
      Returns:
      Twitch Client Builder
    • build

      public TwitchClient build()
      Initialize
      Returns:
      TwitchClient initialized class
    • getClientId

      public String getClientId()
      Client Id
    • getClientSecret

      public String getClientSecret()
      Client Secret
    • getUserAgent

      public String getUserAgent()
      User Agent
    • getRequestQueueSize

      public Integer getRequestQueueSize()
      HTTP Request Queue Size
    • getRedirectUrl

      public String getRedirectUrl()
      Redirect Url
    • getTimeout

      public Integer getTimeout()
      Default Timeout
    • getEnableExtensions

      @Deprecated public Boolean getEnableExtensions()
      Deprecated.
      the Extensions API traditionally uses the decommissioned Kraken API. While the module now forwards calls to Helix, please migrate to using Helix directly as this module will be removed in the future.
      Enabled: Extensions
      See Also:
    • getEnableHelix

      public Boolean getEnableHelix()
      Enabled: Helix
    • getEnableKraken

      @Deprecated public Boolean getEnableKraken()
      Deprecated.
      Kraken is deprecated and has been shut down on Febuary 28, 2022. More details about the deprecation are available here. Use withEnableHelix(Boolean) instead.
      Enabled: Kraken
    • getEnableTMI

      @Deprecated public Boolean getEnableTMI()
      Deprecated.
      All of the TwitchMessagingInterfaceBuilder endpoints have been (or will be) decommissioned by Twitch.
      Enabled: TMI
    • getEnableChat

      public Boolean getEnableChat()
      Enabled: Chat
    • getBotOwnerIds

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

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

      public Boolean getEnablePubSub()
      Enabled: PubSub
    • getEnableGraphQL

      public Boolean getEnableGraphQL()
      Enabled: GraphQL

      This is an unofficial API that is not intended for third-party use. Use at your own risk. Methods could change or stop working at any time.

    • getChatAccount

      public com.github.philippheuer.credentialmanager.domain.OAuth2Credential getChatAccount()
      Chat Account
    • getEnableEventSocket

      public Boolean getEnableEventSocket()
      Enabled: EventSub over WebSocket
    • getEventManager

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

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

      public Integer getChatQueueSize()
      Size of the ChatQueue
    • getChatRateLimit

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

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

      public io.github.bucket4j.Bandwidth getChatJoinLimit()
      Custom RateLimit for JOIN/PART
    • getChatAuthLimit

      public io.github.bucket4j.Bandwidth getChatAuthLimit()
      Custom RateLimit for AUTH
    • getChatChannelMessageLimit

      public io.github.bucket4j.Bandwidth getChatChannelMessageLimit()
      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).

    • getChatQueueTimeout

      public long getChatQueueTimeout()
      Wait time for taking items off chat queue in milliseconds. Default recommended
    • getChatMaxJoinRetries

      public int getChatMaxJoinRetries()
      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.
    • getChatServer

      public String getChatServer()
      Sets the default server used for chat

      Defaults to TwitchChat.TWITCH_WEB_SOCKET_SERVER, you can use TwitchChat.FDGT_TEST_SOCKET_SERVER for testing

    • getHelixBaseUrl

      public String getHelixBaseUrl()
      The base URL to use for Helix API calls.

      Can be adjusted to point to the Twitch CLI Mock API, for example.

      See Also:
    • getCredentialManager

      @NotNull public @NotNull com.github.philippheuer.credentialmanager.CredentialManager getCredentialManager()
      CredentialManager
    • getScheduledThreadPoolExecutor

      public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
      Scheduler Thread Pool Executor
    • getHelperThreadDelay

      public long getHelperThreadDelay()
      Millisecond Delay for Client Helper Thread
    • getDefaultAuthToken

      public com.github.philippheuer.credentialmanager.domain.OAuth2Credential getDefaultAuthToken()
      Default Auth Token for Helix API Requests
    • getDefaultFirstPartyToken

      public com.github.philippheuer.credentialmanager.domain.OAuth2Credential getDefaultFirstPartyToken()
      Default First-Party OAuth Token for GraphQL calls
    • getProxyConfig

      public ProxyConfig getProxyConfig()
      Proxy Configuration
    • getFeignLogLevel

      public feign.Logger.Level getFeignLogLevel()
      you can overwrite the feign loglevel to print the full requests + responses if needed
    • 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:
    • isChatCommandsViaHelix

      public boolean isChatCommandsViaHelix()
      Whether chat commands should be executed via the Helix API, if possible.

      Must have withEnableHelix(Boolean) and withEnableChat(Boolean) set to true.

      Must have withChatAccount(OAuth2Credential) or withDefaultAuthToken(OAuth2Credential) specified.

    • getForwardedChatCommandHelixLimitPerChannel

      public io.github.bucket4j.Bandwidth getForwardedChatCommandHelixLimitPerChannel()
      The per-channel rate limit at which chat commands forwarded to helix should be executed.

      This prevents commands to a single channel from consuming the entire helix rate limit bucket. As such, this can be restricted further or loosened, depending on how many channels the bot serves.

      This has no effect unless isChatCommandsViaHelix() is true.

      Users should migrate to manual helix calls (with whatever throttling they desire) instead.

    • withClientId

      public TwitchClientBuilder 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 TwitchClientBuilder withClientSecret(String clientSecret)
      Client Secret
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withUserAgent

      public TwitchClientBuilder withUserAgent(String userAgent)
      User Agent
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withRequestQueueSize

      public TwitchClientBuilder 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).
    • withRedirectUrl

      public TwitchClientBuilder withRedirectUrl(String redirectUrl)
      Redirect Url
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withTimeout

      public TwitchClientBuilder withTimeout(Integer timeout)
      Default Timeout
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableExtensions

      @Deprecated public TwitchClientBuilder withEnableExtensions(Boolean enableExtensions)
      Deprecated.
      the Extensions API traditionally uses the decommissioned Kraken API. While the module now forwards calls to Helix, please migrate to using Helix directly as this module will be removed in the future.
      Enabled: Extensions
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
      See Also:
    • withEnableHelix

      public TwitchClientBuilder withEnableHelix(Boolean enableHelix)
      Enabled: Helix
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableKraken

      @Deprecated public TwitchClientBuilder withEnableKraken(Boolean enableKraken)
      Deprecated.
      Kraken is deprecated and has been shut down on Febuary 28, 2022. More details about the deprecation are available here. Use withEnableHelix(Boolean) instead.
      Enabled: Kraken
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableTMI

      @Deprecated public TwitchClientBuilder withEnableTMI(Boolean enableTMI)
      Deprecated.
      All of the TwitchMessagingInterfaceBuilder endpoints have been (or will be) decommissioned by Twitch.
      Enabled: TMI
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableChat

      public TwitchClientBuilder withEnableChat(Boolean enableChat)
      Enabled: Chat
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • setBotOwnerIds

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

      public TwitchClientBuilder withEnablePubSub(Boolean enablePubSub)
      Enabled: PubSub
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableGraphQL

      public TwitchClientBuilder withEnableGraphQL(Boolean enableGraphQL)
      Enabled: GraphQL

      This is an unofficial API that is not intended for third-party use. Use at your own risk. Methods could change or stop working at any time.

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

      public TwitchClientBuilder withChatAccount(com.github.philippheuer.credentialmanager.domain.OAuth2Credential chatAccount)
      Chat Account
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEnableEventSocket

      public TwitchClientBuilder withEnableEventSocket(Boolean enableEventSocket)
      Enabled: EventSub over WebSocket
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withEventManager

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

      public TwitchClientBuilder 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).
    • withChatQueueSize

      public TwitchClientBuilder 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 TwitchClientBuilder 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).
    • withChatWhisperLimit

      @Deprecated public TwitchClientBuilder withChatWhisperLimit(io.github.bucket4j.Bandwidth[] chatWhisperLimit)
      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).
    • withChatJoinLimit

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

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

      public TwitchClientBuilder withChatChannelMessageLimit(io.github.bucket4j.Bandwidth chatChannelMessageLimit)
      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).
    • withChatQueueTimeout

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

      public TwitchClientBuilder withChatMaxJoinRetries(int chatMaxJoinRetries)
      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).
    • withChatServer

      public TwitchClientBuilder withChatServer(String chatServer)
      Sets the default server used for chat

      Defaults to TwitchChat.TWITCH_WEB_SOCKET_SERVER, you can use TwitchChat.FDGT_TEST_SOCKET_SERVER for testing

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

      public TwitchClientBuilder withHelixBaseUrl(String helixBaseUrl)
      The base URL to use for Helix API calls.

      Can be adjusted to point to the Twitch CLI Mock API, for example.

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

      public TwitchClientBuilder withCredentialManager(@NotNull @NotNull com.github.philippheuer.credentialmanager.CredentialManager credentialManager)
      CredentialManager
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withScheduledThreadPoolExecutor

      public TwitchClientBuilder 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).
    • withHelperThreadDelay

      public TwitchClientBuilder withHelperThreadDelay(long helperThreadDelay)
      Millisecond Delay for Client Helper Thread
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withDefaultAuthToken

      public TwitchClientBuilder withDefaultAuthToken(com.github.philippheuer.credentialmanager.domain.OAuth2Credential defaultAuthToken)
      Default Auth Token for Helix API Requests
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withDefaultFirstPartyToken

      public TwitchClientBuilder withDefaultFirstPartyToken(com.github.philippheuer.credentialmanager.domain.OAuth2Credential defaultFirstPartyToken)
      Default First-Party OAuth Token for GraphQL calls
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withProxyConfig

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

      public TwitchClientBuilder withFeignLogLevel(feign.Logger.Level feignLogLevel)
      you can overwrite the feign loglevel to print the full requests + responses if needed
      Returns:
      a clone of this object, except with this updated property (returns this if an identical value is passed).
    • withWsPingPeriod

      public TwitchClientBuilder 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 TwitchClientBuilder 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:
    • withChatCommandsViaHelix

      public TwitchClientBuilder withChatCommandsViaHelix(boolean chatCommandsViaHelix)
      Whether chat commands should be executed via the Helix API, if possible.

      Must have withEnableHelix(Boolean) and withEnableChat(Boolean) set to true.

      Must have withChatAccount(OAuth2Credential) or withDefaultAuthToken(OAuth2Credential) specified.

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

      @Deprecated public TwitchClientBuilder withForwardedChatCommandHelixLimitPerChannel(io.github.bucket4j.Bandwidth forwardedChatCommandHelixLimitPerChannel)
      Deprecated.
      The per-channel rate limit at which chat commands forwarded to helix should be executed.

      This prevents commands to a single channel from consuming the entire helix rate limit bucket. As such, this can be restricted further or loosened, depending on how many channels the bot serves.

      This has no effect unless isChatCommandsViaHelix() is true.

      Users should migrate to manual helix calls (with whatever throttling they desire) instead.

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