From d426099bf5304c6736f7cc5a5c6274cbdd39ad09 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 26 Jan 2022 11:03:50 +0100 Subject: [PATCH] Remove input_peer parameter from get_me --- readthedocs/misc/v2-migration-guide.rst | 2 ++ telethon/_client/chats.py | 2 +- telethon/_client/telegramclient.py | 13 ++----------- telethon/_client/users.py | 7 +++---- telethon/_events/common.py | 2 +- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/readthedocs/misc/v2-migration-guide.rst b/readthedocs/misc/v2-migration-guide.rst index dc751b1a..3e4905b1 100644 --- a/readthedocs/misc/v2-migration-guide.rst +++ b/readthedocs/misc/v2-migration-guide.rst @@ -773,3 +773,5 @@ connection type is gone raise_last_call_error is now the default rather than ValueError self-produced updates like getmessage now also trigger a handler + +input_peer removed from get_me; input peers should remain mostly an impl detail diff --git a/telethon/_client/chats.py b/telethon/_client/chats.py index 8ab4bff6..e8a95291 100644 --- a/telethon/_client/chats.py +++ b/telethon/_client/chats.py @@ -648,7 +648,7 @@ async def get_permissions( entity )) 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: if participant.user_id == user.user_id: return _custom.ParticipantPermissions(participant, True) diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index d78b0ce6..3196c1eb 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -3274,19 +3274,13 @@ class TelegramClient: """ @forward_call(users.get_me) - async def get_me(self: 'TelegramClient', input_peer: bool = False) \ - -> 'typing.Union[_tl.User, _tl.InputPeerUser]': + async def get_me(self: 'TelegramClient') \ + -> '_tl.User': """ Gets "me", the current :tl:`User` who is logged in. 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 Your own :tl:`User`. @@ -3434,9 +3428,6 @@ class TelegramClient: :tl:`InputPeerUser`, :tl:`InputPeerChat` or :tl:`InputPeerChannel` 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 .. code-block:: python diff --git a/telethon/_client/users.py b/telethon/_client/users.py index 53da7574..05f925bd 100644 --- a/telethon/_client/users.py +++ b/telethon/_client/users.py @@ -126,11 +126,10 @@ async def _call(self: 'TelegramClient', sender, request, ordered=False, flood_sl 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]': try: - me = (await self(_tl.fn.users.GetUsers([_tl.InputUserSelf()])))[0] - return utils.get_input_peer(me, allow_self=False) if input_peer else me + return (await self(_tl.fn.users.GetUsers([_tl.InputUserSelf()])))[0] except UnauthorizedError: return None @@ -296,7 +295,7 @@ async def get_peer_id( peer = await self.get_input_entity(peer) 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) diff --git a/telethon/_events/common.py b/telethon/_events/common.py index fb941980..c20ac64e 100644 --- a/telethon/_events/common.py +++ b/telethon/_events/common.py @@ -25,7 +25,7 @@ async def _into_id_set(client, chats): else: chat = await client.get_input_entity(chat) 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)) return result