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)
This commit is contained in:
Valentin Lorentz 2022-07-06 22:07:37 +02:00
parent 3ecb37de10
commit 96b7f51e71
3 changed files with 33 additions and 2 deletions

View File

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

View File

@ -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:

View File

@ -1002,6 +1002,23 @@ class PluginRegexpTestCase(ChannelPluginTestCase):
args=(self.channel, 'foo <bar> 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 <bar> baz')))
self.irc.feedMsg(ircmsgs.IrcMsg(
command='BATCH',
args=('-123',)))
self.assertNoResponse(' ')
class RichReplyMethodsTestCase(PluginTestCase):
plugins = ('Config',)
class NoCapability(callbacks.Plugin):