From 5e91a68ab0b24db9484e9eb8b3e0826d40801bd0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 11 Apr 2020 16:13:06 +0200 Subject: [PATCH] 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. --- plugins/Misc/plugin.py | 17 ++++++++++------- plugins/Misc/test.py | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 02b1ff9ab..7b605a1dc 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -381,8 +381,15 @@ class Misc(callbacks.Plugin): return try: L = irc._mores[userHostmask] - number = self.registryValue('mores', msg.channel, irc.network) - chunks = [L.pop() for x in range(0, number)] + 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[-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')]) diff --git a/plugins/Misc/test.py b/plugins/Misc/test.py index a31a000bf..f13a88909 100644 --- a/plugins/Misc/test.py +++ b/plugins/Misc/test.py @@ -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.")