From 63a97fc147b645035ce4b86308e9e6139e3e1a2a Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 18 Nov 2021 13:17:39 +0100 Subject: [PATCH] Owner: Ignore commands when they are in a chathistory batch. --- plugins/Owner/plugin.py | 19 ++++++++++++++----- plugins/Owner/test.py | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index 6423d17fb..ff89c99c7 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -297,11 +297,20 @@ class Owner(callbacks.Plugin): self._doPrivmsgs(irc, synthetic_msg) def doPrivmsg(self, irc, msg): - if conf.supybot.protocols.irc.experimentalExtensions(): - if 'batch' in msg.server_tags \ - and any(batch.type =='draft/multiline' - for batch in irc.state.getParentBatches(msg)): - # We will handle the message in doBatch when the entire batch ends. + if 'batch' in msg.server_tags: + parent_batches = irc.state.getParentBatches(msg) + parent_batch_types = [batch.type for batch in parent_batches] + if 'draft/multiline' in parent_batch_types \ + and conf.supybot.protocols.irc.experimentalExtensions(): + # We will handle the message in doBatch when the entire + # batch ends. + return + if 'chathistory' in parent_batch_types: + # Either sent automatically by the server upon join, + # or triggered by a plugin (why?!) + # Either way, replying to commands from the history would + # look weird, because it may have been sent a while ago, + # and we may have already answered to it. return self._doPrivmsgs(irc, msg) diff --git a/plugins/Owner/test.py b/plugins/Owner/test.py index b3152d1d7..c15f0fb90 100644 --- a/plugins/Owner/test.py +++ b/plugins/Owner/test.py @@ -186,6 +186,28 @@ class CommandsTestCase(PluginTestCase): command='BATCH', args=('-123',))) + def testIgnoreChathistory(self): + self.irc.feedMsg(ircmsgs.IrcMsg( + command='BATCH', + args=('+123', 'chathistory', self.irc.nick))) + + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'batch': '123'}, + prefix=self.prefix, + command='PRIVMSG', + args=(self.irc.nick, 'echo foo'))) + + self.irc.feedMsg(ircmsgs.IrcMsg( + command='BATCH', + args=('-123',))) + + self.irc.feedMsg(ircmsgs.IrcMsg( + prefix=self.prefix, + command='PRIVMSG', + args=(self.irc.nick, 'echo bar'))) + + self.assertResponse('', 'bar') + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: