From 96b7f51e7162f540475ed9dd8763dff38a256e64 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 6 Jul 2022 22:07:37 +0200 Subject: [PATCH] callbacks: Ignore chathistory batches in PluginRegexp This is consistent with what we already do with commands; and generally makes sense, as we don't want to re-send titles and others when cycling on UnrealIRCd (which includes a chathistory batch when joining when chmode +H is set, despite umode +B) --- plugins/Owner/plugin.py | 5 +++-- src/callbacks.py | 13 +++++++++++++ test/test_callbacks.py | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index ff89c99c7..afe174033 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -309,8 +309,9 @@ class Owner(callbacks.Plugin): # 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. + # look weird, because they may have been sent a while ago, + # and we may have already answered to them. + # (this is the same behavior as in PluginRegexp.doPrivmsg) return self._doPrivmsgs(irc, msg) diff --git a/src/callbacks.py b/src/callbacks.py index 38969008b..dcccab3c5 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1804,6 +1804,19 @@ class PluginRegexp(Plugin): def doPrivmsg(self, irc, msg): if msg.isError: return + + if 'batch' in msg.server_tags: + parent_batches = irc.state.getParentBatches(msg) + parent_batch_types = [batch.type for batch in parent_batches] + if 'chathistory' in parent_batch_types: + # Either sent automatically by the server upon join, + # or triggered by a plugin (why?!) + # Either way, replying to messages from the history would + # look weird, because they may have been sent a while ago, + # and we may have already answered them. + # (this is the same behavior as in Owner.doPrivmsg) + return + proxy = self.Proxy(irc, msg) if not msg.addressed: for (r, name) in self.unaddressedRes: diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 4fac79c59..613d546a6 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -1002,6 +1002,23 @@ class PluginRegexpTestCase(ChannelPluginTestCase): args=(self.channel, 'foo baz'))) self.assertResponse(' ', 'hello') + def testIgnoreChathistory(self): + self.irc.feedMsg(ircmsgs.IrcMsg( + command='BATCH', + args=('+123', 'chathistory', self.channel))) + + self.irc.feedMsg(ircmsgs.IrcMsg( + server_tags={'batch': '123'}, + prefix=self.prefix, + command='PRIVMSG', + args=(self.channel, 'foo baz'))) + + self.irc.feedMsg(ircmsgs.IrcMsg( + command='BATCH', + args=('-123',))) + + self.assertNoResponse(' ') + class RichReplyMethodsTestCase(PluginTestCase): plugins = ('Config',) class NoCapability(callbacks.Plugin):