diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index c88659477..522968098 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -389,13 +389,22 @@ class Misc(callbacks.Plugin): 'to see someone else\'s more. To do so, call this ' 'command with that person\'s nick.'), Raise=True) number = self.registryValue('mores', msg.channel, irc.network) + + if conf.supybot.protocols.irc.experimentalExtensions() \ + and 'draft/multiline' in irc.state.capabilities_ack: + use_multiline = True + multiline_cap_values = ircutils.parseCapabilityKeyValue( + irc.state.capabilities_ls['draft/multiline']) + if multiline_cap_values.get('max-lines', '').isnumeric(): + number = min(number, int(multiline_cap_values['max-lines'])) + else: + use_multiline = False + msgs = L[-number:] msgs.reverse() L[-number:] = [] if msgs: - if conf.supybot.protocols.irc.experimentalExtensions() \ - and 'draft/multiline' in irc.state.capabilities_ack \ - and len(msgs) > 1: + if use_multiline and len(msgs) > 1: # If draft/multiline is available, use it. # TODO: set concat=True. For now we can't, because every # message has "(XX more messages)" at the end, so it would be diff --git a/plugins/Misc/test.py b/plugins/Misc/test.py index 736185f2c..25fae3753 100644 --- a/plugins/Misc/test.py +++ b/plugins/Misc/test.py @@ -277,6 +277,48 @@ class MiscTestCase(ChannelPluginTestCase): m, ircmsgs.IrcMsg(command='BATCH', args=( '-' + batch_name,))) + def testMoreBatchMaxLines(self): + self.irc.state.capabilities_ack.add('batch') + self.irc.state.capabilities_ack.add('draft/multiline') + self.irc.state.capabilities_ls['draft/multiline'] = \ + 'max-bytes=4096,max-lines=2' + with conf.supybot.protocols.irc.experimentalExtensions.context(True): + with conf.supybot.plugins.Misc.mores.context(3): + self.assertResponse('echo %s' % ('abc '*400), + 'abc '*112 + ' \x02(3 more messages)\x02') + self.irc.feedMsg(ircmsgs.privmsg( + self.channel, "@more", prefix=self.prefix)) + + # First message opens the batch + m = self.irc.takeMsg() + self.assertEqual(m.command, 'BATCH', m) + batch_name = m.args[0][1:] + self.assertEqual( + m, ircmsgs.IrcMsg(command='BATCH', + args=('+' + batch_name, + 'draft/multiline', self.channel))) + + # Second message, first PRIVMSG + m = self.irc.takeMsg() + self.assertEqual( + m, ircmsgs.IrcMsg(command='PRIVMSG', + args=(self.channel, "abc " * 112 + " \x02(2 more messages)\x02"), + server_tags={'batch': batch_name})) + + # Third message, last PRIVMSG + m = self.irc.takeMsg() + self.assertEqual( + m, ircmsgs.IrcMsg(command='PRIVMSG', + args=(self.channel, + "abc " * 112 + " \x02(1 more message)\x02"), + server_tags={'batch': batch_name})) + + # Last message, closes the batch + m = self.irc.takeMsg() + self.assertEqual( + m, ircmsgs.IrcMsg(command='BATCH', args=( + '-' + batch_name,))) + def testClearMores(self): self.assertRegexp('echo %s' % ('abc'*700), 'more') self.assertRegexp('more', 'more')