fix hs
This commit is contained in:
parent
b5bbce6bd7
commit
2bf6cfae00
|
@ -1,4 +1,4 @@
|
||||||
const request = require("request")
|
const rp = require("request-promise")
|
||||||
, fs = require("fs");
|
, fs = require("fs");
|
||||||
|
|
||||||
const maxoutput = 500;
|
const maxoutput = 500;
|
||||||
|
@ -13,7 +13,6 @@ const hsimports = [
|
||||||
].map(imp => { return `import qualified ${imp}`; }).join("\r\n");
|
].map(imp => { return `import qualified ${imp}`; }).join("\r\n");
|
||||||
|
|
||||||
function sandbox(lang, code) {
|
function sandbox(lang, code) {
|
||||||
console.log(`${ __dirname }/../../../../neofetch`);
|
|
||||||
const langs = {
|
const langs = {
|
||||||
cpp: {
|
cpp: {
|
||||||
"LanguageChoice": "7",
|
"LanguageChoice": "7",
|
||||||
|
@ -23,13 +22,13 @@ function sandbox(lang, code) {
|
||||||
},
|
},
|
||||||
hs: {
|
hs: {
|
||||||
"LanguageChoice": "11",
|
"LanguageChoice": "11",
|
||||||
"Program": `${hsimports}\r\nmain = print(${code})`,
|
"Program": `${hsimports}\r\nmain = ${code}`,
|
||||||
"Input": "",
|
"Input": "",
|
||||||
"CompilerArgs": "-XUnicodeSyntax -XPartialTypeSignatures -o a.out source_file.hs"
|
"CompilerArgs": "-XUnicodeSyntax -XPartialTypeSignatures -o a.out source_file.hs"
|
||||||
},
|
},
|
||||||
py: {
|
py: {
|
||||||
"LanguageChoice": "24",
|
"LanguageChoice": "24",
|
||||||
"Program": "print(" + code + ")",
|
"Program": code,
|
||||||
"Input": "",
|
"Input": "",
|
||||||
"CompilerArgs": "-o a.out source_file.hs"
|
"CompilerArgs": "-o a.out source_file.hs"
|
||||||
},
|
},
|
||||||
|
@ -67,9 +66,7 @@ function sandbox(lang, code) {
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, (err, res, body) => {
|
rp(options).then(body => {
|
||||||
if (err)
|
|
||||||
return reject("Error!");
|
|
||||||
if (body.Errors) {
|
if (body.Errors) {
|
||||||
if (body.Errors.length > maxoutput)
|
if (body.Errors.length > maxoutput)
|
||||||
return reject(`holy fuck, Error wäre viel zu lang! (${body.Errors.length} Zeichen :DDDDDD)`)
|
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)
|
if (body.Result.length === 0)
|
||||||
return reject("lol keine Ausgabe");
|
return reject("lol keine Ausgabe");
|
||||||
resolve(body.Result);
|
resolve(body.Result);
|
||||||
});
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject("Error!");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,4 +98,4 @@ function bfgen(text) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { maxoutput, sandbox, bfgen };
|
export { maxoutput, sandbox, bfgen, hsimports };
|
|
@ -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")
|
const vm = require("vm")
|
||||||
, request = require("request");
|
, rp = require("request-promise");
|
||||||
|
|
||||||
module.exports = bot => {
|
module.exports = bot => {
|
||||||
bot._trigger.set("sandbox_js", {
|
bot._trigger.set("sandbox_js", {
|
||||||
|
@ -13,7 +13,8 @@ module.exports = bot => {
|
||||||
const args = e.message.substring(3);
|
const args = e.message.substring(3);
|
||||||
const context = {
|
const context = {
|
||||||
e: e,
|
e: e,
|
||||||
t: bot._trigger
|
t: bot._trigger,
|
||||||
|
hsimports: hsimports,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
let output = vm.runInNewContext(args, context);
|
let output = vm.runInNewContext(args, context);
|
||||||
|
@ -68,8 +69,11 @@ module.exports = bot => {
|
||||||
json: true
|
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!");
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user