Help abstraction.

This commit is contained in:
Jeremy Fincher 2004-10-27 04:29:03 +00:00
parent 83cc539086
commit 8324de6da4
2 changed files with 36 additions and 29 deletions

View File

@ -216,42 +216,38 @@ class Misc(callbacks.Privmsg):
apropos = wrap(apropos, ['something']) apropos = wrap(apropos, ['something'])
def help(self, irc, msg, args, cb, command): def help(self, irc, msg, args, cb, command):
"""[<plugin>] <command> """[<plugin>] [<command>]
This command gives a useful description of what <command> does. This command gives a useful description of what <command> does.
<plugin> is only necessary if the command is in more than one plugin. <plugin> is only necessary if the command is in more than one plugin.
""" """
def getHelp(method, name=None): def getHelp(cb):
if hasattr(method, '__doc__') and method.__doc__: if hasattr(cb, 'isCommand'):
irc.reply(callbacks.getHelp(method, name=name)) if cb.isCommand(command):
irc.reply(cb.getCommandHelp(command))
else: else:
irc.error('%s has no help.' % name) irc.error('There is no %s command in the %s plugin.' %
if cb is not None: (command, cb.name()))
if hasattr(cb, 'isCommand') and cb.isCommand(command): else:
method = getattr(cb, command) irc.error('The %s plugin exists, but has no commands.' %
getHelp(method, command) cb.name())
return if cb:
if command:
getHelp(cb)
else:
irc.reply(cb.getCommandHelp(cb.name()))
else: 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) cbs = irc.findCallbackForCommand(command)
if not cbs: if not cbs:
irc.error('There is no such command %s.' % command) irc.error('There is no command %s.' % command)
elif len(cbs) > 1: elif len(cbs) > 1:
names = sorted([cb.name() for cb in cbs]) names = sorted([cb.name() for cb in cbs])
irc.error('That command exists in the %s plugins. ' irc.error('That command exists in the %s plugins. '
'Please specify exactly which plugin command ' 'Please specify exactly which plugin command '
'you want help with.'% utils.commaAndify(names)) 'you want help with.'% utils.commaAndify(names))
else: else:
cb = cbs[0] getHelp(cbs[0])
method = getattr(cb, command) help = wrap(help, [optional(('plugin', False)), 'commandName'])
getHelp(method)
help = wrap(help, [additional(('plugin', False)), 'commandName'])
def hostmask(self, irc, msg, args, nick): def hostmask(self, irc, msg, args, nick):
"""[<nick>] """[<nick>]

View File

@ -1131,6 +1131,17 @@ class Privmsg(irclib.IrcCallback):
elapsed = time.time() - start elapsed = time.time() - start
log.stat('%s took %s seconds', name, elapsed) 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): def registryValue(self, name, channel=None, value=True):
plugin = self.name() plugin = self.name()
group = conf.supybot.plugins.get(plugin) group = conf.supybot.plugins.get(plugin)