Merge branch 'develop' into asyncio

# Conflicts:
#	pyrogram/__init__.py
#	pyrogram/client/methods/messages/send_document.py
#	pyrogram/client/methods/messages/send_video_note.py
This commit is contained in:
Dan 2018-09-19 17:54:53 +02:00
commit df8bc62fb3
17 changed files with 89 additions and 43 deletions

View File

@ -26,7 +26,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 81 on top of MTProto 2.0.
- **Updated** to the latest Telegram API version, currently Layer 82 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.
@ -78,14 +78,13 @@ Copyright & License
<h1 align="center">
<a href="https://github.com/pyrogram/pyrogram">
<div><img src="https://media.pyrogram.ml/images/icon.png" alt="Pyrogram Icon"></div>
<div><img src="https://media.pyrogram.ml/images/label.png" alt="Pyrogram Label"></div>
<div><img src="https://raw.githubusercontent.com/pyrogram/logos/master/logos/pyrogram_logo2.png" alt="Pyrogram Logo"></div>
</a>
</h1>
<p align="center">
<b>Telegram MTProto API Client Library for Python</b>
<br>
<a href="https://github.com/pyrogram/pyrogram/releases/latest">
Download
@ -100,25 +99,25 @@ Copyright & License
</a>
<br><br>
<a href="compiler/api/source/main_api.tl">
<img src="https://img.shields.io/badge/SCHEME-LAYER%2081-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
<img src="https://img.shields.io/badge/SCHEME-LAYER%2082-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
alt="Scheme Layer">
</a>
<a href="https://github.com/pyrogram/tgcrypto">
<img src="https://img.shields.io/badge/TGCRYPTO-V1.0.4-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
<img src="https://img.shields.io/badge/TGCRYPTO-V1.1.1-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
alt="TgCrypto">
</a>
</p>
.. |logo| image:: https://pyrogram.ml/images/logo.png
.. |logo| image:: https://raw.githubusercontent.com/pyrogram/logos/master/logos/pyrogram_logo2.png
:target: https://pyrogram.ml
:alt: Pyrogram
.. |description| replace:: **Telegram MTProto API Client Library for Python**
.. |scheme| image:: "https://img.shields.io/badge/SCHEME-LAYER%2081-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
.. |scheme| image:: "https://img.shields.io/badge/SCHEME-LAYER%2082-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
:target: compiler/api/source/main_api.tl
:alt: Scheme Layer
.. |tgcrypto| image:: "https://img.shields.io/badge/TGCRYPTO-V1.0.4-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
.. |tgcrypto| image:: "https://img.shields.io/badge/TGCRYPTO-V1.1.1-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
:target: https://github.com/pyrogram/tgcrypto
:alt: TgCrypto

View File

@ -0,0 +1,2 @@
id message
CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat
1 id message
2 CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat

View File

@ -5,8 +5,7 @@ Welcome to Pyrogram
<div align="center">
<a href="https://docs.pyrogram.ml">
<div><img src="https://media.pyrogram.ml/images/icon.png" alt="Pyrogram Icon"></div>
<div><img src="https://media.pyrogram.ml/images/label.png" alt="Pyrogram Label"></div>
<div><img src="_static/logo.png" alt="Pyrogram Logo"></div>
</a>
</div>
@ -26,11 +25,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://img.shields.io/badge/SCHEME-LAYER%2081-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
<img src="https://img.shields.io/badge/SCHEME-LAYER%2082-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
alt="Scheme Layer">
</a>
<a href="https://github.com/pyrogram/tgcrypto">
<img src="https://img.shields.io/badge/TGCRYPTO-V1.0.4-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
<img src="https://img.shields.io/badge/TGCRYPTO-V1.1.1-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
alt="TgCrypto">
</a>
</p>

View File

@ -57,10 +57,10 @@ Messages
edit_message_text
edit_message_caption
edit_message_reply_markup
edit_message_media
delete_messages
get_messages
get_history
get_dialogs
Chats
-----
@ -84,6 +84,8 @@ Chats
get_chat
get_chat_member
get_chat_members
get_chat_members_count
get_dialogs
Users
-----

