Class CommandKernel

java.lang.Object
com.github.alex1304.ultimategdbot.api.CommandKernel

public class CommandKernel
extends Object
The command kernel 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 the to the proper command providers to trigger the execution of commands.
  • Constructor Details

  • Method Details

    • 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.
    • start

      public void start()
    • getCommandByAlias

      public 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, or null if not found
    • getBlacklist

      public Set<Long> getBlacklist()
      Gets an unmodifiable set of IDs that are not allowed to perform operations on the command kernel.
      Returns:
      an unmodifiable set of IDs
    • 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.
    • invalidateCachedPrefixForGuild

      public void invalidateCachedPrefixForGuild​(long guildId)
      Forces this command kernel to evict the prefix from cache for the specified guild.
      Parameters:
      guildId - the guild id