Ignore messages sent to roles or channels.
authorCMDR furrycat <elite@furrycat.net>
Thu, 29 Sep 2016 17:01:14 +0000 (18:01 +0100)
committerCMDR furrycat <elite@furrycat.net>
Thu, 29 Sep 2016 17:01:14 +0000 (18:01 +0100)
bot.py

diff --git a/bot.py b/bot.py
index 26d5aed..e6b768f 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -610,13 +610,25 @@ def on_ready():
   asyncio.async(do_feeds(feeds))
   asyncio.async(maybe_sleep())
 
+def mentioned_in(message, explicit = True):
+  if message.channel.is_private:
+    return True
+  if not client.user.mentioned_in(message):
+    return False
+  if explicit:
+    for member in message.mentions:
+      if member.id == client.user.id:
+        return True
+    return False
+  return True
+
 @client.event
 @asyncio.coroutine
 def on_message(message):
   if message.author.id == client.user.id:
     return
   log.debug('Got message from {}: {}'.format(message.author, message.content))
-  if not client.user.mentioned_in(message) and not message.channel.is_private:
+  if not mentioned_in(message):
     log.debug('Message is not for me!')
     return
   raw = re.sub('<@{}>'.format(client.user.id), '', message.content).strip()