fix: replace broken interaction_check decorator with MaintenanceAwareTree subclass #83

Merged
cal merged 2 commits from fix/maintenance-mode-interaction-check into main 2026-03-17 17:34:16 +00:00
Owner

Summary

  • The previous code attempted to register a maintenance mode gate via @self.tree.interaction_check inside setup_hook. This is not a valid pattern in discord.py — interaction_check is an async method to be overridden on a CommandTree subclass, not a decorator. The assignment was silently dropped, making maintenance mode a complete no-op and producing a RuntimeWarning about an unawaited coroutine.
  • Adds MaintenanceAwareTree(discord.app_commands.CommandTree) that properly overrides interaction_check: non-admins are blocked with an ephemeral message when bot.maintenance_mode is True, administrators always pass through, and the check is a no-op when maintenance mode is off.
  • The /admin-maintenance command now actually toggles bot.maintenance_mode instead of just displaying a UI that did nothing.

Changes

  • bot.py: Add MaintenanceAwareTree subclass; pass tree_cls=MaintenanceAwareTree to super().__init__(); add self.maintenance_mode: bool = False
  • commands/admin/management.py: Add self.bot.maintenance_mode = is_enabling to admin_maintenance so the flag is actually set
  • tests/test_bot_maintenance_tree.py: 8 new unit tests covering all maintenance mode states, admin pass-through, non-Member DM context, and missing attribute fallback

Test plan

  • All 8 new tests in test_bot_maintenance_tree.py pass
  • Full test suite passes (938 passed, 3 skipped) with no regressions
  • Manually verify /admin-maintenance on blocks a non-admin user with an ephemeral message
  • Manually verify /admin-maintenance on still allows admin commands through
  • Manually verify /admin-maintenance off restores normal operation

Closes #82

## Summary - The previous code attempted to register a maintenance mode gate via `@self.tree.interaction_check` inside `setup_hook`. This is not a valid pattern in discord.py — `interaction_check` is an async method to be overridden on a `CommandTree` subclass, not a decorator. The assignment was silently dropped, making maintenance mode a complete no-op and producing a `RuntimeWarning` about an unawaited coroutine. - Adds `MaintenanceAwareTree(discord.app_commands.CommandTree)` that properly overrides `interaction_check`: non-admins are blocked with an ephemeral message when `bot.maintenance_mode` is `True`, administrators always pass through, and the check is a no-op when maintenance mode is off. - The `/admin-maintenance` command now actually toggles `bot.maintenance_mode` instead of just displaying a UI that did nothing. ## Changes - `bot.py`: Add `MaintenanceAwareTree` subclass; pass `tree_cls=MaintenanceAwareTree` to `super().__init__()`; add `self.maintenance_mode: bool = False` - `commands/admin/management.py`: Add `self.bot.maintenance_mode = is_enabling` to `admin_maintenance` so the flag is actually set - `tests/test_bot_maintenance_tree.py`: 8 new unit tests covering all maintenance mode states, admin pass-through, non-Member DM context, and missing attribute fallback ## Test plan - [x] All 8 new tests in `test_bot_maintenance_tree.py` pass - [x] Full test suite passes (938 passed, 3 skipped) with no regressions - [ ] Manually verify `/admin-maintenance on` blocks a non-admin user with an ephemeral message - [ ] Manually verify `/admin-maintenance on` still allows admin commands through - [ ] Manually verify `/admin-maintenance off` restores normal operation Closes #82
cal added 1 commit 2026-03-17 17:25:33 +00:00
fix: replace broken @self.tree.interaction_check with MaintenanceAwareTree subclass
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m11s
d295f27afe
The previous code attempted to register a maintenance mode gate via
@self.tree.interaction_check inside setup_hook.  That pattern is invalid
in discord.py — interaction_check is an overridable method on CommandTree,
not a decorator.  The assignment was silently dropped, making maintenance
mode a no-op and producing a RuntimeWarning about an unawaited coroutine.

Changes:
- Add MaintenanceAwareTree(discord.app_commands.CommandTree) that overrides
  interaction_check: blocks non-admins when bot.maintenance_mode is True,
  always passes admins through, no-op when maintenance mode is off
- Pass tree_cls=MaintenanceAwareTree to super().__init__() in SBABot.__init__
- Add self.maintenance_mode: bool = False to SBABot.__init__
- Update /admin-maintenance command to actually toggle bot.maintenance_mode
- Add tests/test_bot_maintenance_tree.py with 8 unit tests covering all
  maintenance mode states, admin pass-through, DM context, and missing attr

Closes #82

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cal added 1 commit 2026-03-17 17:32:43 +00:00
Merge origin/main into fix branch to resolve conflict
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m3s
9a4ecda564
Keep both the type: ignore annotation and the logger.info call
in admin_maintenance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cal merged commit 6c49233392 into main 2026-03-17 17:34:16 +00:00
cal deleted branch fix/maintenance-mode-interaction-check 2026-03-17 17:34:17 +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#83
No description provided.