Skip to content

chat bridge: stop Discord lines echoing back into clan chat - #55

Open
joelhalen wants to merge 1 commit into
masterfrom
fix/discord-bridge-echo-loop
Open

chat bridge: stop Discord lines echoing back into clan chat#55
joelhalen wants to merge 1 commit into
masterfrom
fix/discord-bridge-echo-loop

Conversation

@joelhalen

Copy link
Copy Markdown
Owner

What

ClanRelayService.onClanChat now drops any CLAN_CHAT line whose sender carries the Discord marker, and that marker becomes a named constant ChatMessageUtil.DISCORD_SENDER_MARKER rather than a literal written in one place and matched in none.

Why

The two directions of the bridge feed into each other. Rendering a Discord line goes through client.addChatMessage, which posts a real ChatMessage — so our own injected line arrives at the plugin's chat subscriber indistinguishable from something a clanmate typed, and gets relayed back to Discord, into the channel it was just typed in.

The suffix that stops a Discord user being mistaken for an in-game clanmate is also what identifies our own renders, so it does double duty. An in-game display name cannot contain parentheses, so no real clanmate is ever caught by the test.

The check is a substring rather than a suffix match: the marker is appended at the end today, but the guard has to keep holding if the rendered name is ever decorated further, and no real name can contain it either way.

Note

One unrelated fix rides along: the new constant had been inserted between sendEventChatMessage's javadoc and the method itself, leaving the javadoc dangling above a field and the method undocumented. Java accepts two javadoc blocks in a row and silently ignores the first, so this compiled clean. The javadoc is moved back onto its method.

Verification

Full suite green: 251 tests, 0 failures. No behavioural test covers the guard itself — see the PR discussion.

The Discord→game direction feeds straight back into the game→Discord one.
Rendering a Discord line calls through to client.addChatMessage, which posts
a real ChatMessage, so our own injected line arrives at the plugin's chat
subscriber indistinguishable from something a clanmate typed — and gets
relayed back to Discord, into the channel it was just typed in.

The suffix that keeps a Discord user from being mistaken for a clanmate is
also what identifies our own renders, so it becomes a named constant,
DISCORD_SENDER_MARKER, and ClanRelayService.onClanChat drops any CLAN_CHAT
line whose sender wears it. An in-game display name cannot contain
parentheses, so no real clanmate is ever caught by the test.

The check is a substring rather than a suffix match: the marker is appended
at the end today, but the guard has to keep holding if the rendered name is
ever decorated further, and no real name can contain it either way.
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