85 lines
2.8 KiB
Python
85 lines
2.8 KiB
Python
![]() |
from bot.cogs.cog_manager import BaseCog
|
||
|
|
||
|
class CogCommands(BaseCog):
|
||
|
def __init__(self, bot):
|
||
|
super().__init__(bot)
|
||
|
|
||
|
async def cmd_loadcog(self, message):
|
||
|
"""
|
||
|
Load a cog
|
||
|
Usage: .loadcog <cog_name>
|
||
|
"""
|
||
|
content = message.content.strip()
|
||
|
parts = content.split()
|
||
|
|
||
|
if len(parts) != 2:
|
||
|
await message.edit(content="❌ Usage: `.loadcog <cog_name>`")
|
||
|
return
|
||
|
|
||
|
cog_name = parts[1]
|
||
|
if self.bot.cog_manager.load_cog(cog_name):
|
||
|
await message.edit(content=f"✅ Loaded cog: `{cog_name}`")
|
||
|
else:
|
||
|
await message.edit(content=f"❌ Failed to load cog: `{cog_name}`")
|
||
|
|
||
|
async def cmd_unloadcog(self, message):
|
||
|
"""
|
||
|
Unload a cog
|
||
|
Usage: .unloadcog <cog_name>
|
||
|
"""
|
||
|
content = message.content.strip()
|
||
|
parts = content.split()
|
||
|
|
||
|
if len(parts) != 2:
|
||
|
await message.edit(content="❌ Usage: `.unloadcog <cog_name>`")
|
||
|
return
|
||
|
|
||
|
cog_name = parts[1]
|
||
|
# Prevent unloading the cog_commands cog
|
||
|
if cog_name == "cog_commands":
|
||
|
await message.edit(content="❌ Cannot unload the cog management commands.")
|
||
|
return
|
||
|
|
||
|
if self.bot.cog_manager.unload_cog(cog_name):
|
||
|
await message.edit(content=f"✅ Unloaded cog: `{cog_name}`")
|
||
|
else:
|
||
|
await message.edit(content=f"❌ Failed to unload cog: `{cog_name}`")
|
||
|
|
||
|
async def cmd_reloadcog(self, message):
|
||
|
"""
|
||
|
Reload a cog
|
||
|
Usage: .reloadcog <cog_name>
|
||
|
"""
|
||
|
content = message.content.strip()
|
||
|
parts = content.split()
|
||
|
|
||
|
if len(parts) != 2:
|
||
|
await message.edit(content="❌ Usage: `.reloadcog <cog_name>`")
|
||
|
return
|
||
|
|
||
|
cog_name = parts[1]
|
||
|
if self.bot.cog_manager.reload_cog(cog_name):
|
||
|
await message.edit(content=f"✅ Reloaded cog: `{cog_name}`")
|
||
|
else:
|
||
|
await message.edit(content=f"❌ Failed to reload cog: `{cog_name}`")
|
||
|
|
||
|
async def cmd_reloadall(self, message):
|
||
|
"""
|
||
|
Reload all cogs
|
||
|
Usage: .reloadall
|
||
|
"""
|
||
|
self.bot.cog_manager.unload_all_cogs()
|
||
|
num_loaded = self.bot.cog_manager.load_all_cogs()
|
||
|
await message.edit(content=f"✅ Reloaded {num_loaded} cogs.")
|
||
|
|
||
|
async def cmd_listcogs(self, message):
|
||
|
"""
|
||
|
List all loaded cogs
|
||
|
Usage: .listcogs
|
||
|
"""
|
||
|
if not self.bot.cog_manager.cogs:
|
||
|
await message.edit(content="No cogs are currently loaded.")
|
||
|
return
|
||
|
|
||
|
cog_list = "\n".join(f"• {name}" for name in sorted(self.bot.cog_manager.cogs.keys()))
|
||
|
await message.edit(content=f"**Loaded Cogs:**\n{cog_list}")
|