Class MessageContext

java.lang.Object
io.github.unknowncoder56.javaslc.MessageContext

public class MessageContext extends Object
A class to create a context object which contains details about the message like message content, owner (author), server ID, Bot instance, command name and command arguments.
  • Constructor Details

    • MessageContext

      public MessageContext(com.google.gson.JsonObject message, long serverId, Bot bot, String command)
      Constructor to create an instance of the class for a command without arguments.
      Parameters:
      message - The message JSON retrieved from the SLChat API.
      serverId - The ID of the server where the message was sent.
      bot - The Bot instance receiving the message event.
      command - The command name of the command issued by the user.
    • MessageContext

      public MessageContext(com.google.gson.JsonObject message, long serverId, Bot bot, String command, String[] arguments)
      Constructor to create an instance of the class for a command with arguments.
      Parameters:
      message - The message JSON retrieved from the SLChat API.
      serverId - The ID of the server where the message was sent.
      bot - The Bot instance receiving the message event.
      command - The command name of the command issued by the user.
      arguments - An array of the command arguments.
  • Method Details

    • send

      public CompletableFuture<Void> send(String message)
      This method sends a message to a server directly from where the command originated. This method will throw a RuntimeException if the bot is not in the server. To fix it add it to a server with Bot.join(long).
      Parameters:
      message - The message to send.
      Returns:
      A CompletableFuture that will be completed when the message is sent.
      See Also:
    • getContent

      public String getContent()
      Gets the message content.
      Returns:
      The message content.
    • getOwner

      public User getOwner()
      Gets the message owner.
      Returns:
      The User instance of the owner.
    • getServerId

      public long getServerId()
      Gets the server ID of the server where the message was sent.
      Returns:
      The server ID of the server where the message was sent.
    • getBot

      public Bot getBot()
      Gets the Bot which received the command.
      Returns:
      The Bot which received the command.
    • getCommand

      public String getCommand()
      Gets the command name of the command received.
      Returns:
      The command name of the command received.
    • getArguments

      public String[] getArguments()
      Gets the array of the arguments supplied with the command.
      Returns:
      The array of the arguments supplied with the command.