Skip to content

fix(discord): suppress pairing reply in groups without @mention (#1091)#1092

Merged
viettranx merged 2 commits intodevfrom
fix/issue-1091-discord-pairing-mention-gate
May 4, 2026
Merged

fix(discord): suppress pairing reply in groups without @mention (#1091)#1092
viettranx merged 2 commits intodevfrom
fix/issue-1091-discord-pairing-mention-gate

Conversation

@mrgoonie
Copy link
Copy Markdown
Contributor

@mrgoonie mrgoonie commented May 4, 2026

Summary

Hotfix for #1091. Discord channels with pairing group policy + Require @mention in groups enabled were spamming pairing codes on every group message.

Root cause: handleMessage called checkGroupPolicy (which fires sendPairingReply on PolicyNeedsPairing) before the mention gate ran, so the pairing reply bypassed the mention requirement.

Fix: Pre-compute the mentioned flag once at the top of handleMessage, pass it into checkGroupPolicy, and skip sendPairingReply when RequireMention() is enabled and the bot was not addressed. The existing mention gate later in the function reuses the same flag (deduped).

DMs are intentionally unchanged — every DM is implicitly directed at the bot, so checkDMPolicy keeps its current pairing-reply behavior.

Behavior after fix

Scenario Before After
Group, paired user, mentioned reply reply (unchanged)
Group, paired user, not mentioned record history record history (unchanged)
Group, unpaired user, mentioned pairing code pairing code (unchanged)
Group, unpaired user, not mentioned, require_mention=true pairing code (bug) silent (fixed)
Group, unpaired user, not mentioned, require_mention=false pairing code pairing code (unchanged)
DM, unpaired user pairing code pairing code (unchanged)

Test plan

  • go build ./... (PG)
  • go build -tags sqliteonly ./... (Desktop)
  • go vet ./internal/channels/discord/...
  • go test ./internal/channels/discord/...
  • Manual: Discord group with pairing + require_mention=true, send message without mention → bot stays silent
  • Manual: same group, @-mention bot from unpaired account → bot replies with pairing code
  • Manual: DM unpaired bot → bot replies with pairing code (no regression)

Fixes #1091

When `pairing` group policy is combined with `Require @mention`, the bot
posted a pairing code in response to every group message because
`checkGroupPolicy` ran before the mention gate.

Pre-compute the mention flag and pass it into `checkGroupPolicy`. When
RequireMention is enabled and the bot was not addressed, return silently
instead of triggering `sendPairingReply`.

DMs are unchanged — every DM is implicitly directed at the bot.

Fixes #1091
@mrgoonie mrgoonie requested a review from viettranx May 4, 2026 08:11
@clark-cant
Copy link
Copy Markdown

🔍 Code Review — fix(discord): suppress pairing reply in groups without @mention (#1091)

🎯 Tổng quan

Hotfix: Discord channels với pairing policy + Require @mention enabled bị spam pairing code trên mọi group message. Root cause: checkGroupPolicy fires sendPairingReply trước khi mention gate chạy.

Scope: 1 file, +25/-15, 1 commit


🤖 CI Status + Merge Conflicts

CI:All checks passed — go: pass (7m18s), web: pass (46s)
Merge conflicts: ✅ No conflicts (MERGEABLE, mergeStateStatus: CLEAN)


✅ Điểm Tốt

  1. Root cause analysis chính xác. handleMessage gọi checkGroupPolicysendPairingReply trước khi mention gate chạy → pairing code bypass mention requirement. Correct diagnosis.

  2. Fix đúng pattern. Pre-compute mentioned flag một lần ở đầu handleMessage, pass vào checkGroupPolicy, dedup mention check (không duplicate code). Clean refactor.

  3. Mention detection đầy đủ. Check cả m.Mentions (direct @mention) và m.ReferencedMessage (reply to bot) — covers cả 2 trường hợp user tương tác với bot trong group.

  4. DM không bị ảnh hưởng. Explicitly noted: DMs implicitly directed at bot, checkDMPolicy giữ nguyên behavior. Good scope discipline.

  5. Behavior table rõ ràng. PR body có table Before/After cho 6 scenarios — easy to verify correctness.

  6. Test plan thực tế. Manual test scenarios cụ thể cho paired/unpaired + mentioned/not mentioned + DM.


🟢 LOW (Nit)

  1. mentioned flag computed cho cả DM path. Line 47-61 compute mentioned với if !isDM guard — good, không waste computation cho DM. Nhưng nếu sau này có thêm channel type khác (không DM không group), flag sẽ mặc định false. Không blocking, chỉ nên note.

  2. checkGroupPolicy signature change. Thêm param mentioned bool — breaking change cho interface nếu có chỗ nào khác gọi trực tiếp (nhưng search codebase thì chỉ có handleMessage gọi, nên safe).


📊 Summary

Severity Count Issues
🔴 CRITICAL 0
🟡 MEDIUM 0
🟢 LOW 2 mentioned flag scope note, signature change note

💡 Recommendation

🟢 APPROVED

Hotfix nhỏ, clean, đúng root cause, không side effects. Code refactor dedup mention check — improvement chứ không chỉ là band-aid fix.

Ready to merge! 🚀

@mrgoonie mrgoonie added the bug Something isn't working label May 4, 2026
@viettranx viettranx merged commit a97e502 into dev May 4, 2026
2 checks passed
@viettranx viettranx deleted the fix/issue-1091-discord-pairing-mention-gate branch May 4, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Discord: pairing reply ignores 'Require @mention in groups' — bot posts pairing code in groups without being mentioned

3 participants