each cog now handles its own http session

This commit is contained in:
phixxy 2024-02-13 01:54:36 -08:00
parent 10ac529323
commit 5331a5e2e7
7 changed files with 42 additions and 33 deletions

View file

@ -1,7 +1,6 @@
import os
import discord
from discord.ext import commands
import aiohttp
from dotenv import load_dotenv
import src.logger as logger
import src.utils as utils
@ -11,12 +10,6 @@ intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
bot.logger = logger.logger_setup()
async def create_session():
return aiohttp.ClientSession()
async def close_session(http_session):
await http_session.close()
async def load_cogs(bot: commands.Bot, cog_path: str) -> None:
for plugin_file in os.listdir(cog_path):
if plugin_file[-3:] == '.py':
@ -26,18 +19,6 @@ async def load_cogs(bot: commands.Bot, cog_path: str) -> None:
except:
bot.logger.exception(f"Failed to load plugin {plugin_file}")
@bot.event
async def on_connect():
bot.http_session = await create_session()
@bot.event
async def on_resumed():
bot.http_session = await create_session()
@bot.event
async def on_disconnect():
await close_session(bot.http_session)
@bot.event
async def on_ready():
try: