Skip to content

Discord chat: a moderators' log, and timeouts that follow forum restrictions - #445

Merged
TripleU613 merged 2 commits into
mainfrom
discord-chat/mod-log-timeouts
Nov 25, 2026
Merged

TripleU613 merged 2 commits into
mainfrom
discord-chat/mod-log-timeouts

Conversation

@TripleU613

Copy link
Copy Markdown
Owner

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

…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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T18:40:03.857929Z 0cf182f PR opened
🔒 Security Review ✅ Completed 2026-11-25T18:49:49.374944Z 0cf182f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +17 to +18
rescue Api::Error => e
Rails.logger.warn("#{DiscourseDiscordChat::LOG_TAG} mod log: #{e.message}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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
@TripleU613
TripleU613 merged commit 1c9b74a into main Nov 25, 2026
7 of 8 checks passed
@TripleU613
TripleU613 deleted the discord-chat/mod-log-timeouts branch November 25, 2026 18:57
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