Class Context


  • public class Context
    extends Object
    • Constructor Detail

      • Context

        public Context​(Command command,
                       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

        @Deprecated
        public reactor.core.publisher.Mono<Map<Plugin,​Map<String,​String>>> getGuildSettings()
        Deprecated.
        This method returns the values as strings, for view only. It doesnt allow retrieving the raw values, so it isn't relevant to have this method in the Context object. Also, it makes one different database transaction for each guild setting, so there are performance issues as well.
        Gets the guild settings
        Returns:
        an unmodifiable Map containing the guild settings keys and their associated values, grouped by plugins
      • setGuildSetting

        @Deprecated
        public reactor.core.publisher.Mono<Void> setGuildSetting​(String key,
                                                                 String val)
        Deprecated.
        This method only supports setting new values from their string conversion. It doesn't allow a lot of flexibility, and it isn't relevant to have a such method in the Context object to begin with. The recommended way to change a guild setting is by iterating through all plugins (Bot#getPlugins), checking for each plugin if key exists, and using the appropriate value setter on the found entry.
        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