From 86b389618f61b330da67aa698651698bb62eda30 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 16 Aug 2022 00:23:33 +0200 Subject: [PATCH] MessageParser: Ignore chathistory batches To be consistent with commands and PluginRegexp (snarfers) --- plugins/MessageParser/plugin.py | 14 ++++++++++++++ plugins/MessageParser/test.py | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index bbb8ae0a5..981f3a70b 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -163,6 +163,20 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): channel = msg.channel if not channel: 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 and + # PluginRegexp.doPrivmsg) + return + if self.registryValue('enable', channel, irc.network): actions = [] results = [] diff --git a/plugins/MessageParser/test.py b/plugins/MessageParser/test.py index b460868fd..f65c7d0bd 100644 --- a/plugins/MessageParser/test.py +++ b/plugins/MessageParser/test.py @@ -116,10 +116,31 @@ class MessageParserTestCase(ChannelPluginTestCase): def testTrigger(self): self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') - self.feedMsg('this message has some stuff in it') + self.irc.feedMsg(ircmsgs.IrcMsg( + prefix=self.prefix, + command='PRIVMSG', + args=(self.channel, 'this message has some stuff in it'))) m = self.getMsg(' ') self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some stuff')) + def testIgnoreChathistory(self): + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + + 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, 'this message has some stuff in it'))) + self.irc.feedMsg(ircmsgs.IrcMsg( + command='BATCH', + args=('-123',))) + + m = self.getMsg(' ') + self.assertFalse(m) + def testMaxTriggers(self): self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertNotError('messageparser add "sbd" "echo i saw somebody"')