-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bot, irc: in bot.say()
, fill IRC line if possible & add optional truncation indicator
#1958
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going in the right direction, and I think that shouldn't be a problem for you.
I also want to add a quick note about message tags, from https://ircv3.net/specs/extensions/message-tags.html#size-limit
The size limit for message tags is 8191 bytes, including the leading '@' (0x40) and trailing space ' ' (0x20) characters. The size limit for the rest of the message remains unchanged at 512 bytes.
Which is great, I was worried at first that message tags could have a negative effect on this safe length, but that's not the case!
So: yay! Great PR, well done!
This is some quality effort, and something I've wanted for a long time.
|
@Exirel Changes to address your review nitpicks are running CI now. Good call on the extra Unicode @deathbybandaid Yeah, I really don't think Maybe I should build another PR off of this one to make output prefix behave better on split messages, though? I'm still not sure if the current "first message only" prefixing is good enough, or if it should add the prefix to every line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
I still think that 1. more than one line is an edge case and doesn't matter that much and 2. I prefer the prefix for the first message only. |
Nice, new test case covered nicely. Well done again! |
Not quite ready to make this the default behavior, but plugins that make use of `max_messages` are rare enough that we can beta-test it there.
New optional parameter to `bot.say()` allows specifying a suffix that Sopel will append to a message if it's too long to fit in the specified number of `max_messages` (including the default of 1).
Co-authored-by: Exirel <florian.strzelecki@gmail.com>
The new test fails without the change in `irc` itself, proving that the previous algorithm would incorrectly split if the recipient's name contained characters that get sent as multiple bytes in UTF-8.
3ce465c
to
830fbef
Compare
Description
By way of killing (or at least gravely wounding) two birds with one stone, this is my valiant attempt to resolve #1328, and also close #1322—which was left open pending a change like this to make use of the stored hostmask when sending messages. (I say "attempt" mostly because certain @sopel-irc/rockstars might disagree with subtle code style decisions I made; the new logic itself is almost fully covered by new or updated unit tests.)
bot.say()
now has the ability to calculate asafe_length
for messages, and use that instead of the arbitrary default value of 400 fromtools.get_sendable_message()
. There is also a new optional parameter,trailing
, which replicates a common pattern I've seen in my own and other plugins to append some arbitrary "continuation string" to a message that was too long. (Alternative parameter name suggestions welcome; that's just the best I could think up.)For plugin authors, use of the new
trailing
parameter replaces manually callingtools.get_sendable_message()
with some arbitrary length value that "should be" short enough to avoid truncation by the server, and leaves truncating the message to Sopel—which knows its own nick, ident, and hopefully hostmask. If Sopel's hostmask is not known, a worst-case maximum length is used instead (thanks to @deathbybandaid for #1322 (comment), which got me 90% of the way there). The worst-case maximum tries to be as comprehensive as possible, taking advantage of theUSERLEN
token inISUPPORT
if sent by the server, RFC maximum lengths for the hostname and ident, and Sopel's configured ident & nickname values.*This also kind of addresses part of #1559, regarding calculating the penalty based on only the truncated message body, in the case where
(max_messages > 1) or trailing
would evaluate toTrue
during execution ofbot.say()
.The new truncation behavior is explicitly not enabled for the most basic usage of
bot.say()
yet, as noted in the commit log. We are limiting the potential impact of this behavior change in 7.x to existing plugins that already expressed some concern for over-length messages via use ofmax_messages
, and new/updated plugins that opt-in to the newtrailing
behavior.Checklist
make qa
(runsmake quality
andmake test
)Next steps
Future PRs may:
safe_length
for all calls tobot.say()
bot.action()
,bot.notice()
, and possibly even other commands that take text arguments such as KICK/TOPICmax_messages
and/ortrailing
parameters to other messaging functions (e.g.bot.notice()
orbot.reply()
; onlytrailing
would make sense forbot.action()
, IMO)Notes
* — I have considered using the
NICKLEN
token fromISUPPORT
(if available) and the RFC maximum nickname length, too. But in the nickname's case, it seems more likely to cause problems on servers that support longer-than-RFC nicks but don't sendNICKLEN
.