Class CommandRegistry
Object
CommandRegistry
- All Implemented Interfaces:
ICommandRegistry
This class manages all the commands for a bot. You can register and deregister commands on demand
- Author:
- Timo Schulz (Mit0x2)
-
Constructor Summary
ConstructorsConstructorDescriptionCommandRegistry(TelegramClient telegramClient, boolean allowCommandsWithUsername, Supplier<String> botUsernameSupplier) Creates a Command registry -
Method Summary
Modifier and TypeMethodDescriptionbooleanderegister(IBotCommand botCommand) deregister a commandderegisterAll(IBotCommand... botCommands) deregister multiple commandsbooleanexecuteCommand(Message message) Executes a command action if the command is registered.getRegisteredCommand(String commandIdentifier) get registered commandget a collection of all registered commandsbooleanregister(IBotCommand botCommand) register a commandregisterAll(IBotCommand... botCommands) register multiple commandsvoidregisterDefaultAction(BiConsumer<TelegramClient, Message> defaultConsumer) Register a default action when there is no command register that match the message sent
-
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 otherwisebotUsernameSupplier- Bot username supplier
-
-
Method Details
-
registerDefaultAction
Description copied from interface:ICommandRegistryRegister a default action when there is no command register that match the message sent- Specified by:
registerDefaultActionin interfaceICommandRegistry- Parameters:
defaultConsumer- Consumer to evaluate the message
-
register
Description copied from interface:ICommandRegistryregister a command- Specified by:
registerin interfaceICommandRegistry- Parameters:
botCommand- the command to register- Returns:
- whether the command could be registered, was not already registered
-
registerAll
Description copied from interface:ICommandRegistryregister multiple commands- Specified by:
registerAllin interfaceICommandRegistry- Parameters:
botCommands- commands to register- Returns:
- map with results of the command register per command
-
deregister
Description copied from interface:ICommandRegistryderegister a command- Specified by:
deregisterin interfaceICommandRegistry- Parameters:
botCommand- the command to deregister- Returns:
- whether the command could be deregistered, was registered
-
deregisterAll
Description copied from interface:ICommandRegistryderegister multiple commands- Specified by:
deregisterAllin interfaceICommandRegistry- Parameters:
botCommands- commands to deregister- Returns:
- map with results of the command deregistered per command
-
getRegisteredCommands
Description copied from interface:ICommandRegistryget a collection of all registered commands- Specified by:
getRegisteredCommandsin interfaceICommandRegistry- Returns:
- a collection of registered commands
-
getRegisteredCommand
Description copied from interface:ICommandRegistryget registered command- Specified by:
getRegisteredCommandin interfaceICommandRegistry- 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
-