Update code using get_input_entity

This commit is contained in:
Lonami Exo 2022-03-02 12:54:30 +01:00
parent 5ff8eb8159
commit 6d293b440c
22 changed files with 77 additions and 70 deletions

View File

@ -100,12 +100,12 @@ Note that this function can also work with other types, like :tl:`Chat` or
:tl:`Channel` instances. :tl:`Channel` instances.
If you need to convert other types like usernames which might need to perform If you need to convert other types like usernames which might need to perform
API calls to find out the identifier, you can use ``client.get_peer_id``: API calls to find out the identifier, you can use ``client.get_profile``:
.. code-block:: python .. code-block:: python
print(await client.get_peer_id('me')) # your id print((await client.get_profile('me')).id) # your id
If there is no "mark" (no minus sign), Telethon will assume your identifier If there is no "mark" (no minus sign), Telethon will assume your identifier

View File

@ -129,7 +129,7 @@ as you wish. Remember to use the right types! To sum up:
.. code-block:: python .. code-block:: python
result = await client(SendMessageRequest( result = await client(SendMessageRequest(
await client.get_input_entity('username'), 'Hello there!' await client.get_profile('username'), 'Hello there!'
)) ))

View File

@ -8,7 +8,7 @@ does a result have? Well, the easiest thing to do is printing it:
.. code-block:: python .. code-block:: python
entity = await client.get_entity('username') entity = await client.get_profile('username')
print(entity) print(entity)
That will show a huge **string** similar to the following: That will show a huge **string** similar to the following:

View File

