From 675e5ab891a368c04974a0c11c4124eb2b9592eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=ADITQ?= Date: Sat, 23 Mar 2024 02:42:41 +0300 Subject: [PATCH] fix: Fixed error with calling commands within active state --- app/callbacks/profile.py | 2 +- app/handlers/help_command.py | 4 ++-- app/handlers/menu_command.py | 4 ++-- app/handlers/profile_command.py | 4 ++-- app/handlers/start_command.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/callbacks/profile.py b/app/callbacks/profile.py index f6d404a..4f1d336 100644 --- a/app/callbacks/profile.py +++ b/app/callbacks/profile.py @@ -180,6 +180,7 @@ async def profile_change_entered(message: Message, state: FSMContext) -> None: successfully=True, ) + await message.delete() await delete_message_from_state(state, message.chat.id, message.bot) state_data = await state.get_data() @@ -220,7 +221,6 @@ async def profile_change_entered(message: Message, state: FSMContext) -> None: except TelegramBadRequest: pass - await message.delete() await message.answer( messages.PROFILE_UPDATED, reply_markup=ReplyKeyboardRemove(), diff --git a/app/handlers/help_command.py b/app/handlers/help_command.py index 2aadb11..94d0ed7 100644 --- a/app/handlers/help_command.py +++ b/app/handlers/help_command.py @@ -1,7 +1,7 @@ __all__ = () from aiogram import Router -from aiogram.filters import Command +from aiogram.filters import Command, StateFilter from aiogram.types import Message from app import messages @@ -11,6 +11,6 @@ from app.filters.user import Registered router = Router(name="help_command") -@router.message(Command("help"), Registered()) +@router.message(Command("help"), Registered(), StateFilter(None)) async def command_help_handler(message: Message) -> None: await message.answer(messages.HELP_MESSAGE) diff --git a/app/handlers/menu_command.py b/app/handlers/menu_command.py index 9dea594..43b0751 100644 --- a/app/handlers/menu_command.py +++ b/app/handlers/menu_command.py @@ -1,7 +1,7 @@ __all__ = () from aiogram import Router -from aiogram.filters import Command +from aiogram.filters import Command, StateFilter from aiogram.types import Message from app import messages @@ -12,6 +12,6 @@ from app.keyboards.menu import get router = Router(name="menu_command") -@router.message(Command("menu"), Registered()) +@router.message(Command("menu"), Registered(), StateFilter(None)) async def command_menu_handler(message: Message) -> None: await message.answer(messages.MENU, reply_markup=get()) diff --git a/app/handlers/profile_command.py b/app/handlers/profile_command.py index 5b05b7d..4a234cd 100644 --- a/app/handlers/profile_command.py +++ b/app/handlers/profile_command.py @@ -1,7 +1,7 @@ __all__ = () from aiogram import Router -from aiogram.filters import Command +from aiogram.filters import Command, StateFilter from aiogram.types import Message from app import messages @@ -13,7 +13,7 @@ from app.models.user import User router = Router(name="profile_command") -@router.message(Command("profile"), Registered()) +@router.message(Command("profile"), Registered(), StateFilter(None)) async def command_profile_handler(message: Message) -> None: if message.from_user is None: return diff --git a/app/handlers/start_command.py b/app/handlers/start_command.py index 9013790..f21f0dd 100644 --- a/app/handlers/start_command.py +++ b/app/handlers/start_command.py @@ -1,7 +1,7 @@ __all__ = () from aiogram import F, Router -from aiogram.filters import CommandStart +from aiogram.filters import CommandStart, StateFilter from aiogram.fsm.context import FSMContext from aiogram.types import Message, ReplyKeyboardRemove @@ -18,7 +18,7 @@ from app.utils.states import ( router = Router(name="start_command") -@router.message(CommandStart()) +@router.message(CommandStart(), StateFilter(None)) async def command_start_handler(message: Message, state: FSMContext) -> None: if message.from_user is None: return