MessageParser: Ignore chathistory batches

To be consistent with commands and PluginRegexp (snarfers)
This commit is contained in:
Valentin Lorentz 2022-08-16 00:23:33 +02:00
parent fccb4f705b
commit 86b389618f
2 changed files with 36 additions and 1 deletions

View File

@ -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 = []

View File

@ -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"')