rp -> fetch (sandbox)
This commit is contained in:
parent
c302597c63
commit
56a078ec02
|
@ -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,13 +58,12 @@ 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 => {
|
||||
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)`)
|
||||
|
@ -78,10 +76,7 @@ const sandbox = (lang, code) => {
|
|||
if (body.Result.length === 0)
|
||||
return reject("lol keine Ausgabe");
|
||||
resolve(body.Result);
|
||||
})
|
||||
.catch(err => {
|
||||
reject("Error!");
|
||||
})
|
||||
}).catch(err => reject("Error!"));
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
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);
|
||||
});
|
||||
}).catch(err => e.reply(err));
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user