Class CommandService


  • public final class CommandService
    extends Object
    The command service coordinates the command providers from all plugins. It also holds a blacklist to restrict the usage of commands from certain guilds, channels or users. It listens to message create events and dispatch them to the proper command providers to trigger the execution of commands.
    • Method Detail

      • addProvider

        public void addProvider​(CommandProvider provider)
        Adds a new command provider to this kernel.
        Parameters:
        provider - the command provider to add
      • processEvent

        public reactor.core.publisher.Mono<Void> processEvent​(discord4j.core.event.domain.message.MessageCreateEvent event)
        Processes a MessageCreateEvent. It first checks if neither the guild, the channel and the user is blacklisted, then proceeds to find the guild-specific prefix and trigger the command if it matches with one provided by one of the command providers.
        Parameters:
        event - the MessageCreateEvent that was received
        Returns:
        a Mono that completes when the command has terminated. If the blacklist check doesn't pass, a Mono completing immediately is returned. Any errors that may occur when running the command are forwarded through this Mono.
      • getCommandByAlias

        public Optional<Command> getCommandByAlias​(String alias)
        Gets a command instance corresponding to the given alias.
        Parameters:
        alias - the alias of the command
        Returns:
        the corresponding command instance, if present
      • getPermissionChecker

        public PermissionChecker getPermissionChecker()
        Gets the permission checker used to check permissions for commands provided by this kernel.
        Returns:
        the permission checker
      • blacklist

        public void blacklist​(long id)
        Blacklists a new ID.
        Parameters:
        id - the ID of a user, a channel or a guild that won't be allowed to run commands from this kernel.
      • unblacklist

        public void unblacklist​(long id)
        Removes an ID from the blacklist.
        Parameters:
        id - the ID of a user, a channel or a guild that will be allowed to run commands from this kernel again.
      • setPrefixForGuild

        public void setPrefixForGuild​(long guildId,
                                      @Nullable
                                      String prefix)
        Sets a prefix specific for the given guild. If one was already set for the same guild, it is overwritten.
        Parameters:
        guildId - the guild id
        prefix - the new prefix. May be null, in which case the prefix is removed.
      • getCommandProviders

        public Set<CommandProvider> getCommandProviders()
        Gets an immutable view of the command providers added to the service.
        Returns:
        the command providers
      • getCommandPrefix

        public String getCommandPrefix()
      • getFlagPrefix

        public String getFlagPrefix()