From 6f4e3a2dbd8410fd909b9762343450901300bdc3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 15 May 2020 18:17:34 +0200 Subject: [PATCH] QuoteGrabs: Add support for +draft/reply to point to the message to grab. --- plugins/QuoteGrabs/plugin.py | 6 ++++++ plugins/QuoteGrabs/test.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/plugins/QuoteGrabs/plugin.py b/plugins/QuoteGrabs/plugin.py index fde14a069..eae943356 100644 --- a/plugins/QuoteGrabs/plugin.py +++ b/plugins/QuoteGrabs/plugin.py @@ -287,7 +287,13 @@ class QuoteGrabs(callbacks.Plugin): raise callbacks.ArgumentError if ircutils.nickEqual(nick, msg.nick): irc.error(_('You can\'t quote grab yourself.'), Raise=True) + if conf.supybot.protocols.irc.experimentalExtensions(): + msgid = msg.server_tags.get('+draft/reply') + else: + msgid = None for m in reversed(irc.state.history): + if msgid and m.server_tags.get('msgid') != msgid: + continue if m.command == 'PRIVMSG' and ircutils.nickEqual(m.nick, nick) \ and ircutils.strEqual(m.args[0], chan): # TODO: strip statusmsg prefix for comparison? Must be careful diff --git a/plugins/QuoteGrabs/test.py b/plugins/QuoteGrabs/test.py index 87e759673..34b45761e 100644 --- a/plugins/QuoteGrabs/test.py +++ b/plugins/QuoteGrabs/test.py @@ -51,6 +51,41 @@ class QuoteGrabsTestCase(ChannelPluginTestCase): self.assertNotError('grab foo') self.assertResponse('quote foo', '* foo moos') + def testQuoteGrabReplyDisabled(self): + testPrefix = 'foo!bar@baz' + prefixChar = conf.supybot.reply.whenAddressedBy.chars()[0] + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'msgid': 'aaaa'}, prefix=testPrefix, + command='PRIVMSG', args=(self.channel, 'something'))) + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'msgid': 'bbbb'}, prefix=testPrefix, + command='PRIVMSG', args=(self.channel, 'something else'))) + + # supybot.protocols.irc.experimentalExtensions is not enabled, so + # +draft/reply is ignored. + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'+draft/reply': 'aaaa'}, prefix=self.prefix, + command='PRIVMSG', args=(self.channel, prefixChar+'grab foo'))) + self.assertResponse(' ', 'The operation succeeded.') + self.assertResponse('quote foo', ' something else') + + def testQuoteGrabReply(self): + testPrefix = 'foo!bar@baz' + prefixChar = conf.supybot.reply.whenAddressedBy.chars()[0] + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'msgid': 'aaaa'}, prefix=testPrefix, + command='PRIVMSG', args=(self.channel, 'something'))) + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'msgid': 'bbbb'}, prefix=testPrefix, + command='PRIVMSG', args=(self.channel, 'something else'))) + + with conf.supybot.protocols.irc.experimentalExtensions.context(True): + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'+draft/reply': 'aaaa'}, prefix=self.prefix, + command='PRIVMSG', args=(self.channel, prefixChar+'grab foo'))) + self.assertResponse(' ', 'The operation succeeded.') + self.assertResponse('quote foo', ' something') + def testUngrab(self): testPrefix = 'foo!bar@baz' # nothing yet