fixes, chat handlers
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
51
main.py
51
main.py
@@ -17,6 +17,7 @@ from src.core.config import BOT_TOKEN, ADMIN_IDS
|
||||
from src.core.database import async_session_maker, init_db
|
||||
from src.core.services import UserService, LotteryService, ParticipationService
|
||||
from src.core.models import User
|
||||
from src.core.permissions import is_admin, format_commands_help
|
||||
from src.handlers.admin_panel import admin_router
|
||||
from src.handlers.account_handlers import account_router
|
||||
from src.handlers.registration_handlers import router as registration_router
|
||||
@@ -63,11 +64,6 @@ dp.message.middleware(TaskManagerMiddleware())
|
||||
dp.callback_query.middleware(TaskManagerMiddleware())
|
||||
|
||||
|
||||
def is_admin(user_id: int) -> bool:
|
||||
"""Проверка, является ли пользователь администратором"""
|
||||
return user_id in ADMIN_IDS
|
||||
|
||||
|
||||
def get_main_keyboard(is_admin_user: bool = False) -> InlineKeyboardMarkup:
|
||||
"""Главная клавиатура"""
|
||||
buttons = [
|
||||
@@ -139,6 +135,13 @@ async def cmd_start(message: Message):
|
||||
)
|
||||
|
||||
|
||||
@router.message(Command("help"))
|
||||
async def cmd_help(message: Message):
|
||||
"""Показать список доступных команд с учетом прав пользователя"""
|
||||
help_text = format_commands_help(message.from_user.id)
|
||||
await message.answer(help_text, parse_mode="HTML")
|
||||
|
||||
|
||||
@router.callback_query(F.data == "list_lotteries")
|
||||
async def show_active_lotteries(callback: CallbackQuery):
|
||||
"""Показать активные розыгрыши"""
|
||||
@@ -992,10 +995,42 @@ async def back_to_main(callback: CallbackQuery, state: FSMContext):
|
||||
|
||||
async def set_commands():
|
||||
"""Установка команд бота"""
|
||||
commands = [
|
||||
BotCommand(command="start", description="🚀 Запустить бота"),
|
||||
# Команды для обычных пользователей
|
||||
user_commands = [
|
||||
BotCommand(command="start", description="🚀 Начать работу с ботом"),
|
||||
BotCommand(command="help", description="📋 Показать список команд"),
|
||||
BotCommand(command="my_code", description="🔑 Мой реферальный код"),
|
||||
BotCommand(command="my_accounts", description="💳 Мои счета"),
|
||||
]
|
||||
await bot.set_my_commands(commands)
|
||||
|
||||
# Команды для администраторов (добавляются к пользовательским)
|
||||
admin_commands = user_commands + [
|
||||
BotCommand(command="add_account", description="➕ Добавить счет"),
|
||||
BotCommand(command="remove_account", description="➖ Удалить счет"),
|
||||
BotCommand(command="verify_winner", description="✅ Верифицировать победителя"),
|
||||
BotCommand(command="check_unclaimed", description="🔍 Проверить невостребованные"),
|
||||
BotCommand(command="redraw", description="🎲 Повторный розыгрыш"),
|
||||
BotCommand(command="chat_mode", description="💬 Режим чата"),
|
||||
BotCommand(command="ban", description="🚫 Забанить пользователя"),
|
||||
BotCommand(command="unban", description="✅ Разбанить"),
|
||||
BotCommand(command="banlist", description="📋 Список банов"),
|
||||
BotCommand(command="chat_stats", description="📊 Статистика чата"),
|
||||
]
|
||||
|
||||
# Устанавливаем команды для обычных пользователей
|
||||
await bot.set_my_commands(user_commands)
|
||||
|
||||
# Для админов устанавливаем расширенный набор команд
|
||||
from aiogram.types import BotCommandScopeChat
|
||||
for admin_id in ADMIN_IDS:
|
||||
try:
|
||||
await bot.set_my_commands(
|
||||
admin_commands,
|
||||
scope=BotCommandScopeChat(chat_id=admin_id)
|
||||
)
|
||||
except Exception as e:
|
||||
logging.warning(f"Не удалось установить команды для админа {admin_id}: {e}")
|
||||
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
Reference in New Issue
Block a user