fix: implement actual maintenance mode flag in /admin-maintenance (#28) #62

Merged
cal merged 1 commits from ai/major-domo-v2-28 into next-release 2026-03-03 22:08:20 +00:00
Owner

Summary

Fixes #28. The /admin-maintenance command previously showed a success embed but never changed any state — no flag was set and no commands were blocked.

Changes

  • bot.py: Added self.maintenance_mode: bool = False to SBABot.__init__. Registered a global @tree.interaction_check in setup_hook that intercepts every slash command and blocks non-admin users with an ephemeral "maintenance mode" message when the flag is set.
  • commands/admin/management.py: Updated admin_maintenance to set self.bot.maintenance_mode = is_enabling and log the state change (user ID + enabled/disabled). Removed the no-op placeholder comment.

Behaviour

  • Maintenance ON: All slash commands are blocked for non-admin users with 🔧 The bot is currently in maintenance mode. Please try again later. (ephemeral). Admins (guild administrator permission) can still use all commands including the admin suite.
  • Maintenance OFF: Normal operation resumes immediately — all users can use all commands.
  • The flag is in-memory only (resets on restart), consistent with the existing ephemeral nature of the command.

Tests

All 930 tests pass. No existing tests were broken.

## Summary Fixes #28. The `/admin-maintenance` command previously showed a success embed but never changed any state — no flag was set and no commands were blocked. ## Changes - **`bot.py`**: Added `self.maintenance_mode: bool = False` to `SBABot.__init__`. Registered a global `@tree.interaction_check` in `setup_hook` that intercepts every slash command and blocks non-admin users with an ephemeral "maintenance mode" message when the flag is set. - **`commands/admin/management.py`**: Updated `admin_maintenance` to set `self.bot.maintenance_mode = is_enabling` and log the state change (user ID + enabled/disabled). Removed the no-op placeholder comment. ## Behaviour - **Maintenance ON**: All slash commands are blocked for non-admin users with `🔧 The bot is currently in maintenance mode. Please try again later.` (ephemeral). Admins (guild `administrator` permission) can still use all commands including the admin suite. - **Maintenance OFF**: Normal operation resumes immediately — all users can use all commands. - The flag is in-memory only (resets on restart), consistent with the existing ephemeral nature of the command. ## Tests All 930 tests pass. No existing tests were broken.
cal added 1 commit 2026-03-03 17:37:06 +00:00
fix: implement actual maintenance mode flag in /admin-maintenance (#28)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m17s
35ad4e936b
- Add `maintenance_mode: bool = False` flag to `SBABot.__init__`
- Register a global `@tree.interaction_check` that blocks non-admin users
  from all commands when maintenance mode is active
- Update `admin_maintenance` command to set `self.bot.maintenance_mode`
  and log the state change, replacing the no-op placeholder comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cal added the
ai-reviewing
label 2026-03-03 18:01:20 +00:00
cal removed the
ai-reviewing
label 2026-03-03 18:05:01 +00:00
cal added the
ai-reviewing
label 2026-03-03 18:31:25 +00:00
cal reviewed 2026-03-03 18:33:21 +00:00
cal left a comment
Author
Owner

AI Code Review

Files Reviewed

  • bot.py (modified) — added maintenance_mode flag + global interaction_check
  • commands/admin/management.py (modified) — wired flag into admin_maintenance, plus formatting cleanup

Findings

Correctness

  • The self.maintenance_mode: bool = False flag is correctly declared in SBABot.__init__, making it a proper instance attribute.
  • @self.tree.interaction_check inside setup_hook is idiomatic discord.py — it registers once at startup and the nested function captures self via closure, so it always reads the live value of self.maintenance_mode at interaction time. This is correct.
  • The admin bypass check (isinstance(interaction.user, discord.Member) and interaction.user.guild_permissions.administrator) mirrors the existing AdminCommands.interaction_check pattern exactly — consistent and correct.
  • self.bot.maintenance_mode = is_enabling in admin_maintenance correctly mutates the flag. Since mode is constrained by app_commands.choices to "on" / "off", the mode.lower() == "on" test is safe.
  • The ephemeral response in maintenance_check is sent before returning False, which prevents the command from executing without leaving a dangling interaction. No double-response risk.

Security

  • No new surface area introduced. The check is additive — it runs before any command handler, not in place of existing admin guards.
  • The flag is in-memory only (resets on restart), which matches the documented intent and is acceptable for a maintenance gate.

Style & Conventions

  • EmbedTemplate.create_base_embed() is correctly used for the maintenance embed title that contains a custom emoji (🔧), following the CLAUDE.md rule about not putting emoji in EmbedTemplate.success/error/warning/info() titles.
  • self.logger is used consistently per CLAUDE.md conventions.
  • The bulk of the management.py diff is mechanical reformatting (trailing commas, quote normalisation, line wrapping). No functional change there.
  • Missing newline at EOF in original file is fixed.

Suggestions

  • self.bot.maintenance_mode is accessed from AdminCommands where bot is typed as commands.Bot, which doesn't have maintenance_mode. Works at runtime but would fail strict mypy. A typed bot reference would clean it up, but it's a pre-existing pattern in this codebase so not a blocker.
  • No new tests for the maintenance mode behaviour. Given 930 existing tests pass and this is a simple boolean flag with a straightforward interaction_check, coverage is acceptable for this change.

Verdict: APPROVED

Clean, minimal implementation that directly fixes #28. The global interaction_check pattern is the correct discord.py approach, the admin bypass is consistent with existing permission logic, and no existing tests were broken.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `bot.py` (modified) — added `maintenance_mode` flag + global `interaction_check` - `commands/admin/management.py` (modified) — wired flag into `admin_maintenance`, plus formatting cleanup ### Findings #### Correctness - The `self.maintenance_mode: bool = False` flag is correctly declared in `SBABot.__init__`, making it a proper instance attribute. - `@self.tree.interaction_check` inside `setup_hook` is idiomatic discord.py — it registers once at startup and the nested function captures `self` via closure, so it always reads the live value of `self.maintenance_mode` at interaction time. This is correct. - The admin bypass check (`isinstance(interaction.user, discord.Member) and interaction.user.guild_permissions.administrator`) mirrors the existing `AdminCommands.interaction_check` pattern exactly — consistent and correct. - `self.bot.maintenance_mode = is_enabling` in `admin_maintenance` correctly mutates the flag. Since `mode` is constrained by `app_commands.choices` to `"on"` / `"off"`, the `mode.lower() == "on"` test is safe. - The ephemeral response in `maintenance_check` is sent before returning `False`, which prevents the command from executing without leaving a dangling interaction. No double-response risk. #### Security - No new surface area introduced. The check is additive — it runs before any command handler, not in place of existing admin guards. - The flag is in-memory only (resets on restart), which matches the documented intent and is acceptable for a maintenance gate. #### Style & Conventions - `EmbedTemplate.create_base_embed()` is correctly used for the maintenance embed title that contains a custom emoji (`🔧`), following the CLAUDE.md rule about not putting emoji in `EmbedTemplate.success/error/warning/info()` titles. - `self.logger` is used consistently per CLAUDE.md conventions. - The bulk of the `management.py` diff is mechanical reformatting (trailing commas, quote normalisation, line wrapping). No functional change there. - Missing newline at EOF in original file is fixed. #### Suggestions - `self.bot.maintenance_mode` is accessed from `AdminCommands` where `bot` is typed as `commands.Bot`, which doesn't have `maintenance_mode`. Works at runtime but would fail strict mypy. A typed bot reference would clean it up, but it's a pre-existing pattern in this codebase so not a blocker. - No new tests for the maintenance mode behaviour. Given 930 existing tests pass and this is a simple boolean flag with a straightforward `interaction_check`, coverage is acceptable for this change. ### Verdict: APPROVED Clean, minimal implementation that directly fixes #28. The global `interaction_check` pattern is the correct discord.py approach, the admin bypass is consistent with existing permission logic, and no existing tests were broken. --- *Automated review by Claude PR Reviewer*
cal added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-03 18:33:43 +00:00
cal changed target branch from main to next-release 2026-03-03 22:03:31 +00:00
cal force-pushed ai/major-domo-v2-28 from 35ad4e936b to e3610e84ea 2026-03-03 22:08:06 +00:00 Compare
cal merged commit 88ad58fa12 into next-release 2026-03-03 22:08:20 +00:00
cal deleted branch ai/major-domo-v2-28 2026-03-03 22:08:21 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-v2#62
No description provided.