-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
58 lines (46 loc) · 1.71 KB
/
run.py
File metadata and controls
58 lines (46 loc) · 1.71 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
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand
from config import settings
from app.handlers.admin import router as admin_router
from app.handlers.start import router as start_router
from app.handlers.user_profile import router as user_profile_router
from app.handlers.ai_chat import router as ai_chat_router
from app.handlers.ai_models import router as ai_models_router
from app.handlers.help import router as help_router
from app.db.base import engine, Base
async def init_db():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async def set_commands(bot: Bot):
commands = [
BotCommand(command="start", description="Start the bot"),
BotCommand(command="help", description="Show help information"),
BotCommand(command="admin", description="Admin panel"),
BotCommand(command="models", description="Change DeepSeek model"),
BotCommand(command="profile", description="Your profile"),
]
await bot.set_my_commands(commands)
async def main():
# Initialize database
await init_db()
bot = Bot(token=settings.TELEGRAM_BOT_TOKEN)
dp = Dispatcher()
# Add commands menu
await set_commands(bot)
# Register routers from handlers
dp.include_router(start_router)
dp.include_router(admin_router)
dp.include_router(user_profile_router)
dp.include_router(help_router)
dp.include_router(ai_models_router)
dp.include_router(ai_chat_router) # It must be last
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Bot stopped")