This repository was archived by the owner on Dec 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_reader.py
More file actions
40 lines (34 loc) · 1.38 KB
/
Copy pathconfig_reader.py
File metadata and controls
40 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pydantic import SecretStr, computed_field, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing import List, Optional
class Settings(BaseSettings):
# --- Настройки основного бота (обязательные) ---
telegram_bot_token: SecretStr
admin_ids_str: str = Field(alias="ADMIN_IDS", default="")
model_name: str = "gemini-2.5-flash"
# --- Настройки PostgreSQL ---
db_host: str = Field("localhost", alias="DB_HOST")
db_port: int = Field(5432, alias="DB_PORT")
db_user: str = Field("postgres", alias="DB_USER")
db_pass: SecretStr = Field(..., alias="DB_PASS")
db_name: str = Field("mkpluginsec", alias="DB_NAME")
@computed_field
@property
def admin_ids(self) -> List[int]:
if not self.admin_ids_str:
return []
return [int(x.strip()) for x in self.admin_ids_str.split(',') if x.strip()]
@computed_field
@property
def database_dsn(self) -> str:
"""Собирает DSN строку для подключения к PostgreSQL."""
return (
f"postgresql+asyncpg://"
f"{self.db_user}:{self.db_pass.get_secret_value()}@"
f"{self.db_host}:{self.db_port}/{self.db_name}"
)
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8"
)
config = Settings()