Class Game

  • Direct Known Subclasses:
    RichPresence

    public class Game
    extends java.lang.Object
    Represents a Discord Game.
    This should contain all information provided from Discord about a Game.
    Since:
    2.1
    Author:
    John A. Grosh
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Game.GameType
      The type game being played, differentiating between a game and stream types.
    • Method Detail

      • getName

        public java.lang.String getName()
        The displayed name of the Game. If no name has been set, this returns null.
        Returns:
        Possibly-null String containing the Game's name.
      • getUrl

        public java.lang.String getUrl()
        The URL of the Game if the game is actually a Stream.
        This will return null for regular games.
        Returns:
        Possibly-null String containing the Game's URL.
      • getTimestamps

        @Nullable
        public RichPresence.Timestamps getTimestamps()
        Information on the match duration, start, and end.
        Returns:
        Timestamps wrapper of null if unset
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • playing

        public static Game playing​(java.lang.String name)
        Creates a new Game instance with the specified name.
        In order to appear as "streaming" in the official client you must provide a valid (see documentation of method) streaming URL in Game.streaming(String, String).
        Parameters:
        name - The not-null name of the newly created game
        Returns:
        A valid Game instance with the provided name with Game.GameType.DEFAULT
        Throws:
        java.lang.IllegalArgumentException - if the specified name is null, empty or blank
      • streaming

        public static Game streaming​(java.lang.String name,
                                     java.lang.String url)
        Creates a new Game instance with the specified name and url.
        The specified URL must be valid according to discord standards in order to display as "streaming" in the official client. A valid streaming URL must be derived from https://twitch.tv/ and can be verified using isValidStreamingUrl(String). (see documentation)
        Parameters:
        name - The not-null name of the newly created game
        url - The streaming url to use, required to display as "streaming"
        Returns:
        A valid Game instance with the provided name and url
        Throws:
        java.lang.IllegalArgumentException - If the specified name is null or empty
        See Also:
        isValidStreamingUrl(String)
      • listening

        public static Game listening​(java.lang.String name)
        Creates a new Game instance with the specified name.
        This will display as Listening name in the official client
        Parameters:
        name - The not-null name of the newly created game
        Returns:
        A valid Game instance with the provided name with Game.GameType.LISTENING
        Throws:
        java.lang.IllegalArgumentException - if the specified name is null, empty or blank
      • watching

        @Incubating
        public static Game watching​(java.lang.String name)
        Creates a new Game instance with the specified name.
        This will display as Watching name in the official client
        Parameters:
        name - The not-null name of the newly created game
        Returns:
        A valid Game instance with the provided name with Game.GameType.WATCHING
        Throws:
        java.lang.IllegalArgumentException - if the specified name is null, empty or blank
        Incubating:
        This feature is not yet confirmed for the official bot API
      • of

        public static Game of​(Game.GameType type,
                              java.lang.String name)
        Creates a new Game instance with the specified name and url.
        Parameters:
        type - The GameType to use
        name - The not-null name of the newly created game
        Returns:
        A valid Game instance with the provided name and url
        Throws:
        java.lang.IllegalArgumentException - If the specified name is null or empty
      • of

        public static Game of​(Game.GameType type,
                              java.lang.String name,
                              java.lang.String url)
        Creates a new Game instance with the specified name and url.
        The provided url would only be used for GameType.STREAMING and should be a twitch url.
        Parameters:
        type - The GameType to use
        name - The not-null name of the newly created game
        url - The streaming url to use, required to display as "streaming".
        Returns:
        A valid Game instance with the provided name and url
        Throws:
        java.lang.IllegalArgumentException - If the specified name is null or empty
        See Also:
        isValidStreamingUrl(String)
      • isValidStreamingUrl

        public static boolean isValidStreamingUrl​(java.lang.String url)
        Checks if a given String is a valid Twitch url (ie, one that will display "Streaming" on the Discord client).
        Parameters:
        url - The url to check.
        Returns:
        True if the provided url is valid for triggering Discord's streaming status