Class CommandProvider

java.lang.Object
com.github.alex1304.ultimategdbot.api.command.CommandProvider
Direct Known Subclasses:
AnnotatedCommandProvider

public class CommandProvider
extends java.lang.Object
Provides a set of commands. Each command handler provides their own way to handle errors via a CommandErrorHandler.
  • Constructor Summary

    Constructors 
    Constructor Description
    CommandProvider()  
  • Method Summary

    Modifier and Type Method Description
    void add​(Command command)
    Adds a command to this provider.
    Command getCommandByAlias​(java.lang.String alias)
    Gets a command instance corresponding to the given alias.
    CommandErrorHandler getErrorHandler()
    Gets the error handler assigned to this provider.
    java.util.Set<Command> getProvidedCommands()
    Gets all provided commands.
    java.util.Optional<ExecutableCommand> provideFromEvent​(Bot bot, java.lang.String prefix, discord4j.core.event.domain.message.MessageCreateEvent event, discord4j.core.object.entity.MessageChannel channel)
    Provides a command based on a MessageCreateEvent.
    void setErrorHandler​(CommandErrorHandler errorHandler)
    Allows to supply a custom command handler.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • setErrorHandler

      public void setErrorHandler​(CommandErrorHandler errorHandler)
      Allows to supply a custom command handler. If this method is not called, it will use a default handler.
      Parameters:
      errorHandler - the error handler to set
    • add

      public void add​(Command command)
      Adds a command to this provider.
      Parameters:
      command - the command to add
    • provideFromEvent

      public java.util.Optional<ExecutableCommand> provideFromEvent​(Bot bot, java.lang.String prefix, discord4j.core.event.domain.message.MessageCreateEvent event, discord4j.core.object.entity.MessageChannel channel)
      Provides a command based on a MessageCreateEvent. The event must come with a message body containing a prefix and the alias of one of the commands provided by this provider. If it matches with a provided command, arguments and flags are parsed, and everything is wrapped in an ExecutableCommand which is returned. If the event does not match with any command, an empty Optional is returned.
      Parameters:
      bot - the bot instance
      prefix - the guild-specific bot prefix
      event - the MessageCreateEvent to process
      channel - the channel where the event happened
      Returns:
      an ExecutableCommand if the event results in a command to be triggered, an empty Optional otherwise.
    • getErrorHandler

      public CommandErrorHandler getErrorHandler()
      Gets the error handler assigned to this provider.
      Returns:
      the error handler
    • getCommandByAlias

      public Command getCommandByAlias​(java.lang.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
    • getProvidedCommands

      public java.util.Set<Command> getProvidedCommands()
      Gets all provided commands.
      Returns:
      an unmodifiable Set containing all commands provided by this provider
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object