- Add subscription_link column to users table (nullable, unique) - Add SUBSCRIPTION_URL to config settings - Update user creation to include subscription link from Remnawave - Add support subscription ticket creation with formatted message - Add "update link" button to main menu - Refactor support subscription formatting to include user details
96 lines
2.7 KiB
Python
96 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=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]
|
|
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,
|
|
command: CommandObject,
|
|
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)
|