From 8c6264d14d10570165669c7be42aa866635f8701 Mon Sep 17 00:00:00 2001 From: Marcos Date: Sun, 22 Mar 2026 12:14:30 -0300 Subject: [PATCH] Feature: Bot now can send VPS images to Telegram --- bot_logic.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bot_logic.py b/bot_logic.py index be78092..bc34c78 100644 --- a/bot_logic.py +++ b/bot_logic.py @@ -71,6 +71,28 @@ async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_voice(voice=open(audio_path, 'rb')) return + # --- NOVO: Lógica para enviar IMAGENS se a IA localizou um arquivo --- + import re + # Procura por padrões de imagem Markdown ou caminhos absolutos de imagem + img_matches = re.findall(r'!\[.*?\]\((/.*?)\)', reply) # ![alt](/caminho/img.jpg) + if not img_matches: + # Tenta achar caminhos absolutos que terminam em extensões de imagem + img_matches = re.findall(r'(/[^\s]+?\.(?:jpg|jpeg|png|gif|webp))', reply, re.IGNORECASE) + + if img_matches: + for img_path in img_matches: + # Garante que o caminho use /host_root se for um arquivo da VPS + real_path = img_path + if not real_path.startswith("/host_root") and real_path.startswith("/root"): + real_path = f"/host_root{real_path}" + + if os.path.exists(real_path): + try: + await update.message.reply_chat_action(action="upload_photo") + await update.message.reply_photo(photo=open(real_path, 'rb'), caption="🖼️ Imagem localizada na VPS") + except Exception as e: + print(f"Erro ao enviar imagem {real_path}: {e}") + # Responde no chat normalmente await update.message.reply_text(reply)