2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Add get_chat method

This commit is contained in:
Dan 2018-05-05 18:42:28 +02:00
parent 68986171ef
commit 553e7f714c
2 changed files with 51 additions and 0 deletions

View File

@ -3794,3 +3794,18 @@ class Client:
url=url
)
)
def get_chat(self, chat_id: int or str):
# TODO: Add docstrings
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel):
r = self.send(functions.channels.GetFullChannel(peer))
elif isinstance(peer, (types.InputPeerUser, types.InputPeerSelf)):
r = self.send(functions.users.GetFullUser(peer))
else:
r = self.send(functions.messages.GetFullChat(peer.chat_id))
return utils.parse_chat_full(self, r)

View File

@ -749,3 +749,39 @@ def parse_callback_query(client, callback_query, users):
game_short_name=callback_query.game_short_name
# TODO: add inline_message_id
)
def parse_chat_full(
client,
chat_full: types.messages.ChatFull or types.UserFull
) -> pyrogram_types.Chat:
if isinstance(chat_full, types.UserFull):
chat = parse_user_chat(chat_full.user)
chat.description = chat_full.about
else:
full_chat = chat_full.full_chat
chat = None
for i in chat_full.chats:
if full_chat.id == i.id:
chat = i
if isinstance(full_chat, types.ChatFull):
chat = parse_chat_chat(chat)
else:
chat = parse_channel_chat(chat)
chat.description = full_chat.about or None
# TODO: Add StickerSet type
chat.can_set_sticker_set = full_chat.can_set_stickers
chat.sticker_set_name = full_chat.stickerset
if full_chat.pinned_msg_id:
chat.pinned_message = client.get_messages(
int("-100" + str(full_chat.id)),
full_chat.pinned_msg_id
)
if isinstance(full_chat.exported_invite, types.ChatInviteExported):
chat.invite_link = full_chat.exported_invite.link
return chat