mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-18 05:30:15 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/__init__.py # pyrogram/client/methods/chats/get_dialogs.py # pyrogram/client/methods/messages/get_history.py
This commit is contained in:
commit
769b3ebdee
@ -80,3 +80,4 @@ 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
|
||||
PHONE_NUMBER_FLOOD This number has tried to login too many times
|
|
8
docs/source/errors/Forbidden.rst
Normal file
8
docs/source/errors/Forbidden.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Forbidden
|
||||
=========
|
||||
|
||||
.. module:: pyrogram.api.errors.Forbidden
|
||||
|
||||
.. automodule:: pyrogram.api.errors.exceptions.forbidden_403
|
||||
:members:
|
||||
:show-inheritance:
|
8
docs/source/errors/NotAcceptable.rst
Normal file
8
docs/source/errors/NotAcceptable.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Not Acceptable
|
||||
==============
|
||||
|
||||
.. module:: pyrogram.api.errors.NotAcceptable
|
||||
|
||||
.. automodule:: pyrogram.api.errors.exceptions.not_acceptable_406
|
||||
:members:
|
||||
:show-inheritance:
|
@ -25,7 +25,7 @@ Welcome to Pyrogram
|
||||
</a>
|
||||
<br>
|
||||
<a href="https://github.com/pyrogram/pyrogram/blob/master/compiler/api/source/main_api.tl">
|
||||
<img src="https://img.shields.io/badge/schema-layer%2082-eda738.svg?longCache=true&colorA=262b30"
|
||||
<img src="https://img.shields.io/badge/schema-layer%2091-eda738.svg?longCache=true&colorA=262b30"
|
||||
alt="Scheme Layer">
|
||||
</a>
|
||||
<a href="https://github.com/pyrogram/tgcrypto">
|
||||
@ -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:
|
||||
|
@ -9,6 +9,8 @@ Error
|
||||
../errors/SeeOther
|
||||
../errors/BadRequest
|
||||
../errors/Unauthorized
|
||||
../errors/Forbidden
|
||||
../errors/NotAcceptable
|
||||
../errors/Flood
|
||||
../errors/InternalServerError
|
||||
../errors/UnknownError
|
||||
|
11
docs/source/resources/Changelog.rst
Normal file
11
docs/source/resources/Changelog.rst
Normal file
@ -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
|
||||
|
||||
<meta http-equiv="refresh" content="10; URL=https://github.com/pyrogram/pyrogram/releases"/>
|
@ -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 <pyrogram.api.errors.SeeOther>`
|
||||
- :obj:`400 Bad Request <pyrogram.api.errors.BadRequest>`
|
||||
- :obj:`401 Unauthorized <pyrogram.api.errors.Unauthorized>`
|
||||
- :obj:`403 Forbidden <pyrogram.api.errors.Forbidden>`
|
||||
- :obj:`406 Not Acceptable <pyrogram.api.errors.NotAcceptable>`
|
||||
- :obj:`420 Flood <pyrogram.api.errors.Flood>`
|
||||
- :obj:`500 Internal Server Error <pyrogram.api.errors.InternalServerError>`
|
||||
|
||||
@ -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**
|
39
docs/source/resources/TestServers.rst
Normal file
39
docs/source/resources/TestServers.rst
Normal file
@ -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.
|
@ -31,7 +31,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance
|
||||
"e" if sys.getfilesystemencoding() != "utf-8" else "\xe8"
|
||||
)
|
||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||
__version__ = "0.9.4.asyncio"
|
||||
__version__ = "0.10.0.asyncio"
|
||||
|
||||
from .api.errors import Error
|
||||
from .client.types import (
|
||||
|
@ -23,7 +23,7 @@ from ...ext import BaseClient
|
||||
|
||||
class GetDialogs(BaseClient):
|
||||
async def get_dialogs(self,
|
||||
offset_dialog: "pyrogram.Dialog" = None,
|
||||
offset_date: int = 0,
|
||||
limit: int = 100,
|
||||
pinned_only: bool = False) -> "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,
|
||||
|
@ -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 <pyrogram.Messages>` object is returned.
|
||||
|
||||
@ -61,14 +65,14 @@ class GetHistory(BaseClient):
|
||||
:class:`Error <pyrogram.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
|
||||
|
Loading…
Reference in New Issue
Block a user