Added on_typing() and non_command_message() methods.
authorCMDR furrycat <elite@furrycat.net>
Wed, 30 Aug 2017 12:41:48 +0000 (13:41 +0100)
committerCMDR furrycat <elite@furrycat.net>
Wed, 30 Aug 2017 12:41:50 +0000 (13:41 +0100)
Plugins can implement on_typing() to react to a client typing.
Plugins can implement non_command_message() to handle a message that
mentions the bot but was not recognised as a command.

app.py
plugins.py

diff --git a/app.py b/app.py
index b9d7630..814caef 100644 (file)
--- a/app.py
+++ b/app.py
@@ -328,6 +328,17 @@ def mentioned_in(message, explicit = True):
   return True
 
 @client.event
+async def on_typing(channel, user, when):
+  if user.id == client.user.id:
+    return
+  if user.bot:
+    return
+  if channel.is_private:
+    return
+  log.debug('{} is typing in {}'.format(user, channel))
+  await plugins.on_typing(channel, user, when)
+
+@client.event
 async def on_message(message):
   if message.author.id == client.user.id:
     return
@@ -350,6 +361,7 @@ async def on_message(message):
 
   m = re.match(r'^(\S+)', raw)
   if m is None:
+    await plugins.non_command_message(message)
     return
   command = m.group(1)
   result = await builtin_commands(message, command, raw)
index 1e12be9..03f7e4c 100644 (file)
@@ -18,9 +18,11 @@ class Plugins(object):
       'on_ready',
       'on_member_join',
       'on_member_update',
+      'on_typing',
       'handle_command',
       'handle_help',
       'eddn_message',
+      'non_command_message',
       'not_our_message'
     ]
     self.plugins_supporting_methods = {}
@@ -136,6 +138,10 @@ class Plugins(object):
     for name in self.method_cache('on_member_update'):
       asyncio.ensure_future(self.call_coroutine(name, 'on_member_update', before, after))
 
+  async def on_typing(self, channel, user, when):
+    for name in self.method_cache('on_typing'):
+      asyncio.ensure_future(self.call_coroutine(name, 'on_typing', channel, user, when))
+
   # Plugin can return True to force skipping other handlers.
   async def handle_command(self, message, command, raw):
     for name in self.method_cache('handle_command'):
@@ -154,6 +160,11 @@ class Plugins(object):
         log.debug('Plugin {} handled command {}.'.format(name, command))
         continue
 
+  async def non_command_message(self, message):
+    for name in self.plugins():
+      if self.has_method(name, 'non_command_message'):
+        asyncio.ensure_future(self.call_coroutine(name, 'non_command_message', message))
+
   async def not_our_message(self, message):
     for name in self.plugins():
       if self.has_method(name, 'not_our_message'):