From 404244c573584e4125a0676373b3ed27bc7e936e Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 15 Feb 2024 22:37:41 -0800 Subject: [PATCH] fixed bot_base_cog and made an example cog --- cogs/base_cog/bot_base_cog.py | 8 +++++--- examples/cog_example.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 examples/cog_example.py diff --git a/cogs/base_cog/bot_base_cog.py b/cogs/base_cog/bot_base_cog.py index 4f78435..abffe95 100644 --- a/cogs/base_cog/bot_base_cog.py +++ b/cogs/base_cog/bot_base_cog.py @@ -6,12 +6,14 @@ import logging class BotBaseCog(commands.Cog): def __init__(self, bot): self.bot = bot - self.cog_name = __name__ + self.http_session = self.create_aiohttp_session() + self.logger = logging.getLogger("bot") + + def setup(self, name): + self.cog_name = name.lower() self.working_dir = f"tmp/{self.cog_name}" self.data_dir = f"data/{self.cog_name}" self.folder_setup() - self.http_session = self.create_aiohttp_session() - self.logger = logging.getLogger("bot") def create_aiohttp_session(self): return aiohttp.ClientSession() diff --git a/examples/cog_example.py b/examples/cog_example.py new file mode 100644 index 0000000..11c4f09 --- /dev/null +++ b/examples/cog_example.py @@ -0,0 +1,16 @@ +from discord.ext import commands +from cogs.base_cog.bot_base_cog import BotBaseCog + +class Ping(BotBaseCog): + + def __init__(self, bot): + super().__init__(bot) + self.setup(__class__.__name__) + + @commands.command() + async def ping(self, ctx): + await ctx.send("pong") + self.logger.info(f"Ping command called by {ctx.author.name}") + +async def setup(bot): + await bot.add_cog(Ping(bot)) \ No newline at end of file