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.
This commit is contained in:
Valentin Lorentz 2020-04-11 16:40:03 +02:00
parent 61b47bb65b
commit 3eb20adaf2
3 changed files with 31 additions and 28 deletions

View File

@ -386,17 +386,12 @@ class Misc(callbacks.Plugin):
'to see someone else\'s more. To do so, call this ' 'to see someone else\'s more. To do so, call this '
'command with that person\'s nick.'), Raise=True) 'command with that person\'s nick.'), Raise=True)
number = self.registryValue('mores', msg.channel, irc.network) number = self.registryValue('mores', msg.channel, irc.network)
chunks = L[-number:] msgs = L[-number:]
chunks.reverse() msgs.reverse()
L[-number:] = [] L[-number:] = []
if chunks: if msgs:
if L: for msg in msgs:
if len(L) < 2: irc.queueMsg(msg)
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)
else: else:
irc.error(_('That\'s all, there is no more.')) irc.error(_('That\'s all, there is no more.'))
more = wrap(more, [additional('seenNick')]) more = wrap(more, [additional('seenNick')])

View File

@ -212,9 +212,9 @@ class MiscTestCase(ChannelPluginTestCase):
self.assertResponse('echo %s' % ('abc '*400), self.assertResponse('echo %s' % ('abc '*400),
'abc '*112 + ' \x02(3 more messages)\x02') 'abc '*112 + ' \x02(3 more messages)\x02')
self.assertResponse('more', self.assertResponse('more',
'abc '*112 + ' \x02(2 more messages)\x0f') 'abc '*112 + ' \x02(2 more messages)\x02')
self.assertResponse('more', self.assertResponse('more',
'abc '*112 + ' \x02(1 more message)\x0f') 'abc '*112 + ' \x02(1 more message)\x02')
self.assertResponse('more', self.assertResponse('more',
' '.join(['abc']*(400-112*3))) ' '.join(['abc']*(400-112*3)))
self.assertResponse('more', self.assertResponse('more',
@ -225,12 +225,12 @@ class MiscTestCase(ChannelPluginTestCase):
self.assertResponse('echo %s' % ('abc '*400), self.assertResponse('echo %s' % ('abc '*400),
'abc '*112 + ' \x02(3 more messages)\x02') 'abc '*112 + ' \x02(3 more messages)\x02')
self.assertResponse('more', self.assertResponse('more',
'abc '*112) 'abc '*112 + ' \x02(2 more messages)\x02')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.assertIsNot(m, None) self.assertIsNot(m, None)
self.assertEqual( self.assertEqual(
m.args[1], m.args[1],
self.nick + ': ' + 'abc '*112 + ' \x02(1 more message)\x0f') 'abc '*112 + ' \x02(1 more message)\x02')
self.assertResponse('more', self.assertResponse('more',
' '.join(['abc']*(400-112*3))) ' '.join(['abc']*(400-112*3)))
self.assertResponse('more', self.assertResponse('more',

View File

@ -968,15 +968,31 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
# The '(XX more messages)' may have not the same # The '(XX more messages)' may have not the same
# length in the current locale # length in the current locale
allowedLength -= len(_('(XX more messages)')) + 1 # bold allowedLength -= len(_('(XX more messages)')) + 1 # bold
msgs = ircutils.wrap(s, allowedLength) chunks = ircutils.wrap(s, allowedLength)
msgs.reverse()
# 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, instant = conf.get(conf.supybot.reply.mores.instant,
channel=target, network=self.irc.network) channel=target, network=self.irc.network)
while instant > 1 and msgs: while instant > 1 and msgs:
instant -= 1 instant -= 1
response = msgs.pop() response = msgs.pop()
m = _makeReply(self, msg, response, **replyArgs) sendMsg(response)
sendMsg(m)
# XXX We should somehow allow these to be returned, but # XXX We should somehow allow these to be returned, but
# until someone complains, we'll be fine :) We # until someone complains, we'll be fine :) We
# can't return from here, though, for obvious # can't return from here, though, for obvious
@ -985,13 +1001,6 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
if not msgs: if not msgs:
return return
response = msgs.pop() 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 prefix = msg.prefix
if self.to and ircutils.isNick(self.to): if self.to and ircutils.isNick(self.to):
try: try:
@ -1004,9 +1013,8 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
public = bool(self.msg.channel) public = bool(self.msg.channel)
private = self.private or not public private = self.private or not public
self._mores[msg.nick] = (private, msgs) self._mores[msg.nick] = (private, msgs)
m = _makeReply(self, msg, response, **replyArgs) sendMsg(response)
sendMsg(m) return response
return m
finally: finally:
self._resetReplyAttributes() self._resetReplyAttributes()
else: else: