From 056bd5a8db2a700b885ce93a5c173b1521d9fc43 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 4 Jul 2021 22:57:56 +0300 Subject: [PATCH] Construct BotCommandScope from type --- aiogram/types/bot_command_scope.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aiogram/types/bot_command_scope.py b/aiogram/types/bot_command_scope.py index 3ea75702..2705e0e3 100644 --- a/aiogram/types/bot_command_scope.py +++ b/aiogram/types/bot_command_scope.py @@ -32,6 +32,23 @@ class BotCommandScope(base.TelegramObject): """ type: base.String = fields.Field() + def from_type(self, type: str, **kwargs: typing.Any): + if type == BotCommandScopeType.DEFAULT: + return BotCommandScopeDefault(type=type, **kwargs) + if type == BotCommandScopeType.ALL_PRIVATE_CHATS: + return BotCommandScopeAllPrivateChats(type=type, **kwargs) + if type == BotCommandScopeType.ALL_GROUP_CHATS: + return BotCommandScopeAllGroupChats(type=type, **kwargs) + if type == BotCommandScopeType.ALL_CHAT_ADMINISTRATORS: + return BotCommandScopeAllChatAdministrators(type=type, **kwargs) + if type == BotCommandScopeType.CHAT: + return BotCommandScopeChat(type=type, **kwargs) + if type == BotCommandScopeType.CHAT_ADMINISTRATORS: + return BotCommandScopeChatAdministrators(type=type, **kwargs) + if type == BotCommandScopeType.CHAT_MEMBER: + return BotCommandScopeChatMember(type=type, **kwargs) + raise ValueError(f"Unknown BotCommandScope type {type!r}") + class BotCommandScopeDefault(BotCommandScope): """