From 2bf6cfae0020ed4d7662fcc5d733582d01ae31f1 Mon Sep 17 00:00:00 2001 From: Flummi Date: Fri, 24 Nov 2017 09:17:22 +0100 Subject: [PATCH] fix hs --- src/inc/trigger/lib/sandbox.js | 18 +++++++++--------- src/inc/trigger/sandbox.js | 12 ++++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/inc/trigger/lib/sandbox.js b/src/inc/trigger/lib/sandbox.js index af39405..cf19a0d 100644 --- a/src/inc/trigger/lib/sandbox.js +++ b/src/inc/trigger/lib/sandbox.js @@ -1,4 +1,4 @@ -const request = require("request") +const rp = require("request-promise") , fs = require("fs"); const maxoutput = 500; @@ -13,7 +13,6 @@ const hsimports = [ ].map(imp => { return `import qualified ${imp}`; }).join("\r\n"); function sandbox(lang, code) { - console.log(`${ __dirname }/../../../../neofetch`); const langs = { cpp: { "LanguageChoice": "7", @@ -23,13 +22,13 @@ function sandbox(lang, code) { }, hs: { "LanguageChoice": "11", - "Program": `${hsimports}\r\nmain = print(${code})`, + "Program": `${hsimports}\r\nmain = ${code}`, "Input": "", "CompilerArgs": "-XUnicodeSyntax -XPartialTypeSignatures -o a.out source_file.hs" }, py: { "LanguageChoice": "24", - "Program": "print(" + code + ")", + "Program": code, "Input": "", "CompilerArgs": "-o a.out source_file.hs" }, @@ -67,9 +66,7 @@ function sandbox(lang, code) { json: true }; - request(options, (err, res, body) => { - if (err) - return reject("Error!"); + rp(options).then(body => { if (body.Errors) { if (body.Errors.length > maxoutput) return reject(`holy fuck, Error wäre viel zu lang! (${body.Errors.length} Zeichen :DDDDDD)`) @@ -82,7 +79,10 @@ function sandbox(lang, code) { if (body.Result.length === 0) return reject("lol keine Ausgabe"); resolve(body.Result); - }); + }) + .catch(err => { + reject("Error!"); + }) }); } @@ -98,4 +98,4 @@ function bfgen(text) { return out; } -export { maxoutput, sandbox, bfgen }; \ No newline at end of file +export { maxoutput, sandbox, bfgen, hsimports }; \ No newline at end of file diff --git a/src/inc/trigger/sandbox.js b/src/inc/trigger/sandbox.js index 8b1c062..bf7a714 100644 --- a/src/inc/trigger/sandbox.js +++ b/src/inc/trigger/sandbox.js @@ -1,7 +1,7 @@ -import { maxoutput, sandbox, bfgen } from "./lib/sandbox.js"; +import { maxoutput, sandbox, bfgen, hsimports } from "./lib/sandbox.js"; const vm = require("vm") - , request = require("request"); + , rp = require("request-promise"); module.exports = bot => { bot._trigger.set("sandbox_js", { @@ -13,7 +13,8 @@ module.exports = bot => { const args = e.message.substring(3); const context = { e: e, - t: bot._trigger + t: bot._trigger, + hsimports: hsimports, }; try { let output = vm.runInNewContext(args, context); @@ -68,8 +69,11 @@ module.exports = bot => { json: true }; - request(options, (err, res, body) => { + rp(options).then(body => { e.reply(body.success ? (body.stdout.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${body.stdout.length} Zeichen :DDDDDD)` : body.stdout) : "error!"); + }) + .catch(err => { + e.reply(err); }); } });