From 0e3f7fe527d0a9fcace95b815af66caf5ad5628b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 2 Oct 2004 02:21:26 +0000 Subject: [PATCH] Added wildcard support. --- src/commands.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/commands.py b/src/commands.py index c64305a38..23ccbf173 100644 --- a/src/commands.py +++ b/src/commands.py @@ -307,6 +307,12 @@ def getChannel(irc, msg, args, state): state.channel = channel state.args.append(channel) +def inChannel(irc, msg, args, state): + assert not state.channel, 'inChannel acts as a channel' + getChannel(irc, msg, args, state) + if state.channel not in irc.state.channels: + irc.error('I\'m not in %s.' % state.channel, Raise=True) + def getChannelOrNone(irc, msg, args, state): try: getChannel(irc, msg, args, state) @@ -382,6 +388,7 @@ wrappers = ircutils.IrcDict({ 'expiry': getExpiry, 'nick': getNick, 'channel': getChannel, + 'inChannel': inChannel, 'plugin': getPlugin, 'boolean': getBoolean, 'lowered': getLowered, @@ -402,6 +409,9 @@ wrappers = ircutils.IrcDict({ 'checkChannelCapability': checkChannelCapability, }) +def addWrapper(name, wrapper): + wrappers[name] = wrapper + class State(object): def __init__(self, name=None, logger=None): if logger is None: @@ -448,6 +458,8 @@ def args(irc,msg,args, types=[], state=None, optional = True enforce = False name = name[:-1] + elif name[-1] in '*+': + name = name[:-1] default = '' wrapper = wrappers[name] if optional and specArgs: @@ -497,11 +509,24 @@ def args(irc,msg,args, types=[], state=None, # (there's a possibility that there were no required or optional # arguments) then we join the remaining args and work convert that. if types: - assert len(types) == 1 - if args: - rest = ' '.join(args) - args = [rest] - callWrapper(types.pop(0)) + name = types[0] + if isinstance(name, tuple): + name = name[0] + if name[-1] in '*+': + originalStateArgs = state.args + state.args = [] + if name.endswith('+'): + callWrapper(types[0]) # So it raises an error if no args. + while args: + callWrapper(types[0]) + lastArgs = state.args + state.args = originalStateArgs + state.args.append(lastArgs) + else: + if args: + rest = ' '.join(args) + args = [rest] + callWrapper(types.pop(0)) if noExtra and args: log.debug('noExtra and args: %r', args) raise callbacks.ArgumentError