From 896d0844d18173583b17adaf57eb14073da61839 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 12:29:14 +0200 Subject: [PATCH 01/17] Rename venv to venv3.6 --- docs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index cb346f83..c01e3d3d 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ # You can set these variables from the command line. SPHINXOPTS = -SPHINXBUILD = ~/PycharmProjects/pyrogram/venv/bin/sphinx-build +SPHINXBUILD = ~/PycharmProjects/pyrogram/venv3.6/bin/sphinx-build SPHINXPROJ = Pyrogram SOURCEDIR = source BUILDDIR = build From 2f80a0ba7fe9a006ebc343a5cd9f4ead042c2479 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 12:46:04 +0200 Subject: [PATCH 02/17] Add DeletedMessagesHandler to docs --- docs/source/pyrogram/handlers/DeletedMessagesHandler.rst | 6 ++++++ docs/source/pyrogram/handlers/index.rst | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docs/source/pyrogram/handlers/DeletedMessagesHandler.rst diff --git a/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst b/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst new file mode 100644 index 00000000..128bc656 --- /dev/null +++ b/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst @@ -0,0 +1,6 @@ +DeletedMessagesHandler +====================== + +.. autoclass:: pyrogram.DeletedMessagesHandler + :members: + :undoc-members: diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/handlers/index.rst index 191d4eff..272e529f 100644 --- a/docs/source/pyrogram/handlers/index.rst +++ b/docs/source/pyrogram/handlers/index.rst @@ -5,6 +5,7 @@ Handlers .. toctree:: MessageHandler + DeletedMessagesHandler CallbackQueryHandler + DisconnectHandler RawUpdateHandler - DisconnectHandler \ No newline at end of file From ac47ffad8f39201f68c3cde9fe57fa70dad1993f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 12:46:35 +0200 Subject: [PATCH 03/17] Hint about decorators on handlers' docstrings --- pyrogram/client/handlers/callback_query_handler.py | 3 +++ pyrogram/client/handlers/deleted_messages_handler.py | 5 ++++- pyrogram/client/handlers/disconnect_handler.py | 2 ++ pyrogram/client/handlers/message_handler.py | 3 +++ pyrogram/client/handlers/raw_update_handler.py | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/handlers/callback_query_handler.py b/pyrogram/client/handlers/callback_query_handler.py index c0bba510..c5346519 100644 --- a/pyrogram/client/handlers/callback_query_handler.py +++ b/pyrogram/client/handlers/callback_query_handler.py @@ -23,6 +23,9 @@ class CallbackQueryHandler(Handler): """The CallbackQuery handler class. Used to handle callback queries coming from inline buttons. It is intended to be used with :meth:`add_handler() ` + For a nicer way to register this handler, have a look at the + :meth:`on_callback_query() ` decorator. + Args: callback (``callable``): Pass a function that will be called when a new CallbackQuery arrives. It takes *(client, callback_query)* diff --git a/pyrogram/client/handlers/deleted_messages_handler.py b/pyrogram/client/handlers/deleted_messages_handler.py index 6a1f7689..55d5715f 100644 --- a/pyrogram/client/handlers/deleted_messages_handler.py +++ b/pyrogram/client/handlers/deleted_messages_handler.py @@ -20,10 +20,13 @@ from .handler import Handler class DeletedMessagesHandler(Handler): - """The Deleted Messages handler class. Used to handle deleted messages coming from any chat + """The deleted Messages handler class. Used to handle deleted messages coming from any chat (private, group, channel). It is intended to be used with :meth:`add_handler() ` + For a nicer way to register this handler, have a look at the + :meth:`on_deleted_messages() ` decorator. + Args: callback (``callable``): Pass a function that will be called when one or more Messages have been deleted. diff --git a/pyrogram/client/handlers/disconnect_handler.py b/pyrogram/client/handlers/disconnect_handler.py index 9ad4ffbc..a8b800a8 100644 --- a/pyrogram/client/handlers/disconnect_handler.py +++ b/pyrogram/client/handlers/disconnect_handler.py @@ -23,6 +23,8 @@ class DisconnectHandler(Handler): """The Disconnect handler class. Used to handle disconnections. It is intended to be used with :meth:`add_handler() ` + For a nicer way to register this handler, have a look at the + :meth:`on_disconnect() ` decorator. Args: callback (``callable``): diff --git a/pyrogram/client/handlers/message_handler.py b/pyrogram/client/handlers/message_handler.py index 6aae27de..1b4770b3 100644 --- a/pyrogram/client/handlers/message_handler.py +++ b/pyrogram/client/handlers/message_handler.py @@ -24,6 +24,9 @@ class MessageHandler(Handler): any chat (private, group, channel). It is intended to be used with :meth:`add_handler() ` + For a nicer way to register this handler, have a look at the + :meth:`on_message() ` decorator. + Args: callback (``callable``): Pass a function that will be called when a new Message arrives. It takes *(client, message)* diff --git a/pyrogram/client/handlers/raw_update_handler.py b/pyrogram/client/handlers/raw_update_handler.py index 8a1e0a03..5a8913b6 100644 --- a/pyrogram/client/handlers/raw_update_handler.py +++ b/pyrogram/client/handlers/raw_update_handler.py @@ -23,6 +23,9 @@ class RawUpdateHandler(Handler): """The Raw Update handler class. Used to handle raw updates. It is intended to be used with :meth:`add_handler() ` + For a nicer way to register this handler, have a look at the + :meth:`on_raw_update() ` decorator. + Args: callback (``callable``): A function that will be called when a new update is received from the server. It takes From 6be8f1aae326c9efd1d159b6de974bc206e97daf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 12:46:58 +0200 Subject: [PATCH 04/17] Cross reference Handler classes on decorators' docstrings --- pyrogram/client/methods/decorators/on_callback_query.py | 2 +- pyrogram/client/methods/decorators/on_deleted_messages.py | 2 +- pyrogram/client/methods/decorators/on_disconnect.py | 2 +- pyrogram/client/methods/decorators/on_message.py | 2 +- pyrogram/client/methods/decorators/on_raw_update.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index 3bafc94d..5f22fc92 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -24,7 +24,7 @@ class OnCallbackQuery(BaseClient): def on_callback_query(self, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling callback queries. This does the same thing as :meth:`add_handler` using the - CallbackQueryHandler. + :class:`CallbackQueryHandler`. Args: filters (:obj:`Filters `): diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index 4cc2d904..3f603c41 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -24,7 +24,7 @@ class OnDeletedMessages(BaseClient): def on_deleted_messages(self, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling deleted messages. This does the same thing as :meth:`add_handler` using the - DeletedMessagesHandler. + :class:`DeletedMessagesHandler`. Args: filters (:obj:`Filters `): diff --git a/pyrogram/client/methods/decorators/on_disconnect.py b/pyrogram/client/methods/decorators/on_disconnect.py index d1d03723..4bc593e3 100644 --- a/pyrogram/client/methods/decorators/on_disconnect.py +++ b/pyrogram/client/methods/decorators/on_disconnect.py @@ -24,7 +24,7 @@ class OnDisconnect(BaseClient): def on_disconnect(self): """Use this decorator to automatically register a function for handling disconnections. This does the same thing as :meth:`add_handler` using the - DisconnectHandler. + :class:`DisconnectHandler`. """ def decorator(func): diff --git a/pyrogram/client/methods/decorators/on_message.py b/pyrogram/client/methods/decorators/on_message.py index 43c6f9f8..0011e083 100644 --- a/pyrogram/client/methods/decorators/on_message.py +++ b/pyrogram/client/methods/decorators/on_message.py @@ -24,7 +24,7 @@ class OnMessage(BaseClient): def on_message(self, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling messages. This does the same thing as :meth:`add_handler` using the - MessageHandler. + :class:`MessageHandler`. Args: filters (:obj:`Filters `): diff --git a/pyrogram/client/methods/decorators/on_raw_update.py b/pyrogram/client/methods/decorators/on_raw_update.py index ca1c9d9b..902d9854 100644 --- a/pyrogram/client/methods/decorators/on_raw_update.py +++ b/pyrogram/client/methods/decorators/on_raw_update.py @@ -24,7 +24,7 @@ class OnRawUpdate(BaseClient): def on_raw_update(self, group: int = 0): """Use this decorator to automatically register a function for handling raw updates. This does the same thing as :meth:`add_handler` using the - RawUpdateHandler. + :class:`RawUpdateHandler`. Args: group (``int``, *optional*): From 7c97efd2a134523109835a30f115c2833ac48230 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 12:55:52 +0200 Subject: [PATCH 05/17] Update docs --- docs/source/start/Setup.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index dc837a86..e9105cde 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -1,7 +1,7 @@ Setup ===== -Once you successfully installed_ Pyrogram, you will have to follow a few steps before you can actually use +Once you successfully `installed Pyrogram`_, you will still have to follow a few steps before you can actually use the library to make API calls. This section provides all the information you need in order to set up a project with Pyrogram. @@ -46,7 +46,7 @@ There are two ways to configure a Pyrogram application project, and you can choo ) .. note:: The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id* -and *api_hash* parameters usage. + and *api_hash* parameters usage. User Authorization ------------------ @@ -97,6 +97,6 @@ Instead of phone numbers, Bots are authorized via their tokens which are created That's all, no further action is needed. The session file will be named after the Bot user_id, which is ``123456.session`` for the example above. -.. _installed: Installation.html +.. _installed Pyrogram: Installation.html .. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes .. _BotFather: https://t.me/botfather \ No newline at end of file From dab0a05f16641200c22e4368c9db9cc76c6bcdcb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:08:01 +0200 Subject: [PATCH 06/17] Move idle() and signal_handler() definitions near stop() --- pyrogram/client/client.py | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 5e6324fc..2cd31dc9 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -285,6 +285,28 @@ class Client(Methods, BaseClient): self.is_started = False self.session.stop() + def signal_handler(self, *args): + self.is_idle = False + + def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): + """Blocks the program execution until one of the signals are received, + then gently stop the Client by closing the underlying connection. + + Args: + stop_signals (``tuple``, *optional*): + Iterable containing signals the signal handler will listen to. + Defaults to (SIGINT, SIGTERM, SIGABRT). + """ + for s in stop_signals: + signal(s, self.signal_handler) + + self.is_idle = True + + while self.is_idle: + time.sleep(1) + + self.stop() + def add_handler(self, handler, group: int = 0): """Use this method to register an update handler. @@ -790,28 +812,6 @@ class Client(Methods, BaseClient): log.debug("{} stopped".format(name)) - def signal_handler(self, *args): - self.is_idle = False - - def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): - """Blocks the program execution until one of the signals are received, - then gently stop the Client by closing the underlying connection. - - Args: - stop_signals (``tuple``, *optional*): - Iterable containing signals the signal handler will listen to. - Defaults to (SIGINT, SIGTERM, SIGABRT). - """ - for s in stop_signals: - signal(s, self.signal_handler) - - self.is_idle = True - - while self.is_idle: - time.sleep(1) - - self.stop() - def send(self, data: Object): """Use this method to send Raw Function queries. From ffd67ed40839d82c133b6abc5529305385a74a4e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:08:27 +0200 Subject: [PATCH 07/17] Remove debug docstrings --- pyrogram/client/client.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2cd31dc9..f8309b88 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -169,15 +169,10 @@ class Client(Methods, BaseClient): self._proxy["enabled"] = True self._proxy.update(value) - def start(self, debug: bool = False): + def start(self): """Use this method to start the Client after creating it. Requires no parameters. - Args: - debug (``bool``, *optional*): - Enable or disable debug mode. When enabled, extra logging - lines will be printed out on your console. - Raises: :class:`Error ` """ From e3299bb3b7fd08b4224d1d2280c9922ecbd3d93f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:10:09 +0200 Subject: [PATCH 08/17] Add run() method --- pyrogram/client/client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index f8309b88..49b1c898 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -302,6 +302,16 @@ class Client(Methods, BaseClient): self.stop() + def run(self): + """Use this method to automatically :meth:`start` and :meth:`idle` a Client. + Requires no parameters. + + Raises: + :class:`Error ` + """ + self.start() + self.idle() + def add_handler(self, handler, group: int = 0): """Use this method to register an update handler. From 8748ff97ef1eb5d6c00f8816c114aa465b425f95 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:10:14 +0200 Subject: [PATCH 09/17] Update docs --- docs/source/resources/UpdateHandling.rst | 1 + docs/source/start/Usage.rst | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index 4373433b..e4db3574 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -6,6 +6,7 @@ and are handled by registering one or more callback functions with an Handler. T from, one for each kind of update: - `MessageHandler <../pyrogram/handlers/MessageHandler.html>`_ +- `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_ - `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_ - `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_ diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 7750db3f..2a213eb9 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -10,9 +10,9 @@ High-level API The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods_ and types_, which are named after the `Telegram Bot API`_. -.. hint:: If you can't find a method you want to use, chances are it's not implemented yet. In this case, you must use - the `Raw Functions`_. Meanwhile, feel free to join our Community_ if you're stuck or want to propose a - new method! +.. hint:: If you can't find an high-level method you want to use, chances are it's not implemented yet. + In this case, you must use the `Raw Functions`_. Meanwhile, feel free to join our Community_ if you get stuck + or want to propose a new method! Examples: @@ -39,7 +39,7 @@ Examples: Using Raw Functions ------------------- -If you can't find a high-level method for your needs or want complete, low-level access to the whole Telegram API, +If you can't find a high-level method for your needs or if want complete, low-level access to the whole Telegram API, you have to use the raw :mod:`functions ` and :mod:`types ` exposed by the ``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() ` method provided by the Client class. From c067b42bf273f15d8b1a793c63f636642d4ffd53 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:10:33 +0200 Subject: [PATCH 10/17] Add run() method to docs --- docs/source/pyrogram/Client.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 3e65b0f6..0448c3cb 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -17,6 +17,7 @@ Client start stop idle + run on_message on_callback_query on_raw_update From 82a0c965ba9a7193c202e2e156b365ed4e2717fd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:12:31 +0200 Subject: [PATCH 11/17] Don't make start and idle clickable --- pyrogram/client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 49b1c898..6db22fa4 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -303,7 +303,7 @@ class Client(Methods, BaseClient): self.stop() def run(self): - """Use this method to automatically :meth:`start` and :meth:`idle` a Client. + """Use this method to automatically start and idle a Client. Requires no parameters. Raises: From b8e6fc2e6a893cce3d81c10215d1dc462facd053 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:17:39 +0200 Subject: [PATCH 12/17] Update welcome example --- docs/source/index.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 61394d7b..414e47dd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -44,12 +44,11 @@ Welcome to Pyrogram @app.on_message(Filters.private) def hello(client, message): - client.send_message( - message.chat.id, "Hello {}".format(message.from_user.first_name)) + message.reply_text( + "Hello {}".format(message.from_user.first_name)) - app.start() - app.idle() + app.run() Welcome to Pyrogram's Documentation! Here you can find resources for learning how to use the library. Contents are organized by topic and can be accessed from the sidebar, or by following them one by one using the Next From 478f757689fe8b747b4de21846672b8cda9d8879 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:19:04 +0200 Subject: [PATCH 13/17] Update Setup page --- docs/source/start/Setup.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index e9105cde..8b7c0597 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -40,7 +40,7 @@ There are two ways to configure a Pyrogram application project, and you can choo from pyrogram import Client app = Client( - session_name="my_account", + "my_account", api_id=12345, api_hash="0123456789abcdef0123456789abcdef" ) @@ -61,7 +61,7 @@ the :class:`Client ` class by passing to it a ``session_name`` from pyrogram import Client app = Client("my_account") - app.start() + app.run() This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_) and the **phone code** you will receive: @@ -92,7 +92,7 @@ Instead of phone numbers, Bots are authorized via their tokens which are created from pyrogram import Client app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") - app.start() + app.run() That's all, no further action is needed. The session file will be named after the Bot user_id, which is ``123456.session`` for the example above. From fa65abf2763aa6c49932e92c9796f3053a88a6a5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:27:43 +0200 Subject: [PATCH 14/17] Update Usage page --- docs/source/start/Usage.rst | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 2a213eb9..d9cb8fe1 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -14,7 +14,7 @@ named after the `Telegram Bot API`_. In this case, you must use the `Raw Functions`_. Meanwhile, feel free to join our Community_ if you get stuck or want to propose a new method! -Examples: +Examples (more on `GitHub `_): - Get information about the authorized user: @@ -49,15 +49,17 @@ method provided by the Client class. re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API. If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_! -Examples: +Examples (more on `GitHub `_): - Update first name, last name and bio: .. code-block:: python + from pyrogram import Client from pyrogram.api import functions - ... + app = Client("my_account") + app.start() app.send( functions.account.UpdateProfile( @@ -66,13 +68,17 @@ Examples: ) ) + app.stop() + - Share your Last Seen time only with your contacts: .. code-block:: python + from pyrogram import Client from pyrogram.api import functions, types - ... + app = Client("my_account") + app.start() app.send( functions.account.SetPrivacy( @@ -81,13 +87,17 @@ Examples: ) ) + app.stop() + - Invite users to your channel/supergroup: .. code-block:: python + from pyrogram import Client from pyrogram.api import functions, types - ... + app = Client("my_account") + app.start() app.send( functions.channels.InviteToChannel( @@ -100,6 +110,8 @@ Examples: ) ) + app.stop() + .. _methods: ../pyrogram/Client.html#available-methods .. _plenty of them: ../pyrogram/Client.html#available-methods .. _types: ../pyrogram/types/index.html From 142a27f52ac910d8a5afed247c6da493c64c3993 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:30:18 +0200 Subject: [PATCH 15/17] Use app.run() in the examples --- examples/callback_query_handler.py | 3 +-- examples/echo_bot.py | 3 +-- examples/get_history.py | 4 ++-- examples/get_participants.py | 4 ++-- examples/get_participants2.py | 5 ++--- examples/raw_update_handler.py | 3 +-- examples/welcome_bot.py | 3 +-- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/callback_query_handler.py b/examples/callback_query_handler.py index 6b76edd8..999c2686 100644 --- a/examples/callback_query_handler.py +++ b/examples/callback_query_handler.py @@ -34,5 +34,4 @@ def answer(client, callback_query): ) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/echo_bot.py b/examples/echo_bot.py index ed2d4df5..adda52c7 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -36,5 +36,4 @@ def echo(client, message): ) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/get_history.py b/examples/get_history.py index d53bed96..433d127c 100644 --- a/examples/get_history.py +++ b/examples/get_history.py @@ -24,12 +24,12 @@ from pyrogram.api.errors import FloodWait """This example shows how to retrieve the full message history of a chat""" app = Client("my_account") -app.start() - target = "me" # "me" refers to your own chat (Saved Messages) messages = [] # List that will contain all the messages of the target chat offset_id = 0 # ID of the last message of the chunk +app.start() + while True: try: m = app.get_history(target, offset_id=offset_id) diff --git a/examples/get_participants.py b/examples/get_participants.py index d10710ba..fd5257fb 100644 --- a/examples/get_participants.py +++ b/examples/get_participants.py @@ -28,13 +28,13 @@ Refer to get_participants2.py for more than 10.000 users. """ app = Client("my_account") -app.start() - target = "pyrogramchat" # Target channel/supergroup users = [] # List that will contain all the users of the target chat limit = 200 # Amount of users to retrieve for each API call offset = 0 # Offset starts at 0 +app.start() + while True: try: participants = app.send( diff --git a/examples/get_participants2.py b/examples/get_participants2.py index dfad315b..a70afb74 100644 --- a/examples/get_participants2.py +++ b/examples/get_participants2.py @@ -33,15 +33,14 @@ as some user names may not contain ascii letters at all. """ app = Client("my_account") -app.start() - target = "pyrogramchat" # Target channel/supergroup username or id users = {} # To ensure uniqueness, users will be stored in a dictionary with user_id as key limit = 200 # Amount of users to retrieve for each API call (200 is the maximum) - # "" + "0123456789" + "abcdefghijklmnopqrstuvwxyz" (as list) queries = [""] + [str(i) for i in range(10)] + list(ascii_lowercase) +app.start() + for q in queries: print("Searching for '{}'".format(q)) offset = 0 # For each query, offset restarts from 0 diff --git a/examples/raw_update_handler.py b/examples/raw_update_handler.py index eb417c24..c7195761 100644 --- a/examples/raw_update_handler.py +++ b/examples/raw_update_handler.py @@ -28,5 +28,4 @@ def raw(client, update, users, chats): print(update) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/welcome_bot.py b/examples/welcome_bot.py index 8e087728..5fd93293 100644 --- a/examples/welcome_bot.py +++ b/examples/welcome_bot.py @@ -49,5 +49,4 @@ def welcome(client, message): ) -app.start() -app.idle() +app.run() # Automatically start() and idle() From dd156e0f7abf968c069c090d2a19ef6a6462e7d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:32:55 +0200 Subject: [PATCH 16/17] Update UpdateHandling page --- docs/source/resources/UpdateHandling.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index e4db3574..ffa01be9 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -32,8 +32,7 @@ We shall examine the :obj:`MessageHandler `, which will print(message) - app.start() - app.idle() + app.run() - If you prefer not to use decorators, there is an alternative way for registering Handlers. This is useful, for example, when you want to keep your callback functions in separate files. @@ -51,8 +50,7 @@ We shall examine the :obj:`MessageHandler `, which will app.add_handler(MessageHandler(my_handler)) - app.start() - app.idle() + app.run() Using Filters ------------- From 1aa02cb63f63514a61300edabd188db711073d90 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:36:22 +0200 Subject: [PATCH 17/17] Update AutoAuthorization page --- docs/source/resources/AutoAuthorization.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/resources/AutoAuthorization.rst b/docs/source/resources/AutoAuthorization.rst index 46f0809d..73504f80 100644 --- a/docs/source/resources/AutoAuthorization.rst +++ b/docs/source/resources/AutoAuthorization.rst @@ -35,6 +35,7 @@ ask you to input the phone code manually. app.start() print(app.get_me()) + app.stop() Sign Up ------- @@ -61,4 +62,5 @@ Telegram account in case the phone number you passed is not registered yet. ) app.start() - print(app.get_me()) \ No newline at end of file + print(app.get_me()) + app.stop() \ No newline at end of file