2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Add no_updates parameter in Client

Useful to completely disable incoming updates for batch programs
This commit is contained in:
Dan 2019-01-03 11:13:24 +01:00
parent 4493f78138
commit b53ba81a6a

View File

@ -151,6 +151,12 @@ class Client(Methods, BaseClient):
Define a custom directory for your plugins. The plugins directory is the location in your Define a custom directory for your plugins. The plugins directory is the location in your
filesystem where Pyrogram will automatically load your update handlers. filesystem where Pyrogram will automatically load your update handlers.
Defaults to None (plugins disabled). Defaults to None (plugins disabled).
no_updates (``bool``, *optional*):
Pass True to completely disable incoming updates for the current session.
When updates are disabled your client can't receive any new message.
Useful for batch programs that don't need to deal with updates.
Defaults to False (updates enabled and always received).
""" """
def __init__(self, def __init__(self,
@ -173,7 +179,8 @@ class Client(Methods, BaseClient):
workers: int = BaseClient.WORKERS, workers: int = BaseClient.WORKERS,
workdir: str = BaseClient.WORKDIR, workdir: str = BaseClient.WORKDIR,
config_file: str = BaseClient.CONFIG_FILE, config_file: str = BaseClient.CONFIG_FILE,
plugins_dir: str = None): plugins_dir: str = None,
no_updates: bool = None):
super().__init__() super().__init__()
self.session_name = session_name self.session_name = session_name
@ -197,6 +204,7 @@ class Client(Methods, BaseClient):
self.workdir = workdir self.workdir = workdir
self.config_file = config_file self.config_file = config_file
self.plugins_dir = plugins_dir self.plugins_dir = plugins_dir
self.no_updates = no_updates
self.dispatcher = Dispatcher(self, workers) self.dispatcher = Dispatcher(self, workers)
@ -943,6 +951,9 @@ class Client(Methods, BaseClient):
if not self.is_started: if not self.is_started:
raise ConnectionError("Client has not been started") raise ConnectionError("Client has not been started")
if self.no_updates:
data = functions.InvokeWithoutUpdates(data)
r = self.session.send(data, retries, timeout) r = self.session.send(data, retries, timeout)
self.fetch_peers(getattr(r, "users", [])) self.fetch_peers(getattr(r, "users", []))