Refactor bot handlers and keyboards; implement admin features
- Removed unused prehandling, referrals, support, and states files. - Updated admin and client handlers to improve structure and functionality. - Introduced admin filters and routers for better access control. - Added new billing and deposit functionalities for client interactions. - Enhanced keyboard layouts for admin and client menus. - Implemented promotion handling for admin users. - Updated configuration to include admin settings. - Improved utility functions for quote fetching and menu text building. - Added common handlers for undefined commands and message deletions.
This commit is contained in:
58
bot/handlers/client/deposit.py
Normal file
58
bot/handlers/client/deposit.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from aiogram import F, Router
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
|
||||
from bot.keyboards.client import payment_gateways
|
||||
from bot.keyboards.common import return_to_menu
|
||||
from bot.states.buy import BillingStorage
|
||||
from bot.states.deposit import DepositStorage
|
||||
from bot.texts import (
|
||||
CHECKOUT_PAYMENT_CHOICE,
|
||||
DEPOSIT_AMOUNT,
|
||||
DEPOSIT_AMOUNT_BELOW_MINIMAL,
|
||||
DEPOSIT_AMOUNT_FALLBACK,
|
||||
)
|
||||
from config import settings
|
||||
from schemas.billing import BillingContext
|
||||
from schemas.common import GeneralMessageContext
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.callback_query(F.data == "deposit")
|
||||
async def deposit_init(cb: CallbackQuery, state: FSMContext):
|
||||
await state.clear()
|
||||
|
||||
await cb.message.edit_text(DEPOSIT_AMOUNT, reply_markup=return_to_menu)
|
||||
|
||||
ctx = GeneralMessageContext(msg=cb.message)
|
||||
await state.set_state(DepositStorage.amount)
|
||||
await state.set_data({"ctx": ctx})
|
||||
|
||||
|
||||
@router.message(DepositStorage.amount)
|
||||
async def deposit_amount(msg: Message, state: FSMContext):
|
||||
data = await state.get_data()
|
||||
await state.clear()
|
||||
await msg.delete()
|
||||
|
||||
ctx: GeneralMessageContext | None = data.get("ctx")
|
||||
if not isinstance(ctx, GeneralMessageContext) or not msg.text.isdigit():
|
||||
await msg.answer(DEPOSIT_AMOUNT_FALLBACK, reply_markup=return_to_menu)
|
||||
await state.set_state(DepositStorage.amount)
|
||||
await state.set_data(data)
|
||||
return
|
||||
|
||||
if int(msg.text) < settings.deposit_threshold:
|
||||
await ctx.msg.edit_text(
|
||||
DEPOSIT_AMOUNT_BELOW_MINIMAL.format(threshold=settings.deposit_threshold),
|
||||
reply_markup=return_to_menu,
|
||||
)
|
||||
await state.set_state(DepositStorage.amount)
|
||||
await state.set_data(data)
|
||||
return
|
||||
|
||||
await ctx.msg.edit_text(CHECKOUT_PAYMENT_CHOICE, reply_markup=payment_gateways)
|
||||
await state.set_state(BillingStorage.pending)
|
||||
billing_context = BillingContext(amount=int(msg.text))
|
||||
await state.set_data({"ctx": billing_context})
|
||||
Reference in New Issue
Block a user