Add computed properties to settings

This commit is contained in:
Roman Krček
2024-10-13 21:05:51 +02:00
parent 47472d59b7
commit 47248f10ab
3 changed files with 17 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
import os
from functools import cached_property
from pydantic_settings import BaseSettings
from pydantic import computed_field
class Settings(BaseSettings):
@@ -46,10 +48,22 @@ class Settings(BaseSettings):
api_id: int
api_hash: str
bot_token: str
storage: os.path
storage: str
allowed_ids: str
log_level: str
@computed_field
@property
def tt_hash_file(self) -> str:
return os.path.join(settings.storage, "tt_hashes.pickle")
@computed_field
@cached_property
def allowed_ids_list(self) -> list:
allowed_ids = settings.allowed_ids.split(",")
allowed_ids = [int(x) for x in allowed_ids]
return allowed_ids
class Config:
env_file = ".env"