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

View File

@ -32,7 +32,7 @@
from testsupport import * from testsupport import *
class MiscTestCase(ChannelPluginTestCase, PluginDocumentation): class MiscTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('Misc', 'Utilities', 'Gameknot', 'Ctcp', 'Dict') plugins = ('Misc', 'Utilities', 'Gameknot', 'Ctcp', 'Dict', 'User')
def testAction(self): def testAction(self):
self.assertAction('action moos', 'moos') self.assertAction('action moos', 'moos')
@ -71,6 +71,10 @@ class MiscTestCase(ChannelPluginTestCase, PluginDocumentation):
self.assertRegexp('help misc help', r'^\(\x02misc help') self.assertRegexp('help misc help', r'^\(\x02misc help')
self.assertError('help nonExistentCommand') 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): def testHelpStripsPrefixChars(self):
try: try:
original = conf.prefixChars original = conf.prefixChars