progval / Limnoria

A robust, full-featured, and user/programmer-friendly Python IRC bot, with many existing plugins.
https://docs.limnoria.net/
Other
621 stars 174 forks source link

RSS feeds which exceed IRC maximum message length are cut off #1533

Open TehPeGaSuS opened 1 year ago

TehPeGaSuS commented 1 year ago

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 ...

TehPeGaSuS commented 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
progval commented 1 year ago

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.

TehPeGaSuS commented 1 year ago

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.

TehPeGaSuS commented 1 year ago

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.

ThatLurker commented 3 weeks ago

The safest way to do this would be to do a cut at the last space. This in most cases prevents breaking stuff.