diff --git a/src/bot/cogs/debug.py b/src/bot/cogs/debug.py new file mode 100644 index 0000000..e4d4c92 --- /dev/null +++ b/src/bot/cogs/debug.py @@ -0,0 +1,43 @@ +import asyncio +import logging + +import discord +from discord.ext import commands + +from bot.types import RichEmbed + +_log = logging.getLogger(__name__) + + +class Debug(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot = bot + + @commands.command() + async def ping(self, ctx: commands.Context): + _log.debug("pong!") + + embed: RichEmbed = { + "type": "rich", + "description": "Pong." + } + + await ctx.send(embed=discord.Embed.from_dict(embed)) + + +async def setup(bot: commands.Bot): + _log.debug("Adding Debug cog") + await bot.add_cog(Debug(bot)) + + cog = bot.get_cog(Debug.__name__) + + if cog is None: + return + + _log.debug("Loaded Debug cog with the following commands:") + _log.debug([c.name for c in cog.get_commands()]) + + +async def teardown(bot: commands.Bot): + _log.debug("Removing Debug cog") + await bot.remove_cog(Debug.__name__) diff --git a/src/bot/main.py b/src/bot/main.py index 0709a4b..4f9c8ad 100644 --- a/src/bot/main.py +++ b/src/bot/main.py @@ -12,6 +12,9 @@ from bot.env import Environment _log = logging.getLogger(__name__) +_default_extensions: dict[str, str] = { + "Debug": "bot.cogs.debug", +} def setup_logging(): @@ -127,6 +130,17 @@ def register_event_handlers(bot: commands.Bot): async def on_ready(): _log.info("Ready: Connected to Discord") + _log.info("Loading extensions") + for ext_name, ext_path in _default_extensions.items(): + try: + _log.info(f'Loading extension "{ext_name}" ({ext_path})') + await bot.load_extension(ext_path) + _log.info(f'Loaded extension "{ext_name}" ({ext_path})') + except Exception as e: + _log.error( + f'Failed to load extension "{ext_name}" ({ext_path})', exc_info=e + ) + @bot.event async def on_resumed(): _log.info("Resumed: Session with Discord resumed")