mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Support more chats in resolve_to_packed
This commit is contained in:
parent
c91ce98a25
commit
816f6012a9
|
@ -66,11 +66,23 @@ async def resolve_username(self: Client, username: str) -> Chat:
|
|||
|
||||
|
||||
async def resolve_to_packed(self: Client, chat: ChatLike) -> PackedChat:
|
||||
if isinstance(chat, PackedChat):
|
||||
return chat
|
||||
|
||||
if isinstance(chat, (User, Group, Channel)):
|
||||
packed = chat.pack()
|
||||
if packed is None:
|
||||
raise ValueError("Cannot resolve chat")
|
||||
return packed
|
||||
packed = chat.pack() or self._chat_hashes.get(chat.id)
|
||||
if packed is not None:
|
||||
return packed
|
||||
|
||||
# Try anyway (may work for contacts or bot users).
|
||||
if isinstance(chat, User):
|
||||
ty = PackedType.USER
|
||||
elif isinstance(chat, Group):
|
||||
ty = PackedType.MEGAGROUP if chat.is_megagroup else PackedType.CHAT
|
||||
elif isinstance(chat, Channel):
|
||||
ty = PackedType.BROADCAST
|
||||
|
||||
return PackedChat(ty=ty, id=chat.id, access_hash=0)
|
||||
|
||||
if isinstance(chat, abcs.InputPeer):
|
||||
if isinstance(chat, types.InputPeerEmpty):
|
||||
|
@ -126,6 +138,12 @@ async def resolve_to_packed(self: Client, chat: ChatLike) -> PackedChat:
|
|||
if resolved and (packed := resolved.pack()) is not None:
|
||||
return packed
|
||||
|
||||
if isinstance(chat, int):
|
||||
packed = self._chat_hashes.get(chat)
|
||||
if packed is None:
|
||||
raise ValueError("Cannot resolve chat")
|
||||
return packed
|
||||
|
||||
raise ValueError("Cannot resolve chat")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user