Moved generating iss image to tpe
This commit is contained in:
parent
bfe7f5835d
commit
081b62d267
@ -536,7 +536,7 @@ class Utils:
|
|||||||
|
|
||||||
@commands.command(name='iss')
|
@commands.command(name='iss')
|
||||||
async def iss_loc(self, ctx):
|
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:
|
async with self.bot.aio_session.get('https://api.wheretheiss.at/v1/satellites/25544') as response:
|
||||||
iss_loc = await response.json()
|
iss_loc = await response.json()
|
||||||
|
|
||||||
@ -549,9 +549,13 @@ class Utils:
|
|||||||
plt.plot(x, y, 'ok', markersize=10, color='red')
|
plt.plot(x, y, 'ok', markersize=10, color='red')
|
||||||
plt.text(x, y, ' ISS', fontsize=20, color='red')
|
plt.text(x, y, ' ISS', fontsize=20, color='red')
|
||||||
|
|
||||||
with BytesIO() as output:
|
img = BytesIO()
|
||||||
plt.savefig(output, format='png', transparent=True)
|
plt.savefig(img, format='png', transparent=True)
|
||||||
output.seek(0)
|
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'))
|
await ctx.send(file=discord.File(output, 'output.png'))
|
||||||
|
|
||||||
# TODO Create Help command
|
# TODO Create Help command
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from postgres import Postgres
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
import asyncpg
|
import asyncpg
|
||||||
|
from concurrent import futures
|
||||||
|
|
||||||
|
|
||||||
log_format = '{asctime}.{msecs:03.0f}|{levelname:<8}|{name}::{message}'
|
log_format = '{asctime}.{msecs:03.0f}|{levelname:<8}|{name}::{message}'
|
||||||
@ -62,6 +63,7 @@ class Geeksbot(commands.Bot):
|
|||||||
self.voice_chans = {}
|
self.voice_chans = {}
|
||||||
self.spam_list = {}
|
self.spam_list = {}
|
||||||
self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key'])
|
self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key'])
|
||||||
|
self.tpe = futures.ThreadPoolExecutor()
|
||||||
|
|
||||||
async def connect_db(self):
|
async def connect_db(self):
|
||||||
self.db_con = await asyncpg.create_pool(host=self.bot_secrets['db_con']['host'],
|
self.db_con = await asyncpg.create_pool(host=self.bot_secrets['db_con']['host'],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user