Currently src/index.ts has a big switch statement for known commands. This won't scale as additional commands are added and command requests could come from different sources (e.g. Facebook messenger bots, web interface, etc).
The pattern here should be that we define a Command interface that different commands can implement and provide a registry function to add that command to the CommandRegistry. The following is a very rough interface and example.
interface McCommand {
run(args: string[]): Promise<void>;
}
class EchoCommand implements McCommand {
constructor(bot: mineflayer.Bot, mcmanus: McManus) {
...
}
run(args: string[]): Promise<void> {
this.bot.chat(args.join(" "));
return new Promise();
}
}
registryCommand(EchoCommand);
We should support dependency injection so the right dependencies get passed to the constructor of the commands and we can support per command configs, client interfaces such as a sqlite connection, etc.
Currently
src/index.tshas a big switch statement for known commands. This won't scale as additional commands are added and command requests could come from different sources (e.g. Facebook messenger bots, web interface, etc).The pattern here should be that we define a
Commandinterface that different commands can implement and provide a registry function to add that command to theCommandRegistry. The following is a very rough interface and example.We should support dependency injection so the right dependencies get passed to the constructor of the commands and we can support per command configs, client interfaces such as a sqlite connection, etc.