Feature: Bot now can send VPS images to Telegram

This commit is contained in:
Marcos
2026-03-22 12:14:30 -03:00
parent a7d873ba07
commit 8c6264d14d

View File

@@ -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)