Skip to content

feat: add 7d2d discord status bridge module - #57

Merged
El-Limon merged 3 commits into
mainfrom
feature/issue-56-chatbridge-serverstats
Jul 22, 2026
Merged

El-Limon merged 3 commits into
mainfrom
feature/issue-56-chatbridge-serverstats

Conversation

@koji-assistant

Copy link
Copy Markdown
Contributor

Summary

  • Adds discord-7d2d-status-bridge module for 7 Days to Die.
  • Supports Discord ↔ game chat relay, join/leave/death monitoring, /serverstats, persistent Discord status message updates, and blood moon notices from gettime.
  • Includes safety hardening for Discord mention sanitization and game-chat relay privacy: only explicit global/public/all game chat is relayed.

Closes #56

Test evidence

  • npm run build passed.
  • Focused helper test suite passed: node --test-concurrency 1 --import=ts-node-maintained/register/esm --test 'modules/discord-7d2d-status-bridge/test/*.test.ts'.
  • Export validation passed with expected shape: 1 command, 5 hooks, 2 cronjobs, 1 shared function, config schema present.
  • Prior active 7D2D runtime validation on sandbox testing lane verified:
    • gettime returned live 7D2D time (Day 4, 17:22).
    • Module imported and installed on the active 7D2D server.
    • updateStatus cron succeeded, called gettime, sent Discord message, stored persistent message variable.
    • bloodMoonMonitor cron succeeded, called gettime, stored blood moon state.
    • discordChatRelay hook succeeded.
    • gameChatRelay hook succeeded.
    • Test install was uninstalled after validation.

Final safety review notes

  • Reviewer flagged two real issues before PR: persistent status update bypassed sanitization and game chat relay was too permissive for unknown/non-global chat shapes.
  • Both were fixed before this PR.
  • Added tests for mention sanitization, including @everyone, @here, user mentions, nickname mentions, and role mentions.
  • Added tests to only relay explicit global/public/all game chat and default missing/unknown scope to not relayed.

Caveat

A final live rerun after the last safety-only patch was attempted, but the sandbox 7D2D testing game-server record is currently disabled in Takaro and rejected gettime with Game server is disabled. The final code path changed after the prior live run is covered by the helper tests above.

@koji-assistant

Copy link
Copy Markdown
Contributor Author

Fixed the relay echo bug on PR #57 in fe70509.

Root cause: Discord→game relay sends [Discord] <author>: <message> into the game. If the 7D2D connector echoes that injected line back as a normal global chat-message, gameChatRelay could send it back to Discord as a duplicate.

Change:

  • Added isDiscordRelayEcho() to detect [Discord] ... echoed game-chat payloads across the same message fields used by the relay.
  • gameChatRelay now skips those echoed Discord-origin messages before sending to Discord.
  • Added regression coverage for canonical prefix, leading whitespace/case-insensitive prefix, and normal game chat.

Verification:

  • Watched the new regression fail before implementation (ReferenceError: isDiscordRelayEcho is not defined).
  • node --test-concurrency 1 --import=ts-node-maintained/register/esm --test 'modules/discord-7d2d-status-bridge/test/*.test.ts'
  • npm run build
  • node --check modules/discord-7d2d-status-bridge/src/functions/discord-7d2d-status-helpers.js
  • node --check modules/discord-7d2d-status-bridge/src/hooks/game-chat-relay/index.js
  • node dist/scripts/module-to-json.js modules/discord-7d2d-status-bridge /tmp/discord-7d2d-status-bridge-export.json
  • Scoped verifier review: no findings.

Runtime caveat remains unchanged: live 7D2D rerun still depends on a working enabled sandbox 7D2D lane.

@koji-assistant

Copy link
Copy Markdown
Contributor Author

Additional runtime QA on sandbox completed.

I manually created/imported the PR head module through the current API shape because scripts/module-push.sh produced a broken empty import for this module shape. Verified the runtime module version has 1 command, 5 hooks, 2 cronjobs, 1 helper function.

Installed QA module on enabled/reachable sandbox 7D2D lane Iron Mesa 7D2D (92283106-614f-4c84-8e33-004279a4d7b8) with Discord hook config targeting thread/channel 1528056789101182976.

Relay echo test:

  • Triggered chat-message hook with eventMeta.message = "[Discord] HarambeRuntimeTest: echo suppression test", channel = "global".
  • gameChatRelay hook executed with success: true and logs: [].
  • No /discord/channels/.../message call was made, so the echoed Discord-origin game-chat line was suppressed.

Control test:

  • Triggered normal global chat "Harambe QA control: normal relay path".
  • gameChatRelay executed with success: true and logs showed POST /discord/channels/1528056789101182976/message 200 OK with message **Game:** Harambe QA control: normal relay path.

So the normal game→Discord relay still works, while [Discord] ... echoes no longer relay back.

Customize bridge wording, add server status notifications and player-list status output, and cover the module through the real Takaro integration harness.
@El-Limon
El-Limon merged commit fa25caa into main Jul 22, 2026
1 of 2 checks passed
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.

ChatBridge with ServerStats

1 participant