mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 19:14:09 +01:00
ChannelLogger: rewrite relayed messages echoed by the server
The former code worked only with emulated echo-message, as it depends on internal tags. In case echo-message (and labeled-response) is enabled, rely on remembering the label instead.
This commit is contained in:
parent
91d2a2860f
commit
f253da049d
@ -68,6 +68,10 @@ class ChannelLogger(callbacks.Plugin):
|
||||
self.flusher = self.flush
|
||||
world.flushers.append(self.flusher)
|
||||
|
||||
# 10 minutes is long enough to be confident the server won't send
|
||||
# messages after they timeouted.
|
||||
self._emitted_relayed_msgs = utils.structures.ExpiringDict(10*60)
|
||||
|
||||
def die(self):
|
||||
for log in self._logs():
|
||||
log.close()
|
||||
@ -190,7 +194,19 @@ class ChannelLogger(callbacks.Plugin):
|
||||
nick = msg.nick or irc.nick
|
||||
rewriteRelayed = self.registryValue('rewriteRelayed',
|
||||
channel, irc.network)
|
||||
if rewriteRelayed and msg.tagged('ChannelLogger__relayed'):
|
||||
if msg.tagged('ChannelLogger__relayed'):
|
||||
wasRelayed = True
|
||||
elif 'label' in msg.server_tags:
|
||||
label = msg.server_tags['label']
|
||||
if label in self._emitted_relayed_msgs:
|
||||
del self._emitted_relayed_msgs[label]
|
||||
wasRelayed = True
|
||||
else:
|
||||
wasRelayed = False
|
||||
else:
|
||||
wasRelayed = False
|
||||
|
||||
if rewriteRelayed and wasRelayed:
|
||||
(nick, text) = text.split(' ', 1)
|
||||
nick = nick[1:-1]
|
||||
msg.args = (recipients, text)
|
||||
@ -284,9 +300,24 @@ class ChannelLogger(callbacks.Plugin):
|
||||
# Gotta catch my own messages *somehow* :)
|
||||
# Let's try this little trick...
|
||||
if msg.command in ('PRIVMSG', 'NOTICE'):
|
||||
# Other messages should be sent back to us.
|
||||
if msg.tagged('relayedMsg'):
|
||||
msg.tag('ChannelLogger__relayed')
|
||||
rewriteRelayed = self.registryValue(
|
||||
'rewriteRelayed', msg.channel, irc.network)
|
||||
if rewriteRelayed and 'echo-message' in self.state.capabilities_ack:
|
||||
assert 'labeled-response' in self.state.capabilities_ack, \
|
||||
'echo-message was negotiated without labeled-response.'
|
||||
# If we negotiated the echo-message cap, we have to remember
|
||||
# this message was relayed when the server sends it back to us.
|
||||
if 'label' not in msg.server_tags:
|
||||
msg.server_tags['label'] = ircutils.makeLabel()
|
||||
if msg.tagged('relayedMsg'):
|
||||
# Remember this was a relayed message, in case
|
||||
# rewriteRelayed is True.
|
||||
self._emitted_relayed_msgs[msg.server_tags['label']] = True
|
||||
else:
|
||||
# Else, we can simply rely on internal tags, because echos are
|
||||
# simulated.
|
||||
if msg.tagged('relayedMsg'):
|
||||
m.tag('ChannelLogger__relayed')
|
||||
return msg
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user