save sandbox in db
This commit is contained in:
parent
a8da8103f8
commit
11aee08a5d
25
package-lock.json
generated
25
package-lock.json
generated
|
@ -1291,6 +1291,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||||
},
|
},
|
||||||
|
"get-own-enumerable-property-symbols": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-TtY/sbOemiMKPRUDDanGCSgBYe7Mf0vbRsWnBZ+9yghpZ1MvcpSpuZFjHdEeY/LZjZy0vdLjS77L6HosisFiug=="
|
||||||
|
},
|
||||||
"getpass": {
|
"getpass": {
|
||||||
"version": "0.1.7",
|
"version": "0.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||||
|
@ -1549,6 +1554,11 @@
|
||||||
"kind-of": "3.2.2"
|
"kind-of": "3.2.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"is-obj": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8="
|
||||||
|
},
|
||||||
"is-posix-bracket": {
|
"is-posix-bracket": {
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz",
|
||||||
|
@ -1571,6 +1581,11 @@
|
||||||
"has": "1.0.1"
|
"has": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"is-regexp": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk="
|
||||||
|
},
|
||||||
"is-symbol": {
|
"is-symbol": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
|
||||||
|
@ -2313,6 +2328,16 @@
|
||||||
"safe-buffer": "5.1.1"
|
"safe-buffer": "5.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"stringify-object": {
|
||||||
|
"version": "3.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.2.1.tgz",
|
||||||
|
"integrity": "sha512-jPcQYw/52HUPP8uOE4kkjxl5bB9LfHkKCTptIk3qw7ozP5XMIMlHMLjt00GGSwW6DJAf/njY5EU6Vpwl4LlBKQ==",
|
||||||
|
"requires": {
|
||||||
|
"get-own-enumerable-property-symbols": "2.0.1",
|
||||||
|
"is-obj": "1.0.1",
|
||||||
|
"is-regexp": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"stringstream": {
|
"stringstream": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"nodejs-mysql": "github:flummi/nodejs-mysql",
|
"nodejs-mysql": "github:flummi/nodejs-mysql",
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
|
"stringify-object": "^3.2.1",
|
||||||
"winston": "^2.4.0",
|
"winston": "^2.4.0",
|
||||||
"youtube-dl": "^1.12.2"
|
"youtube-dl": "^1.12.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,27 +1,49 @@
|
||||||
import { maxoutput, sandbox, bfgen, hsimports } from "./lib/sandbox.js";
|
import sql from "../sql.js";
|
||||||
|
import { maxoutput, sandbox, bfgen } from "./lib/sandbox.js";
|
||||||
|
|
||||||
const vm = require("vm")
|
const vm = require("vm")
|
||||||
, rp = require("request-promise");
|
, rp = require("request-promise")
|
||||||
|
, stringify = require("stringify-object");
|
||||||
|
|
||||||
|
let _contexts = new Map();
|
||||||
|
sql.exec("select `data` from `useless` where `trigger` = 'sandbox_js'")
|
||||||
|
.then(rows => {
|
||||||
|
eval("_contexts = new Map([..."+JSON.parse(rows[0].data)+"])");
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log("nichts vorhanden lol", err);
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = bot => {
|
module.exports = bot => {
|
||||||
bot._trigger.set("sandbox_js", {
|
bot._trigger.set("sandbox_js", {
|
||||||
call: /^\!js (.*)/i,
|
call: /^\!js (.*)/i,
|
||||||
level: 100,
|
level: 0,
|
||||||
active: true,
|
active: true,
|
||||||
clients: ["irc", "tg"],
|
clients: ["irc", "tg"],
|
||||||
f: e => {
|
f: e => {
|
||||||
const args = e.message.substring(3);
|
const args = e.message.trim().substring(4);
|
||||||
const context = {
|
if (!_contexts.has(`${e.network}.${e.channel}.${e.user.nick}`))
|
||||||
e: e,
|
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, vm.createContext({ }));
|
||||||
t: bot._trigger,
|
if (args.match(/^reset$/)) {
|
||||||
hsimports: hsimports,
|
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, vm.createContext({ }));
|
||||||
};
|
return e.reply("Sandbox resetted!");
|
||||||
|
}
|
||||||
|
let context = vm.createContext(_contexts.get(`${e.network}.${e.channel}.${e.user.nick}`));
|
||||||
try {
|
try {
|
||||||
let output = vm.runInNewContext(args, context);
|
let output = vm.runInContext(args, context, { timeout: 2000 });
|
||||||
if (typeof output !== undefined && output) {
|
if (typeof output !== undefined && output) {
|
||||||
output = JSON.stringify(output);
|
output = JSON.stringify(output);
|
||||||
if (output !== "Converting circular structure to JSON") {
|
if (output.length > maxoutput)
|
||||||
e.reply(output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output);
|
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
|
||||||
|
else {
|
||||||
|
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, context);
|
||||||
|
sql.exec("update `useless` set `data` = ? where `trigger` = 'sandbox_js';", JSON.stringify(stringify([..._contexts]).replace(/\n/g, "").replace(/\t/g, "")))
|
||||||
|
.then(() => {
|
||||||
|
e.reply(output);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user