new sandbox

This commit is contained in:
Flummi
2017-11-20 15:26:41 +01:00
parent e059d189a4
commit feac3e4872
3 changed files with 8 additions and 18 deletions

View File

@ -1,7 +1,7 @@
import { logger } from "./inc/log.js";
import { read } from "./inc/cfg.js";
import { wrapper, clients } from "./inc/wrapper.js";
const safeEval = require("safe-eval");
const vm = require("vm");
read().then(() => {
let bot = new wrapper();
@ -14,20 +14,16 @@ read().then(() => {
if (e.message.match(/^\.js /)) { // JS-Sandbox
args = e.message.substring(3);
var context = {
const context = {
e: e,
gf: "nogf",
c: clients,
console: {
log: console.log
}
c: clients
};
try {
var output = safeEval(args, context);
if (typeof output !== undefined && output !== "undefined" && output) {
let blah = JSON.stringify(output);
if (blah != "Converting circular structure to JSON") {
e.reply(blah.length > 400 ? `holy fuck, Ausgabe wäre viel zu lang! (${blah.length} Zeichen :DDDDDD)` : blah);
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 > 400 ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output);
}
}
}