Misc: Clamp the number of lines returned by @more to the draft/multiline max-lines value, if any.

This commit is contained in:
Valentin Lorentz 2021-03-13 19:49:05 +01:00
parent bbc2e9de0d
commit 91a4083ae1
2 changed files with 54 additions and 3 deletions

View File

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

View File

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