Removed handling of ambiguous commands in IrcObjectProxy; Misc is the only place where it's to be handled. Also fixed bug that a dispatched command raising callbacks.ArgumentError results in the syntax for the dispatcher.

This commit is contained in:
Jeremy Fincher 2003-10-21 07:20:54 +00:00
parent 3ac622ce11
commit 72402b98c7

View File

@ -308,6 +308,15 @@ def findCallbackForCommand(irc, commandName):
L.append(callback) L.append(callback)
return L return L
def formatArgumentError(method, name=None):
if name is None:
name = method.__name__
if hasattr(method, '__doc__') and method.__doc__:
s = '%s %s' % (method.__name__, method.__doc__.splitlines()[0])
else:
s = 'Invalid arguments for %s.' % method.__name__
return s
class IrcObjectProxy: class IrcObjectProxy:
"A proxy object to allow proper nested of commands (even threaded ones)." "A proxy object to allow proper nested of commands (even threaded ones)."
def __init__(self, irc, msg, args): def __init__(self, irc, msg, args):
@ -352,10 +361,7 @@ class IrcObjectProxy:
self.reply(self.msg, '[%s]' % ' '.join(self.args)) self.reply(self.msg, '[%s]' % ' '.join(self.args))
return return
elif len(cbs) > 1: elif len(cbs) > 1:
s = 'The command %s is available in plugins %s. Please specify ' \ return # Misc.doPrivmsg will handle this.
'the plugin whose command you wish to call.' % \
(originalName, utils.commaAndify([cb.name() for cb in cbs]))
self.error(self.msg, s)
else: else:
try: try:
cb = cbs[0] cb = cbs[0]
@ -387,11 +393,7 @@ class IrcObjectProxy:
else: else:
cb.callCommand(command, self, self.msg, self.args) cb.callCommand(command, self, self.msg, self.args)
except (getopt.GetoptError, ArgumentError): except (getopt.GetoptError, ArgumentError):
if hasattr(command, '__doc__'): self.reply(self.msg, formatArgumentError(command, name=name))
s = '%s %s' % (name, command.__doc__.splitlines()[0])
else:
s = 'Invalid arguments for %s.' % name
self.reply(self.msg, s)
except CannotNest, e: except CannotNest, e:
if not isinstance(self.irc, irclib.Irc): if not isinstance(self.irc, irclib.Irc):
self.error(self.msg, 'Command %r cannot be nested.' % name) self.error(self.msg, 'Command %r cannot be nested.' % name)
@ -528,12 +530,8 @@ class CommandThread(threading.Thread):
try: try:
threading.Thread.run(self) threading.Thread.run(self)
except (getopt.GetoptError, ArgumentError): except (getopt.GetoptError, ArgumentError):
if hasattr(self.command, '__doc__'): name = self.commandName
help = self.command.__doc__.splitlines()[0] self.irc.reply(self.msg, formatArgumentError(self.command, name))
s = '%s %s' % (self.commandName, help)
else:
s = 'Invalid arguments for %s.' % self.commandName
self.irc.reply(self.msg, s)
except CannotNest: except CannotNest:
if not isinstance(self.irc.irc, irclib.Irc): if not isinstance(self.irc.irc, irclib.Irc):
s = 'Command %r cannot be nested.' % self.commandName s = 'Command %r cannot be nested.' % self.commandName
@ -598,7 +596,10 @@ class Privmsg(irclib.IrcCallback):
if self.isCommand(name): if self.isCommand(name):
del args[0] del args[0]
method = getattr(self, name) method = getattr(self, name)
method(irc, msg, args) try:
method(irc, msg, args)
except (getopt.GetoptError, ArgumentError):
irc.reply(msg, formatArgumentError(method, name))
else: else:
handleBadArgs() handleBadArgs()
else: else: