Skip to content

Commit 63a97fc

Browse files
committed
Owner: Ignore commands when they are in a chathistory batch.
1 parent 2236c75 commit 63a97fc

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

plugins/Owner/plugin.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,20 @@ def doBatch(self, irc, msg):
297297
self._doPrivmsgs(irc, synthetic_msg)
298298

299299
def doPrivmsg(self, irc, msg):
300-
if conf.supybot.protocols.irc.experimentalExtensions():
301-
if 'batch' in msg.server_tags \
302-
and any(batch.type =='draft/multiline'
303-
for batch in irc.state.getParentBatches(msg)):
304-
# We will handle the message in doBatch when the entire batch ends.
300+
if 'batch' in msg.server_tags:
301+
parent_batches = irc.state.getParentBatches(msg)
302+
parent_batch_types = [batch.type for batch in parent_batches]
303+
if 'draft/multiline' in parent_batch_types \
304+
and conf.supybot.protocols.irc.experimentalExtensions():
305+
# We will handle the message in doBatch when the entire
306+
# batch ends.
307+
return
308+
if 'chathistory' in parent_batch_types:
309+
# Either sent automatically by the server upon join,
310+
# or triggered by a plugin (why?!)
311+
# Either way, replying to commands from the history would
312+
# look weird, because it may have been sent a while ago,
313+
# and we may have already answered to it.
305314
return
306315

307316
self._doPrivmsgs(irc, msg)

plugins/Owner/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ def _sendBatch(self):
186186
command='BATCH',
187187
args=('-123',)))
188188

189+
def testIgnoreChathistory(self):
190+
self.irc.feedMsg(ircmsgs.IrcMsg(
191+
command='BATCH',
192+
args=('+123', 'chathistory', self.irc.nick)))
193+
194+
self.irc.feedMsg(ircmsgs.IrcMsg(
195+
server_tags={'batch': '123'},
196+
prefix=self.prefix,
197+
command='PRIVMSG',
198+
args=(self.irc.nick, 'echo foo')))
199+
200+
self.irc.feedMsg(ircmsgs.IrcMsg(
201+
command='BATCH',
202+
args=('-123',)))
203+
204+
self.irc.feedMsg(ircmsgs.IrcMsg(
205+
prefix=self.prefix,
206+
command='PRIVMSG',
207+
args=(self.irc.nick, 'echo bar')))
208+
209+
self.assertResponse('', 'bar')
210+
189211

190212

191213
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

0 commit comments

Comments
 (0)