diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index c1a02761..c0a5da73 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -79,4 +79,5 @@ BOTS_TOO_MUCH The chat has too many bots USER_ADMIN_INVALID The action requires admin privileges INPUT_USER_DEACTIVATED The target user has been deactivated PASSWORD_RECOVERY_NA The password recovery e-mail is not available -PASSWORD_EMPTY The password entered is empty \ No newline at end of file +PASSWORD_EMPTY The password entered is empty +PHONE_NUMBER_FLOOD This number has tried to login too many times \ No newline at end of file diff --git a/docs/source/errors/Forbidden.rst b/docs/source/errors/Forbidden.rst new file mode 100644 index 00000000..fd2e08ce --- /dev/null +++ b/docs/source/errors/Forbidden.rst @@ -0,0 +1,8 @@ +Forbidden +========= + +.. module:: pyrogram.api.errors.Forbidden + +.. automodule:: pyrogram.api.errors.exceptions.forbidden_403 + :members: + :show-inheritance: diff --git a/docs/source/errors/NotAcceptable.rst b/docs/source/errors/NotAcceptable.rst new file mode 100644 index 00000000..66ebaf72 --- /dev/null +++ b/docs/source/errors/NotAcceptable.rst @@ -0,0 +1,8 @@ +Not Acceptable +============== + +.. module:: pyrogram.api.errors.NotAcceptable + +.. automodule:: pyrogram.api.errors.exceptions.not_acceptable_406 + :members: + :show-inheritance: diff --git a/docs/source/index.rst b/docs/source/index.rst index c6ff71b8..8234374c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -25,7 +25,7 @@ Welcome to Pyrogram
- Scheme Layer @@ -64,7 +64,7 @@ Features - **Easy to use**: You can easily install Pyrogram using pip and start building your app right away. - **High-level**: The low-level details of MTProto are abstracted and automatically handled. - **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C. -- **Updated** to the latest Telegram API version, currently Layer 82 on top of MTProto 2.0. +- **Updated** to the latest Telegram API version, currently Layer 91 on top of MTProto 2.0. - **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API. - **Full API**, allowing to execute any advanced action an official client is able to do, and more. @@ -92,6 +92,8 @@ To get started, press the Next button. resources/SOCKS5Proxy resources/BotsInteraction resources/ErrorHandling + resources/TestServers + resources/Changelog .. toctree:: :hidden: diff --git a/docs/source/pyrogram/Error.rst b/docs/source/pyrogram/Error.rst index b5474e73..2ec1159d 100644 --- a/docs/source/pyrogram/Error.rst +++ b/docs/source/pyrogram/Error.rst @@ -9,6 +9,8 @@ Error ../errors/SeeOther ../errors/BadRequest ../errors/Unauthorized + ../errors/Forbidden + ../errors/NotAcceptable ../errors/Flood ../errors/InternalServerError ../errors/UnknownError diff --git a/docs/source/resources/Changelog.rst b/docs/source/resources/Changelog.rst new file mode 100644 index 00000000..732a1311 --- /dev/null +++ b/docs/source/resources/Changelog.rst @@ -0,0 +1,11 @@ +Changelog +========= + +Currently, all Pyrogram release notes live inside the GitHub repository web page: +https://github.com/pyrogram/pyrogram/releases + +(You will be automatically redirected in 10 seconds.) + +.. raw:: html + + \ No newline at end of file diff --git a/docs/source/resources/ErrorHandling.rst b/docs/source/resources/ErrorHandling.rst index 0d5cf6f9..f2a77b7a 100644 --- a/docs/source/resources/ErrorHandling.rst +++ b/docs/source/resources/ErrorHandling.rst @@ -1,15 +1,16 @@ Error Handling ============== -Errors are inevitable when working with the API, and they must be correctly handled by -the use of ``try..except`` blocks. +Errors are inevitable when working with the API, and they must be correctly handled with ``try..except`` blocks. -There are many errors that Telegram could return, but they all fall in one of these five exception categories +There are many errors that Telegram could return, but they all fall in one of these categories (which are in turn children of the :obj:`pyrogram.Error` superclass) - :obj:`303 See Other ` - :obj:`400 Bad Request ` - :obj:`401 Unauthorized ` +- :obj:`403 Forbidden ` +- :obj:`406 Not Acceptable ` - :obj:`420 Flood ` - :obj:`500 Internal Server Error ` @@ -56,5 +57,3 @@ before you can try again. The value is always stored in the ``x`` field of the r ... except FloodWait as e: time.sleep(e.x) - -**TODO: Better explanation on how to deal with exceptions** \ No newline at end of file diff --git a/docs/source/resources/TestServers.rst b/docs/source/resources/TestServers.rst new file mode 100644 index 00000000..2f82f24c --- /dev/null +++ b/docs/source/resources/TestServers.rst @@ -0,0 +1,39 @@ +Test Servers +============ + +If you wish to test your application in a separate environment, Pyrogram is able to authorize your account into +Telegram's test servers without hassle. All you need to do is start a new session (e.g.: "my_account_test") using +``test_mode=True``: + +.. code-block:: python + + from pyrogram import Client + + with Client("my_account_test", test_mode=True) as app: + print(app.get_me()) + +.. note:: + + If this is the first time you login into test servers, you will be asked to register your account first. + Don't worry about your contacts and chats, they will be kept untouched inside the production environment; + accounts authorized on test servers reside in a different, parallel instance of a Telegram database. + +Test Mode in Official Apps +-------------------------- + +You can also login yourself into test servers using official desktop apps, such as Webogram and TDesktop: + +- **Webogram**: Login here: https://web.telegram.org/?test=1 +- **TDesktop**: Open settings and type ``testmode``. + +Test Numbers +------------ + +Beside normal numbers, the test environment allows you to login with reserved test numbers. +Valid phone numbers follow the pattern ``99966XYYYY``, where ``X`` is the DC number (1 to 3) and ``YYYY`` are random +numbers. Users with such numbers always get ``XXXXX`` as the confirmation code (the DC number, repeated five times). + +.. important:: + + Do not store any important or private information in such test users' accounts; anyone can make use of the + simplified authorization mechanism and login at any time. diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 7c5c8d88..96249768 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -31,7 +31,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès "pyrogram.Dialogs": """Use this method to get the user's dialogs @@ -31,13 +31,13 @@ class GetDialogs(BaseClient): You can get up to 100 dialogs at once. Args: - offset_dialog (:obj:`Dialog`): - Sequential Dialog of the first dialog to be returned. - Defaults to None (start from the beginning). + offset_date (``int``): + The offset date in Unix time taken from the top message of a :obj:`Dialog`. + Defaults to 0. Valid for non-pinned dialogs only. limit (``str``, *optional*): Limits the number of dialogs to be retrieved. - Defaults to 100. + Defaults to 100. Valid for non-pinned dialogs only. pinned_only (``bool``, *optional*): Pass True if you want to get only pinned dialogs. @@ -55,7 +55,7 @@ class GetDialogs(BaseClient): else: r = await self.send( functions.messages.GetDialogs( - offset_date=offset_dialog.top_message.date if offset_dialog else 0, + offset_date=offset_date, offset_id=0, offset_peer=types.InputPeerEmpty(), limit=limit, diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index 46b70d28..3a18d306 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -26,10 +26,11 @@ from ...ext import BaseClient class GetHistory(BaseClient): async def get_history(self, chat_id: Union[int, str], - offset: int = 0, limit: int = 100, + offset: int = 0, offset_id: int = 0, - offset_date: int = 0): + offset_date: int = 0, + reversed: bool = False): """Use this method to retrieve the history of a chat. You can get up to 100 messages at once. @@ -40,20 +41,23 @@ class GetHistory(BaseClient): For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - offset (``int``, *optional*) - Sequential number of the first message to be returned. - Defaults to 0 (most recent message). - limit (``int``, *optional*): Limits the number of messages to be retrieved. By default, the first 100 messages are returned. + offset (``int``, *optional*) + Sequential number of the first message to be returned. Defaults to 0 (most recent message). + Negative values are also accepted and become useful in case you set offset_id or offset_date. + offset_id (``int``, *optional*): Pass a message identifier as offset to retrieve only older messages starting from that message. offset_date (``int``, *optional*): Pass a date in Unix time as offset to retrieve only older messages starting from that date. + reversed (``bool``, *optional*): + Pass True to retrieve the messages in reversed order (from older to most recent). + Returns: On success, a :obj:`Messages ` object is returned. @@ -61,14 +65,14 @@ class GetHistory(BaseClient): :class:`Error ` in case of a Telegram RPC error. """ - return await pyrogram.Messages._parse( + messages = await pyrogram.Messages._parse( self, await self.send( functions.messages.GetHistory( peer=await self.resolve_peer(chat_id), offset_id=offset_id, offset_date=offset_date, - add_offset=offset, + add_offset=offset - (limit if reversed else 0), limit=limit, max_id=0, min_id=0, @@ -76,3 +80,8 @@ class GetHistory(BaseClient): ) ) ) + + if reversed: + messages.messages.reverse() + + return messages