mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Support more chats in resolve_to_packed
This commit is contained in:
parent
c91ce98a25
commit
816f6012a9
|
@ -66,12 +66,24 @@ async def resolve_username(self: Client, username: str) -> Chat:
|
||||||
|
|
||||||
|
|
||||||
async def resolve_to_packed(self: Client, chat: ChatLike) -> PackedChat:
|
async def resolve_to_packed(self: Client, chat: ChatLike) -> PackedChat:
|
||||||
|
if isinstance(chat, PackedChat):
|
||||||
|
return chat
|
||||||
|
|
||||||
if isinstance(chat, (User, Group, Channel)):
|
if isinstance(chat, (User, Group, Channel)):
|
||||||
packed = chat.pack()
|
packed = chat.pack() or self._chat_hashes.get(chat.id)
|
||||||
if packed is None:
|
if packed is not None:
|
||||||
raise ValueError("Cannot resolve chat")
|
|
||||||
return packed
|
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, abcs.InputPeer):
|
||||||
if isinstance(chat, types.InputPeerEmpty):
|
if isinstance(chat, types.InputPeerEmpty):
|
||||||
raise ValueError("Cannot resolve chat")
|
raise ValueError("Cannot resolve chat")
|
||||||
|
@ -126,6 +138,12 @@ async def resolve_to_packed(self: Client, chat: ChatLike) -> PackedChat:
|
||||||
if resolved and (packed := resolved.pack()) is not None:
|
if resolved and (packed := resolved.pack()) is not None:
|
||||||
return packed
|
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")
|
raise ValueError("Cannot resolve chat")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user