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

ChatMember is now typed

https://core.telegram.org/bots/api#chatmember
This commit is contained in:
Badiboy 2022-07-03 23:33:55 +03:00
parent b9b4885568
commit f3b1f97362
2 changed files with 18 additions and 2 deletions

View File

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

View File

@ -1280,6 +1280,21 @@ class ChatMember(JsonDeserializable):
if json_string is None: return None if json_string is None: return None
obj = cls.check_json(json_string) obj = cls.check_json(json_string)
obj['user'] = User.de_json(obj['user']) 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":
return ChatMemberMember(**obj)
elif member_type == "restricted":
return ChatMemberRestricted(**obj)
elif member_type == "left":
return ChatMemberLeft(**obj)
elif member_type == "kicked":
return ChatMemberBanned(**obj)
else:
# Should not be here
return cls(**obj) return cls(**obj)
def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_edited=None, def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_edited=None,
@ -1318,6 +1333,7 @@ class ChatMember(JsonDeserializable):
class ChatMemberOwner(ChatMember): class ChatMemberOwner(ChatMember):
pass pass
class ChatMemberAdministrator(ChatMember): class ChatMemberAdministrator(ChatMember):
pass pass