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 maxoutput = 500;
const hsimports = [ const hsimports = [
"Control.Applicative", "Control.Arrow", "Control.Monad", "Control.Applicative", "Control.Arrow", "Control.Monad",
"Control.Monad.Zip", "Data.Bits", "Data.Bool", "Data.Char", "Control.Monad.Zip", "Data.Bits", "Data.Bool", "Data.Char",
@ -9,7 +8,7 @@ const hsimports = [
"Data.Foldable", "Data.Function", "Data.Functor", "Data.Foldable", "Data.Function", "Data.Functor",
"Data.Int", "Data.List", "Data.Maybe", "Data.Monoid", "Data.Map", "Data.Int", "Data.List", "Data.Maybe", "Data.Monoid", "Data.Map",
"Data.Ord", "Data.Set", "Data.String", "Data.Tuple", "Data.Word" "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 sandbox = (lang, code) => {
const langs = { const langs = {
@ -59,13 +58,12 @@ const sandbox = (lang, code) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const options = { const options = {
url: "http://rextester.com/rundotnet/api",
method: "POST", method: "POST",
body: langs[lang], body: langs[lang]
json: true
}; };
fetch("http://rextester.com/rundotnet/api", options)
rp(options).then(body => { .then(res => res.json())
.then(body => {
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)`)
@ -78,10 +76,7 @@ const 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!"));
.catch(err => {
reject("Error!");
})
}); });
}; };

View File

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