Misc: Fix drop of the last (nb_mores % plugins.Misc.mores) messages.

If the last batch had less than plugins.Misc.mores messages;
getting the last messages of the batch would raise an IndexError,
causing the whole batch to be dropped.
This commit is contained in:
Valentin Lorentz 2020-04-11 16:13:06 +02:00
parent f19079c75e
commit 5e91a68ab0
2 changed files with 12 additions and 7 deletions

View File

@ -381,8 +381,15 @@ class Misc(callbacks.Plugin):
return
try:
L = irc._mores[userHostmask]
except KeyError:
irc.error(_('You haven\'t asked me a command; perhaps you want '
'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)
chunks = [L.pop() for x in range(0, number)]
chunks = L[-number:]
chunks.reverse()
L[-number:] = []
if chunks:
if L:
if len(L) < 2:
more = _('1 more message')
@ -390,11 +397,7 @@ class Misc(callbacks.Plugin):
more = _('%i more messages') % len(L)
chunks[-1] += format(' \x02(%s)\x0F', more)
irc.replies(chunks, noLengthCheck=True, oneToOne=False)
except KeyError:
irc.error(_('You haven\'t asked me a command; perhaps you want '
'to see someone else\'s more. To do so, call this '
'command with that person\'s nick.'))
except IndexError:
else:
irc.error(_('That\'s all, there is no more.'))
more = wrap(more, [additional('seenNick')])

View File

@ -231,6 +231,8 @@ class MiscTestCase(ChannelPluginTestCase):
self.assertEqual(
m.args[1],
self.nick + ': ' + 'abc '*112 + ' \x02(1 more message)\x0f')
self.assertResponse('more',
' '.join(['abc']*(400-112*3)))
self.assertResponse('more',
"Error: That's all, there is no more.")