From 90684ba27fb7fcc219041c0c2f30c478c3998fbe Mon Sep 17 00:00:00 2001 From: Michelle Date: Sat, 25 Apr 2026 17:28:16 +0200 Subject: [PATCH] fix: use aiohttp for racoon command --- main.py | 12 ++++-------- requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 0626c7e..338f0be 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import aiohttp import fluxer import requests import json @@ -166,17 +167,12 @@ async def racoon(message): "https://api.mapach.es/v1/meme", "https://api.mapach.es/v1/coon" ]) - response = requests.get(urls) + async with aiohttp.ClientSession() as session: + async with session.get(urls) as response: + image_bytes = await response.read() if response.status_code != 200: await message.channel.send("Failed to fetch racoon image") return - _, _, payload = response.text.strip().partition(",") - try: - image_bytes = base64.b64decode(payload) - except (ValueError, base64.binascii.Error): - await message.channel.send("Could not decode racoon image") - logging.warning(f"Failed to decode base64 image data: {payload}") - return await message.channel.send(file=fluxer.File(image_bytes, filename="racoon.jpg")) async def post_reddit(): diff --git a/requirements.txt b/requirements.txt index 8b2cade..8935d93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ fluxer.py requests asyncio -dotenv \ No newline at end of file +dotenv +aiohttp \ No newline at end of file