diff --git a/tgbot/requirements.txt b/tgbot/requirements.txt index d2243c3..8aa51f4 100644 --- a/tgbot/requirements.txt +++ b/tgbot/requirements.txt @@ -5,7 +5,7 @@ httpcore==1.0.6 httpx==0.27.2 idna==3.10 pillow==11.0.0 -python-telegram-bot==21.6 +python-telegram-bot==21.11.1 sniffio==1.3.1 requests==2.32.3 Pybooru==4.2.2 diff --git a/tgbot/shit/prompting.py b/tgbot/shit/prompting.py index 164e79e..fc495b5 100644 --- a/tgbot/shit/prompting.py +++ b/tgbot/shit/prompting.py @@ -4,8 +4,11 @@ import json import random import shlex import threading +from io import BytesIO import aiohttp +import httpx +import requests import telegram import websockets from telegram import Update @@ -47,10 +50,22 @@ async def ws_task(): print(f"Received message: {message}") + # Download the image + async with httpx.AsyncClient() as client: + response = await client.get(image_url) + response.raise_for_status() # Raise an exception for HTTP errors + + # Create a BytesIO object from the image data + image_bytes = BytesIO(response.content) + bot = telegram.Bot(TOKEN) async with bot: - await bot.send_photo(chat_id=chat_id, photo=image_url, caption=str(message)) + await bot.send_document( + chat_id=chat_id, + document=image_bytes, + caption=str(message) + ) del scheduled_prompts[prompt_id] @@ -232,7 +247,7 @@ async def gen_image(update: Update, context: ContextTypes.DEFAULT_TYPE): models = await list_models() return await context.bot.send_message(chat_id=update.effective_chat.id, text=models) - query = query.replace("prompting", "").replace("—", "--").replace("\n", "") + query = update.message.text.replace("prompting", "").replace("—", "--").replace("\n", "") parser = create_prompting_parser() @@ -274,4 +289,5 @@ async def gen_image(update: Update, context: ContextTypes.DEFAULT_TYPE): else: return await context.bot.send_message(chat_id=update.effective_chat.id, - text="Some weird incomprehensible error occurred :<") + text="Some weird incomprehensible error occurred :<\n" + + json.dumps(result))