Accepted RFE #812257: Multiple regexp matches in one message.

This commit is contained in:
Jeremy Fincher 2003-10-02 22:37:36 +00:00
parent cecb130106
commit 41bacaba13

View File

@ -52,6 +52,7 @@ import threading
from cStringIO import StringIO from cStringIO import StringIO
import conf import conf
import debug
import utils import utils
import world import world
import ircdb import ircdb
@ -59,8 +60,6 @@ import irclib
import ircmsgs import ircmsgs
import ircutils import ircutils
import debug
### ###
# Privmsg: handles privmsg commands in a standard fashion. # Privmsg: handles privmsg commands in a standard fashion.
### ###
@ -433,12 +432,12 @@ class IrcObjectProxy:
self.args[self.counter] = s self.args[self.counter] = s
self.evalArgs() self.evalArgs()
def error(self, msg, s): def error(self, msg, s, private=False):
if isinstance(self.irc, self.__class__): if isinstance(self.irc, self.__class__):
self.irc.error(msg, s) self.irc.error(msg, s, private)
else: else:
s = 'Error: ' + s s = 'Error: ' + s
if conf.errorReplyPrivate: if private or conf.errorReplyPrivate:
self.irc.queueMsg(ircmsgs.privmsg(msg.nick, s)) self.irc.queueMsg(ircmsgs.privmsg(msg.nick, s))
else: else:
self.irc.queueMsg(reply(msg, s)) self.irc.queueMsg(reply(msg, s))
@ -592,7 +591,7 @@ class Privmsg(irclib.IrcCallback):
(f.im_class.__name__, funcname, elapsed), 'verbose') (f.im_class.__name__, funcname, elapsed), 'verbose')
_r = re.compile(r'^([^\s[]+)(?:\[|\s+|$)') _r = re.compile(r'^([^\s[]+)(?:\[|\s+|$)')
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg, rateLimit=True):
s = addressed(irc.nick, msg) s = addressed(irc.nick, msg)
#debug.printf('Privmsg.doPrivmsg: s == %r' % s) #debug.printf('Privmsg.doPrivmsg: s == %r' % s)
if s: if s:
@ -602,6 +601,7 @@ class Privmsg(irclib.IrcCallback):
return return
m = self._r.match(s) m = self._r.match(s)
if m and self.isCommand(canonicalName(m.group(1))): if m and self.isCommand(canonicalName(m.group(1))):
if rateLimit:
self.rateLimiter.put(msg) self.rateLimiter.put(msg)
msg = self.rateLimiter.get() msg = self.rateLimiter.get()
if msg: if msg:
@ -681,13 +681,14 @@ class PrivmsgRegexp(Privmsg):
if ircdb.checkIgnored(msg.prefix, msg.args[0]): if ircdb.checkIgnored(msg.prefix, msg.args[0]):
debug.msg('PrivmsgRegexp.doPrivmsg: ignoring %s' % msg.prefix) debug.msg('PrivmsgRegexp.doPrivmsg: ignoring %s' % msg.prefix)
return return
fed = False
for (r, method) in self.res: for (r, method) in self.res:
m = r.search(msg.args[1]) for m in r.finditer(msg.args[1]):
if m: if not fed:
fed = True
self.rateLimiter.put(msg) self.rateLimiter.put(msg)
msg = self.rateLimiter.get() msg = self.rateLimiter.get()
if msg: if msg:
irc = IrcObjectProxyRegexp(irc)
self.callCommand(method, irc, msg, m) self.callCommand(method, irc, msg, m)
if self.onlyFirstMatch: if self.onlyFirstMatch:
return return
@ -712,26 +713,16 @@ class PrivmsgCommandAndRegexp(Privmsg):
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]):
return return
fed = False
for (r, method) in self.res: for (r, method) in self.res:
m = r.search(msg.args[1]) for m in r.finditer(msg.args[1]):
if m: if not fed:
fed = True
self.rateLimiter.put(msg) self.rateLimiter.put(msg)
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) Privmsg.doPrivmsg(self, irc, msg, rateLimit=(not fed))
if s:
m = self._r.match(s)
if m and self.isCommand(canonicalName(m.group(1))):
self.rateLimiter.put(msg)
msg = self.rateLimiter.get()
if msg:
args = tokenize(s)
self.Proxy(irc, msg, args)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: