Update project configuration and codebase

This commit is contained in:
2026-04-12 12:19:53 +07:00
parent 0ed0ad2b92
commit 0ac8ed8d64
25 changed files with 273 additions and 310 deletions

View File

@@ -1,6 +1,6 @@
from .referals import router as referal_router
from .menus import router as menus_router
from .support import router as support_router
from .buy import router as buy_router
from .menus import router as menus_router
from .referals import router as referal_router
from .support import router as support_router
routers = [referal_router, menus_router, support_router, buy_router]

View File

@@ -1,15 +1,16 @@
import logging
from typing import Optional
from aiogram import Router, F
from aiogram.types import CallbackQuery
from aiogram import F, Router
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery
from sqlalchemy.ext.asyncio import AsyncSession
from config import settings
from keyboards.client import (
devices_selector,
duration_selector,
return_to_menu,
payment_gateways,
return_to_menu,
)
from misc.utils import (
calculate_price,
@@ -17,7 +18,7 @@ from misc.utils import (
)
from schemas.di import DependenciesDTO
from schemas.subscriptions import SubscriptionPlan
from services.user_service import UserServiceException
from services.user_service import UserServiceError
from states.buy import SubscriptionStorage
from texts import (
CALLBACK_FALLBACK,
@@ -30,7 +31,6 @@ from texts import (
SUBSCRIPTION_DURATION_SELECTOR,
SUPPORT_MSG_SENT,
)
from config import settings
router = Router()
logger = logging.getLogger(__name__)
@@ -55,7 +55,7 @@ async def device_count_select(cb: CallbackQuery, state: FSMContext):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx", SubscriptionPlan())
ctx: SubscriptionPlan | None = data.get("ctx", SubscriptionPlan())
cb_data = cb.data.split(":")
devices = int(cb_data[1]) if cb_data[1].isdigit() else settings.min_devices
@@ -75,17 +75,13 @@ async def toggle_whitelists(cb: CallbackQuery, state: FSMContext):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx", SubscriptionPlan())
ctx.whitelists = (
not ctx.whitelists or ctx.devices >= settings.whitelist_device_threshold
)
ctx: SubscriptionPlan | None = data.get("ctx", SubscriptionPlan())
ctx.whitelists = not ctx.whitelists or ctx.devices >= settings.whitelist_device_threshold
try:
await cb.message.edit_text(
SUBSCRIPTION_DEVICE_SELECTOR.format(price=calculate_price(ctx)),
reply_markup=devices_selector(
current=ctx.devices, whitelists=ctx.whitelists
),
reply_markup=devices_selector(current=ctx.devices, whitelists=ctx.whitelists),
)
except Exception as exc:
if "message is not modified:" in str(exc):
@@ -101,7 +97,7 @@ async def select_duration_init(cb: CallbackQuery, state: FSMContext):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx")
ctx: SubscriptionPlan | None = data.get("ctx")
if not ctx:
await cb.answer(CALLBACK_FALLBACK)
return
@@ -109,9 +105,7 @@ async def select_duration_init(cb: CallbackQuery, state: FSMContext):
try:
await cb.message.edit_text(
SUBSCRIPTION_DURATION_SELECTOR.format(price=calculate_price(ctx)),
reply_markup=duration_selector(
current=ctx.duration, back_cb=f"devices:{ctx.devices}"
),
reply_markup=duration_selector(current=ctx.duration, back_cb=f"devices:{ctx.devices}"),
)
except Exception as exc:
if "message is not modified:" in str(exc):
@@ -129,7 +123,7 @@ async def select_duration(cb: CallbackQuery, state: FSMContext):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx")
ctx: SubscriptionPlan | None = data.get("ctx")
if not ctx:
await cb.answer(CONTEXT_REINITIATED)
ctx = SubscriptionPlan()
@@ -140,9 +134,7 @@ async def select_duration(cb: CallbackQuery, state: FSMContext):
try:
await cb.message.edit_text(
SUBSCRIPTION_DURATION_SELECTOR.format(price=calculate_price(ctx)),
reply_markup=duration_selector(
current=ctx.duration, back_cb=f"devices:{ctx.devices}"
),
reply_markup=duration_selector(current=ctx.duration, back_cb=f"devices:{ctx.devices}"),
)
except Exception as exc:
if "message is not modified:" in str(exc):
@@ -160,7 +152,7 @@ async def proceed_to_checkout(cb: CallbackQuery, state: FSMContext):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx")
ctx: SubscriptionPlan | None = data.get("ctx")
if not ctx:
await cb.message.edit_text(STANDARD_FALLBACK, reply_markup=return_to_menu)
return
@@ -181,18 +173,16 @@ async def checkout_support(
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx")
ctx: SubscriptionPlan | None = data.get("ctx")
if not ctx:
await cb.message.edit_text(STANDARD_FALLBACK, reply_markup=return_to_menu)
return
await cb.message.edit_text(GENERAL_PROCESSING)
try:
await deps.user_service.create_subscription_ticket(
session, cb.from_user, ctx, cb.bot
)
await deps.user_service.create_subscription_ticket(session, cb.from_user, ctx, cb.bot)
await cb.message.edit_text(SUPPORT_MSG_SENT)
except UserServiceException:
except UserServiceError:
await cb.message.edit_text(STANDARD_FALLBACK)
raise
except Exception:

View File

@@ -1,13 +1,13 @@
from aiogram import Router, F
from aiogram.filters import CommandStart, CommandObject, Command
from aiogram.types import CallbackQuery, Message
from aiogram import F, Router
from aiogram.filters import Command, CommandObject, CommandStart
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery, Message
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
from misc.utils import build_main_menu_text, format_subscription_link
from schemas.di import DependenciesDTO
from texts import FAQ_TEXT, GENERAL_PROCESSING
router = Router()
@@ -47,9 +47,7 @@ async def standard_start(
):
await state.clear()
user = await deps.user_service.add_user(
session, user_id=msg.from_user.id, rw_sdk=deps.rw_sdk
)
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)),
@@ -77,9 +75,7 @@ async def update_link(
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
)
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)),

