170 lines
5.8 KiB
Python
170 lines
5.8 KiB
Python
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||
from remnawave.models.hwid import HwidDeviceDto
|
||
|
||
from config import settings
|
||
from misc.utils import convert_duration_to_int, format_hwid_device
|
||
from schemas.subscriptions import SubscriptionDuration
|
||
|
||
from .common import _return_to_menu_btn
|
||
|
||
main_menu = InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="📊 Подписка", callback_data="sub_info")],
|
||
[
|
||
InlineKeyboardButton(text="🛒 Купить", callback_data="buy"),
|
||
InlineKeyboardButton(text="💸 Пополнить", callback_data="deposit"),
|
||
],
|
||
[
|
||
InlineKeyboardButton(text="📢 Наш Канал", url="https://t.me/maleniavpn"),
|
||
InlineKeyboardButton(text="🎧 Тех. Поддержка", url="https://t.me/maleniasupportbot"),
|
||
],
|
||
[
|
||
InlineKeyboardButton(text="🔗 Обновить ссылку", callback_data="update_link"),
|
||
InlineKeyboardButton(text="⁉️ FAQ", callback_data="faq"),
|
||
],
|
||
[InlineKeyboardButton(text="👤 Реферальная система", callback_data="referal")],
|
||
]
|
||
).as_markup()
|
||
|
||
payment_gateways: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="💸 Pally (СБП / Карта)", callback_data="billing:pally")],
|
||
[InlineKeyboardButton(text="✍️ Перейти в поддержку", url="https://t.me/maleniasupportbot")],
|
||
[_return_to_menu_btn],
|
||
]
|
||
).as_markup()
|
||
|
||
close_kb: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||
[[InlineKeyboardButton(text="❌", callback_data="delete")]]
|
||
).as_markup()
|
||
|
||
support_url_kb: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="✍️ Перейти в поддержку", url="https://t.me/maleniasupportbot")],
|
||
[_return_to_menu_btn],
|
||
]
|
||
).as_markup()
|
||
|
||
deposit_kb: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||
[[InlineKeyboardButton(text="💸 Пополнить", callback_data="deposit")], [_return_to_menu_btn]]
|
||
).as_markup()
|
||
|
||
|
||
def subscription_controls(
|
||
show_autorenew: bool, current_autorenewal_status: bool | None = None
|
||
) -> InlineKeyboardMarkup:
|
||
builder = InlineKeyboardBuilder()
|
||
|
||
if show_autorenew:
|
||
autorenewal_text = (
|
||
"🟢 Включить автопродление"
|
||
if not current_autorenewal_status
|
||
else "🔴 Отключить автопродление"
|
||
)
|
||
builder.row(InlineKeyboardButton(text=autorenewal_text, callback_data="toggle:autorenewal"))
|
||
|
||
builder.row(InlineKeyboardButton(text="Управление устройствами", callback_data="hwid_control"))
|
||
builder.row(_return_to_menu_btn)
|
||
return builder.as_markup()
|
||
|
||
|
||
def _return_btn(data: str = "menu:main", text: str = "⬅️ Назад") -> InlineKeyboardButton:
|
||
return InlineKeyboardButton(text=text, callback_data=data)
|
||
|
||
|
||
def build_return_menu(data: str = "menu:main", text: str = "⬅️ Назад") -> InlineKeyboardMarkup:
|
||
return InlineKeyboardBuilder([[_return_btn(data, text)]]).as_markup()
|
||
|
||
|
||
def devices_selector(current: int = settings.min_devices, whitelists: bool = False):
|
||
builder = InlineKeyboardBuilder()
|
||
|
||
buttons = [
|
||
InlineKeyboardButton(
|
||
text=f"{'✅ ' if i == current else ''}{i}", callback_data=f"devices:{i}"
|
||
)
|
||
for i in range(settings.min_devices, settings.max_devices + 1)
|
||
]
|
||
builder.add(*buttons).adjust(6)
|
||
|
||
wl_icon = "✅ " if whitelists else ""
|
||
builder.row(
|
||
InlineKeyboardButton(
|
||
text=f"{wl_icon}Обход Белых Списков (+100₽)",
|
||
callback_data="whitelist:toggle",
|
||
)
|
||
)
|
||
builder.row(InlineKeyboardButton(text="🟢", callback_data="confirm"))
|
||
builder.row(_return_to_menu_btn)
|
||
|
||
return builder.as_markup()
|
||
|
||
|
||
def duration_selector(
|
||
current: SubscriptionDuration = SubscriptionDuration.MONTH,
|
||
back_cb: str = "menu:main",
|
||
) -> InlineKeyboardMarkup:
|
||
builder = InlineKeyboardBuilder()
|
||
duration_int = convert_duration_to_int(current)
|
||
|
||
durations = [
|
||
(1, "1 Месяц"),
|
||
(3, "3 Месяца"),
|
||
(6, "6 Месяцев"),
|
||
(12, "1 Год"),
|
||
]
|
||
|
||
for val, label in durations:
|
||
is_selected = val == duration_int
|
||
|
||
builder.button(
|
||
text=f"{'✅ ' if is_selected else ''}{label}",
|
||
callback_data=f"duration:{val}",
|
||
)
|
||
|
||
builder.row(InlineKeyboardButton(text="🛒 Перейти к оплате", callback_data="confirm"))
|
||
builder.row(_return_btn(back_cb))
|
||
|
||
return builder.as_markup()
|
||
|
||
|
||
def referals_kb(share_link: str) -> InlineKeyboardMarkup:
|
||
return InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="🔗 Поделиться ссылкой", url=share_link)],
|
||
[_return_to_menu_btn],
|
||
]
|
||
).as_markup()
|
||
|
||
|
||
def pay_url(url: str) -> InlineKeyboardMarkup:
|
||
return InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="💸 Оплатить", url=url)],
|
||
[InlineKeyboardButton(text="❌", callback_data="menu:main")],
|
||
]
|
||
).as_markup()
|
||
|
||
|
||
def construct_devices_list(devices: list[HwidDeviceDto]) -> InlineKeyboardMarkup:
|
||
builder = InlineKeyboardBuilder()
|
||
|
||
for device in devices:
|
||
builder.row(
|
||
InlineKeyboardButton(
|
||
text=format_hwid_device(device), callback_data=f"hwid:{device.hwid}"
|
||
)
|
||
)
|
||
builder.row(_return_btn(data="sub_info"))
|
||
return builder.as_markup()
|
||
|
||
|
||
def prompt_hwid_deletion_kb(hwid: str) -> InlineKeyboardMarkup:
|
||
return InlineKeyboardBuilder(
|
||
[
|
||
[InlineKeyboardButton(text="🗑️ Удалить", callback_data=f"delete_hwid:{hwid}")],
|
||
[_return_btn("hwid_control", text="❌ Отмена")],
|
||
]
|
||
).as_markup()
|