linastk/cogs/core.py

77 lines
2.3 KiB
Python
Raw Normal View History

2024-01-02 05:51:44 +00:00
from __future__ import annotations
2023-12-31 05:27:32 +00:00
import discord
from discord.ext import commands
2024-01-02 05:51:44 +00:00
from typing import TYPE_CHECKING, Optional
2023-12-31 05:27:32 +00:00
2024-01-02 05:51:44 +00:00
if TYPE_CHECKING:
from bot import Lina
2023-12-31 05:27:32 +00:00
class Core(commands.Cog):
def __init__(self, bot: Lina):
self.bot: Lina = bot
async def cog_check(self, ctx: commands.Context) -> bool:
return await self.bot.is_owner(ctx.author)
@commands.command(hidden=True)
async def load(self, ctx: commands.Context, *, mod: str):
try:
await self.bot.load_extension(mod)
except commands.ExtensionError as e:
await ctx.reply(f"{e.__class__.__name__}: {e}")
else:
await ctx.reply("Loaded.")
@commands.command(hidden=True)
async def unload(self, ctx: commands.Context, *, mod: str):
try:
await self.bot.unload_extension(mod)
except commands.ExtensionError as e:
await ctx.reply(f"{e.__class__.__name__}: {e}")
else:
await ctx.reply("Unloaded.")
@commands.command(hidden=True)
async def reload(self, ctx: commands.Context, *, mod: str):
try:
await self.bot.reload_extension(mod)
except commands.ExtensionError as e:
await ctx.reply(f"{e.__class__.__name__}: {e}")
else:
await ctx.reply("Reloaded.")
2024-01-02 05:51:44 +00:00
@commands.group(invoke_without_command=True, hidden=True)
2023-12-31 05:27:32 +00:00
@commands.is_owner()
@commands.guild_only()
async def sync(self, ctx: commands.Context, guild_id: Optional[int], copy: bool = False):
if guild_id:
guild = discord.Object(guild_id)
else:
guild = ctx.guild
if copy:
self.bot.tree.copy_global_to(guild=guild)
commands = await self.bot.tree.sync(guild=guild)
await ctx.reply(f"Successfully synced {len(commands)} commands.")
@sync.command(name="global")
@commands.is_owner()
async def sync_global(self, ctx: commands.Context):
commands = await self.bot.tree.sync()
await ctx.reply(f"Successfully synced {len(commands)} commands.")
2024-01-02 11:07:47 +00:00
@commands.command(hidden=True)
async def shutdown(self, ctx: commands.Context):
await ctx.reply("Shutting down :wave:")
await self.bot.close()
2023-12-31 05:27:32 +00:00
async def setup(bot: Lina):
await bot.add_cog(Core(bot))