From 109f938b0c9423885b8726c2d3f5dc238a4c2f30 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 22 Apr 2022 18:30:31 +0200 Subject: [PATCH] Implement +draft/channel-context --- src/callbacks.py | 4 ++++ test/test_callbacks.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/callbacks.py b/src/callbacks.py index 02f7e08a4..38969008b 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -256,6 +256,10 @@ def _makeReply(irc, msg, s, # no harm in doing this extra check, in case a plugin is replying # across network (as it may happen with '@network command'). ret.server_tags['+draft/reply'] = msg.server_tags['msgid'] + if msg.channel and not irc.isChannel(ret.args[0]): + # If replying in non-channel to a channel message, use the tag + # defined in https://github.com/ircv3/ircv3-specifications/pull/498 + ret.server_tags["+draft/channel-context"] = msg.channel return ret def error(*args, **kwargs): diff --git a/test/test_callbacks.py b/test/test_callbacks.py index fbd580e35..38e03555d 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -634,6 +634,51 @@ class PrivmsgTestCase(ChannelPluginTestCase): finally: self.irc.state.capabilities_ack.remove('message-tags') + def testClientTagReplyChannel(self): + self.irc.addCallback(self.First(self.irc)) + + try: + conf.supybot.protocols.irc.experimentalExtensions.setValue(True) + self.irc.state.capabilities_ack.add('message-tags') + + # Reply in channel to channel message -> +draft/channel-context + # is absent + self.irc.feedMsg(ircmsgs.IrcMsg( + command='PRIVMSG', prefix=self.prefix, + args=('#foo', '%s: firstcmd' % self.nick), + server_tags={'msgid': 'foobar'})) + msg = self.irc.takeMsg() + self.assertEqual(msg, ircmsgs.IrcMsg( + command='PRIVMSG', args=('#foo', '%s: foo' % self.nick), + server_tags={'+draft/reply': 'foobar'})) + + # Reply in private to channel message -> +draft/channel-context + # is present + with conf.supybot.reply.inPrivate.context(True): + self.irc.feedMsg(ircmsgs.IrcMsg( + command='PRIVMSG', prefix=self.prefix, + args=('#foo', '%s: firstcmd' % self.nick), + server_tags={'msgid': 'foobar'})) + msg = self.irc.takeMsg() + self.assertEqual(msg, ircmsgs.IrcMsg( + command='NOTICE', args=(self.nick, 'foo'), + server_tags={'+draft/reply': 'foobar', + '+draft/channel-context': '#foo'})) + + # Reply in private to private message -> +draft/channel-context + # is absent + self.irc.feedMsg(ircmsgs.IrcMsg( + command='PRIVMSG', prefix=self.prefix, + args=(self.nick, 'firstcmd'), + server_tags={'msgid': 'foobar'})) + msg = self.irc.takeMsg() + self.assertEqual(msg, ircmsgs.IrcMsg( + command='NOTICE', args=(self.nick, 'foo'), + server_tags={'+draft/reply': 'foobar'})) + finally: + conf.supybot.protocols.irc.experimentalExtensions.setValue(False) + self.irc.state.capabilities_ack.remove('message-tags') + class TwoRepliesFirstAction(callbacks.Plugin): def testactionreply(self, irc, msg, args): irc.reply('foo', action=True)