mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 03:22:29 +00:00
Implement automatic cast to InputUser too (closes #159)
This commit is contained in:
@@ -8,6 +8,7 @@ from .tl.types import (
|
||||
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
|
||||
ChatPhoto, InputPeerChannel, InputPeerChat, InputPeerUser,
|
||||
MessageMediaDocument, MessageMediaPhoto, PeerChannel, InputChannel,
|
||||
UserEmpty, InputUser, InputUserEmpty, InputUserSelf,
|
||||
PeerChat, PeerUser, User, UserFull, UserProfilePhoto)
|
||||
|
||||
|
||||
@@ -81,8 +82,7 @@ def get_input_peer(entity):
|
||||
|
||||
|
||||
def get_input_channel(entity):
|
||||
"""Gets the input peer for the given "entity" (user, chat or channel).
|
||||
A ValueError is raised if the given entity isn't a supported type."""
|
||||
"""Similar to get_input_peer, but for InputChannel's alone"""
|
||||
if type(entity).subclass_of_id == 0x40f202fd: # crc32(b'InputChannel')
|
||||
return entity
|
||||
|
||||
@@ -93,6 +93,27 @@ def get_input_channel(entity):
|
||||
.format(type(entity).__name__))
|
||||
|
||||
|
||||
def get_input_user(entity):
|
||||
"""Similar to get_input_peer, but for InputUser's alone"""
|
||||
if type(entity).subclass_of_id == 0xe669bf46: # crc32(b'InputUser')
|
||||
return entity
|
||||
|
||||
if isinstance(entity, User):
|
||||
if entity.is_self:
|
||||
return InputUserSelf()
|
||||
else:
|
||||
return InputUser(entity.id, entity.access_hash)
|
||||
|
||||
if isinstance(entity, UserEmpty):
|
||||
return InputUserEmpty()
|
||||
|
||||
if isinstance(entity, UserFull):
|
||||
return get_input_user(entity.user)
|
||||
|
||||
raise ValueError('Cannot cast {} to any kind of InputUser.'
|
||||
.format(type(entity).__name__))
|
||||
|
||||
|
||||
def find_user_or_chat(peer, users, chats):
|
||||
"""Finds the corresponding user or chat given a peer.
|
||||
Returns None if it was not found"""
|
||||
|
Reference in New Issue
Block a user