diff --git a/exts/utils.py b/exts/utils.py index 85ef806..5b25256 100644 --- a/exts/utils.py +++ b/exts/utils.py @@ -536,7 +536,7 @@ class Utils: @commands.command(name='iss') async def iss_loc(self, ctx): - async with ctx.typing(): + def gen_image(): async with self.bot.aio_session.get('https://api.wheretheiss.at/v1/satellites/25544') as response: iss_loc = await response.json() @@ -549,9 +549,13 @@ class Utils: plt.plot(x, y, 'ok', markersize=10, color='red') plt.text(x, y, ' ISS', fontsize=20, color='red') - with BytesIO() as output: - plt.savefig(output, format='png', transparent=True) - output.seek(0) + img = BytesIO() + plt.savefig(img, format='png', transparent=True) + img.seek(0) + return img + + async with ctx.typing(): + async with self.bot.loop.run_in_executor(self.bot.tpe, gen_image) as output: await ctx.send(file=discord.File(output, 'output.png')) # TODO Create Help command diff --git a/geeksbot.py b/geeksbot.py index 6264688..0e3307b 100644 --- a/geeksbot.py +++ b/geeksbot.py @@ -9,6 +9,7 @@ from postgres import Postgres from collections import deque from googleapiclient.discovery import build import asyncpg +from concurrent import futures log_format = '{asctime}.{msecs:03.0f}|{levelname:<8}|{name}::{message}' @@ -62,6 +63,7 @@ class Geeksbot(commands.Bot): self.voice_chans = {} self.spam_list = {} self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key']) + self.tpe = futures.ThreadPoolExecutor() async def connect_db(self): self.db_con = await asyncpg.create_pool(host=self.bot_secrets['db_con']['host'],