sandboxes
This commit is contained in:
@ -1,7 +1,13 @@
|
||||
const vm = require("vm");
|
||||
const vm = require("vm")
|
||||
, http = require("http")
|
||||
, https = require("https")
|
||||
, request = require("request")
|
||||
, querystring = require("querystring");
|
||||
|
||||
const maxoutput = 400;
|
||||
|
||||
module.exports = bot => {
|
||||
bot._trigger.set("sandbox", {
|
||||
bot._trigger.set("sandbox_js", {
|
||||
call: /^\!js (.*)/i,
|
||||
level: 100,
|
||||
active: true,
|
||||
@ -16,7 +22,7 @@ module.exports = bot => {
|
||||
if (typeof output !== undefined && output) {
|
||||
output = JSON.stringify(output);
|
||||
if (output !== "Converting circular structure to JSON") {
|
||||
e.reply(output.length > 400 ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output);
|
||||
e.reply(output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,4 +31,107 @@ module.exports = bot => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bot._trigger.set("sandbox_hs", {
|
||||
call: /^\!hs (.*)/i,
|
||||
level: 100,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const args = e.message.substring(4);
|
||||
const params = querystring.stringify({
|
||||
"LanguageChoice": "11",
|
||||
"Program": "main = " + args,
|
||||
"Input": "",
|
||||
"CompilerArgs": "-o a.out source_file.hs"
|
||||
});
|
||||
const options = {
|
||||
hostname: "rextester.com",
|
||||
port: 80,
|
||||
path: "/rundotnet/api",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Content-Length": Buffer.byteLength(params)
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(options, res => {
|
||||
let content = "";
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => content += chunk.toString());
|
||||
res.on('end', () => {
|
||||
content = JSON.parse(content);
|
||||
e.reply(content.Errors ? content.Errors : (content.Result.length > maxoutput) ? `holy fuck, Ausgabe wäre viel zu lang! (${content.Result.length} Zeichen :DDDDDD)` : content.Result);
|
||||
});
|
||||
});
|
||||
req.write(params);
|
||||
req.end();
|
||||
}
|
||||
});
|
||||
|
||||
bot._trigger.set("sandbox_py", {
|
||||
call: /^\!py (.*)/i,
|
||||
level: 100,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const args = e.message.substring(4);
|
||||
const params = querystring.stringify({
|
||||
"LanguageChoice": "24",
|
||||
"Program": "print("+args+")",
|
||||
"Input": "",
|
||||
"CompilerArgs": ""
|
||||
});
|
||||
const options = {
|
||||
hostname: "rextester.com",
|
||||
port: 80,
|
||||
path: "/rundotnet/api",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Content-Length": Buffer.byteLength(params)
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(options, res => {
|
||||
let content = "";
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => content += chunk.toString());
|
||||
res.on('end', () => {
|
||||
content = JSON.parse(content);
|
||||
e.reply(content.Errors ? content.Errors : (content.Result.length > maxoutput) ? `holy fuck, Ausgabe wäre viel zu lang! (${content.Result.length} Zeichen :DDDDDD)` : content.Result);
|
||||
});
|
||||
});
|
||||
req.write(params);
|
||||
req.end();
|
||||
}
|
||||
});
|
||||
|
||||
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!");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -108,6 +108,19 @@ module.exports = bot => {
|
||||
}
|
||||
});
|
||||
|
||||
bot._trigger.set("bier", {
|
||||
call: /^(.|\/)bier/i,
|
||||
level: 0,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
let args = e.message.trim().split(" ");
|
||||
args.shift();
|
||||
args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
|
||||
e.replyAction(`schenkt ein kühles Blondes an [b]${args[0]}[/b] aus.`);
|
||||
}
|
||||
});
|
||||
|
||||
bot._trigger.set("notschlachten", {
|
||||
call: /^(.|\/)notschlachten/i,
|
||||
level: 0,
|
||||
|
Reference in New Issue
Block a user