mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Allow auto-casting custom.Dialog into input_entity
This commit is contained in:
parent
baa6976a0b
commit
0cd44b245c
|
@ -2463,9 +2463,10 @@ class TelegramClient(TelegramBareClient):
|
|||
original_peer = peer
|
||||
if not isinstance(peer, int):
|
||||
try:
|
||||
if peer.SUBCLASS_OF_ID != 0x2d45687: # crc32(b'Peer')
|
||||
if getattr(peer, 'SUBCLASS_OF_ID', 0) != 0x2d45687:
|
||||
# 0x2d45687 == crc32(b'Peer')
|
||||
return utils.get_input_peer(peer)
|
||||
except (AttributeError, TypeError):
|
||||
except TypeError:
|
||||
peer = None
|
||||
|
||||
if not peer:
|
||||
|
|
|
@ -91,7 +91,11 @@ def get_input_peer(entity, allow_self=True):
|
|||
if entity.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer')
|
||||
return entity
|
||||
except AttributeError:
|
||||
_raise_cast_fail(entity, 'InputPeer')
|
||||
if hasattr(entity, 'input_entity'):
|
||||
# e.g. custom.Dialog (can't cyclic import)
|
||||
return entity.input_entity
|
||||
else:
|
||||
_raise_cast_fail(entity, 'InputPeer')
|
||||
|
||||
if isinstance(entity, User):
|
||||
if entity.is_self and allow_self:
|
||||
|
@ -105,7 +109,6 @@ def get_input_peer(entity, allow_self=True):
|
|||
if isinstance(entity, (Channel, ChannelForbidden)):
|
||||
return InputPeerChannel(entity.id, entity.access_hash or 0)
|
||||
|
||||
# Less common cases
|
||||
if isinstance(entity, InputUser):
|
||||
return InputPeerUser(entity.user_id, entity.access_hash)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user