diff --git a/main.py b/main.py index 94719f9..0861170 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import fluxer import requests import json import asyncio +import base64 from dotenv import load_dotenv import sqlite3 import os @@ -158,6 +159,29 @@ async def fox(message): else: await message.channel.send("Failed to fetch fox image") +# time for racoons +@bot.command() +async def racoon(message): + urls = random.choice([ + "https://api.mapach.es/v1/meme", + "https://api.mapach.es/v1/coon" + ]) + response = requests.get(urls) + if response.status_code != 200: + await message.channel.send("Failed to fetch racoon image") + return + match = re.match(r"data:image/(\w+);base64,(.+)", response.text.strip()) + if not match: + await message.channel.send("Could not fetch racoon image") + return + ext, payload = match.group(1), match.group(2) + try: + image_bytes = base64.b64decode(payload) + except (ValueError, base64.binascii.Error): + await message.channel.send("Could not decode racoon image") + return + await message.channel.send(file=fluxer.File(image_bytes, filename=f"racoon.{ext}")) + async def post_reddit(): subreddit = os.getenv("SUBREDDIT", "ich_iel") posts = await get_latest_post(subreddit)