/
ndvkerch
/
deputatbot
Обзор
Документация
Войти
/
ndvkerch
/
deputatbot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/setup_bot.py
97 строк
4 KB
WindSpot Team
UX refactor: profile handler, scoped commands, media flow fix, admin unlimited subscription
19 фев 2026, 15:23
19 фев 2026, 15:23
28681dd
Код
Авторство
О чём код?
"""One-time Telegram Bot API setup: commands, descriptions, avatar instruction.""" from __future__ import annotations import asyncio import sys from pathlib import Path # Allow running from project root sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from aiogram import Bot from aiogram.client.default import DefaultBotProperties from aiogram.types import BotCommand, BotCommandScopeDefault, BotCommandScopeChat from app.config import get_settings PUBLIC_COMMANDS = [ BotCommand(command="start", description="Начало работы"), BotCommand(command="register", description="Регистрация / обновление профиля"), BotCommand(command="vk", description="Подключить / отключить ВКонтакте"), BotCommand(command="help", description="Список команд"), ] ADMIN_EXTRA_COMMANDS = [ BotCommand(command="admin", description="Панель управления"), BotCommand(command="admin_stats", description="Статистика бота"), BotCommand(command="users", description="Список пользователей"), BotCommand(command="sources", description="Источники знаний"), BotCommand(command="sync_sources", description="Синхронизация источников"), ] DESCRIPTION = ( "DeputatBot — AI-помощник для депутатов.\n" "\n" "Создаёт уникальные посты для ВКонтакте с использованием " "искусственного интеллекта и актуальных региональных данных.\n" "\n" "Возможности:\n" "— Генерация постов по описанию и медиа\n" "— Редактирование голосом и текстом\n" "— Публикация и планирование в VK\n" "— Статистика вовлечённости\n" "— База знаний по вашему городу" ) SHORT_DESCRIPTION = ( "AI-помощник депутата: генерация и публикация постов в VK " "с учётом региональной повестки" ) async def main() -> None: settings = get_settings() bot = Bot(token=settings.bot_token, default=DefaultBotProperties()) print("Настройка бота через Telegram Bot API...\n") # 1. Public commands (default scope) await bot.set_my_commands(PUBLIC_COMMANDS, scope=BotCommandScopeDefault()) print(f"[OK] setMyCommands (default) — {len(PUBLIC_COMMANDS)} команд") # 2. Admin commands (per-chat scope) admin_commands = PUBLIC_COMMANDS + ADMIN_EXTRA_COMMANDS for admin_id in settings.admin_id_list: await bot.set_my_commands( admin_commands, scope=BotCommandScopeChat(chat_id=admin_id), ) print(f"[OK] setMyCommands (admin {admin_id}) — {len(admin_commands)} команд") if not settings.admin_id_list: print("[SKIP] Нет ADMIN_IDS — админ-команды не установлены") # 3. setMyDescription await bot.set_my_description(description=DESCRIPTION) print("[OK] setMyDescription — описание профиля установлено") # 4. setMyShortDescription await bot.set_my_short_description(short_description=SHORT_DESCRIPTION) print("[OK] setMyShortDescription — краткое описание установлено") # 5. Avatar — no API method avatar_path = Path(__file__).resolve().parent.parent / "data" / "bot_avatar.png" print() if avatar_path.exists(): print(f"Аватарка готова: {avatar_path}") print("Загрузите через @BotFather → /setuserpic") else: print(f"Аватарка не найдена: {avatar_path}") print("Сгенерируйте аватарку и загрузите через @BotFather → /setuserpic") await bot.session.close() print("\nГотово!") if __name__ == "__main__": asyncio.run(main())