store: Fix: maintenance mode flag in /admin-maintenance (major-domo-v2 #28)

This commit is contained in:
Cal Corum 2026-03-03 11:37:27 -06:00
parent c8de1ff99e
commit 8b76a89b67

View File

@ -0,0 +1,33 @@
---
id: 4c3c7a86-46b6-4d42-a966-35071ba3bfe1
type: fix
title: "Fix: maintenance mode flag in /admin-maintenance (major-domo-v2 #28)"
tags: [major-domo, discord, python, discord.py, bot, maintenance-mode, tree-interaction-check]
importance: 0.6
confidence: 0.8
created: "2026-03-03T17:37:27.125744+00:00"
updated: "2026-03-03T17:37:27.125744+00:00"
---
## Problem
`/admin-maintenance` in `commands/admin/management.py` showed a success embed but never set any state. No flag was set, no commands were blocked.
## Root Cause
The command had a placeholder comment: "This would typically set a global flag or database value. For now, we'll just show the interface."
## Solution
1. Added `self.maintenance_mode: bool = False` to `SBABot.__init__` in `bot.py`
2. Registered a global `@self.tree.interaction_check` in `setup_hook` that intercepts every slash command interaction — returns `False` (with ephemeral message) for non-admin users when `maintenance_mode` is `True`
3. Updated `admin_maintenance` command to set `self.bot.maintenance_mode = is_enabling` and log the state change
## Key Pattern
Discord.py's `CommandTree.interaction_check` is the correct hook for global command blocking. Register via `@bot.tree.interaction_check` inside `setup_hook`. Returning `False` prevents the command from executing.
## Files Changed
- `bot.py` — flag init + global tree check
- `commands/admin/management.py` — set flag + log state change
## Notes
- Flag is in-memory only (resets on restart)
- Admins (guild `administrator` permission) bypass the block
- 930 tests pass