from aiogram import types
|
import pathlib
|
|
import db
|
from cfg import dp
|
|
|
@dp.message()
|
async def rp_action_handler(message: types.Message) -> None:
|
"""Проверяет сообщение на РП триггеры и отправляет действие если найдено."""
|
if not message.text or message.from_user is None:
|
return
|
|
# Пропускаем команды
|
if message.text.startswith("/"):
|
return
|
|
action = await db.check_rp_trigger(message.chat.id, message.text)
|
if not action:
|
return
|
|
# Формируем ответ
|
response = action["response_text"].format(user=message.from_user.first_name)
|
|
# Отправляем гифку + текст
|
if action["gif_file_id"]:
|
try:
|
gif_path = action["gif_file_id"]
|
# Проверяем, является ли это локальным файлом или Telegram file_id
|
if isinstance(gif_path, str) and (gif_path.startswith("data/") or pathlib.Path(gif_path).exists()):
|
# Локальный файл
|
with open(gif_path, "rb") as f:
|
await message.reply_animation(
|
animation=f,
|
caption=response,
|
show_caption_above_media=True,
|
)
|
else:
|
# Telegram file_id
|
await message.reply_animation(
|
animation=gif_path,
|
caption=response,
|
show_caption_above_media=True,
|
)
|
except Exception:
|
# Если гифка недоступна, отправляем просто текст
|
await message.reply(response)
|
else:
|
await message.reply(response)
|