From: CMDR furrycat Date: Thu, 10 Nov 2016 14:22:39 +0000 (+0000) Subject: Plugin enhancements. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=47cca9a76e76a46ce4862b34ab786d2353df55e5;p=furrycat%2Fcatbot.git Plugin enhancements. Log loaded plugins. Command to reload plugins. Logging level set correctly. --- diff --git a/app.py b/app.py index d19ba75..85220ac 100644 --- 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 = [] diff --git a/plugins.py b/plugins.py index fe78446..91470df 100644 --- a/plugins.py +++ b/plugins.py @@ -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