View File

@ -45,7 +45,7 @@ If no error shows up you are good to go.
>>> import pyrogram
>>> pyrogram.__version__
'0.7.5'
'0.8.0'
.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto
.. _develop: http://github.com/pyrogram/pyrogram

View File

@ -183,6 +183,13 @@ class Client(Methods, BaseClient):
self.dispatcher = Dispatcher(self, workers)
def __enter__(self):
self.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()
@property
def proxy(self):
return self._proxy
@ -897,30 +904,18 @@ class Client(Methods, BaseClient):
"More info: https://docs.pyrogram.ml/start/ProjectSetup#configuration"
)
for option in {"app_version", "device_model", "system_version", "lang_code"}:
for option in ["app_version", "device_model", "system_version", "lang_code"]:
if getattr(self, option):
pass
else:
setattr(self, option, Client.APP_VERSION)
if parser.has_section("pyrogram"):
setattr(self, option, parser.get(
"pyrogram",
option,
fallback=getattr(Client, option.upper())
))
if self.lang_code:
pass
else:
self.lang_code = Client.LANG_CODE
if parser.has_section("pyrogram"):
self.lang_code = parser.get(
"pyrogram",
"lang_code",
fallback=Client.LANG_CODE
)
else:
setattr(self, option, getattr(Client, option.upper()))
if self._proxy:
self._proxy["enabled"] = True

View File

