Added IrcMsg attribute tagging, and used it in some places.

This commit is contained in:
Jeremy Fincher 2004-09-09 15:33:57 +00:00
parent 767f5bb0a3
commit 91101978d5
4 changed files with 9 additions and 20 deletions

View File

@ -103,7 +103,6 @@ class Relay(callbacks.Privmsg):
def __init__(self):
callbacks.Privmsg.__init__(self)
self._whois = {}
self.relayedMsgs = {}
self.lastmsg = {}
self.ircstates = {}
self.last20Privmsgs = ircutils.IrcDict()
@ -426,18 +425,12 @@ class Relay(callbacks.Privmsg):
s = '%s%s%s%s %s' % (lt, nick, network, gt, msg.args[1])
return s
def _addRelayedMsg(self, msg):
try:
self.relayedMsgs[msg] += 1
except KeyError:
self.relayedMsgs[msg] = 1
def _sendToOthers(self, irc, msg):
assert msg.command == 'PRIVMSG' or msg.command == 'TOPIC'
for otherIrc in world.ircs:
if otherIrc != irc and not otherIrc.zombie:
if msg.args[0] in otherIrc.state.channels:
self._addRelayedMsg(msg)
msg.relayedMsg = True
otherIrc.queueMsg(msg)
def _detectRelays(self, irc, msg, channel):
@ -592,19 +585,10 @@ class Relay(callbacks.Privmsg):
m = ircmsgs.privmsg(channel, s)
self._sendToOthers(irc, m)
def _isRelayedPrivmsg(self, msg):
if msg in self.relayedMsgs:
self.relayedMsgs[msg] -= 1
if not self.relayedMsgs[msg]:
del self.relayedMsgs[msg]
return True
else:
return False
def outFilter(self, irc, msg):
irc = self._getRealIrc(irc)
if msg.command == 'PRIVMSG':
if not self._isRelayedPrivmsg(msg):
if not hasattr(msg, 'relayedMsg'):
channel = msg.args[0]
if channel in self.registryValue('channels'):
network = self._getIrcName(irc)

View File

@ -209,6 +209,7 @@ def parseMsg(s):
if s:
msg = ircmsgs.IrcMsg(s)
log.stat('Time to parse IrcMsg: %s', time.time()-start)
msg.receivedAt = start
return msg
else:
return None

View File

@ -764,6 +764,8 @@ class Irc(IrcCommandDispatcher):
def feedMsg(self, msg):
"""Called by the IrcDriver; feeds a message received."""
msg.receivedOn = self.network
msg.receivedBy = self
log.debug('Incoming message: ' + str(msg).rstrip('\r\n'))
# Yeah, so this is odd. Some networks (oftc) seem to give us certain

View File

@ -81,8 +81,10 @@ class IrcMsg(object):
IrcMsg(prefix='', args=(newSource, otherMsg.args[1]), msg=otherMsg)
"""
__slots__ = ('args', 'command', 'host', 'nick', 'prefix', 'user',
'_hash', '_str', '_repr', '_len')
# It's too useful to be able to tag IrcMsg objects with extra, unforeseen
# data. Goodbye, __slots__.
# __slots__ = ('args', 'command', 'host', 'nick', 'prefix', 'user',
# '_hash', '_str', '_repr', '_len')
def __init__(self, s='', command='', args=(), prefix='', msg=None):
assert not (msg and s), 'IrcMsg.__init__ cannot accept both s and msg'
if not s and not command and not msg: