mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Remove support for t.me/joinchat/ links in resolve_peer for now
Another way, which is 100% reliable, will be implemented Also clean the method a bit by removing useless checks
This commit is contained in:
parent
32468e5ab0
commit
d270d0d2aa
@ -1011,21 +1011,19 @@ class Client(Methods, BaseClient):
|
|||||||
self.get_initial_dialogs_chunk()
|
self.get_initial_dialogs_chunk()
|
||||||
|
|
||||||
def resolve_peer(self, peer_id: int or str):
|
def resolve_peer(self, peer_id: int or str):
|
||||||
"""Use this method to get the *InputPeer* of a known *peer_id*.
|
"""Use this method to get the InputPeer of a known peer_id.
|
||||||
|
|
||||||
It is intended to be used when working with Raw Functions (i.e: a Telegram API method you wish to use which is
|
This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method
|
||||||
not available yet in the Client class as an easy-to-use method).
|
you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer
|
||||||
|
type is required.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
peer_id (``int`` | ``str`` | ``Peer``):
|
peer_id (``int`` | ``str``):
|
||||||
The Peer ID you want to extract the InputPeer from. Can be one of these types: ``int`` (direct ID),
|
The peer id you want to extract the InputPeer from.
|
||||||
``str`` (@username), :obj:`PeerUser <pyrogram.api.types.PeerUser>`,
|
Can be a direct id (int), a username (str) or a phone number (str).
|
||||||
:obj:`PeerChat <pyrogram.api.types.PeerChat>`, :obj:`PeerChannel <pyrogram.api.types.PeerChannel>`
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`InputPeerUser <pyrogram.api.types.InputPeerUser>` or
|
On success, the resolved peer id is returned in form of an InputPeer object.
|
||||||
:obj:`InputPeerChat <pyrogram.api.types.InputPeerChat>` or
|
|
||||||
:obj:`InputPeerChannel <pyrogram.api.types.InputPeerChannel>` depending on the *peer_id*.
|
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>`
|
:class:`Error <pyrogram.Error>`
|
||||||
@ -1034,38 +1032,21 @@ class Client(Methods, BaseClient):
|
|||||||
if peer_id in ("self", "me"):
|
if peer_id in ("self", "me"):
|
||||||
return types.InputPeerSelf()
|
return types.InputPeerSelf()
|
||||||
|
|
||||||
match = self.INVITE_LINK_RE.match(peer_id)
|
|
||||||
|
|
||||||
try:
|
|
||||||
decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), "-_")
|
|
||||||
return self.resolve_peer(struct.unpack(">2iq", decoded)[1])
|
|
||||||
except (AttributeError, binascii.Error, struct.error):
|
|
||||||
pass
|
|
||||||
|
|
||||||
peer_id = re.sub(r"[@+\s]", "", peer_id.lower())
|
peer_id = re.sub(r"[@+\s]", "", peer_id.lower())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
int(peer_id)
|
int(peer_id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
if peer_id not in self.peers_by_username:
|
||||||
return self.peers_by_username[peer_id]
|
|
||||||
except KeyError:
|
|
||||||
self.send(functions.contacts.ResolveUsername(peer_id))
|
self.send(functions.contacts.ResolveUsername(peer_id))
|
||||||
return self.peers_by_username[peer_id]
|
|
||||||
|
return self.peers_by_username[peer_id]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return self.peers_by_phone[peer_id]
|
return self.peers_by_phone[peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise PeerIdInvalid
|
raise PeerIdInvalid
|
||||||
|
|
||||||
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: # User
|
try: # User
|
||||||
return self.peers_by_id[peer_id]
|
return self.peers_by_id[peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user