Catch unknown command error

This commit is contained in:
Tanguy Herbron 2021-05-09 01:40:54 +02:00
parent 7ff8707520
commit a4bf401f32
2 changed files with 15 additions and 1 deletions

View File

@ -24,4 +24,5 @@ let reply = {
}
}
};
console.log(JSON.stringify(reply));

View File

@ -1,6 +1,11 @@
const fs = require("fs");
const Module = require("./module");
const UNKNOWN_MESSAGE = {
format: "standard",
message: "Unkown command"
}
class ModuleManager {
constructor() {
console.log("Creating module manager");
@ -24,7 +29,15 @@ class ModuleManager {
}
execute(prefix, message) {
let rawResult = this.moduleList[prefix].run(message);
let module = this.moduleList[prefix];
if(module === undefined) {
this.reply(message, UNKNOWN_MESSAGE);
return;
}
let rawResult = module.run(message);
let result = JSON.parse(rawResult.toString());
if(result.status === "success") {