from pydantic import SecretStr from pydantic_settings import BaseSettings, SettingsConfigDict class BotSettings(BaseSettings): token: SecretStr class DatabaseSettings(BaseSettings): host: str = "mongodb" port: int = 27017 user: str = "user" password: str = "password" db_name: str = "prod" connection_params: str = "?authSource=admin" @property def connection_url(self) -> str: return f"mongodb://{self.user}:{self.password}@{self.host}:{self.port}/{self.db_name}{self.connection_params}" class LogSettings(BaseSettings): level: str = "INFO" level_external: str = "WARNING" show_time: bool = False console_width: int = 150 class Settings(BaseSettings): bot: BotSettings db: DatabaseSettings log: LogSettings model_config = SettingsConfigDict( case_sensitive=False, env_file=".env", env_nested_delimiter="__", extra="ignore" ) env = Settings() # ty:ignore[missing-argument]