From 8ac48c555c027f76978c5339b19be48f48518aa5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:34:56 +0200 Subject: [PATCH 001/249] Add ipv6 data center addresses --- pyrogram/session/internals/data_center.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index 232ca13b..154cd9e0 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -34,5 +34,24 @@ class DataCenter: 121: "95.213.217.195" } - def __new__(cls, dc_id: int, test_mode: bool): - return (cls.TEST[dc_id], 80) if test_mode else (cls.PROD[dc_id], 443) + TEST_IPV6 = { + 1: "2001:0b28:f23d:f001:0000:0000:0000:000e", + 2: "2001:067c:04e8:f002:0000:0000:0000:000e", + 3: "2001:0b28:f23d:f003:0000:0000:0000:000e", + 121: "2a03:b0c0:0003:00d0:0000:0000:0114:d001" + } + + PROD_IPV6 = { + 1: "2001:0b28:f23d:f001:0000:0000:0000:000a", + 2: "2001:067c:04e8:f002:0000:0000:0000:000a", + 3: "2001:0b28:f23d:f003:0000:0000:0000:000a", + 4: "2001:067c:04e8:f004:0000:0000:0000:000a", + 5: "2001:0b28:f23f:f005:0000:0000:0000:000a", + 121: "2a03:b0c0:0003:00d0:0000:0000:0114:d001" + } + + def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool): + if ipv6: + return (cls.TEST_IPV6[dc_id], 80) if test_mode else (cls.PROD_IPV6[dc_id], 443) + else: + return (cls.TEST[dc_id], 80) if test_mode else (cls.PROD[dc_id], 443) From efe26bcb196f4fe6a9a6c4db385d48eba47c6593 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:35:41 +0200 Subject: [PATCH 002/249] Allow Connection to connect to ipv6 addresses --- pyrogram/connection/connection.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index a53295ce..043f7cb7 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -21,6 +21,7 @@ import threading import time from .transport import * +from ..session.internals import DataCenter log = logging.getLogger(__name__) @@ -36,16 +37,18 @@ class Connection: 4: TCPIntermediateO } - def __init__(self, address: tuple, proxy: dict, mode: int = 1): - self.address = address + def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, mode: int = 1): + self.ipv6 = ipv6 self.proxy = proxy + self.address = DataCenter(dc_id, test_mode, ipv6) self.mode = self.MODES.get(mode, TCPAbridged) + self.lock = threading.Lock() self.connection = None def connect(self): for i in range(Connection.MAX_RETRIES): - self.connection = self.mode(self.proxy) + self.connection = self.mode(self.ipv6, self.proxy) try: log.info("Connecting...") From 56748ff39075b41c427987127f975a9d672ee999 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:36:26 +0200 Subject: [PATCH 003/249] Make the underlying TCP protocol accept ipv6 addresses --- pyrogram/connection/transport/tcp/tcp.py | 5 +++-- pyrogram/connection/transport/tcp/tcp_abridged.py | 4 ++-- pyrogram/connection/transport/tcp/tcp_abridged_o.py | 5 +++-- pyrogram/connection/transport/tcp/tcp_full.py | 5 +++-- pyrogram/connection/transport/tcp/tcp_intermediate.py | 4 ++-- pyrogram/connection/transport/tcp/tcp_intermediate_o.py | 5 +++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 5df8aacb..8560604f 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -33,8 +33,9 @@ log = logging.getLogger(__name__) class TCP(socks.socksocket): - def __init__(self, proxy: dict): - super().__init__() + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(family=socket.AF_INET6 if ipv6 else socket.AF_INET) + self.settimeout(10) self.proxy_enabled = proxy.get("enabled", False) diff --git a/pyrogram/connection/transport/tcp/tcp_abridged.py b/pyrogram/connection/transport/tcp/tcp_abridged.py index 472f4799..d89421f5 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged.py @@ -24,8 +24,8 @@ log = logging.getLogger(__name__) class TCPAbridged(TCP): - def __init__(self, proxy: dict): - super().__init__(proxy) + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(ipv6, proxy) def connect(self, address: tuple): super().connect(address) diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py index bba88e34..57cc0336 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py @@ -28,8 +28,9 @@ log = logging.getLogger(__name__) class TCPAbridgedO(TCP): RESERVED = (b"HEAD", b"POST", b"GET ", b"OPTI", b"\xee" * 4) - def __init__(self, proxy: dict): - super().__init__(proxy) + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(ipv6, proxy) + self.encrypt = None self.decrypt = None diff --git a/pyrogram/connection/transport/tcp/tcp_full.py b/pyrogram/connection/transport/tcp/tcp_full.py index 1b131678..0aac1a14 100644 --- a/pyrogram/connection/transport/tcp/tcp_full.py +++ b/pyrogram/connection/transport/tcp/tcp_full.py @@ -26,8 +26,9 @@ log = logging.getLogger(__name__) class TCPFull(TCP): - def __init__(self, proxy: dict): - super().__init__(proxy) + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(ipv6, proxy) + self.seq_no = None def connect(self, address: tuple): diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate.py b/pyrogram/connection/transport/tcp/tcp_intermediate.py index 4b2e2596..b33fe466 100644 --- a/pyrogram/connection/transport/tcp/tcp_intermediate.py +++ b/pyrogram/connection/transport/tcp/tcp_intermediate.py @@ -25,8 +25,8 @@ log = logging.getLogger(__name__) class TCPIntermediate(TCP): - def __init__(self, proxy: dict): - super().__init__(proxy) + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(ipv6, proxy) def connect(self, address: tuple): super().connect(address) diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py index df79352a..e8c96ebc 100644 --- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py +++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py @@ -29,8 +29,9 @@ log = logging.getLogger(__name__) class TCPIntermediateO(TCP): RESERVED = (b"HEAD", b"POST", b"GET ", b"OPTI", b"\xee" * 4) - def __init__(self, proxy: dict): - super().__init__(proxy) + def __init__(self, ipv6: bool, proxy: dict): + super().__init__(ipv6, proxy) + self.encrypt = None self.decrypt = None From c9469ed5428ed0a6495a986a9f9afd26b214001a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:37:12 +0200 Subject: [PATCH 004/249] Allow auth to use ipv6 --- pyrogram/session/auth.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 80956187..2142be59 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -26,7 +26,7 @@ from pyrogram.api import functions, types from pyrogram.api.core import Object, Long, Int from pyrogram.connection import Connection from pyrogram.crypto import AES, RSA, Prime -from .internals import MsgId, DataCenter +from .internals import MsgId log = logging.getLogger(__name__) @@ -46,9 +46,10 @@ class Auth: 16 ) - def __init__(self, dc_id: int, test_mode: bool, proxy: dict): + def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict): self.dc_id = dc_id self.test_mode = test_mode + self.ipv6 = ipv6 self.proxy = proxy self.connection = None @@ -84,7 +85,7 @@ class Auth: # The server may close the connection at any time, causing the auth key creation to fail. # If that happens, just try again up to MAX_RETRIES times. while True: - self.connection = Connection(DataCenter(self.dc_id, self.test_mode), self.proxy) + self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy) try: log.info("Start creating a new auth key on DC{}".format(self.dc_id)) From b804709c6c6a88f7b95d3db62c2a231ec7c9591d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:37:35 +0200 Subject: [PATCH 005/249] Allow session to use ipv6 --- pyrogram/session/session.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 7e90cfff..82751f21 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -35,7 +35,7 @@ from pyrogram.api.core import Message, Object, MsgContainer, Long, FutureSalt, I from pyrogram.api.errors import Error, InternalServerError from pyrogram.connection import Connection from pyrogram.crypto import AES, KDF -from .internals import MsgId, MsgFactory, DataCenter +from .internals import MsgId, MsgFactory log = logging.getLogger(__name__) @@ -86,6 +86,7 @@ class Session: def __init__(self, dc_id: int, test_mode: bool, + ipv6: bool, proxy: dict, auth_key: bytes, api_id: int, @@ -98,6 +99,7 @@ class Session: self.dc_id = dc_id self.test_mode = test_mode + self.ipv6 = ipv6 self.proxy = proxy self.api_id = api_id self.is_cdn = is_cdn @@ -130,7 +132,7 @@ class Session: def start(self): while True: - self.connection = Connection(DataCenter(self.dc_id, self.test_mode), self.proxy) + self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy) try: self.connection.connect() From ade1c2f377902c3c2b6c1f4e406bc21a3acd7e4f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:38:14 +0200 Subject: [PATCH 006/249] Accommodate ipv6 in the Client class --- pyrogram/client/client.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 73f45966..65490a55 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -129,6 +129,7 @@ class Client(Methods, BaseClient): session_name: str, api_id: int or str = None, api_hash: str = None, + ipv6: bool = False, proxy: dict = None, test_mode: bool = False, phone_number: str = None, @@ -145,6 +146,7 @@ class Client(Methods, BaseClient): self.session_name = session_name self.api_id = int(api_id) if api_id else None self.api_hash = api_hash + self.ipv6 = ipv6 # TODO: Make code consistent, use underscore for private/protected fields self._proxy = proxy self.test_mode = test_mode @@ -194,6 +196,7 @@ class Client(Methods, BaseClient): self.session = Session( self.dc_id, self.test_mode, + self.ipv6, self._proxy, self.auth_key, self.api_id, @@ -342,11 +345,12 @@ class Client(Methods, BaseClient): self.session.stop() self.dc_id = e.x - self.auth_key = Auth(self.dc_id, self.test_mode, self._proxy).create() + self.auth_key = Auth(self.dc_id, self.test_mode, self.ipv6, self._proxy).create() self.session = Session( self.dc_id, self.test_mode, + self.ipv6, self._proxy, self.auth_key, self.api_id, @@ -390,11 +394,12 @@ class Client(Methods, BaseClient): self.session.stop() self.dc_id = e.x - self.auth_key = Auth(self.dc_id, self.test_mode, self._proxy).create() + self.auth_key = Auth(self.dc_id, self.test_mode, self.ipv6, self._proxy).create() self.session = Session( self.dc_id, self.test_mode, + self.ipv6, self._proxy, self.auth_key, self.api_id, @@ -871,7 +876,7 @@ class Client(Methods, BaseClient): except FileNotFoundError: self.dc_id = 1 self.date = 0 - self.auth_key = Auth(self.dc_id, self.test_mode, self._proxy).create() + self.auth_key = Auth(self.dc_id, self.test_mode, self.ipv6, self._proxy).create() else: self.dc_id = s["dc_id"] self.test_mode = s["test_mode"] @@ -1022,7 +1027,7 @@ class Client(Methods, BaseClient): file_id = file_id or self.rnd_id() md5_sum = md5() if not is_big and not is_missing_part else None - session = Session(self.dc_id, self.test_mode, self._proxy, self.auth_key, self.api_id) + session = Session(self.dc_id, self.test_mode, self.ipv6, self._proxy, self.auth_key, self.api_id) session.start() try: @@ -1108,8 +1113,9 @@ class Client(Methods, BaseClient): session = Session( dc_id, self.test_mode, + self.ipv6, self._proxy, - Auth(dc_id, self.test_mode, self._proxy).create(), + Auth(dc_id, self.test_mode, self.ipv6, self._proxy).create(), self.api_id ) @@ -1127,6 +1133,7 @@ class Client(Methods, BaseClient): session = Session( dc_id, self.test_mode, + self.ipv6, self._proxy, self.auth_key, self.api_id @@ -1197,8 +1204,9 @@ class Client(Methods, BaseClient): cdn_session = Session( r.dc_id, self.test_mode, + self.ipv6, self._proxy, - Auth(r.dc_id, self.test_mode, self._proxy).create(), + Auth(r.dc_id, self.test_mode, self.ipv6, self._proxy).create(), self.api_id, is_cdn=True ) From d38d23f46df7fb03aeefff9938c0b80e3000a065 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:39:06 +0200 Subject: [PATCH 007/249] Log in case connection fails (to test ipv6) --- pyrogram/connection/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 043f7cb7..ca9bd96c 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -53,7 +53,8 @@ class Connection: try: log.info("Connecting...") self.connection.connect(self.address) - except OSError: + except OSError as e: + log.warning(e) # TODO: Remove self.connection.close() time.sleep(1) else: From 321ee5e07d9d7e8357bdb6b6334a3c092a9e4ef4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 16:53:18 +0200 Subject: [PATCH 008/249] Add missing 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 0448c3cb..0000b35f 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -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 From 7d8ebdc0dd6fd51f461b60a5f95d73f0e4b66de5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:11:48 +0200 Subject: [PATCH 009/249] Add "406 Not Acceptable" error class --- compiler/error/source/406_NOT_ACCEPTABLE.tsv | 1 + 1 file changed, 1 insertion(+) create mode 100644 compiler/error/source/406_NOT_ACCEPTABLE.tsv diff --git a/compiler/error/source/406_NOT_ACCEPTABLE.tsv b/compiler/error/source/406_NOT_ACCEPTABLE.tsv new file mode 100644 index 00000000..d82f6e11 --- /dev/null +++ b/compiler/error/source/406_NOT_ACCEPTABLE.tsv @@ -0,0 +1 @@ +id message From 38b7abec3546603697094a22182ec374265c56b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:15:53 +0200 Subject: [PATCH 010/249] Add AUTH_KEY_DUPLICATED error --- compiler/error/source/406_NOT_ACCEPTABLE.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/error/source/406_NOT_ACCEPTABLE.tsv b/compiler/error/source/406_NOT_ACCEPTABLE.tsv index d82f6e11..3a88a7b6 100644 --- a/compiler/error/source/406_NOT_ACCEPTABLE.tsv +++ b/compiler/error/source/406_NOT_ACCEPTABLE.tsv @@ -1 +1,2 @@ id message +AUTH_KEY_DUPLICATED Authorization error. You must log out and log in again with your phone number. We apologize for the inconvenience. \ No newline at end of file From 6e4c608875885c7753af1862614255b120323865 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:16:12 +0200 Subject: [PATCH 011/249] Handle AUTH_KEY_DUPLICATED error --- pyrogram/session/session.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index ef7b565c..b7645b11 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -31,7 +31,7 @@ from pyrogram import __copyright__, __license__, __version__ from pyrogram.api import functions, types, core from pyrogram.api.all import layer from pyrogram.api.core import Message, Object, MsgContainer, Long, FutureSalt, Int -from pyrogram.api.errors import Error, InternalServerError +from pyrogram.api.errors import Error, InternalServerError, AuthKeyDuplicated from pyrogram.connection import Connection from pyrogram.crypto import AES, KDF from .internals import MsgId, MsgFactory, DataCenter @@ -157,6 +157,9 @@ class Session: self.ping_thread.start() log.info("Connection inited: Layer {}".format(layer)) + except AuthKeyDuplicated as e: + self.stop() + raise e except (OSError, TimeoutError, Error): self.stop() except Exception as e: From 0935c4837f2c9cf9f66b69c48ddea81f0d1a6d53 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:41:16 +0200 Subject: [PATCH 012/249] Fix ReplyKeyboardRemove id --- pyrogram/client/types/reply_markup/reply_keyboard_remove.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py index de32f740..3e2aebf5 100644 --- a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py +++ b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py @@ -35,7 +35,7 @@ class ReplyKeyboardRemove(Object): keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. """ - ID = 0xb0700002 + ID = 0xb0700023 def __init__(self, selective: bool = None): self.selective = selective From be451a3bb2d055101c5440786ae1680fb30bf307 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:49:09 +0200 Subject: [PATCH 013/249] Rename parse_photos to parse_profile_photos --- pyrogram/client/ext/utils.py | 2 +- pyrogram/client/methods/users/get_user_profile_photos.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 2913c38b..3d2f88c1 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -757,7 +757,7 @@ def get_offset_date(dialogs): return 0 -def parse_photos(photos): +def parse_profile_photos(photos): if isinstance(photos, types.photos.Photos): total_count = len(photos.photos) else: diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 42fb84bb..5613c21d 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -48,7 +48,7 @@ class GetUserProfilePhotos(BaseClient): Raises: :class:`Error ` """ - return utils.parse_photos( + return utils.parse_profile_photos( self.send( functions.photos.GetUserPhotos( user_id=self.resolve_peer(user_id), From 5f87bbc962d35e33e0faeba5c06a3c0f2bc6e916 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:04:45 +0200 Subject: [PATCH 014/249] Add the new Photo type --- compiler/api/compiler.py | 9 +++---- pyrogram/client/types/__init__.py | 1 + pyrogram/client/types/photo.py | 41 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 pyrogram/client/types/photo.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index d1bf8cfa..7c1412d1 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,17 +494,16 @@ def start(): f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") - f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") - f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") - f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",") f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",") f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",") f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",") - - f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\"") + f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") + f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") + f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n}\n") diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index acd001dd..84c12a44 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -31,6 +31,7 @@ from .location import Location from .message import Message from .message_entity import MessageEntity from .messages import Messages +from .photo import Photo from .photo_size import PhotoSize from .reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py new file mode 100644 index 00000000..39fb8d94 --- /dev/null +++ b/pyrogram/client/types/photo.py @@ -0,0 +1,41 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class Photo(Object): + """This object represents a Photo + + Args: + id (``str``): + Unique identifier for this photo. + + date (``int``): + Date the photo was sent in Unix time + + sizes (List of :obj:`PhotoSize ): + Available sizes of this photo + """ + + ID = 0xb0700027 + + def __init__(self, id: str, date: int, sizes: list): + self.id = id + self.date = date + self.sizes = sizes From 971299f59283278d296d365e2f125c5a9f97f58a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:08 +0200 Subject: [PATCH 015/249] PhotoSize won't store date info anymore --- pyrogram/client/types/photo_size.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/types/photo_size.py b/pyrogram/client/types/photo_size.py index 7e9b3cba..65691de0 100644 --- a/pyrogram/client/types/photo_size.py +++ b/pyrogram/client/types/photo_size.py @@ -32,18 +32,14 @@ class PhotoSize(Object): height (``int``): Photo height. - file_size (``int``, *optional*): + file_size (``int``): File size. - - date (``int``, *optional*): - Date the photo was sent in Unix time """ ID = 0xb0700005 - def __init__(self, file_id, width, height, file_size=None, date=None): - self.file_id = file_id # string - self.width = width # int - self.height = height # int - self.file_size = file_size # flags.0?int - self.date = date + def __init__(self, file_id: str, width: int, height: int, file_size: int): + self.file_id = file_id + self.width = width + self.height = height + self.file_size = file_size From fb10b3b0e7e767610a7774a7e933185c9046151e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:47 +0200 Subject: [PATCH 016/249] UserProfilePhoto.photos is now a list of Photo objects --- pyrogram/client/types/user_profile_photos.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/user_profile_photos.py b/pyrogram/client/types/user_profile_photos.py index 1b7ecbb4..c8ca9e39 100644 --- a/pyrogram/client/types/user_profile_photos.py +++ b/pyrogram/client/types/user_profile_photos.py @@ -26,12 +26,12 @@ class UserProfilePhotos(Object): total_count (``int``): Total number of profile pictures the target user has. - photos (List of List of :obj:`PhotoSize `): - Requested profile pictures (in up to 4 sizes each). + photos (List of :obj:`Photo `): + Requested profile pictures. """ ID = 0xb0700014 def __init__(self, total_count: int, photos: list): - self.total_count = total_count # int - self.photos = photos # Vector> + self.total_count = total_count + self.photos = photos From a3761144b37e24a0d1f956ea1d29e42c936f053a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:07:02 +0200 Subject: [PATCH 017/249] Use Photo as type for media messages --- pyrogram/client/ext/utils.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3d2f88c1..105d0f0c 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -329,13 +329,23 @@ def parse_messages( ), width=size.w, height=size.h, - file_size=file_size, - date=photo.date + file_size=file_size ) photo_sizes.append(photo_size) - photo = photo_sizes + photo = pyrogram_types.Photo( + id=b64encode( + pack( + " Date: Thu, 28 Jun 2018 19:14:29 +0200 Subject: [PATCH 022/249] Add Photo type to docs --- docs/source/pyrogram/types/Photo.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/source/pyrogram/types/Photo.rst diff --git a/docs/source/pyrogram/types/Photo.rst b/docs/source/pyrogram/types/Photo.rst new file mode 100644 index 00000000..78fe13f4 --- /dev/null +++ b/docs/source/pyrogram/types/Photo.rst @@ -0,0 +1,5 @@ +Photo +===== + +.. autoclass:: pyrogram.Photo + :members: From 30497b0e91635a9808904aeb846a14b70fa6e289 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:59:26 +0200 Subject: [PATCH 023/249] Add delete_profile_photos method --- pyrogram/client/methods/users/__init__.py | 2 + .../methods/users/delete_profile_photos.py | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 pyrogram/client/methods/users/delete_profile_photos.py diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index 7a82667d..f7c32b3b 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .delete_profile_photos import DeleteProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers @@ -23,6 +24,7 @@ from .get_users import GetUsers class Users( GetUserProfilePhotos, + DeleteProfilePhotos, GetUsers, GetMe ): diff --git a/pyrogram/client/methods/users/delete_profile_photos.py b/pyrogram/client/methods/users/delete_profile_photos.py new file mode 100644 index 00000000..47a6682a --- /dev/null +++ b/pyrogram/client/methods/users/delete_profile_photos.py @@ -0,0 +1,58 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from base64 import b64decode +from struct import unpack + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class DeleteProfilePhotos(BaseClient): + def delete_profile_photos(self, id: str or list): + """Use this method to delete your own profile photos + + Args: + id (``str`` | ``list``): + A single :obj:`Photo ` id as string or multiple ids as list of strings for deleting + more than one photos at once. + + Returns: + True on success. + + Raises: + :class:`Error ` + """ + id = id if isinstance(id, list) else [id] + input_photos = [] + + for i in id: + s = unpack(" Date: Thu, 28 Jun 2018 19:59:53 +0200 Subject: [PATCH 024/249] Add delete_profile_photos 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 0000b35f..2fbd5879 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -42,6 +42,7 @@ Client send_chat_action download_media get_user_profile_photos + delete_profile_photos edit_message_text edit_message_caption edit_message_reply_markup From 29d45be0a5681445c42b34bb264f2f11ea24f10d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:00:48 +0200 Subject: [PATCH 025/249] Add Photo to types list --- docs/source/pyrogram/types/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index 2fc74e49..ff3de94e 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -9,6 +9,7 @@ Types Message MessageEntity Messages + Photo PhotoSize Audio Document From bae7b4c85127a6d8d0caf963c441912d1140cdd8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:02:31 +0200 Subject: [PATCH 026/249] Make Photo importable from the top level package --- pyrogram/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 96fb4a76..16204830 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,8 +29,8 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, - VideoNote, Voice, CallbackQuery, Messages + Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, + Video, VideoNote, Voice, CallbackQuery, Messages ) from .client.types.reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, From b6206b7938431a24ed81aff35eced0643a44c26e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:03:50 +0200 Subject: [PATCH 027/249] Fix small docstring issue --- pyrogram/client/types/photo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py index 39fb8d94..f5494f13 100644 --- a/pyrogram/client/types/photo.py +++ b/pyrogram/client/types/photo.py @@ -29,7 +29,7 @@ class Photo(Object): date (``int``): Date the photo was sent in Unix time - sizes (List of :obj:`PhotoSize ): + sizes (List of :obj:`PhotoSize `): Available sizes of this photo """ From 6943e16636c04c0a31f1418caa7396a3a4b9a0d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:04:46 +0200 Subject: [PATCH 028/249] Change new_chat_photo type. It is now Photo --- pyrogram/client/types/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index b9048f1e..112bc0bf 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -132,7 +132,7 @@ class Message(Object): new_chat_title (``str``, *optional*): A chat title was changed to this value. - new_chat_photo (List of :obj:`PhotoSize `, *optional*): + new_chat_photo (:obj:`Photo `, *optional*): A chat photo was change to this value. delete_chat_photo (``bool``, *optional*): From 44442a842301069665c5d8af6e0b550687dfc6e8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 29 Jun 2018 01:12:08 +0200 Subject: [PATCH 029/249] Update API scheme to Layer 82 --- compiler/api/source/main_api.tl | 44 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index d1f2fa33..9ee01cb3 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -36,7 +36,7 @@ inputMediaEmpty#9664f57f = InputMedia; inputMediaUploadedPhoto#1e287d04 flags:# file:InputFile stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; inputMediaPhoto#b3ba0635 flags:# id:InputPhoto ttl_seconds:flags.0?int = InputMedia; inputMediaGeoPoint#f9c44144 geo_point:InputGeoPoint = InputMedia; -inputMediaContact#a6e45987 phone_number:string first_name:string last_name:string = InputMedia; +inputMediaContact#f8ab7dfb phone_number:string first_name:string last_name:string vcard:string = InputMedia; inputMediaUploadedDocument#5b38c6c1 flags:# nosound_video:flags.3?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; inputMediaDocument#23ab23d2 flags:# id:InputDocument ttl_seconds:flags.0?int = InputMedia; inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string = InputMedia; @@ -61,6 +61,7 @@ inputFileLocation#14637196 volume_id:long local_id:int secret:long = InputFileLo inputEncryptedFileLocation#f5235d55 id:long access_hash:long = InputFileLocation; inputDocumentFileLocation#430f0724 id:long access_hash:long version:int = InputFileLocation; inputSecureFileLocation#cbc7ee28 id:long access_hash:long = InputFileLocation; +inputTakeoutFileLocation#29be5899 = InputFileLocation; inputAppEvent#770656a8 time:double type:string peer:long data:string = InputAppEvent; @@ -121,7 +122,7 @@ messageService#9e19a1f6 flags:# out:flags.1?true mentioned:flags.4?true media_un messageMediaEmpty#3ded6320 = MessageMedia; messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia; messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; -messageMediaContact#5e7d2f39 phone_number:string first_name:string last_name:string user_id:int = MessageMedia; +messageMediaContact#cbf24940 phone_number:string first_name:string last_name:string vcard:string user_id:int = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; messageMediaDocument#9cb070d7 flags:# document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; @@ -153,7 +154,7 @@ messageActionBotAllowed#abe9affe domain:string = MessageAction; messageActionSecureValuesSentMe#1b287353 values:Vector credentials:SecureCredentialsEncrypted = MessageAction; messageActionSecureValuesSent#d95c6154 types:Vector = MessageAction; -dialog#e4def5db flags:# pinned:flags.2?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; +dialog#e4def5db flags:# pinned:flags.2?true unread_mark:flags.3?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; photoEmpty#2331b22d id:long = Photo; photo#9288dd29 flags:# has_stickers:flags.0?true id:long access_hash:long date:int sizes:Vector = Photo; @@ -163,7 +164,7 @@ photoSize#77bfb61b type:string location:FileLocation w:int h:int size:int = Phot photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize; geoPointEmpty#1117dd5f = GeoPoint; -geoPoint#2049d70c long:double lat:double = GeoPoint; +geoPoint#296f104 long:double lat:double access_hash:long = GeoPoint; auth.checkedPhone#811ea28e phone_registered:Bool = auth.CheckedPhone; @@ -213,6 +214,7 @@ contacts.blockedSlice#900802a1 count:int blocked:Vector users:Ve messages.dialogs#15ba6c40 dialogs:Vector messages:Vector chats:Vector users:Vector = messages.Dialogs; messages.dialogsSlice#71e094f3 count:int dialogs:Vector messages:Vector chats:Vector users:Vector = messages.Dialogs; +messages.dialogsNotModified#f0e3e596 count:int = messages.Dialogs; messages.messages#8c718e87 messages:Vector chats:Vector users:Vector = messages.Messages; messages.messagesSlice#b446ae3 count:int messages:Vector chats:Vector users:Vector = messages.Messages; @@ -309,6 +311,7 @@ updateFavedStickers#e511996d = Update; updateChannelReadMessagesContents#89893b45 channel_id:int messages:Vector = Update; updateContactsReset#7084a7be = Update; updateChannelAvailableMessages#70db6837 channel_id:int available_min_id:int = Update; +updateDialogUnreadMark#e16459c3 flags:# unread:flags.0?true peer:DialogPeer = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -335,7 +338,7 @@ upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; -config#eb7bb160 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; +config#3213dbba flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector dc_txt_domain_name:string chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string gif_search_username:flags.9?string venue_search_username:flags.10?string img_search_username:flags.11?string static_maps_provider:flags.12?string caption_length_max:int message_length_max:int webfile_dc_id:int suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc; @@ -562,7 +565,7 @@ inputBotInlineMessageMediaAuto#3380c786 flags:# message:string entities:flags.1? inputBotInlineMessageText#3dcd7a87 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaGeo#c1b15d65 flags:# geo_point:InputGeoPoint period:int reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaVenue#417bbf11 flags:# geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; -inputBotInlineMessageMediaContact#2daf01a7 flags:# phone_number:string first_name:string last_name:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; +inputBotInlineMessageMediaContact#a6edbffd flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageGame#4b425864 flags:# reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineResult#88bf9319 flags:# id:string type:string title:flags.1?string description:flags.2?string url:flags.3?string thumb:flags.4?InputWebDocument content:flags.5?InputWebDocument send_message:InputBotInlineMessage = InputBotInlineResult; @@ -574,7 +577,7 @@ botInlineMessageMediaAuto#764cf810 flags:# message:string entities:flags.1?Vecto botInlineMessageText#8c7f65e2 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaGeo#b722de65 flags:# geo:GeoPoint period:int reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaVenue#8a86659c flags:# geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; -botInlineMessageMediaContact#35edb4d4 flags:# phone_number:string first_name:string last_name:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; +botInlineMessageMediaContact#18d1cdc2 flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineResult#11965f3a flags:# id:string type:string title:flags.1?string description:flags.2?string url:flags.3?string thumb:flags.4?WebDocument content:flags.5?WebDocument send_message:BotInlineMessage = BotInlineResult; botInlineMediaResult#17db940b flags:# id:string type:string photo:flags.0?Photo document:flags.1?Document title:flags.2?string description:flags.3?string send_message:BotInlineMessage = BotInlineResult; @@ -617,8 +620,9 @@ topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector chats:Vector users:Vector = contacts.TopPeers; +contacts.topPeersDisabled#b52c939d = contacts.TopPeers; -draftMessageEmpty#ba4baec5 = DraftMessage; +draftMessageEmpty#1b0c841a flags:# date:flags.0?int = DraftMessage; draftMessage#fd8e711f flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int message:string entities:flags.3?Vector date:int = DraftMessage; messages.featuredStickersNotModified#4ede3cf = messages.FeaturedStickers; @@ -706,14 +710,13 @@ paymentRequestedInfo#909c3f94 flags:# name:flags.0?string phone:flags.1?string e paymentSavedCredentialsCard#cdc27a1f id:string title:string = PaymentSavedCredentials; -webDocument#c61acbd8 url:string access_hash:long size:int mime_type:string attributes:Vector dc_id:int = WebDocument; +webDocument#1c570ed1 url:string access_hash:long size:int mime_type:string attributes:Vector = WebDocument; webDocumentNoProxy#f9c8bcc6 url:string size:int mime_type:string attributes:Vector = WebDocument; inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector = InputWebDocument; inputWebFileLocation#c239d686 url:string access_hash:long = InputWebFileLocation; -inputWebFileGeoPointLocation#66275a62 geo_point:InputGeoPoint w:int h:int zoom:int scale:int = InputWebFileLocation; -inputWebFileGeoMessageLocation#553f32eb peer:InputPeer msg_id:int w:int h:int zoom:int scale:int = InputWebFileLocation; +inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w:int h:int zoom:int scale:int = InputWebFileLocation; upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile; @@ -883,6 +886,10 @@ account.sentEmailCode#811f854f email_pattern:string length:int = account.SentEma help.deepLinkInfoEmpty#66afa166 = help.DeepLinkInfo; help.deepLinkInfo#6a4ee832 flags:# update_app:flags.0?true message:string entities:flags.1?Vector = help.DeepLinkInfo; +savedPhoneContact#1142bd56 phone:string first_name:string last_name:string date:int = SavedContact; + +account.takeout#4dba4501 id:long = account.Takeout; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -890,13 +897,14 @@ invokeAfterMsgs#3dc4b4f0 {X:Type} msg_ids:Vector query:!X = X; initConnection#785188b8 {X:Type} flags:# api_id:int device_model:string system_version:string app_version:string system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy query:!X = X; invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X; invokeWithoutUpdates#bf9459b7 {X:Type} query:!X = X; +invokeWithMessagesRange#365275f2 {X:Type} range:MessageRange query:!X = X; +invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X; auth.sendCode#86aef0ec flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool api_id:int api_hash:string = auth.SentCode; auth.signUp#1b067634 phone_number:string phone_code_hash:string phone_code:string first_name:string last_name:string = auth.Authorization; auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization; auth.logOut#5717da40 = Bool; auth.resetAuthorizations#9fab0d1a = Bool; -auth.sendInvites#771c1d97 phone_numbers:Vector message:string = Bool; auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization; auth.importAuthorization#e3ef9613 id:int bytes:bytes = auth.Authorization; auth.bindTempAuthKey#cdd42a05 perm_auth_key_id:long nonce:long expires_at:int encrypted_message:bytes = Bool; @@ -948,6 +956,8 @@ account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_ account.verifyPhone#4dd3a7f6 phone_number:string phone_code_hash:string phone_code:string = Bool; account.sendVerifyEmailCode#7011509f email:string = account.SentEmailCode; account.verifyEmail#ecba39db email:string code:string = Bool; +account.initTakeoutSession#f05b4804 flags:# contacts:flags.0?true message_users:flags.1?true message_chats:flags.2?true message_megagroups:flags.3?true message_channels:flags.4?true files:flags.5?true file_max_size:flags.5?int = account.Takeout; +account.finishTakeoutSession#1d2652ee flags:# success:flags.0?true = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; @@ -968,9 +978,11 @@ contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer; contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true phone_calls:flags.3?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; contacts.resetTopPeerRating#1ae373ac category:TopPeerCategory peer:InputPeer = Bool; contacts.resetSaved#879537f1 = Bool; +contacts.getSaved#82f1e39f = Vector; +contacts.toggleTopPeers#8514bdda enabled:Bool = Bool; messages.getMessages#63c66506 id:Vector = messages.Messages; -messages.getDialogs#191ba9c5 flags:# exclude_pinned:flags.0?true offset_date:int offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs; +messages.getDialogs#b098aee6 flags:# exclude_pinned:flags.0?true offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:int = messages.Dialogs; messages.getHistory#dcbb8260 peer:InputPeer offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int hash:int = messages.Messages; messages.search#8614ef68 flags:# peer:InputPeer q:string from_id:flags.0?InputUser filter:MessagesFilter min_date:int max_date:int offset_id:int add_offset:int limit:int max_id:int min_id:int hash:int = messages.Messages; messages.readHistory#e306d3a peer:InputPeer max_id:int = messages.AffectedMessages; @@ -1065,6 +1077,9 @@ messages.getRecentLocations#bbc45b09 peer:InputPeer limit:int hash:int = message messages.sendMultiMedia#2095512f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector = Updates; messages.uploadEncryptedFile#5057c497 peer:InputEncryptedChat file:InputEncryptedFile = EncryptedFile; messages.searchStickerSets#c2b7d08b flags:# exclude_featured:flags.0?true q:string hash:int = messages.FoundStickerSets; +messages.getSplitRanges#1cff7e08 = Vector; +messages.markDialogUnread#c286d98f flags:# unread:flags.0?true peer:InputDialogPeer = Bool; +messages.getDialogUnreadMarks#22e24e22 = Vector; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1131,6 +1146,7 @@ channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool; channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates; +channels.getLeftChannels#8341ecc0 offset:int = messages.Chats; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1161,4 +1177,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 81 +// LAYER 82 From c660d3a7d0f977f321686463089b3e6fa57a8494 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:43:29 +0200 Subject: [PATCH 030/249] Fix PhotoSize not having date anymore --- pyrogram/client/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 20a3e50c..ba584aed 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -711,7 +711,9 @@ class Client(Methods, BaseClient): file_name = "{}_{}_{}{}".format( media_type_str, - datetime.fromtimestamp(media.date or time.time()).strftime("%Y-%m-%d_%H-%M-%S"), + datetime.fromtimestamp( + getattr(media, "date", None) or time.time() + ).strftime("%Y-%m-%d_%H-%M-%S"), self.rnd_id(), extension ) From c85aa5dab2941ddacd154dc2fc672c318001281c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:43:43 +0200 Subject: [PATCH 031/249] Fix Photo downloads --- pyrogram/client/methods/download_media.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/download_media.py index 89b0f61d..20179d08 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/download_media.py @@ -77,7 +77,12 @@ class DownloadMedia(BaseClient): """ if isinstance(message, pyrogram_types.Message): if message.photo: - media = message.photo.sizes[-1] + media = pyrogram_types.Document( + file_id=message.photo.sizes[-1].file_id, + file_size=message.photo.sizes[-1].file_size, + mime_type="", + date=message.photo.date + ) elif message.audio: media = message.audio elif message.document: @@ -96,6 +101,7 @@ class DownloadMedia(BaseClient): return elif isinstance(message, ( pyrogram_types.Photo, + pyrogram_types.PhotoSize, pyrogram_types.Audio, pyrogram_types.Document, pyrogram_types.Video, @@ -104,7 +110,15 @@ class DownloadMedia(BaseClient): pyrogram_types.Sticker, pyrogram_types.GIF )): - media = message + if isinstance(message, pyrogram_types.Photo): + media = pyrogram_types.Document( + file_id=message.sizes[-1].file_id, + file_size=message.sizes[-1].file_size, + mime_type="", + date=message.date + ) + else: + media = message elif isinstance(message, str): media = pyrogram_types.Document( file_id=message, From 8bb4fdd67d36527739b9815a52c0df22971708a1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 2 Jul 2018 20:48:58 +0200 Subject: [PATCH 032/249] Update to v0.7.6dev1 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 16204830..b93b57b1 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Tue, 3 Jul 2018 18:29:25 +0200 Subject: [PATCH 033/249] Log UpdateChannelTooLong updates --- pyrogram/client/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index ba584aed..92666ce5 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -777,6 +777,9 @@ class Client(Methods, BaseClient): pts = getattr(update, "pts", None) pts_count = getattr(update, "pts_count", None) + + if isinstance(update, types.UpdateChannelTooLong): + log.warning(update) if isinstance(update, types.UpdateNewChannelMessage): message = update.message From 29fb0ce599ba67b6aeb532be5350970ece7951a8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 13:18:20 +0200 Subject: [PATCH 034/249] Also log UpdatesTooLong --- pyrogram/client/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 92666ce5..230d4bef 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -839,6 +839,8 @@ class Client(Methods, BaseClient): self.dispatcher.updates.put((diff.other_updates[0], [], [])) elif isinstance(updates, types.UpdateShort): self.dispatcher.updates.put((updates.update, [], [])) + elif isinstance(updates, types.UpdatesTooLong): + log.warning(updates) except Exception as e: log.error(e, exc_info=True) From c7489cf30203b4780e141862d75103154f0a590a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 14:03:14 +0200 Subject: [PATCH 035/249] Reformat code --- 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 230d4bef..e4fb0cc6 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -777,7 +777,7 @@ class Client(Methods, BaseClient): pts = getattr(update, "pts", None) pts_count = getattr(update, "pts_count", None) - + if isinstance(update, types.UpdateChannelTooLong): log.warning(update) From 8bdccda6eed7ada1f3ef83c78606dad563998fbe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 14:03:45 +0200 Subject: [PATCH 036/249] Fix GetDialog call --- pyrogram/client/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e4fb0cc6..a0f51d84 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -983,8 +983,12 @@ class Client(Methods, BaseClient): try: r = self.send( functions.messages.GetDialogs( - offset_date, 0, types.InputPeerEmpty(), - self.DIALOGS_AT_ONCE, True + offset_date=offset_date, + offset_id=0, + offset_peer=types.InputPeerEmpty(), + limit=self.DIALOGS_AT_ONCE, + hash=0, + exclude_pinned=True ) ) except FloodWait as e: From 52f1f390ca7721a8676b0c89b4fc0c49c7de85d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 20:59:21 +0200 Subject: [PATCH 037/249] Rename get_dialogs --- pyrogram/client/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a0f51d84..d7768c86 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -231,7 +231,7 @@ class Client(Methods, BaseClient): self.peers_by_username = {} self.peers_by_phone = {} - self.get_dialogs() + self.get_initial_dialogs() self.get_contacts() else: self.send(functions.messages.GetPinnedDialogs()) @@ -998,7 +998,7 @@ class Client(Methods, BaseClient): log.info("Total peers: {}".format(len(self.peers_by_id))) return r - def get_dialogs(self): + def get_initial_dialogs(self): self.send(functions.messages.GetPinnedDialogs()) dialogs = self.get_dialogs_chunk(0) From 1d7c857e9f31a9ab7afc702c4d1f3147389987a0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:02:26 +0200 Subject: [PATCH 038/249] Rename get_dialogs --- pyrogram/client/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index d7768c86..e8cc394f 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -235,7 +235,7 @@ class Client(Methods, BaseClient): self.get_contacts() else: self.send(functions.messages.GetPinnedDialogs()) - self.get_dialogs_chunk(0) + self.get_initial_dialogs_chunk() else: self.send(functions.updates.GetState()) @@ -978,7 +978,7 @@ class Client(Methods, BaseClient): indent=4 ) - def get_dialogs_chunk(self, offset_date): + def get_initial_dialogs_chunk(self, offset_date: int = 0): while True: try: r = self.send( @@ -1001,14 +1001,14 @@ class Client(Methods, BaseClient): def get_initial_dialogs(self): self.send(functions.messages.GetPinnedDialogs()) - dialogs = self.get_dialogs_chunk(0) + dialogs = self.get_initial_dialogs_chunk() offset_date = utils.get_offset_date(dialogs) while len(dialogs.dialogs) == self.DIALOGS_AT_ONCE: - dialogs = self.get_dialogs_chunk(offset_date) + dialogs = self.get_initial_dialogs_chunk(offset_date) offset_date = utils.get_offset_date(dialogs) - self.get_dialogs_chunk(0) + self.get_initial_dialogs_chunk() def resolve_peer(self, peer_id: int or str): """Use this method to get the *InputPeer* of a known *peer_id*. From 2b36fb31d94262a6f43538c23286ec15ff505284 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:03:29 +0200 Subject: [PATCH 039/249] Add Dialog type --- pyrogram/client/types/dialog.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyrogram/client/types/dialog.py diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py new file mode 100644 index 00000000..792360a6 --- /dev/null +++ b/pyrogram/client/types/dialog.py @@ -0,0 +1,28 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class Dialog(Object): + ID = 0xb0700028 + + def __init__(self, id: int, top_message): + # TODO docstrings + self.id = id + self.top_message = top_message From 1ed202b9261b0b831a472adffa287503e2602d60 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:03:51 +0200 Subject: [PATCH 040/249] Add Dialogs type --- pyrogram/client/types/dialogs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyrogram/client/types/dialogs.py diff --git a/pyrogram/client/types/dialogs.py b/pyrogram/client/types/dialogs.py new file mode 100644 index 00000000..1e1b0cb2 --- /dev/null +++ b/pyrogram/client/types/dialogs.py @@ -0,0 +1,28 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class Dialogs(Object): + ID = 0xb0700029 + + def __init__(self, total_count: int, dialogs: list): + # TODO docstrings + self.total_count = total_count + self.dialogs = dialogs From 91cf2d1a8e4377e476e7a2df91a485b76120edf7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:05:00 +0200 Subject: [PATCH 041/249] Make Dialog and Dialogs importable and printable --- compiler/api/compiler.py | 2 ++ pyrogram/__init__.py | 4 ++-- pyrogram/client/types/__init__.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 7c1412d1..aa5714ec 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -504,6 +504,8 @@ def start(): f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") + f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") + f.write("\n 0xb0700029: \"pyrogram.client.types.Dialogs\",") f.write("\n}\n") diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index b93b57b1..c151ac4a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,8 +29,8 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, - Video, VideoNote, Voice, CallbackQuery, Messages + Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, + Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages ) from .client.types.reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 84c12a44..3c569324 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -22,6 +22,8 @@ from .chat import Chat from .chat_member import ChatMember from .chat_photo import ChatPhoto from .contact import Contact +from .dialog import Dialog +from .dialogs import Dialogs from .document import Document from .gif import GIF from .input_media_photo import InputMediaPhoto From 9ac6633cc81b584515a160a78bd0c859c8a72c96 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:05:43 +0200 Subject: [PATCH 042/249] Add get_dialogs method --- pyrogram/client/methods/messages/__init__.py | 2 + .../client/methods/messages/get_dialogs.py | 100 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 pyrogram/client/methods/messages/get_dialogs.py diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index e2c2462e..94279ffd 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -21,6 +21,7 @@ from .edit_message_caption import EditMessageCaption from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages +from .get_dialogs import GetDialogs from .get_history import GetHistory from .get_messages import GetMessages from .send_audio import SendAudio @@ -47,6 +48,7 @@ class Messages( ForwardMessages, GetHistory, GetMessages, + GetDialogs, SendAudio, SendChatAction, SendContact, diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py new file mode 100644 index 00000000..d0ef032b --- /dev/null +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -0,0 +1,100 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram.api import functions, types +from ...ext import BaseClient, utils + + +class GetDialogs(BaseClient): + # TODO docstrings + + def get_dialogs(self, + last_chunk=None, + limit: int = 100): + offset_date = 0 + offset_id = 0 + offset_peer = types.InputPeerEmpty() + + if last_chunk: + for dialog in reversed(last_chunk.dialogs): + top_message = dialog.top_message + + if top_message: + message_date = top_message.date + + if message_date: + offset_id = top_message.message_id + offset_date = message_date + offset_peer = self.resolve_peer(dialog.id) + break + + r = self.send( + functions.messages.GetDialogs( + offset_date=offset_date, + offset_id=offset_id, + offset_peer=offset_peer, + limit=limit, + hash=0, + exclude_pinned=True + ) + ) + + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + messages = {} + + for message in r.messages: + if isinstance(message, (types.Message, types.MessageService)): + chat_id = message.to_id + + if isinstance(chat_id, types.PeerUser): + chat_id = chat_id.user_id + elif isinstance(chat_id, types.PeerChat): + chat_id = -chat_id.chat_id + else: + chat_id = int("-100" + str(chat_id.channel_id)) + + messages[chat_id] = utils.parse_messages( + self, message, + users, chats + ) + + dialogs = [] + + for dialog in r.dialogs: + chat_id = dialog.peer + + if isinstance(chat_id, types.PeerUser): + chat_id = chat_id.user_id + elif isinstance(chat_id, types.PeerChat): + chat_id = -chat_id.chat_id + else: + chat_id = int("-100" + str(chat_id.channel_id)) + + dialogs.append( + pyrogram.Dialog( + id=chat_id, + top_message=messages.get(chat_id) + ) + ) + + return pyrogram.Dialogs( + total_count=getattr(r, "count", len(r.dialogs)), + dialogs=dialogs + ) From 51194945c6abf89897436bd4e5ec1f7fb6f351da Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:31:50 +0200 Subject: [PATCH 043/249] Add members_count attribute to Chat --- pyrogram/client/types/chat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/chat.py b/pyrogram/client/types/chat.py index 1455bd0f..9cd7aec7 100644 --- a/pyrogram/client/types/chat.py +++ b/pyrogram/client/types/chat.py @@ -81,7 +81,8 @@ class Chat(Object): invite_link: str = None, pinned_message=None, sticker_set_name: str = None, - can_set_sticker_set: bool = None + can_set_sticker_set: bool = None, + members_count: int = None ): self.id = id self.type = type @@ -96,3 +97,4 @@ class Chat(Object): self.pinned_message = pinned_message self.sticker_set_name = sticker_set_name self.can_set_sticker_set = can_set_sticker_set + self.members_count = members_count From fe97a4d92bf85bcbde4ab79e6b9db79866e038f6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:32:35 +0200 Subject: [PATCH 044/249] Parse members_count --- pyrogram/client/ext/utils.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3f287b49..d236c69a 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -884,8 +884,8 @@ def parse_chat_full( chat_full: types.messages.ChatFull or types.UserFull ) -> pyrogram_types.Chat: if isinstance(chat_full, types.UserFull): - chat = parse_user_chat(chat_full.user) - chat.description = chat_full.about + parsed_chat = parse_user_chat(chat_full.user) + parsed_chat.description = chat_full.about else: full_chat = chat_full.full_chat chat = None @@ -895,21 +895,25 @@ def parse_chat_full( chat = i if isinstance(full_chat, types.ChatFull): - chat = parse_chat_chat(chat) + parsed_chat = parse_chat_chat(chat) + + if isinstance(full_chat.participants, types.ChatParticipants): + parsed_chat.members_count = len(full_chat.participants.participants) else: - chat = parse_channel_chat(chat) - chat.description = full_chat.about or None + parsed_chat = parse_channel_chat(chat) + parsed_chat.members_count = full_chat.participants_count + parsed_chat.description = full_chat.about or None # TODO: Add StickerSet type - chat.can_set_sticker_set = full_chat.can_set_stickers - chat.sticker_set_name = full_chat.stickerset + parsed_chat.can_set_sticker_set = full_chat.can_set_stickers + parsed_chat.sticker_set_name = full_chat.stickerset if full_chat.pinned_msg_id: - chat.pinned_message = client.get_messages( + parsed_chat.pinned_message = client.get_messages( int("-100" + str(full_chat.id)), full_chat.pinned_msg_id ) if isinstance(full_chat.exported_invite, types.ChatInviteExported): - chat.invite_link = full_chat.exported_invite.link + parsed_chat.invite_link = full_chat.exported_invite.link - return chat + return parsed_chat From 15e3cf0fd5ffc6fae9adfa076778b49fff32ef3c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:39:09 +0200 Subject: [PATCH 045/249] Small fix --- pyrogram/client/ext/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index d236c69a..f87b9035 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -909,7 +909,7 @@ def parse_chat_full( if full_chat.pinned_msg_id: parsed_chat.pinned_message = client.get_messages( - int("-100" + str(full_chat.id)), + parsed_chat.id, full_chat.pinned_msg_id ) From 8b43ad8a63f6b8f15b24399846074c0bba70240f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:49:11 +0200 Subject: [PATCH 046/249] Add unread messages, mentions count and unread mark to Dialog --- pyrogram/client/methods/messages/get_dialogs.py | 5 ++++- pyrogram/client/types/dialog.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index d0ef032b..28687511 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -90,7 +90,10 @@ class GetDialogs(BaseClient): dialogs.append( pyrogram.Dialog( id=chat_id, - top_message=messages.get(chat_id) + top_message=messages.get(chat_id), + unread_messages_count=dialog.unread_count, + unread_mentions_count=dialog.unread_mentions_count, + unread_mark=dialog.unread_mark ) ) diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py index 792360a6..4210f105 100644 --- a/pyrogram/client/types/dialog.py +++ b/pyrogram/client/types/dialog.py @@ -22,7 +22,15 @@ from pyrogram.api.core import Object class Dialog(Object): ID = 0xb0700028 - def __init__(self, id: int, top_message): + def __init__(self, + id: int, + top_message, + unread_messages_count: int, + unread_mentions_count: int, + unread_mark: bool): # TODO docstrings self.id = id self.top_message = top_message + self.unread_messages_count = unread_messages_count + self.unread_mentions_count = unread_mentions_count + self.unread_mark = unread_mark From 4049b571356353869bcbe512c740993f11f69fa9 Mon Sep 17 00:00:00 2001 From: avi-av <32315634+avi-av@users.noreply.github.com> Date: Thu, 5 Jul 2018 14:42:04 +0300 Subject: [PATCH 047/249] Update docs Type returns in the documentation section --- pyrogram/client/methods/messages/get_messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 49535a40..3c8b4dbe 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -44,7 +44,7 @@ class GetMessages(BaseClient): Returns: On success and in case *message_ids* was a list, the returned value will be a list of the requested - :obj:`Messages ` even if a list contains just one element, otherwise if + :obj:`Messages ` even if a list contains just one element, otherwise if *message_ids* was an integer, the single requested :obj:`Message ` is returned. From 2b6c30d0e1519b1f8eef7efd2e5690b290c119d6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 5 Jul 2018 14:57:45 +0200 Subject: [PATCH 048/249] Update get_dialogs --- pyrogram/client/ext/utils.py | 9 +++ .../client/methods/messages/get_dialogs.py | 71 +++++++++---------- pyrogram/client/types/dialog.py | 4 +- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index f87b9035..6dd98f5d 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -917,3 +917,12 @@ def parse_chat_full( parsed_chat.invite_link = full_chat.exported_invite.link return parsed_chat + + +def parse_dialog_chat(peer, users: dict, chats: dict): + if isinstance(peer, types.PeerUser): + return parse_user_chat(users[peer.user_id]) + elif isinstance(peer, types.PeerChat): + return parse_chat_chat(chats[peer.chat_id]) + else: + return parse_channel_chat(chats[peer.channel_id]) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index 28687511..f43ca6a5 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -25,55 +25,54 @@ class GetDialogs(BaseClient): # TODO docstrings def get_dialogs(self, - last_chunk=None, - limit: int = 100): - offset_date = 0 - offset_id = 0 - offset_peer = types.InputPeerEmpty() + limit: int = 100, + pinned_only: bool = False, + last_chunk=None): + if pinned_only: + r = self.send(functions.messages.GetPinnedDialogs()) + else: + offset_date = 0 - if last_chunk: - for dialog in reversed(last_chunk.dialogs): - top_message = dialog.top_message + if last_chunk: + for dialog in reversed(last_chunk.dialogs): + top_message = dialog.top_message - if top_message: - message_date = top_message.date + if top_message: + message_date = top_message.date - if message_date: - offset_id = top_message.message_id - offset_date = message_date - offset_peer = self.resolve_peer(dialog.id) - break + if message_date: + offset_date = message_date + break - r = self.send( - functions.messages.GetDialogs( - offset_date=offset_date, - offset_id=offset_id, - offset_peer=offset_peer, - limit=limit, - hash=0, - exclude_pinned=True + r = self.send( + functions.messages.GetDialogs( + offset_date=offset_date, + offset_id=0, + offset_peer=types.InputPeerEmpty(), + limit=limit, + hash=0, + exclude_pinned=True + ) ) - ) users = {i.id: i for i in r.users} chats = {i.id: i for i in r.chats} messages = {} for message in r.messages: - if isinstance(message, (types.Message, types.MessageService)): - chat_id = message.to_id + to_id = message.to_id - if isinstance(chat_id, types.PeerUser): - chat_id = chat_id.user_id - elif isinstance(chat_id, types.PeerChat): - chat_id = -chat_id.chat_id + if isinstance(to_id, types.PeerUser): + if message.out: + chat_id = to_id.user_id else: - chat_id = int("-100" + str(chat_id.channel_id)) + chat_id = message.from_id + elif isinstance(to_id, types.PeerChat): + chat_id = -to_id.chat_id + else: + chat_id = int("-100" + str(to_id.channel_id)) - messages[chat_id] = utils.parse_messages( - self, message, - users, chats - ) + messages[chat_id] = utils.parse_messages(self, message, users, chats) dialogs = [] @@ -89,7 +88,7 @@ class GetDialogs(BaseClient): dialogs.append( pyrogram.Dialog( - id=chat_id, + chat=utils.parse_dialog_chat(dialog.peer, users, chats), top_message=messages.get(chat_id), unread_messages_count=dialog.unread_count, unread_mentions_count=dialog.unread_mentions_count, diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py index 4210f105..5ad99477 100644 --- a/pyrogram/client/types/dialog.py +++ b/pyrogram/client/types/dialog.py @@ -23,13 +23,13 @@ class Dialog(Object): ID = 0xb0700028 def __init__(self, - id: int, + chat, top_message, unread_messages_count: int, unread_mentions_count: int, unread_mark: bool): # TODO docstrings - self.id = id + self.chat = chat self.top_message = top_message self.unread_messages_count = unread_messages_count self.unread_mentions_count = unread_mentions_count From 3b29a602d0c704764394d0a50d62c8faf065c291 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 6 Jul 2018 19:12:41 +0200 Subject: [PATCH 049/249] Add get_chat_members method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/get_chat_members.py | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/get_chat_members.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 9c887ef5..ac819e2c 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -18,6 +18,7 @@ from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat +from .get_chat_members import GetChatMembers from .join_chat import JoinChat from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat @@ -34,6 +35,7 @@ class Chats( KickChatMember, UnbanChatMember, RestrictChatMember, - PromoteChatMember + PromoteChatMember, + GetChatMembers ): pass diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py new file mode 100644 index 00000000..4d5a1032 --- /dev/null +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -0,0 +1,66 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient, utils + + +class Filters: + ALL = "all" + KICKED = "kicked" + RESTRICTED = "restricted" + BOTS = "bots" + RECENT = "recent" + ADMINISTRATORS = "administrators" + + +class GetChatMembers(BaseClient): + def get_chat_members(self, + chat_id: int or str, + offset: int = 0, + limit: int = 200, + query: str = "", + filter: str = Filters.ALL): + filter = filter.lower() + + if filter == Filters.ALL: + filter = types.ChannelParticipantsSearch(q=query) + elif filter == Filters.KICKED: + filter = types.ChannelParticipantsKicked(q=query) + elif filter == Filters.RESTRICTED: + filter = types.ChannelParticipantsBanned(q=query) + elif filter == Filters.BOTS: + filter = types.ChannelParticipantsBots() + elif filter == Filters.RECENT: + filter = types.ChannelParticipantsRecent() + elif filter == Filters.ADMINISTRATORS: + filter = types.ChannelParticipantsAdmins() + else: + raise ValueError("Invalid filter \"{}\"".format(filter)) + + return utils.parse_chat_members( + self.send( + functions.channels.GetParticipants( + channel=self.resolve_peer(chat_id), + filter=filter, + offset=offset, + limit=limit, + hash=0 + ) + ) + ) From e3128fca9d63eb81ecd006d2f9eee881f34100f9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 7 Jul 2018 15:47:34 +0200 Subject: [PATCH 050/249] Make get_chat_members work with basic groups --- .../client/methods/chats/get_chat_members.py | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 4d5a1032..a851ef58 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -36,31 +36,44 @@ class GetChatMembers(BaseClient): limit: int = 200, query: str = "", filter: str = Filters.ALL): - filter = filter.lower() + peer = self.resolve_peer(chat_id) - if filter == Filters.ALL: - filter = types.ChannelParticipantsSearch(q=query) - elif filter == Filters.KICKED: - filter = types.ChannelParticipantsKicked(q=query) - elif filter == Filters.RESTRICTED: - filter = types.ChannelParticipantsBanned(q=query) - elif filter == Filters.BOTS: - filter = types.ChannelParticipantsBots() - elif filter == Filters.RECENT: - filter = types.ChannelParticipantsRecent() - elif filter == Filters.ADMINISTRATORS: - filter = types.ChannelParticipantsAdmins() - else: - raise ValueError("Invalid filter \"{}\"".format(filter)) - - return utils.parse_chat_members( - self.send( - functions.channels.GetParticipants( - channel=self.resolve_peer(chat_id), - filter=filter, - offset=offset, - limit=limit, - hash=0 + if isinstance(peer, types.InputPeerChat): + return utils.parse_chat_members( + self.send( + functions.messages.GetFullChat( + peer.chat_id + ) ) ) - ) + elif isinstance(peer, types.InputPeerChannel): + filter = filter.lower() + + if filter == Filters.ALL: + filter = types.ChannelParticipantsSearch(q=query) + elif filter == Filters.KICKED: + filter = types.ChannelParticipantsKicked(q=query) + elif filter == Filters.RESTRICTED: + filter = types.ChannelParticipantsBanned(q=query) + elif filter == Filters.BOTS: + filter = types.ChannelParticipantsBots() + elif filter == Filters.RECENT: + filter = types.ChannelParticipantsRecent() + elif filter == Filters.ADMINISTRATORS: + filter = types.ChannelParticipantsAdmins() + else: + raise ValueError("Invalid filter \"{}\"".format(filter)) + + return utils.parse_chat_members( + self.send( + functions.channels.GetParticipants( + channel=peer, + filter=filter, + offset=offset, + limit=limit, + hash=0 + ) + ) + ) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) From d94139be9a3e0f4177606e696f8a6e191ef0ee84 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 08:39:10 +0200 Subject: [PATCH 051/249] Add parse_chat_members util function --- pyrogram/client/ext/utils.py | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 6dd98f5d..56cb844e 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -926,3 +926,103 @@ def parse_dialog_chat(peer, users: dict, chats: dict): return parse_chat_chat(chats[peer.chat_id]) else: return parse_channel_chat(chats[peer.channel_id]) + + +def parse_chat_members(members: types.channels.ChannelParticipants or types.messages.ChatFull): + users = {i.id: i for i in members.users} + parsed_members = [] + + if isinstance(members, types.channels.ChannelParticipants): + members = members.participants + + for member in members: + user = parse_user(users[member.user_id]) + + if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf)): + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="member" + ) + ) + elif isinstance(member, types.ChannelParticipantCreator): + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="creator" + ) + ) + elif isinstance(member, types.ChannelParticipantAdmin): + rights = member.admin_rights # type: types.ChannelAdminRights + + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="administrator", + can_be_edited=member.can_edit, + can_change_info=rights.change_info, + can_post_messages=rights.post_messages, + can_edit_messages=rights.edit_messages, + can_delete_messages=rights.delete_messages, + can_invite_users=rights.invite_users or rights.invite_link, + can_restrict_members=rights.ban_users, + can_pin_messages=rights.pin_messages, + can_promote_members=rights.add_admins + ) + ) + elif isinstance(member, types.ChannelParticipantBanned): + rights = member.banned_rights # type: types.ChannelBannedRights + + chat_member = pyrogram_types.ChatMember( + user=user, + status="kicked" if rights.view_messages else "restricted", + until_date=0 if rights.until_date == (1 << 31) - 1 else rights.until_date + ) + + if chat_member.status == "restricted": + chat_member.can_send_messages = not rights.send_messages + chat_member.can_send_media_messages = not rights.send_media + chat_member.can_send_other_messages = ( + not rights.send_stickers or not rights.send_gifs or + not rights.send_games or not rights.send_inline + ) + chat_member.can_add_web_page_previews = not rights.embed_links + + parsed_members.append(chat_member) + + return pyrogram_types.ChatMembers( + total_count=members.count, + chat_members=parsed_members + ) + else: + members = members.full_chat.participants.participants + + for member in members: + user = parse_user(users[member.user_id]) + + if isinstance(member, types.ChatParticipant): + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="member" + ) + ) + elif isinstance(member, types.ChatParticipantCreator): + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="creator" + ) + ) + elif isinstance(member, types.ChatParticipantAdmin): + parsed_members.append( + pyrogram_types.ChatMember( + user=user, + status="administrator" + ) + ) + + return pyrogram_types.ChatMembers( + total_count=len(members), + chat_members=parsed_members + ) From 960280b99620822f4c4005aeeb6996f34dbcd69b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 08:39:36 +0200 Subject: [PATCH 052/249] Add new ChatMembers type --- compiler/api/compiler.py | 1 + pyrogram/__init__.py | 2 +- pyrogram/client/types/__init__.py | 1 + pyrogram/client/types/chat_members.py | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/types/chat_members.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index aa5714ec..3b6dbae7 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -506,6 +506,7 @@ def start(): f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") f.write("\n 0xb0700029: \"pyrogram.client.types.Dialogs\",") + f.write("\n 0xb0700030: \"pyrogram.client.types.ChatMembers\",") f.write("\n}\n") diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c151ac4a..29ad17ef 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -27,7 +27,7 @@ __version__ = "0.7.6dev1" from .api.errors import Error from .client.types import ( - Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, + Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 3c569324..d99090ef 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -20,6 +20,7 @@ from .audio import Audio from .callback_query import CallbackQuery from .chat import Chat from .chat_member import ChatMember +from .chat_members import ChatMembers from .chat_photo import ChatPhoto from .contact import Contact from .dialog import Dialog diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/chat_members.py new file mode 100644 index 00000000..5557d161 --- /dev/null +++ b/pyrogram/client/types/chat_members.py @@ -0,0 +1,27 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class ChatMembers(Object): + ID = 0xb0700030 + + def __init__(self, total_count: int, chat_members: list): + self.total_count = total_count + self.chat_members = chat_members From 52ac0c80e676eac953e140e5df3224113d3cdd06 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 08:40:10 +0200 Subject: [PATCH 053/249] Add todo for ChatMembers docstrings --- pyrogram/client/types/chat_members.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/chat_members.py index 5557d161..658a3086 100644 --- a/pyrogram/client/types/chat_members.py +++ b/pyrogram/client/types/chat_members.py @@ -20,6 +20,8 @@ from pyrogram.api.core import Object class ChatMembers(Object): + # TODO: Docstrings + ID = 0xb0700030 def __init__(self, total_count: int, chat_members: list): From 9e4267dd2cd01af99891b3ddcd448de5bc834299 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 08:58:10 +0200 Subject: [PATCH 054/249] Move media types in their own folder --- pyrogram/__init__.py | 8 ++--- pyrogram/client/types/__init__.py | 17 +++------- pyrogram/client/types/media/__init__.py | 31 +++++++++++++++++++ pyrogram/client/types/{ => media}/audio.py | 0 pyrogram/client/types/{ => media}/contact.py | 0 pyrogram/client/types/{ => media}/document.py | 0 pyrogram/client/types/{ => media}/gif.py | 0 pyrogram/client/types/{ => media}/location.py | 0 pyrogram/client/types/{ => media}/photo.py | 0 .../client/types/{ => media}/photo_size.py | 0 pyrogram/client/types/{ => media}/sticker.py | 0 .../types/{ => media}/user_profile_photos.py | 0 pyrogram/client/types/{ => media}/venue.py | 0 pyrogram/client/types/{ => media}/video.py | 0 .../client/types/{ => media}/video_note.py | 0 pyrogram/client/types/{ => media}/voice.py | 0 16 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 pyrogram/client/types/media/__init__.py rename pyrogram/client/types/{ => media}/audio.py (100%) rename pyrogram/client/types/{ => media}/contact.py (100%) rename pyrogram/client/types/{ => media}/document.py (100%) rename pyrogram/client/types/{ => media}/gif.py (100%) rename pyrogram/client/types/{ => media}/location.py (100%) rename pyrogram/client/types/{ => media}/photo.py (100%) rename pyrogram/client/types/{ => media}/photo_size.py (100%) rename pyrogram/client/types/{ => media}/sticker.py (100%) rename pyrogram/client/types/{ => media}/user_profile_photos.py (100%) rename pyrogram/client/types/{ => media}/venue.py (100%) rename pyrogram/client/types/{ => media}/video.py (100%) rename pyrogram/client/types/{ => media}/video_note.py (100%) rename pyrogram/client/types/{ => media}/voice.py (100%) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 29ad17ef..f1442596 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -30,11 +30,9 @@ from .client.types import ( Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, - Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages -) -from .client.types.reply_markup import ( - ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove + Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, + InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, + ReplyKeyboardRemove ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index d99090ef..e6fcc8aa 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,35 +16,26 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .audio import Audio from .callback_query import CallbackQuery from .chat import Chat from .chat_member import ChatMember from .chat_members import ChatMembers from .chat_photo import ChatPhoto -from .contact import Contact from .dialog import Dialog from .dialogs import Dialogs -from .document import Document -from .gif import GIF from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo from .input_phone_contact import InputPhoneContact -from .location import Location +from .media import ( + Audio, Contact, Document, GIF, Location, Photo, PhotoSize, + Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos +) from .message import Message from .message_entity import MessageEntity from .messages import Messages -from .photo import Photo -from .photo_size import PhotoSize from .reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) -from .sticker import Sticker from .update import Update from .user import User -from .user_profile_photos import UserProfilePhotos -from .venue import Venue -from .video import Video -from .video_note import VideoNote -from .voice import Voice diff --git a/pyrogram/client/types/media/__init__.py b/pyrogram/client/types/media/__init__.py new file mode 100644 index 00000000..5b09d832 --- /dev/null +++ b/pyrogram/client/types/media/__init__.py @@ -0,0 +1,31 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .audio import Audio +from .contact import Contact +from .document import Document +from .gif import GIF +from .location import Location +from .photo import Photo +from .photo_size import PhotoSize +from .sticker import Sticker +from .user_profile_photos import UserProfilePhotos +from .venue import Venue +from .video import Video +from .video_note import VideoNote +from .voice import Voice diff --git a/pyrogram/client/types/audio.py b/pyrogram/client/types/media/audio.py similarity index 100% rename from pyrogram/client/types/audio.py rename to pyrogram/client/types/media/audio.py diff --git a/pyrogram/client/types/contact.py b/pyrogram/client/types/media/contact.py similarity index 100% rename from pyrogram/client/types/contact.py rename to pyrogram/client/types/media/contact.py diff --git a/pyrogram/client/types/document.py b/pyrogram/client/types/media/document.py similarity index 100% rename from pyrogram/client/types/document.py rename to pyrogram/client/types/media/document.py diff --git a/pyrogram/client/types/gif.py b/pyrogram/client/types/media/gif.py similarity index 100% rename from pyrogram/client/types/gif.py rename to pyrogram/client/types/media/gif.py diff --git a/pyrogram/client/types/location.py b/pyrogram/client/types/media/location.py similarity index 100% rename from pyrogram/client/types/location.py rename to pyrogram/client/types/media/location.py diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/media/photo.py similarity index 100% rename from pyrogram/client/types/photo.py rename to pyrogram/client/types/media/photo.py diff --git a/pyrogram/client/types/photo_size.py b/pyrogram/client/types/media/photo_size.py similarity index 100% rename from pyrogram/client/types/photo_size.py rename to pyrogram/client/types/media/photo_size.py diff --git a/pyrogram/client/types/sticker.py b/pyrogram/client/types/media/sticker.py similarity index 100% rename from pyrogram/client/types/sticker.py rename to pyrogram/client/types/media/sticker.py diff --git a/pyrogram/client/types/user_profile_photos.py b/pyrogram/client/types/media/user_profile_photos.py similarity index 100% rename from pyrogram/client/types/user_profile_photos.py rename to pyrogram/client/types/media/user_profile_photos.py diff --git a/pyrogram/client/types/venue.py b/pyrogram/client/types/media/venue.py similarity index 100% rename from pyrogram/client/types/venue.py rename to pyrogram/client/types/media/venue.py diff --git a/pyrogram/client/types/video.py b/pyrogram/client/types/media/video.py similarity index 100% rename from pyrogram/client/types/video.py rename to pyrogram/client/types/media/video.py diff --git a/pyrogram/client/types/video_note.py b/pyrogram/client/types/media/video_note.py similarity index 100% rename from pyrogram/client/types/video_note.py rename to pyrogram/client/types/media/video_note.py diff --git a/pyrogram/client/types/voice.py b/pyrogram/client/types/media/voice.py similarity index 100% rename from pyrogram/client/types/voice.py rename to pyrogram/client/types/media/voice.py From 756a6f7630c8790f5b80e7128341bd24561a3ca1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 09:22:08 +0200 Subject: [PATCH 055/249] Add set_chat_photo method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/set_chat_photo.py | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/set_chat_photo.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index ac819e2c..666329f5 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -24,6 +24,7 @@ from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember +from .set_chat_photo import SetChatPhoto from .unban_chat_member import UnbanChatMember @@ -36,6 +37,7 @@ class Chats( UnbanChatMember, RestrictChatMember, PromoteChatMember, - GetChatMembers + GetChatMembers, + SetChatPhoto ): pass diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py new file mode 100644 index 00000000..63c75ff8 --- /dev/null +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -0,0 +1,60 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . +import os +from base64 import b64decode +from struct import unpack + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class SetChatPhoto(BaseClient): + def set_chat_photo(self, chat_id: int or str, photo: str): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if os.path.exists(photo): + photo = types.InputChatUploadedPhoto(file=self.save_file(photo)) + else: + s = unpack(" Date: Sun, 8 Jul 2018 10:18:48 +0200 Subject: [PATCH 056/249] Reformat code --- pyrogram/client/methods/chats/set_chat_photo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index 63c75ff8..b93ba091 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -15,6 +15,7 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . + import os from base64 import b64decode from struct import unpack From 17ca6b709487158efa7e12d2af7acc368fdd7b51 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 10:19:16 +0200 Subject: [PATCH 057/249] Add delete_chat_photo method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/delete_chat_photo.py | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/delete_chat_photo.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 666329f5..c3cc67a6 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .delete_chat_photo import DeleteChatPhoto from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat from .get_chat_members import GetChatMembers @@ -38,6 +39,7 @@ class Chats( RestrictChatMember, PromoteChatMember, GetChatMembers, - SetChatPhoto + SetChatPhoto, + DeleteChatPhoto ): pass diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py new file mode 100644 index 00000000..98998fbd --- /dev/null +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -0,0 +1,45 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class DeleteChatPhoto(BaseClient): + def delete_chat_photo(self, chat_id: int or str): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChat): + self.send( + functions.messages.EditChatPhoto( + chat_id=peer.chat_id, + photo=types.InputChatPhotoEmpty() + ) + ) + elif isinstance(peer, types.InputPeerChannel): + self.send( + functions.channels.EditPhoto( + channel=peer, + photo=types.InputChatPhotoEmpty() + ) + ) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) + + return True From 393caa9d7c24af706d106ab968a7a7f7795566b6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 10:24:39 +0200 Subject: [PATCH 058/249] Add set_chat_title method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/set_chat_title.py | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/set_chat_title.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index c3cc67a6..1df65e69 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -26,6 +26,7 @@ from .leave_chat import LeaveChat from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember from .set_chat_photo import SetChatPhoto +from .set_chat_title import SetChatTitle from .unban_chat_member import UnbanChatMember @@ -40,6 +41,7 @@ class Chats( PromoteChatMember, GetChatMembers, SetChatPhoto, - DeleteChatPhoto + DeleteChatPhoto, + SetChatTitle ): pass diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py new file mode 100644 index 00000000..ba732427 --- /dev/null +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -0,0 +1,45 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class SetChatTitle(BaseClient): + def set_chat_title(self, chat_id: int or str, title: str): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChat): + self.send( + functions.messages.EditChatTitle( + chat_id=peer.chat_id, + title=title + ) + ) + elif isinstance(peer, types.InputPeerChannel): + self.send( + functions.channels.EditTitle( + channel=peer, + title=title + ) + ) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) + + return True From 7d799aed11512a0738f0bc7570096f725374484c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 10:28:54 +0200 Subject: [PATCH 059/249] Add set_chat_description method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../methods/chats/set_chat_description.py | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/set_chat_description.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 1df65e69..c38f9d4a 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -25,6 +25,7 @@ from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember +from .set_chat_description import SetChatDescription from .set_chat_photo import SetChatPhoto from .set_chat_title import SetChatTitle from .unban_chat_member import UnbanChatMember @@ -42,6 +43,7 @@ class Chats( GetChatMembers, SetChatPhoto, DeleteChatPhoto, - SetChatTitle + SetChatTitle, + SetChatDescription ): pass diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py new file mode 100644 index 00000000..3f3871b1 --- /dev/null +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -0,0 +1,40 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class SetChatDescription(BaseClient): + def set_chat_description(self, chat_id: int or str, description: str): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChannel): + self.send( + functions.channels.EditAbout( + channel=peer, + about=description + ) + ) + elif isinstance(peer, types.InputPeerChat): + raise ValueError("The chat_id \"{}\" belongs to a basic group".format(chat_id)) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) + + return True From 486e8b955202e8fc21fb5829d15d887e82620926 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 11:00:56 +0200 Subject: [PATCH 060/249] Add pin_chat_message method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/pin_chat_message.py | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/pin_chat_message.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index c38f9d4a..fa9dd21d 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -23,6 +23,7 @@ from .get_chat_members import GetChatMembers from .join_chat import JoinChat from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat +from .pin_chat_message import PinChatMessage from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember from .set_chat_description import SetChatDescription @@ -44,6 +45,7 @@ class Chats( SetChatPhoto, DeleteChatPhoto, SetChatTitle, - SetChatDescription + SetChatDescription, + PinChatMessage ): pass diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py new file mode 100644 index 00000000..5f7db61e --- /dev/null +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -0,0 +1,41 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class PinChatMessage(BaseClient): + def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChannel): + self.send( + functions.channels.UpdatePinnedMessage( + channel=peer, + id=message_id, + silent=disable_notification or None + ) + ) + elif isinstance(peer, types.InputPeerChat): + raise ValueError("The chat_id \"{}\" belongs to a basic group".format(chat_id)) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) + + return True From 037ded73c353c75a715e6515a205af25caeb737a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jul 2018 11:09:07 +0200 Subject: [PATCH 061/249] Add unpin_chat_message method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../methods/chats/unpin_chat_message.py | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/unpin_chat_message.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index fa9dd21d..038440f6 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -30,6 +30,7 @@ from .set_chat_description import SetChatDescription from .set_chat_photo import SetChatPhoto from .set_chat_title import SetChatTitle from .unban_chat_member import UnbanChatMember +from .unpin_chat_message import UnpinChatMessage class Chats( @@ -46,6 +47,7 @@ class Chats( DeleteChatPhoto, SetChatTitle, SetChatDescription, - PinChatMessage + PinChatMessage, + UnpinChatMessage ): pass diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py new file mode 100644 index 00000000..90f94fef --- /dev/null +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -0,0 +1,40 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class UnpinChatMessage(BaseClient): + def unpin_chat_message(self, chat_id: int or str): + # TODO: Docstrings + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChannel): + self.send( + functions.channels.UpdatePinnedMessage( + channel=peer, + id=0 + ) + ) + elif isinstance(peer, types.InputPeerChat): + raise ValueError("The chat_id \"{}\" belongs to a basic group".format(chat_id)) + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) + + return True From 31f41fae180b5b870c41ecbbf1b5ba2618814ad7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Jul 2018 23:47:29 +0200 Subject: [PATCH 062/249] Add USER_NOT_MUTUAL_CONTACT and USER_CHANNELS_TOO_MUCH errors --- compiler/error/source/400_BAD_REQUEST.tsv | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index cd196077..f02c72ff 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -62,4 +62,6 @@ USER_IS_BOT A bot cannot send messages to other bots or to itself WEBPAGE_CURL_FAILED Telegram could not fetch the provided URL STICKERSET_INVALID The requested sticker set is invalid PEER_FLOOD The method can't be used because your account is limited -MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters \ No newline at end of file +MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters +USER_NOT_MUTUAL_CONTACT The user is not a mutual contact +USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups \ No newline at end of file From ab11c9e3478cff7d64311f6407d242942038d8b2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 10 Jul 2018 15:57:27 +0200 Subject: [PATCH 063/249] Add missing docstring arguments --- pyrogram/client/methods/chats/get_chat.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index 194e6171..588ac468 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -25,6 +25,11 @@ class GetChat(BaseClient): """Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.) + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + Returns: On success, a :obj:`Chat ` object is returned. From 68ea8898247b1b1bc9244e2d13899a2fb4ca3dbd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:05:07 +0200 Subject: [PATCH 064/249] Add REG_ID_GENERATE_FAILED error --- compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv b/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv index abb58495..60d1b51a 100644 --- a/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv +++ b/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv @@ -3,4 +3,5 @@ AUTH_RESTART User authorization has restarted RPC_CALL_FAIL Telegram is having internal problems. Please try again later RPC_MCGET_FAIL Telegram is having internal problems. Please try again later PERSISTENT_TIMESTAMP_OUTDATED Telegram is having internal problems. Please try again later -HISTORY_GET_FAILED Telegram is having internal problems. Please try again later \ No newline at end of file +HISTORY_GET_FAILED Telegram is having internal problems. Please try again later +REG_ID_GENERATE_FAILED Telegram is having internal problems. Please try again later \ No newline at end of file From 0c96fa8b7cd4a7f22bceacf12c85d5f68770db98 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:05:33 +0200 Subject: [PATCH 065/249] Don't flush each chunk. Let python/os deal with it --- pyrogram/client/client.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e8cc394f..709ea95a 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1240,8 +1240,6 @@ class Client(Methods, BaseClient): break f.write(chunk) - f.flush() - os.fsync(f.fileno()) offset += limit @@ -1324,8 +1322,6 @@ class Client(Methods, BaseClient): assert h.hash == sha256(cdn_chunk).digest(), "Invalid CDN hash part {}".format(i) f.write(decrypted_chunk) - f.flush() - os.fsync(f.fileno()) offset += limit From f7b661a6c485ee24b15bc3a7f0eed710b8ab5322 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:09:52 +0200 Subject: [PATCH 066/249] Add API_ID_PUBLISHED_FLOOD --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index f02c72ff..e00c10c5 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -64,4 +64,5 @@ STICKERSET_INVALID The requested sticker set is invalid PEER_FLOOD The method can't be used because your account is limited MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters USER_NOT_MUTUAL_CONTACT The user is not a mutual contact -USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups \ No newline at end of file +USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups +API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side \ No newline at end of file From ad9fb2680818143c1b223caaa981c0972633a868 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:25:39 +0200 Subject: [PATCH 067/249] Cleaner Chat docstrings --- pyrogram/client/types/chat.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/types/chat.py b/pyrogram/client/types/chat.py index 9cd7aec7..afed1ca4 100644 --- a/pyrogram/client/types/chat.py +++ b/pyrogram/client/types/chat.py @@ -24,15 +24,13 @@ class Chat(Object): Args: id (``int``): - Unique identifier for this chat. This number may be greater than 32 bits and some programming - languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, - so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + Unique identifier for this chat. type (``str``): Type of chat, can be either "private", "group", "supergroup" or "channel". title (``str``, *optional*): - Title, for supergroups, channels and group chats. + Title, for supergroups, channels and basic group chats. username (``str``, *optional*): Username, for private chats, supergroups and channels if available. @@ -44,25 +42,33 @@ class Chat(Object): Last name of the other party in a private chat. all_members_are_administrators (``bool``, *optional*): - True if a group has 'All Members Are Admins' enabled. + True if a basic group has "All Members Are Admins" enabled. photo (:obj:`ChatPhoto `, *optional*): - Chat photo. Returned only in getChat. + Chat photo. Suitable for downloads only. description (``str``, *optional*): - Description, for supergroups and channel chats. Returned only in getChat. + Description, for supergroups and channel chats. + Returned only in :meth:`get_chat() `. invite_link (``str``, *optional*): - Chat invite link, for supergroups and channel chats. Returned only in getChat. + Chat invite link, for supergroups and channel chats. + Returned only in :meth:`get_chat() `. pinned_message (:obj:`Message `, *optional*): - Pinned message, for supergroups and channel chats. Returned only in getChat. + Pinned message, for supergroups and channel chats. + Returned only in :meth:`get_chat() `. sticker_set_name (``str``, *optional*): - For supergroups, name of group sticker set. Returned only in getChat. + For supergroups, name of group sticker set. + Returned only in :meth:`get_chat() `. can_set_sticker_set (``bool``, *optional*): - True, if the bot can change the group sticker set. Returned only in getChat. + True, if the group sticker set can be changed by you. + Returned only in :meth:`get_chat() `. + + members_count (``int``, *optional*): + Chat members count, for groups and channels only. """ ID = 0xb0700002 From 5347080fd17646e145c1dcef7caba734e7feb4d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:26:59 +0200 Subject: [PATCH 068/249] Clean Audio comments --- pyrogram/client/types/media/audio.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pyrogram/client/types/media/audio.py b/pyrogram/client/types/media/audio.py index 51cec257..57731266 100644 --- a/pyrogram/client/types/media/audio.py +++ b/pyrogram/client/types/media/audio.py @@ -65,12 +65,12 @@ class Audio(Object): performer: str = None, title: str = None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.duration = duration # int - self.performer = performer # flags.5?string - self.title = title # flags.6?string + self.file_id = file_id + self.thumb = thumb + self.file_name = file_name + self.mime_type = mime_type + self.file_size = file_size + self.date = date + self.duration = duration + self.performer = performer + self.title = title From 7509566796b0084fc1470b2207391f23f802024c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:36:49 +0200 Subject: [PATCH 069/249] Remove Voice thumb and file_name. Add waveform --- pyrogram/client/types/media/voice.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/pyrogram/client/types/media/voice.py b/pyrogram/client/types/media/voice.py index 414d2267..d838cf59 100644 --- a/pyrogram/client/types/media/voice.py +++ b/pyrogram/client/types/media/voice.py @@ -29,11 +29,8 @@ class Voice(Object): duration (``int``): Duration of the audio in seconds as defined by sender. - thumb (:obj:`PhotoSize `, *optional*): - Voice thumbnail. - - file_name (``str``, *optional*): - Voice file name. + waveform (``bytes``, *optional*): + Voice waveform. mime_type (``str``, *optional*): MIME type of the file as defined by sender. @@ -51,15 +48,13 @@ class Voice(Object): self, file_id: str, duration: int, - thumb=None, - file_name: str = None, + waveform: bytes = None, mime_type: str = None, file_size: int = None, date: int = None): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.duration = duration # int + self.file_id = file_id + self.duration = duration + self.waveform = waveform + self.mime_type = mime_type + self.file_size = file_size + self.date = date From 9214416f7cd9ff4ba6a8e90861bb0cda0ea5a4f0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:36:58 +0200 Subject: [PATCH 070/249] Parse Voice waveform --- pyrogram/client/ext/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 56cb844e..177c5eaf 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -400,8 +400,7 @@ def parse_messages( duration=audio_attributes.duration, mime_type=doc.mime_type, file_size=doc.size, - thumb=parse_thumb(doc.thumb), - file_name=file_name, + waveform=audio_attributes.waveform, date=doc.date ) else: From 00e170feea6e71a3007df63be0fb62e6d2ebcb1a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:40:33 +0200 Subject: [PATCH 071/249] Video notes don't have a file_name --- pyrogram/client/types/media/video_note.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pyrogram/client/types/media/video_note.py b/pyrogram/client/types/media/video_note.py index 7f0b6736..642eb5aa 100644 --- a/pyrogram/client/types/media/video_note.py +++ b/pyrogram/client/types/media/video_note.py @@ -35,9 +35,6 @@ class VideoNote(Object): thumb (:obj:`PhotoSize `, *optional*): Video thumbnail. - file_name (``str``, *optional*): - Video note file name. - mime_type (``str``, *optional*): MIME type of the file as defined by sender. @@ -56,16 +53,14 @@ class VideoNote(Object): length: int, duration: int, thumb=None, - file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.length = length # int - self.duration = duration # int + self.file_id = file_id + self.thumb = thumb + self.mime_type = mime_type + self.file_size = file_size + self.date = date + self.length = length + self.duration = duration From 12ef2f8ca222ca5ffe191cbf0ebba12512157273 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 17:48:18 +0200 Subject: [PATCH 072/249] Fix video notes not having a file_name anymore --- pyrogram/client/ext/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 177c5eaf..c4f7ef57 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -463,7 +463,6 @@ def parse_messages( duration=video_attributes.duration, thumb=parse_thumb(doc.thumb), file_size=doc.size, - file_name=file_name, mime_type=doc.mime_type, date=doc.date ) From fade921ac02a0088ec572449c635322f2e4a78d6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 18:05:36 +0200 Subject: [PATCH 073/249] Don't document client, is for internal purposes only --- pyrogram/client/types/message.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 112bc0bf..30b40b63 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -26,9 +26,6 @@ class Message(Object): Args: message_id (``int``): Unique message identifier inside this chat. - - client (:obj:`Client `, *optional*): - The client instance this message is bound to. date (``int``, *optional*): Date the message was sent in Unix time. From e89d56e05811ea26550d3255d7e78d1358195f99 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 23:54:11 +0200 Subject: [PATCH 074/249] Add cashtag message entity --- pyrogram/client/ext/utils.py | 1 + pyrogram/client/types/message_entity.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index c4f7ef57..cd2c34bf 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -60,6 +60,7 @@ class Str(str): ENTITIES = { types.MessageEntityMention.ID: "mention", types.MessageEntityHashtag.ID: "hashtag", + types.MessageEntityCashtag.ID: "cashtag", types.MessageEntityBotCommand.ID: "bot_command", types.MessageEntityUrl.ID: "url", types.MessageEntityEmail.ID: "email", diff --git a/pyrogram/client/types/message_entity.py b/pyrogram/client/types/message_entity.py index 460da6e7..f41907c8 100644 --- a/pyrogram/client/types/message_entity.py +++ b/pyrogram/client/types/message_entity.py @@ -26,9 +26,9 @@ class MessageEntity(Object): Args: type (``str``): Type of the entity. - Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), - code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), - text_mention (for users without usernames). + Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "bold" (bold text), + italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text + URLs), "text_mention" (for users without usernames). offset (``int``): Offset in UTF-16 code units to the start of the entity. From b6a4dee7875bea516059c6aa7219bd808bebe9f2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 11 Jul 2018 23:54:54 +0200 Subject: [PATCH 075/249] Fix some User weird docstrings --- pyrogram/client/types/user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/user.py b/pyrogram/client/types/user.py index 62e79e19..17510738 100644 --- a/pyrogram/client/types/user.py +++ b/pyrogram/client/types/user.py @@ -42,10 +42,10 @@ class User(Object): IETF language tag of the user's language. phone_number (``str``, *optional*): - User's or bot's phone number. + User's phone number. photo (:obj:`ChatPhoto `, *optional*): - User's or bot's current profile photo. + User's or bot's current profile photo. Suitable for downloads only. """ ID = 0xb0700001 From f242aceb31c5a39622535d8370b9414883e16b1d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 00:10:33 +0200 Subject: [PATCH 076/249] Add vCard support for contacts --- pyrogram/client/ext/utils.py | 1 + .../client/methods/messages/send_contact.py | 11 ++++++++--- pyrogram/client/types/media/contact.py | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index cd2c34bf..eba4e65e 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -360,6 +360,7 @@ def parse_messages( phone_number=media.phone_number, first_name=media.first_name, last_name=media.last_name or None, + vcard=media.vcard or None, user_id=media.user_id or None ) elif isinstance(media, types.MessageMediaVenue): diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index fc0abdd5..1a894e30 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -26,6 +26,7 @@ class SendContact(BaseClient): phone_number: str, first_name: str, last_name: str = "", + vcard: str = "", disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None): @@ -47,6 +48,9 @@ class SendContact(BaseClient): last_name (``str``, *optional*): Contact's last name. + vcard (``str``, *optional*): + Contact's vCard information. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -68,9 +72,10 @@ class SendContact(BaseClient): functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaContact( - phone_number, - first_name, - last_name + phone_number=phone_number, + first_name=first_name, + last_name=last_name, + vcard=vcard ), message="", silent=disable_notification or None, diff --git a/pyrogram/client/types/media/contact.py b/pyrogram/client/types/media/contact.py index f625120c..a89b170c 100644 --- a/pyrogram/client/types/media/contact.py +++ b/pyrogram/client/types/media/contact.py @@ -38,8 +38,16 @@ class Contact(Object): ID = 0xb0700011 - def __init__(self, phone_number: str, first_name: str, last_name: str = None, user_id=None): - self.phone_number = phone_number # string - self.first_name = first_name # string - self.last_name = last_name # flags.0?string - self.user_id = user_id # flags.1?int + def __init__( + self, + phone_number: str, + first_name: str, + last_name: str = None, + vcard: str = None, + user_id: int = None + ): + self.phone_number = phone_number + self.first_name = first_name + self.last_name = last_name + self.vcard = vcard + self.user_id = user_id From a9a9dc3cd36edd3b1da23fb8e5c41ac2036e6998 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 00:24:57 +0200 Subject: [PATCH 077/249] Make download_media raise ValueError in case of non-media messages --- pyrogram/client/methods/download_media.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/download_media.py index 20179d08..e2fd463f 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/download_media.py @@ -75,6 +75,8 @@ class DownloadMedia(BaseClient): Raises: :class:`Error ` """ + error_message = "This message doesn't contain any downloadable media" + if isinstance(message, pyrogram_types.Message): if message.photo: media = pyrogram_types.Document( @@ -98,7 +100,7 @@ class DownloadMedia(BaseClient): elif message.gif: media = message.gif else: - return + raise ValueError(error_message) elif isinstance(message, ( pyrogram_types.Photo, pyrogram_types.PhotoSize, @@ -126,7 +128,7 @@ class DownloadMedia(BaseClient): mime_type="" ) else: - return + raise ValueError(error_message) done = Event() path = [None] From 8289dff05f2752be937c4a615d2f68e4dc798af6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 00:31:33 +0200 Subject: [PATCH 078/249] Update download_media docstrings --- pyrogram/client/methods/download_media.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/download_media.py index e2fd463f..174feb27 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/download_media.py @@ -74,6 +74,7 @@ class DownloadMedia(BaseClient): Raises: :class:`Error ` + ``ValueError``: If the message doesn't contain any downloadable media """ error_message = "This message doesn't contain any downloadable media" From 1e727fbb4347283902bb87064a315805eb771adc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 00:54:13 +0200 Subject: [PATCH 079/249] Add extra attributes to User is_self, is_contact, is_mutual_contact and is_deleted --- pyrogram/client/ext/utils.py | 4 ++++ pyrogram/client/types/user.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index eba4e65e..a99ee066 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -129,6 +129,10 @@ def parse_chat_photo(photo): def parse_user(user: types.User) -> pyrogram_types.User or None: return pyrogram_types.User( id=user.id, + is_self=user.is_self, + is_contact=user.contact, + is_mutual_contact=user.mutual_contact, + is_deleted=user.deleted, is_bot=user.bot, first_name=user.first_name, last_name=user.last_name, diff --git a/pyrogram/client/types/user.py b/pyrogram/client/types/user.py index 17510738..9ae5dab2 100644 --- a/pyrogram/client/types/user.py +++ b/pyrogram/client/types/user.py @@ -26,6 +26,18 @@ class User(Object): id (``int``): Unique identifier for this user or bot. + is_self(``bool``): + True, if this user is you yourself. + + is_contact(``bool``): + True, if this user is in your contacts. + + is_mutual_contact(``bool``): + True, if you both have each other's contact. + + is_deleted(``bool``): + True, if this user is deleted. + is_bot (``bool``): True, if this user is a bot. @@ -53,6 +65,10 @@ class User(Object): def __init__( self, id: int, + is_self: bool, + is_contact: bool, + is_mutual_contact: bool, + is_deleted: bool, is_bot: bool, first_name: str, last_name: str = None, @@ -62,6 +78,10 @@ class User(Object): photo=None ): self.id = id + self.is_self = is_self + self.is_contact = is_contact + self.is_mutual_contact = is_mutual_contact + self.is_deleted = is_deleted self.is_bot = is_bot self.first_name = first_name self.last_name = last_name From 72eb7e7a3353ac44a6fa454b0fffe1eff2c24fca Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:13:35 +0200 Subject: [PATCH 080/249] Add missing vcard argument on Contact --- pyrogram/client/types/media/contact.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/client/types/media/contact.py b/pyrogram/client/types/media/contact.py index a89b170c..a59e2047 100644 --- a/pyrogram/client/types/media/contact.py +++ b/pyrogram/client/types/media/contact.py @@ -32,6 +32,9 @@ class Contact(Object): last_name (``str``, *optional*): Contact's last name. + vcard (``str``, *optional*): + Contact's vCard. + user_id (``int``, *optional*): Contact's user identifier in Telegram. """ From 5d9e2f7d7a6a4b59d31d0108b9298c7eee9caa00 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:13:51 +0200 Subject: [PATCH 081/249] Clean up Document docstrings --- pyrogram/client/types/media/document.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/types/media/document.py b/pyrogram/client/types/media/document.py index 076c1934..d87fa666 100644 --- a/pyrogram/client/types/media/document.py +++ b/pyrogram/client/types/media/document.py @@ -20,7 +20,7 @@ from pyrogram.api.core import Object class Document(Object): - """This object represents a general file (as opposed to photos, voice messages and audio files). + """This object represents a general file (as opposed to photos, voice messages, audio files, ...). Args: file_id (``str``): @@ -53,9 +53,9 @@ class Document(Object): file_size: int = None, date: int = None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.3?int + self.file_id = file_id + self.thumb = thumb + self.file_name = file_name + self.mime_type = mime_type + self.file_size = file_size + self.date = date From 62f575d53ff9bfb37020b499933bb59897c88ebd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:14:19 +0200 Subject: [PATCH 082/249] Clean up GIF and Location comments --- pyrogram/client/types/media/gif.py | 18 +++++++++--------- pyrogram/client/types/media/location.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/types/media/gif.py b/pyrogram/client/types/media/gif.py index 71e975f5..5172aae2 100644 --- a/pyrogram/client/types/media/gif.py +++ b/pyrogram/client/types/media/gif.py @@ -65,12 +65,12 @@ class GIF(Object): file_size: int = None, date: int = None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.width = width # int - self.height = height # int - self.duration = duration # int + self.file_id = file_id + self.thumb = thumb + self.file_name = file_name + self.mime_type = mime_type + self.file_size = file_size + self.date = date + self.width = width + self.height = height + self.duration = duration diff --git a/pyrogram/client/types/media/location.py b/pyrogram/client/types/media/location.py index 1f5feb00..be8c839f 100644 --- a/pyrogram/client/types/media/location.py +++ b/pyrogram/client/types/media/location.py @@ -33,5 +33,5 @@ class Location(Object): ID = 0xb0700012 def __init__(self, longitude: float, latitude: float): - self.longitude = longitude # double - self.latitude = latitude # double + self.longitude = longitude + self.latitude = latitude From 109e3836cfc25db611f85e51f4a2e34740d73601 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:16:08 +0200 Subject: [PATCH 083/249] Clean up Photo and PhotoSize docstrings --- pyrogram/client/types/media/photo.py | 4 ++-- pyrogram/client/types/media/photo_size.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/types/media/photo.py b/pyrogram/client/types/media/photo.py index f5494f13..d9deed76 100644 --- a/pyrogram/client/types/media/photo.py +++ b/pyrogram/client/types/media/photo.py @@ -27,10 +27,10 @@ class Photo(Object): Unique identifier for this photo. date (``int``): - Date the photo was sent in Unix time + Date the photo was sent in Unix time. sizes (List of :obj:`PhotoSize `): - Available sizes of this photo + Available sizes of this photo. """ ID = 0xb0700027 diff --git a/pyrogram/client/types/media/photo_size.py b/pyrogram/client/types/media/photo_size.py index 65691de0..764b046b 100644 --- a/pyrogram/client/types/media/photo_size.py +++ b/pyrogram/client/types/media/photo_size.py @@ -20,7 +20,7 @@ from pyrogram.api.core import Object class PhotoSize(Object): - """This object represents one size of a photo or a file / sticker thumbnail. + """This object represents one size of a photo or a file/sticker thumbnail. Args: file_id (``str``): From bee8d1340b6f99825ba941a418050401b6d8fe59 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:16:29 +0200 Subject: [PATCH 084/249] Clean up Sticker, Venue and Video comments --- pyrogram/client/types/media/sticker.py | 22 +++++++++++----------- pyrogram/client/types/media/venue.py | 8 ++++---- pyrogram/client/types/media/video.py | 18 +++++++++--------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pyrogram/client/types/media/sticker.py b/pyrogram/client/types/media/sticker.py index a5ed9085..2e7ac901 100644 --- a/pyrogram/client/types/media/sticker.py +++ b/pyrogram/client/types/media/sticker.py @@ -73,14 +73,14 @@ class Sticker(Object): set_name: str = None, mask_position=None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.width = width # int - self.height = height # int - self.emoji = emoji # flags.5?string - self.set_name = set_name # flags.6?string - self.mask_position = mask_position # flags.7?MaskPosition + self.file_id = file_id + self.thumb = thumb + self.file_name = file_name + self.mime_type = mime_type + self.file_size = file_size + self.date = date + self.width = width + self.height = height + self.emoji = emoji + self.set_name = set_name + self.mask_position = mask_position diff --git a/pyrogram/client/types/media/venue.py b/pyrogram/client/types/media/venue.py index 653f0dd3..5d9e387f 100644 --- a/pyrogram/client/types/media/venue.py +++ b/pyrogram/client/types/media/venue.py @@ -40,7 +40,7 @@ class Venue(Object): ID = 0xb0700013 def __init__(self, location, title: str, address: str, foursquare_id: str = None): - self.location = location # Location - self.title = title # string - self.address = address # string - self.foursquare_id = foursquare_id # flags.0?string + self.location = location + self.title = title + self.address = address + self.foursquare_id = foursquare_id diff --git a/pyrogram/client/types/media/video.py b/pyrogram/client/types/media/video.py index b4ffff2b..8b272a2d 100644 --- a/pyrogram/client/types/media/video.py +++ b/pyrogram/client/types/media/video.py @@ -65,12 +65,12 @@ class Video(Object): file_size: int = None, date: int = None ): - self.file_id = file_id # string - self.thumb = thumb # flags.0?PhotoSize - self.file_name = file_name # flags.1?string - self.mime_type = mime_type # flags.2?string - self.file_size = file_size # flags.3?int - self.date = date # flags.4?int - self.width = width # int - self.height = height # int - self.duration = duration # int + self.file_id = file_id + self.thumb = thumb + self.file_name = file_name + self.mime_type = mime_type + self.file_size = file_size + self.date = date + self.width = width + self.height = height + self.duration = duration From fa512a690d3bcb26fa24793fa5a4cc51fead0d7b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:17:30 +0200 Subject: [PATCH 085/249] Add download() bound method to Message --- pyrogram/client/types/message.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 30b40b63..db13ccd6 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -571,3 +571,39 @@ class Message(Object): raise ValueError("This button is not supported yet") else: raise ValueError("The message doesn't contain any keyboard") + + def download(self, file_name: str = "", block: bool = True): + """Use this method as a shortcut for: + + .. code-block:: python + + client.download_media(message) + + Example: + .. code-block:: python + + message.download() + + Args: + file_name (``str``, *optional*): + A custom *file_name* to be used instead of the one provided by Telegram. + By default, all files are downloaded in the *downloads* folder in your working directory. + You can also specify a path for downloading files in a custom location: paths that end with "/" + are considered directories. All non-existent folders will be created automatically. + + block (``bool``, *optional*): + Blocks the code execution until the file has been downloaded. + Defaults to True. + + Returns: + On success, the absolute path of the downloaded file as string is returned, None otherwise. + + Raises: + :class:`Error ` + ``ValueError``: If the message doesn't contain any downloadable media + """ + return self._client.download_media( + message=self, + file_name=file_name, + block=block + ) From 82d4a99fd590ef5043581d092fef580e4155e688 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:58:01 +0200 Subject: [PATCH 086/249] Add docstrings for Dialog type --- pyrogram/client/types/dialog.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py index 5ad99477..60ffb76c 100644 --- a/pyrogram/client/types/dialog.py +++ b/pyrogram/client/types/dialog.py @@ -20,6 +20,24 @@ from pyrogram.api.core import Object class Dialog(Object): + """This object represents a dialog + + Args: + chat (:obj:`Chat `): + Conversation the dialog belongs to. + + top_message (:obj:`Message `): + The last message sent in the dialog at this time. + + unread_messages_count (``int``): + Amount of unread messages in this dialogs. + + unread_mentions_count (``int``): + Amount of unread messages containing a mention in this dialog. + + unread_mark (``bool``): + True, if the dialog has the unread mark set. + """ ID = 0xb0700028 def __init__(self, @@ -28,7 +46,6 @@ class Dialog(Object): unread_messages_count: int, unread_mentions_count: int, unread_mark: bool): - # TODO docstrings self.chat = chat self.top_message = top_message self.unread_messages_count = unread_messages_count From 5c34e3f08f9acd10a14619e14d49a8a7397f3419 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jul 2018 14:58:18 +0200 Subject: [PATCH 087/249] Clean up Messages comments --- pyrogram/client/types/messages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/messages.py b/pyrogram/client/types/messages.py index 0d5d0a36..7a2546a9 100644 --- a/pyrogram/client/types/messages.py +++ b/pyrogram/client/types/messages.py @@ -33,5 +33,5 @@ class Messages(Object): ID = 0xb0700026 def __init__(self, total_count: int, messages: list): - self.total_count = total_count # int - self.messages = messages # Vector> + self.total_count = total_count + self.messages = messages From 85e3c05216511625d024cb59e13cc6608e35e175 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 13 Jul 2018 01:10:33 +0200 Subject: [PATCH 088/249] Document Dialogs --- pyrogram/client/types/dialogs.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/dialogs.py b/pyrogram/client/types/dialogs.py index 1e1b0cb2..cdf1d951 100644 --- a/pyrogram/client/types/dialogs.py +++ b/pyrogram/client/types/dialogs.py @@ -20,9 +20,17 @@ from pyrogram.api.core import Object class Dialogs(Object): + """This object represents a user's dialogs chunk + + Args: + total_count (``int``): + Total number of dialogs the user has. + + dialogs (List of :obj:`Dialog `): + Requested dialogs. + """ ID = 0xb0700029 def __init__(self, total_count: int, dialogs: list): - # TODO docstrings self.total_count = total_count self.dialogs = dialogs From 84e7bb5c50d3fefb11a04431bf6093ef279c6157 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Jul 2018 00:43:28 +0200 Subject: [PATCH 089/249] Clean up MessageEntity comments --- pyrogram/client/types/message_entity.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/types/message_entity.py b/pyrogram/client/types/message_entity.py index f41907c8..db2eee3e 100644 --- a/pyrogram/client/types/message_entity.py +++ b/pyrogram/client/types/message_entity.py @@ -45,9 +45,16 @@ class MessageEntity(Object): ID = 0xb0700004 - def __init__(self, type: str, offset: int, length: int, url: str = None, user=None): - self.type = type # string - self.offset = offset # int - self.length = length # int - self.url = url # flags.0?string - self.user = user # flags.1?User + def __init__( + self, + type: str, + offset: int, + length: int, + url: str = None, + user=None + ): + self.type = type + self.offset = offset + self.length = length + self.url = url + self.user = user From f8d44b8e77bbffd5752ed17dfc311dc371e416fd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Jul 2018 00:44:50 +0200 Subject: [PATCH 090/249] Document pin_chat_message --- .../client/methods/chats/pin_chat_message.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index 5f7db61e..e9bc533e 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -22,7 +22,29 @@ from ...ext import BaseClient class PinChatMessage(BaseClient): def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None): - # TODO: Docstrings + """Use this method to pin a message in a supergroup or a channel. + You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in + the supergroup or "can_edit_messages" admin right in the channel. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + message_id (``int``): + Identifier of a message to pin. + + disable_notification (``bool``): + Pass True, if it is not necessary to send a notification to all chat members about the new pinned + message. Notifications are always disabled in channels. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): From 15e83e12ca76c4eeac5037adc52578fbb65d51d1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 Jul 2018 16:33:12 +0200 Subject: [PATCH 091/249] Document unpin_chat_message --- .../client/methods/chats/unpin_chat_message.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py index 90f94fef..b1eeec79 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -22,7 +22,22 @@ from ...ext import BaseClient class UnpinChatMessage(BaseClient): def unpin_chat_message(self, chat_id: int or str): - # TODO: Docstrings + """Use this method to unpin a message in a supergroup or a channel. + You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin + right in the supergroup or "can_edit_messages" admin right in the channel. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): From 98578160f0eb8320102983e79fb45aa517e2efb8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 Jul 2018 16:33:41 +0200 Subject: [PATCH 092/249] Document set_chat_description --- .../methods/chats/set_chat_description.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index 3f3871b1..c9597a62 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -22,7 +22,24 @@ from ...ext import BaseClient class SetChatDescription(BaseClient): def set_chat_description(self, chat_id: int or str, description: str): - # TODO: Docstrings + """Use this method to change the description of a supergroup or a channel. + You must be an administrator in the chat for this to work and must have the appropriate admin rights. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + description (``str``): + New chat description, 0-255 characters. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id doesn't belong to a supergroup or a channel. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChannel): From 3fcf9b9ef6981d1abd113e1a030547ea15aca94d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 Jul 2018 16:34:15 +0200 Subject: [PATCH 093/249] Document delete_chat_photo --- .../client/methods/chats/delete_chat_photo.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index 98998fbd..57d90b11 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -22,7 +22,26 @@ from ...ext import BaseClient class DeleteChatPhoto(BaseClient): def delete_chat_photo(self, chat_id: int or str): - # TODO: Docstrings + """Use this method to delete a chat photo. + Photos can't be changed for private chats. + You must be an administrator in the chat for this to work and must have the appropriate admin rights. + + Note: + In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" + setting is off. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id belongs to user. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): From 3fe05b4d2886a8497636e2da32e83a52f62aadd1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 Jul 2018 16:34:32 +0200 Subject: [PATCH 094/249] Document set_chat_photo --- .../client/methods/chats/set_chat_photo.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index b93ba091..d98fefde 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -26,7 +26,29 @@ from ...ext import BaseClient class SetChatPhoto(BaseClient): def set_chat_photo(self, chat_id: int or str, photo: str): - # TODO: Docstrings + """Use this method to set a new profile photo for the chat. + Photos can't be changed for private chats. + You must be an administrator in the chat for this to work and must have the appropriate admin rights. + + Note: + In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" + setting is off. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + photo (``str``): + New chat photo. You can pass a :class:`Photo` id or a file path to upload a new photo. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id belongs to user. + """ peer = self.resolve_peer(chat_id) if os.path.exists(photo): From 5b89a6543714d6655d147ed5fab15118a482d2f1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 Jul 2018 16:34:47 +0200 Subject: [PATCH 095/249] Document set_chat_title --- .../client/methods/chats/set_chat_title.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py index ba732427..f6644a01 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -22,7 +22,29 @@ from ...ext import BaseClient class SetChatTitle(BaseClient): def set_chat_title(self, chat_id: int or str, title: str): - # TODO: Docstrings + """Use this method to change the title of a chat. + Titles can't be changed for private chats. + You must be an administrator in the chat for this to work and must have the appropriate admin rights. + + Note: + In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" + setting is off. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + title (``str``): + New chat title, 1-255 characters. + + Returns: + True on success. + + Raises: + :class:`Error ` + ``ValueError``: If a chat_id belongs to user. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): From f1bb20ebf674015ccfaf51f80d961cf4a1ef3f6d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 16 Jul 2018 00:18:46 +0200 Subject: [PATCH 096/249] Add the new methods to docs --- docs/source/pyrogram/Client.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 2fbd5879..bf9ac2ca 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -67,4 +67,10 @@ Client get_users get_chat get_messages - get_history \ No newline at end of file + get_history + set_chat_photo + delete_chat_photo + set_chat_title + set_chat_description + pin_chat_message + unpin_chat_message \ No newline at end of file From b77771497dbb40d7bebc8440486eb54da523be25 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 17 Jul 2018 09:09:04 +0200 Subject: [PATCH 097/249] Document get_chat_members --- .../client/methods/chats/get_chat_members.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index a851ef58..99e1c12d 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -36,6 +36,37 @@ class GetChatMembers(BaseClient): limit: int = 200, query: str = "", filter: str = Filters.ALL): + """Use this method to get the members list of a chat. + + A chat can be either a basic group, a supergroup or a channel. + You must be admin to retrieve the members (also known as "subscribers") list of a channel. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + offset (``int``, *optional*): + Sequential number of the first member to be returned. + Defaults to 0 [1]_. + + limit (``int``, *optional*): + Limits the number of members to be retrieved. + Defaults to 200, which is also the maximum limit allowed per method call. + + query (``str``, *optional*): + Query string to filter members based on their display names and usernames. + Defaults to "" (empty string) [2]_. + + filter (``str``, *optional*): + Filter used to select the kind of members you want to retrieve. Only applicable for supergroups + and channels. It can be any of "all", "kicked", "restricted", "bots", "recent" and "administrators". + Defaults to "all". + + .. [1] On supergroups and channels you can get up to 10,000 members for a single query string. + + .. [2] A query string is applicable only for "all", "kicked" and "restricted" filters only. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): From de0cc60ec60bb3292bcae32a1eaf3037677d23c5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 18 Jul 2018 02:14:36 +0200 Subject: [PATCH 098/249] Add USER_NOT_PARTICIPANT error --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index e00c10c5..ed332838 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -65,4 +65,5 @@ PEER_FLOOD The method can't be used because your account is limited MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups -API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side \ No newline at end of file +API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side +USER_NOT_PARTICIPANT The user is not a member of this chat \ No newline at end of file From e5915505a15516b9014e1beda9e3199e41d458c8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 19 Jul 2018 23:26:20 +0200 Subject: [PATCH 099/249] Add get_chat_member method --- pyrogram/client/methods/chats/__init__.py | 2 + .../client/methods/chats/get_chat_member.py | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 pyrogram/client/methods/chats/get_chat_member.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 038440f6..ce56f16b 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -19,6 +19,7 @@ from .delete_chat_photo import DeleteChatPhoto from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat +from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers from .join_chat import JoinChat from .kick_chat_member import KickChatMember @@ -43,6 +44,7 @@ class Chats( RestrictChatMember, PromoteChatMember, GetChatMembers, + GetChatMember, SetChatPhoto, DeleteChatPhoto, SetChatTitle, diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py new file mode 100644 index 00000000..082d1671 --- /dev/null +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -0,0 +1,59 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types, errors +from ...ext import BaseClient, utils + + +class GetChatMember(BaseClient): + def get_chat_member(self, + chat_id: int or str, + user_id: int or str): + # TODO: docstrings + chat_id = self.resolve_peer(chat_id) + user_id = self.resolve_peer(user_id) + + if isinstance(chat_id, types.InputPeerChat): + full_chat = self.send( + functions.messages.GetFullChat( + chat_id=chat_id.chat_id + ) + ) + + for member in utils.parse_chat_members(full_chat).chat_members: + if member.user.id == user_id.user_id: + return member + else: + raise errors.UserNotParticipant + elif isinstance(chat_id, types.InputPeerChannel): + r = self.send( + functions.channels.GetParticipant( + channel=chat_id, + user_id=user_id + ) + ) + + return utils.parse_chat_members( + types.channels.ChannelParticipants( + count=1, + participants=[r.participant], + users=r.users + ) + ).chat_members[0] + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) From 418740a3e69021fea78b0591c06c47d80c0ffb15 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 20 Jul 2018 00:08:32 +0200 Subject: [PATCH 100/249] Add get_chat_member and get_chat_members to docs --- docs/source/pyrogram/Client.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index bf9ac2ca..fec829f6 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -73,4 +73,6 @@ Client set_chat_title set_chat_description pin_chat_message - unpin_chat_message \ No newline at end of file + unpin_chat_message + get_chat_member + get_chat_members \ No newline at end of file From 1eaafb8e413bafe40063ef6b040f2fe980d6efab Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 21 Jul 2018 14:09:34 +0200 Subject: [PATCH 101/249] Clearer documentation for get_chat_members --- pyrogram/client/methods/chats/get_chat_members.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 99e1c12d..cfc9861e 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -60,12 +60,18 @@ class GetChatMembers(BaseClient): filter (``str``, *optional*): Filter used to select the kind of members you want to retrieve. Only applicable for supergroups - and channels. It can be any of "all", "kicked", "restricted", "bots", "recent" and "administrators". - Defaults to "all". + and channels. It can be any of the followings: + *"all"* - all kind of members, + *"kicked"* - kicked (banned) members only, + *"restricted"* - restricted members only, + *"bots"* - bots only, + *"recent"* - recent members only, + *"administrators"* - chat administrators only. + Defaults to *"all"*. .. [1] On supergroups and channels you can get up to 10,000 members for a single query string. - .. [2] A query string is applicable only for "all", "kicked" and "restricted" filters only. + .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. """ peer = self.resolve_peer(chat_id) From 215f54f32b17fb2e7c1ed577908d4d449fdd567d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 22 Jul 2018 02:07:44 +0200 Subject: [PATCH 102/249] Add get_chat_member documentation --- .../client/methods/chats/get_chat_member.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index 082d1671..c4fe0715 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -24,7 +24,25 @@ class GetChatMember(BaseClient): def get_chat_member(self, chat_id: int or str, user_id: int or str): - # TODO: docstrings + """Use this method to get information about a single member of a chat. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + user_id (``int`` | ``str``):: + Unique identifier (int) or username (str) of the target chat. + 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). + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + Returns: + On success, a :obj:`ChatMember ` object is returned. + + Raises: + :class:`Error ` + """ chat_id = self.resolve_peer(chat_id) user_id = self.resolve_peer(user_id) From 73361fef4718d39ec63f8123d9f8ab6c2101fe1c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Jul 2018 22:52:54 +0200 Subject: [PATCH 103/249] Add missing methods to docs --- docs/source/pyrogram/Client.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index fec829f6..96388364 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -20,6 +20,8 @@ Client run on_message on_callback_query + on_deleted_messages + on_disconnect on_raw_update add_handler remove_handler @@ -31,6 +33,7 @@ Client send_photo send_audio send_document + send_gif send_sticker send_video send_voice @@ -75,4 +78,5 @@ Client pin_chat_message unpin_chat_message get_chat_member - get_chat_members \ No newline at end of file + get_chat_members + get_dialogs \ No newline at end of file From df2f302c721771e8705aca2a94c11cd199ddc01f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 24 Jul 2018 20:43:49 +0200 Subject: [PATCH 104/249] Better organize Client's methods --- docs/source/pyrogram/Client.rst | 203 ++++++++++++++++++++------------ 1 file changed, 128 insertions(+), 75 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 96388364..642d43d8 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -1,82 +1,135 @@ Client ====== -.. currentmodule:::: pyrogram.Client +.. currentmodule:: pyrogram.Client + +.. autoclass:: pyrogram.Client + +Utilities +--------- + +.. autosummary:: + :nosignatures: + + start + stop + idle + run + add_handler + remove_handler + send + resolve_peer + download_media + +Decorators +---------- + +.. autosummary:: + :nosignatures: + + on_message + on_callback_query + on_deleted_messages + on_disconnect + on_raw_update + +.. _available-methods: + +Messages +-------- + +.. autosummary:: + :nosignatures: + + send_message + forward_messages + send_photo + send_audio + send_document + send_sticker + send_video + send_gif + send_voice + send_video_note + send_media_group + send_location + send_venue + send_contact + send_chat_action + edit_message_text + edit_message_caption + edit_message_reply_markup + delete_messages + get_messages + get_history + get_dialogs + +Chats +----- + +.. autosummary:: + :nosignatures: + + join_chat + leave_chat + kick_chat_member + unban_chat_member + restrict_chat_member + promote_chat_member + export_chat_invite_link + set_chat_photo + delete_chat_photo + set_chat_title + set_chat_description + pin_chat_message + unpin_chat_message + get_chat + get_chat_member + get_chat_members + +Users +----- + +.. autosummary:: + :nosignatures: + + get_me + get_users + get_user_profile_photos + delete_profile_photos + +Contacts +-------- + +.. autosummary:: + :nosignatures: + + add_contacts + get_contacts + delete_contacts + +Password +-------- + +.. autosummary:: + :nosignatures: + + enable_cloud_password + change_cloud_password + remove_cloud_password + +Bots +---- + +.. autosummary:: + :nosignatures: + + get_inline_bot_results + send_inline_bot_result + answer_callback_query + request_callback_answer + .. autoclass:: pyrogram.Client :inherited-members: :members: - - .. _available-methods: - - **Available methods** - - .. autosummary:: - :nosignatures: - - start - stop - idle - run - on_message - on_callback_query - on_deleted_messages - on_disconnect - on_raw_update - add_handler - remove_handler - send - resolve_peer - get_me - send_message - forward_messages - send_photo - send_audio - send_document - send_gif - send_sticker - send_video - send_voice - send_video_note - send_media_group - send_location - send_venue - send_contact - send_chat_action - download_media - get_user_profile_photos - delete_profile_photos - edit_message_text - edit_message_caption - edit_message_reply_markup - delete_messages - join_chat - leave_chat - export_chat_invite_link - enable_cloud_password - change_cloud_password - remove_cloud_password - kick_chat_member - unban_chat_member - restrict_chat_member - promote_chat_member - add_contacts - get_contacts - delete_contacts - get_inline_bot_results - send_inline_bot_result - answer_callback_query - request_callback_answer - get_users - get_chat - get_messages - get_history - set_chat_photo - delete_chat_photo - set_chat_title - set_chat_description - pin_chat_message - unpin_chat_message - get_chat_member - get_chat_members - get_dialogs \ No newline at end of file From 0c8278259028be87291626aa4e32de7c37fa4a30 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 24 Jul 2018 20:46:25 +0200 Subject: [PATCH 105/249] Don't show sub-sections --- docs/source/pyrogram/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index c272bc42..af8b281a 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -7,6 +7,8 @@ In this section you can find a detailed description of the Pyrogram package and after the well established `Telegram Bot API`_ methods, thus offering a familiar look to Bot developers. .. toctree:: + :maxdepth: 1 + Client types/index handlers/index From 5546765c4f04c0af99ab3653a0fef3c8606c4bd0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 25 Jul 2018 22:22:57 +0200 Subject: [PATCH 106/249] Delete Types doc files --- docs/source/pyrogram/types/Audio.rst | 5 ----- docs/source/pyrogram/types/CallbackQuery.rst | 5 ----- docs/source/pyrogram/types/Chat.rst | 5 ----- docs/source/pyrogram/types/ChatMember.rst | 5 ----- docs/source/pyrogram/types/ChatPhoto.rst | 5 ----- docs/source/pyrogram/types/Contact.rst | 5 ----- docs/source/pyrogram/types/Document.rst | 5 ----- docs/source/pyrogram/types/GIF.rst | 5 ----- docs/source/pyrogram/types/InputMediaPhoto.rst | 5 ----- docs/source/pyrogram/types/InputMediaVideo.rst | 5 ----- docs/source/pyrogram/types/InputPhoneContact.rst | 5 ----- docs/source/pyrogram/types/Location.rst | 5 ----- docs/source/pyrogram/types/Message.rst | 5 ----- docs/source/pyrogram/types/MessageEntity.rst | 5 ----- docs/source/pyrogram/types/Messages.rst | 5 ----- docs/source/pyrogram/types/Photo.rst | 5 ----- docs/source/pyrogram/types/PhotoSize.rst | 5 ----- docs/source/pyrogram/types/Sticker.rst | 5 ----- docs/source/pyrogram/types/Update.rst | 5 ----- docs/source/pyrogram/types/User.rst | 5 ----- docs/source/pyrogram/types/UserProfilePhotos.rst | 5 ----- docs/source/pyrogram/types/Venue.rst | 5 ----- docs/source/pyrogram/types/Video.rst | 5 ----- docs/source/pyrogram/types/VideoNote.rst | 5 ----- docs/source/pyrogram/types/Voice.rst | 5 ----- docs/source/pyrogram/types/reply_markup/ForceReply.rst | 5 ----- .../pyrogram/types/reply_markup/InlineKeyboardButton.rst | 5 ----- .../pyrogram/types/reply_markup/InlineKeyboardMarkup.rst | 5 ----- docs/source/pyrogram/types/reply_markup/KeyboardButton.rst | 5 ----- .../pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst | 5 ----- .../pyrogram/types/reply_markup/ReplyKeyboardRemove.rst | 5 ----- 31 files changed, 155 deletions(-) delete mode 100644 docs/source/pyrogram/types/Audio.rst delete mode 100644 docs/source/pyrogram/types/CallbackQuery.rst delete mode 100644 docs/source/pyrogram/types/Chat.rst delete mode 100644 docs/source/pyrogram/types/ChatMember.rst delete mode 100644 docs/source/pyrogram/types/ChatPhoto.rst delete mode 100644 docs/source/pyrogram/types/Contact.rst delete mode 100644 docs/source/pyrogram/types/Document.rst delete mode 100644 docs/source/pyrogram/types/GIF.rst delete mode 100644 docs/source/pyrogram/types/InputMediaPhoto.rst delete mode 100644 docs/source/pyrogram/types/InputMediaVideo.rst delete mode 100644 docs/source/pyrogram/types/InputPhoneContact.rst delete mode 100644 docs/source/pyrogram/types/Location.rst delete mode 100644 docs/source/pyrogram/types/Message.rst delete mode 100644 docs/source/pyrogram/types/MessageEntity.rst delete mode 100644 docs/source/pyrogram/types/Messages.rst delete mode 100644 docs/source/pyrogram/types/Photo.rst delete mode 100644 docs/source/pyrogram/types/PhotoSize.rst delete mode 100644 docs/source/pyrogram/types/Sticker.rst delete mode 100644 docs/source/pyrogram/types/Update.rst delete mode 100644 docs/source/pyrogram/types/User.rst delete mode 100644 docs/source/pyrogram/types/UserProfilePhotos.rst delete mode 100644 docs/source/pyrogram/types/Venue.rst delete mode 100644 docs/source/pyrogram/types/Video.rst delete mode 100644 docs/source/pyrogram/types/VideoNote.rst delete mode 100644 docs/source/pyrogram/types/Voice.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ForceReply.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/KeyboardButton.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst diff --git a/docs/source/pyrogram/types/Audio.rst b/docs/source/pyrogram/types/Audio.rst deleted file mode 100644 index 66ccb32a..00000000 --- a/docs/source/pyrogram/types/Audio.rst +++ /dev/null @@ -1,5 +0,0 @@ -Audio -===== - -.. autoclass:: pyrogram.Audio - :members: diff --git a/docs/source/pyrogram/types/CallbackQuery.rst b/docs/source/pyrogram/types/CallbackQuery.rst deleted file mode 100644 index 9ce0a578..00000000 --- a/docs/source/pyrogram/types/CallbackQuery.rst +++ /dev/null @@ -1,5 +0,0 @@ -CallbackQuery -============= - -.. autoclass:: pyrogram.CallbackQuery - :members: diff --git a/docs/source/pyrogram/types/Chat.rst b/docs/source/pyrogram/types/Chat.rst deleted file mode 100644 index 50a26838..00000000 --- a/docs/source/pyrogram/types/Chat.rst +++ /dev/null @@ -1,5 +0,0 @@ -Chat -==== - -.. autoclass:: pyrogram.Chat - :members: diff --git a/docs/source/pyrogram/types/ChatMember.rst b/docs/source/pyrogram/types/ChatMember.rst deleted file mode 100644 index 0c4f45a3..00000000 --- a/docs/source/pyrogram/types/ChatMember.rst +++ /dev/null @@ -1,5 +0,0 @@ -ChatMember -========== - -.. autoclass:: pyrogram.ChatMember - :members: diff --git a/docs/source/pyrogram/types/ChatPhoto.rst b/docs/source/pyrogram/types/ChatPhoto.rst deleted file mode 100644 index 2b6b49e5..00000000 --- a/docs/source/pyrogram/types/ChatPhoto.rst +++ /dev/null @@ -1,5 +0,0 @@ -ChatPhoto -========= - -.. autoclass:: pyrogram.ChatPhoto - :members: diff --git a/docs/source/pyrogram/types/Contact.rst b/docs/source/pyrogram/types/Contact.rst deleted file mode 100644 index 7d8b0fb2..00000000 --- a/docs/source/pyrogram/types/Contact.rst +++ /dev/null @@ -1,5 +0,0 @@ -Contact -======= - -.. autoclass:: pyrogram.Contact - :members: diff --git a/docs/source/pyrogram/types/Document.rst b/docs/source/pyrogram/types/Document.rst deleted file mode 100644 index 03a57753..00000000 --- a/docs/source/pyrogram/types/Document.rst +++ /dev/null @@ -1,5 +0,0 @@ -Document -======== - -.. autoclass:: pyrogram.Document - :members: diff --git a/docs/source/pyrogram/types/GIF.rst b/docs/source/pyrogram/types/GIF.rst deleted file mode 100644 index 501f187f..00000000 --- a/docs/source/pyrogram/types/GIF.rst +++ /dev/null @@ -1,5 +0,0 @@ -GIF -=== - -.. autoclass:: pyrogram.GIF - :members: diff --git a/docs/source/pyrogram/types/InputMediaPhoto.rst b/docs/source/pyrogram/types/InputMediaPhoto.rst deleted file mode 100644 index aaf8548f..00000000 --- a/docs/source/pyrogram/types/InputMediaPhoto.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputMediaPhoto -=============== - -.. autoclass:: pyrogram.InputMediaPhoto - :members: diff --git a/docs/source/pyrogram/types/InputMediaVideo.rst b/docs/source/pyrogram/types/InputMediaVideo.rst deleted file mode 100644 index 4df4d128..00000000 --- a/docs/source/pyrogram/types/InputMediaVideo.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputMediaVideo -=============== - -.. autoclass:: pyrogram.InputMediaVideo - :members: diff --git a/docs/source/pyrogram/types/InputPhoneContact.rst b/docs/source/pyrogram/types/InputPhoneContact.rst deleted file mode 100644 index bc4e38bc..00000000 --- a/docs/source/pyrogram/types/InputPhoneContact.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputPhoneContact -================= - -.. autoclass:: pyrogram.InputPhoneContact - :members: diff --git a/docs/source/pyrogram/types/Location.rst b/docs/source/pyrogram/types/Location.rst deleted file mode 100644 index 99aeaa70..00000000 --- a/docs/source/pyrogram/types/Location.rst +++ /dev/null @@ -1,5 +0,0 @@ -Location -======== - -.. autoclass:: pyrogram.Location - :members: diff --git a/docs/source/pyrogram/types/Message.rst b/docs/source/pyrogram/types/Message.rst deleted file mode 100644 index 432693fd..00000000 --- a/docs/source/pyrogram/types/Message.rst +++ /dev/null @@ -1,5 +0,0 @@ -Message -======= - -.. autoclass:: pyrogram.Message - :members: diff --git a/docs/source/pyrogram/types/MessageEntity.rst b/docs/source/pyrogram/types/MessageEntity.rst deleted file mode 100644 index 4f2f3be0..00000000 --- a/docs/source/pyrogram/types/MessageEntity.rst +++ /dev/null @@ -1,5 +0,0 @@ -MessageEntity -============= - -.. autoclass:: pyrogram.MessageEntity - :members: diff --git a/docs/source/pyrogram/types/Messages.rst b/docs/source/pyrogram/types/Messages.rst deleted file mode 100644 index f740d092..00000000 --- a/docs/source/pyrogram/types/Messages.rst +++ /dev/null @@ -1,5 +0,0 @@ -Messages -======== - -.. autoclass:: pyrogram.Messages - :members: diff --git a/docs/source/pyrogram/types/Photo.rst b/docs/source/pyrogram/types/Photo.rst deleted file mode 100644 index 78fe13f4..00000000 --- a/docs/source/pyrogram/types/Photo.rst +++ /dev/null @@ -1,5 +0,0 @@ -Photo -===== - -.. autoclass:: pyrogram.Photo - :members: diff --git a/docs/source/pyrogram/types/PhotoSize.rst b/docs/source/pyrogram/types/PhotoSize.rst deleted file mode 100644 index 7ced6190..00000000 --- a/docs/source/pyrogram/types/PhotoSize.rst +++ /dev/null @@ -1,5 +0,0 @@ -PhotoSize -========= - -.. autoclass:: pyrogram.PhotoSize - :members: diff --git a/docs/source/pyrogram/types/Sticker.rst b/docs/source/pyrogram/types/Sticker.rst deleted file mode 100644 index d2646c99..00000000 --- a/docs/source/pyrogram/types/Sticker.rst +++ /dev/null @@ -1,5 +0,0 @@ -Sticker -======= - -.. autoclass:: pyrogram.Sticker - :members: diff --git a/docs/source/pyrogram/types/Update.rst b/docs/source/pyrogram/types/Update.rst deleted file mode 100644 index 1fb22b00..00000000 --- a/docs/source/pyrogram/types/Update.rst +++ /dev/null @@ -1,5 +0,0 @@ -Update -====== - -.. autoclass:: pyrogram.Update - :members: diff --git a/docs/source/pyrogram/types/User.rst b/docs/source/pyrogram/types/User.rst deleted file mode 100644 index f0074a93..00000000 --- a/docs/source/pyrogram/types/User.rst +++ /dev/null @@ -1,5 +0,0 @@ -User -==== - -.. autoclass:: pyrogram.User - :members: diff --git a/docs/source/pyrogram/types/UserProfilePhotos.rst b/docs/source/pyrogram/types/UserProfilePhotos.rst deleted file mode 100644 index 8c9c4d75..00000000 --- a/docs/source/pyrogram/types/UserProfilePhotos.rst +++ /dev/null @@ -1,5 +0,0 @@ -UserProfilePhotos -================= - -.. autoclass:: pyrogram.UserProfilePhotos - :members: diff --git a/docs/source/pyrogram/types/Venue.rst b/docs/source/pyrogram/types/Venue.rst deleted file mode 100644 index 471ab026..00000000 --- a/docs/source/pyrogram/types/Venue.rst +++ /dev/null @@ -1,5 +0,0 @@ -Venue -===== - -.. autoclass:: pyrogram.Venue - :members: diff --git a/docs/source/pyrogram/types/Video.rst b/docs/source/pyrogram/types/Video.rst deleted file mode 100644 index de28ae1c..00000000 --- a/docs/source/pyrogram/types/Video.rst +++ /dev/null @@ -1,5 +0,0 @@ -Video -===== - -.. autoclass:: pyrogram.Video - :members: diff --git a/docs/source/pyrogram/types/VideoNote.rst b/docs/source/pyrogram/types/VideoNote.rst deleted file mode 100644 index 69667454..00000000 --- a/docs/source/pyrogram/types/VideoNote.rst +++ /dev/null @@ -1,5 +0,0 @@ -VideoNote -========= - -.. autoclass:: pyrogram.VideoNote - :members: diff --git a/docs/source/pyrogram/types/Voice.rst b/docs/source/pyrogram/types/Voice.rst deleted file mode 100644 index c80ce124..00000000 --- a/docs/source/pyrogram/types/Voice.rst +++ /dev/null @@ -1,5 +0,0 @@ -Voice -===== - -.. autoclass:: pyrogram.Voice - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ForceReply.rst b/docs/source/pyrogram/types/reply_markup/ForceReply.rst deleted file mode 100644 index db70a834..00000000 --- a/docs/source/pyrogram/types/reply_markup/ForceReply.rst +++ /dev/null @@ -1,5 +0,0 @@ -ForceReply -========== - -.. autoclass:: pyrogram.ForceReply - :members: diff --git a/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst b/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst deleted file mode 100644 index 2e536596..00000000 --- a/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst +++ /dev/null @@ -1,5 +0,0 @@ -InlineKeyboardButton -==================== - -.. autoclass:: pyrogram.InlineKeyboardButton - :members: diff --git a/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst b/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst deleted file mode 100644 index 7ffa2582..00000000 --- a/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst +++ /dev/null @@ -1,5 +0,0 @@ -InlineKeyboardMarkup -==================== - -.. autoclass:: pyrogram.InlineKeyboardMarkup - :members: diff --git a/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst b/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst deleted file mode 100644 index 69488656..00000000 --- a/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst +++ /dev/null @@ -1,5 +0,0 @@ -KeyboardButton -============== - -.. autoclass:: pyrogram.KeyboardButton - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst b/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst deleted file mode 100644 index 2b1e6d16..00000000 --- a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst +++ /dev/null @@ -1,5 +0,0 @@ -ReplyKeyboardMarkup -=================== - -.. autoclass:: pyrogram.ReplyKeyboardMarkup - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst b/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst deleted file mode 100644 index 4146d564..00000000 --- a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst +++ /dev/null @@ -1,5 +0,0 @@ -ReplyKeyboardRemove -=================== - -.. autoclass:: pyrogram.ReplyKeyboardRemove - :members: From fb9fa41c37ad86e108602c17df145411a7427e59 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 25 Jul 2018 22:23:17 +0200 Subject: [PATCH 107/249] Add new Types index page --- docs/source/pyrogram/types/index.rst | 170 ++++++++++++++++++++++++--- 1 file changed, 155 insertions(+), 15 deletions(-) diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index ff3de94e..d93ecceb 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -1,16 +1,34 @@ -:tocdepth: 1 - Types ===== -.. toctree:: +.. currentmodule:: pyrogram + +Users & Chats +------------- + +.. autosummary:: + :nosignatures: + User Chat + ChatPhoto + ChatMember + ChatMembers + Dialog + Dialogs + +Messages & Media +---------------- + +.. autosummary:: + :nosignatures: + Message - MessageEntity Messages + MessageEntity Photo PhotoSize + UserProfilePhotos Audio Document GIF @@ -20,17 +38,139 @@ Types Contact Location Venue - UserProfilePhotos - ChatPhoto - ChatMember + Sticker + +Bots +---- + +.. autosummary:: + :nosignatures: + + ReplyKeyboardMarkup + KeyboardButton + ReplyKeyboardRemove + InlineKeyboardMarkup + InlineKeyboardButton + ForceReply + CallbackQuery + +Input Media +----------- + +.. autosummary:: + :nosignatures: + InputMediaPhoto InputMediaVideo InputPhoneContact - Sticker - reply_markup/ForceReply - reply_markup/InlineKeyboardButton - reply_markup/InlineKeyboardMarkup - reply_markup/KeyboardButton - reply_markup/ReplyKeyboardMarkup - reply_markup/ReplyKeyboardRemove - CallbackQuery \ No newline at end of file + +.. User & Chats + ------------ + +.. autoclass:: User + :members: + +.. autoclass:: Chat + :members: + +.. autoclass:: ChatPhoto + :members: + +.. autoclass:: ChatMember + :members: + +.. autoclass:: ChatMembers + :members: + +.. autoclass:: Dialog + :members: + +.. autoclass:: Dialogs + :members: + +.. Messages & Media + ---------------- + +.. autoclass:: Message + :members: + +.. autoclass:: Messages + :members: + +.. autoclass:: MessageEntity + :members: + +.. autoclass:: Photo + :members: + +.. autoclass:: PhotoSize + :members: + +.. autoclass:: UserProfilePhotos + :members: + +.. autoclass:: Audio + :members: + +.. autoclass:: Document + :members: + +.. autoclass:: GIF + :members: + +.. autoclass:: Video + :members: + +.. autoclass:: Voice + :members: + +.. autoclass:: VideoNote + :members: + +.. autoclass:: Contact + :members: + +.. autoclass:: Location + :members: + +.. autoclass:: Venue + :members: + +.. autoclass:: Sticker + :members: + +.. Bots + ---- + +.. autoclass:: ReplyKeyboardMarkup + :members: + +.. autoclass:: KeyboardButton + :members: + +.. autoclass:: ReplyKeyboardRemove + :members: + +.. autoclass:: InlineKeyboardMarkup + :members: + +.. autoclass:: InlineKeyboardButton + :members: + +.. autoclass:: ForceReply + :members: + +.. autoclass:: CallbackQuery + :members: + +.. Input Media + ----------- + +.. autoclass:: InputMediaPhoto + :members: + +.. autoclass:: InputMediaVideo + :members: + +.. autoclass:: InputPhoneContact + :members: From e9cba4609a8b6b97ecde2565dba0f1e45162d47e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:32:12 +0200 Subject: [PATCH 108/249] Update get_chat_member docstrings --- pyrogram/client/methods/chats/get_chat_member.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index c4fe0715..be2a77b9 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -24,7 +24,7 @@ class GetChatMember(BaseClient): def get_chat_member(self, chat_id: int or str, user_id: int or str): - """Use this method to get information about a single member of a chat. + """Use this method to get information about one member of a chat. Args: chat_id (``int`` | ``str``): From f4175b041c34cc42715ce0488fad83a87867407a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:34:21 +0200 Subject: [PATCH 109/249] Document ChatMembers --- pyrogram/client/types/chat_members.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/chat_members.py index 658a3086..622f8abc 100644 --- a/pyrogram/client/types/chat_members.py +++ b/pyrogram/client/types/chat_members.py @@ -20,7 +20,15 @@ from pyrogram.api.core import Object class ChatMembers(Object): - # TODO: Docstrings + """This object contains information about the members list of a chat. + + Args: + total_count (``int``): + Total number of members the chat has. + + chat_members (List of :obj:`ChatMember `): + Requested chat members. + """ ID = 0xb0700030 From 32468e5ab0359f2eba1d79f29b0c66210520f976 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 27 Jul 2018 00:40:08 +0200 Subject: [PATCH 110/249] Remove hints about using t.me/joinchat/ links as chat ids Such links don't work reliably with the current implementation --- pyrogram/client/methods/bots/request_callback_answer.py | 1 - pyrogram/client/methods/bots/send_inline_bot_result.py | 1 - pyrogram/client/methods/chats/delete_chat_photo.py | 1 - pyrogram/client/methods/chats/get_chat.py | 1 - pyrogram/client/methods/chats/get_chat_member.py | 2 -- pyrogram/client/methods/chats/get_chat_members.py | 1 - pyrogram/client/methods/chats/kick_chat_member.py | 1 - pyrogram/client/methods/chats/pin_chat_message.py | 1 - pyrogram/client/methods/chats/promote_chat_member.py | 1 - pyrogram/client/methods/chats/restrict_chat_member.py | 1 - pyrogram/client/methods/chats/set_chat_description.py | 1 - pyrogram/client/methods/chats/set_chat_photo.py | 1 - pyrogram/client/methods/chats/set_chat_title.py | 1 - pyrogram/client/methods/chats/unban_chat_member.py | 1 - pyrogram/client/methods/chats/unpin_chat_message.py | 1 - pyrogram/client/methods/messages/delete_messages.py | 1 - pyrogram/client/methods/messages/edit_message_caption.py | 1 - pyrogram/client/methods/messages/edit_message_reply_markup.py | 1 - pyrogram/client/methods/messages/edit_message_text.py | 1 - pyrogram/client/methods/messages/forward_messages.py | 2 -- pyrogram/client/methods/messages/get_history.py | 1 - pyrogram/client/methods/messages/get_messages.py | 1 - pyrogram/client/methods/messages/send_audio.py | 1 - pyrogram/client/methods/messages/send_chat_action.py | 1 - pyrogram/client/methods/messages/send_contact.py | 1 - pyrogram/client/methods/messages/send_document.py | 1 - pyrogram/client/methods/messages/send_gif.py | 1 - pyrogram/client/methods/messages/send_location.py | 1 - pyrogram/client/methods/messages/send_media_group.py | 1 - pyrogram/client/methods/messages/send_message.py | 1 - pyrogram/client/methods/messages/send_photo.py | 1 - pyrogram/client/methods/messages/send_sticker.py | 1 - pyrogram/client/methods/messages/send_venue.py | 1 - pyrogram/client/methods/messages/send_video.py | 1 - pyrogram/client/methods/messages/send_video_note.py | 1 - pyrogram/client/methods/messages/send_voice.py | 1 - pyrogram/client/methods/users/get_user_profile_photos.py | 1 - pyrogram/client/types/message.py | 1 - 38 files changed, 40 deletions(-) diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index 52dab58c..b242f4af 100644 --- a/pyrogram/client/methods/bots/request_callback_answer.py +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -33,7 +33,6 @@ class RequestCallbackAnswer(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): The message id the inline keyboard is attached on. diff --git a/pyrogram/client/methods/bots/send_inline_bot_result.py b/pyrogram/client/methods/bots/send_inline_bot_result.py index c194298a..bdfcc65c 100644 --- a/pyrogram/client/methods/bots/send_inline_bot_result.py +++ b/pyrogram/client/methods/bots/send_inline_bot_result.py @@ -35,7 +35,6 @@ class SendInlineBotResult(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. query_id (``int``): Unique identifier for the answered query. diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index 57d90b11..31e02923 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -33,7 +33,6 @@ class DeleteChatPhoto(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: True on success. diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index 588ac468..5cb22db1 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -28,7 +28,6 @@ class GetChat(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: On success, a :obj:`Chat ` object is returned. diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index be2a77b9..51e07f91 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -29,13 +29,11 @@ class GetChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``):: Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: On success, a :obj:`ChatMember ` object is returned. diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index cfc9861e..818c667e 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -44,7 +44,6 @@ class GetChatMembers(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*): Sequential number of the first member to be returned. diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 6275718c..1c849285 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -38,7 +38,6 @@ class KickChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index e9bc533e..eb653f3c 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -29,7 +29,6 @@ class PinChatMessage(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Identifier of a message to pin. diff --git a/pyrogram/client/methods/chats/promote_chat_member.py b/pyrogram/client/methods/chats/promote_chat_member.py index eb70578a..134d1ba3 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -39,7 +39,6 @@ class PromoteChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index ae1e4d9c..fb11a989 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -36,7 +36,6 @@ class RestrictChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index c9597a62..f9b5c7a2 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -28,7 +28,6 @@ class SetChatDescription(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. description (``str``): New chat description, 0-255 characters. diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index d98fefde..224a8d99 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -37,7 +37,6 @@ class SetChatPhoto(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. photo (``str``): New chat photo. You can pass a :class:`Photo` id or a file path to upload a new photo. diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py index f6644a01..98da8737 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -33,7 +33,6 @@ class SetChatTitle(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. title (``str``): New chat title, 1-255 characters. diff --git a/pyrogram/client/methods/chats/unban_chat_member.py b/pyrogram/client/methods/chats/unban_chat_member.py index b0916eb4..e191a0b7 100644 --- a/pyrogram/client/methods/chats/unban_chat_member.py +++ b/pyrogram/client/methods/chats/unban_chat_member.py @@ -31,7 +31,6 @@ class UnbanChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py index b1eeec79..4b0ee46b 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -29,7 +29,6 @@ class UnpinChatMessage(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: True on success. diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index a4c97c76..8932a699 100644 --- a/pyrogram/client/methods/messages/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -38,7 +38,6 @@ class DeleteMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers to delete or a single message id. diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index 25276dc2..a83c670e 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -34,7 +34,6 @@ class EditMessageCaption(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py index b840adab..6d846ca4 100644 --- a/pyrogram/client/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -32,7 +32,6 @@ class EditMessageReplyMarkup(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py index 741c0890..379a1988 100644 --- a/pyrogram/client/methods/messages/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -35,7 +35,6 @@ class EditMessageText(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index 606e54b5..2b24aadf 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -33,13 +33,11 @@ class ForwardMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. from_chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the source chat where the original message was sent. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers in the chat specified in *from_chat_id* or a single message id. diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index 4089dde9..66949a1c 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -37,7 +37,6 @@ class GetHistory(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*) Sequential number of the first message to be returned. diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 3c8b4dbe..c2751d74 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -33,7 +33,6 @@ class GetMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers in the chat specified in *chat_id* or a single message id, as integer. diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 7d590b79..f31ffa21 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -49,7 +49,6 @@ class SendAudio(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. audio (``str``): Audio file to send. diff --git a/pyrogram/client/methods/messages/send_chat_action.py b/pyrogram/client/methods/messages/send_chat_action.py index 49625b48..1117a2dd 100644 --- a/pyrogram/client/methods/messages/send_chat_action.py +++ b/pyrogram/client/methods/messages/send_chat_action.py @@ -32,7 +32,6 @@ class SendChatAction(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. action (:obj:`ChatAction ` | ``str``): Type of action to broadcast. diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index 1a894e30..99a96abc 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -37,7 +37,6 @@ class SendContact(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. phone_number (``str``): Contact's phone number. diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index b2b5c532..01c3eca5 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -44,7 +44,6 @@ class SendDocument(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. document (``str``): File to send. diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_gif.py index a4a14d84..ca323f1d 100644 --- a/pyrogram/client/methods/messages/send_gif.py +++ b/pyrogram/client/methods/messages/send_gif.py @@ -48,7 +48,6 @@ class SendGIF(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. gif (``str``): GIF to send. diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index a3db2561..49a41256 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -35,7 +35,6 @@ class SendLocation(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. latitude (``float``): Latitude of the location. diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index 297d8f83..5465c9f2 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -44,7 +44,6 @@ class SendMediaGroup(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. media (``list``): A list containing either :obj:`InputMediaPhoto ` or diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index 44acaa2e..b770133e 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -37,7 +37,6 @@ class SendMessage(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. text (``str``): Text of the message to be sent. diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index a6264bf3..2d0036f2 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -44,7 +44,6 @@ class SendPhoto(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. photo (``str``): Photo to send. diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index fbf7a205..9f1f64da 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -41,7 +41,6 @@ class SendSticker(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. sticker (``str``): Sticker to send. diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 50946e86..39ae0ca2 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -38,7 +38,6 @@ class SendVenue(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. latitude (``float``): Latitude of the venue. diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index b86b4702..87063ee3 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -49,7 +49,6 @@ class SendVideo(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. video (``str``): Video to send. diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index a266e5dd..6adc6497 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -44,7 +44,6 @@ class SendVideoNote(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. video_note (``str``): Video note to send. diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index f4fe4229..5b577672 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -45,7 +45,6 @@ class SendVoice(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. voice (``str``): Audio file to send. diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 5613c21d..127ad232 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -32,7 +32,6 @@ class GetUserProfilePhotos(BaseClient): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*): Sequential number of the first photo to be returned. diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index db13ccd6..e471c8a5 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -404,7 +404,6 @@ class Message(Object): Unique identifier (int) or username (str) of the target chat. 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). - For a private channel/supergroup you can use its *t.me/joinchat/* link. disable_notification (``bool``, *optional*): Sends the message silently. From d270d0d2aa5ad819f4058773a237471b53e97425 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 28 Jul 2018 23:09:44 +0200 Subject: [PATCH 111/249] Remove support for t.me/joinchat/ links in resolve_peer for now Another way, which is 100% reliable, will be implemented Also clean the method a bit by removing useless checks --- pyrogram/client/client.py | 41 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 709ea95a..3af60931 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1011,21 +1011,19 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() def resolve_peer(self, peer_id: int or str): - """Use this method to get the *InputPeer* of a known *peer_id*. + """Use this method to get the InputPeer of a known peer_id. - It is intended to be used when working with Raw Functions (i.e: a Telegram API method you wish to use which is - not available yet in the Client class as an easy-to-use method). + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. Args: - peer_id (``int`` | ``str`` | ``Peer``): - The Peer ID you want to extract the InputPeer from. Can be one of these types: ``int`` (direct ID), - ``str`` (@username), :obj:`PeerUser `, - :obj:`PeerChat `, :obj:`PeerChannel ` + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). Returns: - :obj:`InputPeerUser ` or - :obj:`InputPeerChat ` or - :obj:`InputPeerChannel ` depending on the *peer_id*. + On success, the resolved peer id is returned in form of an InputPeer object. Raises: :class:`Error ` @@ -1034,38 +1032,21 @@ class Client(Methods, BaseClient): if peer_id in ("self", "me"): return types.InputPeerSelf() - match = self.INVITE_LINK_RE.match(peer_id) - - try: - decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), "-_") - return self.resolve_peer(struct.unpack(">2iq", decoded)[1]) - except (AttributeError, binascii.Error, struct.error): - pass - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) try: int(peer_id) except ValueError: - try: - return self.peers_by_username[peer_id] - except KeyError: + if peer_id not in self.peers_by_username: self.send(functions.contacts.ResolveUsername(peer_id)) - return self.peers_by_username[peer_id] + + return self.peers_by_username[peer_id] else: try: return self.peers_by_phone[peer_id] except KeyError: raise PeerIdInvalid - if type(peer_id) is not int: - if isinstance(peer_id, types.PeerUser): - peer_id = peer_id.user_id - elif isinstance(peer_id, types.PeerChat): - peer_id = -peer_id.chat_id - elif isinstance(peer_id, types.PeerChannel): - peer_id = int("-100" + str(peer_id.channel_id)) - try: # User return self.peers_by_id[peer_id] except KeyError: From e682046713174951d341ef4f0fae9563b0bb3dac Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:37:50 +0200 Subject: [PATCH 112/249] Fix sphinx compilation warnings --- docs/source/resources/TextFormatting.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index aaa78f0a..9b4e2e4c 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -11,7 +11,7 @@ Markdown Style To use this mode, pass :obj:`MARKDOWN ` or "markdown" in the *parse_mode* field when using :obj:`send_message() `. Use the following syntax in your message: -.. code-block:: txt +.. code-block:: text **bold text** @@ -34,7 +34,7 @@ HTML Style To use this mode, pass :obj:`HTML ` or "html" in the *parse_mode* field when using :obj:`send_message() `. The following tags are currently supported: -.. code-block:: txt +.. code-block:: text bold, bold From faef1526a9a1f423c489bd6bd91eeaba81d2087b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:38:30 +0200 Subject: [PATCH 113/249] Tidy up HTML syntax example --- docs/source/resources/TextFormatting.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index 9b4e2e4c..dd619469 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -46,9 +46,7 @@ To use this mode, pass :obj:`HTML ` or "html" in the *p inline fixed-width code -
pre-formatted fixed-width
-    code block
-    
+
pre-formatted fixed-width code block
.. note:: Mentions are only guaranteed to work if you have already met the user (in groups or private chats). From 97f3921729692bf985f8efa3dec4107e8771882b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:40:04 +0200 Subject: [PATCH 114/249] Use clearer words and spacing --- docs/source/resources/TextFormatting.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index dd619469..0ab08694 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -1,8 +1,11 @@ Text Formatting =============== -Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for text messages and -media captions; Markdown uses the same syntax as Telegram Desktop's and is enabled by default. +Pyrogram, just like the `Telegram Bot API`_, natively supports basic Markdown and HTML formatting styles for text +messages and media captions. + +Markdown style uses the same syntax as Telegram Desktop's and is enabled by default. + Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**. Markdown Style From 9d9fc1f94f8547790826b9dcacea3366c1c82542 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 22:59:30 +0200 Subject: [PATCH 115/249] Add InputMedia base class --- pyrogram/client/types/input_media.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pyrogram/client/types/input_media.py diff --git a/pyrogram/client/types/input_media.py b/pyrogram/client/types/input_media.py new file mode 100644 index 00000000..611d5865 --- /dev/null +++ b/pyrogram/client/types/input_media.py @@ -0,0 +1,24 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + + +class InputMedia: + def __init__(self, media: str, caption: str, parse_mode: str): + self.media = media + self.caption = caption + self.parse_mode = parse_mode From 486c9433ace001450c9f958d713f283edb63fc67 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 23:01:14 +0200 Subject: [PATCH 116/249] Make InputMediaPhoto inherit from InputMedia --- pyrogram/client/types/input_media_photo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/input_media_photo.py b/pyrogram/client/types/input_media_photo.py index 336ee849..d58f75a6 100644 --- a/pyrogram/client/types/input_media_photo.py +++ b/pyrogram/client/types/input_media_photo.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from . import InputMedia -class InputMediaPhoto: + +class InputMediaPhoto(InputMedia): """This object represents a photo to be sent inside an album. It is intended to be used with :obj:`send_media_group() `. @@ -41,6 +43,4 @@ class InputMediaPhoto: media: str, caption: str = "", parse_mode: str = ""): - self.media = media - self.caption = caption - self.parse_mode = parse_mode + super().__init__(media, caption, parse_mode) From 2a985e75455856516359563e977e21788af06885 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 23:01:43 +0200 Subject: [PATCH 117/249] Make InputMediaVideo inherit from InputMedia --- pyrogram/client/types/input_media_video.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/input_media_video.py b/pyrogram/client/types/input_media_video.py index eb6c003e..c1f2c9ac 100644 --- a/pyrogram/client/types/input_media_video.py +++ b/pyrogram/client/types/input_media_video.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from . import InputMedia -class InputMediaVideo: + +class InputMediaVideo(InputMedia): """This object represents a video to be sent inside an album. It is intended to be used with :obj:`send_media_group() `. @@ -57,9 +59,8 @@ class InputMediaVideo: height: int = 0, duration: int = 0, supports_streaming: bool = True): - self.media = media - self.caption = caption - self.parse_mode = parse_mode + super().__init__(media, caption, parse_mode) + self.width = width self.height = height self.duration = duration From 5bc9be08586517a5c783da3d1a539bba3734ad10 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:14:21 +0200 Subject: [PATCH 118/249] Add InputMediaAudio --- pyrogram/client/types/input_media_audio.py | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 pyrogram/client/types/input_media_audio.py diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media_audio.py new file mode 100644 index 00000000..c556554f --- /dev/null +++ b/pyrogram/client/types/input_media_audio.py @@ -0,0 +1,67 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from . import InputMedia + + +class InputMediaAudio(InputMedia): + """This object represents a video to be sent inside an album. + It is intended to be used with :obj:`send_media_group() `. + + Args: + media (``str``): + Video to send. + Pass a file_id as string to send a video that exists on the Telegram servers or + 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. + + caption (``str``, *optional*): + Caption of the video to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + + width (``int``, *optional*): + Video width. + + height (``int``, *optional*): + Video height. + + duration (``int``, *optional*): + Video duration. + + supports_streaming (``bool``, *optional*): + Pass True, if the uploaded video is suitable for streaming. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + width: int = 0, + height: int = 0, + duration: int = 0, + supports_streaming: bool = True): + super().__init__(media, caption, parse_mode) + + self.width = width + self.height = height + self.duration = duration + self.supports_streaming = supports_streaming From 570128d980a0be22d1b99fe2c0c8d40f282af413 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:25:41 +0200 Subject: [PATCH 119/249] Add InputMediaAnimation --- .../client/types/input_media_animation.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pyrogram/client/types/input_media_animation.py diff --git a/pyrogram/client/types/input_media_animation.py b/pyrogram/client/types/input_media_animation.py new file mode 100644 index 00000000..12fe0e03 --- /dev/null +++ b/pyrogram/client/types/input_media_animation.py @@ -0,0 +1,60 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from . import InputMedia + + +class InputMediaAnimation(InputMedia): + """This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. + + Args: + media (``str``): + Animation to send. + 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. + + caption (``str``, *optional*): + Caption of the animation to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + + width (``int``, *optional*): + Animation width. + + height (``int``, *optional*): + Animation height. + + duration (``int``, *optional*): + Animation duration. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + width: int = 0, + height: int = 0, + duration: int = 0): + super().__init__(media, caption, parse_mode) + + self.width = width + self.height = height + self.duration = duration From c62575674717c51d9dbbf2be7d8b8e366dee29b7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:29:10 +0200 Subject: [PATCH 120/249] Add InputMediaDocument --- pyrogram/client/types/input_media_document.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pyrogram/client/types/input_media_document.py diff --git a/pyrogram/client/types/input_media_document.py b/pyrogram/client/types/input_media_document.py new file mode 100644 index 00000000..f64da619 --- /dev/null +++ b/pyrogram/client/types/input_media_document.py @@ -0,0 +1,44 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from . import InputMedia + + +class InputMediaDocument(InputMedia): + """This object represents a general file to be sent. + + Args: + media (``str``): + File to send. + 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. + + caption (``str``, *optional*): + Caption of the document to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = ""): + super().__init__(media, caption, parse_mode) From 92fdf79d545121e18bb5636a285339a5429ef9fc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 1 Aug 2018 21:19:11 +0200 Subject: [PATCH 121/249] Expose the new InputMedia types --- pyrogram/__init__.py | 9 ++++----- pyrogram/client/types/__init__.py | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index f1442596..24bdc1a5 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -28,11 +28,10 @@ __version__ = "0.7.6dev1" from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, - InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, - Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, - InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, - ReplyKeyboardRemove + InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, + Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, + UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, + InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index e6fcc8aa..23c15818 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -23,6 +23,10 @@ from .chat_members import ChatMembers from .chat_photo import ChatPhoto from .dialog import Dialog from .dialogs import Dialogs +from .input_media import InputMedia +from .input_media_animation import InputMediaAnimation +from .input_media_audio import InputMediaAudio +from .input_media_document import InputMediaDocument from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo from .input_phone_contact import InputPhoneContact From ea0a75bfd702f512f3a1815d82669bb913aa8a63 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 2 Aug 2018 01:10:29 +0200 Subject: [PATCH 122/249] Add edit_message_media method --- .../methods/messages/edit_message_media.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pyrogram/client/methods/messages/edit_message_media.py diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py new file mode 100644 index 00000000..56295749 --- /dev/null +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -0,0 +1,36 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions +from pyrogram.client.ext import BaseClient + + +class EditMessageMedia(BaseClient): + def edit_message_media(self, + chat_id: int or str, + message_id: int, + media, + reply_markup=None): + r = self.send( + functions.messages.EditMessage( + peer=self.resolve_peer(chat_id), + id=message_id, + reply_markup=reply_markup.write() if reply_markup else None, + media=media + ) + ) From e7b27c2c21e567caece838f970c16995b879da1d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 2 Aug 2018 01:12:31 +0200 Subject: [PATCH 123/249] Expose edit_message_media method --- pyrogram/client/methods/messages/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 94279ffd..6de17d7c 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -18,6 +18,7 @@ from .delete_messages import DeleteMessages from .edit_message_caption import EditMessageCaption +from .edit_message_media import EditMessageMedia from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages @@ -44,6 +45,7 @@ class Messages( DeleteMessages, EditMessageCaption, EditMessageReplyMarkup, + EditMessageMedia, EditMessageText, ForwardMessages, GetHistory, From 6015a14182644b57f76560e74006cdbac4af0574 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:36:38 +0200 Subject: [PATCH 124/249] Add ability to edit photos by uploading new files --- .../methods/messages/edit_message_media.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 56295749..dfee76a8 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -16,8 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api import functions +import os + +from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient +from pyrogram.client.types import ( + InputMediaPhoto +) class EditMessageMedia(BaseClient): @@ -26,11 +31,33 @@ class EditMessageMedia(BaseClient): message_id: int, media, reply_markup=None): + style = self.html if media.parse_mode.lower() == "html" else self.markdown + caption = media.caption + + if isinstance(media, InputMediaPhoto): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedPhoto( + file=self.save_file(media.media) + ) + ) + ) + + media = types.InputMediaPhoto( + id=types.InputPhoto( + id=media.photo.id, + access_hash=media.photo.access_hash + ) + ) + r = self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), id=message_id, reply_markup=reply_markup.write() if reply_markup else None, - media=media + media=media, + **style.parse(caption) ) ) From 8d35559f0bee7ebcba8e8bde294033020dd3e132 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:37:10 +0200 Subject: [PATCH 125/249] Return the higher-level Message object instead of the raw update --- pyrogram/client/methods/messages/edit_message_media.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index dfee76a8..1e42c304 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -19,7 +19,7 @@ import os from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient +from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto ) @@ -61,3 +61,11 @@ class EditMessageMedia(BaseClient): **style.parse(caption) ) ) + + for i in r.updates: + if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): + return utils.parse_messages( + self, i.message, + {i.id: i for i in r.users}, + {i.id: i for i in r.chats} + ) From a3be6a93550423b3ab35529ab397e5738266ea9f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:38:04 +0200 Subject: [PATCH 126/249] Add support for editing photos with external URLs --- pyrogram/client/methods/messages/edit_message_media.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 1e42c304..35c24f1a 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -51,6 +51,10 @@ class EditMessageMedia(BaseClient): access_hash=media.photo.access_hash ) ) + elif media.media.startswith("http"): + media = types.InputMediaPhotoExternal( + url=media.media + ) r = self.send( functions.messages.EditMessage( From 51eb2f90b983ae53f5116c2a7bfab07875efd133 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:38:26 +0200 Subject: [PATCH 127/249] Add support for editing photousing file IDs --- .../methods/messages/edit_message_media.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 35c24f1a..d79ecfbe 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -16,9 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import binascii import os +import struct from pyrogram.api import functions, types +from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto @@ -55,6 +58,28 @@ class EditMessageMedia(BaseClient): media = types.InputMediaPhotoExternal( url=media.media ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Sat, 4 Aug 2018 01:23:31 +0200 Subject: [PATCH 128/249] Add ability to edit video messages --- .../methods/messages/edit_message_media.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index d79ecfbe..02b9062d 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import binascii +import mimetypes import os import struct @@ -24,7 +25,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto + InputMediaPhoto, InputMediaVideo ) @@ -81,6 +82,34 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaVideo): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map[".mp4"], + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeVideo( + supports_streaming=media.supports_streaming or None, + duration=media.duration, + w=media.width, + h=media.height + ), + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + r = self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), From 9f725a6bfb299bac73f6d3fe83f11d4a8d8c92c1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 4 Aug 2018 01:27:02 +0200 Subject: [PATCH 129/249] Add support for editing videos using external URLs and file IDs --- .../methods/messages/edit_message_media.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 02b9062d..2ca9ab9f 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -109,6 +109,32 @@ class EditMessageMedia(BaseClient): access_hash=media.document.access_hash ) ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Sun, 5 Aug 2018 10:15:53 +0200 Subject: [PATCH 130/249] Fix InputMediaAudio copy pasta --- pyrogram/client/types/input_media_audio.py | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media_audio.py index c556554f..2c644107 100644 --- a/pyrogram/client/types/input_media_audio.py +++ b/pyrogram/client/types/input_media_audio.py @@ -25,43 +25,37 @@ class InputMediaAudio(InputMedia): Args: media (``str``): - Video to send. - Pass a file_id as string to send a video that exists on the Telegram servers or - 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. + Audio to send. + 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. caption (``str``, *optional*): - Caption of the video to be sent, 0-200 characters + Caption of the audio to be sent, 0-200 characters parse_mode (``str``, *optional*): Use :obj:`MARKDOWN ` or :obj:`HTML ` if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown. - width (``int``, *optional*): - Video width. - - height (``int``, *optional*): - Video height. - duration (``int``, *optional*): - Video duration. + Duration of the audio in seconds - supports_streaming (``bool``, *optional*): - Pass True, if the uploaded video is suitable for streaming. + performer (``int``, *optional*): + Performer of the audio + + title (``int``, *optional*): + Title of the audio """ def __init__(self, media: str, caption: str = "", parse_mode: str = "", - width: int = 0, - height: int = 0, duration: int = 0, - supports_streaming: bool = True): + performer: int = "", + title: str = ""): super().__init__(media, caption, parse_mode) - self.width = width - self.height = height self.duration = duration - self.supports_streaming = supports_streaming + self.performer = performer + self.title = title From f7c2dc9d30ff8cfb6a39cda9e3f1b02e5755e87a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 5 Aug 2018 10:25:37 +0200 Subject: [PATCH 131/249] Add support for editing messages with Audio --- .../methods/messages/edit_message_media.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 2ca9ab9f..c6b2eb97 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -25,7 +25,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto, InputMediaVideo + InputMediaPhoto, InputMediaVideo, InputMediaAudio ) @@ -136,6 +136,59 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaAudio): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "audio/mpeg"), + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeAudio( + duration=media.duration, + performer=media.performer, + title=media.title + ), + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Mon, 6 Aug 2018 21:32:38 +0200 Subject: [PATCH 132/249] Rename media type id to animation --- pyrogram/client/ext/base_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index cd54570d..c8a6029d 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -60,7 +60,7 @@ class BaseClient: 5: "document", 8: "sticker", 9: "audio", - 10: "gif", + 10: "animation", 13: "video_note" } From b1c12c323236e9a6a8f5e60a5eb0d3aff9808ffc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 6 Aug 2018 21:38:44 +0200 Subject: [PATCH 133/249] Rename GIF to Animation --- pyrogram/__init__.py | 2 +- pyrogram/client/ext/utils.py | 6 +++--- pyrogram/client/methods/download_media.py | 2 +- pyrogram/client/types/__init__.py | 2 +- pyrogram/client/types/media/__init__.py | 2 +- .../client/types/media/{gif.py => animation.py} | 16 ++++++++-------- pyrogram/client/types/message.py | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) rename pyrogram/client/types/media/{gif.py => animation.py} (82%) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 24bdc1a5..a822524c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -30,7 +30,7 @@ from .client.types import ( Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, - UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, + UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .client import ( diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a99ee066..c1d859d0 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -293,7 +293,7 @@ def parse_messages( venue = None audio = None voice = None - gif = None + animation = None video = None video_note = None sticker = None @@ -432,7 +432,7 @@ def parse_messages( elif types.DocumentAttributeAnimated in attributes: video_attributes = attributes.get(types.DocumentAttributeVideo, None) - gif = pyrogram_types.GIF( + animation = pyrogram_types.Animation( file_id=encode( pack( ". +from .animation import Animation from .audio import Audio from .contact import Contact from .document import Document -from .gif import GIF from .location import Location from .photo import Photo from .photo_size import PhotoSize diff --git a/pyrogram/client/types/media/gif.py b/pyrogram/client/types/media/animation.py similarity index 82% rename from pyrogram/client/types/media/gif.py rename to pyrogram/client/types/media/animation.py index 5172aae2..85d5a365 100644 --- a/pyrogram/client/types/media/gif.py +++ b/pyrogram/client/types/media/animation.py @@ -19,27 +19,27 @@ from pyrogram.api.core import Object -class GIF(Object): - """This object represents a GIF file. +class Animation(Object): + """This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). Args: file_id (``str``): Unique identifier for this file. width (``int``): - GIF width as defined by sender. + Animation width as defined by sender. height (``int``): - GIF height as defined by sender. + Animation height as defined by sender. duration (``int``): - Duration of the GIF in seconds as defined by sender. + Duration of the animation in seconds as defined by sender. thumb (:obj:`PhotoSize `, *optional*): - GIF thumbnail. + Animation thumbnail. file_name (``str``, *optional*): - GIF file name. + Animation file name. mime_type (``str``, *optional*): Mime type of a file as defined by sender. @@ -48,7 +48,7 @@ class GIF(Object): File size. date (``int``, *optional*): - Date the GIF was sent in Unix time. + Date the Animation was sent in Unix time. """ ID = 0xb0700025 diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index e471c8a5..7b05bfac 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -92,8 +92,8 @@ class Message(Object): sticker (:obj:`Sticker `, *optional*): Message is a sticker, information about the sticker. - gif (:obj:`Video `, *optional*): - Message is a GIF, information about the GIF. + animation (:obj:`Animation `, *optional*): + Message is an animation, information about the animation. video (:obj:`Video `, *optional*): Message is a video, information about the video. @@ -228,7 +228,7 @@ class Message(Object): game=None, photo=None, sticker=None, - gif=None, + animation=None, video=None, voice=None, video_note=None, @@ -279,7 +279,7 @@ class Message(Object): self.game = game # flags.15?Game self.photo = photo # flags.16?Vector self.sticker = sticker # flags.17?Sticker - self.gif = gif + self.animation = animation self.video = video # flags.18?Video self.voice = voice # flags.19?Voice self.video_note = video_note # flags.20?VideoNote From 2b793dd2a170dd4a0df20b7c17e9a45b4884e4d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 7 Aug 2018 01:23:52 +0200 Subject: [PATCH 134/249] Refactor send_gif. It is now called send_animation --- pyrogram/client/methods/messages/__init__.py | 4 +- pyrogram/client/methods/messages/send_gif.py | 66 ++++++++++---------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 6de17d7c..8bf3bc14 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -29,7 +29,7 @@ from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_gif import SendGIF +from .send_gif import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage @@ -55,7 +55,7 @@ class Messages( SendChatAction, SendContact, SendDocument, - SendGIF, + SendAnimation, SendLocation, SendMediaGroup, SendMessage, diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_gif.py index ca323f1d..55123332 100644 --- a/pyrogram/client/methods/messages/send_gif.py +++ b/pyrogram/client/methods/messages/send_gif.py @@ -26,22 +26,22 @@ from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils -class SendGIF(BaseClient): - def send_gif(self, - chat_id: int or str, - gif: str, - caption: str = "", - parse_mode: str = "", - duration: int = 0, - width: int = 0, - height: int = 0, - thumb: str = None, - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup=None, - progress: callable = None, - progress_args: tuple = ()): - """Use this method to send GIF files. +class SendAnimation(BaseClient): + def send_animation(self, + chat_id: int or str, + animation: str, + caption: str = "", + parse_mode: str = "", + duration: int = 0, + width: int = 0, + height: int = 0, + thumb: str = None, + disable_notification: bool = None, + reply_to_message_id: int = None, + reply_markup=None, + progress: callable = None, + progress_args: tuple = ()): + """Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound). Args: chat_id (``int`` | ``str``): @@ -49,14 +49,14 @@ class SendGIF(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). - gif (``str``): - GIF to send. - Pass a file_id as string to send a GIF that exists on the Telegram servers, - pass an HTTP URL as a string for Telegram to get a GIF from the Internet, or - pass a file path as string to upload a new GIF that exists on your local machine. + animation (``str``): + Animation to send. + Pass a file_id as string to send an animation that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get an animation from the Internet, or + pass a file path as string to upload a new animation that exists on your local machine. caption (``str``, *optional*): - GIF caption, 0-200 characters. + Animation caption, 0-200 characters. parse_mode (``str``, *optional*): Use :obj:`MARKDOWN ` or :obj:`HTML ` @@ -64,16 +64,16 @@ class SendGIF(BaseClient): Defaults to Markdown. duration (``int``, *optional*): - Duration of sent GIF in seconds. + Duration of sent animation in seconds. width (``int``, *optional*): - GIF width. + Animation width. height (``int``, *optional*): - GIF height. + Animation height. thumb (``str``, *optional*): - GIF thumbnail. + 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. @@ -120,9 +120,9 @@ class SendGIF(BaseClient): file = None style = self.html if parse_mode.lower() == "html" else self.markdown - if os.path.exists(gif): + if os.path.exists(animation): thumb = None if thumb is None else self.save_file(thumb) - file = self.save_file(gif, progress=progress, progress_args=progress_args) + file = self.save_file(animation, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( mime_type=mimetypes.types_map[".mp4"], file=file, @@ -134,17 +134,17 @@ class SendGIF(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(os.path.basename(gif)), + types.DocumentAttributeFilename(os.path.basename(animation)), types.DocumentAttributeAnimated() ] ) - elif gif.startswith("http"): + elif animation.startswith("http"): media = types.InputMediaDocumentExternal( - url=gif + url=animation ) else: try: - decoded = utils.decode(gif) + decoded = utils.decode(animation) fmt = " 24 else " Date: Tue, 7 Aug 2018 01:25:34 +0200 Subject: [PATCH 135/249] Rename file --- pyrogram/client/methods/messages/__init__.py | 2 +- .../client/methods/messages/{send_gif.py => send_animation.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pyrogram/client/methods/messages/{send_gif.py => send_animation.py} (100%) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 8bf3bc14..174586bc 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -29,7 +29,7 @@ from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_gif import SendAnimation +from .send_animation import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_animation.py similarity index 100% rename from pyrogram/client/methods/messages/send_gif.py rename to pyrogram/client/methods/messages/send_animation.py From 92a3722e56b9116df3cfce6ccc0f337678dda531 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 8 Aug 2018 15:36:48 +0200 Subject: [PATCH 136/249] Use Animation instead of GIF when creating the types list --- compiler/api/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 3b6dbae7..69713867 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -501,7 +501,7 @@ def start(): f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",") f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",") f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") - f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.Animation\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") From 88d45b085beefc26861470fad17668a1a64d5161 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:46:14 +0200 Subject: [PATCH 137/249] Move InputMedia types in a dedicated folder --- pyrogram/client/types/__init__.py | 11 ++++----- pyrogram/client/types/input_media/__init__.py | 24 +++++++++++++++++++ .../types/{ => input_media}/input_media.py | 0 .../input_media_animation.py | 0 .../{ => input_media}/input_media_audio.py | 0 .../{ => input_media}/input_media_document.py | 0 .../{ => input_media}/input_media_photo.py | 0 .../{ => input_media}/input_media_video.py | 0 .../{ => input_media}/input_phone_contact.py | 0 9 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 pyrogram/client/types/input_media/__init__.py rename pyrogram/client/types/{ => input_media}/input_media.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_animation.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_audio.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_document.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_photo.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_video.py (100%) rename pyrogram/client/types/{ => input_media}/input_phone_contact.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index a07ee27b..46332453 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -23,13 +23,10 @@ from .chat_members import ChatMembers from .chat_photo import ChatPhoto from .dialog import Dialog from .dialogs import Dialogs -from .input_media import InputMedia -from .input_media_animation import InputMediaAnimation -from .input_media_audio import InputMediaAudio -from .input_media_document import InputMediaDocument -from .input_media_photo import InputMediaPhoto -from .input_media_video import InputMediaVideo -from .input_phone_contact import InputPhoneContact +from .input_media import ( + InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, + InputMediaDocument, InputMediaAnimation +) from .media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py new file mode 100644 index 00000000..4b3d90a3 --- /dev/null +++ b/pyrogram/client/types/input_media/__init__.py @@ -0,0 +1,24 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .input_media_animation import InputMediaAnimation +from .input_media_audio import InputMediaAudio +from .input_media_document import InputMediaDocument +from .input_media_photo import InputMediaPhoto +from .input_media_video import InputMediaVideo +from .input_phone_contact import InputPhoneContact diff --git a/pyrogram/client/types/input_media.py b/pyrogram/client/types/input_media/input_media.py similarity index 100% rename from pyrogram/client/types/input_media.py rename to pyrogram/client/types/input_media/input_media.py diff --git a/pyrogram/client/types/input_media_animation.py b/pyrogram/client/types/input_media/input_media_animation.py similarity index 100% rename from pyrogram/client/types/input_media_animation.py rename to pyrogram/client/types/input_media/input_media_animation.py diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media/input_media_audio.py similarity index 100% rename from pyrogram/client/types/input_media_audio.py rename to pyrogram/client/types/input_media/input_media_audio.py diff --git a/pyrogram/client/types/input_media_document.py b/pyrogram/client/types/input_media/input_media_document.py similarity index 100% rename from pyrogram/client/types/input_media_document.py rename to pyrogram/client/types/input_media/input_media_document.py diff --git a/pyrogram/client/types/input_media_photo.py b/pyrogram/client/types/input_media/input_media_photo.py similarity index 100% rename from pyrogram/client/types/input_media_photo.py rename to pyrogram/client/types/input_media/input_media_photo.py diff --git a/pyrogram/client/types/input_media_video.py b/pyrogram/client/types/input_media/input_media_video.py similarity index 100% rename from pyrogram/client/types/input_media_video.py rename to pyrogram/client/types/input_media/input_media_video.py diff --git a/pyrogram/client/types/input_phone_contact.py b/pyrogram/client/types/input_media/input_phone_contact.py similarity index 100% rename from pyrogram/client/types/input_phone_contact.py rename to pyrogram/client/types/input_media/input_phone_contact.py From eeb3b67d37411cfd68c7baae93d8d5763f34dd68 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:49:14 +0200 Subject: [PATCH 138/249] Create a new sub-folder for user and chat types --- pyrogram/client/types/__init__.py | 11 +++----- .../client/types/user_and_chats/__init__.py | 25 +++++++++++++++++++ .../client/types/{ => user_and_chats}/chat.py | 0 .../types/{ => user_and_chats}/chat_member.py | 0 .../{ => user_and_chats}/chat_members.py | 0 .../types/{ => user_and_chats}/chat_photo.py | 0 .../types/{ => user_and_chats}/dialog.py | 0 .../types/{ => user_and_chats}/dialogs.py | 0 .../client/types/{ => user_and_chats}/user.py | 0 9 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 pyrogram/client/types/user_and_chats/__init__.py rename pyrogram/client/types/{ => user_and_chats}/chat.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_member.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_members.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_photo.py (100%) rename pyrogram/client/types/{ => user_and_chats}/dialog.py (100%) rename pyrogram/client/types/{ => user_and_chats}/dialogs.py (100%) rename pyrogram/client/types/{ => user_and_chats}/user.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 46332453..13198982 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -17,12 +17,6 @@ # along with Pyrogram. If not, see . from .callback_query import CallbackQuery -from .chat import Chat -from .chat_member import ChatMember -from .chat_members import ChatMembers -from .chat_photo import ChatPhoto -from .dialog import Dialog -from .dialogs import Dialogs from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation @@ -39,4 +33,7 @@ from .reply_markup import ( KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .update import Update -from .user import User +from .user_and_chats import ( + Chat, ChatMember, ChatMembers, ChatPhoto, + Dialog, Dialogs, User +) diff --git a/pyrogram/client/types/user_and_chats/__init__.py b/pyrogram/client/types/user_and_chats/__init__.py new file mode 100644 index 00000000..45915edc --- /dev/null +++ b/pyrogram/client/types/user_and_chats/__init__.py @@ -0,0 +1,25 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .chat import Chat +from .chat_member import ChatMember +from .chat_members import ChatMembers +from .chat_photo import ChatPhoto +from .dialog import Dialog +from .dialogs import Dialogs +from .user import User diff --git a/pyrogram/client/types/chat.py b/pyrogram/client/types/user_and_chats/chat.py similarity index 100% rename from pyrogram/client/types/chat.py rename to pyrogram/client/types/user_and_chats/chat.py diff --git a/pyrogram/client/types/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py similarity index 100% rename from pyrogram/client/types/chat_member.py rename to pyrogram/client/types/user_and_chats/chat_member.py diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/user_and_chats/chat_members.py similarity index 100% rename from pyrogram/client/types/chat_members.py rename to pyrogram/client/types/user_and_chats/chat_members.py diff --git a/pyrogram/client/types/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py similarity index 100% rename from pyrogram/client/types/chat_photo.py rename to pyrogram/client/types/user_and_chats/chat_photo.py diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/user_and_chats/dialog.py similarity index 100% rename from pyrogram/client/types/dialog.py rename to pyrogram/client/types/user_and_chats/dialog.py diff --git a/pyrogram/client/types/dialogs.py b/pyrogram/client/types/user_and_chats/dialogs.py similarity index 100% rename from pyrogram/client/types/dialogs.py rename to pyrogram/client/types/user_and_chats/dialogs.py diff --git a/pyrogram/client/types/user.py b/pyrogram/client/types/user_and_chats/user.py similarity index 100% rename from pyrogram/client/types/user.py rename to pyrogram/client/types/user_and_chats/user.py From a93f98cfa6967006b43617a4f7e6703fcb99752b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:51:00 +0200 Subject: [PATCH 139/249] Create a new sub-folder for bot related types --- pyrogram/client/types/__init__.py | 13 ++++++++----- .../client/types/{reply_markup => bots}/__init__.py | 1 + pyrogram/client/types/{ => bots}/callback_query.py | 0 .../types/{reply_markup => bots}/force_reply.py | 0 .../inline_keyboard_button.py | 0 .../inline_keyboard_markup.py | 0 .../types/{reply_markup => bots}/keyboard_button.py | 0 .../{reply_markup => bots}/reply_keyboard_markup.py | 0 .../{reply_markup => bots}/reply_keyboard_remove.py | 0 9 files changed, 9 insertions(+), 5 deletions(-) rename pyrogram/client/types/{reply_markup => bots}/__init__.py (96%) rename pyrogram/client/types/{ => bots}/callback_query.py (100%) rename pyrogram/client/types/{reply_markup => bots}/force_reply.py (100%) rename pyrogram/client/types/{reply_markup => bots}/inline_keyboard_button.py (100%) rename pyrogram/client/types/{reply_markup => bots}/inline_keyboard_markup.py (100%) rename pyrogram/client/types/{reply_markup => bots}/keyboard_button.py (100%) rename pyrogram/client/types/{reply_markup => bots}/reply_keyboard_markup.py (100%) rename pyrogram/client/types/{reply_markup => bots}/reply_keyboard_remove.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 13198982..3fd4a8d1 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,7 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .callback_query import CallbackQuery +from .bots import ( + CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove +) +from .bots import ( + ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove +) from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation @@ -28,10 +35,6 @@ from .media import ( from .message import Message from .message_entity import MessageEntity from .messages import Messages -from .reply_markup import ( - ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove -) from .update import Update from .user_and_chats import ( Chat, ChatMember, ChatMembers, ChatPhoto, diff --git a/pyrogram/client/types/reply_markup/__init__.py b/pyrogram/client/types/bots/__init__.py similarity index 96% rename from pyrogram/client/types/reply_markup/__init__.py rename to pyrogram/client/types/bots/__init__.py index 62ce7152..9f7cc7e6 100644 --- a/pyrogram/client/types/reply_markup/__init__.py +++ b/pyrogram/client/types/bots/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .callback_query import CallbackQuery from .force_reply import ForceReply from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup diff --git a/pyrogram/client/types/callback_query.py b/pyrogram/client/types/bots/callback_query.py similarity index 100% rename from pyrogram/client/types/callback_query.py rename to pyrogram/client/types/bots/callback_query.py diff --git a/pyrogram/client/types/reply_markup/force_reply.py b/pyrogram/client/types/bots/force_reply.py similarity index 100% rename from pyrogram/client/types/reply_markup/force_reply.py rename to pyrogram/client/types/bots/force_reply.py diff --git a/pyrogram/client/types/reply_markup/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py similarity index 100% rename from pyrogram/client/types/reply_markup/inline_keyboard_button.py rename to pyrogram/client/types/bots/inline_keyboard_button.py diff --git a/pyrogram/client/types/reply_markup/inline_keyboard_markup.py b/pyrogram/client/types/bots/inline_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/reply_markup/inline_keyboard_markup.py rename to pyrogram/client/types/bots/inline_keyboard_markup.py diff --git a/pyrogram/client/types/reply_markup/keyboard_button.py b/pyrogram/client/types/bots/keyboard_button.py similarity index 100% rename from pyrogram/client/types/reply_markup/keyboard_button.py rename to pyrogram/client/types/bots/keyboard_button.py diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_markup.py b/pyrogram/client/types/bots/reply_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/reply_markup/reply_keyboard_markup.py rename to pyrogram/client/types/bots/reply_keyboard_markup.py diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py b/pyrogram/client/types/bots/reply_keyboard_remove.py similarity index 100% rename from pyrogram/client/types/reply_markup/reply_keyboard_remove.py rename to pyrogram/client/types/bots/reply_keyboard_remove.py From 3a5dc20fb52d528c17f6cdd3034e5528d56b1f70 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:51:43 +0200 Subject: [PATCH 140/249] Rename reply_markup to bots --- compiler/api/compiler.py | 12 ++++++------ pyrogram/client/filters/filters.py | 2 +- pyrogram/client/types/message.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 69713867..555d1824 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,12 +494,12 @@ def start(): f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") - f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") - f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") - f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",") - f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",") - f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",") - f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",") + f.write("\n 0xb0700018: \"pyrogram.client.types.bots.ForceReply\",") + f.write("\n 0xb0700019: \"pyrogram.client.types.bots.InlineKeyboardButton\",") + f.write("\n 0xb0700020: \"pyrogram.client.types.bots.InlineKeyboardMarkup\",") + f.write("\n 0xb0700021: \"pyrogram.client.types.bots.KeyboardButton\",") + f.write("\n 0xb0700022: \"pyrogram.client.types.bots.ReplyKeyboardMarkup\",") + f.write("\n 0xb0700023: \"pyrogram.client.types.bots.ReplyKeyboardRemove\",") f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") f.write("\n 0xb0700025: \"pyrogram.client.types.Animation\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 133ab6c2..e28fdfc5 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -19,7 +19,7 @@ import re from .filter import Filter -from ..types.reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def build(name: str, func: callable, **kwargs) -> type: diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 7b05bfac..0a2022e8 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api.core import Object -from .reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup +from .bots import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): From 2b4138ee30e02d569d606ebb59172f1adbcd7e3f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:53:49 +0200 Subject: [PATCH 141/249] Add new folder for messages and media related types --- .../client/types/{media => messages_and_media}/__init__.py | 3 +++ .../client/types/{media => messages_and_media}/animation.py | 0 pyrogram/client/types/{media => messages_and_media}/audio.py | 0 pyrogram/client/types/{media => messages_and_media}/contact.py | 0 .../client/types/{media => messages_and_media}/document.py | 0 .../client/types/{media => messages_and_media}/location.py | 0 pyrogram/client/types/{ => messages_and_media}/message.py | 0 .../client/types/{ => messages_and_media}/message_entity.py | 0 pyrogram/client/types/{ => messages_and_media}/messages.py | 0 pyrogram/client/types/{media => messages_and_media}/photo.py | 0 .../client/types/{media => messages_and_media}/photo_size.py | 0 pyrogram/client/types/{media => messages_and_media}/sticker.py | 0 .../types/{media => messages_and_media}/user_profile_photos.py | 0 pyrogram/client/types/{media => messages_and_media}/venue.py | 0 pyrogram/client/types/{media => messages_and_media}/video.py | 0 .../client/types/{media => messages_and_media}/video_note.py | 0 pyrogram/client/types/{media => messages_and_media}/voice.py | 0 17 files changed, 3 insertions(+) rename pyrogram/client/types/{media => messages_and_media}/__init__.py (92%) rename pyrogram/client/types/{media => messages_and_media}/animation.py (100%) rename pyrogram/client/types/{media => messages_and_media}/audio.py (100%) rename pyrogram/client/types/{media => messages_and_media}/contact.py (100%) rename pyrogram/client/types/{media => messages_and_media}/document.py (100%) rename pyrogram/client/types/{media => messages_and_media}/location.py (100%) rename pyrogram/client/types/{ => messages_and_media}/message.py (100%) rename pyrogram/client/types/{ => messages_and_media}/message_entity.py (100%) rename pyrogram/client/types/{ => messages_and_media}/messages.py (100%) rename pyrogram/client/types/{media => messages_and_media}/photo.py (100%) rename pyrogram/client/types/{media => messages_and_media}/photo_size.py (100%) rename pyrogram/client/types/{media => messages_and_media}/sticker.py (100%) rename pyrogram/client/types/{media => messages_and_media}/user_profile_photos.py (100%) rename pyrogram/client/types/{media => messages_and_media}/venue.py (100%) rename pyrogram/client/types/{media => messages_and_media}/video.py (100%) rename pyrogram/client/types/{media => messages_and_media}/video_note.py (100%) rename pyrogram/client/types/{media => messages_and_media}/voice.py (100%) diff --git a/pyrogram/client/types/media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py similarity index 92% rename from pyrogram/client/types/media/__init__.py rename to pyrogram/client/types/messages_and_media/__init__.py index 07d1280c..3ab359ae 100644 --- a/pyrogram/client/types/media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -21,6 +21,9 @@ from .audio import Audio from .contact import Contact from .document import Document from .location import Location +from .message import Message +from .message_entity import MessageEntity +from .messages import Messages from .photo import Photo from .photo_size import PhotoSize from .sticker import Sticker diff --git a/pyrogram/client/types/media/animation.py b/pyrogram/client/types/messages_and_media/animation.py similarity index 100% rename from pyrogram/client/types/media/animation.py rename to pyrogram/client/types/messages_and_media/animation.py diff --git a/pyrogram/client/types/media/audio.py b/pyrogram/client/types/messages_and_media/audio.py similarity index 100% rename from pyrogram/client/types/media/audio.py rename to pyrogram/client/types/messages_and_media/audio.py diff --git a/pyrogram/client/types/media/contact.py b/pyrogram/client/types/messages_and_media/contact.py similarity index 100% rename from pyrogram/client/types/media/contact.py rename to pyrogram/client/types/messages_and_media/contact.py diff --git a/pyrogram/client/types/media/document.py b/pyrogram/client/types/messages_and_media/document.py similarity index 100% rename from pyrogram/client/types/media/document.py rename to pyrogram/client/types/messages_and_media/document.py diff --git a/pyrogram/client/types/media/location.py b/pyrogram/client/types/messages_and_media/location.py similarity index 100% rename from pyrogram/client/types/media/location.py rename to pyrogram/client/types/messages_and_media/location.py diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/messages_and_media/message.py similarity index 100% rename from pyrogram/client/types/message.py rename to pyrogram/client/types/messages_and_media/message.py diff --git a/pyrogram/client/types/message_entity.py b/pyrogram/client/types/messages_and_media/message_entity.py similarity index 100% rename from pyrogram/client/types/message_entity.py rename to pyrogram/client/types/messages_and_media/message_entity.py diff --git a/pyrogram/client/types/messages.py b/pyrogram/client/types/messages_and_media/messages.py similarity index 100% rename from pyrogram/client/types/messages.py rename to pyrogram/client/types/messages_and_media/messages.py diff --git a/pyrogram/client/types/media/photo.py b/pyrogram/client/types/messages_and_media/photo.py similarity index 100% rename from pyrogram/client/types/media/photo.py rename to pyrogram/client/types/messages_and_media/photo.py diff --git a/pyrogram/client/types/media/photo_size.py b/pyrogram/client/types/messages_and_media/photo_size.py similarity index 100% rename from pyrogram/client/types/media/photo_size.py rename to pyrogram/client/types/messages_and_media/photo_size.py diff --git a/pyrogram/client/types/media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py similarity index 100% rename from pyrogram/client/types/media/sticker.py rename to pyrogram/client/types/messages_and_media/sticker.py diff --git a/pyrogram/client/types/media/user_profile_photos.py b/pyrogram/client/types/messages_and_media/user_profile_photos.py similarity index 100% rename from pyrogram/client/types/media/user_profile_photos.py rename to pyrogram/client/types/messages_and_media/user_profile_photos.py diff --git a/pyrogram/client/types/media/venue.py b/pyrogram/client/types/messages_and_media/venue.py similarity index 100% rename from pyrogram/client/types/media/venue.py rename to pyrogram/client/types/messages_and_media/venue.py diff --git a/pyrogram/client/types/media/video.py b/pyrogram/client/types/messages_and_media/video.py similarity index 100% rename from pyrogram/client/types/media/video.py rename to pyrogram/client/types/messages_and_media/video.py diff --git a/pyrogram/client/types/media/video_note.py b/pyrogram/client/types/messages_and_media/video_note.py similarity index 100% rename from pyrogram/client/types/media/video_note.py rename to pyrogram/client/types/messages_and_media/video_note.py diff --git a/pyrogram/client/types/media/voice.py b/pyrogram/client/types/messages_and_media/voice.py similarity index 100% rename from pyrogram/client/types/media/voice.py rename to pyrogram/client/types/messages_and_media/voice.py From 888b3cc6aab07b929840cf75847e75af1d1df10b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:55:06 +0200 Subject: [PATCH 142/249] Add missing import --- pyrogram/client/types/input_media/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py index 4b3d90a3..5f5be30d 100644 --- a/pyrogram/client/types/input_media/__init__.py +++ b/pyrogram/client/types/input_media/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .input_media import InputMedia from .input_media_animation import InputMediaAnimation from .input_media_audio import InputMediaAudio from .input_media_document import InputMediaDocument From 61663b3dde608b7a3121d2197736fa5f2d1dd400 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:16:31 +0200 Subject: [PATCH 143/249] Add new utilities folder --- pyrogram/client/methods/utilities/__init__.py | 25 +++++++++++++++++++ .../methods/{ => utilities}/download_media.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/utilities/__init__.py rename pyrogram/client/methods/{ => utilities}/download_media.py (99%) diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py new file mode 100644 index 00000000..f8db23e5 --- /dev/null +++ b/pyrogram/client/methods/utilities/__init__.py @@ -0,0 +1,25 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .download_media import DownloadMedia + + +class Utilities( + DownloadMedia +): + pass diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/utilities/download_media.py similarity index 99% rename from pyrogram/client/methods/download_media.py rename to pyrogram/client/methods/utilities/download_media.py index 816a8cba..d511667c 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -19,7 +19,7 @@ from threading import Event from pyrogram.client import types as pyrogram_types -from ..ext import BaseClient +from ...ext import BaseClient class DownloadMedia(BaseClient): From 4e6add7a70fd25596588761033166dd22dfb3500 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:16:57 +0200 Subject: [PATCH 144/249] Fix download_media referencing to gif instead of animation --- pyrogram/client/methods/utilities/download_media.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/utilities/download_media.py b/pyrogram/client/methods/utilities/download_media.py index d511667c..26918f27 100644 --- a/pyrogram/client/methods/utilities/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -98,8 +98,8 @@ class DownloadMedia(BaseClient): media = message.video_note elif message.sticker: media = message.sticker - elif message.gif: - media = message.gif + elif message.animation: + media = message.animation else: raise ValueError(error_message) elif isinstance(message, ( From 42d3b467fbec32b1314042271c2a08c798ce025f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:17:21 +0200 Subject: [PATCH 145/249] Fix init not having message and media types --- pyrogram/client/types/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 3fd4a8d1..230d5e5d 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -28,13 +28,11 @@ from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation ) -from .media import ( +from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, - Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos + Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos, + Message, Messages, MessageEntity ) -from .message import Message -from .message_entity import MessageEntity -from .messages import Messages from .update import Update from .user_and_chats import ( Chat, ChatMember, ChatMembers, ChatPhoto, From 6437c6c5be6745f6001159b58b8d8082176df8d7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:17:53 +0200 Subject: [PATCH 146/249] Move resolve_peer into utilities --- pyrogram/client/client.py | 48 ------------ .../client/methods/utilities/resolve_peer.py | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 pyrogram/client/methods/utilities/resolve_peer.py diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 3af60931..9fcf6324 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1010,54 +1010,6 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() - def resolve_peer(self, peer_id: int or str): - """Use this method to get the InputPeer of a known peer_id. - - This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method - you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer - type is required. - - Args: - peer_id (``int`` | ``str``): - The peer id you want to extract the InputPeer from. - Can be a direct id (int), a username (str) or a phone number (str). - - Returns: - On success, the resolved peer id is returned in form of an InputPeer object. - - Raises: - :class:`Error ` - """ - if type(peer_id) is str: - if peer_id in ("self", "me"): - return types.InputPeerSelf() - - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) - - try: - int(peer_id) - except ValueError: - if peer_id not in self.peers_by_username: - self.send(functions.contacts.ResolveUsername(peer_id)) - - return self.peers_by_username[peer_id] - else: - try: - return self.peers_by_phone[peer_id] - except KeyError: - raise PeerIdInvalid - - try: # User - return self.peers_by_id[peer_id] - except KeyError: - try: # Chat - return self.peers_by_id[-peer_id] - except KeyError: - try: # Channel - return self.peers_by_id[int("-100" + str(peer_id))] - except (KeyError, ValueError): - raise PeerIdInvalid - def save_file(self, path: str, file_id: int = None, diff --git a/pyrogram/client/methods/utilities/resolve_peer.py b/pyrogram/client/methods/utilities/resolve_peer.py new file mode 100644 index 00000000..7cf31078 --- /dev/null +++ b/pyrogram/client/methods/utilities/resolve_peer.py @@ -0,0 +1,73 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import re + +from pyrogram.api import types, functions +from pyrogram.api.errors import PeerIdInvalid +from ...ext import BaseClient + + +class ResolvePeer(BaseClient): + def resolve_peer(self, peer_id: int or str): + """Use this method to get the InputPeer of a known peer_id. + + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. + + Args: + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). + + Returns: + On success, the resolved peer id is returned in form of an InputPeer object. + + Raises: + :class:`Error ` + """ + if type(peer_id) is str: + if peer_id in ("self", "me"): + return types.InputPeerSelf() + + peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) + + try: + int(peer_id) + except ValueError: + if peer_id not in self.peers_by_username: + self.send(functions.contacts.ResolveUsername(peer_id)) + + return self.peers_by_username[peer_id] + else: + try: + return self.peers_by_phone[peer_id] + except KeyError: + raise PeerIdInvalid + + try: # User + return self.peers_by_id[peer_id] + except KeyError: + try: # Chat + return self.peers_by_id[-peer_id] + except KeyError: + try: # Channel + return self.peers_by_id[int("-100" + str(peer_id))] + except (KeyError, ValueError): + raise PeerIdInvalid From dd422c0edfe8f2b40bfc8c40aab4b2c89da7c82d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:18:28 +0200 Subject: [PATCH 147/249] Export resolve_peer --- pyrogram/client/methods/__init__.py | 4 ++-- pyrogram/client/methods/utilities/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index 396fd3c2..e245a14a 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,7 +20,7 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .download_media import DownloadMedia +from .utilities import Utilities from .messages import Messages from .password import Password from .users import Users @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - DownloadMedia, + Utilities, Messages, Decorators ): diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py index f8db23e5..b14c2a1f 100644 --- a/pyrogram/client/methods/utilities/__init__.py +++ b/pyrogram/client/methods/utilities/__init__.py @@ -17,9 +17,11 @@ # along with Pyrogram. If not, see . from .download_media import DownloadMedia +from .resolve_peer import ResolvePeer class Utilities( - DownloadMedia + DownloadMedia, + ResolvePeer ): pass From ef6f08054672924a8a47e6611f41828236c57924 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:05 +0200 Subject: [PATCH 148/249] Revert "Export resolve_peer" This reverts commit dd422c0 --- pyrogram/client/methods/__init__.py | 4 ++-- pyrogram/client/methods/utilities/__init__.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index e245a14a..396fd3c2 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,7 +20,7 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .utilities import Utilities +from .download_media import DownloadMedia from .messages import Messages from .password import Password from .users import Users @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - Utilities, + DownloadMedia, Messages, Decorators ): diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py index b14c2a1f..f8db23e5 100644 --- a/pyrogram/client/methods/utilities/__init__.py +++ b/pyrogram/client/methods/utilities/__init__.py @@ -17,11 +17,9 @@ # along with Pyrogram. If not, see . from .download_media import DownloadMedia -from .resolve_peer import ResolvePeer class Utilities( - DownloadMedia, - ResolvePeer + DownloadMedia ): pass From da436461a88b7d8a80b05ae770ea8d9e9e82de88 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:13 +0200 Subject: [PATCH 149/249] Revert "Move resolve_peer into utilities" This reverts commit 6437c6c --- pyrogram/client/client.py | 48 ++++++++++++ .../client/methods/utilities/resolve_peer.py | 73 ------------------- 2 files changed, 48 insertions(+), 73 deletions(-) delete mode 100644 pyrogram/client/methods/utilities/resolve_peer.py diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9fcf6324..3af60931 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1010,6 +1010,54 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() + def resolve_peer(self, peer_id: int or str): + """Use this method to get the InputPeer of a known peer_id. + + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. + + Args: + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). + + Returns: + On success, the resolved peer id is returned in form of an InputPeer object. + + Raises: + :class:`Error ` + """ + if type(peer_id) is str: + if peer_id in ("self", "me"): + return types.InputPeerSelf() + + peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) + + try: + int(peer_id) + except ValueError: + if peer_id not in self.peers_by_username: + self.send(functions.contacts.ResolveUsername(peer_id)) + + return self.peers_by_username[peer_id] + else: + try: + return self.peers_by_phone[peer_id] + except KeyError: + raise PeerIdInvalid + + try: # User + return self.peers_by_id[peer_id] + except KeyError: + try: # Chat + return self.peers_by_id[-peer_id] + except KeyError: + try: # Channel + return self.peers_by_id[int("-100" + str(peer_id))] + except (KeyError, ValueError): + raise PeerIdInvalid + def save_file(self, path: str, file_id: int = None, diff --git a/pyrogram/client/methods/utilities/resolve_peer.py b/pyrogram/client/methods/utilities/resolve_peer.py deleted file mode 100644 index 7cf31078..00000000 --- a/pyrogram/client/methods/utilities/resolve_peer.py +++ /dev/null @@ -1,73 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -import re - -from pyrogram.api import types, functions -from pyrogram.api.errors import PeerIdInvalid -from ...ext import BaseClient - - -class ResolvePeer(BaseClient): - def resolve_peer(self, peer_id: int or str): - """Use this method to get the InputPeer of a known peer_id. - - This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method - you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer - type is required. - - Args: - peer_id (``int`` | ``str``): - The peer id you want to extract the InputPeer from. - Can be a direct id (int), a username (str) or a phone number (str). - - Returns: - On success, the resolved peer id is returned in form of an InputPeer object. - - Raises: - :class:`Error ` - """ - if type(peer_id) is str: - if peer_id in ("self", "me"): - return types.InputPeerSelf() - - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) - - try: - int(peer_id) - except ValueError: - if peer_id not in self.peers_by_username: - self.send(functions.contacts.ResolveUsername(peer_id)) - - return self.peers_by_username[peer_id] - else: - try: - return self.peers_by_phone[peer_id] - except KeyError: - raise PeerIdInvalid - - try: # User - return self.peers_by_id[peer_id] - except KeyError: - try: # Chat - return self.peers_by_id[-peer_id] - except KeyError: - try: # Channel - return self.peers_by_id[int("-100" + str(peer_id))] - except (KeyError, ValueError): - raise PeerIdInvalid From 7162850523adbd71d1c8f4298d7af1c8c3e44e09 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:55 +0200 Subject: [PATCH 150/249] Export Utility methods --- pyrogram/client/methods/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index 396fd3c2..eba768bb 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,10 +20,10 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .download_media import DownloadMedia from .messages import Messages from .password import Password from .users import Users +from .utilities import Utilities class Methods( @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - DownloadMedia, + Utilities, Messages, Decorators ): From 9c7de81d8214826d2df3f23abcee5de90ee1f246 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:30:36 +0200 Subject: [PATCH 151/249] Fix relative imports --- pyrogram/client/types/messages_and_media/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 0a2022e8..3065cf9f 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api.core import Object -from .bots import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..bots import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): From 3ccb3de3f4413857e6cab21fbb7e95f68fba3f11 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:46:43 +0200 Subject: [PATCH 152/249] Fix docs still containing GIF instead of Animation --- docs/source/pyrogram/Client.rst | 2 +- docs/source/pyrogram/types/index.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 642d43d8..5dd42e4e 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -48,7 +48,7 @@ Messages send_document send_sticker send_video - send_gif + send_animation send_voice send_video_note send_media_group diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index d93ecceb..92093b11 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -31,7 +31,7 @@ Messages & Media UserProfilePhotos Audio Document - GIF + Animation Video Voice VideoNote @@ -115,7 +115,7 @@ Input Media .. autoclass:: Document :members: -.. autoclass:: GIF +.. autoclass:: Animation :members: .. autoclass:: Video From 80179f2f25aebbd26a2b1a30580d0e558cdcc244 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:47:49 +0200 Subject: [PATCH 153/249] Rework Handler's page They are now all listed in a single page --- docs/source/pyrogram/handlers/index.rst | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/handlers/index.rst index 272e529f..9f69c2c9 100644 --- a/docs/source/pyrogram/handlers/index.rst +++ b/docs/source/pyrogram/handlers/index.rst @@ -1,11 +1,29 @@ -:tocdepth: 1 - Handlers ======== -.. toctree:: +.. currentmodule:: pyrogram + +.. autosummary:: + :nosignatures: + MessageHandler DeletedMessagesHandler CallbackQueryHandler DisconnectHandler RawUpdateHandler + +.. autoclass:: MessageHandler + :members: + +.. autoclass:: DeletedMessagesHandler + :members: + +.. autoclass:: CallbackQueryHandler + :members: + +.. autoclass:: DisconnectHandler + :members: + +.. autoclass:: RawUpdateHandler + :members: + From 58568686a4c326579b1b8cbef7998772ef396739 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:50:03 +0200 Subject: [PATCH 154/249] Delete unused files --- docs/source/pyrogram/handlers/CallbackQueryHandler.rst | 6 ------ docs/source/pyrogram/handlers/DeletedMessagesHandler.rst | 6 ------ docs/source/pyrogram/handlers/DisconnectHandler.rst | 6 ------ docs/source/pyrogram/handlers/MessageHandler.rst | 6 ------ docs/source/pyrogram/handlers/RawUpdateHandler.rst | 6 ------ 5 files changed, 30 deletions(-) delete mode 100644 docs/source/pyrogram/handlers/CallbackQueryHandler.rst delete mode 100644 docs/source/pyrogram/handlers/DeletedMessagesHandler.rst delete mode 100644 docs/source/pyrogram/handlers/DisconnectHandler.rst delete mode 100644 docs/source/pyrogram/handlers/MessageHandler.rst delete mode 100644 docs/source/pyrogram/handlers/RawUpdateHandler.rst diff --git a/docs/source/pyrogram/handlers/CallbackQueryHandler.rst b/docs/source/pyrogram/handlers/CallbackQueryHandler.rst deleted file mode 100644 index 5c9f4c17..00000000 --- a/docs/source/pyrogram/handlers/CallbackQueryHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -CallbackQueryHandler -==================== - -.. autoclass:: pyrogram.CallbackQueryHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst b/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst deleted file mode 100644 index 128bc656..00000000 --- a/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -DeletedMessagesHandler -====================== - -.. autoclass:: pyrogram.DeletedMessagesHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/DisconnectHandler.rst b/docs/source/pyrogram/handlers/DisconnectHandler.rst deleted file mode 100644 index 594081f1..00000000 --- a/docs/source/pyrogram/handlers/DisconnectHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -DisconnectHandler -================= - -.. autoclass:: pyrogram.DisconnectHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/MessageHandler.rst b/docs/source/pyrogram/handlers/MessageHandler.rst deleted file mode 100644 index de908bd3..00000000 --- a/docs/source/pyrogram/handlers/MessageHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -MessageHandler -============== - -.. autoclass:: pyrogram.MessageHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/RawUpdateHandler.rst b/docs/source/pyrogram/handlers/RawUpdateHandler.rst deleted file mode 100644 index a6d21ef3..00000000 --- a/docs/source/pyrogram/handlers/RawUpdateHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -RawUpdateHandler -================ - -.. autoclass:: pyrogram.RawUpdateHandler - :members: - :undoc-members: From ece50e5f9bcff6fa90c8937492876749c8adba8f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:30:54 +0200 Subject: [PATCH 155/249] Rename Filters.gif to Filters.animation --- pyrogram/client/filters/filters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index e28fdfc5..5c2538f4 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -69,8 +69,8 @@ class Filters: sticker = build("Sticker", lambda _, m: bool(m.sticker)) """Filter messages that contain :obj:`Sticker ` objects.""" - gif = build("GIF", lambda _, m: bool(m.gif)) - """Filter messages that contain :obj:`GIF ` objects.""" + animation = build("GIF", lambda _, m: bool(m.animation)) + """Filter messages that contain :obj:`Animation ` objects.""" video = build("Video", lambda _, m: bool(m.video)) """Filter messages that contain :obj:`Video ` objects.""" @@ -276,7 +276,7 @@ class Filters: or Filters.photo(m) or Filters.sticker(m) or Filters.video(m) - or Filters.gif(m) + or Filters.animation(m) or Filters.voice(m) or Filters.video_note(m) or Filters.contact(m) From cbe34d0b28a4a3d0dcb80c96164b5c7084abdd3b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:31:24 +0200 Subject: [PATCH 156/249] Remove handlers and types doc page containing folders --- docs/source/pyrogram/{handlers/index.rst => Handlers.rst} | 0 docs/source/pyrogram/{types/index.rst => Types.rst} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docs/source/pyrogram/{handlers/index.rst => Handlers.rst} (100%) rename docs/source/pyrogram/{types/index.rst => Types.rst} (100%) diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/Handlers.rst similarity index 100% rename from docs/source/pyrogram/handlers/index.rst rename to docs/source/pyrogram/Handlers.rst diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/Types.rst similarity index 100% rename from docs/source/pyrogram/types/index.rst rename to docs/source/pyrogram/Types.rst From 7d516bfff24dbd2e4eaa0f5deeb5275d4e07cce6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:31:58 +0200 Subject: [PATCH 157/249] Fix Pyrogram doc package index page --- docs/source/pyrogram/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index af8b281a..20e7c918 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -10,8 +10,8 @@ after the well established `Telegram Bot API`_ methods, thus offering a familiar :maxdepth: 1 Client - types/index - handlers/index + Types + Handlers Filters ChatAction ParseMode From ba549c2862335bd041a2bb6f0bab6accfadd82af Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:32:10 +0200 Subject: [PATCH 158/249] Remove tocdepth --- docs/source/pyrogram/Error.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/pyrogram/Error.rst b/docs/source/pyrogram/Error.rst index 96a140fa..b5474e73 100644 --- a/docs/source/pyrogram/Error.rst +++ b/docs/source/pyrogram/Error.rst @@ -1,5 +1,3 @@ -:tocdepth: 1 - Error ===== From 85c50ef4dd09e16840385efac39e3794dd9928d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 13 Aug 2018 22:06:20 +0200 Subject: [PATCH 159/249] Add phone_number message entity --- pyrogram/client/ext/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index c1d859d0..9508a426 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -69,7 +69,8 @@ ENTITIES = { types.MessageEntityCode.ID: "code", types.MessageEntityPre.ID: "pre", types.MessageEntityTextUrl.ID: "text_link", - types.MessageEntityMentionName.ID: "text_mention" + types.MessageEntityMentionName.ID: "text_mention", + types.MessageEntityPhone.ID: "phone_number" } From 4fe9cffc32ad511c269774a153a173dca39a0931 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 13 Aug 2018 22:06:43 +0200 Subject: [PATCH 160/249] Code style fix --- pyrogram/client/ext/utils.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 9508a426..8f3245a9 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -81,18 +81,20 @@ def parse_entities(entities: list, users: dict) -> list: entity_type = ENTITIES.get(entity.ID, None) if entity_type: - output_entities.append(pyrogram_types.MessageEntity( - type=entity_type, - offset=entity.offset, - length=entity.length, - url=getattr(entity, "url", None), - user=parse_user( - users.get( - getattr(entity, "user_id", None), - None + output_entities.append( + pyrogram_types.MessageEntity( + type=entity_type, + offset=entity.offset, + length=entity.length, + url=getattr(entity, "url", None), + user=parse_user( + users.get( + getattr(entity, "user_id", None), + None + ) ) ) - )) + ) return output_entities From ec0d6dd6e0df8c7ab9eaab7760544531bff7044f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 14 Aug 2018 14:14:03 +0200 Subject: [PATCH 161/249] Add support for animations in edit_message_media --- .../methods/messages/edit_message_media.py | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index c6b2eb97..086d8dc2 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -25,7 +25,8 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto, InputMediaVideo, InputMediaAudio + InputMediaPhoto, InputMediaVideo, InputMediaAudio, + InputMediaAnimation ) @@ -189,6 +190,61 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaAnimation): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map[".mp4"], + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeVideo( + supports_streaming=True, + duration=media.duration, + w=media.width, + h=media.height + ), + types.DocumentAttributeFilename(os.path.basename(media.media)), + types.DocumentAttributeAnimated() + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Tue, 14 Aug 2018 14:25:54 +0200 Subject: [PATCH 162/249] Add foursquare_type to Venue --- pyrogram/client/ext/utils.py | 3 ++- pyrogram/client/types/messages_and_media/venue.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 8f3245a9..b98a05a8 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -378,7 +378,8 @@ def parse_messages( ), title=media.title, address=media.address, - foursquare_id=media.venue_id or None + foursquare_id=media.venue_id or None, + foursquare_type=media.venue_type ) elif isinstance(media, types.MessageMediaDocument): doc = media.document diff --git a/pyrogram/client/types/messages_and_media/venue.py b/pyrogram/client/types/messages_and_media/venue.py index 5d9e387f..3c5b2b05 100644 --- a/pyrogram/client/types/messages_and_media/venue.py +++ b/pyrogram/client/types/messages_and_media/venue.py @@ -35,12 +35,24 @@ class Venue(Object): foursquare_id (``str``, *optional*): Foursquare identifier of the venue. + foursquare_type (``str``, *optional*): + Foursquare type of the venue. + (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) + """ ID = 0xb0700013 - def __init__(self, location, title: str, address: str, foursquare_id: str = None): + def __init__( + self, + location, + title: str, + address: str, + foursquare_id: str = None, + foursquare_type: str = None + ): self.location = location self.title = title self.address = address self.foursquare_id = foursquare_id + self.foursquare_type = foursquare_type From 49e2e529e13d23b0dbaca72eeb0a52898950724f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 14 Aug 2018 14:36:01 +0200 Subject: [PATCH 163/249] Add parameter foursquare_type to send_venue method --- pyrogram/client/methods/messages/send_venue.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 39ae0ca2..3decd5fb 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -28,6 +28,7 @@ class SendVenue(BaseClient): title: str, address: str, foursquare_id: str = "", + foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None): @@ -54,6 +55,10 @@ class SendVenue(BaseClient): foursquare_id (``str``, *optional*): Foursquare identifier of the venue. + foursquare_type (``str``, *optional*): + Foursquare type of the venue, if known. + (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -83,7 +88,7 @@ class SendVenue(BaseClient): address=address, provider="", venue_id=foursquare_id, - venue_type="" + venue_type=foursquare_type ), message="", silent=disable_notification or None, From 6879a4da9b107bb223ad8e3425a70a108dcf8189 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Aug 2018 22:33:01 +0200 Subject: [PATCH 164/249] Update vcard docstrings for Contact type and send_contact method --- pyrogram/client/methods/messages/send_contact.py | 2 +- pyrogram/client/types/messages_and_media/contact.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index 99a96abc..f661a31f 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -48,7 +48,7 @@ class SendContact(BaseClient): Contact's last name. vcard (``str``, *optional*): - Contact's vCard information. + Additional data about the contact in the form of a vCard, 0-2048 bytes disable_notification (``bool``, *optional*): Sends the message silently. diff --git a/pyrogram/client/types/messages_and_media/contact.py b/pyrogram/client/types/messages_and_media/contact.py index a59e2047..a7be558e 100644 --- a/pyrogram/client/types/messages_and_media/contact.py +++ b/pyrogram/client/types/messages_and_media/contact.py @@ -32,11 +32,11 @@ class Contact(Object): last_name (``str``, *optional*): Contact's last name. - vcard (``str``, *optional*): - Contact's vCard. - user_id (``int``, *optional*): Contact's user identifier in Telegram. + + vcard (``str``, *optional*): + Additional data about the contact in the form of a vCard """ ID = 0xb0700011 @@ -46,11 +46,11 @@ class Contact(Object): phone_number: str, first_name: str, last_name: str = None, - vcard: str = None, - user_id: int = None + user_id: int = None, + vcard: str = None ): self.phone_number = phone_number self.first_name = first_name self.last_name = last_name - self.vcard = vcard self.user_id = user_id + self.vcard = vcard From 30620cb783759f240a712854dcd12402a0fd116a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:53:53 +0200 Subject: [PATCH 165/249] Refine API Keys documentation section --- docs/source/start/Setup.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 417d62d8..79fb169d 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -8,14 +8,17 @@ with Pyrogram. API Keys -------- -The very first step requires you to obtain a valid Telegram API key. +The very first step requires you to obtain a valid Telegram API key (API id/hash pair). If you already have one you can skip this step, otherwise: #. Visit https://my.telegram.org/apps and log in with your Telegram Account. #. Fill out the form to register a new Telegram application. -#. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**. +#. Done. The API key consists of two parts: **App api_id** and **App api_hash**. -.. important:: This key should be kept secret. + +.. important:: + + This API key is personal and should be kept secret. Configuration ------------- From a7c9dd4a59b4e0933c4a58ce985045ed046c1ecb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:54:38 +0200 Subject: [PATCH 166/249] Make it clear that API keys are required for bots too --- docs/source/start/Setup.rst | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 79fb169d..17449911 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -23,10 +23,14 @@ If you already have one you can skip this step, otherwise: Configuration ------------- -There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you: +The API key obtained in the `previous step <#api-keys>`_ defines a token for your application allowing you to access +the Telegram database using the MTProto API — **it is therefore required for all authorizations of both Users and Bots**. + +Having it handy, it's time to configure your Pyrogram project. There are two ways to do so, and you can choose what +fits better for you: - Create a new ``config.ini`` file at the root of your working directory, copy-paste the following and replace the - **api_id** and **api_hash** values with `your own <#api-keys>`_. This is the preferred method because allows you + **api_id** and **api_hash** values with your own. This is the preferred method because allows you to keep your credentials out of your code without having to deal with how to load them: .. code-block:: ini @@ -84,11 +88,12 @@ and as long as you keep the session alive, Pyrogram won't ask you again to enter Bot Authorization ----------------- -Being written entirely from the ground up, Pyrogram is also able to authorize Bots. -Bots are a special kind of users which also make use of MTProto, the underlying Telegram protocol. -This means that you can use Pyrogram to execute API calls with a Bot identity. +Bots are a special kind of users and are authorized via their tokens (instead of phone numbers), which are created by +BotFather_. Bot tokens replace the Users' phone numbers only — you still need to +`configure a Telegram API key <#configuration>`_ with Pyrogram, even when using Bots. -Instead of phone numbers, Bots are authorized via their tokens which are created by BotFather_: +The authorization process is automatically managed. All you need to do is pass the bot token as ``session_name``. +The session file will be named after the Bot user_id, which is ``123456.session`` for the example below. .. code-block:: python @@ -97,9 +102,6 @@ Instead of phone numbers, Bots are authorized via their tokens which are created app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") 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. - .. _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 173fabd869616c82e8fd1172bf6ec4acb2012217 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:55:27 +0200 Subject: [PATCH 167/249] Small Setup page fixes and refinements --- docs/source/start/Setup.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 17449911..e0cccc2c 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -52,7 +52,8 @@ fits better for you: api_hash="0123456789abcdef0123456789abcdef" ) -.. note:: The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id* +.. 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. User Authorization @@ -83,7 +84,7 @@ After successfully authorizing yourself, a new file called ``my_account.session` Pyrogram executing API calls with your identity. This file will be loaded again when you restart your app, and as long as you keep the session alive, Pyrogram won't ask you again to enter your phone number. -.. important:: Your ``*.session`` file(s) must be kept secret. +.. important:: Your ``*.session`` files are personal and must be kept secret. Bot Authorization ----------------- From d45caa63716e1a17d797a9f7fd8ba576a84b9ff6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Aug 2018 02:02:15 +0200 Subject: [PATCH 168/249] Fix some documentation links --- docs/source/pyrogram/Client.rst | 2 -- docs/source/start/Usage.rst | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 5dd42e4e..45d40368 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -33,8 +33,6 @@ Decorators on_disconnect on_raw_update -.. _available-methods: - Messages -------- diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 6c20decd..6c560f90 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -108,9 +108,9 @@ Examples (more on `GitHub Date: Fri, 17 Aug 2018 02:17:48 +0200 Subject: [PATCH 169/249] Rename "build" to "create" (friendlier name) --- pyrogram/client/filters/filters.py | 84 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 5c2538f4..92fb278e 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -22,7 +22,7 @@ from .filter import Filter from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup -def build(name: str, func: callable, **kwargs) -> type: +def create(name: str, func: callable, **kwargs) -> type: d = {"__call__": func} d.update(kwargs) @@ -33,109 +33,109 @@ class Filters: """This class provides access to all Filters available in Pyrogram. Filters are intended to be used with the :obj:`MessageHandler `.""" - bot = build("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) + bot = create("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) """Filter messages coming from bots""" - incoming = build("Incoming", lambda _, m: not m.outgoing) + incoming = create("Incoming", lambda _, m: not m.outgoing) """Filter incoming messages.""" - outgoing = build("Outgoing", lambda _, m: m.outgoing) + outgoing = create("Outgoing", lambda _, m: m.outgoing) """Filter outgoing messages.""" - text = build("Text", lambda _, m: bool(m.text)) + text = create("Text", lambda _, m: bool(m.text)) """Filter text messages.""" - reply = build("Reply", lambda _, m: bool(m.reply_to_message)) + reply = create("Reply", lambda _, m: bool(m.reply_to_message)) """Filter messages that are replies to other messages.""" - forwarded = build("Forwarded", lambda _, m: bool(m.forward_date)) + forwarded = create("Forwarded", lambda _, m: bool(m.forward_date)) """Filter messages that are forwarded.""" - caption = build("Caption", lambda _, m: bool(m.caption)) + caption = create("Caption", lambda _, m: bool(m.caption)) """Filter media messages that contain captions.""" - edited = build("Edited", lambda _, m: bool(m.edit_date)) + edited = create("Edited", lambda _, m: bool(m.edit_date)) """Filter edited messages.""" - audio = build("Audio", lambda _, m: bool(m.audio)) + audio = create("Audio", lambda _, m: bool(m.audio)) """Filter messages that contain :obj:`Audio ` objects.""" - document = build("Document", lambda _, m: bool(m.document)) + document = create("Document", lambda _, m: bool(m.document)) """Filter messages that contain :obj:`Document ` objects.""" - photo = build("Photo", lambda _, m: bool(m.photo)) + photo = create("Photo", lambda _, m: bool(m.photo)) """Filter messages that contain :obj:`Photo ` objects.""" - sticker = build("Sticker", lambda _, m: bool(m.sticker)) + sticker = create("Sticker", lambda _, m: bool(m.sticker)) """Filter messages that contain :obj:`Sticker ` objects.""" - animation = build("GIF", lambda _, m: bool(m.animation)) + animation = create("GIF", lambda _, m: bool(m.animation)) """Filter messages that contain :obj:`Animation ` objects.""" - video = build("Video", lambda _, m: bool(m.video)) + video = create("Video", lambda _, m: bool(m.video)) """Filter messages that contain :obj:`Video ` objects.""" - voice = build("Voice", lambda _, m: bool(m.voice)) + voice = create("Voice", lambda _, m: bool(m.voice)) """Filter messages that contain :obj:`Voice ` note objects.""" - video_note = build("Voice", lambda _, m: bool(m.video_note)) + video_note = create("Voice", lambda _, m: bool(m.video_note)) """Filter messages that contain :obj:`VideoNote ` objects.""" - contact = build("Contact", lambda _, m: bool(m.contact)) + contact = create("Contact", lambda _, m: bool(m.contact)) """Filter messages that contain :obj:`Contact ` objects.""" - location = build("Location", lambda _, m: bool(m.location)) + location = create("Location", lambda _, m: bool(m.location)) """Filter messages that contain :obj:`Location ` objects.""" - venue = build("Venue", lambda _, m: bool(m.venue)) + venue = create("Venue", lambda _, m: bool(m.venue)) """Filter messages that contain :obj:`Venue ` objects.""" - private = build("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) + private = create("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) """Filter messages sent in private chats.""" - group = build("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) + group = create("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) """Filter messages sent in group or supergroup chats.""" - channel = build("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) + channel = create("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) """Filter messages sent in channels.""" - new_chat_members = build("NewChatMembers", lambda _, m: bool(m.new_chat_members)) + new_chat_members = create("NewChatMembers", lambda _, m: bool(m.new_chat_members)) """Filter service messages for new chat members.""" - left_chat_member = build("LeftChatMember", lambda _, m: bool(m.left_chat_member)) + left_chat_member = create("LeftChatMember", lambda _, m: bool(m.left_chat_member)) """Filter service messages for members that left the chat.""" - new_chat_title = build("NewChatTitle", lambda _, m: bool(m.new_chat_title)) + new_chat_title = create("NewChatTitle", lambda _, m: bool(m.new_chat_title)) """Filter service messages for new chat titles.""" - new_chat_photo = build("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) + new_chat_photo = create("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) """Filter service messages for new chat photos.""" - delete_chat_photo = build("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) + delete_chat_photo = create("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) """Filter service messages for deleted photos.""" - group_chat_created = build("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) + group_chat_created = create("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) """Filter service messages for group chat creations.""" - supergroup_chat_created = build("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) + supergroup_chat_created = create("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) """Filter service messages for supergroup chat creations.""" - channel_chat_created = build("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) + channel_chat_created = create("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) """Filter service messages for channel chat creations.""" - migrate_to_chat_id = build("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) + migrate_to_chat_id = create("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) """Filter service messages that contain migrate_to_chat_id.""" - migrate_from_chat_id = build("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) + migrate_from_chat_id = create("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) """Filter service messages that contain migrate_from_chat_id.""" - pinned_message = build("PinnedMessage", lambda _, m: bool(m.pinned_message)) + pinned_message = create("PinnedMessage", lambda _, m: bool(m.pinned_message)) """Filter service messages for pinned messages.""" - reply_keyboard = build("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) + reply_keyboard = create("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) """Filter messages containing reply keyboard markups""" - inline_keyboard = build("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) + inline_keyboard = create("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) """Filter messages containing inline keyboard markups""" @staticmethod @@ -174,7 +174,7 @@ class Filters: return bool(m.command) - return build( + return create( "Command", f, c={command if case_sensitive @@ -206,7 +206,7 @@ class Filters: m.matches = [i for i in _.p.finditer(m.text or "")] return bool(m.matches) - return build("Regex", f, p=re.compile(pattern, flags)) + return create("Regex", f, p=re.compile(pattern, flags)) @staticmethod def user(user: int or str or list): @@ -216,7 +216,7 @@ class Filters: user (``int`` | ``str`` | ``list``): The user or list of user IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "User", lambda _, m: bool(m.from_user and (m.from_user.id in _.u @@ -237,7 +237,7 @@ class Filters: chat (``int`` | ``str`` | ``list``): The chat or list of chat IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "Chat", lambda _, m: bool(m.chat and (m.chat.id in _.c @@ -250,7 +250,7 @@ class Filters: ) ) - service = build( + service = create( "Service", lambda _, m: bool( Filters.new_chat_members(m) @@ -268,7 +268,7 @@ class Filters: ) """Filter all service messages.""" - media = build( + media = create( "Media", lambda _, m: bool( Filters.audio(m) From 0c77fe91fe8be09c4dcc43904cf938298c6fe677 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Aug 2018 12:17:54 +0200 Subject: [PATCH 170/249] Add TODO --- pyrogram/client/filters/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 92fb278e..ba8e7c4b 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -23,6 +23,7 @@ from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def create(name: str, func: callable, **kwargs) -> type: + # TODO: unpack kwargs using **kwargs into the dict itself. For Python 3.5+ only d = {"__call__": func} d.update(kwargs) From 6dfaa3ddeaa0ca26e80716efdc14236909701e76 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 18 Aug 2018 18:18:40 +0200 Subject: [PATCH 171/249] Small documentation updates --- docs/source/start/Installation.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index 8aea16de..bba927e4 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -7,7 +7,8 @@ We recommend using the latest version of Python 3 and pip. Get Python 3 from https://www.python.org/downloads/ or with your package manager and pip by following the instructions at https://pip.pypa.io/en/latest/installing/. -Pyrogram supports Python 3 only, starting from version 3.4 and PyPy. +.. note:: + Pyrogram supports Python 3 only, starting from version 3.4 and PyPy. Install Pyrogram ---------------- From ed05c56f5236e15dbe3922ae50eb522d361607a5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:22:28 +0200 Subject: [PATCH 172/249] Clearer Filters docs. Add create to Filters' namespace --- pyrogram/client/filters/filters.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index ba8e7c4b..043f29ff 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -31,8 +31,14 @@ def create(name: str, func: callable, **kwargs) -> type: class Filters: - """This class provides access to all Filters available in Pyrogram. - Filters are intended to be used with the :obj:`MessageHandler `.""" + """This class provides access to all library-defined Filters available in Pyrogram. + + The Filters listed here are intended to be used with the :obj:`MessageHandler ` only. + At the moment, if you want to filter updates coming from different `Handlers `_ you have to create + your own filters with :meth:`Filters.create` and use them in the same way. + """ + + create = create bot = create("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) """Filter messages coming from bots""" From 493fc4a6582e65fc82af6964b9c6c338329e5990 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:24:24 +0200 Subject: [PATCH 173/249] Document Filters.create() method --- pyrogram/client/filters/filters.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 043f29ff..4cd4b191 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -23,6 +23,27 @@ from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def create(name: str, func: callable, **kwargs) -> type: + """Use this method to create a Filter. + + Custom filters give you extra control over which updates are allowed or not to be processed by your handlers. + + Args: + name (``str``): + Your filter's name. Can be anything you like. + + func (``callable``): + A function that accepts two arguments *(filter, update)* and returns a Boolean: True if the update should be + handled, False otherwise. + The "update" argument type will vary depending on which `Handler `_ is coming from. + For example, in a :obj:`MessageHandler ` the update type will be + a :obj:`Message `; in a :obj:`CallbackQueryHandler ` the + update type will be a :obj:`CallbackQuery `. Your function body can then access the + incoming update and decide whether to allow it or not. + + **kwargs (``any``, *optional*): + Any keyword argument you would like to pass. Useful for custom filters that accept parameters (e.g.: + :meth:`Filters.command`, :meth:`Filters.regex`). + """ # TODO: unpack kwargs using **kwargs into the dict itself. For Python 3.5+ only d = {"__call__": func} d.update(kwargs) From de9beac2ce4614ef8265d6ba67b397489d59e3a1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:25:09 +0200 Subject: [PATCH 174/249] Refactor UpdateHandling page --- docs/source/resources/UpdateHandling.rst | 186 ++++------------------- 1 file changed, 28 insertions(+), 158 deletions(-) diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index 0aa6457f..781a48af 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -2,188 +2,58 @@ Update Handling =============== Updates are events that happen in your Telegram account (incoming messages, new channel posts, new members join, ...) -and are handled by registering one or more callback functions with an Handler. There are multiple Handlers to choose -from, one for each kind of update: +and can be handled by registering one or more callback functions in your app by using an `Handler <../pyrogram/Handlers.html>`_. -- `MessageHandler <../pyrogram/handlers/MessageHandler.html>`_ -- `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_ -- `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_ -- `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_ -- `DisconnectHandler <../pyrogram/handlers/DisconnectHandler.html>`_ +To put it simply, whenever an update is received from Telegram it will be dispatched and your previously defined callback +function(s) will be called back with the update itself as argument. Registering an Handler ---------------------- -We shall examine the :obj:`MessageHandler `, which will be in charge for handling -:obj:`Message ` objects. - -- The easiest and nicest way to register a MessageHandler is by decorating your function with the - :meth:`on_message() ` decorator. Here's a full example that prints out the content - of a message as soon as it arrives. - - .. code-block:: python - - from pyrogram import Client - - app = Client("my_account") +To explain how `Handlers <../pyrogram/Handlers.html>`_ work let's have a look at the most used one, the +:obj:`MessageHandler `, which will be in charge for handling :obj:`Message ` +updates coming from all around your chats. Every other handler shares the same setup logic; you should not have troubles +settings them up once you learn from this section. - @app.on_message() - def my_handler(client, message): - print(message) - - - 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. - - .. code-block:: python - - from pyrogram import Client, MessageHandler - - - def my_handler(client, message): - print(message) - - - app = Client("my_account") - - app.add_handler(MessageHandler(my_handler)) - - app.run() - -Using Filters -------------- - -For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use -:class:`Filters `. - -- This example will show you how to **only** handle messages containing an - :obj:`Audio ` object and filter out any other message: - - .. code-block:: python - - from pyrogram import Filters - - - @app.on_message(Filters.audio) - def my_handler(client, message): - print(message) - -- or, without decorators: - - .. code-block:: python - - from pyrogram import Filters, MessageHandler - - - def my_handler(client, message): - print(message) - - - app.add_handler(MessageHandler(my_handler, Filters.audio)) - -Combining Filters ------------------ - -Filters can also be used in a more advanced way by combining more filters together using bitwise operators: - -- Use ``~`` to invert a filter (behaves like the ``not`` operator). -- Use ``&`` and ``|`` to merge two filters (behave like ``and``, ``or`` operators respectively). - -Here are some examples: - -- Message is a **text** message **and** is **not edited**. - - .. code-block:: python - - @app.on_message(Filters.text & ~Filters.edited) - def my_handler(client, message): - print(message) - -- Message is a **sticker** **and** is coming from a **channel or** a **private** chat. - - .. code-block:: python - - @app.on_message(Filters.sticker & (Filters.channel | Filters.private)) - def my_handler(client, message): - print(message) - -Advanced Filters +Using Decorators ---------------- -Some filters, like :obj:`command() ` or :obj:`regex() ` -can also accept arguments: - -- Message is either a */start* or */help* **command**. - - .. code-block:: python - - @app.on_message(Filters.command(["start", "help"])) - def my_handler(client, message): - print(message) - -- Message is a **text** message matching the given **regex** pattern. - - .. code-block:: python - - @app.on_message(Filters.regex("pyrogram")) - def my_handler(client, message): - print(message) - -More handlers using different filters can also live together. +The easiest and nicest way to register a MessageHandler is by decorating your function with the +:meth:`on_message() ` decorator. Here's a full example that prints out the content +of a message as soon as it arrives. .. code-block:: python - @app.on_message(Filters.command("start")) - def start_command(client, message): - print("This is the /start command") + from pyrogram import Client + + app = Client("my_account") - @app.on_message(Filters.command("help")) - def help_command(client, message): - print("This is the /help command") + @app.on_message() + def my_handler(client, message): + print(message) - @app.on_message(Filters.chat("PyrogramChat")) - def from_pyrogramchat(client, message): - print("New message in @PyrogramChat") + app.run() -Handler Groups --------------- +Using add_handler() +------------------- -If you register handlers with overlapping filters, only the first one is executed and any other handler will be ignored. - -In order to process the same message more than once, you can register your handler in a different group. -Groups are identified by a number (number 0 being the default) and are sorted. This means that a lower group number has -a higher priority. - -For example, in: +If you prefer not to use decorators for any reason, there is an alternative way for registering Handlers. +This is useful, for example, when you want to keep your callback functions in separate files. .. code-block:: python - @app.on_message(Filters.text | Filters.sticker) - def text_or_sticker(client, message): - print("Text or Sticker") + from pyrogram import Client, MessageHandler - @app.on_message(Filters.text) - def just_text(client, message): - print("Just Text") + def my_handler(client, message): + print(message) -``just_text`` is never executed. To enable it, simply register the function using a different group: -.. code-block:: python + app = Client("my_account") - @app.on_message(Filters.text, group=1) - def just_text(client, message): - print("Just Text") + app.add_handler(MessageHandler(my_handler)) -or, if you want ``just_text`` to be fired *before* ``text_or_sticker``: - -.. code-block:: python - - @app.on_message(Filters.text, group=-1) - def just_text(client, message): - print("Just Text") \ No newline at end of file + app.run() From 1666eaac7753a4f8c6275ba6e28b546330ed3557 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:25:39 +0200 Subject: [PATCH 175/249] Add UsingFilter doc page --- docs/source/index.rst | 1 + docs/source/resources/UsingFilters.rst | 228 +++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 docs/source/resources/UsingFilters.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 051b5af8..ec6b24f2 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -84,6 +84,7 @@ To get started, press the Next button. :caption: Resources resources/UpdateHandling + resources/UsingFilters resources/AutoAuthorization resources/CustomizeSessions resources/TgCrypto diff --git a/docs/source/resources/UsingFilters.rst b/docs/source/resources/UsingFilters.rst new file mode 100644 index 00000000..79ecd24f --- /dev/null +++ b/docs/source/resources/UsingFilters.rst @@ -0,0 +1,228 @@ +Using Filters +============= + +For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use +:class:`Filters `. + +.. note:: + This section makes use of Handlers to handle updates. Learn more at `Update Handling `_. + +- This example will show you how to **only** handle messages containing an :obj:`Audio ` object and + ignore any other message: + + .. code-block:: python + + from pyrogram import Filters + + + @app.on_message(Filters.audio) + def my_handler(client, message): + print(message) + +- or, without decorators: + + .. code-block:: python + + from pyrogram import Filters, MessageHandler + + + def my_handler(client, message): + print(message) + + + app.add_handler(MessageHandler(my_handler, Filters.audio)) + +Combining Filters +----------------- + +Filters can also be used in a more advanced way by inverting and combining more filters together using bitwise +operators: + +- Use ``~`` to invert a filter (behaves like the ``not`` operator). +- Use ``&`` and ``|`` to merge two filters (behave like ``and``, ``or`` operators respectively). + +Here are some examples: + +- Message is a **text** message **and** is **not edited**. + + .. code-block:: python + + @app.on_message(Filters.text & ~Filters.edited) + def my_handler(client, message): + print(message) + +- Message is a **sticker** **and** is coming from a **channel or** a **private** chat. + + .. code-block:: python + + @app.on_message(Filters.sticker & (Filters.channel | Filters.private)) + def my_handler(client, message): + print(message) + +Advanced Filters +---------------- + +Some filters, like :meth:`command() ` or :meth:`regex() ` +can also accept arguments: + +- Message is either a */start* or */help* **command**. + + .. code-block:: python + + @app.on_message(Filters.command(["start", "help"])) + def my_handler(client, message): + print(message) + +- Message is a **text** message matching the given **regex** pattern. + + .. code-block:: python + + @app.on_message(Filters.regex("pyrogram")) + def my_handler(client, message): + print(message) + +More handlers using different filters can also live together. + +.. code-block:: python + + @app.on_message(Filters.command("start")) + def start_command(client, message): + print("This is the /start command") + + + @app.on_message(Filters.command("help")) + def help_command(client, message): + print("This is the /help command") + + + @app.on_message(Filters.chat("PyrogramChat")) + def from_pyrogramchat(client, message): + print("New message in @PyrogramChat") + +Handler Groups +-------------- + +If you register handlers with overlapping filters, only the first one is executed and any other handler will be ignored. + +In order to process the same message more than once, you can register your handler in a different group. +Groups are identified by a number (number 0 being the default) and are sorted. This means that a lower group number has +a higher priority. + +For example, in: + +.. code-block:: python + + @app.on_message(Filters.text | Filters.sticker) + def text_or_sticker(client, message): + print("Text or Sticker") + + + @app.on_message(Filters.text) + def just_text(client, message): + print("Just Text") + +``just_text`` is never executed because ``text_or_sticker`` already handles texts. To enable it, simply register the +function using a different group: + +.. code-block:: python + + @app.on_message(Filters.text, group=1) + def just_text(client, message): + print("Just Text") + +or, if you want ``just_text`` to be fired *before* ``text_or_sticker`` (note ``-1``, which is less than ``0``): + +.. code-block:: python + + @app.on_message(Filters.text, group=-1) + def just_text(client, message): + print("Just Text") + +Custom Filters +-------------- + +Pyrogram already provides lots of built-in :class:`Filters ` to work with, but in case you can't find +a specific one for your needs or want to build a custom filter by yourself (to be used in a different handler, for +example) you can use :meth:`Filters.create() `. + +.. note:: + At the moment, the built-in filters are intended to be used with the :obj:`MessageHandler ` + only. + +An example to demonstrate how custom filters work is to show how to create and use one for the +:obj:`CallbackQueryHandler `. Note that callback queries updates are only received by Bots; +create and `authorize your bot <../start/Setup.html#bot-authorization>`_, then send a message with an inline keyboard to +yourself. This allows you to test your filter by pressing the inline button: + +.. code-block:: python + + from pyrogram import InlineKeyboardMarkup, InlineKeyboardButton + + app.send_message( + "username", # Change this to your username or id + "Pyrogram's custom filter test", + reply_markup=InlineKeyboardMarkup( + [[InlineKeyboardButton("Press me", "pyrogram")]] + ) + ) + +Basic Filters +^^^^^^^^^^^^^ + +For this basic filter we will be using only the first two parameters of :meth:`Filters.create() `. + +The code below creates a simple filter for hardcoded callback data. This filter will only allow callback queries +containing "pyrogram" as data: + +.. code-block:: python + + hardcoded_data = Filters.create( + name="HardcodedData", + func=lambda filter, callback_query: callback_query.data == "pyrogram" + ) + +The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same +could be achieved with a normal function, but we don't really need it as it makes sense only inside the filter itself: + +.. code-block:: python + + def func(filter, callback_query): + return callback_query.data == "pyrogram" + + hardcoded_data = Filters.create( + name="HardcodedData", + func=func + ) + +The filter usage remains the same: + +.. code-block:: python + + @app.on_callback_query(hardcoded_data) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") + +Filters with Arguments +^^^^^^^^^^^^^^^^^^^^^^ + +A much cooler filter would be one that accepts "pyrogram" or any other data as argument at usage time. +A dynamic filter like this will make use of the third parameter of :meth:`Filters.create() `. + +This is how a dynamic custom filter looks like: + +.. code-block:: python + + def dynamic_data(data): + return Filters.create( + name="DynamicData", + func=lambda filter, callback_query: filter.data == callback_query.data, + data=data # "data" kwarg is accessed with "filter.data" + ) + +And its usage: + +.. code-block:: python + + @app.on_callback_query(dynamic_data("pyrogram")) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") \ No newline at end of file From 21d914e414ef36a09017d42b40e7bfe638f0f5cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 19:40:23 +0200 Subject: [PATCH 176/249] Remove unused constant --- pyrogram/client/ext/base_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index c8a6029d..c78997c1 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -41,7 +41,6 @@ class BaseClient: platform.release() ) - SYSTEM_LANG_CODE = "en" LANG_CODE = "en" INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/joinchat/)([\w-]+)$") From 088a4c35c973723ebe0ecf3cc0ce9d5046de8274 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 02:12:21 +0200 Subject: [PATCH 177/249] Add is_pinned attribute to Dialog --- pyrogram/client/methods/messages/get_dialogs.py | 3 ++- pyrogram/client/types/user_and_chats/dialog.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index f43ca6a5..e7b3e2a8 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -92,7 +92,8 @@ class GetDialogs(BaseClient): top_message=messages.get(chat_id), unread_messages_count=dialog.unread_count, unread_mentions_count=dialog.unread_mentions_count, - unread_mark=dialog.unread_mark + unread_mark=dialog.unread_mark, + is_pinned=dialog.pinned ) ) diff --git a/pyrogram/client/types/user_and_chats/dialog.py b/pyrogram/client/types/user_and_chats/dialog.py index 60ffb76c..fa5fb2b8 100644 --- a/pyrogram/client/types/user_and_chats/dialog.py +++ b/pyrogram/client/types/user_and_chats/dialog.py @@ -37,6 +37,9 @@ class Dialog(Object): unread_mark (``bool``): True, if the dialog has the unread mark set. + + is_pinned (``bool``): + True, if the dialog is pinned. """ ID = 0xb0700028 @@ -45,9 +48,11 @@ class Dialog(Object): top_message, unread_messages_count: int, unread_mentions_count: int, - unread_mark: bool): + unread_mark: bool, + is_pinned: bool): self.chat = chat self.top_message = top_message self.unread_messages_count = unread_messages_count self.unread_mentions_count = unread_mentions_count self.unread_mark = unread_mark + self.is_pinned = is_pinned From 9c0f8b2f3b4a9fdec002f35dfa165d4bdab838b7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 11:24:00 +0200 Subject: [PATCH 178/249] Document get_dialogs() method --- .../client/methods/messages/get_dialogs.py | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index e7b3e2a8..e22f7e2f 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -22,19 +22,41 @@ from ...ext import BaseClient, utils class GetDialogs(BaseClient): - # TODO docstrings - def get_dialogs(self, + offset_dialogs=None, limit: int = 100, - pinned_only: bool = False, - last_chunk=None): + pinned_only: bool = False): + """Use this method to get the user's dialogs + + You can get up to 100 dialogs at once. + + Args: + limit (``str``, *optional*): + Limits the number of dialogs to be retrieved. + Defaults to 100 + + pinned_only (``bool``, *optional*): + Pass True if you want to get only pinned dialogs. + Defaults to False. + + offset_dialogs (:obj:`Dialogs`): + Pass the previous dialogs object to retrieve the next dialogs chunk starting from the last dialog. + Defaults to None (start from the beginning). + + Returns: + On success, a :obj:`Dialogs` object is returned. + + Raises: + :class:`Error` + """ + if pinned_only: r = self.send(functions.messages.GetPinnedDialogs()) else: offset_date = 0 - if last_chunk: - for dialog in reversed(last_chunk.dialogs): + if offset_dialogs: + for dialog in reversed(offset_dialogs.dialogs): top_message = dialog.top_message if top_message: From 2d8792a7cd09f5c169287c2e4dc60d89dea5a19c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 11:24:47 +0200 Subject: [PATCH 179/249] Move get_dialogs() from "messages" to "chats" namespace --- pyrogram/client/methods/chats/__init__.py | 4 +++- pyrogram/client/methods/{messages => chats}/get_dialogs.py | 0 pyrogram/client/methods/messages/__init__.py | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) rename pyrogram/client/methods/{messages => chats}/get_dialogs.py (100%) diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index ce56f16b..72134abf 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -21,6 +21,7 @@ from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers +from .get_dialogs import GetDialogs from .join_chat import JoinChat from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat @@ -50,6 +51,7 @@ class Chats( SetChatTitle, SetChatDescription, PinChatMessage, - UnpinChatMessage + UnpinChatMessage, + GetDialogs ): pass diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py similarity index 100% rename from pyrogram/client/methods/messages/get_dialogs.py rename to pyrogram/client/methods/chats/get_dialogs.py diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 174586bc..35dae756 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -22,14 +22,13 @@ from .edit_message_media import EditMessageMedia from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages -from .get_dialogs import GetDialogs from .get_history import GetHistory from .get_messages import GetMessages +from .send_animation import SendAnimation from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_animation import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage @@ -50,7 +49,6 @@ class Messages( ForwardMessages, GetHistory, GetMessages, - GetDialogs, SendAudio, SendChatAction, SendContact, From 03b17d5bcefa42e3c413ffde253bb0166aaa96ad Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Aug 2018 21:18:06 +0200 Subject: [PATCH 180/249] Fix clickable link --- pyrogram/client/methods/messages/send_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index b770133e..00087307 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -61,7 +61,7 @@ class SendMessage(BaseClient): instructions to remove reply keyboard or to force a reply from the user. Returns: - On success, the sent Message is returned. + On success, the sent :obj:`Message` is returned. Raises: :class:`Error ` From c501eeb5a2ee164e656742903953cc93e45a9da9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Aug 2018 21:23:19 +0200 Subject: [PATCH 181/249] Update to v0.8.0dev1 There are a quite lot of changes it deserves a new "minor" update. --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a822524c..7ef07777 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Thu, 23 Aug 2018 21:21:27 +0200 Subject: [PATCH 182/249] Add support for Document message edits --- .../methods/messages/edit_message_media.py | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 086d8dc2..7bf66d5e 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -26,7 +26,7 @@ from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto, InputMediaVideo, InputMediaAudio, - InputMediaAnimation + InputMediaAnimation, InputMediaDocument ) @@ -245,6 +245,54 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaDocument): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "text/plain"), + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Fri, 24 Aug 2018 16:03:52 +0200 Subject: [PATCH 183/249] Add phone_number type of entity to docs --- pyrogram/client/types/messages_and_media/message_entity.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message_entity.py b/pyrogram/client/types/messages_and_media/message_entity.py index db2eee3e..f8f41734 100644 --- a/pyrogram/client/types/messages_and_media/message_entity.py +++ b/pyrogram/client/types/messages_and_media/message_entity.py @@ -26,9 +26,9 @@ class MessageEntity(Object): Args: type (``str``): Type of the entity. - Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "bold" (bold text), - italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text - URLs), "text_mention" (for users without usernames). + Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "phone_number", "bold" + (bold text), italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link" + (for clickable text URLs), "text_mention" (for users without usernames). offset (``int``): Offset in UTF-16 code units to the start of the entity. From 0b6b59805934a1897324b306cab066539f539941 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 24 Aug 2018 17:39:55 +0200 Subject: [PATCH 184/249] Log unknown constructors --- pyrogram/api/core/object.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyrogram/api/core/object.py b/pyrogram/api/core/object.py index a1e20726..3cf12329 100644 --- a/pyrogram/api/core/object.py +++ b/pyrogram/api/core/object.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from collections import OrderedDict from datetime import datetime from io import BytesIO @@ -23,13 +24,23 @@ from json import JSONEncoder, dumps from ..all import objects +log = logging.getLogger(__name__) + class Object: all = {} @staticmethod def read(b: BytesIO, *args): - return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args) + constructor_id = int.from_bytes(b.read(4), "little") + + try: + return Object.all[constructor_id].read(b, *args) + except KeyError: + log.error("Unknown constructor found: {}. Full data: {}".format( + hex(constructor_id), + b.getvalue().hex()) + ) def write(self, *args) -> bytes: pass From 77a1d5871485ac1f9f479612d6b1a13d2842a653 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 24 Aug 2018 18:13:07 +0200 Subject: [PATCH 185/249] Normalize "0.8.0dev1" to "0.8.0.dev1" --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 7ef07777..1de05f2c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Sat, 25 Aug 2018 13:53:48 +0200 Subject: [PATCH 186/249] Add clean command to setup.py --- setup.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 00f9be63..a5ad052d 100644 --- a/setup.py +++ b/setup.py @@ -17,9 +17,10 @@ # along with Pyrogram. If not, see . import re +import shutil from sys import argv -from setuptools import setup, find_packages +from setuptools import setup, find_packages, Command from compiler.api import compiler as api_compiler from compiler.docs import compiler as docs_compiler @@ -44,6 +45,24 @@ with open("README.rst", encoding="utf-8") as f: readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme) + +class Clean(Command): + PATHS = "./build ./dist ./Pyrogram.egg-info".split() + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + for path in self.PATHS: + print("removing {}".format(path)) + shutil.rmtree(path, ignore_errors=True) + + setup( name="Pyrogram", version=version, @@ -85,5 +104,8 @@ 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.0.4"]}, + cmdclass={ + "clean": Clean + } ) From 1e56f70b9309ab974de1ac396dc67ef9e090f456 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 25 Aug 2018 13:58:55 +0200 Subject: [PATCH 187/249] Also clean generated filed --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a5ad052d..ee716857 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,15 @@ with open("README.rst", encoding="utf-8") as f: class Clean(Command): - PATHS = "./build ./dist ./Pyrogram.egg-info".split() + PATHS = [ + "./build", + "./dist", + "./Pyrogram.egg-info", + "pyrogram/api/errors/exceptions", + "pyrogram/api/functions", + "pyrogram/api/types", + "pyrogram/api/all.py" + ] user_options = [] From c9a946bc02ef8f1c44774fd3c05790d145b4e37c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 25 Aug 2018 14:00:04 +0200 Subject: [PATCH 188/249] Turn version and readme into function --- setup.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index ee716857..f9153dfe 100644 --- a/setup.py +++ b/setup.py @@ -37,13 +37,17 @@ if len(argv) > 1 and argv[1] != "sdist": docs_compiler.start() error_compiler.start() -with open("pyrogram/__init__.py", encoding="utf-8") as f: - version = re.findall(r"__version__ = \"(.+)\"", f.read())[0] -# PyPI doesn't like raw html -with open("README.rst", encoding="utf-8") as f: - readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) - readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme) +def get_version(): + with open("pyrogram/__init__.py", encoding="utf-8") as f: + return re.findall(r"__version__ = \"(.+)\"", f.read())[0] + + +def get_readme(): + # PyPI doesn't like raw html + with open("README.rst", encoding="utf-8") as f: + readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) + return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme) class Clean(Command): @@ -73,9 +77,9 @@ class Clean(Command): setup( name="Pyrogram", - version=version, + version=get_version(), description="Telegram MTProto API Client Library for Python", - long_description=readme, + long_description=get_readme(), url="https://github.com/pyrogram", download_url="https://github.com/pyrogram/pyrogram/releases/latest", author="Dan Tès", From d6a0fcf4adaacf9315a41282904c0f89cc9aed1e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 25 Aug 2018 14:22:19 +0200 Subject: [PATCH 189/249] Also clean docs generated files --- setup.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index f9153dfe..929222db 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import os import re import shutil from sys import argv @@ -58,7 +59,9 @@ class Clean(Command): "pyrogram/api/errors/exceptions", "pyrogram/api/functions", "pyrogram/api/types", - "pyrogram/api/all.py" + "pyrogram/api/all.py", + "docs/source/functions", + "docs/source/types" ] user_options = [] @@ -71,9 +74,12 @@ class Clean(Command): def run(self): for path in self.PATHS: - print("removing {}".format(path)) - shutil.rmtree(path, ignore_errors=True) - + try: + shutil.rmtree(path) if os.path.isdir(path) else os.remove(path) + except OSError: + print("skipping {}".format(path)) + else: + print("removing {}".format(path)) setup( name="Pyrogram", From 47f8a4eb34b17cd3f4bba493e6ec83e505200903 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 25 Aug 2018 15:14:51 +0200 Subject: [PATCH 190/249] Add generate command to setup.py --- setup.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 929222db..6cc10340 100644 --- a/setup.py +++ b/setup.py @@ -33,38 +33,56 @@ def read(file: str) -> list: return [i.strip() for i in r] -if len(argv) > 1 and argv[1] != "sdist": - api_compiler.start() - docs_compiler.start() - error_compiler.start() - - def get_version(): with open("pyrogram/__init__.py", encoding="utf-8") as f: return re.findall(r"__version__ = \"(.+)\"", f.read())[0] def get_readme(): - # PyPI doesn't like raw html + # PyPI doesn"t like raw html with open("README.rst", encoding="utf-8") as f: readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme) class Clean(Command): - PATHS = [ + DIST = [ "./build", "./dist", - "./Pyrogram.egg-info", + "./Pyrogram.egg-info" + ] + + API = [ "pyrogram/api/errors/exceptions", "pyrogram/api/functions", "pyrogram/api/types", "pyrogram/api/all.py", - "docs/source/functions", - "docs/source/types" ] - user_options = [] + DOCS = [ + "docs/source/functions", + "docs/source/types", + "docs/build" + ] + + ALL = DIST + API + DOCS + + description = "Clean generated files" + + user_options = [ + ("dist", None, "Clean distribution files"), + ("api", None, "Clean generated API files"), + ("docs", None, "Clean generated docs files"), + ("all", None, "Clean all generated files"), + ] + + def __init__(self, dist, **kw): + super().__init__(dist, **kw) + + self.dist = None + self.api = None + self.docs = None + self.all = None def initialize_options(self): pass @@ -73,7 +91,21 @@ class Clean(Command): pass def run(self): - for path in self.PATHS: + paths = set() + + if self.dist: + paths.update(Clean.DIST) + + if self.api: + paths.update(Clean.API) + + if self.docs: + paths.update(Clean.DOCS) + + if self.all: + paths.update(Clean.ALL) + + for path in sorted(list(paths)): try: shutil.rmtree(path) if os.path.isdir(path) else os.remove(path) except OSError: @@ -81,6 +113,40 @@ class Clean(Command): else: print("removing {}".format(path)) + +class Generate(Command): + description = "Generate Pyrogram files" + + user_options = [ + ("api", None, "Generate API files"), + ("docs", None, "Generate docs files"), + ] + + def __init__(self, dist, **kw): + super().__init__(dist, **kw) + + self.api = None + self.docs = None + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + if self.api: + error_compiler.start() + api_compiler.start() + + if self.docs: + docs_compiler.start() + + +if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]: + error_compiler.start() + api_compiler.start() + setup( name="Pyrogram", version=get_version(), @@ -124,6 +190,7 @@ setup( install_requires=read("requirements.txt"), extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]}, cmdclass={ - "clean": Clean + "clean": Clean, + "generate": Generate, } ) From ccc3cb0c876ae43c3fbcffd82bb96d9c38c78c73 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 26 Aug 2018 19:18:14 +0200 Subject: [PATCH 191/249] Rename generate to build Replaces the default build behaviour --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 6cc10340..5df52747 100644 --- a/setup.py +++ b/setup.py @@ -114,12 +114,12 @@ class Clean(Command): print("removing {}".format(path)) -class Generate(Command): - description = "Generate Pyrogram files" +class Build(Command): + description = "Build Pyrogram files" user_options = [ - ("api", None, "Generate API files"), - ("docs", None, "Generate docs files"), + ("api", None, "Build API files"), + ("docs", None, "Build docs files"), ] def __init__(self, dist, **kw): @@ -191,6 +191,6 @@ setup( extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]}, cmdclass={ "clean": Clean, - "generate": Generate, + "build": Build, } ) From 2779e33d1351a461ce3fc1d0f8a692360e4cc8e1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 27 Aug 2018 02:11:07 +0200 Subject: [PATCH 192/249] Rename "token" to "bot_token" --- pyrogram/client/client.py | 8 ++++---- pyrogram/client/ext/base_client.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 3af60931..dba204fd 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -201,7 +201,7 @@ class Client(Methods, BaseClient): raise ConnectionError("Client has already been started") if self.BOT_TOKEN_RE.match(self.session_name): - self.token = self.session_name + self.bot_token = self.session_name self.session_name = self.session_name.split(":")[0] self.load_config() @@ -217,14 +217,14 @@ class Client(Methods, BaseClient): self.is_started = True if self.user_id is None: - if self.token is None: + if self.bot_token is None: self.authorize_user() else: self.authorize_bot() self.save_session() - if self.token is None: + if self.bot_token is None: now = time.time() if abs(now - self.date) > Client.OFFLINE_SLEEP: @@ -381,7 +381,7 @@ class Client(Methods, BaseClient): flags=0, api_id=self.api_id, api_hash=self.api_hash, - bot_auth_token=self.token + bot_auth_token=self.bot_token ) ) except UserMigrate as e: diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index c78997c1..fa96e1db 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -64,7 +64,7 @@ class BaseClient: } def __init__(self): - self.token = None + self.bot_token = None self.dc_id = None self.auth_key = None self.user_id = None From 973ccfcd033b4d11c7fe18a2698da0f064a3306b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 28 Aug 2018 12:23:22 +0200 Subject: [PATCH 193/249] Use compact IPv6 addresses --- pyrogram/session/internals/data_center.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index 154cd9e0..154ba4e5 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -35,19 +35,19 @@ class DataCenter: } TEST_IPV6 = { - 1: "2001:0b28:f23d:f001:0000:0000:0000:000e", - 2: "2001:067c:04e8:f002:0000:0000:0000:000e", - 3: "2001:0b28:f23d:f003:0000:0000:0000:000e", - 121: "2a03:b0c0:0003:00d0:0000:0000:0114:d001" + 1: "2001:b28:f23d:f001::e", + 2: "2001:67c:4e8:f002::e", + 3: "2001:b28:f23d:f003::e", + 121: "2a03:b0c0:3:d0::114:d001" } PROD_IPV6 = { - 1: "2001:0b28:f23d:f001:0000:0000:0000:000a", - 2: "2001:067c:04e8:f002:0000:0000:0000:000a", - 3: "2001:0b28:f23d:f003:0000:0000:0000:000a", - 4: "2001:067c:04e8:f004:0000:0000:0000:000a", - 5: "2001:0b28:f23f:f005:0000:0000:0000:000a", - 121: "2a03:b0c0:0003:00d0:0000:0000:0114:d001" + 1: "2001:b28:f23d:f001::a", + 2: "2001:67c:4e8:f002::a", + 3: "2001:b28:f23d:f003::a", + 4: "2001:67c:4e8:f004::a", + 5: "2001:b28:f23f:f005::a", + 121: "2a03:b0c0:3:d0::114:d001" } def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool): From a0c1018a1bcf63201fb3b0676b6e3aea2eeca4c3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 28 Aug 2018 12:25:08 +0200 Subject: [PATCH 194/249] Minor style fix --- pyrogram/session/internals/data_center.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index 154ba4e5..d36e0613 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -52,6 +52,14 @@ class DataCenter: def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool): if ipv6: - return (cls.TEST_IPV6[dc_id], 80) if test_mode else (cls.PROD_IPV6[dc_id], 443) + return ( + (cls.TEST_IPV6[dc_id], 80) + if test_mode + else (cls.PROD_IPV6[dc_id], 443) + ) else: - return (cls.TEST[dc_id], 80) if test_mode else (cls.PROD[dc_id], 443) + return ( + (cls.TEST[dc_id], 80) + if test_mode + else (cls.PROD[dc_id], 443) + ) From f50638772cebc5bd1dad2b01de8ae6a1b58382e6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 28 Aug 2018 12:38:02 +0200 Subject: [PATCH 195/249] Minor fix: update info log --- pyrogram/session/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index c87f0698..f0387002 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -156,7 +156,7 @@ class Session: self.ping_thread = Thread(target=self.ping, name="PingThread") self.ping_thread.start() - log.info("Connection inited: Layer {}".format(layer)) + log.info("Session initialized: Layer {}".format(layer)) except AuthKeyDuplicated as e: self.stop() raise e From b845544e638eb7b6e96c74154af5052d1300a51d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 28 Aug 2018 12:39:14 +0200 Subject: [PATCH 196/249] Info log device and system parameters --- pyrogram/session/session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index f0387002..4ca32733 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -157,6 +157,9 @@ class Session: self.ping_thread.start() log.info("Session initialized: Layer {}".format(layer)) + log.info("Device: {} - {}".format(self.client.device_model, self.client.app_version)) + log.info("System: {} ({})".format(self.client.system_version, self.client.lang_code.upper())) + except AuthKeyDuplicated as e: self.stop() raise e From 49f2cbe04f1d41d8a62cc6d1981c28109080f574 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 29 Aug 2018 22:04:04 +0200 Subject: [PATCH 197/249] Move CURRENT_DH_PRIME into Prime namespace --- pyrogram/crypto/prime.py | 12 ++++++++++++ pyrogram/session/auth.py | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pyrogram/crypto/prime.py b/pyrogram/crypto/prime.py index 9338c206..8e9426ca 100644 --- a/pyrogram/crypto/prime.py +++ b/pyrogram/crypto/prime.py @@ -20,6 +20,18 @@ from random import randint class Prime: + CURRENT_DH_PRIME = int( + "C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F" + "48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C37" + "20FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F64" + "2477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4" + "A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754" + "FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4" + "E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F" + "0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B", + 16 + ) + # Recursive variant # @classmethod # def gcd(cls, a: int, b: int) -> int: diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 2142be59..a545a642 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -34,18 +34,6 @@ log = logging.getLogger(__name__) class Auth: MAX_RETRIES = 5 - CURRENT_DH_PRIME = int( - "C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F" - "48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C37" - "20FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F64" - "2477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4" - "A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754" - "FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4" - "E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F" - "0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B", - 16 - ) - def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict): self.dc_id = dc_id self.test_mode = test_mode @@ -220,7 +208,7 @@ class Auth: # Security checks ####################### - assert dh_prime == self.CURRENT_DH_PRIME + assert dh_prime == Prime.CURRENT_DH_PRIME log.debug("DH parameters check: OK") # https://core.telegram.org/mtproto/security_guidelines#g-a-and-g-b-validation From ef9fc969d3334c8c97c1cdd203055e00093c3707 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 29 Aug 2018 22:20:00 +0200 Subject: [PATCH 198/249] Info log connection settings --- pyrogram/connection/connection.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index ca9bd96c..b9d4cc87 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -58,6 +58,10 @@ class Connection: self.connection.close() time.sleep(1) else: + log.info("Connected! IPv{} - {}".format( + "6" if self.ipv6 else "4", + self.mode.__name__ + )) break else: raise TimeoutError From 43483a1ccdf46644901a8795dd2d03c6ed55e442 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 29 Aug 2018 22:20:32 +0200 Subject: [PATCH 199/249] Remove info logs from protocol impls --- pyrogram/connection/transport/tcp/tcp_abridged.py | 2 -- pyrogram/connection/transport/tcp/tcp_abridged_o.py | 2 -- pyrogram/connection/transport/tcp/tcp_full.py | 1 - pyrogram/connection/transport/tcp/tcp_intermediate.py | 2 -- pyrogram/connection/transport/tcp/tcp_intermediate_o.py | 2 -- 5 files changed, 9 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp_abridged.py b/pyrogram/connection/transport/tcp/tcp_abridged.py index d89421f5..5566b179 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged.py @@ -31,8 +31,6 @@ class TCPAbridged(TCP): super().connect(address) super().sendall(b"\xef") - log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else "")) - def sendall(self, data: bytes, *args): length = len(data) // 4 diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py index 57cc0336..91ee8375 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py @@ -55,8 +55,6 @@ class TCPAbridgedO(TCP): super().sendall(nonce) - log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else "")) - def sendall(self, data: bytes, *args): length = len(data) // 4 diff --git a/pyrogram/connection/transport/tcp/tcp_full.py b/pyrogram/connection/transport/tcp/tcp_full.py index 0aac1a14..8704247b 100644 --- a/pyrogram/connection/transport/tcp/tcp_full.py +++ b/pyrogram/connection/transport/tcp/tcp_full.py @@ -34,7 +34,6 @@ class TCPFull(TCP): def connect(self, address: tuple): super().connect(address) self.seq_no = 0 - log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else "")) def sendall(self, data: bytes, *args): # 12 = packet_length (4), seq_no (4), crc32 (4) (at the end) diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate.py b/pyrogram/connection/transport/tcp/tcp_intermediate.py index b33fe466..aa198db7 100644 --- a/pyrogram/connection/transport/tcp/tcp_intermediate.py +++ b/pyrogram/connection/transport/tcp/tcp_intermediate.py @@ -32,8 +32,6 @@ class TCPIntermediate(TCP): super().connect(address) super().sendall(b"\xee" * 4) - log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else "")) - def sendall(self, data: bytes, *args): super().sendall(pack(" Date: Thu, 30 Aug 2018 01:17:13 +0200 Subject: [PATCH 200/249] Rename "build" to "generate" It was interfering with the built-in command "install" --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 5df52747..a7a1458a 100644 --- a/setup.py +++ b/setup.py @@ -114,12 +114,12 @@ class Clean(Command): print("removing {}".format(path)) -class Build(Command): - description = "Build Pyrogram files" +class Generate(Command): + description = "Generate Pyrogram files" user_options = [ - ("api", None, "Build API files"), - ("docs", None, "Build docs files"), + ("api", None, "Generate API files"), + ("docs", None, "Generate docs files") ] def __init__(self, dist, **kw): @@ -191,6 +191,6 @@ setup( extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]}, cmdclass={ "clean": Clean, - "build": Build, + "generate": Generate } ) From ca15778ac893214db59d521381364e5a5fdb3515 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Aug 2018 01:17:35 +0200 Subject: [PATCH 201/249] Make clean default to all --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a7a1458a..76f1f7a9 100644 --- a/setup.py +++ b/setup.py @@ -102,7 +102,7 @@ class Clean(Command): if self.docs: paths.update(Clean.DOCS) - if self.all: + if self.all or not paths: paths.update(Clean.ALL) for path in sorted(list(paths)): From 2a78dff79cb75769465fe2e10541e4377fc28789 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Aug 2018 01:17:51 +0200 Subject: [PATCH 202/249] Minor style fixes --- setup.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index 76f1f7a9..b8d5c274 100644 --- a/setup.py +++ b/setup.py @@ -46,25 +46,9 @@ def get_readme(): class Clean(Command): - DIST = [ - "./build", - "./dist", - "./Pyrogram.egg-info" - ] - - API = [ - "pyrogram/api/errors/exceptions", - "pyrogram/api/functions", - "pyrogram/api/types", - "pyrogram/api/all.py", - ] - - DOCS = [ - "docs/source/functions", - "docs/source/types", - "docs/build" - ] - + DIST = ["./build", "./dist", "./Pyrogram.egg-info"] + API = ["pyrogram/api/errors/exceptions", "pyrogram/api/functions", "pyrogram/api/types", "pyrogram/api/all.py"] + DOCS = ["docs/source/functions", "docs/source/types", "docs/build"] ALL = DIST + API + DOCS description = "Clean generated files" From 9f4d7854e8f91ef79562e6566085e3ea6bc0e735 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Aug 2018 01:23:19 +0200 Subject: [PATCH 203/249] Fix ipv6 branch merge mess --- pyrogram/client/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 7d195e01..e9be7a4e 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1074,7 +1074,7 @@ class Client(Methods, BaseClient): file_id = file_id or self.rnd_id() md5_sum = md5() if not is_big and not is_missing_part else None - session = Session(self, self.ipv6, self.dc_id, self.auth_key, is_media=True) + session = Session(self, self.dc_id, self.auth_key, is_media=True) session.start() try: @@ -1160,7 +1160,7 @@ class Client(Methods, BaseClient): session = Session( self, dc_id, - Auth(dc_id, self.test_mode, self._proxy).create(), + Auth(dc_id, self.test_mode, self.ipv6, self._proxy).create(), is_media=True ) @@ -1245,7 +1245,7 @@ class Client(Methods, BaseClient): cdn_session = Session( self, r.dc_id, - Auth(r.dc_id, self.test_mode, self._proxy).create(), + Auth(r.dc_id, self.test_mode, self.ipv6, self._proxy).create(), is_media=True, is_cdn=True ) From d5ca99dfffcf2521e0e53dbace70aa3a3b6a665d Mon Sep 17 00:00:00 2001 From: zeroone2numeral2 Date: Thu, 30 Aug 2018 11:50:09 +0200 Subject: [PATCH 204/249] Allow to set audio thumbnail when using send_audio With the Bot API 4.0 update (https://core.telegram.org/bots/api#july-26-2018), sendAudio allows bots to pass a thumbnail - making it possible for pyrogram to include a 'thumb' parameter in its convenience method 'send_audio' --- pyrogram/client/methods/messages/send_audio.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 7d590b79..43635f01 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -35,6 +35,7 @@ class SendAudio(BaseClient): duration: int = 0, performer: str = None, title: str = None, + thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None, @@ -74,6 +75,11 @@ class SendAudio(BaseClient): title (``str``, *optional*): Track name. + thumb (``str``, *optional*): + Audio 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. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -118,10 +124,12 @@ class SendAudio(BaseClient): style = self.html if parse_mode.lower() == "html" else self.markdown if os.path.exists(audio): + thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(audio, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), file=file, + thumb=thumb, attributes=[ types.DocumentAttributeAudio( duration=duration, From a5979a3ac7b1a3bef249ab111642dafe1c57a026 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 31 Aug 2018 12:56:05 +0200 Subject: [PATCH 205/249] Update tgcrypto function names --- pyrogram/crypto/aes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index e4fb94b1..065a5b4d 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -30,19 +30,19 @@ try: # 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: From f576fc899dc5765822a01d2af1696db648256c82 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 31 Aug 2018 13:12:13 +0200 Subject: [PATCH 206/249] Remove TODO --- pyrogram/crypto/aes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index 065a5b4d..f16688c4 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -27,7 +27,6 @@ try: class AES: - # TODO: Use new tgcrypto function names @classmethod def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes: return tgcrypto.ige256_encrypt(data, key, iv) From 07a9cce8efe1b2353556298e3351611eaa0007b8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 1 Sep 2018 00:58:44 +0200 Subject: [PATCH 207/249] Add missing InputMedia types to docs --- docs/source/pyrogram/Types.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst index 92093b11..e8dc709c 100644 --- a/docs/source/pyrogram/Types.rst +++ b/docs/source/pyrogram/Types.rst @@ -62,6 +62,9 @@ Input Media InputMediaPhoto InputMediaVideo + InputMediaAudio + InputMediaAnimation + InputMediaDocument InputPhoneContact .. User & Chats @@ -172,5 +175,14 @@ Input Media .. autoclass:: InputMediaVideo :members: +.. autoclass:: InputMediaAudio + :members: + +.. autoclass:: InputMediaAnimation + :members: + +.. autoclass:: InputMediaDocument + :members: + .. autoclass:: InputPhoneContact :members: From 4c9d9d84f289c40c3c9b44491db47d2c88b00204 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 1 Sep 2018 01:27:22 +0200 Subject: [PATCH 208/249] Change the way int to bytes conversion is used Maybe at some point I should switch to struct --- pyrogram/api/core/primitives/bool.py | 2 +- pyrogram/api/core/primitives/bytes.py | 2 +- pyrogram/api/core/primitives/int.py | 2 +- pyrogram/api/core/primitives/null.py | 2 +- pyrogram/crypto/rsa.py | 14 +++++--------- pyrogram/session/auth.py | 20 ++++++++++---------- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/pyrogram/api/core/primitives/bool.py b/pyrogram/api/core/primitives/bool.py index cc8655d9..9641e865 100644 --- a/pyrogram/api/core/primitives/bool.py +++ b/pyrogram/api/core/primitives/bool.py @@ -30,7 +30,7 @@ class BoolFalse(Object): return cls.value def __new__(cls) -> bytes: - return int.to_bytes(cls.ID, 4, "little") + return cls.ID.to_bytes(4, "little") class BoolTrue(BoolFalse): diff --git a/pyrogram/api/core/primitives/bytes.py b/pyrogram/api/core/primitives/bytes.py index da438ef1..d161cc9c 100644 --- a/pyrogram/api/core/primitives/bytes.py +++ b/pyrogram/api/core/primitives/bytes.py @@ -48,7 +48,7 @@ class Bytes(Object): else: return ( bytes([254]) - + int.to_bytes(length, 3, "little") + + length.to_bytes(3, "little") + value + bytes(-length % 4) ) diff --git a/pyrogram/api/core/primitives/int.py b/pyrogram/api/core/primitives/int.py index 0985367f..3de37151 100644 --- a/pyrogram/api/core/primitives/int.py +++ b/pyrogram/api/core/primitives/int.py @@ -29,7 +29,7 @@ class Int(Object): return int.from_bytes(b.read(cls.SIZE), "little", signed=signed) def __new__(cls, value: int, signed: bool = True) -> bytes: - return int.to_bytes(value, cls.SIZE, "little", signed=signed) + return value.to_bytes(cls.SIZE, "little", signed=signed) class Long(Int): diff --git a/pyrogram/api/core/primitives/null.py b/pyrogram/api/core/primitives/null.py index 3d73c06e..7a26b112 100644 --- a/pyrogram/api/core/primitives/null.py +++ b/pyrogram/api/core/primitives/null.py @@ -29,4 +29,4 @@ class Null(Object): return None def __new__(cls) -> bytes: - return int.to_bytes(cls.ID, 4, "little") + return cls.ID.to_bytes(4, "little") diff --git a/pyrogram/crypto/rsa.py b/pyrogram/crypto/rsa.py index 9f02e2cc..10302dab 100644 --- a/pyrogram/crypto/rsa.py +++ b/pyrogram/crypto/rsa.py @@ -206,12 +206,8 @@ class RSA: @classmethod def encrypt(cls, data: bytes, fingerprint: int) -> bytes: - return int.to_bytes( - pow( - int.from_bytes(data, "big"), - cls.server_public_keys[fingerprint].e, - cls.server_public_keys[fingerprint].m - ), - 256, - "big" - ) + return pow( + int.from_bytes(data, "big"), + cls.server_public_keys[fingerprint].e, + cls.server_public_keys[fingerprint].m + ).to_bytes(256, "big") diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index a545a642..87817da1 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -111,8 +111,8 @@ class Auth: data = types.PQInnerData( res_pq.pq, - int.to_bytes(p, 4, "big"), - int.to_bytes(q, 4, "big"), + p.to_bytes(4, "big"), + q.to_bytes(4, "big"), nonce, server_nonce, new_nonce, @@ -131,8 +131,8 @@ class Auth: functions.ReqDHParams( nonce, server_nonce, - int.to_bytes(p, 4, "big"), - int.to_bytes(q, 4, "big"), + p.to_bytes(4, "big"), + q.to_bytes(4, "big"), public_key_fingerprint, encrypted_data ) @@ -140,8 +140,8 @@ class Auth: encrypted_answer = server_dh_params.encrypted_answer - server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True) - new_nonce = int.to_bytes(new_nonce, 32, "little", signed=True) + server_nonce = server_nonce.to_bytes(16, "little", signed=True) + new_nonce = new_nonce.to_bytes(32, "little", signed=True) tmp_aes_key = ( sha1(new_nonce + server_nonce).digest() @@ -170,7 +170,7 @@ class Auth: # Step 6 g = server_dh_inner_data.g b = int.from_bytes(urandom(256), "big") - g_b = int.to_bytes(pow(g, b, dh_prime), 256, "big") + g_b = pow(g, b, dh_prime).to_bytes(256, "big") retry_id = 0 @@ -199,8 +199,8 @@ class Auth: # Step 7; Step 8 g_a = int.from_bytes(server_dh_inner_data.g_a, "big") - auth_key = int.to_bytes(pow(g_a, b, dh_prime), 256, "big") - server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True) + auth_key = pow(g_a, b, dh_prime).to_bytes(256, "big") + server_nonce = server_nonce.to_bytes(16, "little", signed=True) # TODO: Handle errors @@ -235,7 +235,7 @@ class Auth: # 3rd message assert nonce == set_client_dh_params_answer.nonce assert server_nonce == set_client_dh_params_answer.server_nonce - server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True) + server_nonce = server_nonce.to_bytes(16, "little", signed=True) log.debug("Nonce fields check: OK") # Step 9 From db6042e91b1b8dfafa2ae51e9e2b8c4d07b6a329 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 2 Sep 2018 13:04:29 +0200 Subject: [PATCH 209/249] Fetch ChatForbidden and ChannelForbidden peers This fixes unwanted PEER_ID_INVALID errors in cases where a user or a bot was kicked/banned from a group, supergroup or channel --- pyrogram/client/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e9be7a4e..a3cbd93b 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -615,7 +615,7 @@ class Client(Methods, BaseClient): if phone is not None: self.peers_by_phone[phone] = input_peer - if isinstance(entity, types.Chat): + if isinstance(entity, (types.Chat, types.ChatForbidden)): chat_id = entity.id peer_id = -chat_id @@ -625,7 +625,7 @@ class Client(Methods, BaseClient): self.peers_by_id[peer_id] = input_peer - if isinstance(entity, types.Channel): + if isinstance(entity, (types.Channel, types.ChannelForbidden)): channel_id = entity.id peer_id = int("-100" + str(channel_id)) @@ -634,7 +634,7 @@ class Client(Methods, BaseClient): if access_hash is None: continue - username = entity.username + username = getattr(entity, "username", None) input_peer = types.InputPeerChannel( channel_id=channel_id, From b619818c407c4ec298e563614360db7d811e0830 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Sep 2018 16:35:22 +0200 Subject: [PATCH 210/249] Clear recv_queue on session stop. Fixes #103 --- pyrogram/session/session.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index b7645b11..2372d6bf 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -196,6 +196,7 @@ class Session: i.join() self.net_worker_list.clear() + self.recv_queue.queue.clear() for i in self.results.values(): i.event.set() From 392f0070fb694c0bc4d3f4a767ebcd3d392d7f93 Mon Sep 17 00:00:00 2001 From: Konstantin Klimov Date: Tue, 4 Sep 2018 08:25:56 +0300 Subject: [PATCH 211/249] Fixed decode error in `api.core.primitives.string.py` --- pyrogram/api/core/primitives/string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/api/core/primitives/string.py b/pyrogram/api/core/primitives/string.py index 5c05e5b0..7d26fb57 100644 --- a/pyrogram/api/core/primitives/string.py +++ b/pyrogram/api/core/primitives/string.py @@ -24,7 +24,7 @@ from . import Bytes class String(Bytes): @staticmethod def read(b: BytesIO, *args) -> str: - return super(String, String).read(b).decode() + return super(String, String).read(b).decode(errors='replace') def __new__(cls, value: str) -> bytes: return super().__new__(cls, value.encode()) From b64d66130542b9d9aeb913c5c3b5f8280a306930 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Sep 2018 16:41:46 +0200 Subject: [PATCH 212/249] Restore original Makefile --- docs/Makefile | 2 +- docs/Makefile_ | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 docs/Makefile_ diff --git a/docs/Makefile b/docs/Makefile index c01e3d3d..c647eb13 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ # You can set these variables from the command line. SPHINXOPTS = -SPHINXBUILD = ~/PycharmProjects/pyrogram/venv3.6/bin/sphinx-build +SPHINXBUILD = sphinx-build SPHINXPROJ = Pyrogram SOURCEDIR = source BUILDDIR = build diff --git a/docs/Makefile_ b/docs/Makefile_ deleted file mode 100644 index c647eb13..00000000 --- a/docs/Makefile_ +++ /dev/null @@ -1,20 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SPHINXPROJ = Pyrogram -SOURCEDIR = source -BUILDDIR = build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file From 024e3280c1c623ff92ed70e810033f5c04e0079d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Sep 2018 16:44:07 +0200 Subject: [PATCH 213/249] Remove unneeded file --- compiler/api/compiler.py | 5 ++--- compiler/api/source/pyrogram.tl | 22 ---------------------- 2 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 compiler/api/source/pyrogram.tl diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 555d1824..bcb96ea4 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -172,9 +172,8 @@ def start(): with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \ open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ - open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api, \ - open("{}/source/pyrogram.tl".format(HOME), encoding="utf-8") as pyrogram: - schema = (auth.read() + system.read() + api.read() + pyrogram.read()).splitlines() + open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: + schema = (auth.read() + system.read() + api.read()).splitlines() with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f: mtproto_template = f.read() diff --git a/compiler/api/source/pyrogram.tl b/compiler/api/source/pyrogram.tl deleted file mode 100644 index a8232bd6..00000000 --- a/compiler/api/source/pyrogram.tl +++ /dev/null @@ -1,22 +0,0 @@ -// Pyrogram - ----types--- - -//pyrogram.update#b0700000 flags:# update_id:int message:flags.0?Message edited_message:flags.1?Message channel_post:flags.2?Message edited_channel_post:flags.3?Message inline_query:flags.4?InlineQuery chosen_inline_result:flags.5?ChosenInlineResult callback_query:flags.6?CallbackQuery shipping_query:flags.7?ShippingQuery pre_checkout_query:flags.8?PreCheckoutQuery = pyrogram.Update; -//pyrogram.user#b0700001 flags:# id:int is_bot:Bool first_name:string last_name:flags.0?string username:flags.1?string language_code:flags.2?string phone_number:flags.3?string photo:flags.4?ChatPhoto = pyrogram.User; -//pyrogram.chat#b0700002 flags:# id:int type:string title:flags.0?string username:flags.1?string first_name:flags.2?string last_name:flags.3?string all_members_are_administrators:flags.4?Bool photo:flags.5?ChatPhoto description:flags.6?string invite_link:flags.7?string pinned_message:flags.8?Message sticker_set_name:flags.9?string can_set_sticker_set:flags.10?Bool = pyrogram.Chat; -//pyrogram.message#b0700003 flags:# message_id:int from_user:flags.0?User date:int chat:Chat forward_from:flags.1?User forward_from_chat:flags.2?Chat forward_from_message_id:flags.3?int forward_signature:flags.4?string forward_date:flags.5?int reply_to_message:flags.6?Message edit_date:flags.7?int media_group_id:flags.8?string author_signature:flags.9?string text:flags.10?string entities:flags.11?Vector caption_entities:flags.12?Vector audio:flags.13?Audio document:flags.14?Document game:flags.15?Game photo:flags.16?Vector sticker:flags.17?Sticker video:flags.18?Video voice:flags.19?Voice video_note:flags.20?VideoNote caption:flags.21?string contact:flags.22?Contact location:flags.23?Location venue:flags.24?Venue new_chat_members:flags.25?Vector left_chat_member:flags.26?User new_chat_title:flags.27?string new_chat_photo:flags.28?Vector delete_chat_photo:flags.29?true group_chat_created:flags.30?true supergroup_chat_created:flags.31?true channel_chat_created:flags.32?true migrate_to_chat_id:flags.33?int migrate_from_chat_id:flags.34?int pinned_message:flags.35?Message invoice:flags.36?Invoice successful_payment:flags.37?SuccessfulPayment connected_website:flags.38?string views:flags.39?int via_bot:flags.40?User = pyrogram.Message; -//pyrogram.messageEntity#b0700004 flags:# type:string offset:int length:int url:flags.0?string user:flags.1?User = pyrogram.MessageEntity; -//pyrogram.photoSize#b0700005 flags:# file_id:string file_size:flags.0?int date:flags.1?int width:int height:int = pyrogram.PhotoSize; -//pyrogram.audio#b0700006 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int performer:flags.5?string title:flags.6?string = pyrogram.Audio; -//pyrogram.document#b0700007 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int = pyrogram.Document; -//pyrogram.video#b0700008 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int duration:int = pyrogram.Video; -//pyrogram.voice#b0700009 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int = pyrogram.Voice; -//pyrogram.videoNote#b0700010 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int length:int duration:int = pyrogram.VideoNote; -//pyrogram.contact#b0700011 flags:# phone_number:string first_name:string last_name:flags.0?string user_id:flags.1?int = pyrogram.Contact; -//pyrogram.location#b0700012 longitude:double latitude:double = pyrogram.Location; -//pyrogram.venue#b0700013 flags:# location:Location title:string address:string foursquare_id:flags.0?string = pyrogram.Venue; -//pyrogram.userProfilePhotos#b0700014 total_count:int photos:Vector> = pyrogram.UserProfilePhotos; -//pyrogram.chatPhoto#b0700015 small_file_id:string big_file_id:string = pyrogram.ChatPhoto; -//pyrogram.chatMember#b0700016 flags:# user:User status:string until_date:flags.0?int can_be_edited:flags.1?Bool can_change_info:flags.2?Bool can_post_messages:flags.3?Bool can_edit_messages:flags.4?Bool can_delete_messages:flags.5?Bool can_invite_users:flags.6?Bool can_restrict_members:flags.7?Bool can_pin_messages:flags.8?Bool can_promote_members:flags.9?Bool can_send_messages:flags.10?Bool can_send_media_messages:flags.11?Bool can_send_other_messages:flags.12?Bool can_add_web_page_previews:flags.13?Bool = pyrogram.ChatMember; -//pyrogram.sticker#b0700017 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int emoji:flags.5?string set_name:flags.6?string mask_position:flags.7?MaskPosition = pyrogram.Sticker; From b07c13a5131c3c5fddf8b3940e7c44b8a7b264bc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Sep 2018 16:50:38 +0200 Subject: [PATCH 214/249] Remove useless definition PyCharm will complain about Long not being a bytes, let's not care. --- pyrogram/api/core/primitives/int.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyrogram/api/core/primitives/int.py b/pyrogram/api/core/primitives/int.py index 3de37151..4b9aded8 100644 --- a/pyrogram/api/core/primitives/int.py +++ b/pyrogram/api/core/primitives/int.py @@ -35,9 +35,6 @@ class Int(Object): class Long(Int): SIZE = 8 - def __new__(cls, *args): - return super().__new__(cls, *args) - class Int128(Int): SIZE = 16 From ea39062d2d1c2f4d9ade1ac237962879bee5efb1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Sep 2018 19:16:51 +0200 Subject: [PATCH 215/249] Add get_chat_members_count method --- pyrogram/client/methods/chats/__init__.py | 4 +- .../methods/chats/get_chat_members_count.py | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/chats/get_chat_members_count.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 72134abf..f9eb25f3 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -21,6 +21,7 @@ from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers +from .get_chat_members_count import GetChatMembersCount from .get_dialogs import GetDialogs from .join_chat import JoinChat from .kick_chat_member import KickChatMember @@ -52,6 +53,7 @@ class Chats( SetChatDescription, PinChatMessage, UnpinChatMessage, - GetDialogs + GetDialogs, + GetChatMembersCount ): pass diff --git a/pyrogram/client/methods/chats/get_chat_members_count.py b/pyrogram/client/methods/chats/get_chat_members_count.py new file mode 100644 index 00000000..efe53c19 --- /dev/null +++ b/pyrogram/client/methods/chats/get_chat_members_count.py @@ -0,0 +1,53 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class GetChatMembersCount(BaseClient): + def get_chat_members_count(self, chat_id: int or str): + """Use this method to get the number of members in a chat. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + On success, an integer is returned. + + Raises: + :class:`Error + ``ValueError``: If a chat_id belongs to user. + """ + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChat): + return self.send( + functions.messages.GetChats( + id=[peer.chat_id] + ) + ).chats[0].participants_count + elif isinstance(peer, types.InputPeerChannel): + return self.send( + functions.channels.GetFullChannel( + channel=peer + ) + ).full_chat.participants_count + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) From 05b3be1e885c21f2dfd920e9cafa49bc9c6ab303 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Sep 2018 19:33:47 +0200 Subject: [PATCH 216/249] Info log DC number on connection --- pyrogram/connection/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index b9d4cc87..e10011d1 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -38,6 +38,7 @@ class Connection: } def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, mode: int = 1): + self.dc_id = dc_id self.ipv6 = ipv6 self.proxy = proxy self.address = DataCenter(dc_id, test_mode, ipv6) @@ -58,7 +59,8 @@ class Connection: self.connection.close() time.sleep(1) else: - log.info("Connected! IPv{} - {}".format( + log.info("Connected! DC{} - IPv{} - {}".format( + self.dc_id, "6" if self.ipv6 else "4", self.mode.__name__ )) From b1aff3ca5e3b670ebdbc618581f97dfdbc477876 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 12 Sep 2018 07:44:49 +0200 Subject: [PATCH 217/249] Small style fixes "double quotes" --- pyrogram/api/core/primitives/string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/api/core/primitives/string.py b/pyrogram/api/core/primitives/string.py index 7d26fb57..3584d1b9 100644 --- a/pyrogram/api/core/primitives/string.py +++ b/pyrogram/api/core/primitives/string.py @@ -24,7 +24,7 @@ from . import Bytes class String(Bytes): @staticmethod def read(b: BytesIO, *args) -> str: - return super(String, String).read(b).decode(errors='replace') + return super(String, String).read(b).decode(errors="replace") def __new__(cls, value: str) -> bytes: return super().__new__(cls, value.encode()) From 6a4bf23b0925e1f17945f9b7e95d8f29f8e6a642 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 12 Sep 2018 08:14:49 +0200 Subject: [PATCH 218/249] Update send_audio docstrings --- pyrogram/client/methods/messages/send_audio.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 43635f01..4d9c729d 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -76,9 +76,10 @@ class SendAudio(BaseClient): Track name. thumb (``str``, *optional*): - Audio 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 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. disable_notification (``bool``, *optional*): Sends the message silently. From eb8513e00900bd0e3b343756eec23c2484260e60 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 12 Sep 2018 08:26:13 +0200 Subject: [PATCH 219/249] Update send_video docstrings Add a more detailed "thumb" description --- pyrogram/client/methods/messages/send_video.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index b86b4702..f646d425 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -75,9 +75,10 @@ class SendVideo(BaseClient): Video height. thumb (``str``, *optional*): - Video 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 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. supports_streaming (``bool``, *optional*): Pass True, if the uploaded video is suitable for streaming. From b893698f1e8bbd04d44dfb4fd6d2a01e98c60908 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 14:37:04 +0200 Subject: [PATCH 220/249] Add ability to add/remove users from the user filter. Use .users to access the inner set of users --- pyrogram/client/filters/filters.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 4cd4b191..26ef8219 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -237,23 +237,27 @@ class Filters: return create("Regex", f, p=re.compile(pattern, flags)) @staticmethod - def user(user: int or str or list): - """Filter messages coming from specific users. + def user(users: int or str or list = None): + """Filter messages coming from one or more specific users. Args: - user (``int`` | ``str`` | ``list``): - The user or list of user IDs (int) or usernames (str) the filter should look for. + users (``int`` | ``str`` | ``list``): + Pass one or more user ids/usernames to filter the users. + The argument passed will be stored as a python set in the *.users* field of the filter instance. + To add or remove users dynamically, simply manipulate the inner set. + Defaults to None (empty set). """ return create( "User", lambda _, m: bool(m.from_user - and (m.from_user.id in _.u + and (m.from_user.id in _.users or (m.from_user.username - and m.from_user.username.lower() in _.u))), - u=( - {user.lower().strip("@") if type(user) is str else user} - if not isinstance(user, list) - else {i.lower().strip("@") if type(i) is str else i for i in user} + and m.from_user.username.lower() in _.users))), + users=( + set() if users is None + else {users.lower().strip("@") if type(users) is str else users} + if not isinstance(users, list) + else {i.lower().strip("@") if type(i) is str else i for i in users} ) ) From 4e293f23a92de671a39b801f02256ec9dca04799 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:28:08 +0200 Subject: [PATCH 221/249] Make handlers test whether filters are callable and not if they exist --- pyrogram/client/handlers/callback_query_handler.py | 2 +- pyrogram/client/handlers/deleted_messages_handler.py | 2 +- pyrogram/client/handlers/message_handler.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/handlers/callback_query_handler.py b/pyrogram/client/handlers/callback_query_handler.py index c5346519..5d09f7d9 100644 --- a/pyrogram/client/handlers/callback_query_handler.py +++ b/pyrogram/client/handlers/callback_query_handler.py @@ -49,6 +49,6 @@ class CallbackQueryHandler(Handler): def check(self, callback_query): return ( self.filters(callback_query) - if self.filters + if callable(self.filters) else True ) diff --git a/pyrogram/client/handlers/deleted_messages_handler.py b/pyrogram/client/handlers/deleted_messages_handler.py index 55d5715f..8f5ef448 100644 --- a/pyrogram/client/handlers/deleted_messages_handler.py +++ b/pyrogram/client/handlers/deleted_messages_handler.py @@ -50,6 +50,6 @@ class DeletedMessagesHandler(Handler): def check(self, messages): return ( self.filters(messages.messages[0]) - if self.filters + if callable(self.filters) else True ) diff --git a/pyrogram/client/handlers/message_handler.py b/pyrogram/client/handlers/message_handler.py index 1b4770b3..e4c3d13f 100644 --- a/pyrogram/client/handlers/message_handler.py +++ b/pyrogram/client/handlers/message_handler.py @@ -50,6 +50,6 @@ class MessageHandler(Handler): def check(self, message): return ( self.filters(message) - if self.filters + if callable(self.filters) else True ) From 31578ddb33cdd29e13a3bee3320d9053be9f2fbf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:29:36 +0200 Subject: [PATCH 222/249] Give Filters.user superpowers It can now add and remove users at runtime --- pyrogram/client/filters/filters.py | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 26ef8219..7636f382 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -236,30 +236,33 @@ class Filters: return create("Regex", f, p=re.compile(pattern, flags)) - @staticmethod - def user(users: int or str or list = None): - """Filter messages coming from one or more specific users. + class user(Filter, set): + """Filter messages coming from one or more users. + + You can use `set bound methods `_ to manipulate the + users container. Args: users (``int`` | ``str`` | ``list``): Pass one or more user ids/usernames to filter the users. - The argument passed will be stored as a python set in the *.users* field of the filter instance. - To add or remove users dynamically, simply manipulate the inner set. - Defaults to None (empty set). + Defaults to None (no users). """ - return create( - "User", - lambda _, m: bool(m.from_user - and (m.from_user.id in _.users - or (m.from_user.username - and m.from_user.username.lower() in _.users))), - users=( - set() if users is None - else {users.lower().strip("@") if type(users) is str else users} - if not isinstance(users, list) - else {i.lower().strip("@") if type(i) is str else i for i in users} + + def __init__(self, users: int or str or list = None): + users = [] if users is None else users if type(users) is list else [users] + super().__init__( + {i.lower().strip("@") if type(i) is str else i for i in users} + if type(users) is list else + {users.lower().strip("@") if type(users) is str else users} + ) + + def __call__(self, message): + return bool( + message.from_user + and (message.from_user.id in self + or (message.from_user.username + and message.from_user.username.lower() in self)) ) - ) @staticmethod def chat(chat: int or str or list): From 339630dafb9c0acfe32f3a028fbf47be6c68173a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:29:56 +0200 Subject: [PATCH 223/249] Add noinspection PyPep8Naming for Filters.user --- pyrogram/client/filters/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 7636f382..e218155a 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -236,6 +236,7 @@ class Filters: return create("Regex", f, p=re.compile(pattern, flags)) + # noinspection PyPep8Naming class user(Filter, set): """Filter messages coming from one or more users. From 3307b410b4dd2b0fdcebe2d740985a52d90fcc68 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:33:32 +0200 Subject: [PATCH 224/249] Give superpowers to Filters.chat too It can now add and remove chats at runtime --- pyrogram/client/filters/filters.py | 40 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index e218155a..a573c875 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -265,26 +265,34 @@ class Filters: and message.from_user.username.lower() in self)) ) - @staticmethod - def chat(chat: int or str or list): - """Filter messages coming from specific chats. + # noinspection PyPep8Naming + class chat(Filter, set): + """Filter messages coming from one or more chats. + + You can use `set bound methods `_ to manipulate the + chats container. Args: - chat (``int`` | ``str`` | ``list``): - The chat or list of chat IDs (int) or usernames (str) the filter should look for. + chats (``int`` | ``str`` | ``list``): + Pass one or more chat ids/usernames to filter the chats. + Defaults to None (no chats). """ - return create( - "Chat", - lambda _, m: bool(m.chat - and (m.chat.id in _.c - or (m.chat.username - and m.chat.username.lower() in _.c))), - c=( - {chat.lower().strip("@") if type(chat) is str else chat} - if not isinstance(chat, list) - else {i.lower().strip("@") if type(i) is str else i for i in chat} + + def __init__(self, chats: int or str or list = None): + chats = [] if chats is None else chats if type(chats) is list else [chats] + super().__init__( + {i.lower().strip("@") if type(i) is str else i for i in chats} + if type(chats) is list else + {chats.lower().strip("@") if type(chats) is str else chats} + ) + + def __call__(self, message): + return bool( + message.chat + and (message.chat.id in self + or (message.chat.username + and message.chat.username.lower() in self)) ) - ) service = create( "Service", From edfdf9d143279aec29e7034a67163d6a956cd972 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:34:00 +0200 Subject: [PATCH 225/249] Small docstring fixes --- pyrogram/client/filters/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index a573c875..79ab0f5f 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -245,7 +245,7 @@ class Filters: Args: users (``int`` | ``str`` | ``list``): - Pass one or more user ids/usernames to filter the users. + Pass one or more user ids/usernames to filter users. Defaults to None (no users). """ @@ -274,7 +274,7 @@ class Filters: Args: chats (``int`` | ``str`` | ``list``): - Pass one or more chat ids/usernames to filter the chats. + Pass one or more chat ids/usernames to filter chats. Defaults to None (no chats). """ From c75a4f182a0d788badfe3b7753604bbbb213ffc0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 15 Sep 2018 13:23:25 +0200 Subject: [PATCH 226/249] Handle Telegram exceptions on start(). Fixes #121 The client doesn't need to be stopped as it never started successfully. --- pyrogram/client/client.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 709ea95a..f0134be0 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -215,29 +215,34 @@ class Client(Methods, BaseClient): self.session.start() self.is_started = True + + try: + if self.user_id is None: + if self.token is None: + self.authorize_user() + else: + self.authorize_bot() + + self.save_session() - if self.user_id is None: if self.token is None: - self.authorize_user() + now = time.time() + + if abs(now - self.date) > Client.OFFLINE_SLEEP: + self.peers_by_username = {} + self.peers_by_phone = {} + + self.get_initial_dialogs() + self.get_contacts() + else: + self.send(functions.messages.GetPinnedDialogs()) + self.get_initial_dialogs_chunk() else: - self.authorize_bot() - - self.save_session() - - if self.token is None: - now = time.time() - - if abs(now - self.date) > Client.OFFLINE_SLEEP: - self.peers_by_username = {} - self.peers_by_phone = {} - - self.get_initial_dialogs() - self.get_contacts() - else: - self.send(functions.messages.GetPinnedDialogs()) - self.get_initial_dialogs_chunk() - else: - self.send(functions.updates.GetState()) + self.send(functions.updates.GetState()) + except Exception as e: + self.is_started = False + self.session.stop() + raise e for i in range(self.UPDATES_WORKERS): self.updates_workers_list.append( From d2d4f55673453dec7167895a5b221c19fa838288 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Sep 2018 16:53:17 +0200 Subject: [PATCH 227/249] Revert "Remove TODO" This reverts commit f576fc8 --- pyrogram/crypto/aes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index f16688c4..065a5b4d 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -27,6 +27,7 @@ try: class AES: + # TODO: Use new tgcrypto function names @classmethod def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes: return tgcrypto.ige256_encrypt(data, key, iv) From 0f0e757f4c1647b16e02570521ba8131e9cfb3cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Sep 2018 16:53:21 +0200 Subject: [PATCH 228/249] Revert "Update tgcrypto function names" This reverts commit a5979a3 --- pyrogram/crypto/aes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index 065a5b4d..e4fb94b1 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -30,19 +30,19 @@ try: # TODO: Use new tgcrypto function names @classmethod def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes: - return tgcrypto.ige256_encrypt(data, key, iv) + return tgcrypto.ige_encrypt(data, key, iv) @classmethod def ige256_decrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes: - return tgcrypto.ige256_decrypt(data, key, iv) + return tgcrypto.ige_decrypt(data, key, iv) @staticmethod def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes: - return tgcrypto.ctr256_encrypt(data, key, iv, state or bytearray(1)) + return tgcrypto.ctr_encrypt(data, key, iv, state or bytearray(1)) @staticmethod def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes: - return tgcrypto.ctr256_decrypt(data, key, iv, state or bytearray(1)) + return tgcrypto.ctr_decrypt(data, key, iv, state or bytearray(1)) @staticmethod def xor(a: bytes, b: bytes) -> bytes: From cd3649448cdbde1eda8d0a1adde9387c85ad66ac Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Sep 2018 18:44:13 +0200 Subject: [PATCH 229/249] Add CHAT_WRITE_FORBIDDEN error --- compiler/error/source/403_FORBIDDEN.tsv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 compiler/error/source/403_FORBIDDEN.tsv diff --git a/compiler/error/source/403_FORBIDDEN.tsv b/compiler/error/source/403_FORBIDDEN.tsv new file mode 100644 index 00000000..7bacbe7d --- /dev/null +++ b/compiler/error/source/403_FORBIDDEN.tsv @@ -0,0 +1,2 @@ +id message +CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat \ No newline at end of file From f850d6352ed160fda27721209f14fdf2805d1920 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Sep 2018 18:53:04 +0200 Subject: [PATCH 230/249] Enhance API by adding support for Context Managers. Closes #122 A batch script would be as simple as this example: from pyrogram import Client with Client("...") as app: app.send_message("haskell", "hi") --- pyrogram/client/client.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 97002e79..f501c01a 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -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 From 19d04ca94fe3d6b79e2bf54ef925ea5e141a32e6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 11:35:19 +0200 Subject: [PATCH 231/249] Reword Audio thumb description --- pyrogram/client/types/messages_and_media/audio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/messages_and_media/audio.py b/pyrogram/client/types/messages_and_media/audio.py index 57731266..37f91992 100644 --- a/pyrogram/client/types/messages_and_media/audio.py +++ b/pyrogram/client/types/messages_and_media/audio.py @@ -30,7 +30,7 @@ class Audio(Object): Duration of the audio in seconds as defined by sender. thumb (:obj:`PhotoSize `, *optional*): - Audio thumbnail. + Thumbnail of the music file album cover. file_name (``str``, *optional*): Audio file name. From 28af5e14b4a2b23c4e57994c9c769fff660b4899 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 11:36:20 +0200 Subject: [PATCH 232/249] Add "thumb" field for all InputMedia types except Photo --- .../client/types/input_media/input_media_animation.py | 8 ++++++++ pyrogram/client/types/input_media/input_media_audio.py | 8 ++++++++ .../client/types/input_media/input_media_document.py | 9 +++++++++ pyrogram/client/types/input_media/input_media_video.py | 8 ++++++++ 4 files changed, 33 insertions(+) diff --git a/pyrogram/client/types/input_media/input_media_animation.py b/pyrogram/client/types/input_media/input_media_animation.py index 12fe0e03..14f8c2de 100644 --- a/pyrogram/client/types/input_media/input_media_animation.py +++ b/pyrogram/client/types/input_media/input_media_animation.py @@ -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 diff --git a/pyrogram/client/types/input_media/input_media_audio.py b/pyrogram/client/types/input_media/input_media_audio.py index 2c644107..83979b4a 100644 --- a/pyrogram/client/types/input_media/input_media_audio.py +++ b/pyrogram/client/types/input_media/input_media_audio.py @@ -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 diff --git a/pyrogram/client/types/input_media/input_media_document.py b/pyrogram/client/types/input_media/input_media_document.py index f64da619..07965534 100644 --- a/pyrogram/client/types/input_media/input_media_document.py +++ b/pyrogram/client/types/input_media/input_media_document.py @@ -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 diff --git a/pyrogram/client/types/input_media/input_media_video.py b/pyrogram/client/types/input_media/input_media_video.py index c1f2c9ac..54ce5e5e 100644 --- a/pyrogram/client/types/input_media/input_media_video.py +++ b/pyrogram/client/types/input_media/input_media_video.py @@ -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 From 61e6e58be7410d055ff65cdab201aa78a0b21592 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 11:36:52 +0200 Subject: [PATCH 233/249] Reword send_animation's thumb parameter description --- pyrogram/client/methods/messages/send_animation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 55123332..30f28b30 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -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. From 42ea51cb77f47ee2d8bdfbde891270c686b256f5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 11:37:11 +0200 Subject: [PATCH 234/249] Make send_document and send_video_note accept a thumbnail #119 --- pyrogram/client/methods/messages/send_document.py | 9 +++++++++ pyrogram/client/methods/messages/send_video_note.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 01c3eca5..28d93f07 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -30,6 +30,7 @@ class SendDocument(BaseClient): def send_document(self, chat_id: int or str, document: str, + thumb: str = None, caption: str = "", parse_mode: str = "", disable_notification: bool = None, @@ -51,6 +52,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 +110,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 self.save_file(thumb) file = 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)) ] diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index 6adc6497..6da1962a 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -32,6 +32,7 @@ class SendVideoNote(BaseClient): video_note: str, duration: int = 0, length: int = 1, + thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None, @@ -57,6 +58,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 +107,12 @@ class SendVideoNote(BaseClient): file = None if os.path.exists(video_note): + thumb = None if thumb is None else self.save_file(thumb) file = 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, From 500ec09b47416c3e6464ca43b12fc5db1161d349 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 19:16:55 +0200 Subject: [PATCH 235/249] Clean up load_config --- pyrogram/client/client.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index f501c01a..3ca979de 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -910,8 +910,6 @@ class Client(Methods, BaseClient): if getattr(self, option): pass else: - setattr(self, option, Client.APP_VERSION) - if parser.has_section("pyrogram"): setattr(self, option, parser.get( "pyrogram", @@ -919,18 +917,6 @@ class Client(Methods, BaseClient): 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 - ) - if self._proxy: self._proxy["enabled"] = True else: From 8b364202c3ee50b8d152c857d9dfb1b61c72356d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 19:17:28 +0200 Subject: [PATCH 236/249] Use list instead of set --- 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 3ca979de..1f25c537 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -906,7 +906,7 @@ 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: From 84492fb942adb3febc05e73ff99d57b5634fdb9c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 18 Sep 2018 21:28:44 +0200 Subject: [PATCH 237/249] Add an extra warning in case connection fails --- pyrogram/connection/connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index e10011d1..8020bc71 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -66,6 +66,7 @@ class Connection: )) break else: + log.warning("Connection failed! Trying again...") raise TimeoutError def close(self): From 7aee163ddd14d85c3cf3c3d2c2a3df92dd1be6cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 11:53:26 +0200 Subject: [PATCH 238/249] Update docs reported version --- docs/source/start/Installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index bba927e4..d3ddfe7d 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -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 \ No newline at end of file From 8adcb34108c45d60f41c1299930278f5ee19d73e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 11:58:48 +0200 Subject: [PATCH 239/249] Update docs logo and badges --- 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 ec6b24f2..0f8a6bf0 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -5,8 +5,7 @@ Welcome to Pyrogram @@ -26,11 +25,11 @@ Welcome to Pyrogram

- Scheme Layer - TgCrypto

From 666c41a79df3afdf2cf4540c389c532a8d23f25d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 12:13:54 +0200 Subject: [PATCH 240/249] Add missing methods to docs --- docs/source/pyrogram/Client.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 45d40368..1cd1a072 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -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 ----- From 9538ed85fecbf8fa106315fdb2ca6906aae1f55e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 13:20:36 +0200 Subject: [PATCH 241/249] Fix missing backtick --- pyrogram/client/methods/chats/get_chat_members_count.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/get_chat_members_count.py b/pyrogram/client/methods/chats/get_chat_members_count.py index efe53c19..41650bdd 100644 --- a/pyrogram/client/methods/chats/get_chat_members_count.py +++ b/pyrogram/client/methods/chats/get_chat_members_count.py @@ -32,7 +32,7 @@ class GetChatMembersCount(BaseClient): On success, an integer is returned. Raises: - :class:`Error + :class:`Error ` ``ValueError``: If a chat_id belongs to user. """ peer = self.resolve_peer(chat_id) From dcd087ba63b54095a5769833a6c75e295c7bb144 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 14:31:51 +0200 Subject: [PATCH 242/249] Revert "Revert "Update tgcrypto function names"" This reverts commit 0f0e757 --- pyrogram/crypto/aes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index e4fb94b1..065a5b4d 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -30,19 +30,19 @@ try: # 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: From 6ce71b404fa8109285ce8cd3ea98aeddfb3c49a7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 14:31:55 +0200 Subject: [PATCH 243/249] Revert "Revert "Remove TODO"" This reverts commit d2d4f55 --- pyrogram/crypto/aes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index 065a5b4d..f16688c4 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -27,7 +27,6 @@ try: class AES: - # TODO: Use new tgcrypto function names @classmethod def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes: return tgcrypto.ige256_encrypt(data, key, iv) From 0f6e5ef29810dd4b89151a1c6e8c1b5b13f2bffe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 14:35:45 +0200 Subject: [PATCH 244/249] Use a stricter tgcrypto version requirement --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b8d5c274..ee0fed9b 100644 --- a/setup.py +++ b/setup.py @@ -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.0"]}, cmdclass={ "clean": Clean, "generate": Generate From 9ef8c786e47438cdf3628fb545e3647840b4f3b6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 16:23:33 +0200 Subject: [PATCH 245/249] Update tgcrypto required version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ee0fed9b..10789e98 100644 --- a/setup.py +++ b/setup.py @@ -172,7 +172,7 @@ setup( packages=find_packages(exclude=["compiler*"]), zip_safe=False, install_requires=read("requirements.txt"), - extras_require={"tgcrypto": ["tgcrypto==1.1.0"]}, + extras_require={"tgcrypto": ["tgcrypto==1.1.1"]}, cmdclass={ "clean": Clean, "generate": Generate From 08f6d0b865480146724f9e8aa3dbe3071b78e0bf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 16:24:30 +0200 Subject: [PATCH 246/249] Fix tgcrypto version in docs index page --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 0f8a6bf0..6e740dd0 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -29,7 +29,7 @@ Welcome to Pyrogram alt="Scheme Layer"> - TgCrypto

From 3a858e6a57c36df41e2b843358c51b7919fa1a67 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 17:30:23 +0200 Subject: [PATCH 247/249] Fix config values not being available when not using config.ini file --- pyrogram/client/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 1f25c537..3d8911a7 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -916,6 +916,8 @@ class Client(Methods, BaseClient): option, fallback=getattr(Client, option.upper()) )) + else: + setattr(self, option, getattr(Client, option.upper())) if self._proxy: self._proxy["enabled"] = True From da92a79b3c1f50559a1e9e04a886d0203297e8b1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 17:47:14 +0200 Subject: [PATCH 248/249] Update README.rst --- README.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 0b9efb76..db2957c3 100644 --- a/README.rst +++ b/README.rst @@ -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

-
Pyrogram Icon
-
Pyrogram Label
+
Pyrogram Logo

Telegram MTProto API Client Library for Python - +
Download @@ -100,25 +99,25 @@ Copyright & License

- Scheme Layer - TgCrypto

-.. |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 From cc47897c6889712158dea83718ad4f2c0bded9c3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 17:47:28 +0200 Subject: [PATCH 249/249] Update to v0.8.0 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 1de05f2c..a1107ee1 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès