Root causes:
1. Multiple plugin subsystems each called startModeratorPresence,
creating competing WebSocket connections to the same bot token.
Discord only allows one connection per bot → 4008 rate limit →
infinite reconnect loop (1000+ connects → token reset by Discord)
2. Invalid session (op 9) handler called scheduleReconnect, but the
new connection would also get kicked → cascading reconnects
Fixes:
- Singleton guard: startModeratorPresence is a no-op if already started
- cleanup() nullifies old ws handlers before creating new connection
- Stale ws check: all callbacks verify they belong to current ws
- Exponential backoff with cap (max 60s) instead of fixed 2-5s delay
- heartbeat ACK tracking: detect zombie connections
- Non-recoverable codes (4004) properly stop all reconnection
Use Node.js built-in WebSocket to maintain a minimal Discord Gateway
connection for the moderator bot, keeping it 'online' with a
'Watching Moderating' status. Handles heartbeat, reconnect, and resume.
Also fix package-plugin.mjs to include moderator-presence.ts in dist.