Class ViewerCache

java.lang.Object
com.gmt2001.twitch.cache.ViewerCache
All Implemented Interfaces:
Listener

public final class ViewerCache extends Object implements Listener
Maintains a list of viewers, Twitch viewer permissions, and username lookups
Author:
gmt2001
  • Method Details

    • instance

      public static ViewerCache instance()
      Singleton method
      Returns:
      The singleton instance of ViewerCache
    • onPropertiesReloadedEvent

      public void onPropertiesReloadedEvent(PropertiesReloadedEvent event)
      Updates the broadcaster and bot in the cache if they have changed
      Parameters:
      event - The event to process
    • onIrcModerationEvent

      public void onIrcModerationEvent(IrcModerationEvent event)
      Updates the cache when a TMI message is received
      Parameters:
      event - The event to process
    • lookupAsync

      public void lookupAsync(List<String> id)
      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

      public void lookupLoginAsync(List<String> login)
      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

      public boolean add(Viewer viewer)
      Adds a viewer to the cache

      If 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 was null
    • get

      public Viewer get(String id)
      Returns the Viewer object for the specified user id

      If 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

      public Viewer getByLogin(String login)
      Returns the Viewer object for the specified user login

      If 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

      public boolean exists(String id)
      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

      public boolean loginExists(String login)
      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

      public void remove(String id)
      Removes the specified user from the cache
      Parameters:
      id - The user id to remove
    • removeByLogin

      public void removeByLogin(String login)
      Removes the specified user from the cache by login name
      Parameters:
      login - The user login to remove
    • bot

      public Viewer bot()
      Returns the Viewer object representing the bot account
      Returns:
      The Viewer object representing the bot account
    • broadcaster

      public Viewer broadcaster()
      Returns the Viewer object representing the broadcaster account
      Returns:
      The Viewer object representing the broadcaster account
    • chatters

      public List<Viewer> chatters()
      Returns a list of Viewer objects representing users recently seen in chat
      Returns:
      A List of Viewer objects
    • activeChatters

      public List<Viewer> activeChatters()
      Returns a list of Viewer objects representing users recently seen in chat, who have sent a message in the past 5 minutes
      Returns:
      A List of Viewer objects
    • lookupLoginById

      public String lookupLoginById(String id)
      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

      public String lookupIdByLogin(String login)
      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