Handle *FromMessage peers in utils' casts

This commit is contained in:
Lonami Exo 2019-12-23 13:47:55 +01:00
parent ecb27f33f7
commit 627e176f8e

View File

@ -211,6 +211,12 @@ def get_input_peer(entity, allow_self=True, check_hash=True):
if isinstance(entity, types.InputUserSelf): if isinstance(entity, types.InputUserSelf):
return types.InputPeerSelf() return types.InputPeerSelf()
if isinstance(entity, types.InputUserFromMessage):
return types.InputPeerUserFromMessage(entity.peer, entity.msg_id, entity.user_id)
if isinstance(entity, types.InputChannelFromMessage):
return types.InputPeerChannelFromMessage(entity.peer, entity.msg_id, entity.channel_id)
if isinstance(entity, types.UserEmpty): if isinstance(entity, types.UserEmpty):
return types.InputPeerEmpty() return types.InputPeerEmpty()
@ -248,6 +254,9 @@ def get_input_channel(entity):
if isinstance(entity, types.InputPeerChannel): if isinstance(entity, types.InputPeerChannel):
return types.InputChannel(entity.channel_id, entity.access_hash) return types.InputChannel(entity.channel_id, entity.access_hash)
if isinstance(entity, types.InputPeerChannelFromMessage):
return types.InputChannelFromMessage(entity.peer, entity.msg_id, entity.channel_id)
_raise_cast_fail(entity, 'InputChannel') _raise_cast_fail(entity, 'InputChannel')
@ -285,6 +294,9 @@ def get_input_user(entity):
if isinstance(entity, types.InputPeerUser): if isinstance(entity, types.InputPeerUser):
return types.InputUser(entity.user_id, entity.access_hash) return types.InputUser(entity.user_id, entity.access_hash)
if isinstance(entity, types.InputPeerUserFromMessage):
return types.InputUserFromMessage(entity.peer, entity.msg_id, entity.user_id)
_raise_cast_fail(entity, 'InputUser') _raise_cast_fail(entity, 'InputUser')
@ -854,11 +866,11 @@ def get_peer(peer):
return types.PeerUser(peer.user_id) return types.PeerUser(peer.user_id)
peer = get_input_peer(peer, allow_self=False, check_hash=False) peer = get_input_peer(peer, allow_self=False, check_hash=False)
if isinstance(peer, types.InputPeerUser): if isinstance(peer, (types.InputPeerUser, types.InputPeerUserFromMessage)):
return types.PeerUser(peer.user_id) return types.PeerUser(peer.user_id)
elif isinstance(peer, types.InputPeerChat): elif isinstance(peer, types.InputPeerChat):
return types.PeerChat(peer.chat_id) return types.PeerChat(peer.chat_id)
elif isinstance(peer, types.InputPeerChannel): elif isinstance(peer, (types.InputPeerChannel, types.InputPeerChannelFromMessage)):
return types.PeerChannel(peer.channel_id) return types.PeerChannel(peer.channel_id)
except (AttributeError, TypeError): except (AttributeError, TypeError):
pass pass