Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
66 lines (53 loc) · 3.47 KB
/
Copy pathbot.py
File metadata and controls
66 lines (53 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram.types import BotCommand
from config import settings
from handlers import router, storage
from middlewares import AccessMiddleware
BOT_COMMANDS = [
BotCommand(command="menu", description="Главное меню настроек и моделей"),
BotCommand(command="start", description="Запустить бота и открыть меню"),
BotCommand(command="help", description="ℹ️ Справка и краткое руководство по боту"),
BotCommand(command="avatar", description="🎭 Режим Аватара: выбор и настройка Личностей"),
BotCommand(command="avatars", description="🎭 Каталог Личностей Аватара (Бро, Бизнес...)"),
BotCommand(command="prompt", description="🥊 Настроить/изменить промпт Stand-режима"),
BotCommand(command="prompts", description="🥊 Каталог промптов и ролей Stand-режима"),
BotCommand(command="voice", description="🎙 Stand-режим: вопрос и ответ голосом"),
BotCommand(command="text", description="💬 Stand-режим: вопрос и ответ текстом"),
BotCommand(command="model", description="🤖 Выбрать основную модель Gemini"),
BotCommand(command="settings", description="⚙️ Параметры чата и голосовые ответы"),
BotCommand(command="tts", description="🎧 Озвучить произвольный текст"),
BotCommand(command="limits", description="📊 Проверить остаток лимитов запросов"),
BotCommand(command="clear", description="🗑 Очистить историю диалога (выбор чатов)"),
BotCommand(command="business", description="💼 Secretary Mode: Telegram Business и авто-ответы"),
BotCommand(command="admin", description="👑 Панель администратора (для админов)"),
]
async def main() -> None:
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
bot: Bot | None = None
try:
# Инициализируем базу данных SQLite
await storage.init_db()
# parse_mode на уровне бота не ставим: rich/plain режим выбирается
# per-message в handlers.py в зависимости от настройки пользователя
bot = Bot(token=settings.telegram_token, default=DefaultBotProperties(parse_mode=None))
dispatcher = Dispatcher()
dispatcher.update.outer_middleware(AccessMiddleware(storage=storage))
dispatcher.include_router(router)
await bot.set_my_commands(BOT_COMMANDS)
logging.info("Меню команд успешно зарегистрировано в Telegram")
await bot.delete_webhook(drop_pending_updates=True)
logging.info("Бот запущен, доступные модели: %s", settings.available_models)
await dispatcher.start_polling(bot, allowed_updates=dispatcher.resolve_used_update_types())
finally:
if bot is not None:
await bot.session.close()
await storage.close()
if __name__ == "__main__":
asyncio.run(main())