yt-dlp-bot/bot/core/config/schema.py

28 lines
744 B
Python
Raw Normal View History

2022-06-11 04:35:48 +08:00
from pydantic import StrictStr, StrictInt, constr, validator
2022-02-04 06:21:27 +08:00
from yt_shared.schemas.base import RealBaseModel
_LOG_LEVELS = {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}
2022-06-11 04:35:48 +08:00
_LANG_CODE_LEN = 2
2022-10-14 03:55:18 +08:00
_LANG_CODE_REGEX = rf'^[a-z]{{{_LANG_CODE_LEN}}}$'
2022-06-11 04:35:48 +08:00
2022-02-04 06:21:27 +08:00
class TelegramSchema(RealBaseModel):
2022-06-11 04:35:48 +08:00
api_id: StrictInt
api_hash: StrictStr
2022-02-04 06:21:27 +08:00
token: StrictStr
allowed_user_ids: list[int]
2022-06-11 04:35:48 +08:00
lang_code: constr(regex=_LANG_CODE_REGEX, to_lower=True)
2022-02-04 06:21:27 +08:00
class ConfigSchema(RealBaseModel):
telegram: TelegramSchema
log_level: StrictStr
@validator('log_level')
def validate_log_level_value(cls, value):
if value not in _LOG_LEVELS:
raise ValueError(f'"log_level" must be one of {_LOG_LEVELS}')
return value