Plugin enhancements.
authorCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 14:22:39 +0000 (14:22 +0000)
committerCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 14:25:38 +0000 (14:25 +0000)
Log loaded plugins.
Command to reload plugins.
Logging level set correctly.

app.py
plugins.py

diff --git a/app.py b/app.py
index d19ba75..85220ac 100644 (file)
--- a/app.py
+++ b/app.py
@@ -19,7 +19,6 @@ import bot
 import cat
 
 db = DBConnection()
-plugins = Plugins()
 
 token_file = 'TOKEN'
 if len(sys.argv) > 1:
@@ -34,7 +33,7 @@ log = logging.getLogger('catbot')
 bot.log = log
 bot.db = db
 log.setLevel(logging.DEBUG if bot.get('debug') else logging.INFO)
-plugins.log_level(log.level)
+plugins = Plugins(log.level)
 
 idletime = multiprocessing.Value('i', 900)
 threads_ready = multiprocessing.Value('b', False)
@@ -241,6 +240,12 @@ if 'admin' in plugins.plugins():
 @asyncio.coroutine
 def builtin_commands(message, command, raw):
   if command == 'plugins':
+    args = shlex.split(raw)
+    if len(args) > 1:
+      if args[1] == 'reload':
+        plugins.refresh()
+        return True
+      return False
     all_plugins = list(plugins.plugins())
     if len(all_plugins):
       lines = []
index fe78446..91470df 100644 (file)
@@ -13,9 +13,11 @@ class PluginCommand(Enum):
   exclusive = 4
 
 class Plugins(object):
-  def __init__(self):
+  def __init__(self, level):
     self.loaded = {}
+    self.log_level(level)
     self.refresh()
+    self.log_level(level)
 
   def refresh(self):
     for py in glob.glob('plugin/*/*.py'):
@@ -36,6 +38,7 @@ class Plugins(object):
         self.loaded[name] = { 'module': module, 'plugin': getattr(module, plugin)() }
       except:
         log.exception('refresh')
+    log.info('Loaded plugins: {}'.format(', '.join(self.plugins())))
 
   def plugins(self):
     return self.loaded.keys()
@@ -139,5 +142,8 @@ class Plugins(object):
           log.debug("Plugin {} doesn't handle help for {} command.".format(name, command))
           continue
       result = yield from self.call_coroutine(name, 'handle_help', message, command, *args)
+      if result is not None:
+        if not result or result is not PluginCommand.exclusive:
+          continue
       return True
     return False