ImageConvert: use non-blocking aiohttp instead
from io import BytesIO
-import requests
+import aiohttp
from PIL import Image
class ImageConvert:
@@ -14,8 +14,10 @@ class ImageConvert:
# BMP conversion
for f in message.attachments:
if f["filename"].lower().endswith('.bmp') and f["size"] <= 600000: # 600kb
- img_request = requests.get(f["url"])
- img_obj = Image.open(BytesIO(img_request.content))
+ async with aiohttp.ClientSession() as session:
+ async with session.get(f["url"]) as img_request:
+ img_content = await img_request.read()
+ img_obj = Image.open(BytesIO(img_content))
img_out = BytesIO()
img_obj.save(img_out, 'png')
img_out.seek(0)
