Files
malenia/handlers/menus.py
hexdev 930fabc028 Implement buy flow and migrate DTOs to schemas
Move DTO definitions from dto/ to schemas/ and update imports.
Add buy handler with FSM state management for device selection,
whitelist toggling, and duration choice. Include pricing logic,
inline keyboards, and new configuration fields.
2026-04-08 19:34:25 +07:00

55 lines
1.5 KiB
Python

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)