This commit is contained in:
Flummi 2017-11-24 09:17:22 +01:00
parent b5bbce6bd7
commit 2bf6cfae00
2 changed files with 17 additions and 13 deletions

View File

@ -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 };
export { maxoutput, sandbox, bfgen, hsimports };

View File

@ -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);
});
}
});