-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (42 loc) · 1.54 KB
/
main.py
File metadata and controls
50 lines (42 loc) · 1.54 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
import asyncio
import logging
import os
from dotenv import load_dotenv
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand
from middlewares import AdminOnlyMiddleware
from services.cron_manager import scheduler, restore_tasks
from database.base import init_db
from handlers import router
load_dotenv()
TOKEN = os.getenv("BOT_TOKEN")
async def main():
logging.basicConfig(level=logging.INFO)
bot = Bot(token=TOKEN)
dp = Dispatcher()
dp.message.middleware(AdminOnlyMiddleware())
dp.include_router(router)
await init_db()
scheduler.start()
await restore_tasks(bot)
# --- УСТАНОВКА МЕНЮ КОМАНД ---
commands = [
BotCommand(command="list", description="📋 Управление задачами"),
BotCommand(command="add", description="✨ Создать задачу"),
BotCommand(command="timezone", description="🌍 Часовой пояс"),
BotCommand(command="export", description="📤 Бэкап (Экспорт)"),
BotCommand(command="import", description="📥 Загрузка (Импорт)"),
BotCommand(command="help", description="ℹ️ Справка"),
]
await bot.set_my_commands(commands)
# -----------------------------
print("🤖 Бот запущен...")
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
print("Бот остановлен")