From 3bc0a7493282ef386ac588837ab0f083dab3f51a Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 16 May 2021 13:23:19 +0200 Subject: [PATCH] async debug --- src/inc/trigger/debug.mjs | 49 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/inc/trigger/debug.mjs b/src/inc/trigger/debug.mjs index 7be9515..91d32c7 100644 --- a/src/inc/trigger/debug.mjs +++ b/src/inc/trigger/debug.mjs @@ -1,5 +1,6 @@ import { getLevel } from "../admin.mjs"; import fetch from "flumm-fetch-cookies"; +import sql from "../sql.mjs"; import vm from "vm"; @@ -8,7 +9,11 @@ let context = vm.createContext({ e: null, bot: null, admins: null, - fetch: fetch + sql: sql, + fetch: fetch, + + a: null, + resolve: null }); export default async bot => { @@ -30,29 +35,29 @@ export default async bot => { } }, { name: "sandbox_debug", - call: /^\!debug (.*)/i, + call: /^\!f0ck debug (.*)/i, active: true, level: 100, - f: e => { - const args = e.message.trim().substring(7); - try { - context.e = e; - context.bot = bot; - context.level = getLevel; - let output = vm.runInContext(args, vm.createContext(context)); - if (typeof output !== undefined && output) { - output = JSON.stringify(output); - if (output.length > maxoutput) - return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`); - else - e.reply(output); - } - else - e.reply("false lol"); - } - catch (err) { - e.reply(err.message); - } + 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); } }]; };