@ -107,7 +107,7 @@ use :tl:`GetMessagesViewsRequest`, setting ``increment=True``:
.. code-block:: python .. code-block:: python
# Obtain `channel' through dialogs or through client.get_entity() or anyhow. # Obtain `channel' through dialogs or through client.get_profile() or anyhow.
# Obtain `msg_ids' through `.get_messages()` or anyhow. Must be a list. # Obtain `msg_ids' through `.get_messages()` or anyhow. Must be a list.
await client(GetMessagesViewsRequest( await client(GetMessagesViewsRequest(

View File

@ -54,6 +54,7 @@ and identifier, rather than just the number.
// TODO we DEFINITELY need to provide a way to "upgrade" old ids // TODO we DEFINITELY need to provide a way to "upgrade" old ids
// TODO and storing type+number by hand is a pain, provide better alternative // TODO and storing type+number by hand is a pain, provide better alternative
// TODO get_peer_id is gone now too!
Synchronous compatibility mode has been removed Synchronous compatibility mode has been removed

View File

@ -118,9 +118,7 @@ Users
get_me get_me
is_bot is_bot
is_user_authorized is_user_authorized
get_entity get_profile
get_input_entity
get_peer_id
Chats Chats
----- -----

View File

@ -16,9 +16,9 @@ async def inline_query(
dialog: 'hints.DialogLike' = None, dialog: 'hints.DialogLike' = None,
offset: str = None, offset: str = None,
geo_point: '_tl.GeoPoint' = None) -> _custom.InlineResults: geo_point: '_tl.GeoPoint' = None) -> _custom.InlineResults:
bot = await self.get_input_entity(bot) bot = await self._get_input_peer(bot)
if dialog: if dialog:
peer = await self.get_input_entity(dialog) peer = await self._get_input_peer(dialog)
else: else:
peer = _tl.InputPeerEmpty() peer = _tl.InputPeerEmpty()

View File

@ -30,7 +30,7 @@ class _ChatAction:
return self._once().__await__() return self._once().__await__()
async def __aenter__(self): async def __aenter__(self):
self._request = dataclasses.replace(self._request, peer=await self._client.get_input_entity(self._request.peer)) self._request = dataclasses.replace(self._request, peer=await self._client._get_input_peer(self._request.peer))
self._running = True self._running = True
self._task = asyncio.create_task(self._update()) self._task = asyncio.create_task(self._update())
return self return self
@ -47,7 +47,7 @@ class _ChatAction:
self._task = None self._task = None
async def _once(self): async def _once(self):
self._request = dataclasses.replace(self._request, peer=await self._client.get_input_entity(self._request.peer)) self._request = dataclasses.replace(self._request, peer=await self._client._get_input_peer(self._request.peer))
await self._client(_tl.fn.messages.SetTyping(self._chat, self._action)) await self._client(_tl.fn.messages.SetTyping(self._chat, self._action))
async def _update(self): async def _update(self):
@ -114,7 +114,7 @@ class _ParticipantsIter(requestiter.RequestIter):
else: else:
raise RuntimeError('unhandled enum variant') raise RuntimeError('unhandled enum variant')
entity = await self.client.get_input_entity(entity) entity = await self.client._get_input_peer(entity)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if search and (filter or ty != helpers._EntityType.CHANNEL): if search and (filter or ty != helpers._EntityType.CHANNEL):
# We need to 'search' ourselves unless we have a PeerChannel # We need to 'search' ourselves unless we have a PeerChannel
@ -172,7 +172,7 @@ class _ParticipantsIter(requestiter.RequestIter):
else: else:
self.total = 1 self.total = 1
if self.limit != 0: if self.limit != 0:
user = await self.client.get_entity(entity) user = await self.client.get_profile(entity)
if self.filter_entity(user): if self.filter_entity(user):
self.buffer.append(user) self.buffer.append(user)
@ -232,7 +232,7 @@ class _AdminLogIter(requestiter.RequestIter):
else: else:
events_filter = None events_filter = None
self.entity = await self.client.get_input_entity(entity) self.entity = await self.client._get_input_peer(entity)
admin_list = [] admin_list = []
if admins: if admins:
@ -240,7 +240,7 @@ class _AdminLogIter(requestiter.RequestIter):
admins = (admins,) admins = (admins,)
for admin in admins: for admin in admins:
admin_list.append(await self.client.get_input_entity(admin)) admin_list.append(await self.client._get_input_peer(admin))
self.request = _tl.fn.channels.GetAdminLog( self.request = _tl.fn.channels.GetAdminLog(
self.entity, q=search or '', min_id=min_id, max_id=max_id, self.entity, q=search or '', min_id=min_id, max_id=max_id,
@ -278,7 +278,7 @@ class _ProfilePhotoIter(requestiter.RequestIter):
async def _init( async def _init(
self, entity, offset, max_id self, entity, offset, max_id
): ):
entity = await self.client.get_input_entity(entity) entity = await self.client._get_input_peer(entity)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if ty == helpers._EntityType.USER: if ty == helpers._EntityType.USER:
self.request = _tl.fn.photos.GetUserPhotos( self.request = _tl.fn.photos.GetUserPhotos(
@ -481,8 +481,8 @@ async def edit_admin(
anonymous: bool = None, anonymous: bool = None,
is_admin: bool = None, is_admin: bool = None,
title: str = None) -> _tl.Updates: title: str = None) -> _tl.Updates:
entity = await self.get_input_entity(chat) entity = await self._get_input_peer(chat)
user = await self.get_input_entity(user) user = await self._get_input_peer(user)
ty = helpers._entity_type(user) ty = helpers._entity_type(user)
perm_names = ( perm_names = (
@ -499,7 +499,7 @@ async def edit_admin(
if post_messages or edit_messages: if post_messages or edit_messages:
# TODO get rid of this once sessions cache this information # TODO get rid of this once sessions cache this information
if entity.channel_id not in self._megagroup_cache: if entity.channel_id not in self._megagroup_cache:
full_entity = await self.get_entity(entity) full_entity = await self.get_profile(entity)
self._megagroup_cache[entity.channel_id] = full_entity.megagroup self._megagroup_cache[entity.channel_id] = full_entity.megagroup
if self._megagroup_cache[entity.channel_id]: if self._megagroup_cache[entity.channel_id]:
@ -545,7 +545,7 @@ async def edit_permissions(
change_info: bool = True, change_info: bool = True,
invite_users: bool = True, invite_users: bool = True,
pin_messages: bool = True) -> _tl.Updates: pin_messages: bool = True) -> _tl.Updates:
entity = await self.get_input_entity(chat) entity = await self._get_input_peer(chat)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
rights = _tl.ChatBannedRights( rights = _tl.ChatBannedRights(
@ -570,7 +570,7 @@ async def edit_permissions(
banned_rights=rights banned_rights=rights
)) ))
user = await self.get_input_entity(user) user = await self._get_input_peer(user)
if isinstance(user, _tl.InputPeerSelf): if isinstance(user, _tl.InputPeerSelf):
raise ValueError('You cannot restrict yourself') raise ValueError('You cannot restrict yourself')
@ -586,8 +586,8 @@ async def kick_participant(
chat: 'hints.DialogLike', chat: 'hints.DialogLike',
user: 'typing.Optional[hints.DialogLike]' user: 'typing.Optional[hints.DialogLike]'
): ):
entity = await self.get_input_entity(chat) entity = await self._get_input_peer(chat)
user = await self.get_input_entity(user) user = await self._get_input_peer(user)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if ty == helpers._EntityType.CHAT: if ty == helpers._EntityType.CHAT:
@ -620,14 +620,14 @@ async def get_permissions(
chat: 'hints.DialogLike', chat: 'hints.DialogLike',
user: 'hints.DialogLike' = None user: 'hints.DialogLike' = None
) -> 'typing.Optional[_custom.ParticipantPermissions]': ) -> 'typing.Optional[_custom.ParticipantPermissions]':
entity = await self.get_entity(chat) entity = await self.get_profile(chat)
if not user: if not user:
if helpers._entity_type(entity) != helpers._EntityType.USER: if helpers._entity_type(entity) != helpers._EntityType.USER:
return entity.default_banned_rights return entity.default_banned_rights
entity = await self.get_input_entity(entity) entity = await self._get_input_peer(entity)
user = await self.get_input_entity(user) user = await self._get_input_peer(user)
if helpers._entity_type(entity) == helpers._EntityType.CHANNEL: if helpers._entity_type(entity) == helpers._EntityType.CHANNEL:
participant = await self(_tl.fn.channels.GetParticipant( participant = await self(_tl.fn.channels.GetParticipant(
@ -653,7 +653,7 @@ async def get_stats(
chat: 'hints.DialogLike', chat: 'hints.DialogLike',
message: 'typing.Union[int, _tl.Message]' = None, message: 'typing.Union[int, _tl.Message]' = None,
): ):
entity = await self.get_input_entity(chat) entity = await self._get_input_peer(chat)
message = utils.get_message_id(message) message = utils.get_message_id(message)
if message is not None: if message is not None:

View File

@ -122,7 +122,7 @@ class _DraftsIter(requestiter.RequestIter):
peers = [] peers = []
for entity in entities: for entity in entities:
peers.append(_tl.InputDialogPeer( peers.append(_tl.InputDialogPeer(
await self.client.get_input_entity(entity))) await self.client._get_input_peer(entity)))
r = await self.client(_tl.fn.messages.GetPeerDialogs(peers)) r = await self.client(_tl.fn.messages.GetPeerDialogs(peers))
items = r.dialogs items = r.dialogs
@ -189,7 +189,7 @@ async def delete_dialog(
else: else:
deactivated = False deactivated = False
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if ty == helpers._EntityType.CHANNEL: if ty == helpers._EntityType.CHANNEL:
return await self(_tl.fn.channels.LeaveChannel(entity)) return await self(_tl.fn.channels.LeaveChannel(entity))

View File

@ -190,7 +190,7 @@ async def download_profile_photo(
INPUTS = (0xc91c90b6, 0xe669bf46, 0x40f202fd) INPUTS = (0xc91c90b6, 0xe669bf46, 0x40f202fd)
entity = profile entity = profile
if not isinstance(entity, tlobject.TLObject) or entity.SUBCLASS_OF_ID in INPUTS: if not isinstance(entity, tlobject.TLObject) or entity.SUBCLASS_OF_ID in INPUTS:
entity = await self.get_entity(entity) entity = await self.get_profile(entity)
possible_names = [] possible_names = []
if entity.SUBCLASS_OF_ID not in ENTITIES: if entity.SUBCLASS_OF_ID not in ENTITIES:
@ -217,7 +217,7 @@ async def download_profile_photo(
dc_id = photo.dc_id dc_id = photo.dc_id
loc = _tl.InputPeerPhotoFileLocation( loc = _tl.InputPeerPhotoFileLocation(
peer=await self.get_input_entity(entity), peer=await self._get_input_peer(entity),
photo_id=photo.photo_id, photo_id=photo.photo_id,
big=thumb >= enums.Size.LARGE big=thumb >= enums.Size.LARGE
) )
@ -244,7 +244,7 @@ async def download_profile_photo(
except errors.LocationInvalidError: except errors.LocationInvalidError:
# See issue #500, Android app fails as of v4.6.0 (1155). # See issue #500, Android app fails as of v4.6.0 (1155).
# The fix seems to be using the full channel chat photo. # The fix seems to be using the full channel chat photo.
ie = await self.get_input_entity(entity) ie = await self._get_input_peer(entity)
ty = helpers._entity_type(ie) ty = helpers._entity_type(ie)
if ty == helpers._EntityType.CHANNEL: if ty == helpers._EntityType.CHANNEL:
full = await self(_tl.fn.channels.GetFullChannel(ie)) full = await self(_tl.fn.channels.GetFullChannel(ie))

View File

@ -19,7 +19,7 @@ async def _replace_with_mention(self: 'TelegramClient', entities, i, user):
try: try:
entities[i] = _tl.InputMessageEntityMentionName( entities[i] = _tl.InputMessageEntityMentionName(
entities[i].offset, entities[i].length, entities[i].offset, entities[i].length,
await self.get_input_entity(user) await self._get_input_peer(user)
) )
return True return True
except (ValueError, TypeError): except (ValueError, TypeError):

View File

@ -28,7 +28,7 @@ class _MessagesIter(requestiter.RequestIter):
): ):
# Note that entity being `None` will perform a global search. # Note that entity being `None` will perform a global search.
if entity: if entity:
self.entity = await self.client.get_input_entity(entity) self.entity = await self.client._get_input_peer(entity)
else: else:
self.entity = None self.entity = None
if self.reverse: if self.reverse:
@ -62,8 +62,8 @@ class _MessagesIter(requestiter.RequestIter):
offset_id = 1 offset_id = 1
if from_user: if from_user:
from_user = await self.client.get_input_entity(from_user) from_user = await self.client._get_input_peer(from_user)
self.from_id = await self.client.get_peer_id(from_user) self.from_id = await self.client._get_peer_id(from_user)
else: else:
self.from_id = None self.from_id = None
@ -272,7 +272,7 @@ class _IDsIter(requestiter.RequestIter):
self.total = len(ids) self.total = len(ids)
self._ids = list(reversed(ids)) if self.reverse else ids self._ids = list(reversed(ids)) if self.reverse else ids
self._offset = 0 self._offset = 0
self._entity = (await self.client.get_input_entity(entity)) if entity else None self._entity = (await self.client._get_input_peer(entity)) if entity else None
self._ty = helpers._entity_type(self._entity) if self._entity else None self._ty = helpers._entity_type(self._entity) if self._entity else None
# 30s flood wait every 300 messages (3 requests of 100 each, 30 of 10, etc.) # 30s flood wait every 300 messages (3 requests of 100 each, 30 of 10, etc.)
@ -327,7 +327,7 @@ async def _get_peer(self: 'TelegramClient', input_peer: 'hints.DialogLike'):
return utils.get_peer(input_peer) return utils.get_peer(input_peer)
except TypeError: except TypeError:
# Can only be self by now # Can only be self by now
return _tl.PeerUser(await self.get_peer_id(input_peer)) return _tl.PeerUser(await self._get_peer_id(input_peer))
def get_messages( def get_messages(
@ -466,7 +466,7 @@ async def send_message(
elif not isinstance(message, InputMessage): elif not isinstance(message, InputMessage):
raise TypeError(f'message must be either str, Message or InputMessage, but got: {message!r}') raise TypeError(f'message must be either str, Message or InputMessage, but got: {message!r}')
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
if comment_to is not None: if comment_to is not None:
entity, reply_to = await _get_comment_data(self, entity, comment_to) entity, reply_to = await _get_comment_data(self, entity, comment_to)
elif reply_to: elif reply_to:
@ -540,11 +540,11 @@ async def forward_messages(
if as_album is not None: if as_album is not None:
warnings.warn('the as_album argument is deprecated and no longer has any effect') warnings.warn('the as_album argument is deprecated and no longer has any effect')
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
if from_dialog: if from_dialog:
from_peer = await self.get_input_entity(from_dialog) from_peer = await self._get_input_peer(from_dialog)
from_peer_id = await self.get_peer_id(from_peer) from_peer_id = await self._get_peer_id(from_peer)
else: else:
from_peer = None from_peer = None
from_peer_id = None from_peer_id = None
@ -632,7 +632,7 @@ async def edit_message(
else: else:
return await self(request) return await self(request)
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
request = _tl.fn.messages.EditMessage( request = _tl.fn.messages.EditMessage(
peer=entity, peer=entity,
id=utils.get_message_id(message), id=utils.get_message_id(message),
@ -659,7 +659,7 @@ async def delete_messages(
) )
if dialog: if dialog:
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
else: else:
# no entity (None), set a value that's not a channel for private delete # no entity (None), set a value that's not a channel for private delete
@ -689,7 +689,7 @@ async def mark_read(
else: else:
max_id = message.id max_id = message.id
entity = await self.get_input_entity(dialog) entity = await self._get_input_peer(dialog)
if clear_mentions: if clear_mentions:
await self(_tl.fn.messages.ReadMentions(entity)) await self(_tl.fn.messages.ReadMentions(entity))
@ -726,7 +726,7 @@ async def unpin_message(
async def _pin(self, entity, message, *, unpin, notify=False, pm_oneside=False): async def _pin(self, entity, message, *, unpin, notify=False, pm_oneside=False):
message = utils.get_message_id(message) or 0 message = utils.get_message_id(message) or 0
entity = await self.get_input_entity(entity) entity = await self._get_input_peer(entity)
if message <= 0: # old behaviour accepted negative IDs to unpin if message <= 0: # old behaviour accepted negative IDs to unpin
await self(_tl.fn.messages.UnpinAllMessages(entity)) await self(_tl.fn.messages.UnpinAllMessages(entity))
return return

View File

@ -3326,7 +3326,7 @@ class TelegramClient:
... ...
# Note that for this to work the phone number must be in your contacts # Note that for this to work the phone number must be in your contacts
some_id = await client.get_peer_id('+34123456789') some_id = (await client.get_profile('+34123456789')).id
""" """
# endregion Users # endregion Users
@ -3395,4 +3395,12 @@ class TelegramClient:
progress_callback: 'hints.ProgressCallback' = None) -> '_tl.TypeInputFile': progress_callback: 'hints.ProgressCallback' = None) -> '_tl.TypeInputFile':
pass pass
@forward_call(users._get_input_peer)
async def _get_input_peer(self, *, save=True, **changes):
pass
@forward_call(users._get_peer_id)
async def _get_peer_id(self, *, save=True, **changes):
pass
# endregion Private # endregion Private

View File

@ -168,7 +168,7 @@ async def _send_album(self: 'TelegramClient', entity, files, caption='',
# In theory documents can be sent inside the albums but they appear # In theory documents can be sent inside the albums but they appear
# as different messages (not inside the album), and the logic to set # as different messages (not inside the album), and the logic to set
# the attributes/avoid cache is already written in .send_file(). # the attributes/avoid cache is already written in .send_file().
entity = await self.get_input_entity(entity) entity = await self._get_input_peer(entity)
if not utils.is_list_like(caption): if not utils.is_list_like(caption):
caption = (caption,) caption = (caption,)

View File

@ -166,7 +166,7 @@ async def get_profile(
if isinstance(x, str): if isinstance(x, str):
inputs.append(x) inputs.append(x)
else: else:
inputs.append(await self.get_input_entity(x)) inputs.append(await self._get_input_peer(x))
lists = { lists = {
helpers._EntityType.USER: [], helpers._EntityType.USER: [],
@ -220,7 +220,7 @@ async def get_profile(
return result[0] if single else result return result[0] if single else result
async def get_input_entity( async def _get_input_peer(
self: 'TelegramClient', self: 'TelegramClient',
peer: 'hints.DialogLike') -> '_tl.TypeInputPeer': peer: 'hints.DialogLike') -> '_tl.TypeInputPeer':
# Short-circuit if the input parameter directly maps to an InputPeer # Short-circuit if the input parameter directly maps to an InputPeer
@ -287,7 +287,7 @@ async def get_input_entity(
.format(peer, type(peer).__name__) .format(peer, type(peer).__name__)
) )
async def get_peer_id( async def _get_peer_id(
self: 'TelegramClient', self: 'TelegramClient',
peer: 'hints.DialogLike') -> int: peer: 'hints.DialogLike') -> int:
if isinstance(peer, int): if isinstance(peer, int):
@ -296,9 +296,9 @@ async def get_peer_id(
try: try:
if peer.SUBCLASS_OF_ID not in (0x2d45687, 0xc91c90b6): if peer.SUBCLASS_OF_ID not in (0x2d45687, 0xc91c90b6):
# 0x2d45687, 0xc91c90b6 == crc32(b'Peer') and b'InputPeer' # 0x2d45687, 0xc91c90b6 == crc32(b'Peer') and b'InputPeer'
peer = await self.get_input_entity(peer) peer = await self._get_input_peer(peer)
except AttributeError: except AttributeError:
peer = await self.get_input_entity(peer) peer = await self._get_input_peer(peer)
if isinstance(peer, _tl.InputPeerSelf): if isinstance(peer, _tl.InputPeerSelf):
peer = _tl.PeerUser(self._session_state.user_id) peer = _tl.PeerUser(self._session_state.user_id)
@ -372,13 +372,13 @@ async def _get_input_dialog(self: 'TelegramClient', dialog):
""" """
try: try:
if dialog.SUBCLASS_OF_ID == 0xa21c9795: # crc32(b'InputDialogPeer') if dialog.SUBCLASS_OF_ID == 0xa21c9795: # crc32(b'InputDialogPeer')
return dataclasses.replace(dialog, peer=await self.get_input_entity(dialog.peer)) return dataclasses.replace(dialog, peer=await self._get_input_peer(dialog.peer))
elif dialog.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') elif dialog.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer')
return _tl.InputDialogPeer(dialog) return _tl.InputDialogPeer(dialog)
except AttributeError: except AttributeError:
pass pass
return _tl.InputDialogPeer(await self.get_input_entity(dialog)) return _tl.InputDialogPeer(await self._get_input_peer(dialog))
async def _get_input_notify(self: 'TelegramClient', notify): async def _get_input_notify(self: 'TelegramClient', notify):
""" """
@ -389,9 +389,9 @@ async def _get_input_notify(self: 'TelegramClient', notify):
try: try:
if notify.SUBCLASS_OF_ID == 0x58981615: if notify.SUBCLASS_OF_ID == 0x58981615:
if isinstance(notify, _tl.InputNotifyPeer): if isinstance(notify, _tl.InputNotifyPeer):
return dataclasses.replace(notify, peer=await self.get_input_entity(notify.peer)) return dataclasses.replace(notify, peer=await self._get_input_peer(notify.peer))
return notify return notify
except AttributeError: except AttributeError:
pass pass
return _tl.InputNotifyPeer(await self.get_input_entity(notify)) return _tl.InputNotifyPeer(await self._get_input_peer(notify))

View File

@ -307,7 +307,7 @@ class ChatAction(EventBuilder):
Returns `added_by` but will make an API call if necessary. Returns `added_by` but will make an API call if necessary.
""" """
if not self.added_by and self._added_by: if not self.added_by and self._added_by:
self._added_by = await self._client.get_entity(self._added_by) self._added_by = await self._client.get_profile(self._added_by)
return self._added_by return self._added_by
@ -328,7 +328,7 @@ class ChatAction(EventBuilder):
Returns `kicked_by` but will make an API call if necessary. Returns `kicked_by` but will make an API call if necessary.
""" """
if not self.kicked_by and self._kicked_by: if not self.kicked_by and self._kicked_by:
self._kicked_by = await self._client.get_entity(self._kicked_by) self._kicked_by = await self._client.get_profile(self._kicked_by)
return self._kicked_by return self._kicked_by

View File

@ -58,7 +58,7 @@ class Draft:
if not self.entity and await self.get_input_entity(): if not self.entity and await self.get_input_entity():
try: try:
self._entity =\ self._entity =\
await self._client.get_entity(self._input_entity) await self._client.get_profile(self._input_entity)
except ValueError: except ValueError:
pass pass

View File

@ -143,7 +143,7 @@ class InlineResult:
""" """
if entity: if entity:
entity = await self._client.get_input_entity(entity) entity = await self._client.get_input_peer(entity)
elif self._entity: elif self._entity:
entity = self._entity entity = self._entity
else: else:

View File

@ -72,7 +72,7 @@ class MessageButton:
it will be "clicked" and the :tl:`BotCallbackAnswer` returned. it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
If it's an inline :tl:`KeyboardButtonUserProfile` button, the If it's an inline :tl:`KeyboardButtonUserProfile` button, the
`client.get_entity` will be called and the resulting :tl:User will be `client.get_profile` will be called and the resulting :tl:User will be
returned. returned.
If it's an inline :tl:`KeyboardButtonSwitchInline` button, the If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
@ -112,7 +112,7 @@ class MessageButton:
except BotResponseTimeoutError: except BotResponseTimeoutError:
return None return None
elif isinstance(self.button, _tl.KeyboardButtonUserProfile): elif isinstance(self.button, _tl.KeyboardButtonUserProfile):
return await self._client.get_entity(self.button.user_id) return await self._client.get_profile(self.button.user_id)
elif isinstance(self.button, _tl.KeyboardButtonSwitchInline): elif isinstance(self.button, _tl.KeyboardButtonSwitchInline):
return await self._client(_tl.fn.messages.StartBot( return await self._client(_tl.fn.messages.StartBot(
bot=self._bot, peer=self._chat, start_param=self.button.query, bot=self._bot, peer=self._chat, start_param=self.button.query,

View File

@ -322,7 +322,7 @@ class App(tkinter.Tk):
try: try:
old = self.chat_id old = self.chat_id
# Valid chat ID, set it and configure the colour back to white # Valid chat ID, set it and configure the colour back to white
self.chat_id = await self.cl.get_peer_id(chat) self.chat_id = (await self.cl.get_profile(chat)).id
self.chat.configure(bg='white') self.chat.configure(bg='white')
# If the chat ID changed, clear the # If the chat ID changed, clear the

View File

@ -23,4 +23,4 @@ messages.MessageMethods,delete_messages,channels.deleteMessages messages.deleteM
messages.MessageMethods,send_read_acknowledge,messages.readMentions channels.readHistory messages.readHistory messages.MessageMethods,send_read_acknowledge,messages.readMentions channels.readHistory messages.readHistory
updates.UpdateMethods,catch_up,updates.getDifference updates.getChannelDifference updates.UpdateMethods,catch_up,updates.getDifference updates.getChannelDifference
uploads.UploadMethods,send_file,messages.sendMedia messages.sendMultiMedia messages.uploadMedia uploads.UploadMethods,send_file,messages.sendMedia messages.sendMultiMedia messages.uploadMedia
users.UserMethods,get_entity,users.getUsers messages.getChats channels.getChannels contacts.resolveUsername users.UserMethods,get_profile,users.getUsers messages.getChats channels.getChannels contacts.resolveUsername

1 ns friendly raw
23 messages.MessageMethods send_read_acknowledge messages.readMentions channels.readHistory messages.readHistory
24 updates.UpdateMethods catch_up updates.getDifference updates.getChannelDifference
25 uploads.UploadMethods send_file messages.sendMedia messages.sendMultiMedia messages.uploadMedia
26 users.UserMethods get_entity get_profile users.getUsers messages.getChats channels.getChannels contacts.resolveUsername

View File

@ -16,11 +16,11 @@ AUTO_GEN_NOTICE = \
AUTO_CASTS = { AUTO_CASTS = {
'InputPeer': 'InputPeer':
'utils.get_input_peer(await client.get_input_entity({}))', 'utils.get_input_peer(await client._get_input_peer({}))',
'InputChannel': 'InputChannel':
'utils.get_input_channel(await client.get_input_entity({}))', 'utils.get_input_channel(await client._get_input_peer({}))',
'InputUser': 'InputUser':
'utils.get_input_user(await client.get_input_entity({}))', 'utils.get_input_user(await client._get_input_peer({}))',
'InputDialogPeer': 'await client._get_input_dialog({})', 'InputDialogPeer': 'await client._get_input_dialog({})',
'InputNotifyPeer': 'await client._get_input_notify({})', 'InputNotifyPeer': 'await client._get_input_notify({})',
@ -33,7 +33,7 @@ AUTO_CASTS = {
} }
NAMED_AUTO_CASTS = { NAMED_AUTO_CASTS = {
('chat_id', 'int'): 'await client.get_peer_id({})' ('chat_id', 'int'): 'await client._get_peer_id({})'
} }
# Secret chats have a chat_id which may be negative. # Secret chats have a chat_id which may be negative.