mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Added IrcMsg attribute tagging, and used it in some places.
This commit is contained in:
parent
767f5bb0a3
commit
91101978d5
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user