2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Modify resolve_peer to accommodate Peer* types

This commit is contained in:
Dan 2018-02-13 14:28:45 +01:00
parent aca6fa390e
commit 78f2c9549c

View File

@ -703,18 +703,26 @@ class Client:
return input_peer return input_peer
def resolve_peer(self, peer_id: int or str): def resolve_peer(self, peer_id: int or str or types.PeerUser or types.PeerChat or types.PeerChannel):
if type(peer_id) is str:
if peer_id in ("self", "me"): if peer_id in ("self", "me"):
return InputPeerSelf() return InputPeerSelf()
else:
if type(peer_id) is str:
peer_id = peer_id.lower().strip("@") peer_id = peer_id.lower().strip("@")
try: try:
return self.peers_by_username[peer_id] return self.peers_by_username[peer_id]
except KeyError: except KeyError:
return self.resolve_username(peer_id) return self.resolve_username(peer_id)
else:
if type(peer_id) is not int:
if isinstance(peer_id, types.PeerUser):
peer_id = peer_id.user_id
elif isinstance(peer_id, types.PeerChat):
peer_id = peer_id.chat_id
elif isinstance(peer_id, types.PeerChannel):
peer_id = int("-100" + str(peer_id.channel_id))
try: try:
return self.peers_by_id[peer_id] return self.peers_by_id[peer_id]
except KeyError: except KeyError: