Files
AnonBot/keyboards/reply.py

119 lines
3.7 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Reply клавиатуры для бота
"""
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
from aiogram.utils.keyboard import ReplyKeyboardBuilder
from services.auth.auth_new import AuthService
from dependencies import get_auth
def get_main_keyboard(user_id: int = None, auth: AuthService = None) -> ReplyKeyboardMarkup:
"""
Основная клавиатура бота
Args:
user_id: ID пользователя для проверки роли
auth: Сервис авторизации для проверки роли
Returns:
Reply клавиатура
"""
builder = ReplyKeyboardBuilder()
builder.add(
KeyboardButton(text="📋 Мои вопросы"),
KeyboardButton(text="🔗 Моя ссылка")
)
builder.add(
KeyboardButton(text="🚫 Заблокированные"),
KeyboardButton(text=" Помощь")
)
# Добавляем кнопку статистики только для администраторов
if user_id and auth and auth.is_admin(user_id):
builder.add(KeyboardButton(text="📊 Статистика"))
builder.adjust(2, 2, 1) # 2 кнопки в первом ряду, 2 во втором, 1 в третьем
else:
builder.adjust(2, 2) # 2 кнопки в первом ряду, 2 во втором
return builder.as_markup(
resize_keyboard=True,
one_time_keyboard=False,
input_field_placeholder="Выберите действие или отправьте вопрос..."
)
def get_main_keyboard_for_user(user_id: int, auth: AuthService = None) -> ReplyKeyboardMarkup:
"""
Основная клавиатура бота для конкретного пользователя
Args:
user_id: ID пользователя для проверки роли
auth: Сервис авторизации для проверки роли (опционально, если не передан, будет получен через DI)
Returns:
Reply клавиатура
"""
if auth is None:
auth = get_auth()
return get_main_keyboard(user_id, auth)
def get_admin_reply_keyboard() -> ReplyKeyboardMarkup:
"""
Reply клавиатура для администраторов
Returns:
Reply клавиатура для админов
"""
builder = ReplyKeyboardBuilder()
builder.add(
KeyboardButton(text="📋 Мои вопросы"),
KeyboardButton(text="🔗 Моя ссылка")
)
builder.add(
KeyboardButton(text="🚫 Заблокированные"),
KeyboardButton(text=" Помощь")
)
builder.add(
KeyboardButton(text="📊 Статистика"),
KeyboardButton(text="⚙️ Админ панель")
)
builder.adjust(2, 2, 2) # 2 кнопки в каждом ряду
return builder.as_markup(
resize_keyboard=True,
one_time_keyboard=False,
input_field_placeholder="Выберите действие или отправьте вопрос..."
)
def get_cancel_keyboard() -> ReplyKeyboardMarkup:
"""
Клавиатура с кнопкой отмены
Returns:
Reply клавиатура
"""
builder = ReplyKeyboardBuilder()
builder.add(
KeyboardButton(text="❌ Отмена")
)
return builder.as_markup(
resize_keyboard=True,
one_time_keyboard=True,
input_field_placeholder="Отправьте текст или нажмите 'Отмена'"
)