Moved waifu pics to a separate module and improved shutdown handling.

This commit is contained in:
kku 2024-12-16 20:00:32 +01:00
parent 53d5827ed9
commit 5c763fc02e
3 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ from libbot.sync import config_get as sync_config_get
from enums.colors import Color from enums.colors import Color
from modules.scheduled import scheduler from modules.scheduled import scheduler
from modules.utils_sync import guild_name from modules.utils_sync import guild_name
from modules.waifu_pics import waifu_pics
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -186,6 +187,7 @@ class Admin(commands.Cog):
) )
scheduler.shutdown() scheduler.shutdown()
await self.client.close() await self.client.close()
await waifu_pics._client_session.close()
sys.exit() sys.exit()
logging.warning( logging.warning(

View File

@ -1,6 +1,5 @@
import logging import logging
from WaifuPicsPython import WaifuAsync
from discord import ApplicationContext, Embed, User, option, slash_command from discord import ApplicationContext, Embed, User, option, slash_command
from discord.ext import commands from discord.ext import commands
from libbot import config_get from libbot import config_get
@ -8,11 +7,10 @@ from libbot.pycord.classes import PycordBot
from libbot.sync import config_get as sync_config_get from libbot.sync import config_get as sync_config_get
from modules.utils_sync import guild_name from modules.utils_sync import guild_name
from modules.waifu_pics import waifu_pics
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
wafiu_pics = WaifuAsync()
class Fun(commands.Cog): class Fun(commands.Cog):
def __init__(self, client: PycordBot): def __init__(self, client: PycordBot):
@ -35,7 +33,7 @@ class Fun(commands.Cog):
action = await config_get("category", "actions", type) action = await config_get("category", "actions", type)
action_verb = await config_get("action", "actions", type) action_verb = await config_get("action", "actions", type)
image = await wafiu_pics.sfw(action) image = await waifu_pics.sfw(action)
logger.info( logger.info(
"User %s (%s) %s %s (%s) with image %s", "User %s (%s) %s %s (%s) with image %s",

3
modules/waifu_pics.py Normal file
View File

@ -0,0 +1,3 @@
from WaifuPicsPython import WaifuAsync
waifu_pics: WaifuAsync = WaifuAsync()