diff --git a/plugins/Plugin/plugin.py b/plugins/Plugin/plugin.py index 6753125ce..136e2fd44 100644 --- a/plugins/Plugin/plugin.py +++ b/plugins/Plugin/plugin.py @@ -67,7 +67,10 @@ class Plugin(callbacks.Plugin): def plugin(self, irc, msg, args, command): """ - Returns the plugin(s) that is in. + Returns the name of the plugin that would be used to call . + + If it is not uniquely determined, returns list of all plugins that + contain . """ (maxL, cbs) = irc.findCallbacksForArgs(command) L = [] @@ -89,6 +92,38 @@ class Plugin(callbacks.Plugin): irc.error(format('There is no command %q.', command)) plugin = wrap(plugin, [many('something')]) + def _findCallbacks(self, irc, command): + command = map(callbacks.canonicalName, command) + plugin_list = [] + for cb in irc.callbacks: + if not hasattr(cb, 'getCommand'): + continue + commandlist = cb.getCommand(command) + if commandlist: + plugin_list.append(cb.name()) + return plugin_list + + def plugins(self, irc, msg, args, command): + """ + + Returns the names of all plugins that contain . + """ + L = self._findCallbacks(irc, command) + command = callbacks.formatCommand(command) + if L: + if irc.nested: + irc.reply(format('%L', L)) + else: + if len(L) > 1: + plugin = 'plugins' + else: + plugin = 'plugin' + irc.reply(format('The %q command is available in the %L %s.', + command, L, plugin)) + else: + irc.error(format('There is no command %q.', command)) + plugins = wrap(plugins, [many('something')]) + def author(self, irc, msg, args, cb): """ diff --git a/plugins/Plugin/test.py b/plugins/Plugin/test.py index b5715adea..75bc52a96 100644 --- a/plugins/Plugin/test.py +++ b/plugins/Plugin/test.py @@ -30,11 +30,15 @@ from supybot.test import * class PluginTestCase(PluginTestCase): - plugins = ('Plugin', 'Utilities') + plugins = ('Plugin', 'Utilities', 'Admin', 'Format') def testPlugin(self): self.assertRegexp('plugin plugin', 'available.*Plugin plugin') self.assertResponse('echo [plugin plugin]', 'Plugin') - + + def testPlugins(self): + self.assertRegexp('plugins join', '(Format.*Admin|Admin.*Format)') + self.assertRegexp('plugins plugin', 'Plugin') + def testList(self): self.assertRegexp('plugin list', 'Plugin.*Utilities')