from aiogram import Router, F from aiogram.filters import CommandStart, CommandObject, Command from aiogram.types import CallbackQuery, Message from aiogram.fsm.context import FSMContext from sqlalchemy.ext.asyncio import AsyncSession from schemas.di import DependenciesDTO from keyboards.client import main_menu from texts import build_main_menu_text router = Router() @router.message(CommandStart(deep_link=True, deep_link_encoded=False)) async def fetch_referal( msg: Message, command: CommandObject, state: FSMContext, session: AsyncSession, deps: DependenciesDTO, ): await state.clear() data = command.args.split() if not data: await standard_start(msg, command, state) return referal = data[0] await deps.user_service.add_user(session, user_id=msg.from_user.id, referal=referal) await msg.reply(build_main_menu_text(), reply_markup=main_menu) @router.message(Command(commands=["start", "cancel"])) async def standard_start( msg: Message, command: CommandObject, state: FSMContext, session: AsyncSession, deps: DependenciesDTO, ): await state.clear() await deps.user_service.add_user(session, user_id=msg.from_user.id) await msg.reply(build_main_menu_text(), reply_markup=main_menu) @router.callback_query(F.data == "menu:main") async def main_menu_cb(cb: CallbackQuery, state: FSMContext): await state.clear() await cb.message.edit_text(build_main_menu_text(), reply_markup=main_menu)