From a0cbeb27b3d9cbe164b4fd2b24f69bc1abf7c5ff Mon Sep 17 00:00:00 2001 From: Mike Cooper Date: Sun, 24 Jul 2011 16:10:43 -0400 Subject: [PATCH] Convert plugin utils to a Command --- hamper/plugins/plugin_utils.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hamper/plugins/plugin_utils.py b/hamper/plugins/plugin_utils.py index 788c82c..8f7f717 100644 --- a/hamper/plugins/plugin_utils.py +++ b/hamper/plugins/plugin_utils.py @@ -3,21 +3,17 @@ from zope.interface import implements from bravo import plugin -from hamper.interfaces import IPlugin +from hamper.interfaces import Command, IPlugin -class PluginUtils(object): - implements(IPlugin) +class PluginUtils(Command): name = 'plugins' priority = 0 + regex = r'^plugins?\W+(.*)$' - def process(self, bot, comm): - match = re.match('^plugins?\w+(.*)$', comm['message']) - if not match: - return - - args = match.groups()[0].split(' ') + def command(self, bot, comm, groups): + args = groups[0].split(' ') args = [a.strip() for a in args] args = [a for a in args if a] @@ -25,9 +21,14 @@ def process(self, bot, comm): 'list': self.listPlugins, 'reload': self.reloadPlugin, } + print args + + if len(args) == 0: + self.listPlugins(bot, *args) + return True if args[0] in dispatch: - dispatch[args[0]](bot, *args[1:]) + dispatch[args[0]](bot, *args) return True def listPlugins(self, bot, *args): @@ -37,7 +38,7 @@ def listPlugins(self, bot, *args): def reloadPlugin(self, bot, *args): """Reload a named plugin.""" - name = ' '.join(args) + name = ' '.join(args[1:]) ps = bot.factory.plugins @@ -53,7 +54,7 @@ def reloadPlugin(self, bot, *args): bot.removePlugin(target_plugin) bot.addPlugin(new_plugin) - bot.say('Request reload of {0}.'.format(new_plugin)) + bot.say('Reloading {0}.'.format(new_plugin)) plugin_utils = PluginUtils()