Changed callerInChannel to callerInGivenChannel; added nickInChannel, added matches, and raised a subclass of KeyError from getConverter so we get prettier tracebacks.

This commit is contained in:
Jeremy Fincher 2004-10-19 03:10:58 +00:00
parent 425436b5f7
commit 9d0fa5e3ff
2 changed files with 19 additions and 4 deletions

View File

@ -531,7 +531,7 @@ class Misc(callbacks.Privmsg):
'with': 'something', 'with': 'something',
'from': 'something', 'from': 'something',
'without': 'something', 'without': 'something',
'in': 'callerInChannel', 'in': 'callerInGivenChannel',
'regexp': 'regexpMatcher',})]) 'regexp': 'regexpMatcher',})])

View File

@ -341,7 +341,7 @@ def onlyInChannel(irc, msg, args, state):
state.channel = msg.args[0] state.channel = msg.args[0]
state.args.append(state.channel) state.args.append(state.channel)
def callerInChannel(irc, msg, args, state): def callerInGivenChannel(irc, msg, args, state):
channel = args[0] channel = args[0]
if irc.isChannel(channel): if irc.isChannel(channel):
if channel in irc.state.channels: if channel in irc.state.channels:
@ -354,6 +354,12 @@ def callerInChannel(irc, msg, args, state):
else: else:
irc.errorInvalid('channel', args[0]) irc.errorInvalid('channel', args[0])
def nickInChannel(irc, msg, args, state):
inChannel(irc, msg, args, state)
if args[0] not in irc.state.channels[state.channel].users:
irc.error('%s is not in %s.' % (args[0], state.channel), Raise=True)
state.args.append(args.pop(0))
def getChannelOrNone(irc, msg, args, state): def getChannelOrNone(irc, msg, args, state):
try: try:
getChannel(irc, msg, args, state) getChannel(irc, msg, args, state)
@ -477,7 +483,8 @@ wrappers = ircutils.IrcDict({
'channel': getChannel, 'channel': getChannel,
'inChannel': inChannel, 'inChannel': inChannel,
'onlyInChannel': onlyInChannel, 'onlyInChannel': onlyInChannel,
'callerInChannel': callerInChannel, 'nickInChannel': nickInChannel,
'callerInGivenChannel': callerInGivenChannel,
'plugin': getPlugin, 'plugin': getPlugin,
'boolean': getBoolean, 'boolean': getBoolean,
'lowered': getLowered, 'lowered': getLowered,
@ -492,6 +499,7 @@ wrappers = ircutils.IrcDict({
'hostmask': getHostmask, 'hostmask': getHostmask,
'banmask': getBanmask, 'banmask': getBanmask,
'user': getUser, 'user': getUser,
'matches': getMatch,
'public': public, 'public': public,
'private': private, 'private': private,
'otherUser': getOtherUser, 'otherUser': getOtherUser,
@ -505,8 +513,14 @@ wrappers = ircutils.IrcDict({
def addConverter(name, wrapper): def addConverter(name, wrapper):
wrappers[name] = wrapper wrappers[name] = wrapper
class UnknownConverter(KeyError):
pass
def getConverter(name): def getConverter(name):
try:
return wrappers[name] return wrappers[name]
except KeyError, e:
raise UnknownConverter, str(e)
def callConverter(name, irc, msg, args, state, *L): def callConverter(name, irc, msg, args, state, *L):
getConverter(name)(irc, msg, args, state, *L) getConverter(name)(irc, msg, args, state, *L)
@ -557,6 +571,7 @@ class context(object):
# additional means: Look for this (and make sure it's of this type). If # additional means: Look for this (and make sure it's of this type). If
# there are no arguments for us to check, then use our default. # there are no arguments for us to check, then use our default.
class additional(context): class additional(context):
# XXX We should allow contexts as well as specs.
def __init__(self, spec, default=None): def __init__(self, spec, default=None):
self.__parent = super(additional, self) self.__parent = super(additional, self)
self.__parent.__init__(spec) self.__parent.__init__(spec)