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 TypeMethodDescriptionboolean
Returns the current state of EventSub mode.void
eventSubMode
(boolean enabled) Sets the current state of EventSub mode.int
The 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.long
Returns 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 streamlong
Returns the uptime of the channel in seconds.int
Deprecated, for removal: This API element is subject to removal in a future version.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 soonvoid
goOffline
(boolean shouldSendEvent) Sets offline statevoid
goOnline
(boolean shouldSendEvent) Sets online statevoid
goOnline
(boolean shouldSendEvent, boolean useOfflineTimeout) Sets online statestatic TwitchCache
instance()
boolean
Indicates if this channel is an affiliateboolean
Indicates if this channel is either an affiliate or a partnerboolean
Indicates if this channel is a partnerboolean
Returns if the channel is online or not.Returns a String representation of true/false to indicate if the stream is online or not.void
kill()
void
Performs startup if properties are reloaded and previous startup has failedvoid
setAffiliatePartner
(boolean isAffiliate, boolean isPartner) Sets the current Affiliate and Partner states, and sends ane vent if they changedvoid
setGameTitle
(String gameTitle) Sets the game titlevoid
setGameTitle
(String gameTitle, boolean sendEvent) Sets the game titlevoid
setStreamStatus
(String streamTitle) Sets the title (status) of the streamvoid
setStreamStatus
(String streamTitle, boolean sendEvent) Sets the title (status) of the streamint
The current number of subscriber points of the broadcaster.int
The current number of subscribers of the broadcaster.void
Syncs the stream status using both Get Streams and Get Channel Information, then sets the online statusvoid
syncStreamInfoFromChannel
(boolean shouldSendEvent, Consumer<Boolean> callback) Syncs teh current stream title/game via the Get Channel Information endpointvoid
Updates the stream status from the APIvoid
syncStreamStatus
(boolean shouldSendEvent) Updates the stream status from the Get Streams endpointvoid
syncStreamStatus
(boolean shouldSendEvent, Consumer<Boolean> callback) Updates the stream title/game/online status from the Get Streams endpointvoid
Updates the current game from the APIvoid
updateGame
(boolean sendEvent) Updates the current gamevoid
updateViewerCount
(int viewers) Updates the viewer countint
viewers()
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
-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
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
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
-true
to 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
-true
to 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;
0
if 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:
-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 aTwitchOnlineEvent
-
goOnline
public void goOnline(boolean shouldSendEvent, boolean useOfflineTimeout) Sets online state- Parameters:
shouldSendEvent
-true
to send aTwitchOnlineEvent
-
goOffline
public void goOffline(boolean shouldSendEvent) Sets offline state- Parameters:
shouldSendEvent
-true
to 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
-true
to sendTwitchOnlineEvent
orTwitchOfflineEvent
, if appropriate
-
syncStreamStatus
Updates the stream title/game/online status from the Get Streams endpoint- Parameters:
shouldSendEvent
-true
to send events, if appropriatecallback
- A callback to execute on success. The parameter istrue
if the stream information was successfully retrieved
-
syncStreamInfoFromChannel
Syncs teh current stream title/game via the Get Channel Information endpoint- Parameters:
shouldSendEvent
-true
to sendTwitchTitleChangeEvent
and/orTwitchGameChangeEvent
, if appropriatecallback
- A callback to execute on success. The parameter istrue
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 sendTwitchGameChangeEvent
, if appropriate
-
kill
public void kill()
-
viewers()
instead