Introduce balance field to User model with Alembic migration. Add referral menu, admin /refpay command, and deep link sharing. Update Dockerfile to multi-stage build and add Postgres service to compose. Fix deep link parsing logic and conditional proxy initialization.
95 lines
2.7 KiB
Python
95 lines
2.7 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 misc.utils import format_subscription_link
|
|
from schemas.di import DependenciesDTO
|
|
from keyboards.client import main_menu, return_to_menu
|
|
from texts import GENERAL_PROCESSING, build_main_menu_text, FAQ_TEXT
|
|
|
|
router = Router()
|
|
|
|
|
|
@router.message(CommandStart(deep_link=True, deep_link_encoded=True))
|
|
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 = int(data[1])
|
|
user = await deps.user_service.add_user(
|
|
session, user_id=msg.from_user.id, referal=referal, rw_sdk=deps.rw_sdk
|
|
)
|
|
|
|
await msg.reply(
|
|
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
|
reply_markup=main_menu,
|
|
)
|
|
|
|
|
|
@router.message(Command(commands=["start", "cancel"]))
|
|
async def standard_start(
|
|
msg: Message,
|
|
state: FSMContext,
|
|
session: AsyncSession,
|
|
deps: DependenciesDTO,
|
|
):
|
|
await state.clear()
|
|
|
|
user = await deps.user_service.add_user(
|
|
session, user_id=msg.from_user.id, rw_sdk=deps.rw_sdk
|
|
)
|
|
|
|
await msg.reply(
|
|
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
|
reply_markup=main_menu,
|
|
)
|
|
|
|
|
|
@router.callback_query(F.data == "menu:main")
|
|
async def main_menu_cb(
|
|
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
|
):
|
|
await state.clear()
|
|
|
|
user = await deps.user_repository.get_user_by_id(session, cb.from_user.id)
|
|
await cb.message.edit_text(
|
|
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
|
reply_markup=main_menu,
|
|
)
|
|
|
|
|
|
@router.callback_query(F.data == "update_link")
|
|
async def update_link(
|
|
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
|
):
|
|
await state.clear()
|
|
await cb.message.edit_text(GENERAL_PROCESSING)
|
|
|
|
user = await deps.user_service.update_user_link(
|
|
session, cb.from_user.id, deps.rw_sdk
|
|
)
|
|
await cb.answer("✅")
|
|
await cb.message.edit_text(
|
|
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
|
reply_markup=main_menu,
|
|
)
|
|
|
|
|
|
@router.callback_query(F.data == "faq")
|
|
async def faq(cb: CallbackQuery, state: FSMContext):
|
|
await state.clear()
|
|
|
|
await cb.message.edit_text(FAQ_TEXT, reply_markup=return_to_menu)
|