Fixed getArgs to raise an empty callbacks.Error on invalid arguments

This commit is contained in:
Jeremy Fincher 2003-03-28 01:16:46 +00:00
parent 551a68c4c3
commit 406b263444

View File

@ -68,13 +68,13 @@ def getArgs(args, needed=1, optional=0):
If there aren't enough args even to satisfy needed, raise an error and If there aren't enough args even to satisfy needed, raise an error and
let the caller handle sending the help message. let the caller handle sending the help message.
""" """
if len(args) < needed:
raise callbacks.Error
if len(args) < needed + optional: if len(args) < needed + optional:
ret = list(args) + ([''] * (needed + optional - len(args))) ret = list(args) + ([''] * (needed + optional - len(args)))
elif len(args) >= needed + optional: elif len(args) >= needed + optional:
ret = list(args[:needed + optional - 1]) ret = list(args[:needed + optional - 1])
ret.append(' '.join(args[needed + optional - 1:])) ret.append(' '.join(args[needed + optional - 1:]))
else:
raise callbacks.Error
if len(ret) == 1: if len(ret) == 1:
return ret[0] return ret[0]
else: else:
@ -100,6 +100,14 @@ def getKeywordArgs(irc, msg, d=None):
del args[0] # The command name itself. del args[0] # The command name itself.
return (args, d) return (args, d)
def checkCapability(f, capability):
def newf(self, irc, msg, args):
if ircdb.checkCapability(msg.prefix, capability):
f(self, irc, msg, args)
else:
irc.error(msg, conf.replyNoCapability % capability)
newf.__doc__ = f.__doc__
return newf
class CapabilityCheckingPrivmsg(callbacks.Privmsg): class CapabilityCheckingPrivmsg(callbacks.Privmsg):
capability = '' # To satisfy PyChecker capability = '' # To satisfy PyChecker