bot: cogs: add Debug cog and load extensions when bot is ready
All checks were successful
/ test (push) Successful in 18s
All checks were successful
/ test (push) Successful in 18s
As the name implies, the Debug cog is solely there to debug stuff. In the future the commands in that cog should only respond to whoever has the provided `BOT_OWNER_ID` (me). Additionally, extensions for discord.py are now loaded dynamically in `main.py`. Signed-off-by: Max R. Carrara <max@aequito.sh>
This commit is contained in:
parent
52d619377e
commit
e71558959c
2 changed files with 57 additions and 0 deletions
43
src/bot/cogs/debug.py
Normal file
43
src/bot/cogs/debug.py
Normal file
|
|
@ -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__)
|
||||||
|
|
@ -12,6 +12,9 @@ from bot.env import Environment
|
||||||
|
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
_default_extensions: dict[str, str] = {
|
||||||
|
"Debug": "bot.cogs.debug",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
|
|
@ -127,6 +130,17 @@ def register_event_handlers(bot: commands.Bot):
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
_log.info("Ready: Connected to Discord")
|
_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
|
@bot.event
|
||||||
async def on_resumed():
|
async def on_resumed():
|
||||||
_log.info("Resumed: Session with Discord resumed")
|
_log.info("Resumed: Session with Discord resumed")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue