aboutsummaryrefslogtreecommitdiffstats
path: root/bot/cogs/math.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-03-10 10:55:01 +0000
committerGravatar GitHub <[email protected]>2018-03-10 10:55:01 +0000
commit7991fb225b9a934e8a581c6b998f1da21ce578b5 (patch)
tree2ad2c629bd4a5535a04aabf0aba3cf368296ef36 /bot/cogs/math.py
parentCommenting out the codeblocks detection code, it appears to be interfering wi... (diff)
Aiohttp fixes (#27)
* Attempt to fix issues with aiohttp spawning way too many threads * Add aiodns to requirements * Math doesn't work for me `Fatal Python error: failed to get random numbers to initialize Python`
Diffstat (limited to 'bot/cogs/math.py')
-rw-r--r--bot/cogs/math.py24
1 files changed, 10 insertions, 14 deletions
diff --git a/bot/cogs/math.py b/bot/cogs/math.py
index 0ef045748..649cf4915 100644
--- a/bot/cogs/math.py
+++ b/bot/cogs/math.py
@@ -8,8 +8,6 @@ from io import BytesIO
from re import search
from subprocess import PIPE, Popen, STDOUT, TimeoutExpired # noqa: B404
-from aiohttp import ClientSession
-
from discord import File
from discord.ext.commands import command
@@ -78,14 +76,13 @@ class Math:
"color": 808080
}
- async with ClientSession() as session:
- async with session.post(LATEX_URL, data=data) as resp:
- html = await resp.text()
+ async with self.bot.http_session.post(LATEX_URL, data=data) as resp:
+ html = await resp.text()
- name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group('url')
+ name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group('url')
- async with session.get(f"{LATEX_URL}/output/{name}.png") as resp:
- bytes_img = await resp.read()
+ async with self.bot.http_session.get(f"{LATEX_URL}/output/{name}.png") as resp:
+ bytes_img = await resp.read()
file = File(fp=BytesIO(bytes_img), filename="latex.png")
@@ -119,14 +116,13 @@ class Math:
"color": 808080
}
- async with ClientSession() as session:
- async with session.post(LATEX_URL, data=data) as resp:
- html = await resp.text()
+ async with self.bot.http_session.post(LATEX_URL, data=data) as resp:
+ html = await resp.text()
- name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group('url')
+ name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group('url')
- async with session.get(f"{LATEX_URL}/output/{name}.png") as resp:
- bytes_img = await resp.read()
+ async with self.bot.http_session.get(f"{LATEX_URL}/output/{name}.png") as resp:
+ bytes_img = await resp.read()
file = File(fp=BytesIO(bytes_img), filename="latex.png")