Bot Version 1.0.0
This commit is contained in:
53
app/config.py
Normal file
53
app/config.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# app.config
|
||||
|
||||
from pydantic import BaseModel, HttpUrl, field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class SiteConfig(BaseModel):
|
||||
"""Schema for a single monitored site."""
|
||||
name: str
|
||||
url: HttpUrl
|
||||
timeout_seconds: int = 10
|
||||
expected_status: int = 200
|
||||
expected_keywords: list[str] = []
|
||||
max_retries: int = 1
|
||||
|
||||
@field_validator("timeout_seconds")
|
||||
@classmethod
|
||||
def timeout_must_be_positive(cls, v: int) -> int:
|
||||
if v <= 0:
|
||||
raise ValueError("timeout_seconds must be a positive integer")
|
||||
return v
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Return a plain dict compatible with check_site() in utils.py."""
|
||||
return {
|
||||
"name": self.name,
|
||||
"url": str(self.url),
|
||||
"timeout_seconds": self.timeout_seconds,
|
||||
"expected_status": self.expected_status,
|
||||
"expected_keywords": self.expected_keywords,
|
||||
"max_retries": self.max_retries,
|
||||
}
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
)
|
||||
|
||||
# Discord
|
||||
discord_secret_key: str = ""
|
||||
discord_client_id: str = ""
|
||||
discord_client_secret: str = ""
|
||||
|
||||
# Database
|
||||
database_path: str = "uptime.db"
|
||||
|
||||
# Sites — stored as a JSON array string in .env:
|
||||
monitored_sites: list[SiteConfig] = []
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user