Package tv.phantombot.cache
Class TwitchCache
java.lang.Object
tv.phantombot.cache.TwitchCache
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionbooleanReturns the current state of EventSub mode.voideventSubMode(boolean enabled) Sets the current state of EventSub mode.intThe current number of followers of the broadcaster.Returns the display name of the streamer.Returns the name of the game being played in the channel.longReturns the uptime of the channel in seconds of the previous stream.Returns the logo link.Returns the preview link.Returns the stream created_at date from Twitch.Returns the title (status) of the streamlongReturns the uptime of the channel in seconds.intDeprecated, for removal: This API element is subject to removal in a future version.intgetViews()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 soonvoidgoOffline(boolean shouldSendEvent) Sets offline statevoidgoOnline(boolean shouldSendEvent) Sets online statevoidgoOnline(boolean shouldSendEvent, boolean useOfflineTimeout) Sets online statestatic TwitchCacheinstance()booleanIndicates if this channel is an affiliatebooleanIndicates if this channel is either an affiliate or a partnerbooleanIndicates if this channel is a partnerbooleanReturns if the channel is online or not.Returns a String representation of true/false to indicate if the stream is online or not.voidkill()voidPerforms startup if properties are reloaded and previous startup has failedvoidsetAffiliatePartner(boolean isAffiliate, boolean isPartner) Sets the current Affiliate and Partner states, and sends ane vent if they changedvoidsetGameTitle(String gameTitle) Sets the game titlevoidsetGameTitle(String gameTitle, boolean sendEvent) Sets the game titlevoidsetStreamStatus(String streamTitle) Sets the title (status) of the streamvoidsetStreamStatus(String streamTitle, boolean sendEvent) Sets the title (status) of the streamintThe current number of subscriber points of the broadcaster.intThe current number of subscribers of the broadcaster.voidSyncs the stream status using both Get Streams and Get Channel Information, then sets the online statusvoidsyncStreamInfoFromChannel(boolean shouldSendEvent, Consumer<Boolean> callback) Syncs teh current stream title/game via the Get Channel Information endpointvoidUpdates the stream status from the APIvoidsyncStreamStatus(boolean shouldSendEvent) Updates the stream status from the Get Streams endpointvoidsyncStreamStatus(boolean shouldSendEvent, Consumer<Boolean> callback) Updates the stream title/game/online status from the Get Streams endpointvoidUpdates the current game from the APIvoidupdateGame(boolean sendEvent) Updates the current gamevoidupdateViewerCount(int viewers) Updates the viewer countintviewers()The current number of viewers of the live stream.
-
Method Details
-
instance
-
onPropertiesReloadedEvent
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-trueIf the broadcaster is an Affiliate (not partner)isPartner-trueIf 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
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:
0Lif no streams have ended since the last bot restart
-
getStreamCreatedAt
Returns the stream created_at date from Twitch.- Returns:
-
getGameTitle
Returns the name of the game being played in the channel.- Returns:
-
setGameTitle
Sets the game title- Parameters:
gameTitle- The new game name
-
setGameTitle
Sets the game title- Parameters:
gameTitle- The new game namesendEvent-trueto send aTwitchGameChangeEvent
-
getStreamStatus
Returns the title (status) of the stream- Returns:
-
setStreamStatus
Sets the title (status) of the stream- Parameters:
streamTitle- The new title
-
setStreamStatus
Sets the title (status) of the stream- Parameters:
streamTitle- The new titlesendEvent-trueto send aTwitchTitleChangeEvent
-
getDisplayName
Returns the display name of the streamer.- Returns:
-
getPreviewLink
Returns the preview link.- Returns:
-
getLogoLink
Returns the logo link.- Returns:
-
getViewerCount
Deprecated, for removal: This API element is subject to removal in a future version.Please useviewers()insteadReturns 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;
0if not live
-
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 soonReturns the views count. Twitch does not report this anymore- Returns:
-1as 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-trueto 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:
trueif EventSub mode is enabled
-
goOnline
public void goOnline(boolean shouldSendEvent) Sets online state- Parameters:
shouldSendEvent-trueto send aTwitchOnlineEvent
-
goOnline
public void goOnline(boolean shouldSendEvent, boolean useOfflineTimeout) Sets online state- Parameters:
shouldSendEvent-trueto send aTwitchOnlineEvent
-
goOffline
public void goOffline(boolean shouldSendEvent) Sets offline state- Parameters:
shouldSendEvent-trueto send aTwitchOfflineEvent
-
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-trueto sendTwitchOnlineEventorTwitchOfflineEvent, if appropriate
-
syncStreamStatus
Updates the stream title/game/online status from the Get Streams endpoint- Parameters:
shouldSendEvent-trueto send events, if appropriatecallback- A callback to execute on success. The parameter istrueif the stream information was successfully retrieved
-
syncStreamInfoFromChannel
Syncs teh current stream title/game via the Get Channel Information endpoint- Parameters:
shouldSendEvent-trueto sendTwitchTitleChangeEventand/orTwitchGameChangeEvent, if appropriatecallback- A callback to execute on success. The parameter istrueif 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-trueto sendTwitchGameChangeEvent, if appropriate
-
kill
public void kill()
-
viewers()instead