From 44aa85fb74ab9f60e1f10deac5072fe37379b11b Mon Sep 17 00:00:00 2001 From: Verum Date: Mon, 23 Feb 2026 14:18:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/handlers/commands/users/cancel.py | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 bot/handlers/commands/users/cancel.py diff --git a/bot/handlers/commands/users/cancel.py b/bot/handlers/commands/users/cancel.py new file mode 100644 index 0000000..bd9d059 --- /dev/null +++ b/bot/handlers/commands/users/cancel.py @@ -0,0 +1,48 @@ +# ====================================================================== +# CLOSE / CANCEL +# ====================================================================== +from __future__ import annotations + +from typing import Optional, Tuple, Dict, Any, List + +from aiogram import Router, F, Bot +from aiogram.types import Message, CallbackQuery +from aiogram.filters import Command +from aiogram.utils.keyboard import InlineKeyboardBuilder +from aiogram.utils.markdown import hide_link +from aiogram.exceptions import TelegramBadRequest, TelegramForbiddenError + +from aiogram.fsm.context import FSMContext +from aiogram.fsm.state import State, StatesGroup + +from configs import settings, COMMANDS +from database import get_manager, AutoComment +from middleware.loggers import logger +from bot.filters.admin import IsAdmin +from bot.utils import log_action, tg_emoji + +__all__ = ("router",) +CMD: str = "cancel" +router: Router = Router(name="channel_comments_router") + +@router.callback_query(F.data == "menu:close") +async def close_menu_callback(callback: CallbackQuery, state: FSMContext) -> None: + await state.clear() + try: + if callback.message: + await callback.message.delete() + except TelegramBadRequest: + pass + await callback.answer("❌ Меню закрыто") + +@router.callback_query(F.data.casefold() == CMD) +@router.message(Command(*COMMANDS[CMD], prefix=settings.PREFIX, ignore_case=True), IsAdmin()) +@log_action(action_name="START_COMMAND", log_args=True) +async def cancel_handler(message: Message, state: FSMContext) -> None: + current_state = await state.get_state() + if current_state is None: + await message.answer("❌ Нечего отменять") + return + + await state.clear() + await message.answer("✅ Действие отменено")