From 78251cdf43941a6dea5ce34d31a12433b63be542 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Mon, 4 Jul 2022 22:41:01 +0300 Subject: [PATCH] ChatMember type checking reordered --- telebot/types.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index 5a8fcf2..5bab9c4 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -1283,20 +1283,21 @@ class ChatMember(JsonDeserializable): obj = cls.check_json(json_string) obj['user'] = User.de_json(obj['user']) member_type = obj['status'] - if member_type == "creator": - return ChatMemberOwner(**obj) - elif member_type == "administrator": - return ChatMemberAdministrator(**obj) - elif member_type == "member": + # Ordered according to estimated appearance frequency. + if member_type == "member": return ChatMemberMember(**obj) - elif member_type == "restricted": - return ChatMemberRestricted(**obj) elif member_type == "left": return ChatMemberLeft(**obj) elif member_type == "kicked": return ChatMemberBanned(**obj) + elif member_type == "restricted": + return ChatMemberRestricted(**obj) + elif member_type == "administrator": + return ChatMemberAdministrator(**obj) + elif member_type == "creator": + return ChatMemberOwner(**obj) else: - # Should not be here + # Should not be here. For "if something happen" compatibility return cls(**obj) def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_edited=None,