fix(support): remove core commands in setup before cog loads
Remove Red's built-in contact and dm commands in setup() before the Support cog loads to prevent command registration conflicts. Commands are stored and restored in teardown() when the cog unloads. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
26b1bf9253
commit
814b0e79e9
2 changed files with 20 additions and 27 deletions
|
|
@ -8,7 +8,25 @@ __red_end_user_data_statement__ = (
|
|||
"conversation history, and user preferences."
|
||||
)
|
||||
|
||||
# Store removed commands for restoration
|
||||
_removed_commands = {}
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
# Remove Red's built-in commands BEFORE loading the cog
|
||||
for cmd_name in ["contact", "dm"]:
|
||||
cmd = bot.get_command(cmd_name)
|
||||
if cmd:
|
||||
_removed_commands[cmd_name] = cmd
|
||||
bot.remove_command(cmd_name)
|
||||
|
||||
cog = Support(bot)
|
||||
await bot.add_cog(cog)
|
||||
|
||||
|
||||
async def teardown(bot):
|
||||
# Restore Red's built-in commands when unloading
|
||||
for cmd_name, cmd in _removed_commands.items():
|
||||
if cmd_name not in bot.all_commands:
|
||||
bot.add_command(cmd)
|
||||
_removed_commands.clear()
|
||||
|
|
|
|||
|
|
@ -153,40 +153,15 @@ class Support(commands.Cog):
|
|||
self.bot.add_view(self._control_view)
|
||||
|
||||
self._cleanup_task: Optional[asyncio.Task] = None
|
||||
self._disabled_core_commands = []
|
||||
|
||||
async def cog_load(self):
|
||||
"""Start background tasks and disable core commands on cog load."""
|
||||
"""Start background tasks on cog load."""
|
||||
self._cleanup_task = asyncio.create_task(self._thread_cleanup_loop())
|
||||
await self._disable_core_commands()
|
||||
|
||||
async def cog_unload(self):
|
||||
"""Clean up and re-enable core commands on unload."""
|
||||
"""Clean up on unload."""
|
||||
if self._cleanup_task:
|
||||
self._cleanup_task.cancel()
|
||||
await self._enable_core_commands()
|
||||
|
||||
async def _disable_core_commands(self):
|
||||
"""Disable Red's built-in contact and dm commands."""
|
||||
core_cog = self.bot.get_cog("Core")
|
||||
if not core_cog:
|
||||
return
|
||||
|
||||
commands_to_disable = ["contact", "dm"]
|
||||
|
||||
for cmd_name in commands_to_disable:
|
||||
cmd = self.bot.get_command(cmd_name)
|
||||
if cmd and cmd.cog_name == "Core":
|
||||
cmd.enabled = False
|
||||
self._disabled_core_commands.append(cmd_name)
|
||||
|
||||
async def _enable_core_commands(self):
|
||||
"""Re-enable Red's core commands when this cog unloads."""
|
||||
for cmd_name in self._disabled_core_commands:
|
||||
cmd = self.bot.get_command(cmd_name)
|
||||
if cmd:
|
||||
cmd.enabled = True
|
||||
self._disabled_core_commands.clear()
|
||||
|
||||
# ── Data Management ──────────────────────────────────────────────────────
|
||||
async def red_delete_data_for_user(self, *, requester: Literal["discord", "owner", "user", "user_strict"], user_id: int):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue