mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Help abstraction.
This commit is contained in:
parent
83cc539086
commit
8324de6da4
54
src/Misc.py
54
src/Misc.py
@ -216,42 +216,38 @@ class Misc(callbacks.Privmsg):
|
||||
apropos = wrap(apropos, ['something'])
|
||||
|
||||
def help(self, irc, msg, args, cb, command):
|
||||
"""[<plugin>] <command>
|
||||
"""[<plugin>] [<command>]
|
||||
|
||||
This command gives a useful description of what <command> does.
|
||||
<plugin> 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):
|
||||
"""[<nick>]
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user