From 3eb20adaf23e47cfaf2d5453896a446bc563e179 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 11 Apr 2020 16:40:03 +0200 Subject: [PATCH] Fix extra arguments to irc.reply() being ignored by messages returned by '@more'. This change builds all the ircmsg objects directly in irc.reply, with the original arguments. A side effect is that if a config var is changed between the initial command call and the call to '@more', this commit makes it use the old values, but that shouldn't be too much of an issue. Closes GH-1405. --- plugins/Misc/plugin.py | 15 +++++---------- plugins/Misc/test.py | 8 ++++---- src/callbacks.py | 36 ++++++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 7b605a1dc..237bb1513 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -386,17 +386,12 @@ 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) - chunks = L[-number:] - chunks.reverse() + msgs = L[-number:] + msgs.reverse() L[-number:] = [] - if chunks: - if L: - if len(L) < 2: - more = _('1 more message') - else: - more = _('%i more messages') % len(L) - chunks[-1] += format(' \x02(%s)\x0F', more) - irc.replies(chunks, noLengthCheck=True, oneToOne=False) + if msgs: + for msg in msgs: + irc.queueMsg(msg) 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 f13a88909..d0a20fc2a 100644 --- a/plugins/Misc/test.py +++ b/plugins/Misc/test.py @@ -212,9 +212,9 @@ class MiscTestCase(ChannelPluginTestCase): self.assertResponse('echo %s' % ('abc '*400), 'abc '*112 + ' \x02(3 more messages)\x02') self.assertResponse('more', - 'abc '*112 + ' \x02(2 more messages)\x0f') + 'abc '*112 + ' \x02(2 more messages)\x02') self.assertResponse('more', - 'abc '*112 + ' \x02(1 more message)\x0f') + 'abc '*112 + ' \x02(1 more message)\x02') self.assertResponse('more', ' '.join(['abc']*(400-112*3))) self.assertResponse('more', @@ -225,12 +225,12 @@ class MiscTestCase(ChannelPluginTestCase): self.assertResponse('echo %s' % ('abc '*400), 'abc '*112 + ' \x02(3 more messages)\x02') self.assertResponse('more', - 'abc '*112) + 'abc '*112 + ' \x02(2 more messages)\x02') m = self.irc.takeMsg() self.assertIsNot(m, None) self.assertEqual( m.args[1], - self.nick + ': ' + 'abc '*112 + ' \x02(1 more message)\x0f') + 'abc '*112 + ' \x02(1 more message)\x02') self.assertResponse('more', ' '.join(['abc']*(400-112*3))) self.assertResponse('more', diff --git a/src/callbacks.py b/src/callbacks.py index ea51d640f..6a2151b5c 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -968,15 +968,31 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): # The '(XX more messages)' may have not the same # length in the current locale allowedLength -= len(_('(XX more messages)')) + 1 # bold - msgs = ircutils.wrap(s, allowedLength) - msgs.reverse() + chunks = ircutils.wrap(s, allowedLength) + + # Last messages to display at the beginning of the list + # (which is used like a stack) + chunks.reverse() + + msgs = [] + for (i, chunk) in enumerate(chunks): + if i == 0: + pass # last message, no suffix to add + else: + if i == 1: + more = _('more message') + else: + more = _('more messages') + n = ircutils.bold('(%i %s)' % (len(msgs), more)) + chunk = '%s %s' % (chunk, n) + msgs.append(_makeReply(self, msg, chunk, **replyArgs)) + instant = conf.get(conf.supybot.reply.mores.instant, channel=target, network=self.irc.network) while instant > 1 and msgs: instant -= 1 response = msgs.pop() - m = _makeReply(self, msg, response, **replyArgs) - sendMsg(m) + sendMsg(response) # XXX We should somehow allow these to be returned, but # until someone complains, we'll be fine :) We # can't return from here, though, for obvious @@ -985,13 +1001,6 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): if not msgs: return response = msgs.pop() - if msgs: - if len(msgs) == 1: - more = _('more message') - else: - more = _('more messages') - n = ircutils.bold('(%i %s)' % (len(msgs), more)) - response = '%s %s' % (response, n) prefix = msg.prefix if self.to and ircutils.isNick(self.to): try: @@ -1004,9 +1013,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): public = bool(self.msg.channel) private = self.private or not public self._mores[msg.nick] = (private, msgs) - m = _makeReply(self, msg, response, **replyArgs) - sendMsg(m) - return m + sendMsg(response) + return response finally: self._resetReplyAttributes() else: