f0ckv2/src/inc/trigger/debug.mjs
2021-05-16 13:23:19 +02:00

64 lines
1.5 KiB
JavaScript

import { getLevel } from "../admin.mjs";
import fetch from "flumm-fetch-cookies";
import sql from "../sql.mjs";
import vm from "vm";
let maxoutput = 750;
let context = vm.createContext({
e: null,
bot: null,
admins: null,
sql: sql,
fetch: fetch,
a: null,
resolve: null
});
export default async bot => {
return [{
name: "level",
call: /^!level (.*)/i,
active: true,
f: e => {
const user = e.message.trim().substring(7);
e.reply( JSON.stringify( getLevel( e.self.user.get(user) || {} ) ) );
}
}, {
name: "self",
call: /^!self$/i,
active: true,
f: e => {
e.reply( JSON.stringify( e.user ) );
}
}, {
name: "sandbox_debug",
call: /^\!f0ck debug (.*)/i,
active: true,
level: 100,
f: async e => {
const args = e.message.trim().substring(12);
context.e = e;
context.bot = bot;
context.level = getLevel;
context.a = null;
await new Promise(resolve => {
context.resolve = resolve;
const code = "Promise.resolve().then(async result => { a = await (async () => "+args+")(); resolve(); }).catch(err => { a = err; resolve(); })";
const script = new vm.Script(code);
script.runInContext(context);
});
let output = JSON.stringify(context.a);
if(output.length > maxoutput)
return e.reply(`fuggg, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
else
return e.reply(output);
}
}];
};