feat: Tái cấu trúc bot sang kiến trúc cog, thêm hỗ trợ đa máy chủ, giới thiệu tính năng đăng ký bóng đá, giao diện web và quản lý cấu hình.

This commit is contained in:
2026-01-16 17:26:42 +07:00
parent 8c38357c28
commit b24365927a
39 changed files with 3864 additions and 997 deletions
+40 -5
View File
@@ -1,11 +1,46 @@
import os
import asyncio
import site
import sys
# Add the project directory to sys.path to ensure module resolution works correctly
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import uvicorn
from dotenv import load_dotenv
from core import events, tasks
from core.bot import bot
from apps import home_debt, score, noi_tu
from bot.core.bot import bot
from web.server import app
from infra.db.postgres import postgres
# Load environment variables
load_dotenv()
# Run the bot
bot.run(os.getenv('BOT_TOKEN'))
async def main():
print("⏳ Waiting for Database connection...")
await postgres.wait_for_connection()
# Ensure schema is migrated (Add missing columns for Multi-Server)
await postgres.verify_and_migrate_schema()
# Ensure tables are created
await postgres.create_tables()
# Configure Web Server
app.state.bot = bot
config = uvicorn.Config(app, host="0.0.0.0", port=8000, log_level="info")
server = uvicorn.Server(config)
# Run Bot and Web Server concurrently
async with bot:
await asyncio.gather(
bot.start(os.getenv('BOT_TOKEN')),
server.serve()
)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
# Handle graceful shutdown
pass