discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.46k stars 3.97k forks source link

Add an escaper for the "hide link embed" markdown sequence #9852

Open janparisek opened 1 year ago

janparisek commented 1 year ago

Which application or package is this feature request for?

formatters

Feature

There's currently many Discord-flavored markdown sequences that can be escaped by the formatters @discordjs/formatters package. However, there's one sequence that's not supported yet: the "hide link embed" sequence.

This causes strings, such as <a:/b> to be rendered as a:/b by the Discord client. The same goes for the intended purpose, of this sequence: <https://discord.js.org/> renders as https://discord.js.org/.

Escaping this sequence would cause text to render correctly.

Ideal solution or implementation

I propose a sophisticated approach to escape any occurrence of the pattern /<[^<>\s:]+:\/[^<>\s]+>/g by surrounding it between \< and >.

E.g. escaping <https://discord.js.org/> would result in the string \<<https://discord.js.org/>>. This correctly renders as <https://discord.js.org/> in the Discord client while the link embed remains hidden.

Please note that this solution is not yet ideal, since there are very complex interactions between the <a:/b> sequence when they're being used in combination with masked links.

Alternative solutions or implementations

My original approach was simpler: Escape any occurrence of the character < with \<. This works similar to how escapeStrikethrough() and escapeSpoiler() already work. However, this causes previously hidden link embeds to not be hidden anymore. Therefore, this requires the MessageFlags.SuppressEmbeds to be set.

Other context

My personal use case is logging member nicknames. I noticed that a member had called themselves </:/:> while the message from the bot displayed their nickname as /:/: without the angled brackets.

Recreation of what it looked like: image

janparisek commented 1 year ago

I think I should mention that I already have two solutions ready since I needed a fix for my own bots.

However, I'd like to further discuss this topic here, for two reasons: