1+ # Pyrogram - Telegram MTProto API Client Library for Python
2+ # Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+ #
4+ # This file is part of Pyrogram.
5+ #
6+ # Pyrogram is free software: you can redistribute it and/or modify
7+ # it under the terms of the GNU Lesser General Public License as published
8+ # by the Free Software Foundation, either version 3 of the License, or
9+ # (at your option) any later version.
10+ #
11+ # Pyrogram is distributed in the hope that it will be useful,
12+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ # GNU Lesser General Public License for more details.
15+ #
16+ # You should have received a copy of the GNU Lesser General Public License
17+ # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+ import asyncio
20+ from typing import Union
21+
22+ import pyrogram
23+ from pyrogram import raw
24+ from pyrogram import types
25+
26+
27+ class GetUser :
28+ async def get_user (
29+ self : "pyrogram.Client" ,
30+ user_id : Union [int , str ]
31+ ) -> "types.User" :
32+ """Get information about a single user.
33+
34+ .. include:: /_includes/usable-by/users-bots.rst
35+
36+ Parameters:
37+ user_id (``int`` | ``str``):
38+ A single user identifier (id or username).
39+ For a contact that exists in your Telegram address book you can use his phone number (str).
40+
41+ Returns:
42+ :obj:`~pyrogram.types.User`: A single user is returned.
43+
44+ Example:
45+ .. code-block:: python
46+
47+ # Get information about one user
48+ await app.get_user("me")
49+
50+ # Get information by user ID
51+ await app.get_user(12345)
52+
53+ # Get information by username
54+ await app.get_user("@username")
55+
56+ Raises:
57+ ValueError: In case of invalid arguments or if the user does not exist.
58+ """
59+ peer = await self .resolve_peer (user_id )
60+
61+ r = await self .invoke (
62+ raw .functions .users .GetUsers (
63+ id = [peer ]
64+ )
65+ )
66+
67+ users = types .List ()
68+
69+ for i in r :
70+ users .append (types .User ._parse (self , i ))
71+
72+ if users :
73+ return users [0 ]
74+
75+ msg = "User does not exist"
76+ raise ValueError (msg )
0 commit comments