Class TwitchClientHelper

java.lang.Object
com.github.twitch4j.TwitchClientHelper
All Implemented Interfaces:
IClientHelper, AutoCloseable

public class TwitchClientHelper extends Object implements IClientHelper
A helper class that covers a few basic use cases of most library users
  • Field Details

  • Constructor Details

    • TwitchClientHelper

      @Internal public TwitchClientHelper(TwitchHelix twitchHelix, com.github.philippheuer.events4j.core.EventManager eventManager, ScheduledThreadPoolExecutor executor, com.github.philippheuer.credentialmanager.CredentialManager credentialManager, com.github.philippheuer.credentialmanager.domain.OAuth2Credential defaultToken)
      Constructor
      Parameters:
      twitchHelix - TwitchHelix
      eventManager - EventManager
      executor - ScheduledThreadPoolExecutor
      credentialManager - CredentialManager
      defaultToken - OAuth2Credential
  • Method Details

    • enableStreamEventListener

      public boolean enableStreamEventListener(String channelId, String channelName)
      Description copied from interface: IClientHelper
      Enable StreamEvent Listener, without invoking a Helix API call
      Specified by:
      enableStreamEventListener in interface IClientHelper
      Parameters:
      channelId - Channel Id
      channelName - Channel Name
      Returns:
      true if the channel was added, false otherwise
    • disableStreamEventListenerForId

      public boolean disableStreamEventListenerForId(String channelId)
      Description copied from interface: IClientHelper
      Disable StreamEventListener, without invoking a Helix API call
      Specified by:
      disableStreamEventListenerForId in interface IClientHelper
      Parameters:
      channelId - Channel Id
      Returns:
      true if the channel was removed, false otherwise
    • enableFollowEventListener

      public boolean enableFollowEventListener(String channelId, String channelName)
      Description copied from interface: IClientHelper
      Enable Follow Listener, without invoking a Helix API call

      For FollowEvent to fire, defaultAuthToken must be a user access token from a moderator of the channel with the TwitchScopes.HELIX_CHANNEL_FOLLOWERS_READ scope. Otherwise, the client helper can only fire ChannelFollowCountUpdateEvent due to Twitch restrictions implemented on 2023-09-12.

      Specified by:
      enableFollowEventListener in interface IClientHelper
      Parameters:
      channelId - Channel Id
      channelName - Channel Name
      Returns:
      true if the channel was added, false otherwise
    • disableFollowEventListenerForId

      public boolean disableFollowEventListenerForId(String channelId)
      Description copied from interface: IClientHelper
      Disable Follow Listener, without invoking a Helix API call
      Specified by:
      disableFollowEventListenerForId in interface IClientHelper
      Parameters:
      channelId - Channel Id
      Returns:
      true when a previously-tracked channel was removed, false otherwise
    • enableClipEventListener

      public boolean enableClipEventListener(String channelId, String channelName, Instant startedAt)
      Description copied from interface: IClientHelper
      Enable Clip Creation Listener, without invoking a Helix API call, starting at a custom timestamp
      Specified by:
      enableClipEventListener in interface IClientHelper
      Parameters:
      channelId - Channel Id
      channelName - Channel Name
      startedAt - The oldest clip creation timestamp to start the queries at
      Returns:
      whether the channel was added
    • disableClipEventListenerForId

      public boolean disableClipEventListenerForId(String channelId)
      Description copied from interface: IClientHelper
      Disable Clip Creation Listener, without invoking a Helix API call
      Specified by:
      disableClipEventListenerForId in interface IClientHelper
      Parameters:
      channelId - Channel Id
      Returns:
      whether a previously-tracked channel was removed
    • setThreadDelay

      public void setThreadDelay(long threadDelay)
      Description copied from interface: IClientHelper
      Updates ExponentialBackoffStrategy.getBaseMillis() for each of the independent listeners (i.e. stream status and followers)
      Specified by:
      setThreadDelay in interface IClientHelper
      Parameters:
      threadDelay - the minimum milliseconds delay between each api call
    • getCachedInformation

      public Optional<ChannelCache> getCachedInformation(String channelId)
      Description copied from interface: IClientHelper
      Get cached information for a channel's stream status and follower count.

      For this information to be valid, the respective event listeners need to be enabled for the channel.

      For thread safety, the setters on this object should not be used; only getters.

      Specified by:
      getCachedInformation in interface IClientHelper
      Parameters:
      channelId - The ID of the channel whose cache is to be retrieved.
      Returns:
      ChannelCache in an optional wrapper.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getTwitchHelix

      public TwitchHelix getTwitchHelix()
      Twitch Helix
      Specified by:
      getTwitchHelix in interface IClientHelper