Owner: Ignore commands when they are in a chathistory batch.

This commit is contained in:
Valentin Lorentz 2021-11-18 13:17:39 +01:00
parent 2236c7552a
commit 63a97fc147
2 changed files with 36 additions and 5 deletions

View File

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

View File

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