Fix module runtime crash and add parameters

This commit is contained in:
Tanguy Herbron 2021-05-09 20:25:00 +02:00
parent 95781d7b0d
commit 4a0ebe2845

View File

@ -1,5 +1,15 @@
const execSync = require("child_process").execSync;
const RUNTIME_ERROR = {
status: "error",
message: "An error occured when running the command, please contact the administrator"
}
const UNSUPPORTED_RUNTIME = {
status: "error",
message: "Runtime not supported, check configuration"
}
class Module {
constructor(name, description, prefix, flavor, entrypoint, version) {
this.name = name;
@ -11,14 +21,19 @@ class Module {
}
run(message) {
console.log("Running module");
switch(this.flavor) {
case "node":
return execSync("node " + this.entrypoint);
let result = undefined;
try {
result = execSync("node " + this.entrypoint + " '" + message.content + "'");
} catch (exception) {
result = RUNTIME_ERROR;
}
return result;
break;
default:
return {"status": "error", "message": "Runtime not supported, check configuration"};
return UNSUPPORTED_RUNTIME;
break;
}
}