mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Fix .get_input_entity returning marked IDs (closes #314)
This commit is contained in:
parent
db623e37fd
commit
da51e71def
|
@ -177,8 +177,10 @@ class EntityDatabase:
|
||||||
|
|
||||||
def get_input_entity(self, peer):
|
def get_input_entity(self, peer):
|
||||||
try:
|
try:
|
||||||
i, k = utils.get_peer_id(peer, add_mark=True, get_kind=True)
|
i = utils.get_peer_id(peer, add_mark=True)
|
||||||
h = self._input_entities[i]
|
h = self._input_entities[i] # we store the IDs marked
|
||||||
|
i, k = utils.resolve_id(i) # removes the mark and returns kind
|
||||||
|
|
||||||
if k == PeerUser:
|
if k == PeerUser:
|
||||||
return InputPeerUser(i, h)
|
return InputPeerUser(i, h)
|
||||||
elif k == PeerChat:
|
elif k == PeerChat:
|
||||||
|
|
|
@ -303,16 +303,14 @@ def get_input_media(media, user_caption=None, is_photo=False):
|
||||||
_raise_cast_fail(media, 'InputMedia')
|
_raise_cast_fail(media, 'InputMedia')
|
||||||
|
|
||||||
|
|
||||||
def get_peer_id(peer, add_mark=False, get_kind=False):
|
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 'get_kind', the kind will be returned as a second value.
|
|
||||||
"""
|
"""
|
||||||
# First we assert it's a Peer TLObject, or early return for integers
|
# First we assert it's a Peer TLObject, or early return for integers
|
||||||
if not isinstance(peer, TLObject):
|
if not isinstance(peer, TLObject):
|
||||||
if isinstance(peer, int):
|
if isinstance(peer, int):
|
||||||
return (peer, PeerUser) if get_kind else peer
|
return peer
|
||||||
else:
|
else:
|
||||||
_raise_cast_fail(peer, 'int')
|
_raise_cast_fail(peer, 'int')
|
||||||
|
|
||||||
|
@ -321,25 +319,20 @@ def get_peer_id(peer, add_mark=False, get_kind=False):
|
||||||
peer = get_input_peer(peer, allow_self=False)
|
peer = get_input_peer(peer, allow_self=False)
|
||||||
|
|
||||||
# Set the right ID/kind, or raise if the TLObject is not recognised
|
# Set the right ID/kind, or raise if the TLObject is not recognised
|
||||||
i, k = None, None
|
|
||||||
if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser):
|
if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser):
|
||||||
i, k = peer.user_id, PeerUser
|
return peer.user_id
|
||||||
elif isinstance(peer, PeerChat) or isinstance(peer, InputPeerChat):
|
elif isinstance(peer, PeerChat) or isinstance(peer, InputPeerChat):
|
||||||
i, k = peer.chat_id, PeerChat
|
return -peer.chat_id if add_mark else peer.chat_id
|
||||||
elif isinstance(peer, PeerChannel) or isinstance(peer, InputPeerChannel):
|
elif isinstance(peer, PeerChannel) or isinstance(peer, InputPeerChannel):
|
||||||
i, k = peer.channel_id, PeerChannel
|
i = peer.channel_id
|
||||||
else:
|
if add_mark:
|
||||||
_raise_cast_fail(peer, 'int')
|
|
||||||
|
|
||||||
if add_mark:
|
|
||||||
if k == PeerChat:
|
|
||||||
i = -i
|
|
||||||
elif k == PeerChannel:
|
|
||||||
# Concat -100 through math tricks, .to_supergroup() on Madeline
|
# Concat -100 through math tricks, .to_supergroup() on Madeline
|
||||||
# IDs will be strictly positive -> log works
|
# IDs will be strictly positive -> log works
|
||||||
i = -(i + pow(10, math.floor(math.log10(i) + 3)))
|
return -(i + pow(10, math.floor(math.log10(i) + 3)))
|
||||||
|
else:
|
||||||
|
return i
|
||||||
|
|
||||||
return (i, k) if get_kind else i # return kind only if get_kind
|
_raise_cast_fail(peer, 'int')
|
||||||
|
|
||||||
|
|
||||||
def resolve_id(marked_id):
|
def resolve_id(marked_id):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user