Give a better error message when a given command isn't found in a plugin.

This commit is contained in:
Jeremy Fincher 2005-06-01 01:10:08 +00:00
parent 6ed01d4a87
commit 5c8677cf22
2 changed files with 26 additions and 5 deletions

View File

@ -81,8 +81,20 @@ class Misc(callbacks.Plugin):
# Now, for normal handling. # Now, for normal handling.
channel = msg.args[0] channel = msg.args[0]
if conf.get(conf.supybot.reply.whenNotCommand, channel): if conf.get(conf.supybot.reply.whenNotCommand, channel):
command = tokens and tokens[0] or '' if len(tokens) >= 2:
irc.errorInvalid('command', command, repr=False) cb = irc.getCallback(tokens[0])
if cb:
plugin = cb.name()
irc.reply(format('The %q plugin is loaded, but there is '
'no command named %q in it. Try "list '
'%s" to see the commands in the %q '
'plugin.', plugin, tokens[1],
plugin, plugin))
else:
irc.errorInvalid('command', tokens[0], repr=False)
else:
command = tokens and tokens[0] or ''
irc.errorInvalid('command', command, repr=False)
else: else:
if tokens: if tokens:
# echo [] will get us an empty token set, but there's no need # echo [] will get us an empty token set, but there's no need

View File

@ -35,12 +35,21 @@ class MiscTestCase(ChannelPluginTestCase):
'Channel', 'Dict', 'User', 'String') 'Channel', 'Dict', 'User', 'String')
def testReplyWhenNotCommand(self): def testReplyWhenNotCommand(self):
try: try:
original = str(conf.supybot.reply.whenNotCommand) original = conf.supybot.reply.whenNotCommand()
conf.supybot.reply.whenNotCommand.set('True') conf.supybot.reply.whenNotCommand.setValue(True)
self.prefix = 'somethingElse!user@host.domain.tld' self.prefix = 'somethingElse!user@host.domain.tld'
self.assertRegexp('foo', 'not.*command')
self.assertRegexp('foo bar baz', 'not.*command') self.assertRegexp('foo bar baz', 'not.*command')
finally: finally:
conf.supybot.reply.whenNotCommand.set(original) conf.supybot.reply.whenNotCommand.setValue(original)
def testReplyWhenNotCommandButFirstCommandIsPluginName(self):
try:
original = conf.supybot.reply.whenNotCommand()
conf.supybot.reply.whenNotCommand.setValue(True)
self.assertRegexp('misc foo', '"list Misc"')
finally:
conf.supybot.reply.whenNotCommand.setValue(original)
# if network: # if network:
# def testNotReplyWhenRegexpsMatch(self): # def testNotReplyWhenRegexpsMatch(self):