Class TwitchCache

java.lang.Object
tv.phantombot.cache.TwitchCache
All Implemented Interfaces:
Listener

public final class TwitchCache extends Object implements Listener
TwitchCache Class This class keeps track of certain Twitch information such as if the channel is online or not and sends events to the JS side to indicate when the channel has gone off or online.
  • Method Details

    • instance

      public static TwitchCache instance()
    • onPropertiesReloadedEvent

      public void onPropertiesReloadedEvent(PropertiesReloadedEvent event)
      Performs startup if properties are reloaded and previous startup has failed
      Parameters:
      event -
    • setAffiliatePartner

      public void setAffiliatePartner(boolean isAffiliate, boolean isPartner)
      Sets the current Affiliate and Partner states, and sends ane vent if they changed
      Parameters:
      isAffiliate - true If the broadcaster is an Affiliate (not partner)
      isPartner - true If the broadcaster is a Partner (not affiliate)
    • isAffiliate

      public boolean isAffiliate()
      Indicates if this channel is an affiliate
      Returns:
    • isPartner

      public boolean isPartner()
      Indicates if this channel is a partner
      Returns:
    • isAffiliateOrPartner

      public boolean isAffiliateOrPartner()
      Indicates if this channel is either an affiliate or a partner
      Returns:
    • isStreamOnline

      public boolean isStreamOnline()
      Returns if the channel is online or not.
      Returns:
    • isStreamOnlineString

      public String isStreamOnlineString()
      Returns a String representation of true/false to indicate if the stream is online or not.
      Returns:
    • getStreamUptimeSeconds

      public long getStreamUptimeSeconds()
      Returns the uptime of the channel in seconds.
      Returns:
    • getLastStreamUptimeSeconds

      public long getLastStreamUptimeSeconds()
      Returns the uptime of the channel in seconds of the previous stream.
      Returns:
      0L if no streams have ended since the last bot restart
    • getStreamCreatedAt

      public String getStreamCreatedAt()
      Returns the stream created_at date from Twitch.
      Returns:
    • getGameTitle

      public String getGameTitle()
      Returns the name of the game being played in the channel.
      Returns:
    • setGameTitle

      public void setGameTitle(String gameTitle)
      Sets the game title
      Parameters:
      gameTitle - The new game name
    • setGameTitle

      public void setGameTitle(String gameTitle, boolean sendEvent)
      Sets the game title
      Parameters:
      gameTitle - The new game name
      sendEvent - true to send a TwitchGameChangeEvent
    • getStreamStatus

      public String getStreamStatus()
      Returns the title (status) of the stream
      Returns:
    • setStreamStatus

      public void setStreamStatus(String streamTitle)
      Sets the title (status) of the stream
      Parameters:
      streamTitle - The new title
    • setStreamStatus

      public void setStreamStatus(String streamTitle, boolean sendEvent)
      Sets the title (status) of the stream
      Parameters:
      streamTitle - The new title
      sendEvent - true to send a TwitchTitleChangeEvent
    • getDisplayName

      public String getDisplayName()
      Returns the display name of the streamer.
      Returns:
    • getPreviewLink

      public String getPreviewLink()
      Returns the preview link.
      Returns:
    • getLogoLink

      public String getLogoLink()
      Returns the logo link.
      Returns:
    • getViewerCount

      @Deprecated(since="3.8.0.0", forRemoval=true) public int getViewerCount()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use viewers() instead
      Returns the viewer count.
      Returns:
    • followers

      public int followers()
      The current number of followers of the broadcaster.

      This number may be slightly off from the actual live numbers due to the nature of Twitch API caching
      Returns:
      The number of followers of the broadcaster
    • subscribers

      public int subscribers()
      The current number of subscribers of the broadcaster.

      This number may be slightly off from the actual live numbers due to the nature of Twitch API caching
      Returns:
      The number of subscribers of the broadcaster
    • subscriberPoints

      public int subscriberPoints()
      The current number of subscriber points of the broadcaster.

      This number may be slightly off from the actual live numbers due to the nature of Twitch API caching
      Returns:
      The number of subscriber points of the broadcaster
    • viewers

      public int viewers()
      The current number of viewers of the live stream.

      This number may be slightly off from the actual live numbers due to the nature of Twitch API caching
      Returns:
      The number of viewers in the stream; 0 if not live
    • getViews

      @Deprecated(since="3.8.0.0", forRemoval=true) public int getViews()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Twitch does not report this anymore, this method is temporarily available to prevent script errors and will be removed soon
      Returns the views count. Twitch does not report this anymore
      Returns:
      -1 as Twitch does not report this anymore
    • eventSubMode

      public void eventSubMode(boolean enabled)
      Sets the current state of EventSub mode. When EventSub mode is enabled, stream title, game, and online state are not synced by TwitchAPI
      Parameters:
      enabled - true to enable EventSub mode
    • eventSubMode

      public boolean eventSubMode()
      Returns the current state of EventSub mode. When EventSub mode is enabled, stream title, game, and online state are not synced by TwitchAPI
      Returns:
      true if EventSub mode is enabled
    • goOnline

      public void goOnline(boolean shouldSendEvent)
      Sets online state
      Parameters:
      shouldSendEvent - true to send a TwitchOnlineEvent
    • goOnline

      public void goOnline(boolean shouldSendEvent, boolean useOfflineTimeout)
      Sets online state
      Parameters:
      shouldSendEvent - true to send a TwitchOnlineEvent
    • goOffline

      public void goOffline(boolean shouldSendEvent)
      Sets offline state
      Parameters:
      shouldSendEvent - true to send a TwitchOfflineEvent
    • syncOnline

      public void syncOnline()
      Syncs the stream status using both Get Streams and Get Channel Information, then sets the online status
    • syncStreamStatus

      public void syncStreamStatus()
      Updates the stream status from the API
    • syncStreamStatus

      public void syncStreamStatus(boolean shouldSendEvent)
      Updates the stream status from the Get Streams endpoint
      Parameters:
      shouldSendEvent - true to send TwitchOnlineEvent or TwitchOfflineEvent, if appropriate
    • syncStreamStatus

      public void syncStreamStatus(boolean shouldSendEvent, Consumer<Boolean> callback)
      Updates the stream title/game/online status from the Get Streams endpoint
      Parameters:
      shouldSendEvent - true to send events, if appropriate
      callback - A callback to execute on success. The parameter is true if the stream information was successfully retrieved
    • syncStreamInfoFromChannel

      public void syncStreamInfoFromChannel(boolean shouldSendEvent, Consumer<Boolean> callback)
      Syncs teh current stream title/game via the Get Channel Information endpoint
      Parameters:
      shouldSendEvent - true to send TwitchTitleChangeEvent and/or TwitchGameChangeEvent, if appropriate
      callback - A callback to execute on success. The parameter is true if the channel information was successfully retrieved
    • updateViewerCount

      public void updateViewerCount(int viewers)
      Updates the viewer count
      Parameters:
      viewers - The new viewer count
    • updateGame

      public void updateGame()
      Updates the current game from the API
    • updateGame

      public void updateGame(boolean sendEvent)
      Updates the current game
      Parameters:
      sendEvent - true to send TwitchGameChangeEvent, if appropriate
    • kill

      public void kill()