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",
|
||||
"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": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||
|
@ -1549,6 +1554,11 @@
|
|||
"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": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz",
|
||||
|
@ -1571,6 +1581,11 @@
|
|||
"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": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
|
||||
|
@ -2313,6 +2328,16 @@
|
|||
"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": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"nodejs-mysql": "github:flummi/nodejs-mysql",
|
||||
"request": "^2.83.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"stringify-object": "^3.2.1",
|
||||
"winston": "^2.4.0",
|
||||
"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")
|
||||
, 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 => {
|
||||
bot._trigger.set("sandbox_js", {
|
||||
call: /^\!js (.*)/i,
|
||||
level: 100,
|
||||
level: 0,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const args = e.message.substring(3);
|
||||
const context = {
|
||||
e: e,
|
||||
t: bot._trigger,
|
||||
hsimports: hsimports,
|
||||
};
|
||||
const args = e.message.trim().substring(4);
|
||||
if (!_contexts.has(`${e.network}.${e.channel}.${e.user.nick}`))
|
||||
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, vm.createContext({ }));
|
||||
if (args.match(/^reset$/)) {
|
||||
_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 {
|
||||
let output = vm.runInNewContext(args, context);
|
||||
let output = vm.runInContext(args, context, { timeout: 2000 });
|
||||
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);
|
||||
if (output.length > maxoutput)
|
||||
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