Skip to content

feat: add gateway bans, audit logs, and auto moderation - #109

Merged
RedStar071 merged 2 commits into
feat/voice-presencefrom
feat/moderation
Sep 25, 2026
Merged

RedStar071 merged 2 commits into
feat/voice-presencefrom
feat/moderation

Conversation

@RedStar071

Copy link
Copy Markdown
Member

Stacked on #108.

🔗 Linked issue

Related to #54 (phase 11a of the roadmap).

🧭 Context

Members could be banned and unbanned, but bans couldn't be listed, and there were no structures for bans, audit logs or auto moderation. The cache already stored bans, rules and audit log entries from the gateway, but their events only reached raw.

📚 Description

Moderation follows discord.js, on the same per-guild manager pattern as emojis and stickers:

  • Bans. GuildBan and guild.bans (client.guilds.bans(guildId)) with list, fetch, create, remove and bulkCreate. The gateway doesn't send ban reasons, so bans from guildBanAdd have none. fetch(userId, { force: true }) gets it, and guildBanRemove emits the cached ban, so the reason is included when it was fetched before.
  • Audit logs. guild.fetchAuditLogs({ user, type, before, after, limit }) returns a page of GuildAuditLogsEntrys. Each entry has its executor resolved from the page's users, which are also added to the cache, and discord.js's actionType. The page also carries its webhooks, rules and threads as structures.
  • Auto moderation. AutoModerationRule and guild.autoModerationRules with fetchAll, create, edit and delete. The rule has discord.js's setters. Discord replaces trigger metadata as a whole, so the trigger setters (setKeywordFilter, setAllowList, setPresets, ...) merge their field into the current trigger instead of wiping the rest. AutoModerationActionExecution covers executed actions.
  • Events: guildBanAdd, guildBanRemove, guildAuditLogEntryCreate, autoModerationRuleCreate/Update/Delete and autoModerationActionExecution.

Left for later: scheduled events, stage instances, soundboard, templates, welcome screen, widget, onboarding, integrations, and sharding (phase 11b).

Key changes

Area Change
Structures GuildBan, GuildAuditLogsEntry, AutoModerationRule, AutoModerationActionExecution; Guild#bans/autoModerationRules/fetchAuditLogs
Managers GuildBanManager, AutoModerationRuleManager, client.guilds.fetchAuditLogs
Events Ban, audit log entry and auto moderation events

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

🤖 AI disclosure: Wolfstar Agent Kit modified this description. My AI open-source policy.

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

◈ PR Lens

PR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z.

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-api@109

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-cache@109

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-gateway@109

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-i18next@109

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-logger@109

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-subcommands-advanced@109

commit: 70df197

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

One correctness bug: GuildAuditLogsEntry#actionType's classification diverges from the discord.js parity it claims.

Reviewed changes

Reviewed the full diff adding gateway bans, audit logs, and auto moderation to @wolfstar/plugin-gateway.

  • GuildBanManager/GuildBan (guild.bans): list, fetch, create, remove, and bulk-create bans, delegating create/remove to the existing member ban/unban REST calls and caching the banned user alongside the ban.
  • AutoModerationRuleManager/AutoModerationRule (guild.autoModerationRules): fetchAll/create/edit/delete, with discord.js-style trigger setters (setKeywordFilter, setAllowList, ...) that merge into the current triggerMetadata since Discord replaces it wholesale on PATCH.
  • GuildManager#fetchAuditLogs/GuildAuditLogsEntry: fetches a page of the audit log, resolves each entry's executor from the page's users (caching them), and builds the page's webhooks/rules/threads as structures.
  • AutoModerationActionExecution: wraps the AUTO_MODERATION_ACTION_EXECUTION dispatch with resolved guild/user relations.
  • Dispatch wiring: adds guildBanAdd/guildBanRemove, guildAuditLogEntryCreate, autoModerationRuleCreate/Update/Delete, and autoModerationActionExecution to DispatchHandlers/GatewayEventMap.

I verified the before/build snapshot ordering for the ban-remove and rule-update handlers against @wolfstar/plugin-cache's actual write/delete ordering (operations.ts), the CachedManager base class, and the guild-scoped manager instantiation convention (Guild.bans/.autoModerationRules match Guild.emojis/.channels) — all correct and consistent with the rest of the codebase.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Claude Sonnet | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No new issues — the new commit is a merge of the stacked base branch (feat/voice-presence) into feat/moderation.

The only files it touches (ThreadChannelMemberManager.ts, ThreadManager.ts, tests/threads.test.ts) are outside this PR's diff — every file in this PR's own TOC is byte-identical to what was reviewed at d292c00. The two inline comments from the previous review (GuildAuditLogsEntry.ts actionType classification) still stand.

Pullfrog  | Fix it ➔ | View workflow run | Using Claude Sonnet | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Reviewed commit 93dec47, which fixes the actionType classification bug flagged in the prior review.

  • Un-swapped ban actions: AuditLogEvent.MemberBanRemove moved into CreateActions and AuditLogEvent.MemberBanAdd moved into DeleteActions, matching discord.js's actual GuildAuditLogsEntry.actionType() mapping.
  • Reclassified auto-moderation block: AuditLogEvent.AutoModerationBlockMessage removed from CreateActions so it now falls through to the default "Update", matching discord.js.
  • Updated test assertion: tests/moderation.test.ts now expects ["Delete", "Delete"] for a MemberBanAdd + MemberKick pair (previously incorrectly expected ["Create", "Delete"]) — a falsifiable assertion that would catch a regression of this swap.

Both inline threads from the previous review are addressed and resolved. No other issues found.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@RedStar071
RedStar071 merged commit 6a9b360 into main Sep 25, 2026
19 of 25 checks passed
@RedStar071
RedStar071 deleted the feat/moderation branch September 25, 2026 18:02
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