J
J
justslipknot2018-06-29 17:24:15
.NET
justslipknot, 2018-06-29 17:24:15

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

3 answer(s)
V
Vladislav, 2018-06-29
@Div100

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()

Here is a pseudo code for you, somehow you can do it. If you have any questions, write

P
Petr Vasiliev, 2018-06-29
@danial72

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.

S
Sergey Gornostaev, 2018-06-29
@sergey-gornostaev

Read about finite state machines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question