From 8324de6da430b08e3eed705b5837bd7e152d098f Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 27 Oct 2004 04:29:03 +0000 Subject: [PATCH] Help abstraction. --- src/Misc.py | 54 ++++++++++++++++++++++-------------------------- src/callbacks.py | 11 ++++++++++ 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/Misc.py b/src/Misc.py index bc953e08a..0f5bd7449 100755 --- a/src/Misc.py +++ b/src/Misc.py @@ -216,42 +216,38 @@ class Misc(callbacks.Privmsg): apropos = wrap(apropos, ['something']) def help(self, irc, msg, args, cb, command): - """[] + """[] [] This command gives a useful description of what does. is only necessary if the command is in more than one plugin. """ - def getHelp(method, name=None): - if hasattr(method, '__doc__') and method.__doc__: - irc.reply(callbacks.getHelp(method, name=name)) + def getHelp(cb): + if hasattr(cb, 'isCommand'): + if cb.isCommand(command): + irc.reply(cb.getCommandHelp(command)) + else: + irc.error('There is no %s command in the %s plugin.' % + (command, cb.name())) else: - irc.error('%s has no help.' % name) - if cb is not None: - if hasattr(cb, 'isCommand') and cb.isCommand(command): - method = getattr(cb, command) - getHelp(method, command) - return + irc.error('The %s plugin exists, but has no commands.' % + cb.name()) + if cb: + if command: + getHelp(cb) else: - irc.error('There is no such command %s.' % command, Raise=True) - #else: - # Is the command a callback? If so, possibly give the plugin doc. - cb = irc.getCallback(command) - if cb is not None and cb.__doc__ and not getattr(cb,'_original',None): - irc.reply(utils.normalizeWhitespace(cb.__doc__)) - return - cbs = irc.findCallbackForCommand(command) - if not cbs: - irc.error('There is no such command %s.' % command) - elif len(cbs) > 1: - names = sorted([cb.name() for cb in cbs]) - irc.error('That command exists in the %s plugins. ' - 'Please specify exactly which plugin command ' - 'you want help with.'% utils.commaAndify(names)) + irc.reply(cb.getCommandHelp(cb.name())) else: - cb = cbs[0] - method = getattr(cb, command) - getHelp(method) - help = wrap(help, [additional(('plugin', False)), 'commandName']) + cbs = irc.findCallbackForCommand(command) + if not cbs: + irc.error('There is no command %s.' % command) + elif len(cbs) > 1: + names = sorted([cb.name() for cb in cbs]) + irc.error('That command exists in the %s plugins. ' + 'Please specify exactly which plugin command ' + 'you want help with.'% utils.commaAndify(names)) + else: + getHelp(cbs[0]) + help = wrap(help, [optional(('plugin', False)), 'commandName']) def hostmask(self, irc, msg, args, nick): """[] diff --git a/src/callbacks.py b/src/callbacks.py index e1083f418..4a39d59c6 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1131,6 +1131,17 @@ class Privmsg(irclib.IrcCallback): elapsed = time.time() - start log.stat('%s took %s seconds', name, elapsed) + def getCommandHelp(self, name): + assert self.isCommand(name) + command = self.getCommand(name) + if hasattr(command, 'isDispatcher') and \ + command.isDispatcher and self.__doc__: + return utils.normalizeWhitespace(self.__doc__) + elif hasattr(command, '__doc__'): + return getHelp(command) + else: + return 'The %s command has no help.' % utils.quoted(name) + def registryValue(self, name, channel=None, value=True): plugin = self.name() group = conf.supybot.plugins.get(plugin)