Added base cog to inherit from
This commit is contained in:
parent
d39a5c395b
commit
02fa32cb1c
4 changed files with 34 additions and 19 deletions
28
cogs/base_cog/bot_base_cog.py
Normal file
28
cogs/base_cog/bot_base_cog.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import os
|
||||
import aiohttp
|
||||
from discord.ext import commands
|
||||
import logging
|
||||
|
||||
class BotBaseCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.class_name = __name__
|
||||
self.working_dir = f"tmp/{self.class_name}"
|
||||
self.data_dir = f"data/{self.class_name}"
|
||||
self.folder_setup()
|
||||
|
||||
self.http_session = self.create_aiohttp_session()
|
||||
self.logger = logging.getLogger("bot")
|
||||
|
||||
|
||||
def create_aiohttp_session(self):
|
||||
return aiohttp.ClientSession()
|
||||
|
||||
def folder_setup(self) -> None:
|
||||
try:
|
||||
if not os.path.exists(self.working_dir):
|
||||
os.mkdir(self.working_dir)
|
||||
if not os.path.exists(self.data_dir):
|
||||
os.mkdir(self.data_dir)
|
||||
except:
|
||||
self.logger.exception(f"{self.class_name} failed to make directories")
|
||||
Loading…
Add table
Add a link
Reference in a new issue