f0ckv2/src/inc/trigger/debug.mjs

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-02 02:35:28 +00:00
import { getLevel } from "../admin.mjs";
import fetch from "flumm-fetch-cookies";
2021-05-16 11:23:19 +00:00
import sql from "../sql.mjs";
2020-04-02 02:35:28 +00:00
2018-09-02 10:07:40 +00:00
import vm from "vm";
2020-04-02 02:35:28 +00:00
let maxoutput = 750;
2018-09-02 10:07:40 +00:00
let context = vm.createContext({
e: null,
bot: null,
admins: null,
2021-05-16 11:23:19 +00:00
sql: sql,
fetch: fetch,
a: null,
resolve: null
2018-09-02 10:07:40 +00:00
});
2019-04-25 18:00:47 +00:00
2020-04-02 02:35:28 +00:00
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) || {} ) ) );
2018-09-02 10:07:40 +00:00
}
2020-10-15 11:02:56 +00:00
}, {
name: "self",
call: /^!self$/i,
active: true,
f: e => {
e.reply( JSON.stringify( e.user ) );
}
2020-04-02 02:35:28 +00:00
}, {
name: "sandbox_debug",
2021-05-16 11:23:19 +00:00
call: /^\!f0ck debug (.*)/i,
2020-04-02 02:35:28 +00:00
active: true,
level: 100,
2021-05-16 11:23:19 +00:00
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);
2019-04-23 15:58:25 +00:00
}
2020-04-02 02:35:28 +00:00
}];
};