View File

@@ -1,15 +1,15 @@
from aiogram import Router, F
from aiogram import F, Router
from aiogram.filters import Command, CommandObject
from aiogram.utils.deep_linking import create_start_link
from aiogram.types import CallbackQuery, Message
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery, Message
from aiogram.utils.deep_linking import create_start_link
from sqlalchemy.ext.asyncio import AsyncSession
from config import settings
from keyboards.client import referals_kb
from misc.utils import format_share_deep_link
from schemas.di import DependenciesDTO
from texts import GENERAL_PROCESSING, REFERALS_MENU
from config import settings
router = Router()
@@ -57,7 +57,5 @@ async def refpay(
return
amount = int(amount)
await deps.user_repository.increase_user_balance(session, user.id, amount)
await status_msg.edit_text(
f"<b>💸 Баланс реферала ({referal.id}) пополнен на {amount}₽</b>"
)
await deps.user_repository.increase_user_balance(session, referal.id, amount)
await status_msg.edit_text(f"<b>💸 Баланс реферала ({referal.id}) пополнен на {amount}₽</b>")

View File

@@ -1,16 +1,17 @@
import logging
from aiogram import Router, F
from aiogram import F, Router
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery, Message
from sqlalchemy.ext.asyncio import AsyncSession
from config import settings
from keyboards.client import return_to_menu
from schemas.di import DependenciesDTO
from services.user_service import UserServiceException
from services.user_service import UserServiceError
from states.support import SupportStorage
from texts import GENERAL_PROCESSING, STANDARD_FALLBACK, SUPPORT_INIT, SUPPORT_MSG_SENT
from keyboards.client import return_to_menu
router = Router()
logger = logging.getLogger(__name__)
@@ -34,7 +35,7 @@ async def received_message(
try:
await deps.user_service.support_forward_message(session, msg, deps.rw_sdk)
except UserServiceException:
except UserServiceError:
await msg.reply(STANDARD_FALLBACK)
raise
except Exception: