Feature: Bot now can send VPS images to Telegram
This commit is contained in:
22
bot_logic.py
22
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) # 
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user