Made help handle defaultplugins and whatnot correctly.

This commit is contained in:
Jeremy Fincher 2003-12-12 17:53:16 +00:00
parent e485984604
commit 590c9c64a0
3 changed files with 34 additions and 17 deletions

View File

@ -1,4 +1,7 @@
* Added Lookup.search
* Fixed Misc.help to follow the same default plugin rules that the
rest of the bot follows.
* Added Lookup.search for searching the various loaded lookups.
* Updated Todo.remove to allow removing multiple taskids

View File

@ -137,6 +137,11 @@ class Misc(callbacks.Privmsg):
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(msg, callbacks.getHelp(method, name=name))
else:
irc.error(msg, '%s has no help.' % name)
if len(args) > 1:
cb = irc.getCallback(args[0])
if cb is not None:
@ -145,10 +150,7 @@ class Misc(callbacks.Privmsg):
name = ' '.join(args)
if hasattr(cb, 'isCommand') and cb.isCommand(command):
method = getattr(cb, command)
if hasattr(method, '__doc__') and method.__doc__ != None:
irc.reply(msg, callbacks.getHelp(method, name=name))
else:
irc.error(msg, 'That command has no help.')
getHelp(method, name)
else:
irc.error(msg, 'There is no such command %s.' % name)
else:
@ -159,21 +161,28 @@ class Misc(callbacks.Privmsg):
command = command.lstrip(conf.prefixChars)
cbs = callbacks.findCallbackForCommand(irc, command)
if len(cbs) > 1:
names = [cb.name() for cb in cbs]
names.sort()
irc.error(msg, 'That command exists in the %s plugins. '
'Please specify exactly which plugin command '
'you want help with.'% utils.commaAndify(names))
return
tokens = [command]
ambiguous = {}
Owner = irc.getCallback('Owner')
Owner.disambiguate(irc, tokens, ambiguous)
if ambiguous:
names = [cb.name() for cb in cbs]
names.sort()
irc.error(msg, 'That command exists in the %s plugins. '
'Please specify exactly which plugin command '
'you want help with.'% utils.commaAndify(names))
return
else:
assert len(tokens) == 2
cb = irc.getCallback(tokens[0])
method = getattr(cb, tokens[1])
getHelp(method)
elif not cbs:
irc.error(msg, 'There is no such command %s.' % command)
else:
cb = cbs[0]
method = getattr(cb, command)
if hasattr(method, '__doc__') and method.__doc__ is not None:
irc.reply(msg, callbacks.getHelp(method, name=command))
else:
irc.error(msg, '%s has no help.' % command)
getHelp(method)
def hostmask(self, irc, msg, args):
"""[<nick>]
@ -377,7 +386,8 @@ class Misc(callbacks.Privmsg):
else:
irc.reply(msg, ircmsgs.prettyPrint(m))
return
irc.error(msg, 'I couldn\'t find a message matching that criteria.')
irc.error(msg, 'I couldn\'t find a message matching that criteria in '
'my history of %s messages.' % len(irc.state.history))
def tell(self, irc, msg, args):
"""<nick|channel> <text>

View File

@ -32,7 +32,7 @@
from testsupport import *
class MiscTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('Misc', 'Utilities', 'Gameknot', 'Ctcp', 'Dict')
plugins = ('Misc', 'Utilities', 'Gameknot', 'Ctcp', 'Dict', 'User')
def testAction(self):
self.assertAction('action moos', 'moos')
@ -71,6 +71,10 @@ class MiscTestCase(ChannelPluginTestCase, PluginDocumentation):
self.assertRegexp('help misc help', r'^\(\x02misc help')
self.assertError('help nonExistentCommand')
def testHelpDoesAmbiguityWithDefaultPlugins(self):
m = self.getMsg('help list') # Misc.list and User.list.
self.failIf(m.args[1].startswith('Error'))
def testHelpStripsPrefixChars(self):
try:
original = conf.prefixChars