use method_cache() instead of iterating over plugins().
authorCMDR furrycat <elite@furrycat.net>
Wed, 27 Sep 2017 09:54:54 +0000 (10:54 +0100)
committerCMDR furrycat <elite@furrycat.net>
Wed, 27 Sep 2017 09:54:54 +0000 (10:54 +0100)
plugins.py

index 03f7e4c..3e7221b 100644 (file)
@@ -161,23 +161,21 @@ class Plugins(object):
         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))
+    for name in self.method_cache('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'):
-        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
+    for name in self.method_cache('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'):
@@ -193,6 +191,5 @@ class Plugins(object):
     return False
 
   async def eddn_message(self, schema, data, message):
-    for name in self.plugins():
-      if self.has_method(name, 'eddn_message'):
-        asyncio.ensure_future(self.call_coroutine(name, 'eddn_message', schema, data, message))
+    for name in self.method_cache('eddn_message'):
+      asyncio.ensure_future(self.call_coroutine(name, 'eddn_message', schema, data, message))