From 56a078ec0299f85c7c59448f68eeff9c6dddc3b4 Mon Sep 17 00:00:00 2001 From: Flummi Date: Fri, 14 Sep 2018 21:44:33 +0200 Subject: [PATCH] rp -> fetch (sandbox) --- src/inc/trigger/lib/sandbox.mjs | 43 +++++++++++++++------------------ src/inc/trigger/sandbox.mjs | 17 ++++++------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/inc/trigger/lib/sandbox.mjs b/src/inc/trigger/lib/sandbox.mjs index d5c8f77..1e0b7c7 100644 --- a/src/inc/trigger/lib/sandbox.mjs +++ b/src/inc/trigger/lib/sandbox.mjs @@ -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!")); }); }; diff --git a/src/inc/trigger/sandbox.mjs b/src/inc/trigger/sandbox.mjs index 53d205c..fdeb67b 100644 --- a/src/inc/trigger/sandbox.mjs +++ b/src/inc/trigger/sandbox.mjs @@ -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)); } }));