Object
CommandRegistry
All Implemented Interfaces:
ICommandRegistry

public final class CommandRegistry extends Object implements ICommandRegistry
This class manages all the commands for a bot. You can register and deregister commands on demand
Author:
Timo Schulz (Mit0x2)
  • Constructor Details

    • CommandRegistry

      public CommandRegistry(TelegramClient telegramClient, boolean allowCommandsWithUsername, Supplier<String> botUsernameSupplier)
      Creates a Command registry
      Parameters:
      allowCommandsWithUsername - True to allow commands with username, false otherwise
      botUsernameSupplier - Bot username supplier
  • Method Details

    • registerDefaultAction

      public void registerDefaultAction(BiConsumer<TelegramClient,Message> defaultConsumer)
      Description copied from interface: ICommandRegistry
      Register a default action when there is no command register that match the message sent
      Specified by:
      registerDefaultAction in interface ICommandRegistry
      Parameters:
      defaultConsumer - Consumer to evaluate the message
    • register

      public boolean register(IBotCommand botCommand)
      Description copied from interface: ICommandRegistry
      register a command
      Specified by:
      register in interface ICommandRegistry
      Parameters:
      botCommand - the command to register
      Returns:
      whether the command could be registered, was not already registered
    • registerAll

      public Map<IBotCommand,Boolean> registerAll(IBotCommand... botCommands)
      Description copied from interface: ICommandRegistry
      register multiple commands
      Specified by:
      registerAll in interface ICommandRegistry
      Parameters:
      botCommands - commands to register
      Returns:
      map with results of the command register per command
    • deregister

      public boolean deregister(IBotCommand botCommand)
      Description copied from interface: ICommandRegistry
      deregister a command
      Specified by:
      deregister in interface ICommandRegistry
      Parameters:
      botCommand - the command to deregister
      Returns:
      whether the command could be deregistered, was registered
    • deregisterAll

      public Map<IBotCommand,Boolean> deregisterAll(IBotCommand... botCommands)
      Description copied from interface: ICommandRegistry
      deregister multiple commands
      Specified by:
      deregisterAll in interface ICommandRegistry
      Parameters:
      botCommands - commands to deregister
      Returns:
      map with results of the command deregistered per command
    • getRegisteredCommands

      public Collection<IBotCommand> getRegisteredCommands()
      Description copied from interface: ICommandRegistry
      get a collection of all registered commands
      Specified by:
      getRegisteredCommands in interface ICommandRegistry
      Returns:
      a collection of registered commands
    • getRegisteredCommand

      public IBotCommand getRegisteredCommand(String commandIdentifier)
      Description copied from interface: ICommandRegistry
      get registered command
      Specified by:
      getRegisteredCommand in interface ICommandRegistry
      Returns:
      registered command if exists or null if not
    • executeCommand

      public boolean executeCommand(Message message)
      Executes a command action if the command is registered.
      Parameters:
      message - input message
      Returns:
      True if a command or default action is executed, false otherwise