Open TehPeGaSuS opened 1 year ago
Here's an example that I took from Bitbot, that kinda shows what I mean:
(bitbot) [issue] progval commented on #369 ([Important] Bot crashes when parsing the URL of certain RSS feeds): That's because `{}` in the entry is inserted by `.replace("$longtitle", feed_title_str)`, and[...] - https://github.com/bitbot-irc/bitbot/issues/369#issuecomment-1589764538
Here is how I'd fix it: in format_entry
, we could compute total message size (len(str(ircmsgs.privmsg(channel, normalized_entry))
) and if it's over 512, then subtract 512 to the message size and truncate this many bytes (not characters! sigh) from entry["description"]
, then format and normalize again.
We just need to be careful so we don't remove anything from the URL (GitHub URLs tend to be quite big), otherwise we'll end up with a broken link.
Small addendum: it would be nice to decide also what to do if the message would exceed the 512 bytes limit, like spit out the whole message (that could be 2+ lines), etc.
A bit like the supybot.reply.mores.instant
option but automatically.
The safest way to do this would be to do a cut at the last space. This in most cases prevents breaking stuff.
So, I've set my bot to spit RSS feeds in the format
[Feed Name] $title :: $link :: $description
. what happens is that sometimes descriptions are big and are cut off. it'd be nice if we could figure out when the message is exceeding the maximum length, cut it before the last word and add something like...
to the end instead.Example:
[Ubuntu Security Notices] USN-6049-1: Netty vulnerabilities :: https://ubuntu.com/security/notices/USN-6049-1 :: It was discovered that Netty's Zlib decoders did not limit memory allocations. A remote attacker ...