Бот для капчи в чатах
Roman Sergienko
8 hours ago c80fb18220a339f2b1a218fd1b5886e0a41725f6
cmds.py
@@ -1,5 +1,6 @@
from aiogram import F, types
from aiogram.filters import Command, CommandObject
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
import db
import cfg
@@ -16,6 +17,7 @@
    "/areport <текст> - жалоба администрации (можно ответом на сообщение)\n"
    "\n"
    "Для администраторов:\n"
    "/panel - открыть панель управления этим чатом (Mini App)\n"
    "/config - настройки капчи\n"
    "/config <кнопки> <секунды> <попытки> - изменить капчу\n"
    "/warncfg <лимит> <mute|ban> <время> - настроить систему варнов\n"
@@ -73,18 +75,74 @@
@dp.message(Command("start"))
async def cmd_start(message: types.Message) -> None:
async def cmd_start(message: types.Message, command: CommandObject) -> None:
    if message.chat.type == "private" and message.from_user is not None:
        # Запоминаем, что боту можно писать в ЛС (для уведомлений тревоги).
        await db.add_dm(message.from_user.id, now_ts())
        # Обработка параметра start для panel_{chat_id}
        args = (command.args or "").strip()
        if args and args.startswith("panel_"):
            if not cfg.WEB_BASE_URL:
                await message.answer("Панель недоступна.")
                return
            try:
                chat_id = int(args[6:])
                # Проверяем права на этот чат
                if not await check_perm(chat_id, message.from_user.id, P_CFG):
                    await message.answer("У вас нет доступа к панели этого чата.")
                    return
                keyboard = InlineKeyboardMarkup(inline_keyboard=[[
                    InlineKeyboardButton(
                        text="Открыть панель",
                        web_app=WebAppInfo(url=f"{cfg.WEB_BASE_URL}/miniapp?chat_id={chat_id}"),
                    )
                ]])
                await message.answer("Панель управления чатом:", reply_markup=keyboard)
                return
            except ValueError:
                pass
        # Стандартный старт
        keyboard = None
        if cfg.WEB_BASE_URL:
            keyboard = InlineKeyboardMarkup(inline_keyboard=[[
                InlineKeyboardButton(
                    text="Открыть панель",
                    web_app=WebAppInfo(url=f"{cfg.WEB_BASE_URL}/miniapp"),
                )
            ]])
        await message.answer(
            "Привет! Я Amadeus. Теперь сюда будут приходить уведомления о тревоге. "
            "Добавь меня в чат и выдай права администратора."
            "Добавь меня в чат и выдай права администратора.",
            reply_markup=keyboard,
        )
    else:
        await message.answer("Привет! Список команд: /help")
@dp.message(Command("panel"))
async def cmd_panel(message: types.Message) -> None:
    if message.from_user is None or message.chat.type == "private":
        return
    if not cfg.WEB_BASE_URL:
        await message.answer("Панель недоступна.")
        return
    if not await check_perm(message.chat.id, message.from_user.id, P_CFG):
        await message.answer("У вас нет доступа к панели.")
        return
    # Формируем ссылку на открытие бота с параметром panel_{chat_id}
    bot_username = (await bot.get_me()).username
    panel_link = f"https://t.me/{bot_username}?start=panel_{message.chat.id}"
    keyboard = InlineKeyboardMarkup(inline_keyboard=[[
        InlineKeyboardButton(
            text="Открыть панель",
            url=panel_link,
        )
    ]])
    await message.answer("Панель управления чатом:", reply_markup=keyboard)
@dp.message(Command("floodcfg"))
async def cmd_floodcfg(message: types.Message, command: CommandObject) -> None:
    if message.from_user is None: