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
+49
View File
@@ -0,0 +1,49 @@
from typing import List, Optional
from sqlalchemy import select
from models.guild import Guild
from infra.db import postgres
class GuildRepository:
def __init__(self):
self.Session = postgres.get_sessionmaker()
async def get(self, guild_id: int) -> Optional[Guild]:
try:
async with self.Session() as session:
stmt = select(Guild).where(Guild.id == guild_id)
result = await session.execute(stmt)
return result.scalar_one_or_none()
except Exception as e:
print(f"Error getting guild {guild_id}: {e}")
return None
async def create_or_update(self, guild_id: int, name: str) -> Optional[Guild]:
try:
async with self.Session() as session:
stmt = select(Guild).where(Guild.id == guild_id)
result = await session.execute(stmt)
guild = result.scalar_one_or_none()
if guild:
guild.name = name
guild.is_active = True
else:
guild = Guild(id=guild_id, name=name, is_active=True)
session.add(guild)
await session.commit()
await session.refresh(guild)
return guild
except Exception as e:
print(f"Error upserting guild {guild_id}: {e}")
return None
async def get_all(self) -> List[Guild]:
try:
async with self.Session() as session:
stmt = select(Guild).where(Guild.is_active == True)
result = await session.execute(stmt)
return list(result.scalars().all())
except Exception as e:
print(f"Error getting all guilds: {e}")
return []