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-30 07:57:36 +00:00
|
|
|
import logging
|
2024-03-07 11:46:06 +00:00
|
|
|
from sys import version as python_version
|
|
|
|
from aiohttp import __version__ as aiohttp_version
|
|
|
|
from asyncpg import __version__ as asyncpg_version
|
2024-01-02 05:51:44 +00:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2023-12-31 05:27:32 +00:00
|
|
|
|
2024-01-30 07:57:36 +00:00
|
|
|
log = logging.getLogger("lina.cogs.core")
|
|
|
|
|
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
|
|
|
|
|
2024-03-07 11:46:06 +00:00
|
|
|
@commands.is_owner()
|
2023-12-31 05:27:32 +00:00
|
|
|
@commands.command(hidden=True)
|
|
|
|
async def load(self, ctx: commands.Context, *, mod: str):
|
|
|
|
try:
|
2024-01-18 03:34:48 +00:00
|
|
|
await ctx.channel.typing()
|
2023-12-31 05:27:32 +00:00
|
|
|
await self.bot.load_extension(mod)
|
|
|
|
except commands.ExtensionError as e:
|
2024-01-30 07:57:36 +00:00
|
|
|
log.exception("%s: Unable to load:", mod, exc_info=e)
|
2023-12-31 05:27:32 +00:00
|
|
|
await ctx.reply(f"{e.__class__.__name__}: {e}")
|
|
|
|
else:
|
|
|
|
await ctx.reply("Loaded.")
|
|
|
|
|
2024-03-07 11:46:06 +00:00
|
|
|
@commands.is_owner()
|
2023-12-31 05:27:32 +00:00
|
|
|
@commands.command(hidden=True)
|
|
|
|
async def unload(self, ctx: commands.Context, *, mod: str):
|
|
|
|
try:
|
2024-01-18 03:34:48 +00:00
|
|
|
await ctx.channel.typing()
|
2023-12-31 05:27:32 +00:00
|
|
|
await self.bot.unload_extension(mod)
|
|
|
|
except commands.ExtensionError as e:
|
2024-01-30 07:57:36 +00:00
|
|
|
log.exception("%s: Unable to unload:", mod, exc_info=e)
|
2023-12-31 05:27:32 +00:00
|
|
|
await ctx.reply(f"{e.__class__.__name__}: {e}")
|
|
|
|
else:
|
|
|
|
await ctx.reply("Unloaded.")
|
|
|
|
|
2024-03-07 11:46:06 +00:00
|
|
|
@commands.is_owner()
|
2023-12-31 05:27:32 +00:00
|
|
|
@commands.command(hidden=True)
|
|
|
|
async def reload(self, ctx: commands.Context, *, mod: str):
|
|
|
|
try:
|
2024-01-18 03:34:48 +00:00
|
|
|
await ctx.channel.typing()
|
2023-12-31 05:27:32 +00:00
|
|
|
await self.bot.reload_extension(mod)
|
|
|
|
except commands.ExtensionError as e:
|
2024-01-30 07:57:36 +00:00
|
|
|
log.exception("%s: Unable to reload:", mod, exc_info=e)
|
2023-12-31 05:27:32 +00:00
|
|
|
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:
|
2024-01-20 04:01:45 +00:00
|
|
|
guild = ctx.guild
|
2023-12-31 05:27:32 +00:00
|
|
|
|
2024-01-18 03:34:48 +00:00
|
|
|
|
|
|
|
await ctx.channel.typing()
|
2023-12-31 05:27:32 +00:00
|
|
|
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-03-07 11:46:06 +00:00
|
|
|
@commands.is_owner()
|
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
|
|
|
|
2024-03-07 11:46:06 +00:00
|
|
|
@commands.hybrid_command(name="version")
|
|
|
|
async def version(self, ctx: commands.Context):
|
|
|
|
await ctx.reply(embed=discord.Embed(
|
|
|
|
title="Version information",
|
|
|
|
description=(
|
|
|
|
"## Core\n"
|
|
|
|
"**linaSTK**: {version}\n"
|
|
|
|
"**Python**: {pythonversion}\n"
|
|
|
|
"**discord.py**: {discordpyversion}\n"
|
|
|
|
"**AIOHTTP**: {aiohttpversion}\n"
|
|
|
|
"**asyncpg**: {asyncpgversion}\n\n"
|
|
|
|
"## Kernel Version\n"
|
|
|
|
"```\n{kernelver}\n```").format(
|
|
|
|
version=self.bot.version,
|
|
|
|
discordpyversion=discord.__version__,
|
|
|
|
pythonversion=python_version,
|
|
|
|
kernelver=open("/proc/version").read(),
|
|
|
|
aiohttpversion=aiohttp_version,
|
|
|
|
asyncpgversion=asyncpg_version
|
|
|
|
),
|
|
|
|
color=self.bot.accent_color
|
|
|
|
).set_thumbnail(url=self.bot.user.avatar.url),
|
|
|
|
mention_author=False)
|
|
|
|
|
2023-12-31 05:27:32 +00:00
|
|
|
async def setup(bot: Lina):
|
|
|
|
await bot.add_cog(Core(bot))
|