Answer the question
In order to leave comments, you need to log in
Handling chatbot commands?
I'm scratching my head on how to handle chatbot commands. The easiest and probably dumbest way is if ( message == "any_command") // code. Or the same but with the help of switch. But with the growth of the number of teams, it looks terrible. Also, the first approach has a problem with processing arguments (command arg1 arg2 arg3 ... ) Maybe there are some other ways?
Answer the question
In order to leave comments, you need to log in
interface ICommand {
execute();
}
Command1 implements ICommand {
execute() {
//command1 job
};
}
Command2 implements ICommand {
execute() {
//command2 job
};
}
//далее делаешь комманд фактори, который будет возвращать по интерфейсу ICommand и //вызывать у них execute
//в самой CommandFactory можешь использовать CommandRegistry, в которой будут
//храниться все существующие команды и оттуда просто
//CommandRegistry.get(commandName). В registry можешь в Map<String, ICommand> хранить
CommandFactory.get(commandName).execute()
I'm not sure that this is possible on Sharp, but you can make an array where the key is the command, and the value is a pointer to the function.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question