Add labels to outgoing messages when labeled-response is supported.

This is going to be useful for implementing echo-message; and to plugins
targetting only networks with labeled-response support.
This commit is contained in:
Valentin Lorentz 2020-05-07 20:56:59 +02:00
parent bb063b8064
commit 572c609181
2 changed files with 20 additions and 1 deletions

View File

@ -1040,6 +1040,13 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
self.outstandingPing = True
self.queueMsg(ircmsgs.ping(now))
if msg:
if not world.testing and 'label' not in msg.server_tags \
and 'labeled-response' in self.state.capabilities_ack:
# Not adding labels while testing, because it would break
# all plugin tests using IrcMsg equality (unless they
# explicitly add the label, but it becomes a burden).
msg.server_tags['label'] = ircutils.makeLabel()
msg._len = msg._str = None
for callback in reversed(self.callbacks):
self._setMsgChannel(msg)
msg = callback.outFilter(self, msg)
@ -1247,7 +1254,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
'multi-prefix', 'metadata-notify', 'account-tag',
'userhost-in-names', 'invite-notify', 'server-time',
'chghost', 'batch', 'away-notify', 'message-tags',
'msgid', 'setname'])
'msgid', 'setname', 'labeled-response'])
def _queueConnectMessages(self):
if self.zombie:

View File

@ -41,6 +41,7 @@ from __future__ import print_function
import re
import sys
import time
import uuid
import base64
import random
import string
@ -960,6 +961,17 @@ def parseStsPolicy(logger, policy, parseDuration):
return parsed_policy
def makeLabel():
"""Returns a unique label for outgoing message tags.
Unicity is not guaranteed across restarts.
Returns should be handled as opaque strings, using only equality.
This is used for <https://ircv3.net/specs/extensions/labeled-response>
"""
return str(uuid.uuid4())
numerics = {
# <= 2.10
# Reply