2025-01-05 20:35:47 +01:00
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
2025-07-22 19:32:19 +03:00
|
|
|
import discord.ext
|
|
|
|
import discord.ext.commands
|
2025-07-23 10:19:08 +03:00
|
|
|
from modules.permission import requires_admin
|
2025-07-23 15:42:13 +03:00
|
|
|
from modules.settings import instance as settings_manager
|
|
|
|
from modules.globalvars import available_cogs
|
2025-07-23 10:19:08 +03:00
|
|
|
|
2025-07-22 19:32:19 +03:00
|
|
|
settings = settings_manager.settings
|
|
|
|
|
2025-01-05 20:35:47 +01:00
|
|
|
|
2025-07-16 01:32:38 +02:00
|
|
|
COG_PREFIX = "assets.cogs."
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
|
2025-01-05 20:35:47 +01:00
|
|
|
class CogManager(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2025-01-21 17:05:45 +01:00
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
@requires_admin()
|
2025-01-05 20:35:47 +01:00
|
|
|
@commands.command()
|
2025-07-22 19:32:19 +03:00
|
|
|
async def enable(self, ctx, cog_name: str):
|
|
|
|
try:
|
|
|
|
await self.bot.load_extension(COG_PREFIX + cog_name)
|
|
|
|
await ctx.send(f"Loaded cog `{cog_name}` successfully.")
|
|
|
|
settings["bot"]["enabled_cogs"].append(cog_name)
|
2025-07-23 15:42:13 +03:00
|
|
|
settings_manager.add_admin_log_event(
|
|
|
|
{
|
|
|
|
"action": "add",
|
|
|
|
"author": ctx.author.id,
|
|
|
|
"change": "enabled_cogs",
|
|
|
|
"messageId": ctx.message.id,
|
|
|
|
"target": cog_name,
|
|
|
|
}
|
|
|
|
)
|
2025-07-22 19:32:19 +03:00
|
|
|
settings_manager.commit()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f"Error enabling cog `{cog_name}`: {e}")
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
@requires_admin()
|
2025-07-22 19:32:19 +03:00
|
|
|
@commands.command()
|
|
|
|
async def load(self, ctx, cog_name: str | None = None):
|
|
|
|
if cog_name is None:
|
|
|
|
await ctx.send("Give cog_name")
|
|
|
|
return
|
2025-07-23 10:19:08 +03:00
|
|
|
|
2025-07-22 19:32:19 +03:00
|
|
|
if cog_name[:-3] not in settings["bot"]["enabled_cogs"]:
|
|
|
|
await ctx.send("Please enable the cog first!")
|
|
|
|
return
|
2025-01-05 20:35:47 +01:00
|
|
|
if cog_name is None:
|
|
|
|
await ctx.send("Please provide the cog name to load.")
|
|
|
|
return
|
|
|
|
try:
|
2025-07-16 01:32:38 +02:00
|
|
|
await self.bot.load_extension(COG_PREFIX + cog_name)
|
2025-01-05 20:35:47 +01:00
|
|
|
await ctx.send(f"Loaded cog `{cog_name}` successfully.")
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f"Error loading cog `{cog_name}`: {e}")
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
@requires_admin()
|
2025-01-05 20:35:47 +01:00
|
|
|
@commands.command()
|
2025-07-22 19:32:19 +03:00
|
|
|
async def unload(self, ctx, cog_name: str | None = None):
|
2025-01-05 20:35:47 +01:00
|
|
|
if cog_name is None:
|
|
|
|
await ctx.send("Please provide the cog name to unload.")
|
|
|
|
return
|
|
|
|
try:
|
2025-07-16 01:32:38 +02:00
|
|
|
await self.bot.unload_extension(COG_PREFIX + cog_name)
|
2025-01-05 20:35:47 +01:00
|
|
|
await ctx.send(f"Unloaded cog `{cog_name}` successfully.")
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
@requires_admin()
|
2025-01-05 20:35:47 +01:00
|
|
|
@commands.command()
|
2025-07-22 19:32:19 +03:00
|
|
|
async def disable(self, ctx, cog_name: str | None = None):
|
|
|
|
if cog_name is None:
|
|
|
|
await ctx.send("Please provide the cog name to disable.")
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
await self.bot.unload_extension(COG_PREFIX + cog_name)
|
|
|
|
await ctx.send(f"Unloaded cog `{cog_name}` successfully.")
|
|
|
|
settings["bot"]["enabled_cogs"].remove(cog_name)
|
2025-07-23 15:42:13 +03:00
|
|
|
settings_manager.add_admin_log_event(
|
|
|
|
{
|
|
|
|
"action": "del",
|
|
|
|
"author": ctx.author.id,
|
|
|
|
"change": "enabled_cogs",
|
|
|
|
"messageId": ctx.message.id,
|
|
|
|
"target": cog_name,
|
|
|
|
}
|
|
|
|
)
|
2025-07-22 19:32:19 +03:00
|
|
|
settings_manager.commit()
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
@requires_admin()
|
2025-07-22 19:32:19 +03:00
|
|
|
@commands.command()
|
|
|
|
async def reload(self, ctx, cog_name: str | None = None):
|
2025-01-05 20:35:47 +01:00
|
|
|
if cog_name is None:
|
|
|
|
await ctx.send("Please provide the cog name to reload.")
|
|
|
|
return
|
2025-07-22 19:32:19 +03:00
|
|
|
|
|
|
|
if cog_name[:-3] not in settings["bot"]["enabled_cogs"]:
|
|
|
|
await ctx.send("Please enable the cog first!")
|
|
|
|
return
|
2025-01-05 20:35:47 +01:00
|
|
|
try:
|
2025-07-16 01:32:38 +02:00
|
|
|
await self.bot.unload_extension(COG_PREFIX + cog_name)
|
|
|
|
await self.bot.load_extension(COG_PREFIX + cog_name)
|
2025-01-05 20:35:47 +01:00
|
|
|
await ctx.send(f"Reloaded cog `{cog_name}` successfully.")
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f"Error reloading cog `{cog_name}`: {e}")
|
|
|
|
|
2025-01-21 17:05:45 +01:00
|
|
|
@commands.command()
|
|
|
|
async def listcogs(self, ctx):
|
|
|
|
"""Lists all currently loaded cogs in an embed."""
|
|
|
|
cogs = list(self.bot.cogs.keys())
|
|
|
|
if not cogs:
|
|
|
|
await ctx.send("No cogs are currently loaded.")
|
|
|
|
return
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
embed = discord.Embed(
|
|
|
|
title="Loaded Cogs",
|
|
|
|
description="Here is a list of all currently loaded cogs:",
|
|
|
|
)
|
2025-07-23 15:42:13 +03:00
|
|
|
embed.add_field(name="Loaded cogs", value="\n".join(cogs), inline=False)
|
|
|
|
embed.add_field(name="Available cogs", value="\n".join(available_cogs()))
|
2025-01-21 17:05:45 +01:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2025-07-23 10:19:08 +03:00
|
|
|
|
2025-01-05 20:35:47 +01:00
|
|
|
async def setup(bot):
|
|
|
|
await bot.add_cog(CogManager(bot))
|