Package com.gmt2001.twitch.cache
Class ViewerCache
java.lang.Object
com.gmt2001.twitch.cache.ViewerCache
- All Implemented Interfaces:
Listener
Maintains a list of viewers, Twitch viewer permissions, and username lookups
- Author:
- gmt2001
-
Method Summary
Modifier and TypeMethodDescriptionReturns a list ofViewerobjects representing users recently seen in chat, who have sent a message in the past 5 minutesbooleanAdds a viewer to the cachebot()Returns theViewerobject representing the bot accountReturns theViewerobject representing the broadcaster accountchatters()Returns a list ofViewerobjects representing users recently seen in chatbooleanIndicates if the specified user id is already in the cacheReturns theViewerobject for the specified user idgetByLogin(String login) Returns theViewerobject for the specified user loginstatic ViewerCacheinstance()Singleton methodbooleanloginExists(String login) Indicates if the specified user login is already in the cachevoidlookupAsync(List<String> id) Performs an asynchronous operation to lookup the users on Twitch API and add them to the cachelookupIdByLogin(String login) Looks up the specified user login in the mapping database and returns the associated user idvoidlookupLoginAsync(List<String> login) Performs an asynchronous operation to lookup the users on Twitch API and add them to the cacheLooks up the specified user id in the mapping database and returns the associated user loginvoidUpdates the cache when a TMI message is receivedvoidUpdates the broadcaster and bot in the cache if they have changedvoidRemoves the specified user from the cachevoidremoveByLogin(String login) Removes the specified user from the cache by login name
-
Method Details
-
instance
Singleton method- Returns:
- The singleton instance of ViewerCache
-
onPropertiesReloadedEvent
Updates the broadcaster and bot in the cache if they have changed- Parameters:
event- The event to process
-
onIrcModerationEvent
Updates the cache when a TMI message is received- Parameters:
event- The event to process
-
lookupAsync
Performs an asynchronous operation to lookup the users on Twitch API and add them to the cache- Parameters:
id- A list of user ids to lookup
-
lookupLoginAsync
Performs an asynchronous operation to lookup the users on Twitch API and add them to the cache- Parameters:
login- A list of user logins to lookup
-
add
Adds a viewer to the cacheIf a viewer with the same user id exists, then the new object is discarded and the
Viewer.seen()method is called instead- Parameters:
viewer- The viewer object to add- Returns:
trueif the new object was added;falseif the viewer already exists- Throws:
NullPointerException- if the new object wasnull
-
get
Returns theViewerobject for the specified user idIf the object does not yet exist, a lookup is performed on Twitch API
- Parameters:
id- The user id to lookup- Returns:
- The
Viewerobject for the user;nullif not found
-
getByLogin
Returns theViewerobject for the specified user loginIf the object does not yet exist, a lookup is performed on Twitch API
- Parameters:
login- The user login to lookup- Returns:
- The
Viewerobject for the user;nullif not found
-
exists
Indicates if the specified user id is already in the cache- Parameters:
id- The user id to lookup- Returns:
trueif this user id is already in the cache
-
loginExists
Indicates if the specified user login is already in the cache- Parameters:
login- The user login to lookup- Returns:
trueif this user login is already in the cache
-
remove
Removes the specified user from the cache- Parameters:
id- The user id to remove
-
removeByLogin
Removes the specified user from the cache by login name- Parameters:
login- The user login to remove
-
bot
Returns theViewerobject representing the bot account- Returns:
- The
Viewerobject representing the bot account
-
broadcaster
Returns theViewerobject representing the broadcaster account- Returns:
- The
Viewerobject representing the broadcaster account
-
chatters
Returns a list ofViewerobjects representing users recently seen in chat -
activeChatters
Returns a list ofViewerobjects representing users recently seen in chat, who have sent a message in the past 5 minutes -
lookupLoginById
Looks up the specified user id in the mapping database and returns the associated user login- Parameters:
id- The user id to lookup- Returns:
- The associated user login;
nullif the specified user id is not in the database
-
lookupIdByLogin
Looks up the specified user login in the mapping database and returns the associated user id- Parameters:
login- The user login to lookup- Returns:
- The associated user id;
nullif the specified user login is not in the database
-