mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Reword some methods' docstring
This commit is contained in:
parent
591499121f
commit
bd9bb83df5
@ -261,8 +261,7 @@ class Client(Methods, BaseClient):
|
|||||||
self._proxy.update(value)
|
self._proxy.update(value)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Use this method to start the Client after creating it.
|
"""Use this method to start the Client.
|
||||||
Requires no parameters.
|
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
|
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
|
||||||
@ -355,8 +354,7 @@ class Client(Methods, BaseClient):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Use this method to manually stop the Client.
|
"""Use this method to stop the Client.
|
||||||
Requires no parameters.
|
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
``ConnectionError`` in case you try to stop an already stopped Client.
|
``ConnectionError`` in case you try to stop an already stopped Client.
|
||||||
@ -399,7 +397,6 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
"""Use this method to restart the Client.
|
"""Use this method to restart the Client.
|
||||||
Requires no parameters.
|
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
``ConnectionError`` in case you try to restart a stopped Client.
|
``ConnectionError`` in case you try to restart a stopped Client.
|
||||||
@ -408,8 +405,16 @@ class Client(Methods, BaseClient):
|
|||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
|
def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
|
||||||
"""Blocks the program execution until one of the signals are received,
|
"""Use this method to block the main script execution until a signal (e.g.: from CTRL+C) is received.
|
||||||
then gently stop the Client by closing the underlying connection.
|
Once the signal is received, the client will automatically stop and the main script will continue its execution.
|
||||||
|
|
||||||
|
This is used after starting one or more clients and is useful for event-driven applications only, that are,
|
||||||
|
applications which react upon incoming Telegram updates through handlers, rather than executing a set of methods
|
||||||
|
sequentially.
|
||||||
|
|
||||||
|
The way Pyrogram works, will keep your handlers in a pool of workers, which are executed concurrently outside
|
||||||
|
the main script; calling idle() will ensure the client(s) will be kept alive by not letting the main script to
|
||||||
|
end, until you decide to quit.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
stop_signals (``tuple``, *optional*):
|
stop_signals (``tuple``, *optional*):
|
||||||
@ -417,6 +422,8 @@ class Client(Methods, BaseClient):
|
|||||||
Defaults to (SIGINT, SIGTERM, SIGABRT).
|
Defaults to (SIGINT, SIGTERM, SIGABRT).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# TODO: Maybe make this method static and don't automatically stop
|
||||||
|
|
||||||
def signal_handler(*args):
|
def signal_handler(*args):
|
||||||
self.is_idle = False
|
self.is_idle = False
|
||||||
|
|
||||||
@ -431,8 +438,11 @@ class Client(Methods, BaseClient):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Use this method to automatically start and idle a Client.
|
"""Use this method as a convenience shortcut to automatically start the Client and idle the main script.
|
||||||
Requires no parameters.
|
|
||||||
|
This is a convenience method that literally just calls :meth:`start` and :meth:`idle`. It makes running a client
|
||||||
|
less verbose, but is not suitable in case you want to run more than one client in a single main script,
|
||||||
|
since :meth:`idle` will block.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
|
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
|
||||||
@ -465,7 +475,7 @@ class Client(Methods, BaseClient):
|
|||||||
return handler, group
|
return handler, group
|
||||||
|
|
||||||
def remove_handler(self, handler: Handler, group: int = 0):
|
def remove_handler(self, handler: Handler, group: int = 0):
|
||||||
"""Removes a previously-added update handler.
|
"""Use this method to remove a previously-registered update handler.
|
||||||
|
|
||||||
Make sure to provide the right group that the handler was added in. You can use
|
Make sure to provide the right group that the handler was added in. You can use
|
||||||
the return value of the :meth:`add_handler` method, a tuple of (handler, group), and
|
the return value of the :meth:`add_handler` method, a tuple of (handler, group), and
|
||||||
@ -752,9 +762,16 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
print("Logged in successfully as {}".format(r.user.first_name))
|
print("Logged in successfully as {}".format(r.user.first_name))
|
||||||
|
|
||||||
def fetch_peers(self, entities: List[Union[types.User,
|
def fetch_peers(
|
||||||
types.Chat, types.ChatForbidden,
|
self,
|
||||||
types.Channel, types.ChannelForbidden]]):
|
entities: List[
|
||||||
|
Union[
|
||||||
|
types.User,
|
||||||
|
types.Chat, types.ChatForbidden,
|
||||||
|
types.Channel, types.ChannelForbidden
|
||||||
|
]
|
||||||
|
]
|
||||||
|
):
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
if isinstance(entity, types.User):
|
if isinstance(entity, types.User):
|
||||||
user_id = entity.id
|
user_id = entity.id
|
||||||
@ -1018,16 +1035,19 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
log.debug("{} stopped".format(name))
|
log.debug("{} stopped".format(name))
|
||||||
|
|
||||||
def send(self,
|
def send(self, data: Object, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT):
|
||||||
data: Object,
|
"""Use this method to send raw Telegram queries.
|
||||||
retries: int = Session.MAX_RETRIES,
|
|
||||||
timeout: float = Session.WAIT_TIMEOUT):
|
|
||||||
"""Use this method to send Raw Function queries.
|
|
||||||
|
|
||||||
This method makes possible to manually call every single Telegram API method in a low-level manner.
|
This method makes it possible to manually call every single Telegram API method in a low-level manner.
|
||||||
Available functions are listed in the :obj:`functions <pyrogram.api.functions>` package and may accept compound
|
Available functions are listed in the :obj:`functions <pyrogram.api.functions>` package and may accept compound
|
||||||
data types from :obj:`types <pyrogram.api.types>` as well as bare types such as ``int``, ``str``, etc...
|
data types from :obj:`types <pyrogram.api.types>` as well as bare types such as ``int``, ``str``, etc...
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
This is a utility method intended to be used **only** when working with raw
|
||||||
|
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
|
||||||
|
available yet in the Client class as an easy-to-use method).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (``Object``):
|
data (``Object``):
|
||||||
The API Schema function filled with proper arguments.
|
The API Schema function filled with proper arguments.
|
||||||
@ -1285,8 +1305,7 @@ class Client(Methods, BaseClient):
|
|||||||
indent=4
|
indent=4
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_initial_dialogs_chunk(self,
|
def get_initial_dialogs_chunk(self, offset_date: int = 0):
|
||||||
offset_date: int = 0):
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
r = self.send(
|
r = self.send(
|
||||||
@ -1318,13 +1337,15 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
self.get_initial_dialogs_chunk()
|
self.get_initial_dialogs_chunk()
|
||||||
|
|
||||||
def resolve_peer(self,
|
def resolve_peer(self, peer_id: Union[int, str]):
|
||||||
peer_id: Union[int, str]):
|
"""Use this method to get the InputPeer of a known peer id.
|
||||||
"""Use this method to get the InputPeer of a known peer_id.
|
Useful whenever an InputPeer type is required.
|
||||||
|
|
||||||
This is a utility method intended to be used **only** when working with Raw Functions (i.e: a Telegram API
|
.. note::
|
||||||
method you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an
|
|
||||||
InputPeer type is required.
|
This is a utility method intended to be used **only** when working with raw
|
||||||
|
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
|
||||||
|
available yet in the Client class as an easy-to-use method).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
peer_id (``int`` | ``str``):
|
peer_id (``int`` | ``str``):
|
||||||
@ -1391,17 +1412,22 @@ class Client(Methods, BaseClient):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise PeerIdInvalid
|
raise PeerIdInvalid
|
||||||
|
|
||||||
def save_file(self,
|
def save_file(
|
||||||
path: str,
|
self,
|
||||||
file_id: int = None,
|
path: str,
|
||||||
file_part: int = 0,
|
file_id: int = None,
|
||||||
progress: callable = None,
|
file_part: int = 0,
|
||||||
progress_args: tuple = ()):
|
progress: callable = None,
|
||||||
|
progress_args: tuple = ()
|
||||||
|
):
|
||||||
"""Use this method to upload a file onto Telegram servers, without actually sending the message to anyone.
|
"""Use this method to upload a file onto Telegram servers, without actually sending the message to anyone.
|
||||||
|
Useful whenever an InputFile type is required.
|
||||||
|
|
||||||
This is a utility method intended to be used **only** when working with Raw Functions (i.e: a Telegram API
|
.. note::
|
||||||
method you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an
|
|
||||||
InputFile type is required.
|
This is a utility method intended to be used **only** when working with raw
|
||||||
|
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
|
||||||
|
available yet in the Client class as an easy-to-use method).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
path (``str``):
|
path (``str``):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user