From 5aa12c4e401a1246052ba88f6a1712f8e248a3fc Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 23 May 2017 10:05:07 +0100 Subject: [PATCH] Handle copy/paste of previou commands. --- app.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index a61c234..c4505a0 100644 --- a/app.py +++ b/app.py @@ -339,8 +339,16 @@ async def on_message(message): if message.author.bot: log.debug('Ignoring message from bot!') return + + # Strip our mention from the message. raw = re.sub('<@{}>'.format(client.user.id), '', message.content).strip() - m = re.match(r'^\s*(\S+)', raw) + + # Handle copy/paste; Discord client will prepend (BOT): to pasted + # text. Deal with the common cases of the user copying his own message + # or quoting the bot. + raw = re.sub('^(?:BOT{}|{}):\s+'.format(client.user.name, message.author.name), '', raw) + + m = re.match(r'^(\S+)', raw) if m is None: return command = m.group(1) -- 2.7.4