mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 13:14:31 +03:00
Fix get_peer_id going into infinite recursion for InputPeerSelf
This commit is contained in:
parent
16f929b8b6
commit
a8edacd34a
|
@ -304,6 +304,16 @@ def get_peer_id(peer, add_mark=False):
|
||||||
"""Finds the ID of the given peer, and optionally converts it to
|
"""Finds the ID of the given peer, and optionally converts it to
|
||||||
the "bot api" format if 'add_mark' is set to True.
|
the "bot api" format if 'add_mark' is set to True.
|
||||||
"""
|
"""
|
||||||
|
if not isinstance(peer, TLObject):
|
||||||
|
if isinstance(peer, int):
|
||||||
|
return peer
|
||||||
|
else:
|
||||||
|
_raise_cast_fail(peer, 'int')
|
||||||
|
|
||||||
|
if type(peer).SUBCLASS_OF_ID not in {0x2d45687, 0xc91c90b6}:
|
||||||
|
# Not a Peer or an InputPeer, so first get its Input version
|
||||||
|
peer = get_input_peer(peer)
|
||||||
|
|
||||||
if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser):
|
if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser):
|
||||||
return peer.user_id
|
return peer.user_id
|
||||||
else:
|
else:
|
||||||
|
@ -321,10 +331,6 @@ def get_peer_id(peer, add_mark=False):
|
||||||
i = peer.channel_id # IDs will be strictly positive -> log works
|
i = peer.channel_id # IDs will be strictly positive -> log works
|
||||||
return -(i + pow(10, math.floor(math.log10(i) + 3)))
|
return -(i + pow(10, math.floor(math.log10(i) + 3)))
|
||||||
|
|
||||||
# Maybe a full entity was given and we just need its ID
|
|
||||||
try:
|
|
||||||
return get_peer_id(get_input_peer(peer), add_mark=add_mark)
|
|
||||||
except ValueError:
|
|
||||||
_raise_cast_fail(peer, 'int')
|
_raise_cast_fail(peer, 'int')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user