mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +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'])
|
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:
|
||||||
|
irc.error('There is no %s command in the %s plugin.' %
|
||||||
|
(command, cb.name()))
|
||||||
else:
|
else:
|
||||||
irc.error('%s has no help.' % name)
|
irc.error('The %s plugin exists, but has no commands.' %
|
||||||
if cb is not None:
|
cb.name())
|
||||||
if hasattr(cb, 'isCommand') and cb.isCommand(command):
|
if cb:
|
||||||
method = getattr(cb, command)
|
if command:
|
||||||
getHelp(method, command)
|
getHelp(cb)
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
irc.error('There is no such command %s.' % command, Raise=True)
|
irc.reply(cb.getCommandHelp(cb.name()))
|
||||||
#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))
|
|
||||||
else:
|
else:
|
||||||
cb = cbs[0]
|
cbs = irc.findCallbackForCommand(command)
|
||||||
method = getattr(cb, command)
|
if not cbs:
|
||||||
getHelp(method)
|
irc.error('There is no command %s.' % command)
|
||||||
help = wrap(help, [additional(('plugin', False)), 'commandName'])
|
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):
|
def hostmask(self, irc, msg, args, nick):
|
||||||
"""[<nick>]
|
"""[<nick>]
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user