Skip to content
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

Fix empty CTCP ACTION sending two literal underscores on Discord #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yutotakano
Copy link
Contributor

@yutotakano yutotakano commented Nov 9, 2024

The Bug that this PR Fixes

Sending an empty CTCP ACTION (i.e. a /me command) from IRC will make go-discord-irc send the message __ (two underscores) to Discord. This renders on Discord clients as literal underscores instead of an empty message, breaking the expectation of the IRC user and changing the perceived content of the message.

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

This issue is rather obscure since most IRC clients forbid you from sending an empty CTCP ACTION. However, with the use of programmatic bots/clients, you can do this. (It is common when you want to play with the bot's nickname). The intended look of these messages is that it shows the nick of the user in emphasis, without a message to follow it. So, it is a bug in go-discord-irc that there is a visible message content.

The Implemented Fix

The 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 wrap the empty CTCP ACTION with underscore characters, before sending it onto the Go channel read by bridge.go, which then sees a non-empty message and thus does not insert ZWBs.

This commit fixes the bug by not wrapping a CTCP ACTION with underscores if the content is empty. This way, an empty message is sent onto the Go channel read by bridge.go, which then will give the necessary ZWB treatment, and send an empty message onto 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.
@yutotakano
Copy link
Contributor Author

yutotakano commented Nov 9, 2024

Not very sure what the CI failure is caused by, but this issue in golangci-lint says that a version bump should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant