mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
Merge branch 'develop' into asyncio
This commit is contained in:
commit
77c696aec0
12 changed files with 98 additions and 31 deletions
|
|
@ -77,7 +77,8 @@ def generate(source_path, base):
|
|||
|
||||
build(source_path)
|
||||
|
||||
for k, v in all_entities.items():
|
||||
for k, v in sorted(all_entities.items()):
|
||||
v = sorted(v)
|
||||
entities = []
|
||||
|
||||
for i in v:
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ Welcome to Pyrogram
|
|||
</a>
|
||||
<br><br>
|
||||
<a href="https://github.com/pyrogram/pyrogram/blob/master/compiler/api/source/main_api.tl">
|
||||
<img src="https://media.pyrogram.ml/images/scheme.svg"
|
||||
alt="Scheme Layer 75">
|
||||
<img src="https://img.shields.io/badge/SCHEME-LAYER%2081-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
|
||||
alt="Scheme Layer">
|
||||
</a>
|
||||
<a href="https://github.com/pyrogram/tgcrypto">
|
||||
<img src="https://media.pyrogram.ml/images/tgcrypto.svg"
|
||||
<img src="https://img.shields.io/badge/TGCRYPTO-V1.0.4-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
|
||||
alt="TgCrypto">
|
||||
</a>
|
||||
</p>
|
||||
|
|
@ -56,7 +56,7 @@ button at the end of each page. But first, here's a brief overview of what is th
|
|||
About
|
||||
-----
|
||||
|
||||
Pyrogram is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building
|
||||
**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building
|
||||
custom Telegram applications that interact with the MTProto API as both User and Bot.
|
||||
|
||||
Features
|
||||
|
|
@ -65,8 +65,8 @@ 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 76 running on MTProto 2.0.
|
||||
- **Documented**: Pyrogram API methods are documented and resemble the Telegram Bot API.
|
||||
- **Updated** to the latest Telegram API version, currently Layer 81 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.
|
||||
|
||||
To get started, press the Next button.
|
||||
|
|
@ -84,10 +84,11 @@ To get started, press the Next button.
|
|||
:caption: Resources
|
||||
|
||||
resources/UpdateHandling
|
||||
resources/SOCKS5Proxy
|
||||
resources/TgCrypto
|
||||
resources/AutoAuthorization
|
||||
resources/CustomizeSessions
|
||||
resources/TgCrypto
|
||||
resources/TextFormatting
|
||||
resources/SOCKS5Proxy
|
||||
resources/BotsInteraction
|
||||
resources/ErrorHandling
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ Client
|
|||
get_inline_bot_results
|
||||
send_inline_bot_result
|
||||
answer_callback_query
|
||||
request_callback_answer
|
||||
get_users
|
||||
get_chat
|
||||
get_messages
|
||||
|
|
|
|||
|
|
@ -28,8 +28,12 @@ Inline Bots
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
# Send the first result (bot_results.results[0]) to your own chat (Saved Messages)
|
||||
app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id)
|
||||
# Send the first result to your own chat
|
||||
app.send_inline_bot_result(
|
||||
"me",
|
||||
bot_results.query_id,
|
||||
bot_results.results[0].id
|
||||
)
|
||||
|
||||
.. figure:: https://i.imgur.com/wwxr7B7.png
|
||||
:width: 90%
|
||||
|
|
|
|||
66
docs/source/resources/CustomizeSessions.rst
Normal file
66
docs/source/resources/CustomizeSessions.rst
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
Customize Sessions
|
||||
==================
|
||||
|
||||
As you may probably know, Telegram allows Users (and Bots) having more than one session (authorizations) registered
|
||||
in the system at the same time.
|
||||
|
||||
Briefly explaining, sessions are simply new logins in your account. They can be reviewed in the settings of an official
|
||||
app (or by invoking `GetAuthorizations <../functions/account/GetAuthorizations.html>`_ with Pyrogram) and store some useful
|
||||
information about the client who generated them.
|
||||
|
||||
|
||||
.. figure:: https://i.imgur.com/lzGPCdZ.png
|
||||
:width: 70%
|
||||
:align: center
|
||||
|
||||
A Pyrogram session running on Linux, Python 3.6.
|
||||
|
||||
That's how a session looks like on the Android app, showing the three main pieces of information.
|
||||
|
||||
- ``app_version``: **Pyrogram 🔥 0.7.5**
|
||||
- ``device_model``: **CPython 3.6.5**
|
||||
- ``system_version``: **Linux 4.15.0-23-generic**
|
||||
|
||||
Set Custom Values
|
||||
-----------------
|
||||
|
||||
To set custom values, you can either make use of the ``config.ini`` file, this way:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[pyrogram]
|
||||
app_version = 1.2.3
|
||||
device_model = PC
|
||||
system_version = Linux
|
||||
|
||||
Or, pass the arguments directly in the Client's constructor.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
app = Client(
|
||||
"my_account",
|
||||
app_version="1.2.3",
|
||||
device_model="PC",
|
||||
system_version="Linux"
|
||||
)
|
||||
|
||||
Set Custom Languages
|
||||
--------------------
|
||||
|
||||
To tell Telegram in which language should speak to you (terms of service, bots, service messages, ...) you can
|
||||
set ``lang_code`` in `ISO 639-1 <https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>`_ standard (defaults to "en",
|
||||
English).
|
||||
|
||||
With the following code we make Telegram know we want it to speak in Italian (it):
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[pyrogram]
|
||||
lang_code = it
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
app = Client(
|
||||
"my_account",
|
||||
lang_code="it",
|
||||
)
|
||||
|
|
@ -9,6 +9,7 @@ from, one for each kind of update:
|
|||
- `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_
|
||||
- `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_
|
||||
- `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_
|
||||
- `DisconnectHandler <../pyrogram/handlers/DisconnectHandler.html>`_
|
||||
|
||||
Registering an Handler
|
||||
----------------------
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ User Authorization
|
|||
In order to use the API, Telegram requires that Users be authorized via their phone numbers.
|
||||
Pyrogram automatically manages this access, all you need to do is create an instance of
|
||||
the :class:`Client <pyrogram.Client>` class by passing to it a ``session_name`` of your choice
|
||||
(e.g.: "my_account") and call the :meth:`start() <pyrogram.Client.start>` method:
|
||||
(e.g.: "my_account") and call the :meth:`run() <pyrogram.Client.run>` method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ 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 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 (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_):
|
||||
|
||||
- Get information about the authorized user:
|
||||
|
|
@ -34,10 +30,8 @@ Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/exa
|
|||
|
||||
app.send_photo("me", "/home/dan/perla.jpg", "Cute!")
|
||||
|
||||
.. _using-raw-functions:
|
||||
|
||||
Using Raw Functions
|
||||
-------------------
|
||||
Raw Functions
|
||||
-------------
|
||||
|
||||
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 <pyrogram.api.functions>` and :mod:`types <pyrogram.api.types>` exposed by the
|
||||
|
|
@ -45,8 +39,10 @@ you have to use the raw :mod:`functions <pyrogram.api.functions>` and :mod:`type
|
|||
method provided by the Client class.
|
||||
|
||||
.. hint:: Every high-level method mentioned in the section above is built on top of these raw functions.
|
||||
|
||||
Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already
|
||||
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 (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_):
|
||||
|
|
|
|||
|
|
@ -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.7.5.dev5"
|
||||
__version__ = "0.7.5"
|
||||
|
||||
from .api.errors import Error
|
||||
from .client.types import (
|
||||
|
|
|
|||
|
|
@ -86,10 +86,6 @@ class Client(Methods, BaseClient):
|
|||
Operating System version. Defaults to *platform.system() + " " + platform.release()*
|
||||
This is an alternative way to set it if you don't want to use the *config.ini* file.
|
||||
|
||||
system_lang_code (``str``, *optional*):
|
||||
Code of the language used on the system, in ISO 639-1 standard. Defaults to "en".
|
||||
This is an alternative way to set it if you don't want to use the *config.ini* file.
|
||||
|
||||
lang_code (``str``, *optional*):
|
||||
Code of the language used on the client, in ISO 639-1 standard. Defaults to "en".
|
||||
This is an alternative way to set it if you don't want to use the *config.ini* file.
|
||||
|
|
@ -149,7 +145,6 @@ class Client(Methods, BaseClient):
|
|||
app_version: str = None,
|
||||
device_model: str = None,
|
||||
system_version: str = None,
|
||||
system_lang_code: str = None,
|
||||
lang_code: str = None,
|
||||
proxy: dict = None,
|
||||
test_mode: bool = False,
|
||||
|
|
@ -170,7 +165,6 @@ class Client(Methods, BaseClient):
|
|||
self.app_version = app_version
|
||||
self.device_model = device_model
|
||||
self.system_version = system_version
|
||||
self.system_lang_code = system_lang_code
|
||||
self.lang_code = lang_code
|
||||
# TODO: Make code consistent, use underscore for private/protected fields
|
||||
self._proxy = proxy
|
||||
|
|
@ -595,6 +589,8 @@ class Client(Methods, BaseClient):
|
|||
self.password = None
|
||||
self.user_id = r.user.id
|
||||
|
||||
print("Login successful")
|
||||
|
||||
def fetch_peers(self, entities: list):
|
||||
for entity in entities:
|
||||
if isinstance(entity, types.User):
|
||||
|
|
@ -887,7 +883,7 @@ class Client(Methods, BaseClient):
|
|||
"More info: https://docs.pyrogram.ml/start/ProjectSetup#configuration"
|
||||
)
|
||||
|
||||
for option in {"app_version", "device_model", "system_version", "system_lang_code", "lang_code"}:
|
||||
for option in {"app_version", "device_model", "system_version", "lang_code"}:
|
||||
if getattr(self, option):
|
||||
pass
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -516,7 +516,8 @@ class Message(Object):
|
|||
|
||||
Raises:
|
||||
:class:`Error <pyrogram.Error>`
|
||||
``ValueError``: If the provided index or position is out of range or the button label was not found.
|
||||
``ValueError``: If the provided index or position is out of range or the button label was not found
|
||||
``TimeoutError``: If, after clicking an inline button, the bot fails to answer within 10 seconds
|
||||
"""
|
||||
if isinstance(self.reply_markup, ReplyKeyboardMarkup):
|
||||
if quote is None:
|
||||
|
|
@ -561,7 +562,7 @@ class Message(Object):
|
|||
return await self._client.request_callback_answer(
|
||||
chat_id=self.chat.id,
|
||||
message_id=self.message_id,
|
||||
data=button.callback_data
|
||||
callback_data=button.callback_data
|
||||
)
|
||||
elif button.url:
|
||||
return button.url
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ class Session:
|
|||
app_version=self.client.app_version,
|
||||
device_model=self.client.device_model,
|
||||
system_version=self.client.system_version,
|
||||
system_lang_code=self.client.system_lang_code,
|
||||
system_lang_code=self.client.lang_code,
|
||||
lang_code=self.client.lang_code,
|
||||
lang_pack="",
|
||||
query=functions.help.GetConfig(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue