From 4a0ebe28455730a86a1f0fc06f308b8f97118dbd Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 9 May 2021 20:25:00 +0200 Subject: [PATCH] Fix module runtime crash and add parameters --- src/module.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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; } }