From ee8eaba33433e2f6f7535b4588a4e313c041e1ff Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Sat, 9 Nov 2024 21:38:10 +0100 Subject: [PATCH] Fix empty CTCP ACTION sending two literal underscores on Discord Wrapping of IRC CTCP ACTION commands with underscores to mimic the italicization on Discord happens before the logic for ZWB treatment of empty messages. This means that we send two underscore characters for an empty CTCP ACTION, which renders as literal underscores in the Discord UI (instead of the intended empty message). This commit fixes it by not wrapping a CTCP ACTION with underscores if it is empty. Having any non-zero whitespace in the CTCP ACTION will not cause this issue (only the true empty string), as Discord renders the sequence `_ _` as empty but `__` as two underscores. --- bridge/irc_listener.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bridge/irc_listener.go b/bridge/irc_listener.go index aca9e47..bcd1b5c 100644 --- a/bridge/irc_listener.go +++ b/bridge/irc_listener.go @@ -257,10 +257,14 @@ func (i *ircListener) OnPrivateMessage(e *irc.Event) { replacements..., ).Replace(e.Message()) - if e.Code == "CTCP_ACTION" { + + // Italicize the /me action so it appears like Discord's /me functionality. + // We don't do it for empty messages, since Discord will show two literal underscores. + // Sending empty messages onto the discordMessagesChan is fine, since the sender will + // take care of inserting ZWBs if necessary. + if e.Code == "CTCP_ACTION" && msg != "" { msg = "_" + msg + "_" } - msg = ircf.BlocksToMarkdown(ircf.Parse(msg)) go func(e *irc.Event) {