2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +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,25 +703,33 @@ 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 peer_id in ("self", "me"): if type(peer_id) is str:
return InputPeerSelf() if peer_id in ("self", "me"):
else: return InputPeerSelf()
if type(peer_id) is str:
peer_id = peer_id.lower().strip("@")
try: peer_id = peer_id.lower().strip("@")
return self.peers_by_username[peer_id]
except KeyError: try:
return self.resolve_username(peer_id) return self.peers_by_username[peer_id]
else: except KeyError:
try: return self.resolve_username(peer_id)
return self.peers_by_id[peer_id]
except KeyError: if type(peer_id) is not int:
try: if isinstance(peer_id, types.PeerUser):
return self.peers_by_id[int("-100" + str(peer_id))] peer_id = peer_id.user_id
except KeyError: elif isinstance(peer_id, types.PeerChat):
raise PeerIdInvalid peer_id = peer_id.chat_id
elif isinstance(peer_id, types.PeerChannel):
peer_id = int("-100" + str(peer_id.channel_id))
try:
return self.peers_by_id[peer_id]
except KeyError:
try:
return self.peers_by_id[int("-100" + str(peer_id))]
except KeyError:
raise PeerIdInvalid
def get_me(self): def get_me(self):
"""A simple method for testing the user authorization. Requires no parameters. """A simple method for testing the user authorization. Requires no parameters.