add register

This commit is contained in:
Yuriy Yuriev
2026-05-14 18:23:50 +07:00
parent 7802bd3410
commit 328f510151
9 changed files with 312 additions and 233 deletions
+30 -19
View File
@@ -4,9 +4,9 @@
import asyncio
import logging
from types import SimpleNamespace
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand
from aiogram.client.session.aiohttp import AiohttpSession
from config.settings import settings
from core.logger import setup_logger
from managers.proxy_manager import ProxyManager
@@ -18,17 +18,20 @@ from managers.storage import TaskStorage, ChatStorage
logger = setup_logger(__name__)
async def set_bot_commands(bot: Bot):
async def set_bot_commands(bot: Bot, is_admin: bool = False):
"""Устанавливает команды бота в меню."""
commands = [
BotCommand(command="start", description="🏠 Главное меню"),
BotCommand(command="register", description="🔐 Зарегистрироваться"),
BotCommand(command="login", description="🔑 Войти"),
BotCommand(command="logout", description="🔒 Выйти"),
BotCommand(command="streamers", description="📺 Стримеры"),
BotCommand(command="tasks", description="📊 Задачи"),
BotCommand(command="status", description="📈 Статус"),
]
if is_admin:
commands = [
BotCommand(command="start", description="🏠 Главное меню"),
BotCommand(command="logout", description="🔒 Выйти"),
BotCommand(command="streamers", description="📺 Стримеры"),
BotCommand(command="tasks", description="📊 Задачи"),
BotCommand(command="status", description="📈 Статус"),
]
else:
commands = [
BotCommand(command="start", description="🤖 Старт"),
]
await bot.set_my_commands(commands)
@@ -50,8 +53,16 @@ class BotApplication:
browser_service=self.browser_service,
storage=self.storage,
chat_storage=self.chat_storage,
bot_ref=self,
)
async def _update_bot_commands(self):
is_admin = any(
self.interface.auth_manager.is_admin(uid)
for uid in self.interface.auth_manager._sessions
)
await set_bot_commands(self.bot, is_admin=is_admin)
async def initialize(self):
"""Инициализация бота."""
logger.info("Initializing bot...")
@@ -64,8 +75,8 @@ class BotApplication:
self.dispatcher = Dispatcher()
self.interface.register(self.dispatcher)
await set_bot_commands(self.bot)
await self._update_bot_commands()
# Восстанавливаем задачи
await self._restore_tasks()
@@ -88,13 +99,13 @@ class BotApplication:
await self.interface.task_manager.add_task(task_id, params)
if params.task_type == "twitch_irc" and params.chat_id:
class FakeMsg:
chat = type('obj', (object,), {'id': params.chat_id})
bot = self.bot
msg_mock = SimpleNamespace(
chat=SimpleNamespace(id=params.chat_id),
bot=self.bot,
)
await self.background_tasks.start_task(
task_id=task_id,
coro=self.interface._run_twitch(task_id, params, FakeMsg()),
coro=self.interface._run_twitch(task_id, params, msg_mock),
task_type="twitch_irc",
metadata={'type': 'twitch_irc', 'channel': params.channel, 'chat_id': params.chat_id}
)
@@ -104,7 +115,7 @@ class BotApplication:
async def start(self):
"""Запуск бота."""
await self.initialize() # ← ВОТ ЭТО БЫЛО ПРОПУЩЕНО
await self.initialize()
logger.info("Starting polling...")
await self.dispatcher.start_polling(self.bot)