From fdddefe129187403afbf0ead6fc33e1c108cd670 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 4 Feb 2005 20:08:38 +0000 Subject: [PATCH] Added a listCommands method to PrivmsgRegexp, to allow plugins to list their own commands. --- plugins/Misc/plugin.py | 27 ++++++--------------------- src/callbacks.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index be19aeea2..1d4ac523f 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -125,28 +125,13 @@ class Misc(callbacks.Privmsg): else: irc.reply('There are no public plugins.') else: - if isinstance(cb, callbacks.PrivmsgRegexp) or \ - not isinstance(cb, callbacks.Privmsg): - irc.error('That plugin exists, but it has no commands. ' - 'You may wish to check if it has any useful ' - 'configuration variables with the command ' - '"config list supybot.plugins.%s".' % cb.name()) + commands = cb.listCommands() + if commands: + commands.sort() + irc.reply(format('%L', commands)) else: - name = callbacks.canonicalName(cb.name()) - commands = [] - for s in dir(cb): - if cb.isCommand(s) and \ - (s != name or cb._original) and \ - s == callbacks.canonicalName(s): - method = getattr(cb, s) - if hasattr(method, '__doc__') and method.__doc__: - commands.append(s) - if commands: - commands.sort() - irc.reply(format('%L', commands)) - else: - irc.error('That plugin exists, but it has no ' - 'commands with help.') + irc.error('That plugin exists, but it has no ' + 'commands with help.') list = wrap(list, [getopts({'private':''}), additional('plugin')]) def apropos(self, irc, msg, args, s): diff --git a/src/callbacks.py b/src/callbacks.py index 4cf84c694..50815c5ff 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1115,6 +1115,19 @@ class Privmsg(irclib.IrcCallback): assert self.isCommand(name), format('%s is not a command.', name) return getattr(self, name) + def listCommands(self): + commands = [] + name = canonicalName(self.name()) + for s in dir(self): + if self.isCommand(s) and \ + (s != name or self._original) and \ + s == canonicalName(s): + method = getattr(self, s) + if hasattr(method, '__doc__') and method.__doc__: + commands.append(s) + commands.sort() + return commands + def callCommand(self, name, irc, msg, *L, **kwargs): checkCapabilities = kwargs.pop('checkCapabilities', True) if checkCapabilities: @@ -1283,6 +1296,9 @@ class PrivmsgRegexp(Privmsg): value.__doc__, e) utils.gen.sortBy(operator.itemgetter(1), self.res) + def isCommand(self): + return [] + def callCommand(self, name, irc, msg, *L, **kwargs): try: self.__parent.callCommand(name, irc, msg, *L, **kwargs)