mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Redesign the message truncation algorithm.
This commit is contained in:
parent
1f400e4020
commit
7cc7b4fac9
@ -905,11 +905,15 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
allowedLength = conf.get(conf.supybot.reply.mores.length,
|
allowedLength = conf.get(conf.supybot.reply.mores.length,
|
||||||
target)
|
target)
|
||||||
if not allowedLength: # 0 indicates this.
|
if not allowedLength: # 0 indicates this.
|
||||||
allowedLength = 470 - len(self.irc.prefix)
|
allowedLength = (512
|
||||||
allowedLength -= len(msg.nick)
|
- len(':') - len(self.irc.prefix)
|
||||||
# The '(XX more messages)' may have not the same
|
- len(' PRIVMSG ')
|
||||||
# length in the current locale
|
- len(target)
|
||||||
allowedLength -= len(_('(XX more messages)'))
|
- len(' :')
|
||||||
|
- len('\r\n')
|
||||||
|
)
|
||||||
|
if self.prefixNick:
|
||||||
|
allowedLength -= len(msg.nick) + len(': ')
|
||||||
maximumMores = conf.get(conf.supybot.reply.mores.maximum,
|
maximumMores = conf.get(conf.supybot.reply.mores.maximum,
|
||||||
target)
|
target)
|
||||||
maximumLength = allowedLength * maximumMores
|
maximumLength = allowedLength * maximumMores
|
||||||
@ -920,16 +924,6 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
s_size = len(s.encode()) if minisix.PY3 else len(s)
|
s_size = len(s.encode()) if minisix.PY3 else len(s)
|
||||||
if s_size <= allowedLength or \
|
if s_size <= allowedLength or \
|
||||||
not conf.get(conf.supybot.reply.mores, target):
|
not conf.get(conf.supybot.reply.mores, target):
|
||||||
# In case we're truncating, we add 20 to allowedLength,
|
|
||||||
# because our allowedLength is shortened for the
|
|
||||||
# "(XX more messages)" trailer.
|
|
||||||
if minisix.PY3:
|
|
||||||
appended = _('(XX more messages)').encode()
|
|
||||||
s = s.encode()[:allowedLength-len(appended)]
|
|
||||||
s = s.decode('utf8', 'ignore')
|
|
||||||
else:
|
|
||||||
appended = _('(XX more messages)')
|
|
||||||
s = s[:allowedLength-len(appended)]
|
|
||||||
# There's no need for action=self.action here because
|
# There's no need for action=self.action here because
|
||||||
# action implies noLengthCheck, which has already been
|
# action implies noLengthCheck, which has already been
|
||||||
# handled. Let's stick an assert in here just in case.
|
# handled. Let's stick an assert in here just in case.
|
||||||
@ -941,6 +935,9 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
stripCtcp=stripCtcp)
|
stripCtcp=stripCtcp)
|
||||||
sendMsg(m)
|
sendMsg(m)
|
||||||
return m
|
return m
|
||||||
|
# The '(XX more messages)' may have not the same
|
||||||
|
# length in the current locale
|
||||||
|
allowedLength -= len(_('(XX more messages)'))
|
||||||
msgs = ircutils.wrap(s, allowedLength)
|
msgs = ircutils.wrap(s, allowedLength)
|
||||||
msgs.reverse()
|
msgs.reverse()
|
||||||
instant = conf.get(conf.supybot.reply.mores.instant,target)
|
instant = conf.get(conf.supybot.reply.mores.instant,target)
|
||||||
|
Loading…
Reference in New Issue
Block a user