From b3a6858ac064f77ea2df751d15e33e934965a121 Mon Sep 17 00:00:00 2001 From: 1computer1 Date: Wed, 13 Mar 2019 03:09:58 -0400 Subject: [PATCH] Add reactions for evals --- src/listeners/messageInvalid.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/listeners/messageInvalid.js b/src/listeners/messageInvalid.js index ac832f8..7ccc62c 100644 --- a/src/listeners/messageInvalid.js +++ b/src/listeners/messageInvalid.js @@ -20,8 +20,29 @@ class MessageInvalidListener extends Listener { return null; } + let reaction; + if (!message.guild || message.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) { + reaction = await message.react('📝'); + } + + let errored = false; const result = await this.client.languageHandler.evalCode(message, parse) - .catch(e => e.message) || '\n'; + .catch(e => { + errored = true; + return e.message; + }) || '\n'; + + if (!message.guild || message.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) { + if (reaction) { + reaction.users.remove(); + } + + if (errored) { + message.react('✖'); + } else { + message.react('✔'); + } + } const invalid = parse.invalid.length ? `Invalid options: ${parse.invalid.join(', ')}\n` : ''; const output = `${invalid}\`\`\`${parse.language.highlight}\n${result}\`\`\``; @@ -37,8 +58,8 @@ class MessageInvalidListener extends Listener { } parseMessage(message) { - const regex1 = /^\s*>\s*(?:(.+?))?\s*```(.+?)\n([^]+)```\s*$/; - const regex2 = /^\s*>\s*(?:(.+?))?\s*`(.+?) \s*([^]+)`\s*$/; + const regex1 = /^\s*>\s*(.+?)?\s*```(.+?)\n([^]+)```\s*$/; + const regex2 = /^\s*>\s*(.+?)?\s*`(.+?) \s*([^]+)`\s*$/; const match = message.content.match(regex1) || message.content.match(regex2); if (!match) { return null;