mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 18:35:29 +03:00
update
This commit is contained in:
@@ -17,11 +17,11 @@ class DatabaseConfig:
|
||||
user: str
|
||||
password: str
|
||||
database: str
|
||||
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return f"postgresql+asyncpg://{self.user}:{self.password}@{self.host}:{self.port}/{self.database}"
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
@@ -31,30 +31,30 @@ class Config:
|
||||
|
||||
def load_config() -> Config:
|
||||
config_path = Path("config.toml")
|
||||
|
||||
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"Config file not found: {config_path}")
|
||||
|
||||
|
||||
with open(config_path, "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
|
||||
|
||||
if "bot" not in data:
|
||||
raise KeyError("Missing required section: bot")
|
||||
if "database" not in data:
|
||||
raise KeyError("Missing required section: database")
|
||||
|
||||
|
||||
bot_data = data["bot"]
|
||||
if "token" not in bot_data:
|
||||
raise KeyError("Missing required field: bot.token")
|
||||
if "creator_id" not in bot_data:
|
||||
raise KeyError("Missing required field: bot.creator_id")
|
||||
|
||||
|
||||
database_data = data["database"]
|
||||
required_db_fields = ["host", "port", "user", "password", "database"]
|
||||
for field in required_db_fields:
|
||||
if field not in database_data:
|
||||
raise KeyError(f"Missing required field: database.{field}")
|
||||
|
||||
|
||||
return Config(
|
||||
bot=BotConfig(
|
||||
token=bot_data["token"],
|
||||
|
||||
Reference in New Issue
Block a user