refactoring: polished some files, .env.example update
This commit is contained in:
@@ -3,15 +3,22 @@ from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from bot.keyboards.admins import action_confirmation
|
||||
from bot.keyboards.common import return_to_menu
|
||||
from bot.states.admins import AdminStorage
|
||||
from bot.texts import (
|
||||
ADM_PROMO_INIT,
|
||||
ADM_VERIFY_PROMOTION,
|
||||
CALLBACK_FALLBACK,
|
||||
GENERAL_PROCESSING,
|
||||
SUCCESSFULLY_SENT_PROMO,
|
||||
)
|
||||
from schemas.di import DependenciesDTO
|
||||
from schemas.promotions import NewPromotionContext
|
||||
from bot.texts import ADM_PROMO_INIT, CALLBACK_FALLBACK, GENERAL_PROCESSING, ADM_VERIFY_PROMOTION, SUCCESSFULLY_SENT_PROMO
|
||||
from bot.keyboards.common import return_to_menu
|
||||
from bot.keyboards.admins import action_confirmation
|
||||
from bot.states.admins import AdminStorage
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.callback_query(F.data == "promotion")
|
||||
async def promo_init(cb: CallbackQuery, state: FSMContext):
|
||||
await state.clear()
|
||||
@@ -22,6 +29,7 @@ async def promo_init(cb: CallbackQuery, state: FSMContext):
|
||||
await state.set_state(AdminStorage.promotion_msg)
|
||||
await state.set_data({"ctx": ctx})
|
||||
|
||||
|
||||
@router.message(AdminStorage.promotion_msg)
|
||||
async def promo_text(msg: Message, state: FSMContext):
|
||||
data = await state.get_data()
|
||||
@@ -31,15 +39,18 @@ async def promo_text(msg: Message, state: FSMContext):
|
||||
ctx: NewPromotionContext | None = data.get("ctx")
|
||||
if ctx:
|
||||
await ctx.msg.delete()
|
||||
|
||||
|
||||
ctx.promotion = msg
|
||||
await edited_msg.edit_text(ADM_VERIFY_PROMOTION, reply_markup=action_confirmation)
|
||||
|
||||
await state.set_state(AdminStorage.promotion_msg)
|
||||
await state.set_data({"ctx": ctx})
|
||||
|
||||
|
||||
@router.callback_query(AdminStorage.promotion_msg, F.data.in_(("approve", "decline")))
|
||||
async def promo_send(cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO):
|
||||
async def promo_send(
|
||||
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
||||
):
|
||||
data = await state.get_data()
|
||||
await state.clear()
|
||||
|
||||
@@ -47,6 +58,8 @@ async def promo_send(cb: CallbackQuery, state: FSMContext, session: AsyncSession
|
||||
if not (ctx and ctx.promotion and ctx.msg):
|
||||
await cb.message.edit_text(CALLBACK_FALLBACK, reply_markup=return_to_menu)
|
||||
return
|
||||
|
||||
|
||||
successful = await deps.user_service.launch_promotion(session, ctx.promotion)
|
||||
await cb.message.edit_text(SUCCESSFULLY_SENT_PROMO.format(successful=successful), reply_markup=return_to_menu)
|
||||
await cb.message.edit_text(
|
||||
SUCCESSFULLY_SENT_PROMO.format(successful=successful), reply_markup=return_to_menu
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from bot.keyboards.client import deposit_kb, devices_selector, duration_selector
|
||||
from bot.keyboards.common import return_to_menu
|
||||
|
||||
from bot.states.buy import SubscriptionStorage
|
||||
from bot.texts import (
|
||||
CALLBACK_FALLBACK,
|
||||
|
||||
@@ -11,6 +11,7 @@ from bot.texts import (
|
||||
FAQ_TEXT,
|
||||
GENERAL_PROCESSING,
|
||||
GENERAL_SUCCESS,
|
||||
NO_SUBSCRIPTION,
|
||||
NOTHING_PLACEHOLDER,
|
||||
)
|
||||
from db.models.users import User
|
||||
@@ -122,11 +123,15 @@ async def sub_info(
|
||||
)
|
||||
sub = await deps.subscriptions_repository.get_subscription_by_user_id(session, cb.from_user.id)
|
||||
|
||||
if not user:
|
||||
await cb.answer(CALLBACK_FALLBACK)
|
||||
if not rw_user:
|
||||
await cb.message.edit_text(NO_SUBSCRIPTION, reply_markup=return_to_menu)
|
||||
return
|
||||
|
||||
if not sub:
|
||||
if not user:
|
||||
await cb.answer("1" + CALLBACK_FALLBACK)
|
||||
return
|
||||
|
||||
if rw_user and not sub:
|
||||
try:
|
||||
dto = SubscriptionPlan(
|
||||
devices=rw_user.hwid_device_limit,
|
||||
@@ -143,7 +148,7 @@ async def sub_info(
|
||||
plan_price_paid=utils.calculate_price(dto),
|
||||
)
|
||||
except Exception:
|
||||
await cb.answer(CALLBACK_FALLBACK)
|
||||
await cb.answer("2" + CALLBACK_FALLBACK)
|
||||
return
|
||||
|
||||
await cb.message.edit_text(
|
||||
|
||||
@@ -4,7 +4,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
main_menu: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||||
[
|
||||
[InlineKeyboardButton(text="📢 Рассылка", callback_data="promotion")],
|
||||
[InlineKeyboardButton(text="👤 Управление пользователем", callback_data="usermgmt")],
|
||||
# [InlineKeyboardButton(text="👤 Управление пользователем", callback_data="usermgmt")],
|
||||
]
|
||||
).as_markup()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from config import settings
|
||||
from misc.utils import convert_duration_to_int
|
||||
from schemas.subscriptions import SubscriptionDuration
|
||||
|
||||
from .common import _return_to_menu_btn
|
||||
|
||||
main_menu = InlineKeyboardBuilder(
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from config import settings
|
||||
from misc.utils import convert_duration_to_int
|
||||
from schemas.subscriptions import SubscriptionDuration
|
||||
|
||||
_return_to_menu_btn: InlineKeyboardButton = InlineKeyboardButton(
|
||||
text="⬅️ Назад", callback_data="menu:main"
|
||||
)
|
||||
|
||||
return_to_menu: InlineKeyboardMarkup = InlineKeyboardBuilder([[_return_to_menu_btn]]).as_markup()
|
||||
return_to_menu: InlineKeyboardMarkup = InlineKeyboardBuilder([[_return_to_menu_btn]]).as_markup()
|
||||
|
||||
@@ -215,5 +215,7 @@ ADM_MAIN_MENU = (
|
||||
)
|
||||
|
||||
ADM_PROMO_INIT = "<b>📢 Введите/перешлите текст рассылки:</b>"
|
||||
ADM_VERIFY_PROMOTION = "<b>❓ Отправить рассылку? <i>Это действие будет невозможно отменить.</i></b>"
|
||||
SUCCESSFULLY_SENT_PROMO = "<b>💚 Успешно отправлена рассылка.</b>\n<i>⚡ Успешных отправок: <code>{successful}</code>.</i>"
|
||||
ADM_VERIFY_PROMOTION = (
|
||||
"<b>❓ Отправить рассылку? <i>Это действие будет невозможно отменить.</i></b>"
|
||||
)
|
||||
SUCCESSFULLY_SENT_PROMO = "<b>💚 Успешно отправлена рассылка.</b>\n<i>⚡ Успешных отправок: <code>{successful}</code>.</i>"
|
||||
|
||||
Reference in New Issue
Block a user