From 7b63e5c77facbca9b6e268e45c6653509e864d5e Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 3 Jan 2020 19:54:58 +0000 Subject: [PATCH] Add flags --- src/commands/eval.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/commands/eval.ts b/src/commands/eval.ts index cdbe4d4..f12e6cb 100644 --- a/src/commands/eval.ts +++ b/src/commands/eval.ts @@ -19,12 +19,24 @@ export default class Eval extends Command { public async run(message: Message, args: string[]) { try { // const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1).join(' '); + let evalString = args.join(' ').trim(); let evaled: any; + let depth = 0; + + if (args[0] && args[0].startsWith('-d')) { + depth = Number(args[0].replace('-d', '')); + if (!depth || depth < 0) depth = 0; + args.shift(); + } + if (args[0] === '-a' || args[0] === '-async') { + evalString = `(async () => { ${evalString} })()`; + args.shift(); + } try { - evaled = await eval(args.join(' ').trim()); + evaled = await eval(evalString); if (typeof evaled !== 'string') { - evaled = inspect(evaled, { depth: 0 }); + evaled = inspect(evaled, { depth }); } if (evaled === undefined) { evaled = 'undefined';