mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 21:10:29 +00:00
Update docstrings to have consistent style
This commit is contained in:
@@ -108,14 +108,19 @@ class UserMethods(TelegramBaseClient):
|
||||
|
||||
If the user has not logged in yet, this method returns ``None``.
|
||||
|
||||
Args:
|
||||
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`.
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
print(client.get_me().username)
|
||||
"""
|
||||
if input_peer and self._self_input_peer:
|
||||
return self._self_input_peer
|
||||
@@ -137,6 +142,14 @@ class UserMethods(TelegramBaseClient):
|
||||
async def is_bot(self: 'TelegramClient') -> bool:
|
||||
"""
|
||||
Return ``True`` if the signed-in user is a bot, ``False`` otherwise.
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
if client.is_bot():
|
||||
print('Beep')
|
||||
else:
|
||||
print('Hello')
|
||||
"""
|
||||
if self._bot is None:
|
||||
self._bot = (await self.get_me()).bot
|
||||
@@ -146,6 +159,14 @@ class UserMethods(TelegramBaseClient):
|
||||
async def is_user_authorized(self: 'TelegramClient') -> bool:
|
||||
"""
|
||||
Returns ``True`` if the user is authorized (i.e. has logged in).
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
if not client.is_user_authorized():
|
||||
client.send_code_request(phone)
|
||||
code = input('enter code: ')
|
||||
client.sign_in(phone, code)
|
||||
"""
|
||||
if self._authorized is None:
|
||||
try:
|
||||
@@ -165,35 +186,35 @@ class UserMethods(TelegramBaseClient):
|
||||
or :tl:`Channel`. You can also pass a list or iterable of entities,
|
||||
and they will be efficiently fetched from the network.
|
||||
|
||||
entity (`str` | `int` | :tl:`Peer` | :tl:`InputPeer`):
|
||||
If a username is given, **the username will be resolved** making
|
||||
an API call every time. Resolving usernames is an expensive
|
||||
operation and will start hitting flood waits around 50 usernames
|
||||
in a short period of time.
|
||||
Arguments
|
||||
entity (`str` | `int` | :tl:`Peer` | :tl:`InputPeer`):
|
||||
If a username is given, **the username will be resolved** making
|
||||
an API call every time. Resolving usernames is an expensive
|
||||
operation and will start hitting flood waits around 50 usernames
|
||||
in a short period of time.
|
||||
|
||||
If you want to get the entity for a *cached* username, you should
|
||||
first `get_input_entity(username) <get_input_entity>` which will
|
||||
use the cache), and then use `get_entity` with the result of the
|
||||
previous call.
|
||||
If you want to get the entity for a *cached* username, you should
|
||||
first `get_input_entity(username) <get_input_entity>` which will
|
||||
use the cache), and then use `get_entity` with the result of the
|
||||
previous call.
|
||||
|
||||
Similar limits apply to invite links, and you should use their
|
||||
ID instead.
|
||||
Similar limits apply to invite links, and you should use their
|
||||
ID instead.
|
||||
|
||||
Using phone numbers (from people in your contact list), exact
|
||||
names, integer IDs or :tl:`Peer` rely on a `get_input_entity`
|
||||
first, which in turn needs the entity to be in cache, unless
|
||||
a :tl:`InputPeer` was passed.
|
||||
Using phone numbers (from people in your contact list), exact
|
||||
names, integer IDs or :tl:`Peer` rely on a `get_input_entity`
|
||||
first, which in turn needs the entity to be in cache, unless
|
||||
a :tl:`InputPeer` was passed.
|
||||
|
||||
Unsupported types will raise ``TypeError``.
|
||||
Unsupported types will raise ``TypeError``.
|
||||
|
||||
If the entity can't be found, ``ValueError`` will be raised.
|
||||
If the entity can't be found, ``ValueError`` will be raised.
|
||||
|
||||
Returns:
|
||||
Returns
|
||||
:tl:`User`, :tl:`Chat` or :tl:`Channel` corresponding to the
|
||||
input entity. A list will be returned if more than one was given.
|
||||
|
||||
Example:
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
from telethon import utils
|
||||
@@ -284,57 +305,57 @@ class UserMethods(TelegramBaseClient):
|
||||
first, but if you're going to use an entity often, consider making the
|
||||
call:
|
||||
|
||||
>>> import asyncio
|
||||
>>> rc = asyncio.get_event_loop().run_until_complete
|
||||
>>>
|
||||
>>> from telethon import TelegramClient
|
||||
>>> client = TelegramClient(...)
|
||||
>>> # If you're going to use "username" often in your code
|
||||
>>> # (make a lot of calls), consider getting its input entity
|
||||
>>> # once, and then using the "user" everywhere instead.
|
||||
>>> user = rc(client.get_input_entity('username'))
|
||||
>>> # The same applies to IDs, chats or channels.
|
||||
>>> chat = rc(client.get_input_entity(-123456789))
|
||||
Arguments
|
||||
entity (`str` | `int` | :tl:`Peer` | :tl:`InputPeer`):
|
||||
If a username or invite link is given, **the library will
|
||||
use the cache**. This means that it's possible to be using
|
||||
a username that *changed* or an old invite link (this only
|
||||
happens if an invite link for a small group chat is used
|
||||
after it was upgraded to a mega-group).
|
||||
|
||||
entity (`str` | `int` | :tl:`Peer` | :tl:`InputPeer`):
|
||||
If a username or invite link is given, **the library will
|
||||
use the cache**. This means that it's possible to be using
|
||||
a username that *changed* or an old invite link (this only
|
||||
happens if an invite link for a small group chat is used
|
||||
after it was upgraded to a mega-group).
|
||||
If the username or ID from the invite link is not found in
|
||||
the cache, it will be fetched. The same rules apply to phone
|
||||
numbers (``'+34 123456789'``) from people in your contact list.
|
||||
|
||||
If the username or ID from the invite link is not found in
|
||||
the cache, it will be fetched. The same rules apply to phone
|
||||
numbers (``'+34 123456789'``) from people in your contact list.
|
||||
If an exact name is given, it must be in the cache too. This
|
||||
is not reliable as different people can share the same name
|
||||
and which entity is returned is arbitrary, and should be used
|
||||
only for quick tests.
|
||||
|
||||
If an exact name is given, it must be in the cache too. This
|
||||
is not reliable as different people can share the same name
|
||||
and which entity is returned is arbitrary, and should be used
|
||||
only for quick tests.
|
||||
If a positive integer ID is given, the entity will be searched
|
||||
in cached users, chats or channels, without making any call.
|
||||
|
||||
If a positive integer ID is given, the entity will be searched
|
||||
in cached users, chats or channels, without making any call.
|
||||
If a negative integer ID is given, the entity will be searched
|
||||
exactly as either a chat (prefixed with ``-``) or as a channel
|
||||
(prefixed with ``-100``).
|
||||
|
||||
If a negative integer ID is given, the entity will be searched
|
||||
exactly as either a chat (prefixed with ``-``) or as a channel
|
||||
(prefixed with ``-100``).
|
||||
If a :tl:`Peer` is given, it will be searched exactly in the
|
||||
cache as either a user, chat or channel.
|
||||
|
||||
If a :tl:`Peer` is given, it will be searched exactly in the
|
||||
cache as either a user, chat or channel.
|
||||
If the given object can be turned into an input entity directly,
|
||||
said operation will be done.
|
||||
|
||||
If the given object can be turned into an input entity directly,
|
||||
said operation will be done.
|
||||
Unsupported types will raise ``TypeError``.
|
||||
|
||||
Unsupported types will raise ``TypeError``.
|
||||
If the entity can't be found, ``ValueError`` will be raised.
|
||||
|
||||
If the entity can't be found, ``ValueError`` will be raised.
|
||||
|
||||
Returns:
|
||||
Returns
|
||||
: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
|
||||
|
||||
# If you're going to use "username" often in your code
|
||||
# (make a lot of calls), consider getting its input entity
|
||||
# once, and then using the "user" everywhere instead.
|
||||
user = client.get_input_entity('username')
|
||||
|
||||
# The same applies to IDs, chats or channels.
|
||||
chat = client.get_input_entity(-123456789)
|
||||
"""
|
||||
# Short-circuit if the input parameter directly maps to an InputPeer
|
||||
try:
|
||||
@@ -411,6 +432,11 @@ class UserMethods(TelegramBaseClient):
|
||||
|
||||
If ``add_mark is False``, then a positive ID will be returned
|
||||
instead. By default, bot-API style IDs (signed) are returned.
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
print(client.get_peer_id('me'))
|
||||
"""
|
||||
if isinstance(peer, int):
|
||||
return utils.get_peer_id(peer, add_mark=add_mark)
|
||||
|
Reference in New Issue
Block a user