diff --git a/src/module.js b/src/module.js index 9c26cee..efa7e66 100644 --- a/src/module.js +++ b/src/module.js @@ -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; } }