rp -> fetch (sandbox)

This commit is contained in:
Flummi 2018-09-14 21:44:33 +02:00
parent c302597c63
commit 56a078ec02
2 changed files with 26 additions and 34 deletions

View File

@ -1,7 +1,6 @@
import rp from "request-promise-native";
import fetch from "../../fetch";
const maxoutput = 500;
const hsimports = [
"Control.Applicative", "Control.Arrow", "Control.Monad",
"Control.Monad.Zip", "Data.Bits", "Data.Bool", "Data.Char",
@ -9,7 +8,7 @@ const hsimports = [
"Data.Foldable", "Data.Function", "Data.Functor",
"Data.Int", "Data.List", "Data.Maybe", "Data.Monoid", "Data.Map",
"Data.Ord", "Data.Set", "Data.String", "Data.Tuple", "Data.Word"
].map(imp => { return `import qualified ${imp}`; }).join("\r\n");
].map(imp => `import qualified ${imp}`).join("\r\n");
const sandbox = (lang, code) => {
const langs = {
@ -59,29 +58,25 @@ const sandbox = (lang, code) => {
return new Promise((resolve, reject) => {
const options = {
url: "http://rextester.com/rundotnet/api",
method: "POST",
body: langs[lang],
json: true
body: langs[lang]
};
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)`)
return reject(body.Errors);
}
if (body.Result === null)
return reject("Keine Ausgabe :(");
if (body.Result.length > maxoutput)
return reject(`holy fuck, Ausgabe wäre viel zu lang! (${body.Result.length} Zeichen :DDDDDD)`);
if (body.Result.length === 0)
return reject("lol keine Ausgabe");
resolve(body.Result);
})
.catch(err => {
reject("Error!");
})
fetch("http://rextester.com/rundotnet/api", options)
.then(res => res.json())
.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)`)
return reject(body.Errors);
}
if (body.Result === null)
return reject("Keine Ausgabe :(");
if (body.Result.length > maxoutput)
return reject(`holy fuck, Ausgabe wäre viel zu lang! (${body.Result.length} Zeichen :DDDDDD)`);
if (body.Result.length === 0)
return reject("lol keine Ausgabe");
resolve(body.Result);
}).catch(err => reject("Error!"));
});
};

View File

@ -2,7 +2,7 @@ import sql from "../sql";
import { maxoutput, sandbox, bfgen } from "./lib/sandbox";
import vm from "vm";
import rp from "request-promise";
import fetch from "../fetch";
import stringify from "stringify-object";
let _contexts = new Map();
@ -78,18 +78,15 @@ export default bot => {
tests: false
};
const options = {
url: "https://play.rust-lang.org/execute",
method: "POST",
body: params,
json: true
body: params
};
rp(options).then(body => {
e.reply(e.user.nick + ": " + 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);
});
fetch("https://play.rust-lang.org/execute", options)
.then(res => res.json())
.then(body => {
e.reply(e.user.nick + ": " + 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));
}
}));