Skip to content

feat(discord): add archive/unarchive commands for read-only channel archiving - #104

Merged
BK1031 merged 6 commits into
mainfrom
bk1031/channel-archive
Aug 8, 2026
Merged

feat(discord): add archive/unarchive commands for read-only channel archiving#104
BK1031 merged 6 commits into
mainfrom
bk1031/channel-archive

Conversation

@BK1031

@BK1031 BK1031 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor
  • Add !archive command: snapshots the channel's permission overwrites + parent category to a new archived_channel table, moves it to an ARCHIVE category, and rewrites permissions to Sentinel's standardized archived form
  • Archived form: every overwrite loses its write-bit allows and @everyone gets an explicit write deny (send, threads, reactions, voice connect) — view/read-history bits are untouched, so visibility stays exactly as it was, just read-only
  • Robot and DevOps roles get explicit view + write exemption overwrites; Admin/Officer need none since Administrator bypasses overwrites
  • Auto-provision archive categories: Discord caps categories at 50 channels, so when every category named ARCHIVE is full (or none exists), Sentinel creates a new one (duplicate names are allowed), cloning overwrites from the last existing archive category
  • Gate both commands by Sentinel group membership: the invoker's Discord ID is resolved to their entity, and their groups (via GET /api/core/entity/:id/groups) must include one of Admins/Leads/Officers (case-insensitive, configurable in config.ArchiveCommandAllowedGroups); fails closed on missing entity link or lookup errors
  • Posts a non-pinging notice: archived by whom + !unarchive to restore
  • Add !unarchive command: restores the snapshotted overwrites and original category, deletes the snapshot
  • Store both the archiver's Sentinel entity ID and Discord ID on the snapshot (same pattern as discord_message)
  • Add GET /discord/archived-channels endpoint (scope sentinel:all) for surfacing archive info in the frontend (web UI to follow in a separate PR)
  • Add Robot, SpecialAdvisor, and DevOps role IDs to config (SpecialAdvisor is config-only, not exempted)
  • No event-driven archiving and no category permission syncing — archiving is purely command-driven

@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: 313f80b4d5

ℹ️ 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".

Comment thread discord/service/channel_archive.go Outdated
}

if _, err := GetArchivedChannel(channel.ID); err != nil {
overwrites, err := json.Marshal(channel.PermissionOverwrites)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist the pre-update overwrites in the snapshot

When a move into ARCHIVE also synchronizes or otherwise changes permission overwrites in the same channel update, channel contains the post-update values while BeforeUpdate contains the state being archived. Serializing channel.PermissionOverwrites therefore records the archive permissions, so unarchive cannot restore the channel's original access configuration. Pass and persist the overwrites from BeforeUpdate when it is available.

Useful? React with 👍 / 👎.

Comment thread discord/service/channel_archive.go Outdated
logger.SugarLogger.Infof("channel archive: snapshot already exists for %s (%s), keeping original", channel.ID, channel.Name)
}

if len(category.PermissionOverwrites) > 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Clear overwrites when the archive category has none

When the ARCHIVE category has zero explicit overwrites, this guard skips permission synchronization entirely, leaving every channel-specific allow and deny from before the move in place. Such a channel does not match the category and can remain visible to members explicitly allowed by its old overwrites; the empty target set needs to be applied by deleting the channel's existing overwrites, as the unarchive path already does.

Useful? React with 👍 / 👎.

Comment on lines +122 to +124
if err := Discord.ChannelPermissionDelete(channelID, overwrite.ID); err != nil {
logger.SugarLogger.Errorf("channel archive: failed to delete overwrite %s on %s: %v", overwrite.ID, channelID, err)
}

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 Keep the snapshot when overwrite cleanup fails

When restoring a channel whose original overwrite list was empty, any rejected ChannelPermissionDelete is only logged, after which the snapshot is deleted and the operation returns success. The channel then retains part of the archive permission set while the state needed to retry restoration is lost; return an error and preserve the snapshot unless every deletion succeeds.

Useful? React with 👍 / 👎.

@BK1031 BK1031 changed the title feat(discord): archive channels moved to ARCHIVE category with unarchive command feat(discord): add archive/unarchive commands for read-only channel archiving Aug 8, 2026
@BK1031
BK1031 merged commit 4d4c3a1 into main Aug 8, 2026
19 checks passed
@BK1031
BK1031 deleted the bk1031/channel-archive branch August 8, 2026 21:48
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