Added addressedRegexps set to PrivmsgCommandAndRegexp.

This commit is contained in:
Jeremy Fincher 2003-10-09 04:29:37 +00:00
parent d376476462
commit e96c1359fd
2 changed files with 24 additions and 1 deletions

View File

@ -75,6 +75,10 @@ class MiscCommands(callbacks.Privmsg):
for (r, _) in cb.res: for (r, _) in cb.res:
if r.search(msg.args[1]): if r.search(msg.args[1]):
return return
if hasattr(cb, 'addressedRes'):
for (r, _) in cb.addressedRes:
if r.search(s):
return
notCommands = [] notCommands = []
tokens = callbacks.tokenize(s) tokens = callbacks.tokenize(s)
for command in callbacks.getCommands(tokens): for command in callbacks.getCommands(tokens):

View File

@ -725,15 +725,23 @@ class PrivmsgCommandAndRegexp(Privmsg):
(or list) attribute "regexps". (or list) attribute "regexps".
""" """
flags = re.I flags = re.I
regexps = sets.Set() regexps = () # Use sets.Set() in your own callbacks.
addressedRegexps = () # Ditto on the sets.Sets() idea.
def __init__(self): def __init__(self):
Privmsg.__init__(self) Privmsg.__init__(self)
self.res = [] self.res = []
self.addressedRes = []
for name in self.regexps: for name in self.regexps:
method = getattr(self, name) method = getattr(self, name)
r = re.compile(method.__doc__, self.flags) r = re.compile(method.__doc__, self.flags)
self.res.append((r, method)) self.res.append((r, method))
for name in self.addressedRegexps:
method = getattr(self, name)
r = re.compile(method.__doc__, self.flags)
self.addressedRes.append((r, method))
self.res.sort(lambda (r1, m1), (r2, m2): cmp(m1.__name__, m2.__name__)) self.res.sort(lambda (r1, m1), (r2, m2): cmp(m1.__name__, m2.__name__))
self.addressedRes.sort(lambda (r1, m1), (r2, m2): cmp(m1.__name__,
m2.__name__))
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
if ircdb.checkIgnored(msg.prefix, msg.args[0]): if ircdb.checkIgnored(msg.prefix, msg.args[0]):
@ -747,6 +755,17 @@ class PrivmsgCommandAndRegexp(Privmsg):
msg = self.rateLimiter.get() msg = self.rateLimiter.get()
if msg: if msg:
self.callCommand(method, IrcObjectProxyRegexp(irc), msg, m) self.callCommand(method, IrcObjectProxyRegexp(irc), msg, m)
s = addressed(irc.nick, msg)
if s:
for (r, method) in self.addressedRes:
for m in r.finditer(s):
if not fed:
fed = True
self.rateLimiter.put(msg)
msg = self.rateLimiter.get()
if msg:
proxy = IrcObjectProxyRegexp(irc)
self.callCommand(method, proxy, msg, m)
Privmsg.doPrivmsg(self, irc, msg, rateLimit=(not fed)) Privmsg.doPrivmsg(self, irc, msg, rateLimit=(not fed))