Remove input_peer parameter from get_me

This commit is contained in:
Lonami Exo 2022-01-26 11:03:50 +01:00
parent 7778e54467
commit d426099bf5
5 changed files with 9 additions and 17 deletions

View File

@ -773,3 +773,5 @@ connection type is gone
raise_last_call_error is now the default rather than ValueError raise_last_call_error is now the default rather than ValueError
self-produced updates like getmessage now also trigger a handler self-produced updates like getmessage now also trigger a handler
input_peer removed from get_me; input peers should remain mostly an impl detail

View File

@ -648,7 +648,7 @@ async def get_permissions(
entity entity
)) ))
if isinstance(user, _tl.InputPeerSelf): if isinstance(user, _tl.InputPeerSelf):
user = await self.get_me(input_peer=True) user = _tl.PeerUser(self._session_state.user_id)
for participant in chat.full_chat.participants.participants: for participant in chat.full_chat.participants.participants:
if participant.user_id == user.user_id: if participant.user_id == user.user_id:
return _custom.ParticipantPermissions(participant, True) return _custom.ParticipantPermissions(participant, True)

View File

@ -3274,19 +3274,13 @@ class TelegramClient:
""" """
@forward_call(users.get_me) @forward_call(users.get_me)
async def get_me(self: 'TelegramClient', input_peer: bool = False) \ async def get_me(self: 'TelegramClient') \
-> 'typing.Union[_tl.User, _tl.InputPeerUser]': -> '_tl.User':
""" """
Gets "me", the current :tl:`User` who is logged in. Gets "me", the current :tl:`User` who is logged in.
If the user has not logged in yet, this method returns `None`. If the user has not logged in yet, this method returns `None`.
Arguments
input_peer (`bool`, optional):
Whether to return the :tl:`InputPeerUser` version or the normal
:tl:`User`. This can be useful if you just need to know the ID
of yourself.
Returns Returns
Your own :tl:`User`. Your own :tl:`User`.
@ -3434,9 +3428,6 @@ class TelegramClient:
:tl:`InputPeerUser`, :tl:`InputPeerChat` or :tl:`InputPeerChannel` :tl:`InputPeerUser`, :tl:`InputPeerChat` or :tl:`InputPeerChannel`
or :tl:`InputPeerSelf` if the parameter is ``'me'`` or ``'self'``. or :tl:`InputPeerSelf` if the parameter is ``'me'`` or ``'self'``.
If you need to get the ID of yourself, you should use
`get_me` with ``input_peer=True``) instead.
Example Example
.. code-block:: python .. code-block:: python

View File

@ -126,11 +126,10 @@ async def _call(self: 'TelegramClient', sender, request, ordered=False, flood_sl
raise last_error raise last_error
async def get_me(self: 'TelegramClient', input_peer: bool = False) \ async def get_me(self: 'TelegramClient') \
-> 'typing.Union[_tl.User, _tl.InputPeerUser]': -> 'typing.Union[_tl.User, _tl.InputPeerUser]':
try: try:
me = (await self(_tl.fn.users.GetUsers([_tl.InputUserSelf()])))[0] return (await self(_tl.fn.users.GetUsers([_tl.InputUserSelf()])))[0]
return utils.get_input_peer(me, allow_self=False) if input_peer else me
except UnauthorizedError: except UnauthorizedError:
return None return None
@ -296,7 +295,7 @@ async def get_peer_id(
peer = await self.get_input_entity(peer) peer = await self.get_input_entity(peer)
if isinstance(peer, _tl.InputPeerSelf): if isinstance(peer, _tl.InputPeerSelf):
peer = await self.get_me(input_peer=True) peer = _tl.PeerUser(self._session_state.user_id)
return utils.get_peer_id(peer) return utils.get_peer_id(peer)

View File

@ -25,7 +25,7 @@ async def _into_id_set(client, chats):
else: else:
chat = await client.get_input_entity(chat) chat = await client.get_input_entity(chat)
if isinstance(chat, _tl.InputPeerSelf): if isinstance(chat, _tl.InputPeerSelf):
chat = await client.get_me(input_peer=True) chat = _tl.PeerUser(self._session_state.user_id)
result.add(utils.get_peer_id(chat)) result.add(utils.get_peer_id(chat))
return result return result