From d94430c602492fbb1259d1ed32d7b8f3636bc3b5 Mon Sep 17 00:00:00 2001 From: machka-pasla Date: Fri, 5 Sep 2025 14:55:54 +0300 Subject: [PATCH] Enhance ad creation flow with state-based filtering - Introduced StateFilter to the ads creation flow, ensuring that messages are processed only when the bot is in specific admin states. - Improved the organization of imports by removing redundant imports and clarifying state management for ad-related interactions. --- bot/handlers/admin/ads.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bot/handlers/admin/ads.py b/bot/handlers/admin/ads.py index 88f5b1c..7ba5e6b 100644 --- a/bot/handlers/admin/ads.py +++ b/bot/handlers/admin/ads.py @@ -1,5 +1,6 @@ import logging from aiogram import Router, F, types +from aiogram.filters import StateFilter from aiogram.fsm.context import FSMContext from typing import Optional from sqlalchemy.ext.asyncio import AsyncSession @@ -7,6 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from config.settings import Settings from bot.middlewares.i18n import JsonI18n from db.dal import ad_dal +from bot.states.admin_states import AdminStates router = Router(name="admin_ads_router") @@ -76,9 +78,15 @@ async def ads_create_start(callback: types.CallbackQuery, state: FSMContext, set pass -@router.message(F.text, state="*") +@router.message( + StateFilter( + AdminStates.waiting_for_ad_source, + AdminStates.waiting_for_ad_start_param, + AdminStates.waiting_for_ad_cost, + ), + F.text, +) async def ads_create_flow(message: types.Message, state: FSMContext, settings: Settings, i18n_data: dict, session: AsyncSession): - from bot.states.admin_states import AdminStates current_state = await state.get_state() if current_state not in ( AdminStates.waiting_for_ad_source.state,