Бот для капчи в чатах
Roman Sergienko
8 hours ago 0b66bae39759a5553d8ce46131dca3026325097b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)