Files
shveitechbot/misc/kb/admins.py
2026-08-13 11:30:04 +07:00

82 lines
2.9 KiB
Python

from collections.abc import Callable
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.utils.keyboard import InlineKeyboardBuilder
from db.models import Product
main_menu: InlineKeyboardMarkup = InlineKeyboardBuilder(
[
[InlineKeyboardButton(text="📦 Изменить каталог", callback_data="cat:root")],
# [InlineKeyboardButton(text="", callback_data="")],
]
).as_markup()
def back_to_product_kb(product_id: int | str, *, cb_factory: Callable[[int | str], str]):
return InlineKeyboardBuilder(
[[InlineKeyboardButton(text="⬅️", callback_data=cb_factory(product_id))]]
).as_markup()
def customer_contacts(
user_id: int, has_mention: bool, mention: str | None = None
) -> InlineKeyboardMarkup:
btns: list[list[InlineKeyboardButton]] = []
(
btns.append([InlineKeyboardButton(text="👤 Перейти", url=f"https://t.me/{mention}")])
if has_mention
else None
)
btns.append(
[
InlineKeyboardButton(text="✍️", url=f"tg://openmessage?user_id={user_id}"),
InlineKeyboardButton(text="✍️", url=f"tg://user?id={user_id}"),
]
)
return InlineKeyboardBuilder(btns).as_markup()
def payment_link(url: str) -> InlineKeyboardMarkup:
return InlineKeyboardBuilder([[InlineKeyboardButton(text="💸 Оплатить", url=url)]]).as_markup()
def verify_payment(invoice_id: int):
return InlineKeyboardBuilder(
[
[
InlineKeyboardButton(
text="🟢 Подтвердить", callback_data=f"verify_payment:{invoice_id}"
)
]
]
).as_markup()
def edit_product(product: Product):
product_id = product.id
prefix = f"edit_product:{product_id}"
visibility_btn = "🙈 Скрыт" if product.is_hidden else "👁️ Видим"
photo_btn = "🗑️ Удалить фото" if product.file_id or product.img_path else "📷 Добавить фото"
photo_action = "delete_photo" if product.file_id or product.img_path else "photo"
return InlineKeyboardBuilder(
[
[
InlineKeyboardButton(text="✍️ Название", callback_data=f"{prefix}:name"),
InlineKeyboardButton(
text="✍️ Описание",
callback_data=f"{prefix}:description",
),
],
[InlineKeyboardButton(text="💸 Цена", callback_data=f"{prefix}:price")],
[InlineKeyboardButton(text=photo_btn, callback_data=f"{prefix}:{photo_action}")],
[
InlineKeyboardButton(text=visibility_btn, callback_data=f"{prefix}:hide"),
InlineKeyboardButton(text="❌", callback_data=f"{prefix}:delete"),
],
[InlineKeyboardButton(text="⬅️", callback_data=f"cat:{product.category_id}")],
]
).as_markup()