Package io.github.unknowncoder56.javaslc
Class MessageContext
java.lang.Object
io.github.unknowncoder56.javaslc.MessageContext
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 Summary
ConstructorsConstructorDescriptionMessageContext(com.google.gson.JsonObject message, long serverId, Bot bot, String command) Constructor to create an instance of the class for a command without arguments.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. -
Method Summary
Modifier and TypeMethodDescriptionString[]Gets the array of the arguments supplied with the command.getBot()Gets theBotwhich received the command.Gets the command name of the command received.Gets the message content.getOwner()Gets the message owner.longGets the server ID of the server where the message was sent.This method sends a message to a server directly from where the command originated.
-
Constructor Details
-
MessageContext
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- TheBotinstance 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- TheBotinstance 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
This method sends a message to a server directly from where the command originated. This method will throw aRuntimeExceptionif the bot is not in the server. To fix it add it to a server withBot.join(long).- Parameters:
message- The message to send.- Returns:
- A
CompletableFuturethat will be completed when the message is sent. - See Also:
-
getContent
Gets the message content.- Returns:
- The message content.
-
getOwner
Gets the message owner.- Returns:
- The
Userinstance 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
Gets theBotwhich received the command.- Returns:
- The
Botwhich received the command.
-
getCommand
Gets the command name of the command received.- Returns:
- The command name of the command received.
-
getArguments
Gets the array of the arguments supplied with the command.- Returns:
- The array of the arguments supplied with the command.
-