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 ofViewer
objects representing users recently seen in chat, who have sent a message in the past 5 minutesboolean
Adds a viewer to the cachebot()
Returns theViewer
object representing the bot accountReturns theViewer
object representing the broadcaster accountchatters()
Returns a list ofViewer
objects representing users recently seen in chatboolean
Indicates if the specified user id is already in the cacheReturns theViewer
object for the specified user idgetByLogin
(String login) Returns theViewer
object for the specified user loginstatic ViewerCache
instance()
Singleton methodboolean
loginExists
(String login) Indicates if the specified user login is already in the cachevoid
lookupAsync
(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 idvoid
lookupLoginAsync
(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 loginvoid
Updates the cache when a TMI message is receivedvoid
Updates the broadcaster and bot in the cache if they have changedvoid
Removes the specified user from the cachevoid
removeByLogin
(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:
true
if the new object was added;false
if the viewer already exists- Throws:
NullPointerException
- if the new object wasnull
-
get
Returns theViewer
object 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
Viewer
object for the user;null
if not found
-
getByLogin
Returns theViewer
object 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
Viewer
object for the user;null
if not found
-
exists
Indicates if the specified user id is already in the cache- Parameters:
id
- The user id to lookup- Returns:
true
if 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:
true
if 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 theViewer
object representing the bot account- Returns:
- The
Viewer
object representing the bot account
-
broadcaster
Returns theViewer
object representing the broadcaster account- Returns:
- The
Viewer
object representing the broadcaster account
-
chatters
Returns a list ofViewer
objects representing users recently seen in chat -
activeChatters
Returns a list ofViewer
objects 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;
null
if 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;
null
if the specified user login is not in the database
-