diff --git a/src/main.py b/src/main.py index 2e5b090..e74c754 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,4 @@ +import asyncio import logging import os from shlex import join @@ -55,8 +56,13 @@ async def pixivprev(interaction: discord.Interaction, url: str): if result and match is not None: await interaction.response.defer() with TemporaryDirectory() as tmp_dir: - data = pixiv_api.dowload_pixiv_images( - int(match.group("id")), tmp_dir, REFRESH_TOKEN + loop = asyncio.get_running_loop() + data = await loop.run_in_executor( + None, + pixiv_api.dowload_pixiv_images, + int(match.group("id")), + tmp_dir, + REFRESH_TOKEN, ) if data is None: await interaction.response.send_message( @@ -86,8 +92,13 @@ async def pixiv_preview(interaction: discord.Interaction, message: discord.Messa if result and match is not None: await interaction.response.defer() with TemporaryDirectory() as tmp_dir: - data = pixiv_api.dowload_pixiv_images( - int(match.group("id")), tmp_dir, REFRESH_TOKEN + loop = asyncio.get_running_loop() + data = await loop.run_in_executor( + None, + pixiv_api.dowload_pixiv_images, + int(match.group("id")), + tmp_dir, + REFRESH_TOKEN, ) if data is None: await interaction.response.send_message( @@ -126,8 +137,13 @@ async def on_message(message: discord.Message): if result and match is not None: with TemporaryDirectory() as tmp_dir: async with message.channel.typing(): - data = pixiv_api.dowload_pixiv_images( - int(match.group("id")), tmp_dir, REFRESH_TOKEN + loop = asyncio.get_running_loop() + data = await loop.run_in_executor( + None, + pixiv_api.dowload_pixiv_images, + int(match.group("id")), + tmp_dir, + REFRESH_TOKEN, ) if data is None: return