import { maxoutput, sandbox, bfgen } from "./lib/sandbox.js"; const vm = require("vm") , request = require("request"); module.exports = bot => { bot._trigger.set("sandbox_js", { call: /^\!js (.*)/i, level: 100, active: true, clients: ["irc", "tg"], f: e => { const args = e.message.substring(3); const context = { e: e, t: bot._trigger }; try { let output = vm.runInNewContext(args, context); if (typeof output !== undefined && output) { output = JSON.stringify(output); if (output !== "Converting circular structure to JSON") { e.reply(output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output); } } } catch (err) { e.reply(err.message); } } }); bot._trigger.set("sandbox", { call: /^\!(hs|py|cpp|bf|php|lua|bash) .*/i, level: 100, active: true, clients: ["irc", "tg"], f: e => { let args = e.message.trim().substring(1).split(" "); const lang = args.shift(); args = args.join(" "); sandbox(lang, args).then( resolve => e.reply(resolve), reject => e.reply(reject.replace("\n", " ")) ); } }); bot._trigger.set("sandbox_rs", { call: /^\!rs (.*)/i, level: 100, active: true, clients: ["irc", "tg"], f: e => { const args = e.message.substring(4); const params = { channel: "stable", code: "fn main() { " + args + " }", crateType: "bin", mode: "debug", tests: false }; const options = { url: "https://play.rust-lang.org/execute", method: "POST", body: params, json: true }; request(options, (err, res, 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!"); }); } }); bot._trigger.set("bfgen", { call: /^\!bfgen .*/i, level: 100, active: true, clients: ["irc", "tg"], f: e => { let args = e.message.trim().substring(7); let output = bfgen(args); e.reply(output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output); } }); };