1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1605 from Badiboy/master

ChatMember is now typed
This commit is contained in:
Badiboy 2022-07-05 00:01:38 +03:00 committed by GitHub
commit e0e6eee374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -108,7 +108,6 @@ class AsyncTeleBot:
self.current_states = state_storage
self.middlewares = []
async def close_session(self):
@ -117,6 +116,7 @@ class AsyncTeleBot:
Use this function if you stop polling.
"""
await asyncio_helper.session_manager.session.close()
async def get_updates(self, offset: Optional[int]=None, limit: Optional[int]=None,
timeout: Optional[int]=20, allowed_updates: Optional[List]=None, request_timeout: Optional[int]=None) -> List[types.Update]:
"""

View File

@ -1248,9 +1248,10 @@ class CallbackQuery(JsonDeserializable):
obj['from_user'] = User.de_json(obj.pop('from'))
if 'message' in obj:
obj['message'] = Message.de_json(obj.get('message'))
obj['json_string'] = json_string
return cls(**obj)
def __init__(self, id, from_user, data, chat_instance, message=None, inline_message_id=None, game_short_name=None, **kwargs):
def __init__(self, id, from_user, data, chat_instance, json_string, message=None, inline_message_id=None, game_short_name=None, **kwargs):
self.id: int = id
self.from_user: User = from_user
self.message: Message = message
@ -1258,6 +1259,7 @@ class CallbackQuery(JsonDeserializable):
self.chat_instance: str = chat_instance
self.data: str = data
self.game_short_name: str = game_short_name
self.json = json_string
class ChatPhoto(JsonDeserializable):
@ -1280,7 +1282,23 @@ class ChatMember(JsonDeserializable):
if json_string is None: return None
obj = cls.check_json(json_string)
obj['user'] = User.de_json(obj['user'])
return cls(**obj)
member_type = obj['status']
# Ordered according to estimated appearance frequency.
if member_type == "member":
return ChatMemberMember(**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. For "if something happen" compatibility
return cls(**obj)
def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_edited=None,
can_post_messages=None, can_edit_messages=None, can_delete_messages=None,
@ -1318,6 +1336,7 @@ class ChatMember(JsonDeserializable):
class ChatMemberOwner(ChatMember):
pass
class ChatMemberAdministrator(ChatMember):
pass

View File

@ -49,7 +49,7 @@ content_type_service = [
]
update_types = [
"update_id", "message", "edited_message", "channel_post", "edited_channel_post", "inline_query",
"message", "edited_message", "channel_post", "edited_channel_post", "inline_query",
"chosen_inline_result", "callback_query", "shipping_query", "pre_checkout_query", "poll", "poll_answer",
"my_chat_member", "chat_member", "chat_join_request"
]