dedicated jssandbox for debugging

This commit is contained in:
Flummi 2017-11-24 22:35:56 +01:00
parent 82ab711f45
commit 06915ce3e7

36
src/inc/trigger/debug.js Normal file
View File

@ -0,0 +1,36 @@
const vm = require("vm");
let maxoutput = 500;
let context = vm.createContext({
e: null,
bot: null
});
module.exports = bot => {
bot._trigger.set("sandbox_debug", {
call: /^\!debug (.*)/i,
level: 0,
active: true,
clients: ["irc", "tg"],
f: e => {
const args = e.message.trim().substring(7);
if ((e.user.nick === "Flummi" && e.network === "n0xy")
|| (e.user.nick === "belst" && e.network === "n0xy")
|| (e.user.nick === "jkhsjdhjs" && e.network === "n0xy")
) {
try {
let output = vm.runInContext(args, context);
if (typeof output !== undefined && output) {
output = JSON.stringify(output);
if (output.length > maxoutput)
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
else
e.reply(output);
}
}
catch (err) {
e.reply(err.message);
}
}
}
});
};