New implementation to the 'prevent myself from relaying my own relay messages' code.

This commit is contained in:
Jeremy Fincher 2004-04-17 17:14:59 +00:00
parent a4f2336769
commit 136ec785b0

View File

@ -96,11 +96,12 @@ class Relay(callbacks.Privmsg):
priority = sys.maxint priority = sys.maxint
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
self._whois = {}
self.ircs = ircs self.ircs = ircs
self.started = False self.started = False
self.ircstates = ircstates self.relayedMsgs = {}
self.lastmsg = lastmsg self.lastmsg = lastmsg
self._whois = {} self.ircstates = ircstates
self.abbreviations = abbreviations self.abbreviations = abbreviations
def __call__(self, irc, msg): def __call__(self, irc, msg):
@ -504,6 +505,11 @@ class Relay(callbacks.Privmsg):
for otherIrc in self.ircs.itervalues(): for otherIrc in self.ircs.itervalues():
if otherIrc != irc: if otherIrc != irc:
if msg.args[0] in otherIrc.state.channels: if msg.args[0] in otherIrc.state.channels:
if msg.command == 'PRIVMSG':
try:
self.relayedMsgs[msg].append(otherIrc)
except KeyError:
self.relayedMsgs[msg] = [otherIrc]
otherIrc.queueMsg(msg) otherIrc.queueMsg(msg)
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
@ -615,18 +621,10 @@ class Relay(callbacks.Privmsg):
irc = self._getRealIrc(irc) irc = self._getRealIrc(irc)
if msg.command == 'PRIVMSG': if msg.command == 'PRIVMSG':
abbreviations = self.abbreviations.values() abbreviations = self.abbreviations.values()
rPrivmsg = re.compile(r'<[^@]+@(?:%s)>' % '|'.join(abbreviations)) if msg in self.relayedMsgs and irc in self.relayedMsgs[msg]:
rAction = re.compile(r'\* [^/]+@(?:%s) ' % '|'.join(abbreviations)) self.relayedMsgs[msg].remove(irc)
text = ircutils.stripColor(msg.args[1]) if not self.relayedMsgs[msg]:
if not (rPrivmsg.match(text) or \ del self.relayedMsgs[msg]
rAction.match(text) or \
'has left on ' in text or \
'has joined on ' in text or \
'has quit' in text or \
'was kicked by' in text or \
text.startswith('mode change') or \
text.startswith('nick change') or \
text.startswith('topic change')):
channel = msg.args[0] channel = msg.args[0]
if channel in self.registryValue('channels'): if channel in self.registryValue('channels'):
abbreviation = self.abbreviations[irc] abbreviation = self.abbreviations[irc]