Handle copy/paste of previou commands.
authorCMDR furrycat <elite@furrycat.net>
Tue, 23 May 2017 09:05:07 +0000 (10:05 +0100)
committerCMDR furrycat <elite@furrycat.net>
Tue, 23 May 2017 09:05:07 +0000 (10:05 +0100)
app.py

diff --git a/app.py b/app.py
index a61c234..c4505a0 100644 (file)
--- 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)<user>: 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)