add_commands: coupon/invite
This commit is contained in:
@@ -138,13 +138,13 @@ async def handle_coupon_delete(callback_query: CallbackQuery, callback_data: Adm
|
||||
try:
|
||||
result = await delete_coupon(coupon_code, session)
|
||||
if result:
|
||||
await callback_query.edit_text(f"Купон {coupon_code} удалён!")
|
||||
await callback_query.message.edit_text(f"Купон {coupon_code} удалён!")
|
||||
else:
|
||||
await callback_query.edit_text(f"❌ Купон с кодом {coupon_code} не найден.", show_alert=True)
|
||||
await callback_query.message.edit_text(f"❌ Купон с кодом {coupon_code} не найден.", show_alert=True)
|
||||
await update_coupons_list(callback_query.message, session)
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка при удалении купона: {e}")
|
||||
await callback_query.edit_text("Произошла ошибка при удалении купона.", show_alert=True)
|
||||
await callback_query.message.edit_text("Произошла ошибка при удалении купона.", show_alert=True)
|
||||
|
||||
|
||||
async def update_coupons_list(message, session: Any, page: int = 1):
|
||||
|
||||
+14
-4
@@ -14,6 +14,8 @@ from database import (
|
||||
update_coupon_usage_count,
|
||||
)
|
||||
|
||||
from .utils import edit_or_send_message
|
||||
|
||||
|
||||
class CouponActivationState(StatesGroup):
|
||||
waiting_for_coupon_code = State()
|
||||
@@ -23,14 +25,22 @@ router = Router()
|
||||
|
||||
|
||||
@router.callback_query(F.data == "activate_coupon")
|
||||
async def handle_activate_coupon(callback_query: CallbackQuery, state: FSMContext):
|
||||
@router.message(F.text == "/activate_coupon")
|
||||
async def handle_activate_coupon(callback_query_or_message: Message | CallbackQuery, state: FSMContext):
|
||||
builder = InlineKeyboardBuilder()
|
||||
builder.row(InlineKeyboardButton(text="👤 Личный кабинет", callback_data="profile"))
|
||||
|
||||
await callback_query.message.answer(
|
||||
"<b>🎫 Введите код купона:</b>\n\n"
|
||||
"📝 Пожалуйста, введите действующий код купона, который вы хотите активировать. 🔑",
|
||||
if isinstance(callback_query_or_message, CallbackQuery):
|
||||
target_message = callback_query_or_message.message
|
||||
else:
|
||||
target_message = callback_query_or_message
|
||||
|
||||
await edit_or_send_message(
|
||||
target_message=target_message,
|
||||
text="<b>🎫 Введите код купона:</b>\n\n"
|
||||
"📝 Пожалуйста, введите действующий код купона, который вы хотите активировать. 🔑",
|
||||
reply_markup=builder.as_markup(),
|
||||
media_path=None
|
||||
)
|
||||
await state.set_state(CouponActivationState.waiting_for_coupon_code)
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ from database import (
|
||||
add_connection,
|
||||
check_connection_exists,
|
||||
create_temporary_data,
|
||||
delete_key,
|
||||
get_balance,
|
||||
get_key_details,
|
||||
get_trial,
|
||||
|
||||
+2701
-1746
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+1683
-2255
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+1218
-1159
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+11
-3
@@ -193,8 +193,16 @@ async def view_tariffs_handler(callback_query: CallbackQuery):
|
||||
|
||||
|
||||
@router.callback_query(F.data == "invite")
|
||||
async def invite_handler(callback_query: CallbackQuery):
|
||||
chat_id = callback_query.message.chat.id
|
||||
@router.message(F.text == "/invite")
|
||||
async def invite_handler(callback_query_or_message: Message | CallbackQuery):
|
||||
chat_id = None
|
||||
if isinstance(callback_query_or_message, CallbackQuery):
|
||||
chat_id = callback_query_or_message.message.chat.id
|
||||
target_message = callback_query_or_message.message
|
||||
else:
|
||||
chat_id = callback_query_or_message.chat.id
|
||||
target_message = callback_query_or_message
|
||||
|
||||
referral_link = get_referral_link(chat_id)
|
||||
referral_stats = await get_referral_stats(chat_id)
|
||||
invite_message = invite_message_send(referral_link, referral_stats)
|
||||
@@ -210,7 +218,7 @@ async def invite_handler(callback_query: CallbackQuery):
|
||||
builder.adjust(1)
|
||||
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
target_message=target_message,
|
||||
text=invite_message,
|
||||
reply_markup=builder.as_markup(),
|
||||
media_path=image_path,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from aiogram.filters.callback_data import CallbackData
|
||||
from aiogram.types import InlineKeyboardMarkup
|
||||
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from keyboards.admin.panel_kb import AdminPanelCallback, build_admin_back_btn
|
||||
@@ -38,20 +38,22 @@ def build_manage_cluster_kb(cluster_servers, cluster_name) -> InlineKeyboardMark
|
||||
text="➕ Добавить сервер",
|
||||
callback_data=AdminServerEditorCallback(action="servers_add", data=cluster_name).pack(),
|
||||
)
|
||||
builder.button(
|
||||
text="🌐 Доступность серверов",
|
||||
callback_data=AdminServerEditorCallback(action="servers_availability", data=cluster_name).pack(),
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text="🌐 Доступность",
|
||||
callback_data=AdminServerEditorCallback(action="servers_availability", data=cluster_name).pack(),
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
text="🔄 Синхронизация",
|
||||
callback_data=AdminServerEditorCallback(action="clusters_sync", data=cluster_name).pack(),
|
||||
)
|
||||
)
|
||||
builder.button(
|
||||
text="💾 Создать бэкап кластера",
|
||||
callback_data=AdminServerEditorCallback(action="clusters_backup", data=cluster_name).pack(),
|
||||
)
|
||||
builder.button(
|
||||
text="🔄 Синхронизировать",
|
||||
callback_data=AdminServerEditorCallback(action="clusters_sync", data=cluster_name).pack(),
|
||||
)
|
||||
builder.row(build_admin_back_btn("servers"))
|
||||
builder.adjust(1)
|
||||
builder.adjust(1, 1, 1, 1, 1, 2, 1)
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user