@ -32,7 +32,7 @@ class GetChatMembersCount(BaseClient):
On success, an integer is returned.
Raises:
:class:`Error <pyrogram.Error>
:class:`Error <pyrogram.Error>`
``ValueError``: If a chat_id belongs to user.
"""
peer = await self.resolve_peer(chat_id)

View File

@ -73,9 +73,10 @@ class SendAnimation(BaseClient):
Animation height.
thumb (``str``, *optional*):
Animation thumbnail.
Pass a file path as string to send an image that exists on your local machine.
Thumbnail should have 90 or less pixels of width and 90 or less pixels of height.
Thumbnail of the animation file sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
disable_notification (``bool``, *optional*):
Sends the message silently.

View File

@ -30,7 +30,7 @@ class SendDocument(BaseClient):
async def send_document(self,
chat_id: int or str,
document: str,
caption: str = "",
thumb: str = None,caption: str = "",
parse_mode: str = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
@ -51,6 +51,12 @@ class SendDocument(BaseClient):
pass an HTTP URL as a string for Telegram to get a file from the Internet, or
pass a file path as string to upload a new file that exists on your local machine.
thumb (``str``):
Thumbnail of the file sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Document caption, 0-200 characters.
@ -103,10 +109,12 @@ class SendDocument(BaseClient):
style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(document):
thumb = None if thumb is None else await self.save_file(thumb)
file = await self.save_file(document, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"),
file=file,
thumb=thumb,
attributes=[
types.DocumentAttributeFilename(os.path.basename(document))
]

View File

@ -32,7 +32,7 @@ class SendVideoNote(BaseClient):
video_note: str,
duration: int = 0,
length: int = 1,
disable_notification: bool = None,
thumb: str = None,disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
progress: callable = None,
@ -57,6 +57,12 @@ class SendVideoNote(BaseClient):
length (``int``, *optional*):
Video width and height.
thumb (``str``, *optional*):
Thumbnail of the video sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
disable_notification (``bool``, *optional*):
Sends the message silently.
Users will receive a notification with no sound.
@ -100,10 +106,12 @@ class SendVideoNote(BaseClient):
file = None
if os.path.exists(video_note):
thumb = None if thumb is None else await self.save_file(thumb)
file = await self.save_file(video_note, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"],
file=file,
thumb=thumb,
attributes=[
types.DocumentAttributeVideo(
round_message=True,

View File

@ -28,6 +28,12 @@ class InputMediaAnimation(InputMedia):
Pass a file_id as string to send a file that exists on the Telegram servers or
pass a file path as string to upload a new file that exists on your local machine.
thumb (``str``, *optional*):
Thumbnail of the animation file sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the animation to be sent, 0-200 characters
@ -48,6 +54,7 @@ class InputMediaAnimation(InputMedia):
def __init__(self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
width: int = 0,
@ -55,6 +62,7 @@ class InputMediaAnimation(InputMedia):
duration: int = 0):
super().__init__(media, caption, parse_mode)
self.thumb = thumb
self.width = width
self.height = height
self.duration = duration

View File

@ -29,6 +29,12 @@ class InputMediaAudio(InputMedia):
Pass a file_id as string to send an audio that exists on the Telegram servers or
pass a file path as string to upload a new audio that exists on your local machine.
thumb (``str``, *optional*):
Thumbnail of the music file album cover.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the audio to be sent, 0-200 characters
@ -49,6 +55,7 @@ class InputMediaAudio(InputMedia):
def __init__(self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
duration: int = 0,
@ -56,6 +63,7 @@ class InputMediaAudio(InputMedia):
title: str = ""):
super().__init__(media, caption, parse_mode)
self.thumb = thumb
self.duration = duration
self.performer = performer
self.title = title

View File

@ -28,6 +28,12 @@ class InputMediaDocument(InputMedia):
Pass a file_id as string to send a file that exists on the Telegram servers or
pass a file path as string to upload a new file that exists on your local machine.
thumb (``str``):
Thumbnail of the file sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the document to be sent, 0-200 characters
@ -39,6 +45,9 @@ class InputMediaDocument(InputMedia):
def __init__(self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = ""):
super().__init__(media, caption, parse_mode)
self.thumb = thumb

View File

@ -30,6 +30,12 @@ class InputMediaVideo(InputMedia):
pass a file path as string to upload a new video that exists on your local machine.
Sending video by a URL is currently unsupported.
thumb (``str``):
Thumbnail of the video sent.
The thumbnail should be in JPEG format and less than 200 KB in size.
A thumbnail's width and height should not exceed 90 pixels.
Thumbnails can't be reused and can be only uploaded as a new file.
caption (``str``, *optional*):
Caption of the video to be sent, 0-200 characters
@ -53,6 +59,7 @@ class InputMediaVideo(InputMedia):
def __init__(self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
width: int = 0,
@ -61,6 +68,7 @@ class InputMediaVideo(InputMedia):
supports_streaming: bool = True):
super().__init__(media, caption, parse_mode)
self.thumb = thumb
self.width = width
self.height = height
self.duration = duration

View File

@ -30,7 +30,7 @@ class Audio(Object):
Duration of the audio in seconds as defined by sender.
thumb (:obj:`PhotoSize <pyrogram.PhotoSize>`, *optional*):
Audio thumbnail.
Thumbnail of the music file album cover.
file_name (``str``, *optional*):
Audio file name.

View File

@ -27,22 +27,21 @@ try:
class AES:
# TODO: Use new tgcrypto function names
@classmethod
def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
return tgcrypto.ige_encrypt(data, key, iv)
return tgcrypto.ige256_encrypt(data, key, iv)
@classmethod
def ige256_decrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
return tgcrypto.ige_decrypt(data, key, iv)
return tgcrypto.ige256_decrypt(data, key, iv)
@staticmethod
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
return tgcrypto.ctr_encrypt(data, key, iv, state or bytearray(1))
return tgcrypto.ctr256_encrypt(data, key, iv, state or bytearray(1))
@staticmethod
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
return tgcrypto.ctr_decrypt(data, key, iv, state or bytearray(1))
return tgcrypto.ctr256_decrypt(data, key, iv, state or bytearray(1))
@staticmethod
def xor(a: bytes, b: bytes) -> bytes:

View File

@ -172,7 +172,7 @@ setup(
packages=find_packages(exclude=["compiler*"]),
zip_safe=False,
install_requires=read("requirements.txt"),
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
extras_require={"tgcrypto": ["tgcrypto==1.1.1"]},
cmdclass={
"clean": Clean,
"generate": Generate