Class Context


  • public class Context
    extends Object
    • Constructor Detail

      • Context

        public Context​(Command originalCommand,
                       discord4j.core.event.domain.message.MessageCreateEvent event,
                       List<String> args,
                       Bot bot,
                       String prefixUsed)
    • Method Detail

      • getCommand

        public Command getCommand()
        Gets the command that created this context.
        Returns:
        the original command
      • getEvent

        public discord4j.core.event.domain.message.MessageCreateEvent getEvent()
        Gets the message create event associated to this command.
        Returns:
        the event
      • getArgs

        public List<String> getArgs()
        Gets the arguments of the command.
        Returns:
        the args
      • getBot

        public Bot getBot()
        Gets the bot instance.
        Returns:
        the bot
      • reply

        public reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply​(String message)
        Sends a message in the same channel the command was sent.
        Parameters:
        message - the message content of the reply
        Returns:
        a Mono emitting the message sent
      • reply

        public reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply​(java.util.function.Consumer<? super discord4j.core.spec.MessageCreateSpec> spec)
        Sends a message in the same channel the command was sent. This method supports advanced message construction.
        Parameters:
        spec - the message content of the reply
        Returns:
        a Mono emitting the message sent
      • getPrefixUsed

        public String getPrefixUsed()
        Gets the prefix used in the command that created this context.
        Returns:
        the prefix used
      • setVar

        public void setVar​(String name,
                           Object val)
        Adds a variable in this context. If a variable of the same name exists, it is overwritten.
        Parameters:
        name - the name of the variable
        val - the value of the variable
      • setVarIfNotExists

        public void setVarIfNotExists​(String name,
                                      Object val)
        Adds a variable in this context. If a variable of the same name exists, nothing happens.
        Parameters:
        name - the name of the variable
        val - the value of the variable
      • getVar

        public <T> T getVar​(String name,
                            Class<T> type)
        Gets the value of a variable.
        Type Parameters:
        T - the variable type
        Parameters:
        name - the variable name
        type - the type of the variable
        Returns:
        the value of the variable, or null if not found or exists in the wrong type
      • getVarOrDefault

        public <T> T getVarOrDefault​(String name,
                                     T defaultVal)
        Gets the value of a variable. If not found, the provided default value is returned instead.
        Type Parameters:
        T - the variable type
        Parameters:
        name - the variable name
        defaultVal - the default value to return if not found
        Returns:
        the value of the variable, or the default value if not found or exists in the wrong type
      • getGuildSettings

        public reactor.core.publisher.Mono<Map<Plugin,​Map<String,​String>>> getGuildSettings()
        Gets the guild settings
        Returns:
        an unmodifiable Map containing the guild settings keys and their associated values, grouped by plugins
      • setGuildSetting

        public reactor.core.publisher.Mono<Void> setGuildSetting​(String key,
                                                                 String val)
        Edits an entry of the guild settings.
        Parameters:
        key - the setting key
        val - the setting value
        Returns:
        a Mono that completes when successfully updated
        Throws:
        NoSuchElementException - if no entry is found for the given key
        IllegalArgumentException - if the given value is not accepted by the entry
        UnsupportedOperationException - if this method is called in a context that is outside of a Discord guild