127 lines
5.5 KiB
Python
127 lines
5.5 KiB
Python
# keyboards.py
|
||
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||
|
||
|
||
def admin_decision_keyboard(user_id: int):
|
||
return InlineKeyboardMarkup(inline_keyboard=[
|
||
[
|
||
InlineKeyboardButton(text="✅ Да", callback_data=f"approve_{user_id}"),
|
||
InlineKeyboardButton(text="❌ Нет", callback_data=f"deny_{user_id}")
|
||
]
|
||
])
|
||
|
||
|
||
def admin_panel_keyboard():
|
||
return InlineKeyboardMarkup(inline_keyboard=[
|
||
[InlineKeyboardButton(text="✏️ Сменить почту для отправки", callback_data="change_email")],
|
||
[InlineKeyboardButton(text="📋 Список пользователей", callback_data="list_users")],
|
||
[InlineKeyboardButton(text="📊 Статус очереди", callback_data="queue_status")],
|
||
[InlineKeyboardButton(text="👑 Передать права админа", callback_data="transfer_admin")]
|
||
])
|
||
|
||
|
||
def users_list_keyboard(users: list, page: int = 0, for_transfer: bool = False):
|
||
"""
|
||
Создаёт клавиатуру со списком пользователей
|
||
Для ожидающих пользователей (is_allowed=0) показывает кнопки "Дать доступ/Отклонить"
|
||
Для подтверждённых (is_allowed=1) показывает кнопку удаления
|
||
"""
|
||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||
|
||
ITEMS_PER_PAGE = 3 # Уменьшил до 3, чтобы влезали кнопки действий
|
||
start_idx = page * ITEMS_PER_PAGE
|
||
end_idx = start_idx + ITEMS_PER_PAGE
|
||
page_users = users[start_idx:end_idx]
|
||
|
||
keyboard = []
|
||
|
||
for user in page_users:
|
||
user_id, username, full_name, is_allowed = user
|
||
status = "✅" if is_allowed else "⏳"
|
||
name = full_name[:20] if full_name else f"ID:{user_id}"
|
||
if username and username != "None":
|
||
name = f"@{username}"[:15]
|
||
|
||
if for_transfer:
|
||
# Для передачи прав - только выбор пользователя
|
||
keyboard.append([
|
||
InlineKeyboardButton(
|
||
text=f"{status} {name}",
|
||
callback_data=f"select_new_admin_{user_id}"
|
||
)
|
||
])
|
||
elif is_allowed == 0:
|
||
# Пользователь ожидает доступа - показываем кнопки "Дать/Отклонить"
|
||
keyboard.append([
|
||
InlineKeyboardButton(
|
||
text=f"⏳ {name} (ожидает)",
|
||
callback_data=f"pending_user_{user_id}"
|
||
)
|
||
])
|
||
keyboard.append([
|
||
InlineKeyboardButton(text="✅ Дать доступ", callback_data=f"quick_approve_{user_id}"),
|
||
InlineKeyboardButton(text="❌ Отклонить", callback_data=f"quick_deny_{user_id}")
|
||
])
|
||
keyboard.append([InlineKeyboardButton(text="─" * 20, callback_data="noop")])
|
||
else:
|
||
# Подтверждённый пользователь - кнопка удаления
|
||
keyboard.append([
|
||
InlineKeyboardButton(
|
||
text=f"✅ {name}",
|
||
callback_data=f"user_{user_id}"
|
||
)
|
||
])
|
||
|
||
# Кнопки навигации
|
||
nav_buttons = []
|
||
if page > 0:
|
||
nav_buttons.append(InlineKeyboardButton(text="◀️ Назад", callback_data=f"users_page_{page - 1}_{for_transfer}"))
|
||
if end_idx < len(users):
|
||
nav_buttons.append(
|
||
InlineKeyboardButton(text="Вперёд ▶️", callback_data=f"users_page_{page + 1}_{for_transfer}"))
|
||
|
||
if nav_buttons:
|
||
keyboard.append(nav_buttons)
|
||
|
||
# Кнопка отмены/закрытия
|
||
if for_transfer:
|
||
keyboard.append([
|
||
InlineKeyboardButton(text="❌ Отмена", callback_data="cancel_transfer")
|
||
])
|
||
else:
|
||
keyboard.append([
|
||
InlineKeyboardButton(text="🔄 Обновить", callback_data="list_users"),
|
||
InlineKeyboardButton(text="❌ Закрыть", callback_data="close_users")
|
||
])
|
||
|
||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||
|
||
|
||
def confirm_delete_keyboard(user_id: int, username: str):
|
||
"""Клавиатура подтверждения удаления"""
|
||
return InlineKeyboardMarkup(inline_keyboard=[
|
||
[
|
||
InlineKeyboardButton(text="✅ Да, удалить", callback_data=f"confirm_delete_{user_id}"),
|
||
InlineKeyboardButton(text="❌ Отмена", callback_data="cancel_delete")
|
||
]
|
||
])
|
||
|
||
|
||
def confirm_transfer_keyboard(user_id: int, username: str, full_name: str):
|
||
"""Клавиатура подтверждения передачи прав админа"""
|
||
return InlineKeyboardMarkup(inline_keyboard=[
|
||
[
|
||
InlineKeyboardButton(text="✅ Да, передать права", callback_data=f"confirm_transfer_{user_id}"),
|
||
InlineKeyboardButton(text="❌ Отмена", callback_data="cancel_transfer")
|
||
]
|
||
])
|
||
|
||
|
||
def quick_decision_keyboard(user_id: int):
|
||
"""Быстрая клавиатура для принятия решения по ожидающему пользователю"""
|
||
return InlineKeyboardMarkup(inline_keyboard=[
|
||
[
|
||
InlineKeyboardButton(text="✅ Дать доступ", callback_data=f"quick_approve_{user_id}"),
|
||
InlineKeyboardButton(text="❌ Отклонить", callback_data=f"quick_deny_{user_id}")
|
||
]
|
||
]) |