diff --git a/structure/Client.js b/structure/Client.js index ed917fb..0730428 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -116,7 +116,7 @@ class ModmailClient extends Client { } this.logger.debug(`Executing command ${command.name}`); - const result = await command.execute(message, args).catch((err) => { + const result = await command.execute(message, { args, clean: message.content.replace(`${this.prefix}${commandName}`, '').trim() }).catch((err) => { this.logger.error(`Command ${command.name} errored during execution:\n${err.stack}`); return { error: true, diff --git a/structure/commands/CannedReply.js b/structure/commands/CannedReply.js index 1d1eea8..5c97c3d 100644 --- a/structure/commands/CannedReply.js +++ b/structure/commands/CannedReply.js @@ -11,8 +11,8 @@ class CannedReply extends Command { }); } - async execute(message, args) { - + async execute(message, { args }) { + const [first] = args.map((a) => a); // eslint-disable-next-line prefer-const let { channel, content, _caller } = message, diff --git a/structure/commands/Eval.js b/structure/commands/Eval.js new file mode 100644 index 0000000..7db3037 --- /dev/null +++ b/structure/commands/Eval.js @@ -0,0 +1,56 @@ +const { inspect } = require('util'); +const { username } = require('os').userInfo(); + +const Command = require('../Command'); + +class Eval extends Command { + + constructor(client) { + super(client, { + name: 'eval', + aliases: ['e'] + }); + } + + async execute(message, { clean }) { + + const { guild, author, member, client } = message; //eslint-disable-line no-unused-vars + + try { + let evaled = eval(clean); //eslint-disable-line no-eval + if (evaled instanceof Promise) await evaled; + if (typeof evaled !== 'string') evaled = inspect(evaled); + + evaled = evaled + .replace(new RegExp(this.client.token, 'gu'), '') + .replace(new RegExp(username, 'gu'), ''); + + //if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Success: ${evaled}`); + + if (evaled.length > 1850) { + evaled = `${evaled.substring(0, 1850)}...`; + } + await message.respond( + `Evaluation was successful.\`\`\`js\n${evaled}\`\`\``, + { emoji: 'success' } + ); + + + } catch (error) { + + let msg = `${error}${error.stack ? `\n${error.stack}` : ''}`; + + //if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Fail: ${msg}`); + if (msg.length > 2000) msg = `${msg.substring(0, 1900)}...`; + await message.respond( + `Evaluation failed.\`\`\`js\n${msg}\`\`\``, + { emoji: 'failure' } + ); + + } + + } + +} + +module.exports = Eval; \ No newline at end of file diff --git a/structure/commands/Logs.js b/structure/commands/Logs.js index 00765d7..e7d926b 100644 --- a/structure/commands/Logs.js +++ b/structure/commands/Logs.js @@ -11,8 +11,8 @@ class Logs extends Command { }); } - async execute(message, args) { - + async execute(message, { args }) { + const user = await this.client.resolveUser(args[0]); let pageNr = 1; if (args[1]) { diff --git a/structure/commands/Markread.js b/structure/commands/Markread.js index f35e4b6..fce7c19 100644 --- a/structure/commands/Markread.js +++ b/structure/commands/Markread.js @@ -8,7 +8,7 @@ class Markread extends Command { }); } - async execute(message, args) { + async execute(message) { return this.client.modmail.markread(message); diff --git a/structure/commands/Modmail.js b/structure/commands/Modmail.js index e5fd915..05deef4 100644 --- a/structure/commands/Modmail.js +++ b/structure/commands/Modmail.js @@ -11,7 +11,7 @@ class Modmail extends Command { }); } - async execute(message, args) { + async execute(message, { args }) { // eslint-disable-next-line prefer-const let [first, second] = args.map((a) => a); diff --git a/structure/commands/Ping.js b/structure/commands/Ping.js index bdf7762..c22ab99 100644 --- a/structure/commands/Ping.js +++ b/structure/commands/Ping.js @@ -8,6 +8,10 @@ class Ping extends Command { }); } + execute() { + return `PONG!`; + } + } module.exports = Ping; \ No newline at end of file diff --git a/structure/commands/Reply.js b/structure/commands/Reply.js index 7a8e7b2..26d65db 100644 --- a/structure/commands/Reply.js +++ b/structure/commands/Reply.js @@ -11,7 +11,7 @@ class Reply extends Command { }); } - async execute(message, args) { + async execute(message, { args }) { const [first] = args.map((a) => a); // eslint-disable-next-line prefer-const