Skip to content

feat(bot)!: serve one guild through guild-scoped commands and Discord's own permissions - #184

Merged
TheMeinerLP merged 3 commits into
mainfrom
docs/openspec-single-guild-native
Oct 14, 2026
Merged

TheMeinerLP merged 3 commits into
mainfrom
docs/openspec-single-guild-native

Conversation

@TheMeinerLP

@TheMeinerLP TheMeinerLP commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Makes one Sturnus installation serve one guild, and lets Discord itself decide who may run the administrative commands.

Depends on #183 and must merge after it. This branch contains #183's commits, so GitHub shows them here until #183 is merged; the diff of this PR is the last three commits only (two docs(openspec) commits and the feat(bot)! implementation).

What it does

Sturnus is used by one team, so the scope decision of 2026-09-19 stands (one installation, one guild) and its reason is now simply that a single team has a single guild. The earlier reason, isolation promised to external customers, is void, and so is the machinery that was built to back that promise. This change replaces self-built mechanisms with the ones Discord already has:

  • Guild-scoped command registration. The bot copies its command tree to the configured guild and syncs there, then clears the commands it once registered globally, in that order so the commands never vanish from the served guild. A command that does not exist in a foreign guild needs no reply explaining why.
  • default_member_permissions plus Server Settings > Integrations. /config, /queue, /setup and /audio-purge require Manage Server by default; /consent, /link, /about and /audio delete stay open. Discord does not deliver the interaction to a member without the permission, and the team's admins adjust it per role, user and channel in Integrations. The in-process require_admin() check is removed from those commands.
  • "Public Bot" off and guild-install only, as the primary protection. With a private application nobody but the owner can invite the bot to a second guild. This is deployment work, documented in docs/operations.md and docs/first-deployment.md.
  • One guard. A pure domain predicate ("does this installation serve this guild") sits at the head of reconcile_guild, which is the chokepoint on_guild_join, on_shard_ready, _tick_guild, /config apply and /setup all pass through. A foreign guild is reconciled into nothing and the refusal is logged with the two guild ids only, never a name.

Why it is shaped this way

The failure this prevents is narrow: today nothing stops the bot being invited to a second guild and reconciling it, which would create configuration and write recordings of people who never consented to this installation into the team's database and bucket. The platform setting is the real protection; the guard exists so that a portal checkbox flipped by mistake costs a log line instead of a foreign recording. That is also why STURNUS_GUILD_ID has no default, for the same reason STURNUS_TRANSCRIPTION_BASE_URL has none: it is a consent boundary.

/audio purge becomes the top-level /audio-purge because Discord applies default permissions per top-level command. A subcommand cannot be stricter than its siblings, and /audio delete has to stay available to every member, so purge had to leave the group.

There is no Administrator fallback after the move. A second authority would disagree with Integrations the moment an admin restricted a command there: Discord would hide the command while the code admitted the same person by another route.

What it deliberately refuses to do

  • The bot never leaves a guild on its own. A mistyped STURNUS_GUILD_ID would otherwise make it leave the guild it is meant to serve.
  • No worker check and no console read confinement. They defended a promise to external customers that no longer exists; the worker does not gain STURNUS_GUILD_ID.
  • admin_role_id stays, with its mirror into admin_member: the console signs in through Outline OAuth and authorizes through that table, and its login is unchanged. Only the commands stop reading the role.
  • It does not refuse to start when the bot can see more than one guild, so availability does not depend on who invites the bot.

OpenSpec

The branch carries the change single-guild-instance (implemented here, tasks 1 to 4 and 5.1 done) and remove-multi-guild-machinery (proposed only, not implemented: gateway sharding and per-guild OAuth clients, to ship after this one is deployed). It also fixes the markdownlint configuration the specs needed.

Still open after deployment

  • Task 5.2: in the real guild, verify the commands appear instantly, no global command remains, an unprivileged member cannot see the admin commands, and an Integrations override is honoured.
  • Task 5.3: verify "Public Bot" is off on the Team-owned application and that an unrelated account cannot add it; Discord does not document what bot_public: false means for a Team, so this needs a real check, recorded in docs/first-deployment.md.

Checks

pytest -q 2752 passed · ruff check · ruff format --check · mypy (296 files) · console vitest run 1719 passed (56 files) · vue-tsc --noEmit — all clean.

BREAKING CHANGE: STURNUS_GUILD_ID is required for the bot; /audio purge is now
/audio-purge; access to /config, /queue, /setup and /audio-purge is governed by
Manage Server and Server Settings > Integrations instead of the admin role.

@TheMeinerLP
TheMeinerLP force-pushed the docs/openspec-single-guild-native branch from 5abaaa9 to 6818de8 Compare October 14, 2026 19:55
…'s own permissions

Sturnus serves a single team, so one installation now serves one guild named
by STURNUS_GUILD_ID. Commands are registered for that guild only and the old
global ones are cleared. /config, /queue, /setup and /audio-purge default to
Manage Server and Discord enforces it, replacing the in-process require_admin
check; /audio purge becomes the top-level /audio-purge because Discord sets
default permissions per top-level command. reconcile_guild and the tick
refuse any other guild and log the two ids. admin_role_id and the console
mirror are untouched.

BREAKING CHANGE: STURNUS_GUILD_ID is required for the bot; /audio purge is now
/audio-purge; access to /config, /queue, /setup and /audio-purge is governed by
Manage Server and Server Settings > Integrations instead of the admin role.
@TheMeinerLP
TheMeinerLP force-pushed the docs/openspec-single-guild-native branch from 6818de8 to a5f992b Compare October 14, 2026 20:00
@TheMeinerLP
TheMeinerLP merged commit 1a0d5fd into main Oct 14, 2026
14 checks passed
@TheMeinerLP
TheMeinerLP deleted the docs/openspec-single-guild-native branch October 15, 2026 11:50
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