Pass public messages without our mention to not_our_message() plugin method.
authorCMDR furrycat <elite@furrycat.net>
Mon, 17 Jul 2017 10:14:00 +0000 (11:14 +0100)
committerCMDR furrycat <elite@furrycat.net>
Mon, 17 Jul 2017 10:14:00 +0000 (11:14 +0100)
plugins.py

index 8a8a271..1e12be9 100644 (file)
@@ -20,7 +20,8 @@ class Plugins(object):
       'on_member_update',
       'handle_command',
       'handle_help',
-      'eddn_message'
+      'eddn_message',
+      'not_our_message'
     ]
     self.plugins_supporting_methods = {}
     self.loaded = {}
@@ -153,6 +154,20 @@ class Plugins(object):
         log.debug('Plugin {} handled command {}.'.format(name, command))
         continue
 
+  async def not_our_message(self, message):
+    for name in self.plugins():
+      if self.has_method(name, 'not_our_message'):
+        result = asyncio.ensure_future(self.call_coroutine(name, 'not_our_message', message))
+        if result is PluginCommand.ignored:
+          log.debug('Plugin {} ignored message.'.format(name))
+          continue
+        elif result is PluginCommand.exclusive:
+          log.info('Plugin {} handled message exclusively.'.format(name))
+          return True
+        elif result is PluginCommand.handled:
+          log.debug('Plugin {} handled message.'.format(name))
+          continue
+
   async def handle_help(self, message, command, *args):
     for name in self.method_cache('handle_help'):
       if self.has_method(name, 'valid_commands'):