Repository navigation
Discord chat: a moderators' log, and timeouts that follow forum restrictions - #445
Conversation
…ictions discord_chat_mod_log_channel_id posts what the forum does in the server to a moderators-only channel: who got in (with their forum username), who lost access, and timeouts set and lifted. Lines never ping anyone, and a line that fails to post is dropped rather than stopping the sync. discord_chat_sync_timeouts times a linked member out while they're suspended or silenced on the forum, capped at Discord's 28 days and renewed as it runs down. A timeout already within a day of the right end is left alone, so long suspensions aren't rewritten every minute. The forum records the timeouts it set and lifts only those; a moderator's own timeout in the server is never cleared. The server owner is skipped. Both settings default off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0cf182fd77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| wanted = timeout_until(user) | ||
| current = Time.zone.parse(member["communication_disabled_until"].to_s) | ||
| current = nil if current && current <= Time.zone.now | ||
| ours = PluginStore.get(STORE, timeout_key(discord_id)).present? |
There was a problem hiding this comment.
Preload timeout ownership before iterating members
When timeout syncing is enabled, every non-bot guild member reaches this PluginStore.get, which performs a separate database query even for members without a forum restriction. Because the scheduled job runs every minute, a guild with hundreds or thousands of members produces the same number of avoidable reads on every run; load the ownership keys in one query before entering members.each.
AGENTS.md reference: AGENTS.md:L24-L24
Useful? React with 👍 / 👎.
| end | ||
| end | ||
|
|
||
| sync_timeout(member, user) if discord_id != owner_id && SiteSetting.discord_chat_sync_timeouts |
There was a problem hiding this comment.
Clear or validate markers when timeout syncing is disabled
If an admin disables this setting after the forum has set a timeout, this guard prevents the stored ours marker from ever being cleaned up. If the forum restriction is then lifted, a Discord moderator applies a new manual timeout, and syncing is re-enabled, the stale marker makes the elsif ours branch clear the moderator's timeout, contradicting the guarantee that manually applied Discord timeouts are left alone; remove markers when disabling the setting or store enough state to verify that the current timeout is still the forum-created one.
Useful? React with 👍 / 👎.
| rescue Api::Error => e | ||
| Rails.logger.warn("#{DiscourseDiscordChat::LOG_TAG} mod log: #{e.message}") |
There was a problem hiding this comment.
Isolate transport failures from the member sync
When posting the optional log line encounters a network failure such as Net::ReadTimeout, Net::OpenTimeout, or SocketError, Api#bot propagates it because these exceptions are not Api::Error. This rescue therefore does not drop the failed line as documented: the exception escapes both sync_member and the scheduled job, aborting processing of all remaining members for that run. Rescue the expected transport exceptions here so logging cannot hold up synchronization.
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs
Adds two default-off switches to the Discord chat module.
discord_chat_mod_log_channel_id: forum actions in the server (got in / lost access / timeouts) posted to a moderators-only channel, no pings, failures dropped.discord_chat_sync_timeouts: forum suspension or silence → server timeout until it ends (28-day cap, renewed). Only forum-set timeouts are ever lifted; a moderator's manual timeout is kept. Owner skipped.Specs: timeout set/capped/left alone/lifted, manual timeout untouched, setting off; log lines and no-channel case.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs