Add computed properties to settings
This commit is contained in:
@@ -7,3 +7,4 @@ uvloop==0.19.0
|
|||||||
tgcrypto==1.2.5
|
tgcrypto==1.2.5
|
||||||
sentry-sdk==2.15.0
|
sentry-sdk==2.15.0
|
||||||
pydantic-settings==2.5.2
|
pydantic-settings==2.5.2
|
||||||
|
pydantic==2.9.2
|
||||||
@@ -3,9 +3,6 @@ from functools import wraps
|
|||||||
from telegram_downloader_bot.logger import log
|
from telegram_downloader_bot.logger import log
|
||||||
from telegram_downloader_bot.settings import settings
|
from telegram_downloader_bot.settings import settings
|
||||||
|
|
||||||
allowed_ids = settings.allowed_ids.split(",")
|
|
||||||
allowed_ids = [int(x) for x in allowed_ids]
|
|
||||||
|
|
||||||
|
|
||||||
def protected(func):
|
def protected(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
from functools import cached_property
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
from pydantic import computed_field
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
@@ -46,10 +48,22 @@ class Settings(BaseSettings):
|
|||||||
api_id: int
|
api_id: int
|
||||||
api_hash: str
|
api_hash: str
|
||||||
bot_token: str
|
bot_token: str
|
||||||
storage: os.path
|
storage: str
|
||||||
allowed_ids: str
|
allowed_ids: str
|
||||||
log_level: 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:
|
class Config:
|
||||||
env_file = ".env"
|
env_file = ".env"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user