Added wildcard support.

This commit is contained in:
Jeremy Fincher 2004-10-02 02:21:26 +00:00
parent d2c05a460f
commit 0e3f7fe527

View File

@ -307,6 +307,12 @@ def getChannel(irc, msg, args, state):
state.channel = channel state.channel = channel
state.args.append(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): def getChannelOrNone(irc, msg, args, state):
try: try:
getChannel(irc, msg, args, state) getChannel(irc, msg, args, state)
@ -382,6 +388,7 @@ wrappers = ircutils.IrcDict({
'expiry': getExpiry, 'expiry': getExpiry,
'nick': getNick, 'nick': getNick,
'channel': getChannel, 'channel': getChannel,
'inChannel': inChannel,
'plugin': getPlugin, 'plugin': getPlugin,
'boolean': getBoolean, 'boolean': getBoolean,
'lowered': getLowered, 'lowered': getLowered,
@ -402,6 +409,9 @@ wrappers = ircutils.IrcDict({
'checkChannelCapability': checkChannelCapability, 'checkChannelCapability': checkChannelCapability,
}) })
def addWrapper(name, wrapper):
wrappers[name] = wrapper
class State(object): class State(object):
def __init__(self, name=None, logger=None): def __init__(self, name=None, logger=None):
if logger is None: if logger is None:
@ -448,6 +458,8 @@ def args(irc,msg,args, types=[], state=None,
optional = True optional = True
enforce = False enforce = False
name = name[:-1] name = name[:-1]
elif name[-1] in '*+':
name = name[:-1]
default = '' default = ''
wrapper = wrappers[name] wrapper = wrappers[name]
if optional and specArgs: 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 # (there's a possibility that there were no required or optional
# arguments) then we join the remaining args and work convert that. # arguments) then we join the remaining args and work convert that.
if types: if types:
assert len(types) == 1 name = types[0]
if args: if isinstance(name, tuple):
rest = ' '.join(args) name = name[0]
args = [rest] if name[-1] in '*+':
callWrapper(types.pop(0)) 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: if noExtra and args:
log.debug('noExtra and args: %r', args) log.debug('noExtra and args: %r', args)
raise callbacks.ArgumentError raise callbacks.ArgumentError