diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-06-10 23:02:34 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-06-10 23:02:34 +0300 |
commit | b0bf43e6a272d42a55158e657bd937cb82fc3d8d (patch) | |
tree | f1bc13253bc028abcaed9c88882f5aee384a269c /src/home/telegram/config.py | |
parent | f3b9d50496257d87757802dfb472b5ffae11962c (diff) |
move files, rename home package to homekit
Diffstat (limited to 'src/home/telegram/config.py')
-rw-r--r-- | src/home/telegram/config.py | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/home/telegram/config.py b/src/home/telegram/config.py deleted file mode 100644 index 4c7d74b..0000000 --- a/src/home/telegram/config.py +++ /dev/null @@ -1,75 +0,0 @@ -from ..config import ConfigUnit -from typing import Optional, Union -from abc import ABC -from enum import Enum - - -class TelegramUserListType(Enum): - USERS = 'users' - NOTIFY = 'notify_users' - - -class TelegramUserIdsConfig(ConfigUnit): - NAME = 'telegram_user_ids' - - @classmethod - def schema(cls) -> Optional[dict]: - return { - 'roottype': 'dict', - 'type': 'integer' - } - - -_user_ids_config = TelegramUserIdsConfig() - - -def _user_id_mapper(user: Union[str, int]) -> int: - if isinstance(user, int): - return user - return _user_ids_config[user] - - -class TelegramChatsConfig(ConfigUnit): - NAME = 'telegram_chats' - - @classmethod - def schema(cls) -> Optional[dict]: - return { - 'type': 'dict', - 'schema': { - 'id': {'type': 'string', 'required': True}, - 'token': {'type': 'string', 'required': True}, - } - } - - -class TelegramBotConfig(ConfigUnit, ABC): - @classmethod - def schema(cls) -> Optional[dict]: - return { - 'bot': { - 'type': 'dict', - 'schema': { - 'token': {'type': 'string', 'required': True}, - TelegramUserListType.USERS: {**TelegramBotConfig._userlist_schema(), 'required': True}, - TelegramUserListType.NOTIFY: TelegramBotConfig._userlist_schema(), - } - } - } - - @staticmethod - def _userlist_schema() -> dict: - return {'type': 'list', 'schema': {'type': ['string', 'int']}} - - @staticmethod - def custom_validator(data): - for ult in TelegramUserListType: - users = data['bot'][ult.value] - for user in users: - if isinstance(user, str): - if user not in _user_ids_config: - raise ValueError(f'user {user} not found in {TelegramUserIdsConfig.NAME}') - - def get_user_ids(self, - ult: TelegramUserListType = TelegramUserListType.USERS) -> list[int]: - return list(map(_user_id_mapper, self['bot'][ult.value]))
\ No newline at end of file |