From cebecb99c0e53d4de22a335540d84919658e5521 Mon Sep 17 00:00:00 2001 From: Abir Hasan Date: Mon, 13 Dec 2021 18:20:55 +0600 Subject: [PATCH 001/539] Fix renamed raw API function (#810) `raw.functions.channels.DeleteUserHistory` to `raw.functions.channels.DeleteParticipantHistory` --- pyrogram/methods/chats/delete_user_history.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py index e2f780f9fc..8043432de3 100644 --- a/pyrogram/methods/chats/delete_user_history.py +++ b/pyrogram/methods/chats/delete_user_history.py @@ -42,9 +42,9 @@ async def delete_user_history( """ r = await self.send( - raw.functions.channels.DeleteUserHistory( + raw.functions.channels.DeleteParticipantHistory( channel=await self.resolve_peer(chat_id), - user_id=await self.resolve_peer(user_id) + participant=await self.resolve_peer(user_id) ) ) From cd027b8c1c252149cc7304b95b6ec8da53bd01fa Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Dec 2021 13:18:13 +0100 Subject: [PATCH 002/539] Implement missing MTProto checks --- pyrogram/crypto/mtproto.py | 44 ++++++++++++++++++++++++++++--- pyrogram/raw/core/future_salt.py | 9 +++++++ pyrogram/raw/core/future_salts.py | 14 ++++++++++ pyrogram/session/session.py | 8 +++++- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index 803db29704..1eec7b7a3e 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -19,9 +19,11 @@ from hashlib import sha256 from io import BytesIO from os import urandom +from typing import Optional, List from pyrogram.raw.core import Message, Long from . import aes +from ..session.internals import MsgId def kdf(auth_key: bytes, msg_key: bytes, outgoing: bool) -> tuple: @@ -49,13 +51,19 @@ def pack(message: Message, salt: int, session_id: bytes, auth_key: bytes, auth_k return auth_key_id + msg_key + aes.ige256_encrypt(data + padding, aes_key, aes_iv) -def unpack(b: BytesIO, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -> Message: +def unpack( + b: BytesIO, + session_id: bytes, + auth_key: bytes, + auth_key_id: bytes, + stored_msg_ids: List[int] +) -> Optional[Message]: assert b.read(8) == auth_key_id, b.getvalue() msg_key = b.read(16) aes_key, aes_iv = kdf(auth_key, msg_key, False) data = BytesIO(aes.ige256_decrypt(b.read(), aes_key, aes_iv)) - data.read(8) + data.read(8) # Salt # https://core.telegram.org/mtproto/security_guidelines#checking-session-id assert data.read(8) == session_id @@ -75,11 +83,41 @@ def unpack(b: BytesIO, session_id: bytes, auth_key: bytes, auth_key_id: bytes) - raise ValueError(f"The server sent an unknown constructor: {hex(e.args[0])}\n{left}") # https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key - # https://core.telegram.org/mtproto/security_guidelines#checking-message-length # 96 = 88 + 8 (incoming message) assert msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24] + # https://core.telegram.org/mtproto/security_guidelines#checking-message-length + data.seek(32) # Get to the payload, skip salt (8) + session_id (8) + msg_id (8) + seq_no (4) + length (4) + payload = data.read() + padding = payload[message.length:] + assert 12 <= len(padding) <= 1024 + assert len(payload) % 4 == 0 + # https://core.telegram.org/mtproto/security_guidelines#checking-msg-id assert message.msg_id % 2 != 0 + if len(stored_msg_ids) > 200: + stored_msg_ids = stored_msg_ids[50:] + + if stored_msg_ids: + # Ignored message: msg_id is lower than all of the stored values + if message.msg_id < stored_msg_ids[0]: + return None + + # Ignored message: msg_id is equal to any of the stored values + if message.msg_id in stored_msg_ids: + return None + + time_diff = (message.msg_id - MsgId()) / 2 ** 32 + + # Ignored message: msg_id belongs over 30 seconds in the future + if time_diff > 30: + return None + + # Ignored message: msg_id belongs over 300 seconds in the past + if time_diff < -300: + return None + + stored_msg_ids.append(message.msg_id) + return message diff --git a/pyrogram/raw/core/future_salt.py b/pyrogram/raw/core/future_salt.py index 85303d1203..54a1296361 100644 --- a/pyrogram/raw/core/future_salt.py +++ b/pyrogram/raw/core/future_salt.py @@ -42,3 +42,12 @@ def read(data: BytesIO, *args: Any) -> "FutureSalt": salt = Long.read(data) return FutureSalt(valid_since, valid_until, salt) + + def write(self, *args: Any) -> bytes: + b = BytesIO() + + b.write(Int(self.valid_since)) + b.write(Int(self.valid_until)) + b.write(Long(self.salt)) + + return b.getvalue() diff --git a/pyrogram/raw/core/future_salts.py b/pyrogram/raw/core/future_salts.py index faa4b74163..9fa2f8e97e 100644 --- a/pyrogram/raw/core/future_salts.py +++ b/pyrogram/raw/core/future_salts.py @@ -45,3 +45,17 @@ def read(data: BytesIO, *args: Any) -> "FutureSalts": salts = [FutureSalt.read(data) for _ in range(count)] return FutureSalts(req_msg_id, now, salts) + + def write(self, *args: Any) -> bytes: + b = BytesIO() + + b.write(Long(self.req_msg_id)) + b.write(Int(self.now)) + + count = len(self.salts) + b.write(Int(count)) + + for salt in self.salts: + b.write(salt.write()) + + return b.getvalue() diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 721586a01c..39fe605ca3 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -102,6 +102,8 @@ def __init__( self.results = {} + self.stored_msg_ids = [] + self.ping_task = None self.ping_task_event = asyncio.Event() @@ -224,9 +226,13 @@ async def handle_packet(self, packet): BytesIO(packet), self.session_id, self.auth_key, - self.auth_key_id + self.auth_key_id, + self.stored_msg_ids ) + if data is None: + return + messages = ( data.body.messages if isinstance(data.body, MsgContainer) From bc420da0e2ec34506263d0a8abef7019e1770194 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Dec 2021 15:04:44 +0100 Subject: [PATCH 003/539] Maintain a sorted list of stored_msg_ids --- pyrogram/crypto/mtproto.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index 1eec7b7a3e..81cf56f4a8 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.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 bisect from hashlib import sha256 from io import BytesIO from os import urandom @@ -118,6 +119,6 @@ def unpack( if time_diff < -300: return None - stored_msg_ids.append(message.msg_id) + bisect.insort(stored_msg_ids, message.msg_id) return message From 2a1af2b8e9afb54cc8f96bffb95317e52fbafcd3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:02:39 +0100 Subject: [PATCH 004/539] Close and reestablish the TCP connection in case of mismatch --- pyrogram/crypto/mtproto.py | 14 +++++++------- pyrogram/session/session.py | 25 +++++++++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index 81cf56f4a8..a22693fe49 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -20,7 +20,7 @@ from hashlib import sha256 from io import BytesIO from os import urandom -from typing import Optional, List +from typing import List, Tuple from pyrogram.raw.core import Message, Long from . import aes @@ -58,7 +58,7 @@ def unpack( auth_key: bytes, auth_key_id: bytes, stored_msg_ids: List[int] -) -> Optional[Message]: +) -> Tuple[Message, bool]: assert b.read(8) == auth_key_id, b.getvalue() msg_key = b.read(16) @@ -103,22 +103,22 @@ def unpack( if stored_msg_ids: # Ignored message: msg_id is lower than all of the stored values if message.msg_id < stored_msg_ids[0]: - return None + return message, False # Ignored message: msg_id is equal to any of the stored values if message.msg_id in stored_msg_ids: - return None + return message, False time_diff = (message.msg_id - MsgId()) / 2 ** 32 # Ignored message: msg_id belongs over 30 seconds in the future if time_diff > 30: - return None + return message, False # Ignored message: msg_id belongs over 300 seconds in the past if time_diff < -300: - return None + return message, False bisect.insort(stored_msg_ids, message.msg_id) - return message + return message, True diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 39fe605ca3..b3875f3c9e 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -220,17 +220,22 @@ async def restart(self): await self.start() async def handle_packet(self, packet): - data = await self.loop.run_in_executor( - pyrogram.crypto_executor, - mtproto.unpack, - BytesIO(packet), - self.session_id, - self.auth_key, - self.auth_key_id, - self.stored_msg_ids - ) + try: + data, ok = await self.loop.run_in_executor( + pyrogram.crypto_executor, + mtproto.unpack, + BytesIO(packet), + self.session_id, + self.auth_key, + self.auth_key_id, + self.stored_msg_ids + ) + except AssertionError: + self.connection.close() + return - if data is None: + if not ok: + self.connection.close() return messages = ( From c2a29c8c302feff24e84e7974b7618f4437db105 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:53:17 +0100 Subject: [PATCH 005/539] Tune stored_msg_ids max size --- pyrogram/crypto/mtproto.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index a22693fe49..2b4f71af1b 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -26,6 +26,8 @@ from . import aes from ..session.internals import MsgId +STORED_MSG_IDS_MAX_SIZE = 1000 * 2 + def kdf(auth_key: bytes, msg_key: bytes, outgoing: bool) -> tuple: # https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector @@ -97,8 +99,8 @@ def unpack( # https://core.telegram.org/mtproto/security_guidelines#checking-msg-id assert message.msg_id % 2 != 0 - if len(stored_msg_ids) > 200: - stored_msg_ids = stored_msg_ids[50:] + if len(stored_msg_ids) > STORED_MSG_IDS_MAX_SIZE: + del stored_msg_ids[:STORED_MSG_IDS_MAX_SIZE // 2] if stored_msg_ids: # Ignored message: msg_id is lower than all of the stored values From ed9c7e4694f770f2ef90adc87152889c8530fc01 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Dec 2021 19:26:54 +0100 Subject: [PATCH 006/539] Simplify the error handling a bit --- pyrogram/crypto/mtproto.py | 16 ++++++++-------- pyrogram/session/session.py | 6 +----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index 2b4f71af1b..f9b885f66b 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -20,7 +20,7 @@ from hashlib import sha256 from io import BytesIO from os import urandom -from typing import List, Tuple +from typing import List from pyrogram.raw.core import Message, Long from . import aes @@ -60,8 +60,8 @@ def unpack( auth_key: bytes, auth_key_id: bytes, stored_msg_ids: List[int] -) -> Tuple[Message, bool]: - assert b.read(8) == auth_key_id, b.getvalue() +) -> Message: + assert b.read(8) == auth_key_id msg_key = b.read(16) aes_key, aes_iv = kdf(auth_key, msg_key, False) @@ -105,22 +105,22 @@ def unpack( if stored_msg_ids: # Ignored message: msg_id is lower than all of the stored values if message.msg_id < stored_msg_ids[0]: - return message, False + assert False # Ignored message: msg_id is equal to any of the stored values if message.msg_id in stored_msg_ids: - return message, False + assert False time_diff = (message.msg_id - MsgId()) / 2 ** 32 # Ignored message: msg_id belongs over 30 seconds in the future if time_diff > 30: - return message, False + assert False # Ignored message: msg_id belongs over 300 seconds in the past if time_diff < -300: - return message, False + assert False bisect.insort(stored_msg_ids, message.msg_id) - return message, True + return message diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index b3875f3c9e..3504c3adcf 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -221,7 +221,7 @@ async def restart(self): async def handle_packet(self, packet): try: - data, ok = await self.loop.run_in_executor( + data = await self.loop.run_in_executor( pyrogram.crypto_executor, mtproto.unpack, BytesIO(packet), @@ -234,10 +234,6 @@ async def handle_packet(self, packet): self.connection.close() return - if not ok: - self.connection.close() - return - messages = ( data.body.messages if isinstance(data.body, MsgContainer) From a720726479bd1f9b6804b837a7679bc4b9f682b1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:05:01 +0100 Subject: [PATCH 007/539] Remove unneeded assertion --- pyrogram/methods/auth/accept_terms_of_service.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py index b5abab8613..c8cfd36d71 100644 --- a/pyrogram/methods/auth/accept_terms_of_service.py +++ b/pyrogram/methods/auth/accept_terms_of_service.py @@ -36,6 +36,4 @@ async def accept_terms_of_service(self, terms_of_service_id: str) -> bool: ) ) - assert r - - return True + return bool(r) From 8aa358129c3484a2cd35454dc82228e34663be13 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:38:24 +0100 Subject: [PATCH 008/539] Use specialized exceptions for handling security checks --- pyrogram/client.py | 3 ++- pyrogram/crypto/mtproto.py | 21 +++++++++++---------- pyrogram/errors/__init__.py | 24 ++++++++++++++++++++++++ pyrogram/session/auth.py | 25 +++++++++++++------------ pyrogram/session/session.py | 7 +++++-- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index b54794fad2..8867d2f90e 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -35,6 +35,7 @@ from pyrogram import raw from pyrogram import utils from pyrogram.crypto import aes +from pyrogram.errors import CDNFileHashMismatch from pyrogram.errors import ( SessionPasswordNeeded, VolumeLocNotFound, ChannelPrivate, @@ -1009,7 +1010,7 @@ async def get_file( # https://core.telegram.org/cdn#verifying-files for i, h in enumerate(hashes): cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] - assert h.hash == sha256(cdn_chunk).digest(), f"Invalid CDN hash part {i}" + CDNFileHashMismatch.check(h.hash == sha256(cdn_chunk).digest()) f.write(decrypted_chunk) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index f9b885f66b..ccea119c83 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -22,6 +22,7 @@ from os import urandom from typing import List +from pyrogram.errors import SecurityCheckMismatch from pyrogram.raw.core import Message, Long from . import aes from ..session.internals import MsgId @@ -61,7 +62,7 @@ def unpack( auth_key_id: bytes, stored_msg_ids: List[int] ) -> Message: - assert b.read(8) == auth_key_id + SecurityCheckMismatch.check(b.read(8) == auth_key_id) msg_key = b.read(16) aes_key, aes_iv = kdf(auth_key, msg_key, False) @@ -69,7 +70,7 @@ def unpack( data.read(8) # Salt # https://core.telegram.org/mtproto/security_guidelines#checking-session-id - assert data.read(8) == session_id + SecurityCheckMismatch.check(data.read(8) == session_id) try: message = Message.read(data) @@ -87,17 +88,17 @@ def unpack( # https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key # 96 = 88 + 8 (incoming message) - assert msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24] + SecurityCheckMismatch.check(msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24]) # https://core.telegram.org/mtproto/security_guidelines#checking-message-length data.seek(32) # Get to the payload, skip salt (8) + session_id (8) + msg_id (8) + seq_no (4) + length (4) payload = data.read() padding = payload[message.length:] - assert 12 <= len(padding) <= 1024 - assert len(payload) % 4 == 0 + SecurityCheckMismatch.check(12 <= len(padding) <= 1024) + SecurityCheckMismatch.check(len(payload) % 4 == 0) # https://core.telegram.org/mtproto/security_guidelines#checking-msg-id - assert message.msg_id % 2 != 0 + SecurityCheckMismatch.check(message.msg_id % 2 != 0) if len(stored_msg_ids) > STORED_MSG_IDS_MAX_SIZE: del stored_msg_ids[:STORED_MSG_IDS_MAX_SIZE // 2] @@ -105,21 +106,21 @@ def unpack( if stored_msg_ids: # Ignored message: msg_id is lower than all of the stored values if message.msg_id < stored_msg_ids[0]: - assert False + SecurityCheckMismatch.check(False) # Ignored message: msg_id is equal to any of the stored values if message.msg_id in stored_msg_ids: - assert False + SecurityCheckMismatch.check(False) time_diff = (message.msg_id - MsgId()) / 2 ** 32 # Ignored message: msg_id belongs over 30 seconds in the future if time_diff > 30: - assert False + SecurityCheckMismatch.check(False) # Ignored message: msg_id belongs over 300 seconds in the past if time_diff < -300: - assert False + SecurityCheckMismatch.check(False) bisect.insort(stored_msg_ids, message.msg_id) diff --git a/pyrogram/errors/__init__.py b/pyrogram/errors/__init__.py index 1b94700faa..5011b08020 100644 --- a/pyrogram/errors/__init__.py +++ b/pyrogram/errors/__init__.py @@ -18,3 +18,27 @@ from .exceptions import * from .rpc_error import UnknownError + + +class SecurityError(Exception): + """Generic security error.""" + + @classmethod + def check(cls, cond: bool): + """Raises this exception if the condition is false""" + if not cond: + raise cls + + +class SecurityCheckMismatch(SecurityError): + """Raised when a security check mismatch occurs.""" + + def __init__(self): + super().__init__("A security check mismatch has occurred.") + + +class CDNFileHashMismatch(SecurityError): + """Raised when a CDN file hash mismatch occurs.""" + + def __init__(self): + super().__init__("A CDN file hash mismatch has occurred.") diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index a3e87ff41c..6b1ad9530d 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -27,6 +27,7 @@ from pyrogram import raw from pyrogram.connection import Connection from pyrogram.crypto import aes, rsa, prime +from pyrogram.errors import SecurityCheckMismatch from pyrogram.raw.core import TLObject, Long, Int from .internals import MsgId @@ -210,33 +211,33 @@ async def create(self): # Security checks ####################### - assert dh_prime == prime.CURRENT_DH_PRIME + SecurityCheckMismatch.check(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 g_b = int.from_bytes(g_b, "big") - assert 1 < g < dh_prime - 1 - assert 1 < g_a < dh_prime - 1 - assert 1 < g_b < dh_prime - 1 - assert 2 ** (2048 - 64) < g_a < dh_prime - 2 ** (2048 - 64) - assert 2 ** (2048 - 64) < g_b < dh_prime - 2 ** (2048 - 64) + SecurityCheckMismatch.check(1 < g < dh_prime - 1) + SecurityCheckMismatch.check(1 < g_a < dh_prime - 1) + SecurityCheckMismatch.check(1 < g_b < dh_prime - 1) + SecurityCheckMismatch.check(2 ** (2048 - 64) < g_a < dh_prime - 2 ** (2048 - 64)) + SecurityCheckMismatch.check(2 ** (2048 - 64) < g_b < dh_prime - 2 ** (2048 - 64)) log.debug("g_a and g_b validation: OK") # https://core.telegram.org/mtproto/security_guidelines#checking-sha1-hash-values answer = server_dh_inner_data.write() # Call .write() to remove padding - assert answer_with_hash[:20] == sha1(answer).digest() + SecurityCheckMismatch.check(answer_with_hash[:20] == sha1(answer).digest()) log.debug("SHA1 hash values check: OK") # https://core.telegram.org/mtproto/security_guidelines#checking-nonce-server-nonce-and-new-nonce-fields # 1st message - assert nonce == res_pq.nonce + SecurityCheckMismatch.check(nonce == res_pq.nonce) # 2nd message server_nonce = int.from_bytes(server_nonce, "little", signed=True) - assert nonce == server_dh_params.nonce - assert server_nonce == server_dh_params.server_nonce + SecurityCheckMismatch.check(nonce == server_dh_params.nonce) + SecurityCheckMismatch.check(server_nonce == server_dh_params.server_nonce) # 3rd message - assert nonce == set_client_dh_params_answer.nonce - assert server_nonce == set_client_dh_params_answer.server_nonce + SecurityCheckMismatch.check(nonce == set_client_dh_params_answer.nonce) + SecurityCheckMismatch.check(server_nonce == set_client_dh_params_answer.server_nonce) server_nonce = server_nonce.to_bytes(16, "little", signed=True) log.debug("Nonce fields check: OK") diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 3504c3adcf..72f2762172 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -29,7 +29,10 @@ from pyrogram import raw from pyrogram.connection import Connection from pyrogram.crypto import mtproto -from pyrogram.errors import RPCError, InternalServerError, AuthKeyDuplicated, FloodWait, ServiceUnavailable +from pyrogram.errors import ( + RPCError, InternalServerError, AuthKeyDuplicated, FloodWait, + ServiceUnavailable, SecurityCheckMismatch +) from pyrogram.raw.all import layer from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalt, FutureSalts from .internals import MsgId, MsgFactory @@ -230,7 +233,7 @@ async def handle_packet(self, packet): self.auth_key_id, self.stored_msg_ids ) - except AssertionError: + except SecurityCheckMismatch: self.connection.close() return From ea3281b5f62caa916ea6f1ebb2f406bb66a2b36f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:39:52 +0100 Subject: [PATCH 009/539] Raise directly when not checking a boolean expression --- pyrogram/crypto/mtproto.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index ccea119c83..2fc3b9f848 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -106,21 +106,21 @@ def unpack( if stored_msg_ids: # Ignored message: msg_id is lower than all of the stored values if message.msg_id < stored_msg_ids[0]: - SecurityCheckMismatch.check(False) + raise SecurityCheckMismatch # Ignored message: msg_id is equal to any of the stored values if message.msg_id in stored_msg_ids: - SecurityCheckMismatch.check(False) + raise SecurityCheckMismatch time_diff = (message.msg_id - MsgId()) / 2 ** 32 # Ignored message: msg_id belongs over 30 seconds in the future if time_diff > 30: - SecurityCheckMismatch.check(False) + raise SecurityCheckMismatch # Ignored message: msg_id belongs over 300 seconds in the past if time_diff < -300: - SecurityCheckMismatch.check(False) + raise SecurityCheckMismatch bisect.insort(stored_msg_ids, message.msg_id) From 6fb427fb9a61bfcd31494f65c948bcb3b9d1d676 Mon Sep 17 00:00:00 2001 From: Adek Date: Fri, 17 Dec 2021 16:41:39 +0700 Subject: [PATCH 010/539] Add new chat actions (#751) * Add new chat action * Update send_chat_action.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/methods/messages/send_chat_action.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py index 586d1ea746..f618670d7e 100644 --- a/pyrogram/methods/messages/send_chat_action.py +++ b/pyrogram/methods/messages/send_chat_action.py @@ -37,6 +37,8 @@ class ChatAction: PLAYING = raw.types.SendMessageGamePlayAction CHOOSE_CONTACT = raw.types.SendMessageChooseContactAction SPEAKING = raw.types.SpeakingInGroupCallAction + IMPORT_HISTORY = raw.types.SendMessageHistoryImportAction + CHOOSE_STICKER = raw.types.SendMessageChooseStickerAction CANCEL = raw.types.SendMessageCancelAction @@ -59,6 +61,7 @@ async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool: *"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files, *"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes, *"choose_contact"* for contacts, *"playing"* for games, *"speaking"* for speaking in group calls or + *"import_history"* for importing history, *"choose_sticker"* for stickers or *"cancel"* to cancel any chat action currently displayed. Returns: @@ -89,7 +92,7 @@ async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool: raise ValueError("Invalid chat action '{}'. Possible values are: {}".format( action, json.dumps(POSSIBLE_VALUES, indent=4))) from None - if "Upload" in action.__name__: + if "Upload" in action.__name__ or "History" in action.__name__: action = action(progress=0) else: action = action() From 9b28a120e2a70711446b9c0489a596b9f3be66b8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Dec 2021 11:49:53 +0100 Subject: [PATCH 011/539] Fix megagroup attribute on ChatForbidden objects --- pyrogram/types/user_and_chats/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index cf607c66df..4042c0739a 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -221,7 +221,7 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat": return Chat( id=peer_id, - type="supergroup" if channel.megagroup else "channel", + type="supergroup" if getattr(channel, "megagroup", None) else "channel", is_verified=getattr(channel, "verified", None), is_restricted=getattr(channel, "restricted", None), is_creator=getattr(channel, "creator", None), From ef6125b57ad22aa2aff83365216b6e90970f54df Mon Sep 17 00:00:00 2001 From: AduchiMergen Date: Tue, 21 Dec 2021 02:22:56 +0700 Subject: [PATCH 012/539] Fix -503 Timeout errors #664 (#812) --- pyrogram/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index b54794fad2..61722ac3bc 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -916,9 +916,6 @@ async def get_file( while True: chunk = r.bytes - if not chunk: - break - f.write(chunk) offset += limit @@ -938,6 +935,9 @@ async def get_file( else: await self.loop.run_in_executor(self.executor, func) + if len(chunk) < limit: + break + r = await session.send( raw.functions.upload.GetFile( location=location, From fe764e0e2b26e1222f8ba7d45d756c41378d75f3 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Dec 2021 03:34:57 +0800 Subject: [PATCH 013/539] Update session string format (#818) --- pyrogram/storage/memory_storage.py | 3 ++- pyrogram/storage/storage.py | 9 +++++++-- pyrogram/utils.py | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyrogram/storage/memory_storage.py b/pyrogram/storage/memory_storage.py index 4934354051..5f097a1c50 100644 --- a/pyrogram/storage/memory_storage.py +++ b/pyrogram/storage/memory_storage.py @@ -36,7 +36,8 @@ async def open(self): if self.name != ":memory:": dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack( - self.SESSION_STRING_FORMAT, + (self.SESSION_STRING_FORMAT if len(self.name) == MemoryStorage.SESSION_STRING_SIZE else + self.SESSION_STRING_FORMAT_64), base64.urlsafe_b64decode( self.name + "=" * (-len(self.name) % 4) ) diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py index c506c8ca04..3690cafd73 100644 --- a/pyrogram/storage/storage.py +++ b/pyrogram/storage/storage.py @@ -20,10 +20,14 @@ import struct from typing import List, Tuple +from pyrogram import utils + class Storage: SESSION_STRING_FORMAT = ">B?256sI?" + SESSION_STRING_FORMAT_64 = ">B?256sQ?" SESSION_STRING_SIZE = 351 + SESSION_STRING_SIZE_64 = 356 def __init__(self, name: str): self.name = name @@ -71,13 +75,14 @@ async def is_bot(self, value: bool = object): raise NotImplementedError async def export_session_string(self): + user_id = await self.user_id() return base64.urlsafe_b64encode( struct.pack( - self.SESSION_STRING_FORMAT, + self.SESSION_STRING_FORMAT if user_id < utils.MAX_USER_ID_OLD else self.SESSION_STRING_FORMAT_64, await self.dc_id(), await self.test_mode(), await self.auth_key(), - await self.user_id(), + user_id, await self.is_bot() ) ).decode().rstrip("=") diff --git a/pyrogram/utils.py b/pyrogram/utils.py index e5b15aad63..9d53d8bfba 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -159,6 +159,7 @@ def unpack_inline_message_id(inline_message_id: str) -> "raw.types.InputBotInlin MIN_CHANNEL_ID = -1002147483647 MAX_CHANNEL_ID = -1000000000000 MIN_CHAT_ID = -2147483647 +MAX_USER_ID_OLD = 2147483647 MAX_USER_ID = 999999999999 From 4bb57a4da347f2c07e3a932521bca5b39f3d8acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Mon, 20 Dec 2021 19:37:08 +0000 Subject: [PATCH 014/539] Include tests in sdist (#819) --- MANIFEST.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 4a750253e2..b1f5bc04f3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,10 +1,11 @@ ## Include include README.md COPYING COPYING.lesser NOTICE requirements.txt recursive-include compiler *.py *.tl *.tsv *.txt +recursive-include tests *.py ## Exclude prune pyrogram/errors/exceptions prune pyrogram/raw/functions prune pyrogram/raw/types prune pyrogram/raw/base -exclude pyrogram/raw/all.py \ No newline at end of file +exclude pyrogram/raw/all.py From 419ecb1af5427a1a0bae8f1b782daf0dfbc40228 Mon Sep 17 00:00:00 2001 From: David Hu <81270448+D4v1dH03@users.noreply.github.com> Date: Mon, 20 Dec 2021 11:40:32 -0800 Subject: [PATCH 015/539] Add RPC Error: CHAT_FORWARDS_RESTRICTED (#825) * Add RPC Error: CHAT_FORWARD_RESTRICTED * Fix the typo in the previous commit Sorry, made a typo in the error name * Update 400_BAD_REQUEST.tsv Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/errors/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index ab23069722..e1d29f3803 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -52,6 +52,7 @@ CHANNEL_TOO_LARGE The channel is too large to be deleted; this error is issued w CHAT_ABOUT_NOT_MODIFIED The chat about text was not modified because you tried to edit it using the same content CHAT_ABOUT_TOO_LONG The chat about text is too long CHAT_ADMIN_REQUIRED The method requires chat admin privileges +CHAT_FORWARDS_RESTRICTED The chat restricts forwarding content CHAT_ID_EMPTY The provided chat id is empty CHAT_ID_INVALID The chat id being used is invalid or not known yet. Make sure you see the chat before interacting with it CHAT_INVALID The chat is invalid @@ -346,4 +347,4 @@ WEBDOCUMENT_URL_EMPTY The web document URL is empty WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media -YOU_BLOCKED_USER You blocked this user \ No newline at end of file +YOU_BLOCKED_USER You blocked this user From 56e7e110372aa3bdd8de37a90d79cfe34deba7e4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:01:05 +0100 Subject: [PATCH 016/539] Use a specialized exception for handling BadMsgNotification --- pyrogram/errors/__init__.py | 21 +++++++++++++++++++++ pyrogram/session/session.py | 30 ++++++------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/pyrogram/errors/__init__.py b/pyrogram/errors/__init__.py index 1b94700faa..514e7a1280 100644 --- a/pyrogram/errors/__init__.py +++ b/pyrogram/errors/__init__.py @@ -18,3 +18,24 @@ from .exceptions import * from .rpc_error import UnknownError + + +class BadMsgNotification(Exception): + descriptions = { + 16: "The msg_id is too low, the client time has to be synchronized.", + 17: "The msg_id is too high, the client time has to be synchronized.", + 18: "Incorrect two lower order of the msg_id bits, the server expects the client message " + "msg_id to be divisible by 4.", + 19: "The container msg_id is the same as the msg_id of a previously received message.", + 20: "The message is too old, it cannot be verified by the server.", + 32: "The msg_seqno is too low.", + 33: "The msg_seqno is too high.", + 34: "An even msg_seqno was expected, but an odd one was received.", + 35: "An odd msg_seqno was expected, but an even one was received.", + 48: "Incorrect server salt.", + 64: "Invalid container." + } + + def __init__(self, code): + description = self.descriptions.get(code, "Unknown error code") + super().__init__(f"[{code}] {description}") diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 721586a01c..06df212594 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -29,7 +29,9 @@ from pyrogram import raw from pyrogram.connection import Connection from pyrogram.crypto import mtproto -from pyrogram.errors import RPCError, InternalServerError, AuthKeyDuplicated, FloodWait, ServiceUnavailable +from pyrogram.errors import ( + RPCError, InternalServerError, AuthKeyDuplicated, FloodWait, ServiceUnavailable, BadMsgNotification +) from pyrogram.raw.all import layer from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalt, FutureSalts from .internals import MsgId, MsgFactory @@ -44,7 +46,6 @@ def __init__(self): class Session: - INITIAL_SALT = 0x616e67656c696361 START_TIMEOUT = 1 WAIT_TIMEOUT = 15 SLEEP_THRESHOLD = 10 @@ -54,20 +55,6 @@ class Session: notice_displayed = False - BAD_MSG_DESCRIPTION = { - 16: "[16] msg_id too low, the client time has to be synchronized", - 17: "[17] msg_id too high, the client time has to be synchronized", - 18: "[18] incorrect two lower order msg_id bits, the server expects client message msg_id to be divisible by 4", - 19: "[19] container msg_id is the same as msg_id of a previously received message", - 20: "[20] message too old, it cannot be verified by the server", - 32: "[32] msg_seqno too low", - 33: "[33] msg_seqno too high", - 34: "[34] an even msg_seqno expected, but odd received", - 35: "[35] odd msg_seqno expected, but even received", - 48: "[48] incorrect server salt", - 64: "[64] invalid container" - } - def __init__( self, client: "pyrogram.Client", @@ -129,7 +116,7 @@ async def start(self): self.network_task = self.loop.create_task(self.network_worker()) - self.current_salt = FutureSalt(0, 0, Session.INITIAL_SALT) + self.current_salt = FutureSalt(0, 0, 0) self.current_salt = FutureSalt( 0, 0, (await self._send( @@ -243,9 +230,7 @@ async def handle_packet(self, packet): MsgId.set_server_time(msg.msg_id / (2 ** 32)) if msg.seq_no % 2 != 0: - if msg.msg_id in self.pending_acks: - continue - else: + if msg.msg_id not in self.pending_acks: self.pending_acks.add(msg.msg_id) if isinstance(msg.body, (raw.types.MsgDetailedInfo, raw.types.MsgNewDetailedInfo)): @@ -395,10 +380,7 @@ async def _send(self, data: TLObject, wait_response: bool = True, timeout: float RPCError.raise_it(result, type(data)) elif isinstance(result, raw.types.BadMsgNotification): - raise Exception(self.BAD_MSG_DESCRIPTION.get( - result.error_code, - f"Error code {result.error_code}" - )) + raise BadMsgNotification(result.error_code) else: return result From 29b4615848591eaf4c982a0be722879671ad026f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:08:24 +0100 Subject: [PATCH 017/539] Update create/edit_chat_invite_link --- .../methods/invite_links/create_chat_invite_link.py | 11 +++++++++++ .../methods/invite_links/edit_chat_invite_link.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py index 006e7e1445..b90b9b1524 100644 --- a/pyrogram/methods/invite_links/create_chat_invite_link.py +++ b/pyrogram/methods/invite_links/create_chat_invite_link.py @@ -27,8 +27,10 @@ class CreateChatInviteLink(Scaffold): async def create_chat_invite_link( self, chat_id: Union[int, str], + name: str = None, expire_date: int = None, member_limit: int = None, + creates_join_request: bool = None ) -> "types.ChatInviteLink": """Create an additional invite link for a chat. @@ -41,6 +43,9 @@ async def create_chat_invite_link( Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). + name (``str``, *optional*): + Invite link name. + expire_date (``int``, *optional*): Point in time (Unix timestamp) when the link will expire. Defaults to None (no expiration date). @@ -50,6 +55,10 @@ async def create_chat_invite_link( this invite link; 1-99999. Defaults to None (no member limit). + creates_join_request (``bool``, *optional*): + True, if users joining the chat via the link need to be approved by chat administrators. + If True, member_limit can't be specified. + Returns: :obj:`~pyrogram.types.ChatInviteLink`: On success, the new invite link is returned. @@ -67,6 +76,8 @@ async def create_chat_invite_link( peer=await self.resolve_peer(chat_id), expire_date=expire_date, usage_limit=member_limit, + title=name, + request_needed=creates_join_request ) ) diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py index 07c84d3c4d..ea4be32f55 100644 --- a/pyrogram/methods/invite_links/edit_chat_invite_link.py +++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py @@ -28,8 +28,10 @@ async def edit_chat_invite_link( self, chat_id: Union[int, str], invite_link: str, + name: str = None, expire_date: int = None, member_limit: int = None, + creates_join_request: bool = None ) -> "types.ChatInviteLink": """Edit a non-primary invite link. @@ -43,6 +45,9 @@ async def edit_chat_invite_link( invite_link (``str``): The invite link to edit + name (``str``, *optional*): + Invite link name. + expire_date (``int``, *optional*): Point in time (Unix timestamp) when the link will expire. Defaults to None (no change), pass 0 to set no expiration date. @@ -52,6 +57,10 @@ async def edit_chat_invite_link( invite link; 1-99999. Defaults to None (no change), pass 0 to set no member limit. + creates_join_request (``bool``, *optional*): + True, if users joining the chat via the link need to be approved by chat administrators. + If True, member_limit can't be specified. + Returns: :obj:`~pyrogram.types.ChatInviteLink`: On success, the new invite link is returned @@ -70,6 +79,8 @@ async def edit_chat_invite_link( link=invite_link, expire_date=expire_date, usage_limit=member_limit, + title=name, + request_needed=creates_join_request ) ) From 7d917f43e5c0ba0cd0aa442d5143c0e163d1660f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:12:57 +0100 Subject: [PATCH 018/539] Add approve/decline_chat_join_request --- compiler/docs/compiler.py | 2 + pyrogram/methods/invite_links/__init__.py | 12 ++-- .../invite_links/approve_chat_join_request.py | 55 +++++++++++++++++++ .../invite_links/decline_chat_join_request.py | 55 +++++++++++++++++++ 4 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 pyrogram/methods/invite_links/approve_chat_join_request.py create mode 100644 pyrogram/methods/invite_links/decline_chat_join_request.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index be726c44eb..84fc4f2051 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -253,6 +253,8 @@ def get_title_list(s: str) -> list: get_chat_admin_invite_links_count get_chat_admins_with_invite_links delete_chat_admin_invite_links + approve_chat_join_request + decline_chat_join_request """, contacts=""" Contacts diff --git a/pyrogram/methods/invite_links/__init__.py b/pyrogram/methods/invite_links/__init__.py index 198ce1bd8f..ccdad31297 100644 --- a/pyrogram/methods/invite_links/__init__.py +++ b/pyrogram/methods/invite_links/__init__.py @@ -17,17 +17,19 @@ # along with Pyrogram. If not, see . +from .approve_chat_join_request import ApproveChatJoinRequest from .create_chat_invite_link import CreateChatInviteLink +from .decline_chat_join_request import DeclineChatJoinRequest from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks from .delete_chat_invite_link import DeleteChatInviteLink from .edit_chat_invite_link import EditChatInviteLink from .export_chat_invite_link import ExportChatInviteLink +from .get_chat_admin_invite_links import GetChatAdminInviteLinks +from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks from .get_chat_invite_link import GetChatInviteLink from .get_chat_invite_link_members import GetChatInviteLinkMembers from .get_chat_invite_link_members_count import GetChatInviteLinkMembersCount -from .get_chat_admin_invite_links import GetChatAdminInviteLinks -from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount from .revoke_chat_invite_link import RevokeChatInviteLink @@ -43,6 +45,8 @@ class InviteLinks( DeleteChatAdminInviteLinks, GetChatAdminInviteLinksCount, GetChatAdminsWithInviteLinks, - GetChatInviteLink + GetChatInviteLink, + ApproveChatJoinRequest, + DeclineChatJoinRequest ): - pass \ No newline at end of file + pass diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py new file mode 100644 index 0000000000..013b64feaf --- /dev/null +++ b/pyrogram/methods/invite_links/approve_chat_join_request.py @@ -0,0 +1,55 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class ApproveChatJoinRequest(Scaffold): + async def approve_chat_join_request( + self, + chat_id: Union[int, str], + user_id: int, + ) -> bool: + """Approve a chat join request. + + The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator + right. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). + + user_id (``int``): + Unique identifier of the target user. + + Returns: + ``bool``: True on success. + """ + await self.send( + raw.functions.messages.HideChatJoinRequest( + peer=await self.resolve_peer(chat_id), + user_id=await self.resolve_peer(user_id), + approved=True + ) + ) + + return True diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py new file mode 100644 index 0000000000..5a0f942c1c --- /dev/null +++ b/pyrogram/methods/invite_links/decline_chat_join_request.py @@ -0,0 +1,55 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class DeclineChatJoinRequest(Scaffold): + async def decline_chat_join_request( + self, + chat_id: Union[int, str], + user_id: int, + ) -> bool: + """Decline a chat join request. + + The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator + right. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). + + user_id (``int``): + Unique identifier of the target user. + + Returns: + ``bool``: True on success. + """ + await self.send( + raw.functions.messages.HideChatJoinRequest( + peer=await self.resolve_peer(chat_id), + user_id=await self.resolve_peer(user_id), + approved=False + ) + ) + + return True From 8f8c85e8f3be80252b6a012230f7e5de87041828 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:13:44 +0100 Subject: [PATCH 019/539] Update ChatInviteLink --- .../types/user_and_chats/chat_invite_link.py | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat_invite_link.py b/pyrogram/types/user_and_chats/chat_invite_link.py index f4803b6a73..1f8a9256fc 100644 --- a/pyrogram/types/user_and_chats/chat_invite_link.py +++ b/pyrogram/types/user_and_chats/chat_invite_link.py @@ -44,6 +44,12 @@ class ChatInviteLink(Object): creator (:obj:`~pyrogram.types.User`, *optional*): Creator of the link. + name (``str``, *optional*): + Invite link name + + creates_join_request (``bool``, *optional*): + True, if users joining the chat via the link need to be approved by chat administrators. + expire_date (``int``, *optional*): Point in time (Unix timestamp) when the link will expire or has been expired. @@ -53,36 +59,45 @@ class ChatInviteLink(Object): member_count (``int``, *optional*): Number of users that joined via this link and are currently member of the chat. + + pending_join_request_count (``int``, *optional*): + Number of pending join requests created using this link """ def __init__( self, *, invite_link: str, - creator: "types.User", date: int, is_primary: bool = None, is_revoked: bool = None, + creator: "types.User" = None, + name: str = None, + creates_join_request: bool = None, start_date: int = None, expire_date: int = None, member_limit: int = None, - member_count: int = None + member_count: int = None, + pending_join_request_count: int = None ): super().__init__() self.invite_link = invite_link - self.creator = creator self.date = date self.is_primary = is_primary self.is_revoked = is_revoked + self.creator = creator + self.name = name + self.creates_join_request = creates_join_request self.start_date = start_date self.expire_date = expire_date self.member_limit = member_limit self.member_count = member_count + self.pending_join_request_count = pending_join_request_count @staticmethod def _parse( client: "pyrogram.Client", - invite: "raw.types.ChatInviteExported", + invite: "raw.base.ExportedChatInvite", users: Dict[int, "raw.types.User"] = None ) -> "ChatInviteLink": creator = ( @@ -93,11 +108,14 @@ def _parse( return ChatInviteLink( invite_link=invite.link, - creator=creator, date=invite.date, is_primary=invite.permanent, is_revoked=invite.revoked, + creator=creator, + name=invite.title, + creates_join_request=invite.request_needed, expire_date=invite.expire_date, member_limit=invite.usage_limit, - member_count=invite.usage + member_count=invite.usage, + pending_join_request_count=invite.requested ) From d103ae48feb21a1668103110aa88a106af013702 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:34:12 +0100 Subject: [PATCH 020/539] Add support for ChatJoinRequest events --- pyrogram/dispatcher.py | 11 ++- pyrogram/handlers/__init__.py | 1 + .../handlers/chat_join_request_handler.py | 47 +++++++++++ pyrogram/methods/decorators/__init__.py | 4 +- .../decorators/on_chat_join_request.py | 61 ++++++++++++++ pyrogram/types/user_and_chats/__init__.py | 4 +- .../types/user_and_chats/chat_join_request.py | 82 +++++++++++++++++++ 7 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 pyrogram/handlers/chat_join_request_handler.py create mode 100644 pyrogram/methods/decorators/on_chat_join_request.py create mode 100644 pyrogram/types/user_and_chats/chat_join_request.py diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index 0f46d64236..ccd8b9da82 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -26,7 +26,7 @@ from pyrogram.handlers import ( CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, UserStatusHandler, RawUpdateHandler, InlineQueryHandler, PollHandler, - ChosenInlineResultHandler, ChatMemberUpdatedHandler + ChosenInlineResultHandler, ChatMemberUpdatedHandler, ChatJoinRequestHandler ) from pyrogram.raw.types import ( UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage, @@ -34,7 +34,8 @@ UpdateDeleteMessages, UpdateDeleteChannelMessages, UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, UpdateUserStatus, UpdateBotInlineQuery, UpdateMessagePoll, - UpdateBotInlineSend, UpdateChatParticipant, UpdateChannelParticipant + UpdateBotInlineSend, UpdateChatParticipant, UpdateChannelParticipant, + UpdateBotChatInviteRequester ) log = logging.getLogger(__name__) @@ -106,6 +107,9 @@ async def chosen_inline_result_parser(update, users, chats): async def chat_member_updated_parser(update, users, chats): return pyrogram.types.ChatMemberUpdated._parse(self.client, update, users, chats), ChatMemberUpdatedHandler + async def chat_join_request_parser(update, users, chats): + return pyrogram.types.ChatJoinRequest._parse(self.client, update, users, chats), ChatJoinRequestHandler + self.update_parsers = { Dispatcher.MESSAGE_UPDATES: message_parser, Dispatcher.DELETE_MESSAGES_UPDATES: deleted_messages_parser, @@ -114,7 +118,8 @@ async def chat_member_updated_parser(update, users, chats): (UpdateBotInlineQuery,): inline_query_parser, (UpdateMessagePoll,): poll_parser, (UpdateBotInlineSend,): chosen_inline_result_parser, - Dispatcher.CHAT_MEMBER_UPDATES: chat_member_updated_parser + Dispatcher.CHAT_MEMBER_UPDATES: chat_member_updated_parser, + (UpdateBotChatInviteRequester,): chat_join_request_parser } self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple} diff --git a/pyrogram/handlers/__init__.py b/pyrogram/handlers/__init__.py index 71ecab72b0..1312c6e59d 100644 --- a/pyrogram/handlers/__init__.py +++ b/pyrogram/handlers/__init__.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from .callback_query_handler import CallbackQueryHandler +from .chat_join_request_handler import ChatJoinRequestHandler from .chat_member_updated_handler import ChatMemberUpdatedHandler from .chosen_inline_result_handler import ChosenInlineResultHandler from .deleted_messages_handler import DeletedMessagesHandler diff --git a/pyrogram/handlers/chat_join_request_handler.py b/pyrogram/handlers/chat_join_request_handler.py new file mode 100644 index 0000000000..f26abefc95 --- /dev/null +++ b/pyrogram/handlers/chat_join_request_handler.py @@ -0,0 +1,47 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 .handler import Handler + + +class ChatJoinRequestHandler(Handler): + """The ChatJoinRequest handler class. Used to handle join chat requests. + It is intended to be used with :meth:`~pyrogram.Client.add_handler`. + + For a nicer way to register this handler, have a look at the + :meth:`~pyrogram.Client.on_chat_join_request` decorator. + + Parameters: + callback (``callable``): + Pass a function that will be called when a new ChatJoinRequest event arrives. It takes + *(client, chat_join_request)* as positional arguments (look at the section below for a detailed + description). + + filters (:obj:`Filters`): + Pass one or more filters to allow only a subset of updates to be passed in your callback function. + + Other parameters: + client (:obj:`~pyrogram.Client`): + The Client itself, useful when you want to call other API methods inside the handler. + + chat_join_request (:obj:`~pyrogram.types.ChatJoinRequest`): + The received chat join request. + """ + + def __init__(self, callback: callable, filters=None): + super().__init__(callback, filters) diff --git a/pyrogram/methods/decorators/__init__.py b/pyrogram/methods/decorators/__init__.py index 01ddffcee6..384560fe3e 100644 --- a/pyrogram/methods/decorators/__init__.py +++ b/pyrogram/methods/decorators/__init__.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from .on_callback_query import OnCallbackQuery +from .on_chat_join_request import OnChatJoinRequest from .on_chat_member_updated import OnChatMemberUpdated from .on_chosen_inline_result import OnChosenInlineResult from .on_deleted_messages import OnDeletedMessages @@ -38,6 +39,7 @@ class Decorators( OnInlineQuery, OnPoll, OnChosenInlineResult, - OnChatMemberUpdated + OnChatMemberUpdated, + OnChatJoinRequest ): pass diff --git a/pyrogram/methods/decorators/on_chat_join_request.py b/pyrogram/methods/decorators/on_chat_join_request.py new file mode 100644 index 0000000000..93d48c1059 --- /dev/null +++ b/pyrogram/methods/decorators/on_chat_join_request.py @@ -0,0 +1,61 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Callable + +import pyrogram +from pyrogram.filters import Filter +from pyrogram.scaffold import Scaffold + + +class OnChatJoinRequest(Scaffold): + def on_chat_join_request( + self=None, + filters=None, + group: int = 0 + ) -> callable: + """Decorator for handling chat join requests. + + This does the same thing as :meth:`~pyrogram.Client.add_handler` using the + :obj:`~pyrogram.handlers.ChatJoinRequestHandler`. + + Parameters: + filters (:obj:`~pyrogram.filters`, *optional*): + Pass one or more filters to allow only a subset of updates to be passed in your function. + + group (``int``, *optional*): + The group identifier, defaults to 0. + """ + + def decorator(func: Callable) -> Callable: + if isinstance(self, pyrogram.Client): + self.add_handler(pyrogram.handlers.ChatJoinRequestHandler(func, filters), group) + elif isinstance(self, Filter) or self is None: + if not hasattr(func, "handlers"): + func.handlers = [] + + func.handlers.append( + ( + pyrogram.handlers.ChatJoinRequestHandler(func, self), + group if filters is None else filters + ) + ) + + return func + + return decorator diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 39e5d786ac..22455486b8 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -21,6 +21,7 @@ from .chat_event import ChatEvent from .chat_event_filter import ChatEventFilter from .chat_invite_link import ChatInviteLink +from .chat_join_request import ChatJoinRequest from .chat_member import ChatMember from .chat_member_updated import ChatMemberUpdated from .chat_permissions import ChatPermissions @@ -53,5 +54,6 @@ "VoiceChatEnded", "VoiceChatMembersInvited", "ChatMemberUpdated", - "VoiceChatScheduled" + "VoiceChatScheduled", + "ChatJoinRequest" ] diff --git a/pyrogram/types/user_and_chats/chat_join_request.py b/pyrogram/types/user_and_chats/chat_join_request.py new file mode 100644 index 0000000000..4ed7c1ed38 --- /dev/null +++ b/pyrogram/types/user_and_chats/chat_join_request.py @@ -0,0 +1,82 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Dict + +import pyrogram +from pyrogram import raw, utils +from pyrogram import types +from ..object import Object +from ..update import Update + + +class ChatJoinRequest(Object, Update): + """Represents a join request sent to a chat. + + Parameters: + chat (:obj:`~pyrogram.types.Chat`): + Chat to which the request was sent. + + from_user (:obj:`~pyrogram.types.User`): + User that sent the join request. + + date (``int``): + Date the request was sent in Unix time + + bio (``str``, *optional*): + Bio of the user. + + invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*): + Chat invite link that was used by the user to send the join request. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + chat: "types.Chat", + from_user: "types.User", + date: int, + bio: str = None, + invite_link: "types.ChatInviteLink" = None + ): + super().__init__(client) + + self.chat = chat + self.from_user = from_user + self.date = date + self.bio = bio + self.invite_link = invite_link + + @staticmethod + def _parse( + client: "pyrogram.Client", + update: "raw.types.UpdateBotChatInviteRequester", + users: Dict[int, "raw.types.User"], + chats: Dict[int, "raw.types.Chat"] + ) -> "ChatJoinRequest": + chat_id = utils.get_raw_peer_id(update.peer) + + return ChatJoinRequest( + chat=types.Chat._parse_chat(client, chats[chat_id]), + from_user=types.User._parse(client, users[update.user_id]), + date=update.date, + bio=update.about, + invite_link=types.ChatInviteLink._parse(client, update.invite, users), + client=client + ) From a909dc12e7d2d587533f73e7036718fe4e7e88c6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:36:02 +0100 Subject: [PATCH 021/539] Add support for user profile buttons --- .../inline_keyboard_button.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py index 84d70642bd..b3882d9342 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py @@ -43,6 +43,9 @@ class InlineKeyboardButton(Object): An HTTP URL used to automatically authorize the user. Can be used as a replacement for the `Telegram Login Widget `_. + user_id (``id``, *optional*): + User id, for links to the user profile. + switch_inline_query (``str``, *optional*): If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just @@ -68,6 +71,7 @@ def __init__( callback_data: Union[str, bytes] = None, url: str = None, login_url: "types.LoginUrl" = None, + user_id: int = None, switch_inline_query: str = None, switch_inline_query_current_chat: str = None, callback_game: "types.CallbackGame" = None @@ -75,9 +79,10 @@ def __init__( super().__init__() self.text = str(text) + self.callback_data = callback_data self.url = url self.login_url = login_url - self.callback_data = callback_data + self.user_id = user_id self.switch_inline_query = switch_inline_query self.switch_inline_query_current_chat = switch_inline_query_current_chat self.callback_game = callback_game @@ -110,6 +115,12 @@ def read(b: "raw.base.KeyboardButton"): login_url=types.LoginUrl.read(b) ) + if isinstance(b, raw.types.KeyboardButtonUserProfile): + return InlineKeyboardButton( + text=b.text, + user_id=b.user_id + ) + if isinstance(b, raw.types.KeyboardButtonSwitchInline): if b.same_peer: return InlineKeyboardButton( @@ -150,6 +161,12 @@ async def write(self, client: "pyrogram.Client"): bot=await client.resolve_peer(self.login_url.bot_username) ) + if self.user_id is not None: + return raw.types.InputKeyboardButtonUserProfile( + text=self.text, + user_id=await client.resolve_peer(self.user_id) + ) + if self.switch_inline_query is not None: return raw.types.KeyboardButtonSwitchInline( text=self.text, From 2024b3c120d0e04a4cce3f53b8e81421d1721937 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:39:52 +0100 Subject: [PATCH 022/539] Rename kick(ed) occurrences to ban(ned) --- compiler/docs/compiler.py | 4 ++-- pyrogram/methods/chats/__init__.py | 6 +++--- ...{kick_chat_member.py => ban_chat_member.py} | 12 ++++++------ pyrogram/methods/chats/get_chat_members.py | 8 ++++---- pyrogram/methods/chats/iter_chat_members.py | 8 ++++---- pyrogram/methods/chats/unban_chat_member.py | 2 +- pyrogram/types/user_and_chats/chat.py | 18 +++++++++--------- pyrogram/types/user_and_chats/chat_member.py | 8 ++++---- 8 files changed, 33 insertions(+), 33 deletions(-) rename pyrogram/methods/chats/{kick_chat_member.py => ban_chat_member.py} (92%) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 84fc4f2051..c390391385 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -187,7 +187,7 @@ def get_title_list(s: str) -> list: Chats join_chat leave_chat - kick_chat_member + ban_chat_member unban_chat_member restrict_chat_member promote_chat_member @@ -501,7 +501,7 @@ def get_title_list(s: str) -> list: Chat.set_title Chat.set_description Chat.set_photo - Chat.kick_member + Chat.ban_member Chat.unban_member Chat.restrict_member Chat.promote_member diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 31ffe4fd2f..71125ce0a2 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -18,6 +18,7 @@ from .add_chat_members import AddChatMembers from .archive_chats import ArchiveChats +from .ban_chat_member import BanChatMember from .create_channel import CreateChannel from .create_group import CreateGroup from .create_supergroup import CreateSupergroup @@ -30,13 +31,13 @@ from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers from .get_chat_members_count import GetChatMembersCount +from .get_chat_online_count import GetChatOnlineCount from .get_dialogs import GetDialogs from .get_dialogs_count import GetDialogsCount from .get_nearby_chats import GetNearbyChats from .iter_chat_members import IterChatMembers from .iter_dialogs import IterDialogs from .join_chat import JoinChat -from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat from .mark_chat_unread import MarkChatUnread from .pin_chat_message import PinChatMessage @@ -53,14 +54,13 @@ from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername -from .get_chat_online_count import GetChatOnlineCount class Chats( GetChat, LeaveChat, JoinChat, - KickChatMember, + BanChatMember, UnbanChatMember, RestrictChatMember, PromoteChatMember, diff --git a/pyrogram/methods/chats/kick_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py similarity index 92% rename from pyrogram/methods/chats/kick_chat_member.py rename to pyrogram/methods/chats/ban_chat_member.py index 495eac9402..0d17fec699 100644 --- a/pyrogram/methods/chats/kick_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -23,14 +23,14 @@ from pyrogram.scaffold import Scaffold -class KickChatMember(Scaffold): - async def kick_chat_member( +class BanChatMember(Scaffold): + async def ban_chat_member( self, chat_id: Union[int, str], user_id: Union[int, str], until_date: int = 0 ) -> Union["types.Message", bool]: - """Kick a user from a group, a supergroup or a channel. + """Ban a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. You must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -63,10 +63,10 @@ async def kick_chat_member( from time import time # Ban chat member forever - app.kick_chat_member(chat_id, user_id) + app.ban_chat_member(chat_id, user_id) - # Kick chat member and automatically unban after 24h - app.kick_chat_member(chat_id, user_id, int(time.time() + 86400)) + # Ban chat member and automatically unban after 24h + app.ban_chat_member(chat_id, user_id, int(time.time() + 86400)) """ chat_peer = await self.resolve_peer(chat_id) user_peer = await self.resolve_peer(user_id) diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index 64abf1e5e2..d22cc44670 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -28,7 +28,7 @@ class Filters: ALL = "all" - KICKED = "kicked" + BANNED = "banned" RESTRICTED = "restricted" BOTS = "bots" RECENT = "recent" @@ -72,7 +72,7 @@ async def get_chat_members( Filter used to select the kind of members you want to retrieve. Only applicable for supergroups and channels. It can be any of the followings: *"all"* - all kind of members, - *"kicked"* - kicked (banned) members only, + *"banned"* - banned members only, *"restricted"* - restricted members only, *"bots"* - bots only, *"recent"* - recent members only, @@ -83,7 +83,7 @@ async def get_chat_members( .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members on channels. - .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. + .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only. Returns: List of :obj:`~pyrogram.types.ChatMember`: On success, a list of chat members is returned. @@ -121,7 +121,7 @@ async def get_chat_members( if filter == Filters.ALL: filter = raw.types.ChannelParticipantsSearch(q=query) - elif filter == Filters.KICKED: + elif filter == Filters.BANNED: filter = raw.types.ChannelParticipantsKicked(q=query) elif filter == Filters.RESTRICTED: filter = raw.types.ChannelParticipantsBanned(q=query) diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py index 86ef457c12..3db3935567 100644 --- a/pyrogram/methods/chats/iter_chat_members.py +++ b/pyrogram/methods/chats/iter_chat_members.py @@ -26,7 +26,7 @@ class Filters: ALL = "all" - KICKED = "kicked" + BANNED = "banned" RESTRICTED = "restricted" BOTS = "bots" RECENT = "recent" @@ -34,7 +34,7 @@ class Filters: QUERIES = [""] + [str(i) for i in range(10)] + list(ascii_lowercase) -QUERYABLE_FILTERS = (Filters.ALL, Filters.KICKED, Filters.RESTRICTED) +QUERYABLE_FILTERS = (Filters.ALL, Filters.BANNED, Filters.RESTRICTED) class IterChatMembers(Scaffold): @@ -67,7 +67,7 @@ async def iter_chat_members( Filter used to select the kind of members you want to retrieve. Only applicable for supergroups and channels. It can be any of the followings: *"all"* - all kind of members, - *"kicked"* - kicked (banned) members only, + *"banned"* - banned members only, *"restricted"* - restricted members only, *"bots"* - bots only, *"recent"* - recent members only, @@ -77,7 +77,7 @@ async def iter_chat_members( .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members on channels. - .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. + .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only. Returns: ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects. diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py index 44c19286a6..9f81f9c7ce 100644 --- a/pyrogram/methods/chats/unban_chat_member.py +++ b/pyrogram/methods/chats/unban_chat_member.py @@ -28,7 +28,7 @@ async def unban_chat_member( chat_id: Union[int, str], user_id: Union[int, str] ) -> bool: - """Unban a previously kicked user in a supergroup or channel. + """Unban a previously banned user in a supergroup or channel. The user will **not** return to the group or channel automatically, but will be able to join via link, etc. You must be an administrator for this to work. diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4042c0739a..5ba68aacff 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -479,18 +479,18 @@ async def set_photo(self, photo: str) -> bool: photo=photo ) - async def kick_member( + async def ban_member( self, user_id: Union[int, str], until_date: int = 0 ) -> Union["types.Message", bool]: - """Bound method *kick_member* of :obj:`~pyrogram.types.Chat`. + """Bound method *ban_member* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: .. code-block:: python - client.kick_chat_member( + client.ban_chat_member( chat_id=chat_id, user_id=user_id ) @@ -498,7 +498,7 @@ async def kick_member( Example: .. code-block:: python - chat.kick_member(123456789) + chat.ban_member(123456789) Note: In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" setting is @@ -523,7 +523,7 @@ async def kick_member( RPCError: In case of a Telegram RPC error. """ - return await self._client.kick_chat_member( + return await self._client.ban_chat_member( chat_id=self.id, user_id=user_id, until_date=until_date @@ -840,7 +840,7 @@ async def get_members( Filter used to select the kind of members you want to retrieve. Only applicable for supergroups and channels. It can be any of the followings: *"all"* - all kind of members, - *"kicked"* - kicked (banned) members only, + *"banned"* - banned members only, *"restricted"* - restricted members only, *"bots"* - bots only, *"recent"* - recent members only, @@ -851,7 +851,7 @@ async def get_members( .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members on channels. - .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. + .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only. Example: .. code-block:: python @@ -903,7 +903,7 @@ def iter_members( Filter used to select the kind of members you want to retrieve. Only applicable for supergroups and channels. It can be any of the followings: *"all"* - all kind of members, - *"kicked"* - kicked (banned) members only, + *"banned"* - banned members only, *"restricted"* - restricted members only, *"bots"* - bots only, *"recent"* - recent members only, @@ -914,7 +914,7 @@ def iter_members( .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members on channels. - .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. + .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only. Example: .. code-block:: python diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py index d33bcfc5d0..a6f2f4ccb9 100644 --- a/pyrogram/types/user_and_chats/chat_member.py +++ b/pyrogram/types/user_and_chats/chat_member.py @@ -31,14 +31,14 @@ class ChatMember(Object): status (``str``): The member's status in the chat. - Can be "creator", "administrator", "member", "restricted", "left" or "kicked". + Can be "creator", "administrator", "member", "restricted", "left" or "banned". title (``str``, *optional*): A custom title that will be shown to all members instead of "Owner" or "Admin". Creator (owner) and administrators only. Can be None in case there's no custom title set. until_date (``int``, *optional*): - Restricted and kicked only. + Restricted and banned only. Date when restrictions will be lifted for this user; unix time. joined_date (``int``, *optional*): @@ -53,7 +53,7 @@ class ChatMember(Object): Administrators only. Information about the user who promoted this member as administrator. restricted_by (:obj:`~pyrogram.types.User`, *optional*): - Restricted and kicked only. Information about the user who restricted or kicked this member. + Restricted and banned only. Information about the user who restricted or banned this member. is_member (``bool``, *optional*): Restricted only. True, if the user is a member of the chat at the moment of the request. @@ -305,7 +305,7 @@ def _parse(client, member, users, chats) -> "ChatMember": return ChatMember( user=user, - status="kicked" if member.banned_rights.view_messages else "restricted", + status="banned" if member.banned_rights.view_messages else "restricted", until_date=denied_permissions.until_date, joined_date=member.date, is_member=not member.left, From a138b46668219399c3591d0c38c05d57636cf897 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:49:28 +0100 Subject: [PATCH 023/539] Add Message/Chat.has_protected_content --- pyrogram/types/messages_and_media/message.py | 6 ++++++ pyrogram/types/user_and_chats/chat.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 2fa21c4eb7..9e1c7e1a24 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -128,6 +128,9 @@ class Message(Object, Update): Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. + has_protected_content (``str``, *optional*): + True, if the message can't be forwarded. + text (``str``, *optional*): For text messages, the actual UTF-8 text of the message, 0-4096 characters. If the message contains entities (bold, italic, ...) you can access *text.markdown* or @@ -312,6 +315,7 @@ def __init__( edit_date: int = None, media_group_id: str = None, author_signature: str = None, + has_protected_content: bool = None, text: Str = None, entities: List["types.MessageEntity"] = None, caption_entities: List["types.MessageEntity"] = None, @@ -382,6 +386,7 @@ def __init__( self.edit_date = edit_date self.media_group_id = media_group_id self.author_signature = author_signature + self.has_protected_content = has_protected_content self.text = text self.entities = entities self.caption_entities = caption_entities @@ -743,6 +748,7 @@ async def _parse( else None ), author_signature=message.post_author, + has_protected_content=message.noforwards, forward_from=forward_from, forward_sender_name=forward_sender_name, forward_from_chat=forward_from_chat, diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 5ba68aacff..3324cc9862 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -83,6 +83,9 @@ class Chat(Object): It is accurate only in case the owner has set the chat photo, otherwise the dc_id will be the one assigned to the administrator who set the current chat photo. + has_protected_content (``bool``, *optional*): + True, if messages from the chat can't be forwarded to other chats. + invite_link (``str``, *optional*): Chat invite link, for groups, supergroups and channels. Returned only in :meth:`~pyrogram.Client.get_chat`. @@ -139,6 +142,7 @@ def __init__( bio: str = None, description: str = None, dc_id: int = None, + has_protected_content: bool = None, invite_link: str = None, pinned_message=None, sticker_set_name: str = None, @@ -167,6 +171,7 @@ def __init__( self.bio = bio self.description = description self.dc_id = dc_id + self.has_protected_content = has_protected_content self.invite_link = invite_link self.pinned_message = pinned_message self.sticker_set_name = sticker_set_name @@ -211,6 +216,7 @@ def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat": permissions=types.ChatPermissions._parse(getattr(chat, "default_banned_rights", None)), members_count=getattr(chat, "participants_count", None), dc_id=getattr(getattr(chat, "photo", None), "dc_id", None), + has_protected_content=chat.noforwards, client=client ) @@ -234,6 +240,7 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat": permissions=types.ChatPermissions._parse(getattr(channel, "default_banned_rights", None)), members_count=getattr(channel, "participants_count", None), dc_id=getattr(getattr(channel, "photo", None), "dc_id", None), + has_protected_content=channel.noforwards, client=client ) From e8076d1b8a9b9be3d1e37ea83abefe6f31f7ad05 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 22 Dec 2021 15:00:03 +0100 Subject: [PATCH 024/539] Add method get_discussion_message --- compiler/docs/compiler.py | 1 + pyrogram/methods/messages/__init__.py | 4 +- .../messages/get_discussion_message.py | 62 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/messages/get_discussion_message.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c390391385..6e320bf9b9 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -182,6 +182,7 @@ def get_title_list(s: str) -> list: search_messages search_global download_media + get_discussion_message """, chats=""" Chats diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index 45cccb7e4e..8dee8402c3 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -29,6 +29,7 @@ from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages +from .get_discussion_message import GetDiscussionMessage from .get_history import GetHistory from .get_history_count import GetHistoryCount from .get_media_group import GetMediaGroup @@ -104,6 +105,7 @@ class Messages( CopyMessage, CopyMediaGroup, SearchMessagesCount, - SearchGlobalCount + SearchGlobalCount, + GetDiscussionMessage ): pass diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py new file mode 100644 index 0000000000..cda7ae5212 --- /dev/null +++ b/pyrogram/methods/messages/get_discussion_message.py @@ -0,0 +1,62 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram import raw +from pyrogram import types +from pyrogram.scaffold import Scaffold + + +class GetDiscussionMessage(Scaffold): + async def get_discussion_message( + self, + chat_id: Union[int, str], + message_id: int, + ) -> "types.Message": + """Get the discussion message from the linked discussion group of a channel post. + + Reply to the returned message to leave a comment on the linked channel post. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + message_id (``int``): + Message id. + + Example: + .. code-block:: python + + # Get the discussion message + m = app.get_discussion_message(channel_id, message_id) + + # Comment to the post by replying + m.reply("comment") + """ + r = await self.send( + raw.functions.messages.GetDiscussionMessage( + peer=await self.resolve_peer(chat_id), + msg_id=message_id + ) + ) + + users = {u.id: u for u in r.users} + chats = {c.id: c for c in r.chats} + + return await types.Message._parse(self, r.messages[0], users, chats) From 9a2bc25bc7f318378fa846048e85b983917887cc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 23 Dec 2021 16:53:03 +0100 Subject: [PATCH 025/539] Add support for "send_as" chats - Add methods get_send_as_chats() and set_send_as_chat() - Add field Chat.send_as_chat --- compiler/docs/compiler.py | 2 + pyrogram/methods/chats/__init__.py | 6 +- pyrogram/methods/chats/get_send_as_chats.py | 63 +++++++++++++++++++++ pyrogram/methods/chats/set_send_as_chat.py | 55 ++++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 52 ++++++++++------- 5 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 pyrogram/methods/chats/get_send_as_chats.py create mode 100644 pyrogram/methods/chats/set_send_as_chat.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 6e320bf9b9..c8823ceb03 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -224,6 +224,8 @@ def get_title_list(s: str) -> list: mark_chat_unread get_chat_event_log get_chat_online_count + get_send_as_chats + set_send_as_chat """, users=""" Users diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 71125ce0a2..ce8fe14c5b 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -35,6 +35,7 @@ from .get_dialogs import GetDialogs from .get_dialogs_count import GetDialogsCount from .get_nearby_chats import GetNearbyChats +from .get_send_as_chats import GetSendAsChats from .iter_chat_members import IterChatMembers from .iter_dialogs import IterDialogs from .join_chat import JoinChat @@ -48,6 +49,7 @@ from .set_chat_permissions import SetChatPermissions from .set_chat_photo import SetChatPhoto from .set_chat_title import SetChatTitle +from .set_send_as_chat import SetSendAsChat from .set_slow_mode import SetSlowMode from .unarchive_chats import UnarchiveChats from .unban_chat_member import UnbanChatMember @@ -94,6 +96,8 @@ class Chats( UnpinAllChatMessages, MarkChatUnread, GetChatEventLog, - GetChatOnlineCount + GetChatOnlineCount, + GetSendAsChats, + SetSendAsChat ): pass diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py new file mode 100644 index 0000000000..6eb6c4a684 --- /dev/null +++ b/pyrogram/methods/chats/get_send_as_chats.py @@ -0,0 +1,63 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import List, Union + +from pyrogram import raw +from pyrogram import types +from pyrogram.scaffold import Scaffold + + +class GetSendAsChats(Scaffold): + async def get_send_as_chats( + self, + chat_id: Union[int, str] + ) -> List["types.Chat"]: + """Get the list of "send_as" chats available. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + List[:obj:`~pyrogram.types.Chat`]: The list of chats. + + Example: + .. code-block:: python + + chats = app.get_send_as_chats(chat_id) + print(chats) + """ + r = await self.send( + raw.functions.channels.GetSendAs( + peer=await self.resolve_peer(chat_id) + ) + ) + + users = {u.id: u for u in r.users} + chats = {c.id: c for c in r.chats} + + send_as_chats = types.List() + + for p in r.peers: + if isinstance(p, raw.types.PeerUser): + send_as_chats.append(types.Chat._parse_chat(self, users[p.user_id])) + else: + send_as_chats.append(types.Chat._parse_chat(self, chats[p.channel_id])) + + return send_as_chats diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py new file mode 100644 index 0000000000..ccf13952dc --- /dev/null +++ b/pyrogram/methods/chats/set_send_as_chat.py @@ -0,0 +1,55 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class SetSendAsChat(Scaffold): + async def set_send_as_chat( + self, + chat_id: Union[int, str], + send_as_chat_id: Union[int, str] + ) -> bool: + """Set the default "send_as" chat for a chat. + + Use :meth:`~pyrogram.Client.get_send_as_chats` to get all the "send_as" chats available for use. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + send_as_chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the send_as chat. + + Returns: + ``bool``: On success, true is returned + + Example: + .. code-block:: python + + app.set_send_as_chat(chat_id, send_as_chat_id) + """ + return await self.send( + raw.functions.messages.SaveDefaultSendAs( + peer=await self.resolve_peer(chat_id), + send_as=await self.resolve_peer(send_as_chat_id) + ) + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 3324cc9862..4cee964097 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -120,6 +120,10 @@ class Chat(Object): linked_chat (:obj:`~pyrogram.types.Chat`, *optional*): The linked discussion group (in case of channels) or the linked channel (in case of supergroups). Returned only in :meth:`~pyrogram.Client.get_chat`. + + send_as_chat (:obj:`~pyrogram.types.Chat`, *optional*): + The default "send_as" chat. + Returned only in :meth:`~pyrogram.Client.get_chat`. """ def __init__( @@ -151,7 +155,8 @@ def __init__( restrictions: List["types.Restriction"] = None, permissions: "types.ChatPermissions" = None, distance: int = None, - linked_chat: "types.Chat" = None + linked_chat: "types.Chat" = None, + send_as_chat: "types.Chat" = None ): super().__init__(client) @@ -181,6 +186,7 @@ def __init__( self.permissions = permissions self.distance = distance self.linked_chat = linked_chat + self.send_as_chat = send_as_chat @staticmethod def _parse_user_chat(client, user: raw.types.User) -> "Chat": @@ -275,43 +281,51 @@ def _parse_dialog(client, peer, users: dict, chats: dict): @staticmethod async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.types.users.UserFull]) -> "Chat": + users = {u.id: u for u in chat_full.users} + chats = {c.id: c for c in chat_full.chats} + if isinstance(chat_full, raw.types.users.UserFull): - parsed_chat = Chat._parse_user_chat(client, chat_full.users[0]) - parsed_chat.bio = chat_full.full_user.about + full_user = chat_full.full_user - if chat_full.full_user.pinned_msg_id: + parsed_chat = Chat._parse_user_chat(client, users[full_user.id]) + parsed_chat.bio = full_user.about + + if full_user.pinned_msg_id: parsed_chat.pinned_message = await client.get_messages( parsed_chat.id, - message_ids=chat_full.full_user.pinned_msg_id + message_ids=full_user.pinned_msg_id ) else: full_chat = chat_full.full_chat - chat = None - linked_chat = None - - for c in chat_full.chats: - if full_chat.id == c.id: - chat = c - - if isinstance(full_chat, raw.types.ChannelFull): - if full_chat.linked_chat_id == c.id: - linked_chat = c + chat_raw = chats[full_chat.id] if isinstance(full_chat, raw.types.ChatFull): - parsed_chat = Chat._parse_chat_chat(client, chat) + parsed_chat = Chat._parse_chat_chat(client, chat_raw) parsed_chat.description = full_chat.about or None if isinstance(full_chat.participants, raw.types.ChatParticipants): parsed_chat.members_count = len(full_chat.participants.participants) else: - parsed_chat = Chat._parse_channel_chat(client, chat) + parsed_chat = Chat._parse_channel_chat(client, chat_raw) parsed_chat.members_count = full_chat.participants_count parsed_chat.description = full_chat.about or None # TODO: Add StickerSet type parsed_chat.can_set_sticker_set = full_chat.can_set_stickers parsed_chat.sticker_set_name = getattr(full_chat.stickerset, "short_name", None) - if linked_chat: - parsed_chat.linked_chat = Chat._parse_channel_chat(client, linked_chat) + + linked_chat_raw = chats.get(full_chat.linked_chat_id, None) + + if linked_chat_raw: + parsed_chat.linked_chat = Chat._parse_channel_chat(client, linked_chat_raw) + + default_send_as = full_chat.default_send_as + + if isinstance(default_send_as, raw.types.PeerUser): + send_as_raw = users[default_send_as.user_id] + else: + send_as_raw = chats[default_send_as.channel_id] + + parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw) if full_chat.pinned_msg_id: parsed_chat.pinned_message = await client.get_messages( From cc4a850134e393dace1149a86bfb101b111f3474 Mon Sep 17 00:00:00 2001 From: Udith Amasura Date: Thu, 23 Dec 2021 22:26:22 +0530 Subject: [PATCH 026/539] Make bot_username optional for LoginUrl (#817) * make bot username optional * Update login_url.py * Update login_url.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/types/bots_and_keyboards/inline_keyboard_button.py | 2 +- pyrogram/types/bots_and_keyboards/login_url.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py index 84d70642bd..0e4bb40ba9 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py @@ -147,7 +147,7 @@ async def write(self, client: "pyrogram.Client"): if self.login_url is not None: return self.login_url.write( text=self.text, - bot=await client.resolve_peer(self.login_url.bot_username) + bot=await client.resolve_peer(self.login_url.bot_username or "self") ) if self.switch_inline_query is not None: diff --git a/pyrogram/types/bots_and_keyboards/login_url.py b/pyrogram/types/bots_and_keyboards/login_url.py index 21c7a45dcc..52ef8dc8ee 100644 --- a/pyrogram/types/bots_and_keyboards/login_url.py +++ b/pyrogram/types/bots_and_keyboards/login_url.py @@ -31,7 +31,8 @@ class LoginUrl(Object): url (``str``): An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will - be opened. The data added is the same as described in Receiving authorization data. + be opened. The data added is the same as described in + `Receiving authorization data `. **NOTE**: You **must** always check the hash of the received data to verify the authentication and the integrity of the data as described in @@ -42,7 +43,7 @@ class LoginUrl(Object): bot_username (``str``, *optional*): Username of a bot, which will be used for user authorization. - See `Setting up `_ a bot for more details. + See `Setting up a bot `_ for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See `Linking your domain to the bot `_ From 42c690757dc27a396fca1745f33bc041ff5a45c3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 08:57:02 +0100 Subject: [PATCH 027/539] Update API schema to Layer 136 --- compiler/api/source/main_api.tl | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index bc5b1bf365..3cfee8a5e0 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -106,8 +106,8 @@ chatForbidden#6592a1a7 id:long title:string = Chat; channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat; -chatFull#46a6ffb4 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector = ChatFull; -channelFull#56662e2e flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer = ChatFull; +chatFull#d18ee226 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?Vector = ChatFull; +channelFull#e13c3d20 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?Vector = ChatFull; chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant; chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant; @@ -120,7 +120,7 @@ chatPhotoEmpty#37c1011c = ChatPhoto; chatPhoto#1c6e1c11 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = ChatPhoto; messageEmpty#90a6ca84 flags:# id:int peer_id:flags.0?Peer = Message; -message#85d6cbe2 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true pinned:flags.24?true noforwards:flags.26?true id:int from_id:flags.8?Peer peer_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long reply_to:flags.3?MessageReplyHeader date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector views:flags.10?int forwards:flags.10?int replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long restriction_reason:flags.22?Vector ttl_period:flags.25?int = Message; +message#38116ee0 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true pinned:flags.24?true noforwards:flags.26?true id:int from_id:flags.8?Peer peer_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long reply_to:flags.3?MessageReplyHeader date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector views:flags.10?int forwards:flags.10?int replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long reactions:flags.20?MessageReactions restriction_reason:flags.22?Vector ttl_period:flags.25?int = Message; messageService#2b085862 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?Peer peer_id:Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction ttl_period:flags.25?int = Message; messageMediaEmpty#3ded6320 = MessageMedia; @@ -359,6 +359,7 @@ updateGroupCallConnection#b783982 flags:# presentation:flags.0?true params:DataJ updateBotCommands#4d712f2e peer:Peer bot_id:long commands:Vector = Update; updatePendingJoinRequests#7063c3db peer:Peer requests_pending:int recent_requesters:Vector = Update; updateBotChatInviteRequester#11dfa986 peer:Peer date:int user_id:long about:string invite:ExportedChatInvite qts:int = Update; +updateMessageReactions#154798c3 peer:Peer msg_id:int reactions:MessageReactions = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -592,6 +593,7 @@ messageEntityUnderline#9c4e7e8b offset:int length:int = MessageEntity; messageEntityStrike#bf0693d4 offset:int length:int = MessageEntity; messageEntityBlockquote#20df5d0 offset:int length:int = MessageEntity; messageEntityBankCard#761e6af4 offset:int length:int = MessageEntity; +messageEntitySpoiler#32ca960f offset:int length:int = MessageEntity; inputChannelEmpty#ee8c1e86 = InputChannel; inputChannel#f35aec28 channel_id:long access_hash:long = InputChannel; @@ -897,6 +899,7 @@ channelAdminLogEventActionChangeHistoryTTL#6e941a38 prev_value:int new_value:int channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatInvite approved_by:long = ChannelAdminLogEventAction; channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction; channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction; +channelAdminLogEventActionChangeAvailableReactions#9cf7f76a prev_value:Vector new_value:Vector = ChannelAdminLogEventAction; channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent; @@ -1260,7 +1263,7 @@ account.resetPasswordFailedWait#e3779861 retry_date:int = account.ResetPasswordR account.resetPasswordRequestedWait#e9effc7d until_date:int = account.ResetPasswordResult; account.resetPasswordOk#e926d63e = account.ResetPasswordResult; -sponsoredMessage#d151e19a flags:# random_id:bytes from_id:Peer channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage; +sponsoredMessage#3a836df8 flags:# random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage; messages.sponsoredMessages#65a4c7d5 messages:Vector chats:Vector users:Vector = messages.SponsoredMessages; @@ -1280,6 +1283,19 @@ messages.peerSettings#6880b94d settings:PeerSettings chats:Vector users:Ve auth.loggedOut#c3a2835f flags:# future_auth_token:flags.0?bytes = auth.LoggedOut; +reactionCount#6fb250d1 flags:# chosen:flags.0?true reaction:string count:int = ReactionCount; + +messageReactions#87b6e36 flags:# min:flags.0?true can_see_list:flags.2?true results:Vector recent_reactons:flags.1?Vector = MessageReactions; + +messageUserReaction#932844fa user_id:long reaction:string = MessageUserReaction; + +messages.messageReactionsList#a366923c flags:# count:int reactions:Vector users:Vector next_offset:flags.0?string = messages.MessageReactionsList; + +availableReaction#21d7c4b flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document = AvailableReaction; + +messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions; +messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1418,9 +1434,9 @@ messages.deleteHistory#b08f922a flags:# just_clear:flags.0?true revoke:flags.1?t messages.deleteMessages#e58e95d2 flags:# revoke:flags.0?true id:Vector = messages.AffectedMessages; messages.receivedMessages#5a954c0 max_id:int = Vector; messages.setTyping#58943ee2 flags:# peer:InputPeer top_msg_id:flags.0?int action:SendMessageAction = Bool; -messages.sendMessage#d9d75a4 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; -messages.sendMedia#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; -messages.forwardMessages#cc30290b flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true drop_author:flags.11?true drop_media_captions:flags.12?true from_peer:InputPeer id:Vector random_id:Vector to_peer:InputPeer schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; +messages.sendMessage#d9d75a4 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; +messages.sendMedia#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; +messages.forwardMessages#cc30290b flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true drop_author:flags.11?true drop_media_captions:flags.12?true noforwards:flags.14?true from_peer:InputPeer id:Vector random_id:Vector to_peer:InputPeer schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; messages.reportSpam#cf1592db peer:InputPeer = Bool; messages.getPeerSettings#efd9a6a2 peer:InputPeer = messages.PeerSettings; messages.report#8953ab4e peer:InputPeer id:Vector reason:ReportReason message:string = Bool; @@ -1499,7 +1515,7 @@ messages.faveSticker#b9ffc55b id:InputDocument unfave:Bool = Bool; messages.getUnreadMentions#46578472 peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages; messages.readMentions#f0189d3 peer:InputPeer = messages.AffectedHistory; messages.getRecentLocations#702a40e0 peer:InputPeer limit:int hash:long = messages.Messages; -messages.sendMultiMedia#f803138f 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 schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; +messages.sendMultiMedia#f803138f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; messages.uploadEncryptedFile#5057c497 peer:InputEncryptedChat file:InputEncryptedFile = EncryptedFile; messages.searchStickerSets#35705b8a flags:# exclude_featured:flags.0?true q:string hash:long = messages.FoundStickerSets; messages.getSplitRanges#1cff7e08 = Vector; @@ -1558,6 +1574,12 @@ messages.hideChatJoinRequest#7fe7e815 flags:# approved:flags.0?true peer:InputPe messages.hideAllChatJoinRequests#e085f4ea flags:# approved:flags.0?true peer:InputPeer link:flags.1?string = Updates; messages.toggleNoForwards#b11eafa2 peer:InputPeer enabled:Bool = Updates; messages.saveDefaultSendAs#ccfddf96 peer:InputPeer send_as:InputPeer = Bool; +messages.sendReaction#25690ce4 flags:# peer:InputPeer msg_id:int reaction:flags.0?string = Updates; +messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector = Updates; +messages.getMessageReactionsList#e0ee6b77 flags:# peer:InputPeer id:int reaction:flags.0?string offset:flags.1?string limit:int = messages.MessageReactionsList; +messages.setChatAvailableReactions#14050ea6 peer:InputPeer available_reactions:Vector = Updates; +messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions; +messages.setDefaultReaction#d960c4d4 reaction:string = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1706,4 +1728,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 135 \ No newline at end of file +// LAYER 136 \ No newline at end of file From f7b9137a6852e6f8c20903d2eabf0b08a62fb092 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 09:14:49 +0100 Subject: [PATCH 028/539] Add support for "spoiler" MessageEntity --- docs/source/topics/text-formatting.rst | 7 +++++++ pyrogram/parser/html.py | 4 +++- pyrogram/parser/markdown.py | 8 +++++++- pyrogram/types/messages_and_media/message_entity.py | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index 5d9a9376c2..bada964b16 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -34,6 +34,7 @@ list of the basic styles currently supported by Pyrogram. - *italic* - :strike:`strike` - :underline:`underline` +- spoiler - `text URL `_ - `user text mention `_ - ``inline fixed-width code`` @@ -63,6 +64,8 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us ~~strike~~ + ##spoiler## + [text URL](https://docs.pyrogram.org/) [text user mention](tg://user?id=23122162) @@ -86,6 +89,7 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us "__italic__, " "--underline--, " "~~strike~~, " + "##spoiler##, " "[mention](tg://user?id=23122162), " "[URL](https://pyrogram.org), " "`code`, " @@ -113,6 +117,8 @@ The following tags are currently supported: strike, strike, strike + spoiler + text URL inline mention @@ -136,6 +142,7 @@ The following tags are currently supported: "italic, " "underline, " "strike, " + "spoiler, " "mention, " "URL, " "code\n\n" diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index f3f55195c2..805ca02153 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -61,6 +61,8 @@ def handle_starttag(self, tag, attrs): elif tag == "pre": entity = raw.types.MessageEntityPre extra["language"] = "" + elif tag == "spoiler": + entity = raw.types.MessageEntitySpoiler elif tag == "a": url = attrs.get("href", "") @@ -153,7 +155,7 @@ def unparse(text: str, entities: list): start = entity.offset end = start + entity.length - if entity_type in ("bold", "italic", "underline", "strikethrough"): + if entity_type in ("bold", "italic", "underline", "strikethrough", "spoiler"): start_tag = f"<{entity_type[0]}>" end_tag = f"" elif entity_type in ("code", "pre", "blockquote"): diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index f71503d832..3652c4c48f 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -28,6 +28,7 @@ ITALIC_DELIM = "__" UNDERLINE_DELIM = "--" STRIKE_DELIM = "~~" +SPOILER_DELIM = "##" CODE_DELIM = "`" PRE_DELIM = "```" @@ -41,7 +42,8 @@ STRIKE_DELIM, UNDERLINE_DELIM, ITALIC_DELIM, - BOLD_DELIM + BOLD_DELIM, + SPOILER_DELIM ] ]] ))) @@ -90,6 +92,8 @@ async def parse(self, text: str, strict: bool = False): tag = "code" elif delim == PRE_DELIM: tag = "pre" + elif delim == SPOILER_DELIM: + tag = "spoiler" else: continue @@ -127,6 +131,8 @@ def unparse(text: str, entities: list): start_tag = end_tag = CODE_DELIM elif entity_type in ("pre", "blockquote"): start_tag = end_tag = PRE_DELIM + elif entity_type == "spoiler": + start_tag = end_tag = SPOILER_DELIM elif entity_type == "text_link": url = entity.url start_tag = "[" diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index a0fc86a922..9a211fde74 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -42,6 +42,7 @@ class MessageEntityType(AutoName): ITALIC = auto() UNDERLINE = auto() STRIKETHROUGH = auto() + SPOILER = auto() CODE = auto() PRE = auto() TEXT_LINK = auto() @@ -62,6 +63,7 @@ class MessageEntityType(AutoName): raw.types.MessageEntityPre: MessageEntityType.PRE, raw.types.MessageEntityUnderline: MessageEntityType.UNDERLINE, raw.types.MessageEntityStrike: MessageEntityType.STRIKETHROUGH, + raw.types.MessageEntitySpoiler: MessageEntityType.SPOILER, raw.types.MessageEntityBlockquote: MessageEntityType.BLOCKQUOTE, raw.types.MessageEntityTextUrl: MessageEntityType.TEXT_LINK, raw.types.MessageEntityMentionName: MessageEntityType.TEXT_MENTION, @@ -90,6 +92,7 @@ class MessageEntity(Object): - "italic": *italic text*. - "underline": underlined text. - "strikethrough": strikethrough text. + - "spoiler": spoiler text. - "code": monowidth string. - "pre": monowidth block (see *language* below). - "text_link": for clickable text URLs. From 00c91120d82b5ae3b23961e60b5edb5f2eaadde4 Mon Sep 17 00:00:00 2001 From: SUBIN <64341611+subinps@users.noreply.github.com> Date: Thu, 30 Dec 2021 15:36:37 +0530 Subject: [PATCH 029/539] Handle the case when default_send_as is None (#842) * fix parsing send_as peer. * Update chat.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/types/user_and_chats/chat.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4cee964097..898a4325ca 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -320,12 +320,13 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw. default_send_as = full_chat.default_send_as - if isinstance(default_send_as, raw.types.PeerUser): - send_as_raw = users[default_send_as.user_id] - else: - send_as_raw = chats[default_send_as.channel_id] - - parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw) + if default_send_as: + if isinstance(default_send_as, raw.types.PeerUser): + send_as_raw = users[default_send_as.user_id] + else: + send_as_raw = chats[default_send_as.channel_id] + + parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw) if full_chat.pinned_msg_id: parsed_chat.pinned_message = await client.get_messages( From 46d3d8aaf60a67e4603cf11cdbc0afdaf4b0dd01 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:39:58 +0100 Subject: [PATCH 030/539] Update REACTION_INVALID error message --- compiler/errors/source/400_BAD_REQUEST.tsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index e1d29f3803..1b12472c13 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -249,7 +249,7 @@ RANDOM_ID_INVALID The provided random ID is invalid RANDOM_LENGTH_INVALID The random length is invalid RANGES_INVALID Invalid range provided REACTION_EMPTY The reaction provided is empty -REACTION_INVALID Invalid reaction provided (only emoji are allowed) +REACTION_INVALID Invalid reaction provided (only valid emoji are allowed) REFLECTOR_NOT_AVAILABLE The call reflector is not available REPLY_MARKUP_BUY_EMPTY Reply markup for buy button empty REPLY_MARKUP_GAME_EMPTY The provided reply markup for the game is empty From b0a9d28bda7e1408b8355cc31f80af8e22e05d4e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:41:23 +0100 Subject: [PATCH 031/539] Add field Chat.available_reactions --- pyrogram/types/user_and_chats/chat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4cee964097..6622c18139 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -124,6 +124,10 @@ class Chat(Object): send_as_chat (:obj:`~pyrogram.types.Chat`, *optional*): The default "send_as" chat. Returned only in :meth:`~pyrogram.Client.get_chat`. + + available_reactions (List of ``str``, *optional*): + Available reactions in the chat. + Returned only in :meth:`~pyrogram.Client.get_chat`. """ def __init__( @@ -156,7 +160,8 @@ def __init__( permissions: "types.ChatPermissions" = None, distance: int = None, linked_chat: "types.Chat" = None, - send_as_chat: "types.Chat" = None + send_as_chat: "types.Chat" = None, + available_reactions: List[str] = None ): super().__init__(client) @@ -187,6 +192,7 @@ def __init__( self.distance = distance self.linked_chat = linked_chat self.send_as_chat = send_as_chat + self.available_reactions = available_reactions @staticmethod def _parse_user_chat(client, user: raw.types.User) -> "Chat": @@ -336,6 +342,8 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw. if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported): parsed_chat.invite_link = full_chat.exported_invite.link + parsed_chat.available_reactions = full_chat.available_reactions or None + return parsed_chat @staticmethod From 1fa637553d797b377929346251691d8c5e91e2e6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:43:30 +0100 Subject: [PATCH 032/539] Add method send_reaction --- pyrogram/methods/messages/__init__.py | 4 +- pyrogram/methods/messages/send_reaction.py | 65 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/messages/send_reaction.py diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index 8dee8402c3..84cc143db9 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -53,6 +53,7 @@ from .send_message import SendMessage from .send_photo import SendPhoto from .send_poll import SendPoll +from .send_reaction import SendReaction from .send_sticker import SendSticker from .send_venue import SendVenue from .send_video import SendVideo @@ -106,6 +107,7 @@ class Messages( CopyMediaGroup, SearchMessagesCount, SearchGlobalCount, - GetDiscussionMessage + GetDiscussionMessage, + SendReaction ): pass diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py new file mode 100644 index 0000000000..a65cb5bcee --- /dev/null +++ b/pyrogram/methods/messages/send_reaction.py @@ -0,0 +1,65 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class SendReaction(Scaffold): + async def send_reaction( + self, + chat_id: Union[int, str], + message_id: int, + emoji: str = "" + ) -> bool: + """Send a reaction to a message. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + message_id (``int``): + Identifier of the message. + + emoji (``str``, *optional*): + Reaction emoji. + Pass "" as emoji (default) to retract the reaction. + + Returns: + ``bool``: On success, True is returned. + + Example: + .. code-block:: python + + # Send a reaction + app.send_reaction(chat_id, message_id, "🔥") + + # Retract a reaction + app.send_reaction(chat_id, message_id) + """ + await self.send( + raw.functions.messages.SendReaction( + peer=await self.resolve_peer(chat_id), + msg_id=message_id, + reaction=emoji + ) + ) + + return True From 2799011c07f83fa239f5409377ccb6a282115f66 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:45:43 +0100 Subject: [PATCH 033/539] Add type Reaction --- pyrogram/types/messages_and_media/__init__.py | 4 +- pyrogram/types/messages_and_media/reaction.py | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/messages_and_media/reaction.py diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 864019fe24..9f31dde066 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -36,8 +36,10 @@ from .video_note import VideoNote from .voice import Voice from .webpage import WebPage +from .reaction import Reaction __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", - "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice" + "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", + "Reaction" ] diff --git a/pyrogram/types/messages_and_media/reaction.py b/pyrogram/types/messages_and_media/reaction.py new file mode 100644 index 0000000000..9d4baa54fa --- /dev/null +++ b/pyrogram/types/messages_and_media/reaction.py @@ -0,0 +1,49 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 ..object import Object + + +class Reaction(Object): + """Contains information about a reaction. + + Parameters: + emoji (``str``): + Reaction emoji. + + count (``int``): + Reaction count. + + chosen (``bool``): + Whether this is the chosen reaction. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + emoji: str, + count: int, + chosen: bool + ): + super().__init__(client) + + self.emoji = emoji + self.count = count + self.chosen = chosen From fb64e143b6e55a325df9c31b7e69d938c95e1c80 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:46:44 +0100 Subject: [PATCH 034/539] Add field Message.reactions --- pyrogram/types/messages_and_media/message.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 9e1c7e1a24..9306a894ce 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -284,6 +284,9 @@ class Message(Object, Update): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + reactions (List of :obj:`~pyrogram.types.Reaction`): + List of the reactions to this message. + link (``str``, *property*): Generate a link to this message, only for groups and channels. """ @@ -361,7 +364,8 @@ def __init__( "types.ReplyKeyboardMarkup", "types.ReplyKeyboardRemove", "types.ForceReply" - ] = None + ] = None, + reactions: List["types.Reaction"] = None ): super().__init__(client) @@ -428,6 +432,7 @@ def __init__( self.voice_chat_started = voice_chat_started self.voice_chat_ended = voice_chat_ended self.voice_chat_members_invited = voice_chat_members_invited + self.reactions = reactions @staticmethod async def _parse( @@ -721,6 +726,9 @@ async def _parse( from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None + reactions = [types.Reaction(emoji=r.reaction, count=r.count, chosen=r.chosen) + for r in message.reactions.results] if message.reactions else None + parsed_message = Message( message_id=message.id, date=message.date, @@ -780,6 +788,7 @@ async def _parse( via_bot=types.User._parse(client, users.get(message.via_bot_id, None)), outgoing=message.out, reply_markup=reply_markup, + reactions=reactions, client=client ) From f6625192d02b882068fa0e70eaef124479b37ef2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:12:24 +0100 Subject: [PATCH 035/539] Add parameter protect_content to send_* methods --- pyrogram/methods/bots/send_game.py | 5 +++++ pyrogram/methods/messages/copy_message.py | 5 +++++ pyrogram/methods/messages/forward_messages.py | 9 +++++++-- pyrogram/methods/messages/send_animation.py | 5 +++++ pyrogram/methods/messages/send_audio.py | 5 +++++ pyrogram/methods/messages/send_contact.py | 5 +++++ pyrogram/methods/messages/send_dice.py | 5 +++++ pyrogram/methods/messages/send_document.py | 5 +++++ pyrogram/methods/messages/send_location.py | 5 +++++ pyrogram/methods/messages/send_media_group.py | 7 ++++++- pyrogram/methods/messages/send_message.py | 7 ++++++- pyrogram/methods/messages/send_photo.py | 5 +++++ pyrogram/methods/messages/send_poll.py | 5 +++++ pyrogram/methods/messages/send_sticker.py | 5 +++++ pyrogram/methods/messages/send_venue.py | 5 +++++ pyrogram/methods/messages/send_video.py | 5 +++++ pyrogram/methods/messages/send_video_note.py | 5 +++++ pyrogram/methods/messages/send_voice.py | 5 +++++ pyrogram/types/messages_and_media/message.py | 6 ++++++ 19 files changed, 100 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py index 8f6d10ab82..f6e6a3409c 100644 --- a/pyrogram/methods/bots/send_game.py +++ b/pyrogram/methods/bots/send_game.py @@ -30,6 +30,7 @@ async def send_game( game_short_name: str, disable_notification: bool = None, reply_to_message_id: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -55,6 +56,9 @@ async def send_game( reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): An object for an inline keyboard. If empty, one ‘Play game_title’ button will be shown automatically. If not empty, the first button must launch the game. @@ -80,6 +84,7 @@ async def send_game( silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None ) ) diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py index 3250ac8906..5e8869496d 100644 --- a/pyrogram/methods/messages/copy_message.py +++ b/pyrogram/methods/messages/copy_message.py @@ -37,6 +37,7 @@ async def copy_message( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -88,6 +89,9 @@ async def copy_message( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -112,5 +116,6 @@ async def copy_message( disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, schedule_date=schedule_date, + protect_content=protect_content, reply_markup=reply_markup ) diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py index b67e50ec0b..9218bf6ee2 100644 --- a/pyrogram/methods/messages/forward_messages.py +++ b/pyrogram/methods/messages/forward_messages.py @@ -30,7 +30,8 @@ async def forward_messages( from_chat_id: Union[int, str], message_ids: Union[int, Iterable[int]], disable_notification: bool = None, - schedule_date: int = None + schedule_date: int = None, + protect_content: bool = None ) -> Union["types.Message", List["types.Message"]]: """Forward messages of any kind. @@ -56,6 +57,9 @@ async def forward_messages( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + Returns: :obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was an integer, the single forwarded message is returned, otherwise, in case *message_ids* was an iterable, @@ -82,7 +86,8 @@ async def forward_messages( id=message_ids, silent=disable_notification or None, random_id=[self.rnd_id() for _ in message_ids], - schedule_date=schedule_date + schedule_date=schedule_date, + noforwards=protect_content ) ) diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index d365ae562c..d1ee9585ff 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -46,6 +46,7 @@ async def send_animation( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -116,6 +117,9 @@ async def send_animation( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -222,6 +226,7 @@ def progress(current, total): reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index 4fa683a9ea..eeb45f6543 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -45,6 +45,7 @@ async def send_audio( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -113,6 +114,9 @@ async def send_audio( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -217,6 +221,7 @@ def progress(current, total): reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py index 6317a8296a..f744fab033 100644 --- a/pyrogram/methods/messages/send_contact.py +++ b/pyrogram/methods/messages/send_contact.py @@ -34,6 +34,7 @@ async def send_contact( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -71,6 +72,9 @@ async def send_contact( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -97,6 +101,7 @@ async def send_contact( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None ) ) diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py index 4b7422b316..6c7f70cd4d 100644 --- a/pyrogram/methods/messages/send_dice.py +++ b/pyrogram/methods/messages/send_dice.py @@ -31,6 +31,7 @@ async def send_dice( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -63,6 +64,9 @@ async def send_dice( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -91,6 +95,7 @@ async def send_dice( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, message="" ) diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py index a7e342855f..3661b2552e 100644 --- a/pyrogram/methods/messages/send_document.py +++ b/pyrogram/methods/messages/send_document.py @@ -43,6 +43,7 @@ async def send_document( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -105,6 +106,9 @@ async def send_document( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -194,6 +198,7 @@ def progress(current, total): reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py index e70d9661d0..1bc3b0326c 100644 --- a/pyrogram/methods/messages/send_location.py +++ b/pyrogram/methods/messages/send_location.py @@ -32,6 +32,7 @@ async def send_location( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -63,6 +64,9 @@ async def send_location( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -89,6 +93,7 @@ async def send_location( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None ) ) diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index 4073ddecaa..dc8ca7f000 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -44,6 +44,7 @@ async def send_media_group( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, ) -> List["types.Message"]: """Send a group of photos or videos as an album. @@ -66,6 +67,9 @@ async def send_media_group( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + Returns: List of :obj:`~pyrogram.types.Message`: On success, a list of the sent messages is returned. @@ -377,7 +381,8 @@ async def send_media_group( multi_media=multi_media, silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - schedule_date=schedule_date + schedule_date=schedule_date, + noforwards=protect_content ), sleep_threshold=60 ) diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py index 552a233bbe..54fcfe4850 100644 --- a/pyrogram/methods/messages/send_message.py +++ b/pyrogram/methods/messages/send_message.py @@ -34,6 +34,7 @@ async def send_message( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -75,6 +76,9 @@ async def send_message( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -132,7 +136,8 @@ async def send_message( schedule_date=schedule_date, reply_markup=await reply_markup.write(self) if reply_markup else None, message=message, - entities=entities + entities=entities, + noforwards=protect_content ) ) diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index fcc3c04c6c..ff69558974 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -41,6 +41,7 @@ async def send_photo( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -93,6 +94,9 @@ async def send_photo( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -172,6 +176,7 @@ async def send_photo( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py index dc0ccf178c..6fbb0aab95 100644 --- a/pyrogram/methods/messages/send_poll.py +++ b/pyrogram/methods/messages/send_poll.py @@ -36,6 +36,7 @@ async def send_poll( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -83,6 +84,9 @@ async def send_poll( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -117,6 +121,7 @@ async def send_poll( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None ) ) diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py index c7ae122a57..144bba37a5 100644 --- a/pyrogram/methods/messages/send_sticker.py +++ b/pyrogram/methods/messages/send_sticker.py @@ -37,6 +37,7 @@ async def send_sticker( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -71,6 +72,9 @@ async def send_sticker( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -150,6 +154,7 @@ async def send_sticker( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, message="" ) diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py index 7dbae7a0e9..557aa673b4 100644 --- a/pyrogram/methods/messages/send_venue.py +++ b/pyrogram/methods/messages/send_venue.py @@ -36,6 +36,7 @@ async def send_venue( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -80,6 +81,9 @@ async def send_venue( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -113,6 +117,7 @@ async def send_venue( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None ) ) diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index d42846eda4..2356317518 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -47,6 +47,7 @@ async def send_video( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -122,6 +123,9 @@ async def send_video( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -228,6 +232,7 @@ def progress(current, total): reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py index 91ba93fe4c..231e149820 100644 --- a/pyrogram/methods/messages/send_video_note.py +++ b/pyrogram/methods/messages/send_video_note.py @@ -39,6 +39,7 @@ async def send_video_note( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -85,6 +86,9 @@ async def send_video_note( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -174,6 +178,7 @@ async def send_video_note( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, message="" ) diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index c534767bc4..9828ccf898 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -41,6 +41,7 @@ async def send_voice( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -91,6 +92,9 @@ async def send_voice( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -178,6 +182,7 @@ async def send_voice( reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, + noforwards=protect_content, reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 9306a894ce..9690baf992 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -2924,6 +2924,7 @@ async def copy( disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, + protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -2979,6 +2980,9 @@ async def copy( schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -3008,6 +3012,7 @@ async def copy( disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, schedule_date=schedule_date, + protect_content=protect_content, reply_markup=self.reply_markup if reply_markup is object else reply_markup ) elif self.media: @@ -3017,6 +3022,7 @@ async def copy( disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, schedule_date=schedule_date, + protect_content=protect_content, reply_markup=self.reply_markup if reply_markup is object else reply_markup ) From ebaf1a23fbe797d24e9ecc8d803bf4e174f9e967 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:19:02 +0100 Subject: [PATCH 036/539] Change markdown spoiler delimiter --- docs/source/topics/text-formatting.rst | 4 ++-- pyrogram/parser/markdown.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index bada964b16..e3b730e585 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -64,7 +64,7 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us ~~strike~~ - ##spoiler## + ||spoiler|| [text URL](https://docs.pyrogram.org/) @@ -89,7 +89,7 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us "__italic__, " "--underline--, " "~~strike~~, " - "##spoiler##, " + "||spoiler||, " "[mention](tg://user?id=23122162), " "[URL](https://pyrogram.org), " "`code`, " diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index 3652c4c48f..5d14f8e8cb 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -28,7 +28,7 @@ ITALIC_DELIM = "__" UNDERLINE_DELIM = "--" STRIKE_DELIM = "~~" -SPOILER_DELIM = "##" +SPOILER_DELIM = "||" CODE_DELIM = "`" PRE_DELIM = "```" From b283bce2623d3646f3d785378267e5db271a85ec Mon Sep 17 00:00:00 2001 From: Fernando Werneck Date: Wed, 5 Jan 2022 08:37:25 -0300 Subject: [PATCH 037/539] Add No Forwards chat option (#839) * Add No Forwards chat option * Fix chat.py --- compiler/docs/compiler.py | 1 + pyrogram/methods/chats/__init__.py | 4 +- pyrogram/methods/chats/toggle_no_forwards.py | 49 ++++++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 23 +++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/chats/toggle_no_forwards.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c8823ceb03..7becd223cf 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -515,6 +515,7 @@ def get_title_list(s: str) -> list: Chat.join Chat.leave Chat.mark_unread + Chat.no_forwards """, user=""" User diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index ce8fe14c5b..87634793b8 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -56,6 +56,7 @@ from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername +from .toggle_no_forwards import ToggleNoForwards class Chats( @@ -98,6 +99,7 @@ class Chats( GetChatEventLog, GetChatOnlineCount, GetSendAsChats, - SetSendAsChat + SetSendAsChat, + ToggleNoForwards ): pass diff --git a/pyrogram/methods/chats/toggle_no_forwards.py b/pyrogram/methods/chats/toggle_no_forwards.py new file mode 100644 index 0000000000..182c8e7790 --- /dev/null +++ b/pyrogram/methods/chats/toggle_no_forwards.py @@ -0,0 +1,49 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# 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 typing import Union + +from pyrogram.raw import functions +from pyrogram.scaffold import Scaffold + + +class ToggleNoForwards(Scaffold): + async def toggle_no_forwards( + self, + chat_id: Union[int, str], + enabled: bool = False + ) -> bool: + """Toggle no forwards chat option + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + enabled (``bool``, *optional*): + Pass True to enable no forwards + + Returns: + ``bool``: On success, True is returned. + """ + + return await self.send( + functions.messages.ToggleNoForwards( + peer=await self.resolve_peer(chat_id), + enabled=enabled + ) + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 898a4325ca..8d95e4a94c 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -1011,3 +1011,26 @@ async def mark_unread(self, ) -> bool: """ return await self._client.mark_chat_unread(self.id) + + async def no_forwards(self, enabled: bool = False) -> bool: + """Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`. + + Use as a shortcut for: + + .. code-block:: python + + client.toggle_no_forwards(chat_id, enabled) + + Example: + .. code-block:: python + + chat.toggle_no_forwards(True) + + Returns: + ``bool``: On success, True is returned. + """ + + return await self._client.toggle_no_forwards( + self.id, + enabled=enabled + ) From ac3d2b8d7a6e48d9fd304ebc8d3676028f4b2a02 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Jan 2022 12:45:09 +0100 Subject: [PATCH 038/539] Rename methods and add proper docs --- compiler/docs/compiler.py | 3 ++- pyrogram/methods/chats/__init__.py | 4 ++-- ...forwards.py => set_chat_protected_content.py} | 16 +++++++++------- pyrogram/types/user_and_chats/chat.py | 16 ++++++++++------ 4 files changed, 23 insertions(+), 16 deletions(-) rename pyrogram/methods/chats/{toggle_no_forwards.py => set_chat_protected_content.py} (81%) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 7becd223cf..6dd8adf4db 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -226,6 +226,7 @@ def get_title_list(s: str) -> list: get_chat_online_count get_send_as_chats set_send_as_chat + set_chat_protected_content """, users=""" Users @@ -515,7 +516,7 @@ def get_title_list(s: str) -> list: Chat.join Chat.leave Chat.mark_unread - Chat.no_forwards + Chat.set_protected_content """, user=""" User diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 87634793b8..70c02dee15 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -48,6 +48,7 @@ from .set_chat_description import SetChatDescription from .set_chat_permissions import SetChatPermissions from .set_chat_photo import SetChatPhoto +from .set_chat_protected_content import SetChatProtectedContent from .set_chat_title import SetChatTitle from .set_send_as_chat import SetSendAsChat from .set_slow_mode import SetSlowMode @@ -56,7 +57,6 @@ from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername -from .toggle_no_forwards import ToggleNoForwards class Chats( @@ -100,6 +100,6 @@ class Chats( GetChatOnlineCount, GetSendAsChats, SetSendAsChat, - ToggleNoForwards + SetChatProtectedContent ): pass diff --git a/pyrogram/methods/chats/toggle_no_forwards.py b/pyrogram/methods/chats/set_chat_protected_content.py similarity index 81% rename from pyrogram/methods/chats/toggle_no_forwards.py rename to pyrogram/methods/chats/set_chat_protected_content.py index 182c8e7790..8057873da3 100644 --- a/pyrogram/methods/chats/toggle_no_forwards.py +++ b/pyrogram/methods/chats/set_chat_protected_content.py @@ -22,28 +22,30 @@ from pyrogram.scaffold import Scaffold -class ToggleNoForwards(Scaffold): - async def toggle_no_forwards( +class SetChatProtectedContent(Scaffold): + async def set_chat_protected_content( self, chat_id: Union[int, str], - enabled: bool = False + enabled: bool ) -> bool: - """Toggle no forwards chat option + """Set the chat protected content setting. Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - enabled (``bool``, *optional*): - Pass True to enable no forwards + enabled (``bool``): + Pass True to enable the protected content setting, False to disable. Returns: ``bool``: On success, True is returned. """ - return await self.send( + await self.send( functions.messages.ToggleNoForwards( peer=await self.resolve_peer(chat_id), enabled=enabled ) ) + + return True diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 8d95e4a94c..486fe66fd2 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -325,7 +325,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw. send_as_raw = users[default_send_as.user_id] else: send_as_raw = chats[default_send_as.channel_id] - + parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw) if full_chat.pinned_msg_id: @@ -1012,25 +1012,29 @@ async def mark_unread(self, ) -> bool: return await self._client.mark_chat_unread(self.id) - async def no_forwards(self, enabled: bool = False) -> bool: - """Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`. + async def set_protected_content(self, enabled: bool) -> bool: + """Bound method *set_protected_content* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: .. code-block:: python - client.toggle_no_forwards(chat_id, enabled) + client.set_chat_protected_content(chat_id, enabled) + + Parameters: + enabled (``bool``): + Pass True to enable the protected content setting, False to disable. Example: .. code-block:: python - chat.toggle_no_forwards(True) + chat.set_protected_content(enabled) Returns: ``bool``: On success, True is returned. """ - return await self._client.toggle_no_forwards( + return await self._client.set_chat_protected_content( self.id, enabled=enabled ) From 8c8288412fc80552f7a001d77d9afac905d81fc7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 7 Jan 2022 10:18:51 +0100 Subject: [PATCH 039/539] Various improvements --- .github/FUNDING.yml | 3 +- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/config.yml | 6 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- README.md | 58 ++- compiler/docs/compiler.py | 8 + compiler/docs/template/bound-methods.rst | 7 +- compiler/docs/template/methods.rst | 7 +- compiler/docs/template/types.rst | 1 - compiler/errors/source/400_BAD_REQUEST.tsv | 3 +- compiler/errors/source/401_UNAUTHORIZED.tsv | 2 +- docs/README.md | 8 - docs/requirements.txt | 4 +- docs/robots.txt | 7 - docs/scripts/releases.py | 84 ---- docs/scripts/sitemap.py | 81 ---- docs/source/_images/favicon.ico | Bin 16958 -> 0 bytes docs/source/_images/pyrogram.png | Bin 48928 -> 0 bytes docs/source/api/client.rst | 1 - docs/source/api/decorators.rst | 4 - docs/source/api/handlers.rst | 1 - docs/source/conf.py | 28 +- docs/source/faq.rst | 407 ------------------ .../client-started-but-nothing-happens.rst | 11 + ...alling-stop-restart-add-remove-handler.rst | 12 + docs/source/faq/how-to-avoid-flood-waits.rst | 23 + docs/source/faq/how-to-use-webhooks.rst | 9 + docs/source/faq/index.rst | 47 ++ ...ing-the-account-to-another-data-center.rst | 10 + docs/source/faq/peer-id-invalid-error.rst | 14 + ...-raised-exception-oserror-timeouterror.rst | 10 + ...interfaceerror-error-binding-parameter.rst | 13 + ...e3-operationalerror-database-is-locked.rst | 17 + ...e-account-has-been-limited-deactivated.rst | 16 + .../unicodeencodeerror-codec-cant-encode.rst | 7 + ...h-urls-gives-error-webpage-curl-failed.rst | 7 + ...le-clients-at-once-on-the-same-account.rst | 7 + ...same-file-id-across-different-accounts.rst | 6 + ...-ip-addresses-of-telegram-data-centers.rst | 30 ++ .../why-is-the-api-key-needed-for-bots.rst | 12 + ...eacting-slowly-in-supergroups-channels.rst | 18 + ...-event-handler-triggered-twice-or-more.rst | 28 ++ docs/source/glossary.rst | 86 ---- docs/source/index.rst | 65 +-- docs/source/intro/install.rst | 18 +- docs/source/intro/quickstart.rst | 35 +- docs/source/intro/setup.rst | 24 +- docs/source/license.rst | 16 - docs/source/start/auth.rst | 21 +- docs/source/start/errors.rst | 13 +- docs/source/start/examples/bot_keyboards.rst | 4 +- docs/source/start/examples/echobot.rst | 2 +- docs/source/start/examples/hello_world.rst | 6 - docs/source/start/examples/inline_queries.rst | 2 - .../source/start/examples/use_inline_bots.rst | 4 +- docs/source/start/examples/welcomebot.rst | 2 +- docs/source/start/invoking.rst | 99 +++-- docs/source/start/updates.rst | 52 +-- docs/source/support.rst | 74 ++-- docs/source/topics/advanced-usage.rst | 69 ++- docs/source/topics/bots-interaction.rst | 50 --- ...ssion-settings.rst => client-settings.rst} | 26 +- docs/source/topics/config-file.rst | 4 +- docs/source/topics/create-filters.rst | 2 +- docs/source/topics/debugging.rst | 68 ++- docs/source/topics/more-on-updates.rst | 1 - docs/source/topics/mtproto-vs-botapi.rst | 33 +- docs/source/topics/scheduling.rst | 4 +- docs/source/topics/serializing.rst | 5 +- docs/source/topics/smart-plugins.rst | 40 +- docs/source/topics/storage-engines.rst | 38 +- docs/source/topics/test-servers.rst | 17 +- docs/source/topics/text-formatting.rst | 26 +- docs/source/topics/tgcrypto.rst | 19 +- docs/source/topics/use-filters.rst | 10 +- docs/source/topics/voice-calls.rst | 4 +- pyrogram/client.py | 20 +- .../connection/transport/tcp/tcp_abridged.py | 1 - pyrogram/connection/transport/tcp/tcp_full.py | 2 +- .../transport/tcp/tcp_intermediate.py | 2 +- .../transport/tcp/tcp_intermediate_o.py | 2 +- pyrogram/errors/rpc_error.py | 2 +- pyrogram/filters.py | 9 - pyrogram/methods/bots/__init__.py | 2 +- pyrogram/methods/chats/get_chat_member.py | 4 +- pyrogram/methods/chats/get_chat_members.py | 18 +- .../methods/chats/get_chat_members_count.py | 2 +- pyrogram/methods/chats/iter_chat_members.py | 72 ++-- .../methods/chats/set_administrator_title.py | 2 +- pyrogram/methods/chats/set_slow_mode.py | 4 +- pyrogram/methods/contacts/add_contact.py | 2 +- pyrogram/methods/contacts/import_contacts.py | 6 +- pyrogram/methods/messages/copy_media_group.py | 5 +- pyrogram/methods/messages/download_media.py | 2 +- pyrogram/methods/messages/forward_messages.py | 1 - pyrogram/methods/messages/get_history.py | 6 +- .../methods/messages/get_history_count.py | 2 +- pyrogram/methods/messages/get_media_group.py | 4 +- pyrogram/methods/messages/get_messages.py | 4 +- pyrogram/methods/messages/read_history.py | 4 +- pyrogram/methods/messages/search_global.py | 10 +- pyrogram/methods/messages/search_messages.py | 16 +- pyrogram/methods/messages/send_animation.py | 2 +- pyrogram/methods/messages/send_audio.py | 5 +- .../methods/messages/send_cached_media.py | 2 +- pyrogram/methods/messages/send_contact.py | 2 +- pyrogram/methods/messages/send_dice.py | 6 +- pyrogram/methods/messages/send_document.py | 2 +- pyrogram/methods/messages/send_media_group.py | 2 +- pyrogram/methods/messages/send_message.py | 5 +- pyrogram/methods/messages/send_sticker.py | 2 +- pyrogram/methods/messages/send_video.py | 2 +- pyrogram/methods/messages/send_voice.py | 2 +- pyrogram/methods/users/get_common_chats.py | 2 +- pyrogram/methods/users/get_profile_photos.py | 6 +- .../methods/users/get_profile_photos_count.py | 2 +- pyrogram/methods/users/get_users.py | 2 +- pyrogram/methods/users/iter_profile_photos.py | 2 +- pyrogram/methods/utilities/add_handler.py | 1 - .../utilities/export_session_string.py | 1 - pyrogram/methods/utilities/idle.py | 1 - pyrogram/methods/utilities/remove_handler.py | 1 - pyrogram/methods/utilities/restart.py | 1 - pyrogram/methods/utilities/run.py | 5 +- pyrogram/methods/utilities/start.py | 1 - pyrogram/methods/utilities/stop.py | 1 - .../methods/utilities/stop_transmission.py | 3 +- pyrogram/raw/core/primitives/vector.py | 2 +- pyrogram/session/session.py | 8 - pyrogram/types/bots_and_keyboards/__init__.py | 2 +- pyrogram/types/inline_mode/__init__.py | 2 +- pyrogram/types/messages_and_media/message.py | 2 +- .../messages_and_media/message_entity.py | 2 +- pyrogram/types/user_and_chats/chat.py | 4 +- setup.py | 5 +- 135 files changed, 836 insertions(+), 1416 deletions(-) delete mode 100644 docs/README.md delete mode 100644 docs/robots.txt delete mode 100644 docs/scripts/releases.py delete mode 100644 docs/scripts/sitemap.py delete mode 100644 docs/source/_images/favicon.ico delete mode 100644 docs/source/_images/pyrogram.png delete mode 100644 docs/source/faq.rst create mode 100644 docs/source/faq/client-started-but-nothing-happens.rst create mode 100644 docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst create mode 100644 docs/source/faq/how-to-avoid-flood-waits.rst create mode 100644 docs/source/faq/how-to-use-webhooks.rst create mode 100644 docs/source/faq/index.rst create mode 100644 docs/source/faq/migrating-the-account-to-another-data-center.rst create mode 100644 docs/source/faq/peer-id-invalid-error.rst create mode 100644 docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst create mode 100644 docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst create mode 100644 docs/source/faq/sqlite3-operationalerror-database-is-locked.rst create mode 100644 docs/source/faq/the-account-has-been-limited-deactivated.rst create mode 100644 docs/source/faq/unicodeencodeerror-codec-cant-encode.rst create mode 100644 docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst create mode 100644 docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst create mode 100644 docs/source/faq/using-the-same-file-id-across-different-accounts.rst create mode 100644 docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst create mode 100644 docs/source/faq/why-is-the-api-key-needed-for-bots.rst create mode 100644 docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst create mode 100644 docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst delete mode 100644 docs/source/glossary.rst delete mode 100644 docs/source/license.rst delete mode 100644 docs/source/topics/bots-interaction.rst rename docs/source/topics/{session-settings.rst => client-settings.rst} (54%) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 13e0071eb0..19d0cd78d1 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ github: delivrance -custom: https://docs.pyrogram.org/support +liberapay: delivrance +open_collective: pyrogram diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7efd4ca160..e3bc5909d1 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,6 @@ --- name: Bug Report -about: Create a bug report affecting the library or the documentation +about: Create a bug report affecting the framework or the documentation --- diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 37e0cd33be..453151d8bd 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ blank_issues_enabled: false contact_links: - name: Ask Pyrogram related questions url: https://stackoverflow.com/questions/tagged/pyrogram - about: This place is for issues about Pyrogram. If you'd like to ask a question, please do so at StackOverflow. - - name: Join the Telegram community + about: This place is only for reporting issues about Pyrogram. You can ask questions at StackOverflow. + - name: Join the Telegram channel url: https://t.me/pyrogram - about: Join the official channel to stay tuned for news and updates. \ No newline at end of file + about: Join the official channel and stay tuned for news, updates and announcements. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 854db44d9c..bf5e6a21f3 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,7 +7,7 @@ labels: "enhancement" ## Checklist -- [ ] I believe the idea is awesome and would benefit the library. +- [ ] I believe the idea is awesome and would benefit the framework. - [ ] I have searched in the issue tracker for similar requests, including closed ones. ## Description diff --git a/README.md b/README.md index f8c4432e5f..e51ee0eb0b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- Pyrogram + Pyrogram
Telegram MTProto API Framework for Python @@ -9,17 +9,19 @@ Documentation • - + Releases • - - Community + + News

## Pyrogram +> Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots + ``` python from pyrogram import Client, filters @@ -28,34 +30,33 @@ app = Client("my_account") @app.on_message(filters.private) async def hello(client, message): - await message.reply_text(f"Hello {message.from_user.mention}") + await message.reply("Hello from Pyrogram!") app.run() ``` -**Pyrogram** is a modern, elegant and easy-to-use [Telegram](https://telegram.org/) client library framework written -from the ground up in Python and C. It enables you to easily create custom Telegram client applications for both user -and bot identities (bot API alternative) via the [MTProto API](https://docs.pyrogram.org/topics/mtproto-vs-botapi). +**Pyrogram** is a modern, elegant and asynchronous [MTProto API](https://docs.pyrogram.org/topics/mtproto-vs-botapi) +framework. It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot +identity (bot API alternative) using Python. -### Features +### Support -- **Easy**: You can install Pyrogram with pip and start building your applications right away. -- **Elegant**: Low-level details are abstracted and re-presented in a much nicer and easier way. -- **Fast**: Crypto parts are boosted up by [TgCrypto](https://github.com/pyrogram/tgcrypto), a high-performance library - written in pure C. -- **Asynchronous**: Allows both synchronous and asynchronous models to fit all usage needs. -- **Documented**: API methods, types and public interfaces are all [well documented](https://docs.pyrogram.org). -- **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. -- **Updated**, to make use of the latest Telegram API version and features. -- **Bot API-like**: Similar to the Bot API in its simplicity, but much more powerful and detailed. -- **Pluggable**: The Smart Plugin system allows to write components with minimal boilerplate code. -- **Comprehensive**: Execute any advanced action an official client is able to do, and even more. +If you'd like to support Pyrogram, you can consider: + +- [Become a GitHub sponsor](https://github.com/sponsors/delivrance). +- [Become a LiberaPay patron](https://liberapay.com/delivrance). +- [Become an OpenCollective backer](https://opencollective.com/pyrogram>). -### Requirements +### Key Features -- Python 3.6 or higher. -- A [Telegram API key](https://docs.pyrogram.org/intro/setup#api-keys). +- **Ready**: Install Pyrogram with pip and start building your applications right away. +- **Easy**: Makes the Telegram API simple and intuitive, while still allowing advanced usages. +- **Elegant**: Low-level details are abstracted and re-presented in a more convenient way. +- **Fast**: Boosted up by [TgCrypto](https://github.com/pyrogram/tgcrypto), a high-performance crypto library written in pure C. +- **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. +- **Async**: Fully asynchronous (also usable synchronously if wanted, for convenience). +- **Powerful**: Full access to Telegram's API to execute any official client action and more. ### Installing @@ -65,11 +66,6 @@ pip3 install pyrogram ### Resources -- The docs contain lots of resources to help you get started with Pyrogram: https://docs.pyrogram.org. -- Seeking extra help? Come join and ask our community: https://t.me/pyrogram. -- For other kind of inquiries, you can send a [message](https://t.me/haskell) or an [e-mail](mailto:dan@pyrogram.org). - -### Copyright & License - -- Copyright (C) 2017-2021 Dan <> -- Licensed under the terms of the [GNU Lesser General Public License v3 or later (LGPLv3+)](COPYING.lesser) +- Check out the docs at https://docs.pyrogram.org to learn more about Pyrogram, get started right +away and discover more in-depth material for building your client applications. +- Join the official channel at https://t.me/pyrogram and stay tuned for news, updates and announcements. diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 6dd8adf4db..65f6743660 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -158,6 +158,7 @@ def get_title_list(s: str) -> list: send_venue send_contact send_cached_media + send_reaction edit_message_text edit_message_caption edit_message_media @@ -180,7 +181,9 @@ def get_title_list(s: str) -> list: retract_vote send_dice search_messages + search_messages_count search_global + search_global_count download_media get_discussion_message """, @@ -284,6 +287,7 @@ def get_title_list(s: str) -> list: send_game set_game_score get_game_high_scores + set_bot_commands """, authorization=""" Authorization @@ -360,6 +364,7 @@ def get_title_list(s: str) -> list: ChatEvent ChatEventFilter ChatMemberUpdated + ChatJoinRequest Dialog Restriction """, @@ -384,6 +389,7 @@ def get_title_list(s: str) -> list: Poll PollOption Dice + Reaction VoiceChatScheduled VoiceChatStarted VoiceChatEnded @@ -420,6 +426,8 @@ def get_title_list(s: str) -> list: InlineQueryResultArticle InlineQueryResultPhoto InlineQueryResultAnimation + InlineQueryResultAudio + InlineQueryResultVideo ChosenInlineResult """, input_message_content=""" diff --git a/compiler/docs/template/bound-methods.rst b/compiler/docs/template/bound-methods.rst index 13a51b047e..ebaa2ab899 100644 --- a/compiler/docs/template/bound-methods.rst +++ b/compiler/docs/template/bound-methods.rst @@ -1,12 +1,11 @@ Bound Methods ============= -Some Pyrogram types define what are called bound methods. Bound methods are functions attached to a class which are -accessed via an instance of that class. They make it even easier to call specific methods by automatically inferring +Some Pyrogram types define what are called bound methods. Bound methods are functions attached to a type which are +accessed via an instance of that type. They make it even easier to call specific methods by automatically inferring some of the required arguments. .. code-block:: python - :emphasize-lines: 8 from pyrogram import Client @@ -15,7 +14,7 @@ some of the required arguments. @app.on_message() def hello(client, message) - message.reply_text("hi") + message.reply("hi") app.run() diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst index dc2950dca7..794e657e4c 100644 --- a/compiler/docs/template/methods.rst +++ b/compiler/docs/template/methods.rst @@ -1,18 +1,17 @@ Available Methods ================= -This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance, -except for :meth:`~pyrogram.idle()`, which is a special function that can be found in the main package directly. +This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance. +Some other utility functions can instead be found in the main package directly. .. code-block:: python - :emphasize-lines: 6 from pyrogram import Client app = Client("my_account") with app: - app.send_message("haskell", "hi") + app.send_message("me", "hi") .. contents:: Contents :backlinks: none diff --git a/compiler/docs/template/types.rst b/compiler/docs/template/types.rst index 8b34000623..2651c3559a 100644 --- a/compiler/docs/template/types.rst +++ b/compiler/docs/template/types.rst @@ -6,7 +6,6 @@ Unless required as argument to a client method, most of the types don't need to are only returned by other methods. You also don't need to import them, unless you want to type-hint your variables. .. code-block:: python - :emphasize-lines: 1 from pyrogram.types import User, Message, ... diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 1b12472c13..d6754027ee 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -62,6 +62,7 @@ CHAT_NOT_MODIFIED The chat settings (title, permissions, photo, etc..) were not CHAT_RESTRICTED The chat is restricted and cannot be used CHAT_SEND_INLINE_FORBIDDEN You cannot use inline bots to send messages in this chat CHAT_TITLE_EMPTY The chat title is empty +CHAT_TOO_BIG The chat is too big for this action CODE_EMPTY The provided code is empty CODE_HASH_INVALID The provided code hash invalid CODE_INVALID The provided code is invalid (i.e. from email) @@ -347,4 +348,4 @@ WEBDOCUMENT_URL_EMPTY The web document URL is empty WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media -YOU_BLOCKED_USER You blocked this user +YOU_BLOCKED_USER You blocked this user \ No newline at end of file diff --git a/compiler/errors/source/401_UNAUTHORIZED.tsv b/compiler/errors/source/401_UNAUTHORIZED.tsv index 1bb07b89ce..32e0265f53 100644 --- a/compiler/errors/source/401_UNAUTHORIZED.tsv +++ b/compiler/errors/source/401_UNAUTHORIZED.tsv @@ -2,7 +2,7 @@ id message ACTIVE_USER_REQUIRED The method is only available to already activated users AUTH_KEY_INVALID The key is invalid AUTH_KEY_PERM_EMPTY The method is unavailable for temporary authorization key, not bound to permanent -AUTH_KEY_UNREGISTERED The key is not registered in the system +AUTH_KEY_UNREGISTERED The key is not registered in the system. Delete your session file and login again SESSION_EXPIRED The authorization has expired SESSION_PASSWORD_NEEDED The two-step verification is enabled and a password is required SESSION_REVOKED The authorization has been invalidated, because of the user terminating all sessions diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 680e2cf488..0000000000 --- a/docs/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Pyrogram Docs - -- Install requirements. -- Install `pandoc` and `latexmk`. -- HTML: `make html` -- PDF: `make latexpdf` - -TODO: Explain better \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt index 2cfd56798c..f83e673d74 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ sphinx -sphinx_rtd_theme +sphinx_rtd_theme==1.0.0 sphinx_copybutton pypandoc requests -sphinx-autobuild \ No newline at end of file +sphinx-autobuild diff --git a/docs/robots.txt b/docs/robots.txt deleted file mode 100644 index 3e416f245f..0000000000 --- a/docs/robots.txt +++ /dev/null @@ -1,7 +0,0 @@ -User-agent: * - -Allow: / - -Disallow: /old* - -Sitemap: https://docs.pyrogram.org/sitemap.xml \ No newline at end of file diff --git a/docs/scripts/releases.py b/docs/scripts/releases.py deleted file mode 100644 index 4a32dd298f..0000000000 --- a/docs/scripts/releases.py +++ /dev/null @@ -1,84 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2021 Dan -# -# 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 shutil -from datetime import datetime -from pathlib import Path - -import pypandoc -import requests - -URL = "https://api.github.com/repos/pyrogram/pyrogram/releases" -DEST = Path("../source/releases") -INTRO = """ -Release Notes -============= - -Release notes for Pyrogram releases will describe what's new in each version, and will also make you aware of any -backwards-incompatible changes made in that version. - -When upgrading to a new version of Pyrogram, you will need to check all the breaking changes in order to find -incompatible code in your application, but also to take advantage of new features and improvements. - -**Contents** - -""".lstrip("\n") - -shutil.rmtree(DEST, ignore_errors=True) -DEST.mkdir(parents=True) - -releases = requests.get(URL).json() - -with open(DEST / "index.rst", "w") as index: - index.write(INTRO) - - tags = [] - - for release in releases: - tag = release["tag_name"] - title = release["name"] - name = title.split(" - ")[1] - - date = datetime.strptime( - release["published_at"], - "%Y-%m-%dT%H:%M:%SZ" - ).strftime("%b %d, %Y") - - body = pypandoc.convert_text( - release["body"].replace(r"\r\n", "\n"), - "rst", - format="markdown_github", - extra_args=["--wrap=none"] - ) - - tarball_url = release["tarball_url"] - zipball_url = release["zipball_url"] - - index.write("- :doc:`{} <{}>`\n".format(title, tag)) - tags.append(tag) - - with open(DEST / "{}.rst".format(tag), "w") as page: - page.write("Pyrogram " + tag + "\n" + "=" * (len(tag) + 9) + "\n\n") - page.write("\t\tReleased on " + str(date) + "\n\n") - page.write("- :download:`Source Code (zip) <{}>`\n".format(zipball_url)) - page.write("- :download:`Source Code (tar.gz) <{}>`\n\n".format(tarball_url)) - page.write(name + "\n" + "-" * len(name) + "\n\n") - page.write(body + "\n\n") - - index.write("\n.. toctree::\n :hidden:\n\n") - index.write("\n".join(" {}".format(tag) for tag in tags)) diff --git a/docs/scripts/sitemap.py b/docs/scripts/sitemap.py deleted file mode 100644 index 9c28bd1c5c..0000000000 --- a/docs/scripts/sitemap.py +++ /dev/null @@ -1,81 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2021 Dan -# -# 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 datetime -import os - -canonical = "https://docs.pyrogram.org/" - -dirs = { - ".": ("weekly", 1.0), - "intro": ("weekly", 0.9), - "start": ("weekly", 0.9), - "api": ("weekly", 0.8), - "topics": ("weekly", 0.8), - "releases": ("weekly", 0.8), - "telegram": ("weekly", 0.6) -} - - -def now(): - return datetime.datetime.today().strftime("%Y-%m-%d") - - -with open("sitemap.xml", "w") as f: - f.write('\n') - f.write('\n') - - urls = [] - - - def search(path): - try: - for j in os.listdir(path): - search(f"{path}/{j}") - except NotADirectoryError: - if not path.endswith(".rst"): - return - - path = path.split("/")[2:] - - if path[0].endswith(".rst"): - folder = "." - else: - folder = path[0] - - path = f"{canonical}{'/'.join(path)}"[:-len(".rst")] - - if path.endswith("index"): - path = path[:-len("index")] - - urls.append((path, now(), *dirs[folder])) - - - search("../source") - - urls.sort(key=lambda x: x[3], reverse=True) - - for i in urls: - f.write(f" \n") - f.write(f" {i[0]}\n") - f.write(f" {i[1]}\n") - f.write(f" {i[2]}\n") - f.write(f" {i[3]}\n") - f.write(f" \n") - - f.write("") diff --git a/docs/source/_images/favicon.ico b/docs/source/_images/favicon.ico deleted file mode 100644 index 4165f9edce821093f62506253dc379390f17cb64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16958 zcmd5@2YeLA^*;W@AvVp16PTt(FOp~mgRw>Lp_oo62G?MlVlZG+bSD84AUc>TnnY29 zP-3uYqBqkFrWygEqjJKrlQ{n*FW)zJdz@B#$LRn&r{B};%6t6a3UI_k7O4p8*>aAu;y{-$TN#7OH>g@z+H)OrEACf3- z-dih82doi+0D+pdY}8MdpxczhP&PHcO7?d7uQ-+=iw@kA`Frll>>YPx=2y2B z&HDN__y+yodry`gzAtOeWPyj&1D%ebu9Qm;l}>dYmMlR{rYT!$=f5=;qd5KK9f$?)+l2M1A59=_N zHeUTvCZ(K{*ZRaMyFgouer-knIQ2g@9%$GrHi?7WEwDQlA@=b8Dhiv8;Ua-BJ$sOTWHLDs|W^;qM=l zA@eUu{K-s7JfFJ_wwH7vN0uMGD}yF|EoJIX(sbb*c+l9vgIvBtew9Mgd3#+JHP&h4 zx(rX1r3Y{4!OcF=&aFO`DZdA9%9*%~@apmF^BO;b+onm~-Unq8c)8(nPA)#PJ@T64 zW%ROR;@>DnndaVNb||z8DKy`}&l2arpcL%13alC5GBDJ$@XR z9X<~5Z>H~EqtzVcldd(Gi`nj~6B$ys&mr`Qn1C4=13H|Ppf|5bQ1@#R)Z@k@>W*uc zb-5^k?T_PG%mL&@KKY<*D#pT?RaYg+U|wLq65w0+7`;jP&5+~I7zZ`U1HU?RnHc^w zdk>$s6W&p4mQhO%3+G!skC{)tkS*QDoxxnbO9EOSkf5%YCAile&|L}cea|!TnVz>K zsPlR7AwV9d4S9lhz_Y-PC-bcbw1=Hw3sNr```alOAIi{q z2b3+KJi&t@#8{wQMTOP%pZT|KR2I*S=d*!WyV1W&zVOgc_Nnl1!iSuZz&Fz+xKD-; zxOMu`=RWl3BJ>EhA|HAX0NtVg%(>TCM{}fc?>KF}knUH1+H(YIv}T0x?}C-)_XGUT}hUT$n?qynuVVIPR%0sh5rY9L|9W zr?ces5l>O>27IC(csoZ{?X*wEuf67WE?5uWa5Bbn5yWJGF%x54t(RTL0Lq(!ZWqCP zAC+`g_zroeC;EA_c4bQa51uW4&LM%nKjRe-I0oLEbrJZD`%Db9W7S&D)^uR9xpqb_ z6#({+DEpw-rg^L<@w+UsZpx65x1WLT=h6f47ybh0)yLUGt{Hp7A6f_5=;fv5ska}* z?p85HVBLl}-cMry>>gsxmQ{?gbsCo9c74OTl7N5A+6<{a;928m{r531LI)l*A80;t zJl35WUZZr@wkz<5RQ!xFBbWFgeO>E!zY7>6*7avR){%TZONOn4?f-)T{$42S3F_e> zUXxg!OSazTX$#ZgJ9}PFQvU6RpOodt9(e3KV+A!^&rxx9;OzmMr{V*UeLeWee=h~Q zzj*&mk98zp0R9y&_%*zJ?@7@684@@=QvyE)jn0z5PckLw!wd-;0A1F2@fbb?;<*al z?n!x20QrdL1KJ+)r~|~`cGwBTLOkPN_04_hJUm6klYyW6E)HM7(u%%*olXl>9NI{C zw6Y|~e^h*?RPAS%Yv9lf@sF}eg&8?gVWt5&%Kc+(5-=uHf(L>ZZuEh88x6g$_&X{A zF%-)K3GNG?Vm;w$43xuqsKX~GW#u=YtCfKA7`dHY=AWx_zPk0hVjh)FIJl% z%?7P@#;dh=^eOG%#0{BJV{E4Q#{%~p1I$KzVA(7?1$>q*L2u=rKPdMBvmXe3E4INj z^-`9MOU{xSy)Ssg&+*?4K9Ihz`aEsm=w(N-=cN3A!_fQZ)&5+lHG;OU^YB!mj_BWW z&96rtQx9fK$fA7U*7E~A^Pg&yz@g9w_)vk6dyCQcW!X`CJj=DcKYeeL-jlCMfCn2` zq4^#e82z1FA6To8>p080Gr~9)_T%nD?nTU@mfwO83yM`4C;cXViCCj&9U>3oPG(8{ zB{nIq$CaNvbz$~H2^b4I(f7W*JugFOTeZGwDgFBBEw??&Ke+8)8NT?6TmMI^i}2rBEW~Yi*YtOq&H=v*G5}^C}!Rzi>@?m_oytgDnQea#4 zZ4y7%H=f3SX!irc7(3Ub`uAP)ToX^-d_jU=pHBI6Jy;yF=ic2q;(u@YZp2bO&!Ma@ z31jo~ofyNjpI{8Q@T2VX9OhTm!Ev{7QP=v2f7+IdQZYPM zlRxmo28LKy7ODKX44z`&%W!?i=z1OcwFXpu{?oy)>CtE4slGk#e+*lES?J>$@gS&8 zntZh2GWK8G`@UM8#2>Tig4#F2e9yH2@pDgS4#$6=aa+`$qxQU~GzDW|$X1(_iG4ae zD2sWr_QD)l@=b0X*l^h16dmR5<2QfAZ{r`X9FN!r#LEs~z|HOn- z_OV~fas#*vo5Ln^{_nvU_Z$6JsQo0Z?Z>6;XUzU=DF@j-(OlrL1?5ps<+(W$kNq6B zt@cx3*J^al8xwjN`)TbzIq8+$U2%+Bd_ErcYP6m$%MRUf^4|45 zch}r|`e2JqN;yRsz_yrt~>PdS%I_v!C)uXG9aN8RXRPPGd?M`c-jxC@a=(Nrz8!#6xNV_YI2Om}YqMGev z+?V?-(VIQ5Q;hn#^7uXMy1M_vdXD={4WA0T$ddOnM1Y%cFyq3@SI&+{n3I5WUF2k_bh zzSRHPQS<@l(*`tuEB>*5guY(p>95l-d^6F`1KI>%#{q50{DT?NapXxSe)6FX_F2ZQ zxu*8kjr#DoGM+0cjI&t4`WN7@O5J~{=4d7+lnun3_|KQ?M9Er*{drt{`uo&_1iU+9 zd$zJ;zRU}>ffeW3WaeS4vlm`gdurxJJEhCm(`s*-=L+=gdXry&&W8DYE6y&c_(vk* zKgEgLFU)>s2>hrI9;9;}G<5EM6*u;#UZZE|A5GeuEmh~`sJX#gJs|dAU~jl4OJa}M z_poBN+?1(XZ>s&y$N9HLebLH@zf3*nzVH}g*Z+WjBmJV9ZRVBZ9 z^LpGn(CY9dW&iu8*u>w(*EiCI0IVZwF15+4>$2n$N$% z6}#)TIb=HRAkNQNq(QgEu(5g19_6PG#7~=84?ZGsQ^p$kW8FtxueR7G_2aXpaiRk| zc>zY`w!D&H*Y!r4+>uiM`~4aC5d-q3eoxQPUNGia8)ry~ z33S+1-tMk3K8}>c9Le*zix1p%yZ`N}ZS9^~D`HM)0&K+F5csI)9OF)Xcfnr|wlC_y z(;53bD>yK6yD+Y6$8UXA$=Y$2QIB8K38Yo{JpH7%qP~(f@EbKezN9J8)kKe(o=3;j33%`%SrmMM0-?@fK4o?#4&u}p`rhjqTSE%BMdrs!dM%;P=! zM7MbU{1wax+#B(APNYsZhHg{G^*mr1ZD7RyC)a!0d!CV|AIC8a3=xoJL61OnH?cqN zEW!J|P|rWOKhmhzGIj3LCmvu7yq@F+KV<*T_AKYR-;-=T-P`#6k1B@8Z!H}0tt4P6 zN-#M8;Kbz31?_T7rZaIp*jbg-LF4_=lJm0lyJMf!Iv92T$aQl02GKGh{*-E)bB!mx zB(~-7XX^t$?Hpwujb?|P_zp4Mm7(T{g#N#{S|>=67ruJ5>y;E8XB_fQZ08h$S{ z;){c7ez(W7EI*--v&~_S^IcCt?s=HtC_p4ddqS=dcq_XFz5-9?#U| z(R1htb%=8e$M-<%b}5f@{oJ=@8xF!c)!NV;5}|Ap0lCV@XMp*5(e*4bz6Yy_ex-o0 zuWb1zV)w{o_~UbcXEDD2TZUNVvLkowgt5Hz;4Q>^Z%FLcOEM3_4dFsN zukBj)Yh6B}WuBWiiV5y3<4$@bVHbF{ijBBhlthI0* zgtRm;<~gHUDlFQ|7XLRM^Q$|!`qy2B0jxX+Kn4GKi#{7 ze?p#P;(g=B!zv%0w_q&`FNXJSF18>?8wRlVdm9Fu4v$E=!zjboDg1Z${LLIxVH)M}!O0`CrAWs_{yAxC*rQdm%eDpjvjiOh9n7?XLtM7l zdT;!#C|EYqH~jGA{EP;2v3hywDYe#PvC{t6)YSjo>R}ek>hi{|cK8TvXH~WlDKm8x zh4w#gve;#{dxS<}P8FCthKr9be|+$Fo-%9LzwnZ7_+{oIeQ74%^{ew-`O(RnvR;?N zVlurq3aM=mI^6qEBV^H>Jkm@ZFq316GtD+!)!4{%*9koDBaeLO7DVP$GymuW&;gs% z&Nb6dfWJA#hP3?&@3=TKY;8S6?@!NFL@C$*MeBT=|0DY6wX@d1esy>GzJ|#5h{Ip4 zhIb4NGUN0h#;Al+teW7Kz_{9~ccb-->Xmr$9Z@6h5m7G57)N3@(~C6c?QgZRnz1k6 zaApi=I{-)Ad-f$%`s2O+^k*~~xC!{fJ9pGCGLfrM+aBvhOI-xGga1Utiw(Xot#&lu ze}#Y`b+T|$u)l;G$e3G3uij+waZ+cvwmVk?Ag<*SBIH%^Z+|HA9G$~&KKO&`wA8x! z`IlDQgx03$Q9?<6z=-v7^F-S#hOni~&fDo)RKMS0?ek9$;F`@wW!Bf1qkR{X4zW4f+fgiTXV?vxbL_nr&dW1`ZS^s+Z_AHQT21MS1Ksb-N&5L6)%WDqcOR{!bgAmo*V{a<540{hXZNxh z$!S_H@49`@^<_Fzob?Nw&Wg!TxXZBf8U}hnZm}4U&(En}5sZ$~oaPuO=kpZr?%bSZ z_V5tcc!t8Pzg^QyPoFQZueTK0tYF8!cb6B^Zr3)D&(Y8;pkKn$HO{4_Ad-lFD|~0n6UId1G!@BdcJatc0#w);<9TtfAd|?^jvO9o`pQ% zp81jY)FbcLw9Tg20NfjcuI{{3_)u0bV|=O!$e^#{K5Ln*k!5|_ZRDOjPLyBmP&oUp z!M6NFeP(7_eP*y|DH5i+A=*Iu)}w!DzjIU2rv=g_1d8+Mf36f&or_7;<%#5aY{Yk0 zGv**ZBp8Z?8*;qz?36FFdmqB5WHJR)oe~_jMLCff-O3(^jDJIY6~#O#%Hni%nyh{x zAgtn0y~pVF>X7^Pdn2(rwZOyu2ET%=F4D9dLZfvjQQ3P&l3k>C^gcFg8&<}Y+dtW4 zj)?kr8mk*I7WC4USSk+GRfDubH;?hxt#b*;5_7s&Co|Anz}u(<4{p|F?1NnOCipP!SbFKM@^4}Xa^_C6C&*=k$A`PSuf>dqG7@7WW? zA5xU)1btA&>Pz+_gl|= z^g>7a!2INBK9FAE7NdP2>_z!4Z@@r`?lTL+Z^f(A7E~E~Z_B5}9o;SqXnH-QdN3|XZxFJf{&ULtT0S*DI zVZQ6ni4;cGK6@IV%l>8$y5>E|gtB97oZ*`v@^=DKO_YOg2|Ca)_!1~gwPLH_K{=SL z==QG%D#?1g3O3#ZIv{X`V^Y8z`!cVk9b)5GmhJL$a#EnoGdW_6fsA;L*MxBT)AXLgT$g+WITU6u6%(IMRB-YnB_ zS+@S9BbwqZE~Z0w($}ybMrQ>1+w#2G>hURmLu)F+xCh6&f6DS_7=`J|sN^W_t*|JW zH&XMj0GYEt++wyMVBq@pkkjO`T+)3(qV(xM6IM43Zj^nnIHSB5y#TipC44D8J@Fq2 z`K|-YsFv7WbGnEz!DI72q0#@!$VUpFg?#%AsFj@H+)&PUS|wO2`@B|1)@7XO7!&X( zEA$S{=HCFcVZ-Mvd8q%pll2GFa*N6ezj#3QDJF#dNhsllReF~KMpiWVT*;lwev04+ z(CUc>wql8~TFc^vDI^WiN#;=b8+T9bQF9@Ur;@>=VLvk$)DB_|6err)AR}N;blL<$$;Is zg;O0W)0co@zKF-wqnrt$&n?Om&-!a?gMKvU327*vJ?UW{@9~z)N^$V2PI?$gFrlcm zK_?)7Xd2;o%jaX+@i)ppokTBh{Ltpm7?3UX#=H_&kYH+lHSIi0B!7Feh2K-UcQ4(o ztYPs zi2~mdIT*G7+@c#b<$P9c=LTeK_ZWE?n;=CK@G_2xVb0Sc zSNLm@C1$+(_&>R((Xa{P16q>>cJxXK!9N#mD}n@Vi9xXym52 zX~A9zw*TE51D7>Vb((wmLq^?#MFMgnpD(lrTY*(sk%R*tV9-GRpHRBfl;n@CA}_7p zmRzX)WFRu$S=D1|ejL&Hz;<=zRu6lq#9^?N&UfS0=PmW*J~9Vn16y*0pZ@B6A_O&w zt~`+cI{bO~(d?%J(Ugvf7hay9QeqX4?$FkdqU9Cu)6f7e|4{YUhJ$xXh$21MbEcvL zdlcfc*4-4`0>Do+?kdZ|vpnHN8{4EsBRn^Nh4xWMio&=%B=<1!4+*u$NIhdz`6=mk z{Ib|?3<844x4Ukp->2j)YZ8uU1=&|crj_sg7sKDUA}s+(C^C5uR#tAZB|!HB$WZ zqZw_o1?GgVNT!ZLLzc*nmG>l?lBvO$w?PR}zkHGKkNbWe4-BH5)w5!MD!!AU;1bcj(=4bLCD@#y;j??f{d0qomNG9yCND!` zIVGm8l-HX?YEAHBppN3!g=&m;+8woGgM-hHEAzf#bZ3`9LR`jg!xU%Kob29%?vTg& zAIq72u?5)bP?WyQyt9C?0^AYsKxit_KK+i3m9|Y(On>|$`{`fK|0u!+I=GcoV-J4V zd{GbFI0`ZqA(WB(>%@0o)Ln*nt()Z;V*s}u2m6!sLknRl%2*Cd#p9u7b^ASG>vYqn zzt(sujY59d$d9mwq&%JZmbUxg=Ii6VlwvBbr{?Oc*|;={XY`jWB-ZyrXLIML)*{w~ z895$@x)w_ih@B*V0`pEs-FixN05E8NwlcrfcMmGu5K?Y?hvdH-;If{M?4OfihVdtn zzbd>&t3%B7NEe3^UlNDW@Ka4hZoMh&gs)jLV^voMXGRWq6qk-`Lm!W$qFkucHweU5 z)LMjIo;AJuy&REBk3(Q*y_&R^{J@7>SSDI~n7CC^B3tCg@7=s6CY&qSFP&F!CB zDG(JnWj1@Q9DbD8d)zoEdE`DUc{Dqcj@pA+kQG7AoVyVT4q4ZUo0oKaca z;#GXjGf&Lw<*v4hc$Hl$jXo_|8&6i(UY#Dd)-LW%psCbxD6QbUtpJ>YXn)=dz8{Ut zS5Wh|LAZ7(KjFQm`gF!1qi>!!V$5rhSq{_7JA95>DlyUXH(&ZMac8#@SUkHgFm~(u z)m}*w@NEF@uOd2M=g3OAerK#h?{|TY*s^m}hRUVFK5f z-~PV8_qih#t82$O={Fkd|J9?=dVq5MEnEcmw}(3newIm+M|Az>%LAp+6O*!y0mMsq zaN0IqB|55OY(+miTFUjpkAUX-9rJg);pH*%*=-_uSe&r+cyp;@ah>k+sc|J?Vn-@? zqS3_u`n?u?b?SzmS2dn0-Y_}TJ&Zsih_xSq`fcXIR5V){Di4v3(e9ciGPfw zY+KNN{J7qpd0FOv;}0JZib<>d-1FMhS(OSGZYO~(9q`CyUvg~S`^U^DrHbPgY`}>m zoSH{-q$Rt&aC>;o-Hb{t_#eOlJsyBFbu{bpb(7X}pRBxk4Pj|tn^5JO*W+vSBw#<= zt@12(m6nZrq(;Xd55_cfwEwxn4TxgEFcJ#u`%rR!T+){vUB`f1!xU=?|AU6e1`Lm| z=r#5wfPKqUF;!ZJ75?}aShL1xuU=)A#eV1=qH9j58B z@0AymEdzaYJ!~$1WwE{>Qy214<*)`94m56#D<)eW@=w0D2ZUlB5iZ7S=dTUfQGOl_ zs9gxh!)walnRv>%&^{^l5Rb?!8#s39HP|1T==?E3eusLv;&S_;Dz=_955wq@t9TM3;;bhCTW{0H>;68TIzK9apFH?hEw8UA0z;~i+#BZe2dtz-7fk5m$MWc zB-hkroFrg4?0ZhfK=!t%GOdH(_}MJ^yNK(t9JV;J-Bxhtv4Ofucu@bp4AvD& zkU3xI%j^L0BdJP=Jm=PHJ)R6o&3%}ayubO_y?7gDvUAPWPa`DrCu>hub@;9a z*sSr)4{y!Y=8W*5_Quv0?Xnf*ukG{cwS2&EPacn1YpbLEN15ybk0>AEO91YOv%l2! zA805Z)WEUt1IpUqd$wI!{%aFzX^r6jQOn_-K7ffhQH{K(8NX}_O8ZS&bI|@1j|wkd z(q@*f!0I|SQn2*+s092E@!b_-nUkJorpt4Dq1YE;tGRnUk`s$JLFw9AHdS-qdY%}l zQMe>4O5e!`t4wu0euIqyFG!hF*ETd$6TF(aF49`y^`I8t5yXF9eaHKnepvLa#BFZ) zz9(t)pCRPvKeAW3S3{-4KO&B2HDaXPPgJS?1q2%b9*<+vUAD|yT6@;jY`K93X93ghk`C|o?HW~4c$xrk6 zM4T_T3M7!xdhY3Wu#?Th^!S?W+X!B8)%}5a!J0np(4Yb^(r?{~@t>c3L*mCGF=!FB zzNGulv>w0tUtHq0*mt03$i06q{TCkxepcFcBtex; zuBBFolm!1W$?;P{G5WBJEq-72Nl%8j59GqGbTa?r9&d9EpY)N0^cT#JccAv!PartN z5$V6M`>hCA`}iE!PaH*3eaS>JV_}j%+$jB;;hOXlJzlnmq%WbfOBMu{cW2Ss`LMIt zA^v}ZJ9z6weAxVm0=WK)10TWd&D;q-|8GiscD$RXVJ4+eTBY$MEb}X<)OV5a|5zo$ zv-)y~8YZxn-jh_PM*9CN~7Ly z2b>f$Eq#P^9&X4W*i*CAMJuaSJF7qu8CdM#LviUUQ1Z6abKIT>z<88?r7=X^X6yBp z9Iw!L6O{Zi8x~|i#%ZsHItQ^#=7Sbv#R|1adc zJ8zZV?Yh7wx-t9sv2WxGE;tGqkUI=J3XP317D}|(W~NJ}=>_=-x|GuanL_``M~{~; z7WKwA3*+r;HuCIcCSJ$-IiUEAx2i?L+tquAa%rpc-_k7CYBhL%6%;t!@~U}uolzKw z@sz5YrJThnRciA|XVoj|VMo0nkX{ZbLRG&}*wnus6AChTQXrTsZCt+Hw!=+5E%_$9F@F2%DBN`hZnB! zIofAQyJ&Tb>B08T*}4qulxkj8F>CVOEXDH9PgU|((}f|m5Z0^x|alm2LSP+BIYku2RdIF*O+VbZB55XOTXv)e#PI7B?7`0iHNyV z%^pXCJr!oF#fXKEYJA+q-VqrM*aeep?l~z&vCHDkrSO}C6yv;N6l~1bEAA&_hR<Fggcu#nHDOrO{>0O}K_$YEf4Q)FXobhO?o% zgHA)S@phA|7Q;($wo|;;Kn;l@9=nUrO;}A ztM;W%jbMgoA;3gkB=|O@k|apGMU*UhLd6h(Q8Q>ArKp`&12;!SMNM3n-Aj~st-tfx zvK6f-zIYY3W+BHk;IUlSZSAXQYdbC~`&GgcIep`E*DJ`%;ShF8w&;-qbsDeLmw;s} zY~q1nUj{2^=`nq$wY0krcD^qamR6TIm5R`W1$D+H15N|1^@JuS3rg_EVK;8{O3L1I zgDqDPXIoiD__J<6UrlGddb52@SW_5ioZsQNlgXo=?E$-^J?U)ZGV%r+kK~- zve7z}wNP>0!k zrpaI>GwDV?8qq1GjyQpFPR)@do1#egTCd~1V5XSfbvk4deikm}@t0TG)cjZ^h{4O! zEAwR^*xApxGQ-qe7N zrunEfO7w!^PW1@oC z`LsTL=M2@lmGX_0qLuZ@fkmcKSDQ{&P^5C*0AQCJ>HHwLym&xl1lXblHS?tK1Ozjm zzg39JeZMsPMi-!EAQ-d!M=fPB-y5J`?Z~~d6Ej#*SHBQ+aGDA`c!JZ zU#(qh5D(>t1HuG(GtJ zw5V|VV;@Q6_ZmHQqX<0Vu3Y zrI~XSLk#qhXU5EjbUraWI-c)ieDTv;AMojmc^Px^}eg9VHGvH-D5g&uxZouEnVYiWrd2#)D&mQ&fmfxr9u^VW7k|m; zgERHd_Bi2Uw>STQ&j>#N=d#n2doIn|Eam7euXHaXhaG`#i5H;%>RExxD!8};2kLeE zCiN>;%vqI2iQ;~dCf`*B|8Qc#b)VFL{-jyWs3C4EIH!Pd`w;cf$@8T=URus6|) zuy+fWkXy0zCIK0Rq>m;l%h$9P*`opZ2(#kJC;9Sguq?DneEYTi$@(k_;7KYR*Sms-g@j40Fqr-Y9e=92me3^p|Va zb2m0&b`|yXE)}pX2C}PpzH&_|Q5PinN=uE^xqRq4a0G}Z+Z8n$sr#N@!XHzhitAx3 zW*-J;vnCy~cf8!xp~k|atu?#x)O3*bolE#$UGqfesC@|x*j!Z=3l0X5W{AHgK{mUrCSt5*YSHIAvQsb$EF25-2zSYjT7KevwDHTf{Ze z6o#I=>prUk9{6rDkaT{U=pNHlvw-DE)FhR)JAqO)=2orP_R#?_J15*4S_*}h^MN-- zOuJ__4RlRjvt3PgwNEE{wYf|$!sX?EU~ISOFv0;Zgob{o(DbV71AC}+W9CpJ?T0_y zGqLh6=hIu;X<}qO9=!~;)N{s@qCjV6#4X*>LvJJPz-2)8v2F+CKu-whNbD^P%)Simvsx=>rrN^nAq?xO2 z#&=~Qn?G^&J0O@roB8*rtR`}54=cM{K9od>%0=> z#-(gPRSdq^D@bb95FZnmM5YZtE$(9>3{N)T97pRl=DWZy_B~kO-uvWBk49QPW1^=t z=LV9{SQuVyzL+h2^}N?#^khw(@+;1B3Zz#Sk3m40GK-x5pnfI>y6xis{OlnK81mS6 zos;R7N6h6fIdbVDYe%XlyI~~79*Xnf!ishUmSg!L`+uj@(tm#OSQR)w5BBFe>%Lsf zgfmXPF{4ffrxpk{OL@LlkeSM*j%<(QMeay%+$ef}T|g*}ZfOk!u5Q~+we3}a$}h_t zp&N=_ZDqNPQi|DP&pyf6<%IX;Fzb}j+i=rkzR_h9q5$i zq|8*6``DXMw22P!#KSWCs;9?oJV$~1F{XxIpqZLUe-pRy<%$kLIjVJsR=`~P#v;}* zU(3{;w!(@gmFeEq7WtEJT34#R|U@ z({cF0eUv~%@@Wc@`meh2og>f60lO0ft<$8_gZYn#^(ryqDbrK|xCX2ma7c9L6^8js zC#ak7W&TyfztVg_5)k=IHhcPqz@#(`JyaX2aPyuBrzds`!LE%ChncaW&V~Y&yV6(+ zW{k3{nz!3jnC9Cyq&S>@Q*Ai3;*)hcR4Qe|ikiq?$mBIb49E$ngw_F5<*YQYzBhsS z%xXyjYFdQ_=geDKl3+%*M$pWZCn#m?0PM`lrdHiYB@{M5h@ znwK4RLoGTSEut{wCpBi)y7mj4p@cmF=IqE${pRa>fyC_5MDN;&jl-fdd-Bg ze0ENRKc-=+W&0$Nv6I$PA@q5sFgN4OZa3XQI>C%0JrvvCHXFY{Q)P zq!=#5h4boF**{G-$l z(=He7we&{sQM3pbMUAZ9^7PaAjg3Z@3YhMVaMtv*n z*o~hn8Ju*stT~=1$n8 z0e18y4Gaj1#Oqy^Fgb6ZngnoTf8XBmNLvREKYdBfX7Y7L(+o2{GJG+l8)u&++rTNSsWCN-<#O=_*?1KybV$ zH^Ozt0BeTZB0d`X*jj(B9UrLs?YTU~-sriF#EY~3I$}tn-NfK%qw3cQAB>Kp*cKqo zsu8{$H4a1^n!KRDI|Pq76W8C))_Y;HiTW)tf&7KH9eL$s92Cw_Iwadgt+;>HwS7|& z{#=IK_n<~n)n(P)jkLCO?>~Jp*UU@-h?T$p)~B5_OdpiJReHI8ygCg1Y86`82)|g4 zY0K{4if;pCXz69TXB^iLY&t}b- zTD6$U9x|6Sc@J_aBQfkUu*Wo>qIV}rox&?oTW`DBUD>PdPD}EXw2u3h!CmbitrMv+ zf!#J2?_YbX6we1tzR|Cho1$X{HQx;<%{jSRc-ZuAXXZq}|IR&8zPl}G!Z|OiOCI(u z^d{_5(9^Rk@ApsOk?(HZ?1!D8=)$O&HqXB5it&2)Id74o#7#(dYdX)Sjx1zLtk3Vc zM)g(FxKZ+n6g<|E;gYe;V{9d+?-yy$P4bzyii`fT^OZkj#m=v=rnJ?6K9WtvclSVR zDE&y)qbJ+cd%m8ubdxrGbs?pFstjE(w1v!JZV`W`jN=`;?w;)Bo0Edo?KW-~xep2I zxIQ6F;>tJI~j}`Ia_p?IQCp#6dae6u<@bIm+Lp2XHlnKcbI0LQzE@y!)H002uwC%X0u4t z8Ez+Gn^OMpnYIcYqqyfflkBdhFJ$vago5hKj>kw=dAi=&mdCvJ7Gg0b|4(C-I$bmh z-ca3bT4V0sSV6h5^B3g{I2?_<(kMgYeGVCN2#(sucB{i#yUa>V*T^~`pGwd*`{W9i z&bO2(n)|dWa;cjL)+=Vt$tnYsM!V?R9bJk&PF!rX3w1!d)l4j~ zl=t1)E5wJZ>SAY-#3K3Kb>8P^zQ_vrpCOmb6aTuPwi7%zzf1PQm1 zUR(7>T(Yc@RB-`YrjUd!-MHz30-v&{S8#4UM}%VIbvVB9)@6aR8l~F`EuMcO?|#`> zROya7ucz5DW5En#L9{B=F0j^%k0A!S1_Y6JnHpbfEj{J%=&pA z#?(td7muoH;xaIhMX~)OGF5UPrrs>Q_YH$h3fnp)66R_@d{7rNi}{7SOb{z-#{)9` zAK(B!46?M3UUI2a#Tnaw4Mjb%a!LJwI}cls8g5E`s`6icPuoIr(?OM~x7O(&X8NMw zr9p8LFd;G;dtPtz^eOF&E5?>0c}T%U#T$Bs(>3=CQtfidp_E#XE zjQ{EeR4wP$Dx^evNGGaMmsO=0ZG|@V_n0LQ$m*G$7TbIW#v_l}Rd*Yaenl&-tAmB# zA9Cu?RLPLHFOHTn`$@5L&fw2juE1jXFVbX?V_1)_bdJ)7Kej5YXP{0L@v4NuN&*4> zk!}XbZk!3xfd3g*TiWBD;16aWqo+i;fsG378@${Qb|;ig3B>cKB$_ z>dOu?0c@|$X-agW+3(cq-rEXATS22lCn5*EkRnOe9<$~u>+z!ahBK>+Qh^MMMfmAc z+hJ{gg#_N`5ls%%0`@_?@X3lSV zbp$3aE&j5?&L5$^tyROPZ+t5nUw3|s9ZDqrSe!A%FTvH?zz->@M!$xNcLUJpT|uYA1+;J0IP4U=Daxf)#8eP`4)s|j zSNeslo)DNEWFx7WNu-mhc?w(boX?*hkq-OX>q-qgrZBi5mhP_d?ds+%?p z&FwtV57Pj-GS&BVb$4uOB$+Vd7CRQ5vbQmSSA@P7(ALop`)j(5zjlKEaq0ua~aip z#ozhjIlk!WFJJB^($$@HL^(^ReVC5o+&6uUJhyv4D@Q;4uv%G2v7>J7boFI~^E;0| z=T>*M&ibLCJHb_aG^wCSZ&R&9Ju~OVng^j*C-$S#S?c%#!5=$T`;^?T!w1r8H(N}#kJ>`jHlO@wI2DUAY;>LzGE;5we3&bfTUt`4 z$3`Qni?D*SIISug8%U}Z;4wd4>^lYw%O#r@frV>V!&^L(>VH-HLZ%$LsOsmXRL*Ip zWUh>_Q=f9K*0TG?;*-Q}z_+=a!Ygk1AL1$0kA?kfJUzs@3rdxo zCfh;xdu7mL>5ejhI)UsZ)XJs;z-geb)!)lPy-r>jmeetnA+9gvq+F@m97$* zt;EDX0$^c7eX3`%iHtHT=cXKIbnuNLYgE_`0_vS!0vx zvI{WKqNAdEnAIkd`GVo*W`=tm@73vqfKpka4o|rlu)NaI!3yFu-19I|ce1cM1q6Mh zYkL=$A35d-Q~?Z8_gf8B-RHCkSne*HQ0`W$N_1sTcdH;7NSeU;4U(nNvR5nEC>9JQB~xYdC_{91a2P(r2k4SHuE>J5i*Oa7>EQTIsKTclBAeo#W2oy_q>gCFn1 zE4uqijQK8`w`rJAgNH6P$d0g(&NycvFVG0!lvJl&Qx2#_7`Ap3HVq9t+kg2x80YC| z4oyt8ElBM@OXmiqdDIt2cBfq)Hp95(zt;GK1kvhBwrvr#k@JA`dKRi0KvkO4^>_S+85bJE|| zMO>^3PPC^2PXX7jNrXWn^tq6w7L*7nD@wP5sg{s27?-;+$1MCZ~0TDLu>( z83YieVw}2xa_nW6x!5yMkRtwP0iw|(w4^BJ_!!fp$KNbLm$PH#nmN$Sy1cj z@4scEjL^0jyvt0Rob+5FjU%5gUew*8Ai)|sRU%9lU1xV%tp?Rou}`R*=&yS7S}iK7 zKC7izS5I#sA*J0K99dwM0DQOYgy)ygc4v;AGXBlWQQG^8X^AI`d&)o;py5)#5I3xR zYstAe-Z%w$pA3Rqcm3SWs?R$@xM_R?QQ(vi0LS{M}WwtJc#4Kws>bKyBN z4-;P~VIqdXaoe|pC&2i2l0LvB`-kjB4!*g&?&ZIWl`T#Jax@>;tIGnJ9ILwSy`FVoMK|`i0-&I%eN3tX&add7Q$Y%2X40`UZQ`PYXL6a89%7Qe6`wFg5AS-9#`n zdy96lr8Wv&$5%`G2r9tkJ4BSc?TD`%Fdo4D%6gdK6w>qFkIXa5M77QieZ*&ISuJtL z$*)+BtSu|C+P-MoL#E~avnM4IM#C4zt$2zayxVkp(IqPt_DRGhIZqySp(l?jht6Oo zE|s8~?(QVyM;usH)?`Q;hdLUXR-YGk{REjW za-2slMPN;ICAAO&@y*$)BhgIQ;b`_E+eO2w%X3$kUUy@tPc3A&$T2UUH+|Gc8-eI< zNi&V`OuaU&=3d}CC#k~U z+#ga{sV5zPfIHLy7cf@pKz(LOyUHw31*~sIP@A%f&dPc?793q5duR8fc_L7%gB?TJ zCzYgJm|S6uedcdGBlh%9{ePkxW|ty;&ChL>ZF;tSo0H?+p-Un~not)~uuvjcELkXv z2Xr&ac~p4Rsldbt+U~vkUgT@*(UwBXSK`2n%fUJ{=jqP*51oQBg%u^B#4W zP*TKNw02mf@uD1H)~j1RLOXn8WLb8R8L0|lW(dW^R0C3qyboJe)_!`tzG%^bvORGy(*x%ASj>i_6Mm8GSAi(tf7#*BlHVdCjG|^d3sh5o zuIkvB${f~(i^k#=jt{7PQBk9`@_TUr#{JN zp-kljKok($vJ+W7obf+DW?NT1xD)7tKe7|I-fAa0)7Y;IFCEZs=Vk?93 zDfZ1Px)X=cwT~~-zowcNV(%HJ2emN z0K)E2{{yLVlqsyigitRm*Z`c*zr;dTDe?cCgUI&=jo>Si{t6k-w+$v8idyy73MUnk zVkqmLyET_^yGRiJg1}M#bZcc@O*MRq^tO|WOS-h@W|Nr`&X5sIa5_>YbW>5Wcb!#~ zsysU3z=9I;mX8Q;4Br|o{0nY+>7@zNGT#abP@j|kmTMD1E%G-b-^%nGkv&pQUk7|j z)#sgem#kN@-~7D)NKlgckvW@AMP>DYsJP7~Crif;)d;!A656-!RC2a-YHe+MXehg2 zfk=7ek-|4gc88gJBi}0Cw)|4YRrZ7*elII4YolqZt`cIwaMHmVI=0rRs~lE2Yr7-$ zf7+-bv3Cof6u;Q|Xo#ThAH-1)OIuR`J09Y_~WcXDYZS;y z2>RHY_gSSvjN+}POtqQOoaV%8k# z$BJPg+Ia}CREy`8rXGgF+&t^?_mI$Lf9}xn@o^>sdov3M#oU7ZhGJsDRo3>4&c9Xg zr`YKEG>6{7@Rrx&rqqaWTOD0?yj5Q*JV^9j=AY-4G(?=?eYEh+2XxMWmS}Oy$EBv@ zLueNA@s90`1|y|pB4432VQ{&MZjeO0MX2OSvs?VTbLlS%U80*nkFCQXta#HDk35|u z1lGjwQ?VnP?dV+Qx1Tm%{w^qxa`PFTwn^sEXNR&LP&^nG(n*q_ik`}J#EX`6pzG~! z_uG!zvz{fsp7`Bee)WCVIWhMA=$fF;Nvo&~#Y6*lcI4J2SeRiX+8>)Oh{QiHrc4!1 zNJUX`#8z?V3_4hhG=DyjOMn}HdIjs7q%qvtSo$!H zz@zN-f>Lnx%559;)Zf=yFW4{xP;UX9r>(nLt(M zg?Z}wnuz-et$q@M>TUtPb?<8QCrV$sqBOB?R5sV!#YWcyJymL;Tl;2edIz|Nph_{B znl@oU>s6E_7M!;4#p1FrOG?s&J1NdJQ-=ulY^phrc+fr!spJoXnUa-la|^U}j$who z)YN;@Ne3U>Xhdysk8<_TgMF#8(RyaP_I+?x|yfMi|pGlqrmSZ=aax8$#kZqCY5TC7Sna3oRD*8CkRIy>loyN);3bvFAc?0zmNPuMXt~>{lBdopbHJHu?b#x^KN0yH( z+v>d&4yuHO@cKASFoBtRe5XSnzQ?S_MziWYle1~6f^u!yjdI)_ z^#b+k$L(58r%H$G)QU%X5VG-O74fYpa&+_qDpJ$RM@8a<7tqyl&72 z%029EuwGeyw+-?CXu8JeIJ;;a+jbf?jcvP8(_muTwrw`Hn`Gj~PLswqC$??e`R-kJ zt(jl5=FC1@@7~XT&Y4#5R(;GkH>u7A^S{b@4?96?T!`4%i%pPKp~#r?N-NPN2j&jv z`j)AWG$o)sNW`AntC-`j`<{+I_!;~(@0#${Hl6b}MObr-Vn4O0-yW+uXEFKs$p=G> zjG`u?r&wE3JEl`RMbq4l-)%5k{Oj$>+AOL>N1@_5V696X2pk&beUyLceB-itVJBw% zbY#;l*eFlo9SJfvR#hpY_>!H->FgTA(P3RrKGkn$wW|5e?bpS{$MP>?7Svh(SAi4e zahP0FA(wvp@>;8;ySj*A7hkZCbqN{hTfO zf31p5r8sE*8J73kR31GW&%S)=DRi=$n4ZXM0H!sHC^k>Ub2xV=E+zf8$^UitC&Cyj zz2s*rxGq7LBig-vT_R209?q%mAwbf&G>i3;o|Wq40z9Zuw%-X8ev)IWq+6~5a}2`tlp;KM7< zu%Krdzxn77+MpME3=3pSjk7!7bcdujwQH&HPYq~pmo!xc*o_GnzkLq)maw(!sCea# z)sK1`+5w}1C!$|4TBS3WMpl|`^`_o`b)UeT-xmtf9>5p>vDVKtxs#WDlr@%U7DkJ! zS|E>b?A!|Lb^v2$@+w++V>5=;WF$Kb_nt|v7qt%IK;Z2IeCFB3-R4cN=7ESeScPgM zZ(3n&9iFjC{s2Co8Y)@vvo6(CKgBg8ValqV?O=?RkJWpIj5$7e=_1 zy_~g&p4YNWR<9TXrLsgU*FWlA#N2)v(yN!WE$3+TP=hG~gHO#t1jPmEaP7y9ufWa* zb=heG(!-z__xhX9(Ro$*^u@c=pgGOz8&SQyZzIUr5N}1`K%mWsEw9SLca3cmoAnsr zHx)QOxu+pKB*xwL>XwH9Bionuv9~<38sKAx>FK&Ml@V2#T5I2|yz-`wO=ah9$+cf& zz$j0le*a?^=ZZfugGsku=1>#29?d7ku~fo8D!OBjjaKRK@p|W+esFYQe#Jf%Uxqk# z3A(BG!MO>`{Oo~yX#R!s4NhII3T4#J>u`CRyVl@nNfjxUxylTC4g}JTdAD11e{EW7JdjD>*P;y9CLTjae)VB9S%Q-<|C1UOIxt_Y0a{!8TEjAcB-=|vaiAT zRrc%`_YkInZWi-WpNJc126K({??`i|@Oui$XnS`2vp4Ph497AzgW9e#3_ZkUC}Uk? z!@5+*bh63FdpU!I$8%x6$_Guw@k0Jy(<&i zOeNNGgIN|VUB@?8oXdZa36hZrcGpPttCgb!x##*uKV(%BWTIVMt=K;~sH>Y2OlTgYY)EL=IT9 zx%0={nn3tbO1x5pYjFYXcu;B3GPa~5)LnGc^rpio(rs=^)_VfF{@Xk%gOb|z`LMsN znWw&2p?->&;&f)sLE8z4GpxHlP>ZhZYr)+CDQ8pC$2qcqe!%&CFc9eJAp0MIZO$@c zi*E88A?u9;)RIYUtK6?s>*SIlL6w|(c7FEDg%tOe?^*d}{UXV(bI>-s>b3M81TIN( zV<$Y%{GJ0B#aZqaH;F#pVQq?1Xz%a|O7244er` z@aQ$bPWG+KjCO+YcvF#8W}+fb%My@gX??(zQAof@l*}%iCuULg2-nV#HZQl~J#k;+ zi(dc+tSjHT*zcdRUV`j;?aZ=EKJ1v4Ezv)%G`OC5uNwJWOre4}sQr|v58whZ*!t1qu0snGNV~P5whI)yNVrnRm`?rG1gRpFm z`hnYT0cs&itHKiV`~{OJwil^#>pTl{;s_w{kvr22LX+RzakYvoCcNR3akjNtdqo6& zERu%9{JO|p_H**Vhey6$Y8LvJHT4uz$gf8cUQIAFqx3jc2 zXJk>iu^LKV;a?n99OTMHx6s;JdBD;al=yF;%B>R?Opjl7=Q8rzQZ{7&lCw?Tgat|! z$o$?X~gioB3iVKc1%o;s-AF&d+lzHAF465youxWfmi5p+rr}x1)|{zxl@aNX`poa* zNJwq~-h4a?F6i+4h~tSP$g8Bf0)Ekp{#?PyRdy2V#WWxtvU64Iy(WD`y>~NmohMZ8 zg;j=;RKpR&fsrwDf=pGTsgNrJHb^{FCvN~NPxvm$7rsNSw0GpaGWrGND+!Ap`CoJ$ zZunfZ_4wc&d2@^Xb)vix+=A^L3xfHJ(Dl#=kx^s=vjVR`rV3PQ8;~e`c($!af$D*( zanXC$TLPNNP@~9)nCU>BI z_gR@FC4lb;_-?Vrg-bgBz>892O+>~AKi%-ydT!viR$)Y3n0 z0nLvK)hD&NH;vh#$GJ@fJq{Ua(ovgs^11=qzI1b->QNMr)Q_xJMR-X*H<3_&nQ=$a zzLJU}Y19=We+cFHgZC(N!1uvrNPLnM$wvL)8{QwEnCG+mns%!#(0o^8aHJ}XS64nM zMv@1V1GgC^L<>U+`14cn8@kl@;rrgY5n{9oMN4tU)JIXqlz(saf(lR&{)zo6bjsz# z3Nju1!~GlxV{CzOksp)&m#?^#289=G-qLLOT_xb}99ZtHb0{px;_2Sx4ltbN zc`}Y|;VRi!Sc7}TkkU(=4u z{RJ!O*LSlt2!lS9=NIZLIn0fpqZY(+H6Cs?(<&6%Oa~3*l5Ut+XofK&>P%y(jT{HA z26XwijIJtDJgT%~3Oh!C$x8LgbllsO)Z*r@u?xLXjV<@qKAJ+X-O9=r0wh@?LDuv)?8WWf=%xr#SqXd z{u-{Zb0hB`+C2#bSN~}W^iTn)*<6iR-&h_KW^#i#Z%v)zL~;}0UtcGL84shc&yVjX z&RT3D?6qyhg&9+J${Gg9zByYom`c&SgAy0mBd)|(LgR_G0iyS9U?1sTU}(t0LKqOQ zX#pEr1~4_?OZol>Si?2_4sp%r@7?q(AN#96BHxi!~C_j2clqUG+b#3YmG>DTI zvWTNg7+UywYPYWu)-AJziNdJWSNcEm9 z`?5{?l{h zx@tW%hkuitnTvitQyc)qJt8pTIx_>w2YP-kRX}QSB&=qK4zMzAOU_I0q02U3Mz!iG zP=txQ$=jMfAE1qy-*Fu$XV)UcA+)RaXxRW{ay3oMR+!T5f){57;US)VKxv8 zJgG?L^mA$IW`rpxk3j*@K*+33>@E_?`a}k(o-3=GRj5DaX)FKj z&(V4wZVz2dgShVbP#l2?Ib`4~Fgqt4d^k2&XQTVQ;}Y2y<+*vP$36bxzH_X)O|7zN zc(Q42so`JEQ&O>%sm*W%>qrE5#J*dr(YuM9BM|kIyoU%cBPx@`wWe>1=vAs&x%P?h zc~=!R!n6g&ncJ|)^RLEG3x7f;$=XXQ1LmFi7JYDXvVG^5^eoG7d2#}gzOa`u&$bX< zRVh=?Z8DF9_72H}R57&SJ_li%kMH9@RUfw}LZ(c5UBD?vv9u3K_2mFA-&Mzj6)!H0 z6@2$1WoM-BDrbPWE{*$dJ$WO3{lfPC!W@Ub^M`NfP7aTrdP(o!x6JBI4i`}Fnmg(V zPNZ9h6aVo?^K?2C>Am$2-CImXr|Q`uKePURnm%~IJo-((?Xb{Lc2y)v&oNTgtVsCv z)EF3Gw+AnuyFwJ(O=*izr@t_fWo;`qWDLLU61WtG%w6bfw8DNniB@^bCk0|rt}P(I z(KX%klxBw0-*Msy>FoihC??^tdCn*^)6UXKTij*QyP49H8qS%Y)#_^yZ-wnXqhd8_fqI0I)IWTkZ>|8^c(~y?>vzgk5kgyUr|X675BBMhmK~e*BBOBL?;BIB zou~hd3ESsN8AC)H@zEE|d`Kx*qMl>wwLsM^=?PaOM+;O?6zR>VLKDVw-2{ObkQOXl zbgfa_@+R8#T7>VMa05N2+-U7eDr*Sqz>!_=uHuJEHSp(GZYkj&ZW{-BcXwVw8~oN+ zekGn~h)+k5&f81sEzO&|4k$m==z?j*@#MH-+lmlPqzwB#fQ?8Y&Z>{6za-++nfCYt zLx+;`N~fV6RQMt}p5tAC)_gRG%5(N~;WL$Y-E7kyLLG0X(PdmDT)!<13{ivtP<99E zrEmBi%EordnG_EeR5IDI(ViLk%z9bY8#C;3&5oZo ztP@x=w5wSL%xBuyfHV3`L2a@4^DS(_FU}sLOFmJs&J!np1*UV-4J6`LebW>_lOME1 zV9)V=13o)Q3Q~88YfEga1Grv!lvg8u@x_=U>3f0VE(xZVXjl2nerUlH(R~Wkro?kI za;{$383kb=VFgaIm9^UzWug)>Z*qLNdzN-~V zU)JBn&HPZ#AB~(J&K26n()2ps1vI+N4%TW>|B2O~W8?GRp{$Q~=a#*Jj7h4b0w@|2 zl%OA1N!bKB1!g~L6YP)CpIOZ_xc7pR0Ih28Oq9fsJuaHv#?FA%<^=;a#Xd=|=eQF+ zK$9Y-2I5)-v$pis7Z$iYn}UjLxo2IaFScpUQ$jyZL-Su9Glg*UV`X6UC{xMceWwGN zKWr-!*YFeHO|l9&o_R^!KrMuq43%V|D#9AFCG7b{dABaq=@~s0C#9w0_9hT}hwuUf z)Csi(`_AfHm|+R2xvNyf8dbb!=y)*$Wu{s%!X!#&_V`aUj=rLg*0`+zfQT}GxHU-N z#>;))?N({0;?6I49Yy!d!G^l^eRI-+EjbAcn`myMo9g_TmWs;{&hu<%~wqq)omko zPDzB+Fm2o1BPPDeTBAOZ7{VSo@W>o`if6^J)5Hpe0|qoDf1ilWawYi>(B~lcT!lI7 zZp3~LK|c6eri6d@y8xlJvJzQJB;3mxJgn*|F77W@8Z+yKN_aI8wP}H|{LHAivHevL z(|+MopoYG{={MDh-Rc9=^NbAea}piqE60~(Jx9eT8SPtxo=>;m(kt&QPnjZ1$`Qbk zdp=`V+Z1I*EJ5uJ+YkC^Aw%YSJgeV-D1MPP3`;PvlrD`z_{%$1AdvUwLn+dtLom*> z(A6}WR(^YqQZ8zy8hbPPbzKkgOP((Nxvsm{xd*y_(```g(_*1rODB2D^z-J+-pgkU z*;W@L`&YrEtb}Zq=alGYj|yWI!YmEQ(O^E~a4YcwnIEm}Rh=y4;x&w%l-b=Juq}j= zu=Si)RLg|x93)#?d{u((u9%2Wq6c|A?aOlU_hlJiR7d0&T+_Kf zl7`yz;n1NR?vw4vwHG7t8~Qw)_r9i-+9u$Ii{` z@uX9kaxpP}e+NH};iA>fM=fT&#ZUiC>1850TlYV_nYTmDj0u<41rKSY=K{|YMCX<#|=zDow&yMn?%`1h?3l#31@^dKoR?3Wm%c+3E=KjL=0mL+p z+XivW1FIZMvDV69r{9ZLM4xvV_w)PceUUIfQu?v+pT=sCbm59DuwgL(Qsp3 zqh?|Vobx4HZSs|ttO*2 zO`z2iGS{y#|H!5}A^Jl#ChlgD3xkTjUvv~tYan;|k-8@Qa>Ky8{Ul(a=T%I*fw$K4 z1~>Em?%+-yaMp8lDs21f?S`PR5-89-;4bo_(cu&xbUKwIHL$>4!1J%4RgdfR5J0-V z00D4JOYcs#!Ole=bzTB-CuaIc3ox2Qc z@aiYRW7fUl;=#+N?4#w&C?SSnW;tl!fm_6K0YpVv>9Bv-5A_cxHV7Gejj2@Uyz6dj z{y8m4?}Gk;<+|zG^zc#B7ahJ?3b;R{ypamN-XgLl@N05PXK`t?@EEJtN48!gh11|< z)3hyWo&-l#Yb2Eh@k>ekPl*o*wH!mulAJ}!~X{^ z1m(kv`qyeVemm#m!?@Ih+UQZUhk1_);;NfF5=li`2@h>ay;->j_nhxP?6$nI zbCtd(LpX3#S8k>wjX|IK)Si4GetTMvGnMH1dIMK5uq!MQe{urxqe3>u?I&q5j1&_@ zdu_pyS?PbF9#ZP-ZU;`S=w;kj)n6F%7AiH$PZxzHglr$_cDqnIR~ED#NB9b~Raq}* zxG}z9J^^H3ETa9(Tj@_1%q|126J}ZsW}hmm;?rQ zXq3Ay#t^8r@EsLQsCuZ?1O96lI{!rd7014q4BXEkMqDRqx9h*XX9;+^Uwq7YjIhgZ z-%}LmexAe(+j-v}L~q!=nEJ8yu$}%sw&;=f>@#6OZaDRD>zH7V{Gc&}qDn%%eD|-y zorhFl)tJ2rNVJ;EZSfZ>kOPIgO+oM71iHtA<3nVh8k9lZDbiJn_}yoH6eN{!doxd> zam|xrhT&;Lmv7_w&Dx@jP@qZtmU7Eg;>P>iFu!f2;9KDoC__Xf)he>E{aYKs);-*d zuS|WNV5CL5Y;X-et_i!N$;nIAD_kH?`b}H-_~6J>riJ} zDp*4>3R?Nq2VnQ{hMPxAD#}g= z;|Sl^`VW_^FDjQ?iuVhUs%5b2c~Mf}hX%b>(%&o9*ZjDuLejMz7EsS8i8uNEu{I(U z$s$=&)%SsMI)5(ucX;(g*AHFp7kUG{RwB!>Win3AqjrR5>YK^Zjt*(=wX5epaLl`? zDANi59O|B=#}qK^kW<~zjUUVkVl)_AGN4{bSIEv;?fBJ<5IHJ2GU=Ec8S%nxf2%it zcJ6W88L}ioXe{?7xwr_^s?JLj+c*-t$xXT*T?HyYhJ@ga|&v(al{@pkBHp+EdYE03=@b48@ znGe>=Rymlepi)h9gWNUKR<~XpyJDQ>I-$Tu#f*p*i2qkrfL*+cvTn(I0xfzEwa_2ejwez+Bcu$f^R)P9}$vG|N)xm7T zcxsNY%h^A!D1PJJNe@1c_NTq$|L#e5AkKGN*hbmwP?ATW|CWiL30Xxt!DEa@J9iX} z9WmGsnJ1U5bnYj?$EMha9&8^|#G{2g*%+6a8GGeD??>Es4AU@c=J1ohi1!@}bdz{m z)IN#(0?WPY0L+~3XXFCeO((Cxf>_k@9SL+7B)zmaLMpS$ZKIXfcDK-AT-O*ZwaU-k z$^{8c9Nn;?$Fc|+Ih8?sTNe#`IR=hS1OzrPpl*ACYnef*Tl|IFyMWzsEvERV2cnHY zVwzeQ^URq^-^Q_Gxx@kAMc81+=hnNF6dqV7u%TeS>>F*~a#b^Nd}9znXunLkY5VDu znDfUHv$qn3n=nfw0Pr3&l|G?-7=h!7xPh(4e02z+v~L??cVDYxCCHOW-hP=~>T6Gq zmq(SSAWxYpORJK3im?c_2{B2Xv6oXs^aY*Yjm=86?6_a9=R@ zF1*^u-1-XpFgEw5j*^2I9jjWR=(HM$CzXZkbaep&oW9Rw6`1`cEl+k{rM(x{hGI@U zstu|%Vffe7?9h|@M75h*pHUK&L$wnbI+yXiWR@-Qk;wXDsQgtYK`FaK^aDQQs91B# zrY{rHGbzQ9j`i;tpLTya*7swLyR}df#rj1=&r{iFh0yQ<>_&7`LdQHMJWaK@082dwTC;E>NeGV5&Xtp7<8hmQ*N}`Wzss7sEC3+kFb# z%ve~pZM})s3>Z+(iowNaTi%!AoN{8esj`4kf9K)9{)e=U3;LEkFX3L@k zVXH@jh%u_6%qsBl$^+L}e!`O05#scR=dm3K!Ed3Zo&O^zoanueGJP4St9~auMk#cLWhH6rqa##AOZ>vAkKltYF-UG<@_ojMn{sni$L86PK%nPKrakn>oT%!l7z_P@%Wo{=jnEz#(%#CQ zYnql+In-J#@AwG64-WBkBfd=Tz5sbn!(YBcKV5x>_mc1H&u0K8Y6ny#4h8v@XP6&% zM304vbM2P_=bSubQKknlp$tI*u;!tz1Y8SSI8i^9ajArJ2O7n-&UGNPWm$wHshSY&(h`DYORJ-%Dx3E-)~jsW%QdpqC3rE2E!t*jhXQ z?@S+ue?18&>ciFlMAObyd+PkXZ&neu&|b;xE_uLm&+%dIy;UF!sbMGt5|zmP9XgP? zhhV0h>Q@MgF`h1)*&}*1^8M{*fR2YMn80xj2E|ZAe{4~OW;<2@xI`^X{0?P)@lJa; zR|{co5cyQO6YPT++YhV4q@bCy{?@m-4>+Cekwa%Gzbtq$4O3mK9f0pBVnUVb!5$e8 z>wOinHx~ic(&7G*Zg5CPYJ=P=6OQqWMqsf$`)vxjfqQ!-^W28+%>FJ%_L3g)bn!mn zDL*faEwEHI8ZKu~xf&LrEt?83Yd=BzxSnq4U6nm!8#lz1$2hs_`3a_f|?KMf65NRv&{ zGe8YP-q@A%xuj_bf;cgJo8PH9XeWi=?|L8jl12sLx8X%&hVb(O=5UMJ4QffA+cwrPRkzn2T(4k+-)485s&_cF$Sufvj)1Yo)w0_pCX`$ z&+Pe+I-?seRGad!s0J#^^28`pFC6FF5QiZhj2a8i{)*QD`xatuq}XH28m%+oerzb~ z%Tt7E1=qB#{3kDgYnZc{EtcyKooqdbAreA z7$e*IR?T!ξZHTiogJDl32mR9){duBKZ9NM0%1NBvQY1PR=A&Hr|4xP|A<8Pm4uf@_=C-n5j{D?2xQyFldf~LkyYN&ol z^nvHMuE>tfGVkk%-uX)Gf70i-`#Hs0cx<8Q@sJ@-{jB|QOcU~gGZWjgzO0?AzX-ft z6*RQ7^n%mu5ID)(REXRONKF*|KNp}2)-vwO5&A%k7Q^oHr5hokdeb^#=C38L2B8S% z`G#GoJton&zKxH1oo|I!qoy4Q(hf#E(1*~6RL+W&sa`lwxT6lZ>hqEeHn)6AulPz# zxMDw`yAe7G9Fh|luK1SRYLB&>#G&h=0%EVc-h8g{5@UiyI1L$ZF{k>7E}0KpUW41h z7}0`KwjcVkR0mnm>y;CQW{t`deAMREgT09sLnfgDCE0}tlRhCfkQE52`qA*jG+I=O z6{b;_>$ON8KI|HsqEzdSnHl>+H-IYDaeCD0z{x2-Q{6-A^c@@xPS!#(&*Y z0^6*%cQY_G`l1|l5N)3#-r0g-jx~2~` zpKCK{*oCze7f2Oo$hcx5vSNGQPm@F7np&vFbb$TDRk^nAk$Ti!(j)K;();HNhBZ>n zH()seXCm_G@Q;SZ+r z(XS|L|4Ay6H+S%n@VYq-it#NtHW*FNHBg17gIfOzYX@IgsZ}8ie%*;-r)1Md@kJbt zRc3=Z!<0_7^vRG`-z@*x^tOIvm{Ks;#Gs**q!TLbLVre1Fg5@iHi~^}2X$P0+$4=m zYL4>GcU#aSbj2rE4#^cn6wDAQk;`z`aCR{P^fs$VL|*@`yibPN4%uVeY!a;d?;8St znVmSYTi*imy8hYtiX4zaYBk`mTd3!h_(LjHltpJt)K9>BYEPro30q3JyZ5Z|@m}9xa0^KoT3e;*U_I@MO z*YuTc%M<+tpxU}{allGP#)mnFiLs6Pc^g%bj0xy+b2RQ93FqglOj44FH5>hzkL++v$CILFjkrggoW==MbJ z{!n17Gdh+LWsn64p4+#XC&<&84pCPf5Q21P-h8pA$uIZ{kp z)qzA;9GQ}7=K;p9Mqpty322V2(KkMqUUmz@qsJ>I)@}M{69O|> z7dZ+)NbceWe3`Gd9e{!;wl{MdBtm0fpzO-1>(=P#s^w_sQ0?4-S0{Mm# zx>T{A>_SqK_R!tZLR{Z5>cYI8s_}!@l*cVZ^chVxmT+tSv7UnPtL}Tu73b4S7H;t( z!e&UmPQLvM?C>4XX4Ur_@7u|k(FlViZuxHZSkn_Pa1Ar2Mh0o(nYs=p0MO$)zi(%; zbO90{w+y7L-3ljBRemg<{M>b7_w5C-_4x{M9)7FXL}Y$)H+Ro zf&REf0N5Sle@sFKXMJ_FJxbi}ABpbWab*3ZTs^aGG;Tqlch|mb>nS#Snb%WCiiqH7 z4zKKWD}N0DkBOTc(Io?@hb^wAsE%mZqT=Aa6ZRu2f1ILR5AI&RmQGfoS|QTD4d-*x z{c9iNlvdTXiXL&B=kNadVEo~s8O%({TTu*+`$(C%7UU%CYQ*E%1=Lri-*b=OgJ$00 zH-G%S0BvscpMUo~!Adazh?Pt*zu&1+FLrUob555(2gu(p4S&=e7~mvOC5cA*~kCZ?=&Nf?>PR* zX<3K{QARG$*w{5dTLsA;mnv!Ukr1&N8ro|90Bk`s`?6#0k^H3J!+8S3d7k&I{tx?P zjR6keX{WJ=v*k9t7>__~@Gox~$>inYqvYZzzhoGYQ*h|^uU7J5BFmxfX=#WkwHL-9 za-+PQu?pwBB8}LzoXS(?mSCDG#bVn!Cixz1u;-wgpM%nin?Q0Kls}J{8K40^Xu@H? zt>#j-2M%IL){fx)DvJ!j6Q1HGzLbtYVRE0VKaw)-`<5b&1ympu-RY~DB^N~PP<$rg zMn0Y#A3a5x=qft&cA@_SD(R!1UJRVtLIsX1dooS$o@>{`=q+O^nH>bJ2k`)=(Bbi) zz5)+ZkXDA|o(Ex~D|Y8uPZz8ZsTyE%?+Y3bCU+d!%P#*$*)b;shmT@7S!3M711wFRitrk2)m0-K zSlkRurP8(13(|n1zvec*5v0}K9h$@U-dFEp0u9ne;5n+6lMV^mU|cmJz8=@`lPq!7 z5ffCuB+9qctouBHqxlTZ(%Vqvn#N$>Jv*i2neQUL)iU=|;5@vfB&-#=2hq_k2jPEU zh`q%n^GWdxk3M;PSu=TP>lEqOp8!RxYBI}7<@yVY?VRGFOqrbRYbllVNbF4CDWywV z0WuvP^&I7}MNk7O_bC*)BcNwpOY=A?DNrkT(tA2HwdFq@F76~coikK}g({5FTVAkm znG!mE;Bg8D6-NYN9hZDbfI7rQZac!iRendU>mMTPq|8$we_$t5GKbJ#+2S4pddGkU z@Tf$I`}!~*)=Y;j6;owoo>AxYac?C!(@%vyx@nHYkubdwuk`yT^iSI_mfDdvGUS0p zn!%HtRq(k|U$)SF7~W>0Hz*O77f*Mz58EsX%~t1wQ~L_5(-B0x-Z7qrjD-chMu*@a zw~=k(3%hUQU}`yseu~5m`arK&pVi;M_H| z*|KPefT?8u8^IU4A#`XH=l%N*uGFO=J7X~xtAxrwTGOhP(4eCt!)VaXK~ z`f!+oN42&QkMq;EM&u2j5q3&ewdd0vH_20k1k^$9Hua2j&a?H*t7>2 zT=$2roS`6!qR(| zp`I;ghMWQ&mf|6k-diw7PKa0|UeQf=l!Y9||HK6U7v)P8MuSt$9E$GpR&%%BsD+(W zt7R{X(h?tKiTKw_y71MC!WU8KZj)7Lhj6M%I-`v50QW5lzUuNOAMsEx`Lw{{!$9tk z33avSBC!}3uxz*P=QqVlU+-(d&dmF!x89PbGxWX^z1f$ZJy9?#WY~3x7IAPq_hDLk zWvhV0L%&_k>=@Sv3x?k(H1jp84>xY*DR{r&3#}=*=OK?<84A3rf%A9_RfwN(69eZ) z!<>x**Zib)1)m=3(~p%p-z>?!^~7~ecW5E^R~?APw)(js4MO_|;glaP2T{s>-+tyb zzQX$*$IGIdXP=HydS)w|Prh&%-zsZoNDY9^*lc}j^k}BaVb@?GY)o@)tCsZbUym&$ zvyrumc62 z`N>-KTK&aHs-jJJLOqP|D8}k>K*S`gL&3ujEWB}fCfHV_Tk4_eQh*i}YMa~ts;g1J za3f@L&!qal*xxXB{lRyf&=||GMpwrQ3)_4@Uk;AHeoAhq**v zM_R}K*t;DzfW`0|6r=m-94L{SdSnYoT9JG5Ybh{_?*`ptpxU}I=~_}ZG1Qz+Ni9KL znHj#?)*-fed@m-A|1UW+Epfc8T3m=oGBm^%pcU!mu%RCYAKRo}8Kjj^BZ}!dfg3j+ zEp&%bE&c~#-8|>|g~i@vw(*AmEZ*-r3(*x3ORp#@3b1S@x6B`&J*odVV#So{x0|q= zAwDT7Yv~Rebk1zapnxKOhgdZ*p9Lsr(aIo^iJsnv8pjRJsbx;GPH4pr1K(UCO}U0d ziIvK4EJM2YW&HoPQD&iy_}Vv~*r-LbV1-6Rb`r8G(u-(Us>OP-*no=XsKxNVO&t-W z6*LfZT%|IlFE(#3gEbcP0sPao6y8jBFKSEf(UaO|6kFQ=Su2#Gbmqrc4#iVo3Jw9g zN)6_Qvpb`$Xm?2e1O3ju!0e$@B46%+;>s~^1>x5`B5T2Imsf{)+Vptz_C&mrSv1Ga zpx^%5^qf@?WBLIXP|jN47rXBZh}YT^Bj8iGGZG3ZOH2vCir>8N~MRWdV>0My_dq*%>Hw_n-$}x~XF{mdXtte28Ge-uw zYxMbkPf1ma#0V&_htlTzvTFv{%p7)csStl1uTUj7UH=Di*V6JV+u9z!Z`Eedp5l0t++hJ82TFY(W@^MIncqx? zrq~R`uIU;PoDqlldg)N#E>K_HZJQ}hF*{0tf6zY3p+7Ez<6R4qb&(bRzS7s^T1rR^ zdpuFsB*WYj zuLz4NfyDr^JyXNqCh8#D|Bw4nHuTzMwS=tR=Sx%G>GL6o>91*uJL_dvbnK&CO)jHN)XuVRuwZH< z8~qi?O>HotXDBZnPrsm}>g=S2Mkis#I-B)_Rvihx7`F8Dh`$F{<}3LVewcU=n2FO2 zrh|87Om&N=dKIw12*V4Co7|w-73$~SGM2mq8&mikW_8jWNJrQB>Idogo%P)YN@J0E z@YJw3 zSwe!jRKKtVm_YY_p7HyH}E_TuXu*OCD2(k?ZJQ05$UJ9ox zx23}yBmc;EYS9j!EP^a=9UZ(N;v!z*XN(nax&Swi@WoOEhs*cx<@B(4F$oeNo1)kN zz}ui8zkmRk>e+(rAADg`D$cB+J>6Ky&-_*i_#{b8VQ&zv(N7%jEUrvM9p4R_TRq#_ zF>5`z$+}t#Ut@*tvL9rKGhsOzmg z4ZH4e5<2c0xyNJ;{sGB$E{4y++Y&zF%ym>>7H{e9Rf6_; zqVlgNI)Cb)4(WDj(CjwXPA>|2cB}iusBQnPWtG7i?0wrk_7r~3SO|MMxRlciU5g^) zvjEHJG@HRDeL_9S8Nvj|_Qr=d^FVUzV-VX!Yn{W0O}#hJgH|uyqw0nu82_YVfOvH4qVxPi1cb-~m;Oae&6Lr>3@)zHcoujN;92E8ZZ zD-#%Xn+*PQtac?H$o#*yIfl~+Xn%d_nN`o9m0^ZS_*kqr&@kfE>Sw@n%*m143)8nf zdq&3apt9k%k7$}h>EPuOx&gvNp+_aKe44fWk9pAY(^AO59vE+l<=Zv+=d)&T+tjEr z^zS>P>XShMQ2}$8b|O0Ck>-vK?aqh-@&=~s8cx^DoENS-q}Wxk5bE9<@~@Ai8tvMD z0z7?XaSML^{c8EExqJW9-di@*)dOpwxJxPS#f!UJu|m<}?pB=Q?ykk1P0`|3+&0DC z-5oaW4tKrhp7ZVggqzP<$;!-RGV)~d3E@C?J<79ssu613oeNpuwl8T;?lX$=Kw!mhn)_RDtKyU-F!XD9j~DC1NF`FZ^wtgAV1 z_m!dmUUS|;xY}-UhYYQh$!`>!z`Z~SmQVjr6V~en?EHzow#gdSlq-HE@+7G>`#hXq z{JtGjSC8;Re;@wlnNxkMtnLrbzg-!@pfRYP(r4Qt@oGRC`O}lR$kaIg1%I zzPf%-N3I7K zhfdES47?s|&j2zM^@aV5^Am;iZW5}%^w;zMd>(iYkfsIotqW960H~<1;*7W|V;|Fm zGV!K0!Gq%z$p_azpCd@hakkpMIFgL&v~<{moZ31u+u_RCXD9LljMOBJsF$jh=F05G z$w|FAA2UY0lfu%Zegpr(*K*+!`40D^fzJ2BlwRmm&|$6D#9Y8YAaA~&+UP-}_K_6& z6JwsJB3n>t5s20@A-_m`dG3v-<8JyTDy@@O)jw|6v3S98Gd7J>?a=u|< zSKkBnRRfd+;$AF;QrPj&7@Uwl++V;fA-2MKU|e__RnPebhJ!q($M5}yuJHhHVn6;L z7)r_r%xk+at&g|C@|h+TG`D@hEH}XB55fM6(J;>cCMfu%*Lc_bXU~u+_dol#wyi(! zww`2fJf8h*7ux}dQ%pisy>8QUSQ!3vmZndvYcQFeTE~2{R$oGXVWD0-Rk`W>5WVuZ zR)9TMmRH(1M^+f;Y6ALX*+=Y*5M_abK7Ijq!1LlLg~cnW1vTz1&^bX^RfRUtU zo95KQdV+tQPC41-I*21vpf8*jRk?{e4|0r=!OHw@ZGX@c-sN4)NEjP_n2bRxU_>## zxmUC9Iq$Izd)}Qa`RSqQNSTY{%pXC-6$7(imOF}Ix)cjJ=+b{M<;uq+itKim=qJa! z6Rw&;`(#oM$mKC~3K>TuG~BZN*$kpEjR=3eQ$aH!(K+Q9>B?G%9yWz7RP&t5zD!Ff-j9>UH^+s zJNALx#ZYi-d~UZ%^XOpvb~OTBf-)rob`>^z_j-|*HgO1yW2RgPf4v@3S=`t~e!Zem zNjS9i2ZAbwAG>WRfmC=uP}qm+5Ur3|hY5M?pLf+fYUqRNr`8J{d$zGXcdcd2WB-vU z;CsK@7j0jk=t0Du47u=E2w(+pVH%9x5ml&7?dTrVn``YI$rGn&H2(PcMX{UY=oUX%oy@1za0}LE;cW~Pdsh*u;)oNY87097 z$haC(rVvi~MbUB20IBUZsX^!_sB8529kamtmnmO9k;6_4>RHc2FCY7NE-b6`G<(Vv z5ke0r8Tc=a%nS$y*y>F`N;#JyrHhXo+_aNXGh_%Z+j0P|mEsrAVDWK@1op zDLmQAKH7g1V`)-}p#^LoXg`8Y7LD&!=uNo5kcf^xg?Qx<*DnqM-X0`_`s^h~(U)q) zzvp0fhFnN?G1|XAX^e>V&BP>?cu~LXPTax*59Oop4%{19ul0 zU{Uly=A0b>{Kl`8uzFE{*@(du0IL@x7$3gY?O?g%7Rl=is*TGcs`eidt{9J?k0z;!GC*uH}(RN zF{X=AtVl?Jc(Vt906q7K+c%|H+~k#YeM~S2BE-8PF8xNa3xjY;L%y2*xpKyO&NIJM zy9-f|aMPX#mi(iKCuPbb6h!1ZQ%w8SMUa{f$*vUmz7$(3_G?L*U+G`#P}YA8cy%ej zuXAqtQfLLK2Jk{Td`J+}$!w%i$#4ZL<_Wo6=7_CH*du%>q-4g=_UPBPeOfUMb0xxz8MaL;pH%%{tpYV|NaN!3*1H0>LO7p&XU~S2%Pv>F`UF6k^z1yd814i z{Y#|>|AII{TMfsD+YA6gMjc0hw?*_vh!==2rFe?l?_NF~!tKK4jr5XT8v6`jQNX3{ z>s)mc^E8ZS-Pc>by>`~sRkeKup?k&xJBV5M7KS1<`+9Si-)bE*)#oD2PUEAJHkGXF z4W>)|52L|gDR4ymo9{|sIP4-fe3gEOm-e4MMpvqhcsWQrK(>ZH^Sl?{?z?<%l;}Wj zEZ}ixvwiaIp)K{<9FUO0cB%ZTSf`Y*QWpNM9(;2<09<`&A93j0=zX9PLv^Hd6mg`# z{r52q=0KS)JV-;VrJ%CQR!B%z@)hYPd^)j-dK1m3*L1X18cGlegQBw2sAGONCz#7( zJj2<-%(nGQ+H&sSAKjM2#Jq2+l_k%4J?$#xn%CLuXO63Uh*(UN0l>Lu-X*uh;hg)4 z$7&ed3r}ZgM{~)wEVWdPuKej7P|Jn@9$!hP^egJ|d?f%ec!BfK2DfTJoyGs-xf#Oa zr?<9g=m>T7#qAVv`Hdm~=RyBZ4xS#63J`-=*C$W)HGPKNw_H4~same$IC+?TWG9}( zJ}|0qC!CKZxb$`0fr4Kxt%XY%L1@F;bb?L!7vBYbK_$Z}5_|b`m^(G%A691YJ9a`7 zfLwEcb}xstzE&!}&zs+d*FS8_qnU?+m%v#8ns6^?zB)n~o?4SifiK5wPs<2CPE+}# zHiClnvHYJT`%Oi9U9*3?y$q+hMg4a3xy&OLHD~L$pj6i3nuOCI*jsQB@!AU&Jv%;m zJFo=V)YMNDxqr_P?*3glROezGYTY4wJno0zu$t|@d==8tk0@@&Ocdg;$mJ} zX!1NV1S2ed(jxb08S-wg%g)a92@MHW-Sp4KXfE4YM zi!(oeFXtRCSR@DSh3>)=Yf0GZySt*S`BSOo_Y7I#LP4g!-l`8jQee z9#JQKW8j*=0lfPe^+)Z}U&4BEN}>#v(m8pY>LCO1w;~FV6#wS}M{0PHq?Hg=rB+!T z9n7rBPM}EEc~x!wM53T^uj+ME&p4(eV()ye}h6#R>_;vjz{k1X?c4Mbjo?S1=*rK-vb; zvs?B3r?}8~P_GrBZSerO12151IH(tyht8rZ_@M6vQvGt?RLbR1jj!=jS20+enlgrv z@Wz%##ZgfrwF6~B&a;j)OBCDAKKG*nCgA*OL(9>>piEuXr&>RU*ub(J&T6bIzAZ-7 zjmwnV|CkIO&g03(P7iQ=EG#Xf9q@Fe-_$Njl#(t*w~Z;r+k=&X(-#V1;Kd$o zk2D7Rm+@i3mr4M~E#?EcAa{Vfy3heJdE_6%C(A~vX|nzy_un#X3@th&L{`TM=ZxKywGzL4f3q)4~?cssiMRs-P9JX!Pb*{W$j zkJQGj`d|tyKj`+?N^NfOHcvaMcNXEfOjakh_8PBz#ZWbr$7ESKI6qQCwAl{EKx5Rh z`fS)To;&jWr^rp0dS;)h(@>=}`UCFW$)`jv3TeRI$XNaNdq@nhzWF!obJ>s6u~!%V zl8LvtIi#G`MeiNGNc5@moLB!RUpMoqGyW5y@{~t z65lDREUAMQKLqJa$O*dFNx@}!k)1jK!mt~d*Y__MSGL$@?Ij0JIUX^OeB^TIf44MQ znpF$xti&ZIncoH#UMmMC{HnRQF()8p-TSY%dX~b$sU#ecW#vGbO6|6iukPB+->eCy zSIc%3v!Bo9M4V>wQofR&Zcm^4a;=H~+?BXaWodwkCsHGa^71_qqbpOsCcBu4Hv5^J zW}``=3H_>RRIt`A-F((l!cg@ha7YSV9EFYQ1PN$!&tDJ>L#>B~HNcLA4eXYjq5iDX z8&jQ-vc$4Y4vc5;`biI3;RxEer-GNtLP`?u$clVWn9LDz?L468eWg6aW7bQK>D@I`22iN9+ses&TzX^qAY`WI#4doE^Xm|sm6gz08>`)Xt z<|R_Bmsw}(U8l)f`?J7t*)x>mH9>aC@rT@S_eX{mwZB$qN1Zg0aYY~dL%%caGJr8F zAShh(Q16GWPocnVY{D&Gi^oX^#Pi5*?S~}yd-`loy1uod-Y5)dwu%%-0kFG%Jvr@ z%q3jpF`TpDI{zMuYAddRQ5Qj~AeOkEEgB{Tdy+LyQQy93n@Zgm=?z$+9tVBj!!rVx z)od!DUzkEDDly$Fhhq<^=x9H}bgJ)WA6(vBJ_<>rN|IEY3yu%8L`%{vOxDK8i9F<_ zR5~B{8UNj&*Gw6E)}KGAtgGK>P&btR9qEnvN%$V^4~_6^7!n|dkE7f7zU5}2%F@Kc z0Yv^aI-e;wv?dcGmk1*gr)Qr3gxjb0kM)VWX~NO`w;Z7wM<%9~Of?6Xw-NizE~{N^3(vN0 z3em}-t9E_K@P00lZ(~F^`)|mSQM=1uO$M@E|7CwasErcFs$E;e17ZR6xy8n`zfA#0^g8 zS@@!solR3)$^pS*=Vz!0I|zT+aE)$j&NnB=KiErs2L(?IOs*_k4g@K*Mp?-lT27HT z1Mooo+uT1%;V`T5ye7+HNG66R$Mu)_G;L9NZ5? z7)6xMkFFB>8cY;O3-#xEpWSDByG&@7*xD=2%qE)XmdI6`>{cRrd8FvFd(Vr`=e(19 zSrM|WHoGjh+ua)l9Qzc#1*>EC{id(|2cxw6P}kLvYLbJcn{sf>T9wJ~Ec18GOenK) z{uSk7@q=FoZ;){Rx88aDD+Rtt+|A`I`m+!lloQ^>OD*!604DNnqu8Vy!lXdtJe@8NmY4V+!rO$zFG2!w6WSPtshO#CR+65a#aemyh^x8aNGPY->9qP zOiEsvO)aj}9MS41bJ-3#rb-iiz?Y(=iYQvx?*OsD+E<}V!;~fDUwT+vq;uYLRYu|2 zRA-&1&C%=(Gx|ytZP8+ncvsj=z~qtyO`LwMc&)&WuVe|!`l-=3t@VtXr-d2(^tPvb>6v_; zy?c|KLs@g0bFu#6VSW2l!na}bvlVNQNIYW(pLyRP{Ix4XuR)G(Ms14_!FC79E+EqD(CYhSk*oa1o=KQJ_0{#^tVo6w(GK|N({$$GIB3zxG&@Fv0tvK>Xb z%F06}c+g{yF-Dy~LG_ztx9$I1@3V)iy-~ArwJ*<+wm;7`#!TPnVrG$q`*b2;^IOn- zX=$&{Sc#Utsg`*xmyBi)WnYY?`jCXjbUCA*^+BvDKS4RDsK=`~niH&9B28JAZX)AI zZGz{)Af4v@IU~Xq&y*zA9L94!9QlHH)L5btotMT$c)s-j>Ye=}N_8|Jyrn4ASWMtB z{;hYpqG14b0(XeH!>Cf22KW{hZu*TQuQt73vR_5wji>wl*e0rvJEa#U3-g8x~%9-lONj=CaU`@T5!3NK<07aITOjbZ(&Yv%KvO)al#w^StOz*%7ed^9k>YEX= zdh9*T*QQ$Gpio~hQdGXNZT)B+DBLG9Y&qI&-3`>o`_6{2E>PRNPVDN(wCGUs$1SQq ziT{VmE8ZFNHo<&CS8U$>-O=yGfTYO1S1lF<7C5h{8yZ-WMGW9bG7gFO!>lWig37B-v+vRCO1>veV0YLal|&{n$9J z6+wMB*S3=*SF7`pQQKohZLgV(5Ci|^L?_OTXT-M(I`gBGroZ>v%ihd@2(7f~HM$jg z`YL4t8*6BdKCzASd7xwJtgfChiTY$AaW4PkAF_rPFXP>ymW_wn=?Yke7&?qF4_=TO zI&OHeBp3V($4J`ax9eftz870wk3y0ppMH1nce@cAP3D2ffwz!`=)n^?%|i#2Hm2+? z9Tt1p-muxo{h^epPBOzMP{8%&{+s%99Wq}PaEp3*7xKf4{M}zHZha-(B*?yO0_RRX ziI@NK$45Q{j{>OZE+W2hLRHtsq=?hS5);%)V9pP-L+IA{Y*6sB^jI zz-zJogvW9cO2c&}19jyq=H4YE#HTD-%N(35^G(H8_CwS+nL5+d?v|ar=r2pH^YWDT zs=Ap9r&f(_%_k5itD_<6GcVOlTwa{?#OY4pv9Iyc_kPk9oYf2(l~qO9|S=-Fh4DTFQ}n}xsEGjk+u)4ml=fSnkYK%|+>6UO|X3FBEv z(*rqn+dEC*J4l)DwN5^6nzOp+feYsA1|y~Y>y3NDfZ93rJ=ai9b)Mz5Eri&fHRpoA ze>~NAxWF&=46RWpK9|Ec!;L^I3O#Z8KlBK``-`NW-oZ3Mqbmw|X{uTv|2!iqWH${M z7Fv)4gN*^{<0rH6SB>3T6g!rPB|QD@O=6A)Vx8@*_yN3tiTJiM;jb%Fen%v)yp}pB zlB-9)$7$(nxz!-*t=R1$2d{RsbM&Ga>$=7X@aU?xBDJjs`5VRBw;I z%ZA(7z~Ae63l-YNIg&TZHdb(*puW4D*uXQ*+PfcgSaxKP+h*e)1i)HYH4#PD3%a+M zu|pVl)W4rKqinrhdrOR-P^wDQrsXY>E%Kq6+kL-*bmXY%ZXB|vHlFvIV$74Fyo~qs zoxs||>Yn!&@bX0-iacxEc&3a7Vzn3r8bTo&tKjor9>xjvSum_Gf-VO$Gc&v2MwiHJ zqc_k(5f2`l(rL_6$Gy7kYv2XHvb4%;SeY-m7O9rJi|>4;x7e!}k4GGV;br{j(BeGx zkkD2+aa^((_b(k~PNS9$1Qlk!6|8U5Qu2o?JOf(I^N$RL;n`j5Rl6DGvbboPNe1RB zyhnq>DdJf}YM8M1vb}rQV&eRL<$y;8-Q1cRY%0QLXJGFa5m#8znt2|9%fpFG4QBU^ z5>UGQcxv0;{$KuJ@HpWz3kw*UXav)ELQ0VZ0`!s(#r%s|R5D=*tuu4O{&m^X7x&M@)e7t-&)* zm&lmHmInftixBbCo+uVE{Kxg3vl`?AMa-CtJZ$Eo&+r3EKxH5dLDQ|+u1WEIXm>KM z-z0}e_iyXp{A^BT=CroT(WTKYDw%v=P>rH}eb=EkOOL8VHc1*zIuKeEaR45>ZBL=r zganfRdRG|Pm_-z_H?GBw_oK*&uwQO0)lO-|92*-0_~u1NCX8u=|LfbV>uxi_8u%4& z<*>J4!)JxQ@|=I0^V*3=qn4i-+taQ~j@;2=>eld53xpkSfKCGQlKaw0-U#ikdjiP5 zS0;9Rm91jC|HlgY+Eo~L%gR2>R4@q0+=E=Ur!12q)A84Tcho7Z@cCFw-o@S#a$*o1 zObzTAN^Cs_v)fFeKHKVU648CJ&euaFYB@U~?XjHCK4Bzol&ZE+k@vw($qJju z_L>eN&OOxN;yBadTDPn%GW7G*73=LKP%YJA46>YZ{DEiq_3Rt1NndV&=wPt90JGW# zpLnG=dGMNi&_UMxvJOY&sO8YaXtFR^DF8NyU7e10XUe=R2U9h^HUv99*Rs~tEVZ-h zle3puqb5<~ym(N`^+xZSPI9Pa*YaC^c7jN&xkB&^=BKDbZQ)}~) zsp-Ds7M2y}9nLKkAT>Q~Q%Z2nN-*Ky4wg-?5#;x`|N?S4bHc7ad zEcVjQwyxFM#u^=S32GB1|A4|9*H0Y2A%vo5cwri2;)|^9_*$Siw;kMh$Vfb2uE{|k z6#}k_I)n5@k4Nj(yX53wHo8Nw3_Y!MZJ=>mBpWmq#jg*DH=XJ@VJqhTO+*X&VX@}i zG&HdzT=O?vxTneYE&~RGn7;*B7uCmjGn6mu85h8R!gm^R!meHCc)0Y5@TjF>>cn3z z;?a?Hbce#5-4Va=WE9%0eDVQ6%f_2*ac z4*Gs?zTG)vS{tAf|7P)ouZ&LQl0zNWJC^2vRl%WJf&&e1k=XI;kX}+-)V{-$^es4jS{Qd(}#673)y3oZu$0W8jBJ0o7TV}4RQdC~Q-6WgXq2*Lo z@_r|q(?><2%wjO^ZP;J}BbmojUv%7?_h-h`G|OIYz$G!g8DOXMzZJa7Dq z+kDxRBti)@{9Rbav6+1~(26>VBnw)e@Xr7w5Lyd4Lz{06%wjYHzHTLXh;HCHbN6o3 zs3uE3^>=D1^_sVwBwUDt;k?#=>ZCP7&%l;hfFZssI48!GCpvsC?kG5C^ls{`c3Tg6 zx7KMHWnRAP^vXbGf=vyD5VLZp^P5@xV}*eXQHL{Z6iw85`<@g1xF3UcZTx3q*t5MT zva&Y&*XR4lDRq8r>(gL2m>XRBnrwo*)N0j3>xHOy7%&4L@t`Sh#T z<}O7JZxJ_4pIbB^SJ)0bFSHvSTh{p-7+>0%^IK^8PoWeY=TCp3Z3r!62)VzrzWHu| zVrj5z=S>dF(WK694cCksg`W?~1vQ!8t6XQK{JT^_g0;IgG-fBdd{%$URe{`Iickgv z$Vs`@9r9jASnZC#b5U!G-(qzI9t@6OX)KteQSa2IMe&EZ-X=(yS?E_1Jm?_zRz{op zG`4k>kLfqr>!(7hrx4+4i~9)#qesI|UA=u3phN&eR;j$f-=+TF^(CP{ludaIyDGxA zK;~%oCkI+jA6V9XeKSSlH4|oHrgn@QUYdN_LCv{CWztucX|CR8hI%y zRk8RBJmkL}3pN6d?_8IQi)mkt67I>KF;j?NuL+|&H=0bJX|y`dzd>Ib}v{eN9PgZ1_x+xYBLC%eNWH^!lQ=Z-UR=XDTJ^UCtvUx=F;lMiTFR zhUlcrMmtmp!ljE!(;1uBUP*QF~cm8&%Z+O3Wt%|ZrQe?^DlKLia`FDCqm5f-# zZu+Qx{3%zFVtvF8F^=_?nD4!)@--@KSLHJaA-tJ$>7zroq-{7QGbPNf{do(o704P3 zYe;b8d)wAy+WLmNI{A~{P~p(TpQk?OnBQjGyL1dTmf0fb(}>C0D-V0Zx> z@vG|}ess~WUr~kre2$KInfpWHew8UsM@i{+vB(y9j|xxD_72xwXmoyy))mA>9%^WP>SuFQ#$&DR3-Tk2jA%FaU}3djmYs}@ zkXe5WgTyZQA9UujBeDuvX?b*}wnfpQWvRYD{DCD_%JT2?zojRlT>pSFaUa-{ags~@ zAj3fhWXL3UnfVna2_MjFt=y5bp4bT5wV-&@CVUo|DgKp>b4Q2 z$y2m1fQ@AB)wb()L5{RM9huabWxtk{Qz!-nh1K*;QcTVBZFHtu!%4AM0s^5j4Imym z+uu?S)-L`53_BJ<(v@&@K@X6>EkGO!aqX54Rqt)MNy+*=g85l9OEHa}A@NqT`%6um z(-!o*6ZlrnL5)kY-CV=B7is|}sotj)ByjmBRRf@xzCE@J-fNuIAq`UILwit3Wt~BFE6r!7yy7i$_U2zH_!S)? z(@8IOkAb*$HJXH5e=I^qz;98XPqFmj4^c~J9mUIKpS#erjg&;MH?W)(Flm73NSfC? z0T2B)C8a-A8nOVY3*#;&Wuk-Z zaZjR}o{VxGyR15Vbb5Y?zj?L8Mx+1leQAWp`tA_o-ic1b^**svR^D*~!l~GQVpRgS z)`s-nrE3WCd13e06mWftm(P=gPIxs5qG|NeI3-Pbdpq3eF?`+nDka%l9uyA!o*s;9 zSAP++%}i;4Tjs#!y47z5sAmT?wfmg3dUx6dLlm@;tx7l3SjC^XSPAVj6ja};s(-p0yx=xeDajq`Q3|ZaE+WE$JZi%atA8{Tv9}Cy;r_= z->3txRr}s2YYHxKy>iX9mK!K1U^4L8o8+7H|DD0tYjSDHr`Xna%}~{KfV0@!bh4^( zX9T9e{q1Plz`jqgDZlwWZ#$=&tA#O^5M!4^Y$3rdB@Y`b;YBs*3|7ZujcQ80$^R6) zvYNT8#eFBt*;a>hYfspK8CFb|ZsDc5%y_)%pW(A|7NAu;>0l4`4|PUntlTriStuXX zG|A}^;}8^KV@>At~AZ1(>OHe^E|vGhvb2vTL%% zZ|BuF%Rp4G{s<2I0Gljd^*9#s#E(Dvyq`nd{K|_G6)`XuN@dC>1QRnlMdMx3fXR48 znaBtbZj!(mDx+|92%H>$!Cv63wHwKgF-2@m1JD3ocG6ceR#T|?=L{z=X~XT3sQ%>K z>PyE>ZmO)5`QcUkAA4pH|MdzshOU#tSZ&&8Q$`h};Q6P1r_HXw7XJ1V&Ur0#1S#rr ziwUa>ZBR8?j}>4fF&o|OPz@-ehA;h++0B38=Eqo|Z6LtHx`d%Qyz5CW=vu;DZG7=Q z5MHY-J}T~H&Qh#7`U}GuLf{{eNUus>ovwV{&_6=%lS53d`CSs_i+(dZ(!Rl_Du3sV zufoq9LMqB&RuYUPj&2>c5^X;Cbi@b5qaEqA4@|ILPL7N-P9&`hb6%2?y{O4~#Bk_o z>nrWsWfP!TQO|8c{jp<*lZ{%}pnR2=AX7S9hVqOTSI|##yY?3`c*(*qA^SXVZ2LSM zBOOjwNevn{8&YPIvtxE_52I#mAUSi3VP;A}x+=gemvu_Y%SzZ`tJ0MFh=s-aJ;?so zXxEh`p2v^A`*F|q>)Wz&FJ8OW!P7G)b+f4WY9B4lrP(9* zoX`be9kT2sdfj81$Rx5}`&BWkXtSmEN!c6eN_@jnvS9+f5A6qe#ILb_?Os#=7!Q1R zq<>0D7S@FPL#OF?Lc9nS((A-Lfh~i_di(?V7u&6QgxnzA++ePg_rZvF8zQS@967d zkPX?}T47I@H7;(#KNWm?62uo2K6)jo8n8btHv26(Wu55Lwa;s?#4T3Rp3UgQrSQ=# z86bja%s;)2*(V324+6V^4WEr6&BOzDV!zi zs`q`w-djph(K66wsL~L2A(+uIQ+AEEd6Dwv4+*ccxd+G6F%1QQIoj?0(EObxnzI#v z=rJbejr^YE-#A9FUwRo;aJPHyK|OHgA5WVmwL`TNsND1jxO}YavfizW;;%m^YvXfr z2e#J@0|RBKRsSkHobR31rihVCZnU$vD&>5&4pzcz@_EO!Ec-q-*i_q734`}3ApYRO zZyFqJtpP{_?pKOI&|H(jkL4_0vW2F$y}Gwb2a+GE0`iosm|`{5q$HwSdq(DcbKQ|U zAOpvYyPx>UtizU+$UPb#>x=^ zLT>e!_NQBX(me0c)mu=s)4`Q1b^VWNKM?fE###>DP=%0%9wALiTIrCJmUhdYR;sn! zGZZPhXP=@y(xRDSVNwDOx3yi1C9>WeOPO_7Sx5}5>~P-4ay zc1>u*9$n6!cbc5D7K>BJTp2YMAr5dfTLu(d>BVR|uJw(V?VWvEUuZG25IwNAowi}- zOpH9lYhVCG7KP>z<;xY_yI#Zd+@5sF^NgY5>FQ6J)`ChkWl#UNC@kT?TGRK5gZnjp zj*os`ccSb0<`$GvX7lYxA|ocS?$Fo58tr3R`}~nV%B^K35#;oJcZoKygz$UdVPvM#(h9bVps(S_HAe8s(_$GP=N+~`Wbm=hDW|9Yi$F+DXL#9;c97#30 z@rc3AJKx)c38=2yFUtAz%c?QmMoU)H_Q#prj3PHG@yji-exQj})a;y{E6`DI!Fv(j zf4V0hP9Hk@eKV*m_q0uP36Sk(HJg#GqsDoiEFvB6wahP2KpLa4%c=KV_G|2m`qAL9 z=xEmo^jI=By~+#~mh2NhN;6^l&XkFWDf0jgwz8cF3uQ0^jy;J*%o1G8&6l6{h>9>_ zu!4bn7aSMf6~5iydY{&h$rr+?pg~*DV9^5)`74A}0XnQxwdntJy>d{M4E6cb*F1M6 zX}g6m1?j@pR?#CjHx|W)vs_!%*Uo(Fn!r3_0&a_}>cZXlx8bb`Opx+5qW?F?x$J0r zxpLeHw8-uwYSU43@YWY3B(I8yV`d*A!gvT25f-5f=kfkWq||lH?47`E7nlWT&5i=r zMlev^e-kJ-6g@%of&gPQ0+xsFgz;g*-0SR(ly>-T1N>L@fB!{e-!l2|^5%Iubc=X* zY9G1T8a-p@4OxAAOK7YvVI#7v!7qBH$b{LvRm=k_%w_HDUhF3T+AGOjNk3DVJ0<$@yU(Vx^<%5j-+S-C#q3*vwm= z_iQ4d^K5|QR($?_Lj6tnlH0YkYCZT_=YFw@h1lSe?+Nwu|hgM>oKUNv>=D>HHbeJxZ5Up^GLNKvdTz ztxu$du?llXLHD*U*D5J_*H(?n3m1FY7tjJIk?1ePjv)gQ2QZd4=lsCNVW2q-L66th zoqDo%Nv^gwYaaO)XSR5ueU_U#^m>|8M6)wMp1oWD{`}2`#_*9Wpv`vbRIkAkF242{~Q*-C}X(LYTVG! z_T+ABC=A(z)hz+Jgx-Xjrb*|*Er>`AVNBvLgRDu*mYS5MRMDs1L zQ@@-yp5EARi22(v+B>iwt&fIa`CHLxQ$Kuds8)g*spy1?1g7%?a=pP(nWf77ozh2O|e`n6qI{G`QZ%h?^Jx9Vt?l2_HyG78?DCEdQSo0?SA= zT7|!>+;OB&K+{MFkyPv0C|NJHTmzABx=Nk!hzOjIq#r5%8%+glF;+HUi1&haf%IJ% zPGS=3sz6zy7Ze zHP8n;&^w?Y`hn+pa1^gyBt@1cbD=`54{$2GRfB+40No=(AXH+o_)rVb>Oj)>6buVy zwkImFa#edC1w8$!@BiCvaCUa~y8*u!QJ77@1Z+1<2QDffcn$CQi=p&!BkE{R6`*_l|&^QGO=iH2nrnwg2HI1-06SmOWcIObHYSo_4>MZza$WR!RHh zJUs2ejYYRnK82c+QX=kuxgwzkM4iw~i2{_M$zkze3!n}0SS*K_^nI}&3{fWtPn?n< zN80rku?&D86UIez_#Y`GLo&8JA1>j+ydwnru+D)W*hv3SBsDWa!vwthij2bx1kxH2 zUJ#|G)ws1ppW5j(=t1LSVJ$`f@03@a)(1Sv4>5#R#v$y*L>}1yR0Y2VSxfYy0rx@F zX6cu_WE(E9<^SK7z=RY^MJ2HnmPh$NjQ@|T|9|`cpuqFZJ2Yn+bcKa6A2SrtzDX%c JR*4%0{XfJV4qE^K diff --git a/docs/source/api/client.rst b/docs/source/api/client.rst index 4190af5b1d..3db28693dc 100644 --- a/docs/source/api/client.rst +++ b/docs/source/api/client.rst @@ -8,7 +8,6 @@ found starting from this page. This page is about the Client class, which exposes high-level methods for an easy access to the API. .. code-block:: python - :emphasize-lines: 1-3 from pyrogram import Client diff --git a/docs/source/api/decorators.rst b/docs/source/api/decorators.rst index c859063a70..fa0e7ad337 100644 --- a/docs/source/api/decorators.rst +++ b/docs/source/api/decorators.rst @@ -1,16 +1,12 @@ Decorators ========== -While still being methods bound to the :class:`~pyrogram.Client` class, decorators are of a special kind and thus -deserve a dedicated page. - Decorators are able to register callback functions for handling updates in a much easier and cleaner way compared to :doc:`Handlers `; they do so by instantiating the correct handler and calling :meth:`~pyrogram.Client.add_handler` automatically. All you need to do is adding the decorators on top of your functions. .. code-block:: python - :emphasize-lines: 6 from pyrogram import Client diff --git a/docs/source/api/handlers.rst b/docs/source/api/handlers.rst index 2d83a05d8a..9694142932 100644 --- a/docs/source/api/handlers.rst +++ b/docs/source/api/handlers.rst @@ -5,7 +5,6 @@ Handlers are used to instruct Pyrogram about which kind of updates you'd like to For a much more convenient way of registering callback functions have a look at :doc:`Decorators ` instead. .. code-block:: python - :emphasize-lines: 2, 11 from pyrogram import Client from pyrogram.handlers import MessageHandler diff --git a/docs/source/conf.py b/docs/source/conf.py index a9fcef52cb..ae84c5b806 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -29,35 +29,37 @@ FriendlyStyle.background_color = "#f3f2f1" project = "Pyrogram" -copyright = f"2017-{datetime.now().year}, Dan" +copyright = f"2017-present, Dan" author = "Dan" +version = ".".join(__version__.split(".")[:-1]) + extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx.ext.autosummary", - "sphinx_copybutton", - "sphinx_tabs.tabs" + "sphinx_copybutton" ] master_doc = "index" source_suffix = ".rst" autodoc_member_order = "bysource" -version = __version__ -release = version - -templates_path = ["_templates"] +templates_path = ["_resources/templates"] +html_copy_source = False napoleon_use_rtype = False +napoleon_use_param = False pygments_style = "friendly" copybutton_prompt_text = "$ " +suppress_warnings = ["image.not_readable"] + html_title = "Pyrogram Documentation" html_theme = "sphinx_rtd_theme" -html_static_path = ["_static"] +html_static_path = ["_resources/static"] html_show_sourcelink = True html_show_copyright = False html_theme_options = { @@ -65,17 +67,15 @@ "collapse_navigation": True, "sticky_navigation": False, "logo_only": True, - "display_version": True, + "display_version": False, "style_external_links": True } -napoleon_use_param = False - -html_logo = "_images/pyrogram.png" -html_favicon = "_images/favicon.ico" +html_logo = "_resources/static/img/pyrogram.png" +html_favicon = "_resources/static/img/favicon.ico" latex_engine = "xelatex" -latex_logo = "_images/pyrogram.png" +latex_logo = "_resources/static/img/pyrogram.png" latex_elements = { "pointsize": "12pt", diff --git a/docs/source/faq.rst b/docs/source/faq.rst deleted file mode 100644 index 4bfc7135c7..0000000000 --- a/docs/source/faq.rst +++ /dev/null @@ -1,407 +0,0 @@ -Pyrogram FAQ -============ - -.. role:: strike - :class: strike - -This FAQ page provides answers to common questions about Pyrogram and, to some extent, Telegram in general. - -.. tip:: - - If you think something interesting could be added here, feel free to propose it by opening a `Feature Request`_. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -What is Pyrogram? ------------------ - -**Pyrogram** is an elegant, easy-to-use Telegram_ client library and framework written from the ground up in Python and -C. It enables you to easily create custom applications for both user and bot identities (bot API alternative) via the -:doc:`MTProto API ` with the Python programming language. - -.. _Telegram: https://telegram.org - -Where does the name come from? ------------------------------- - -The name "Pyrogram" is composed by **pyro**, which comes from the Greek word *πῦρ (pyr)*, meaning fire, and **gram**, -from *Telegram*. The word *pyro* itself is built from *Python*, **py** for short, and the suffix **ro** to come up with -the word *fire*, which also inspired the project logo. - -How old is Pyrogram? --------------------- - -Pyrogram was first released on December 12, 2017. The actual work on the framework began roughly three months prior to the -initial public release on `GitHub`_. - -.. _GitHub: https://github.com/pyrogram/pyrogram - -Why Pyrogram? -------------- - -- **Easy**: You can install Pyrogram with pip and start building your applications right away. -- **Elegant**: Low-level details are abstracted and re-presented in a much nicer and easier way. -- **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C. -- **Asynchronous**: Allows both synchronous and asynchronous models to fit all usage needs. -- **Documented**: API methods, types and public interfaces are all well documented. -- **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. -- **Updated**, to make use of the latest Telegram API version and features. -- **Bot API-like**: Similar to the Bot API in its simplicity, but much more powerful and detailed. -- **Pluggable**: The :doc:`Smart Plugin ` system allows to write components with minimal - boilerplate code. -- **Comprehensive**: Execute any :doc:`advanced action ` an official client is able to do, and - even more. - -.. _TgCrypto: https://github.com/pyrogram/tgcrypto - -Why is Pyrogram defined as both Client Library and Framework? -------------------------------------------------------------- - -Simply because it falls in both categories, depending on how you use it. - -Pyrogram as a client library makes it easy and intuitive accessing the Telegram API by offering idiomatic Python code -that is generated or hand-written. Low-level details and client-server communication protocols are handled under the -hood. Pyrogram acts as a client library when *you call* its methods and use its types in a batch application that -executes a set of instructions. - -Pyrogram as a framework makes it easy to handle live events by allowing you to register event handlers that will be -executed as soon as they arrive from the server side. Pyrogram acts as a framework when it's Pyrogram itself that -*calls your code*, that is, your registered event handlers. Such applications are usually started and left online -indefinitely, until you decide to stop them. - -What can MTProto do more than the Bot API? ------------------------------------------- - -For a detailed answer, please refer to the :doc:`MTProto vs. Bot API ` page. - -Why do I need an API key for bots? ----------------------------------- - -Requests against the official bot API endpoint are made via JSON/HTTP, but are handled by an intermediate server -application that implements the MTProto protocol -- just like Pyrogram -- and uses its own API key, which is always -required, but hidden to the public. - -.. figure:: https://i.imgur.com/WvwBoZo.png - :align: center - -Using MTProto is the only way to communicate with the actual Telegram servers, and the main API requires developers to -identify applications by means of a unique key; the bot token identifies a bot as a user and replaces the user's phone -number only. - -Can I use Webhooks? -------------------- - -Lots of people ask this question because they are used to the bot API, but things are different in Pyrogram! - -There is no webhook in Pyrogram, simply because there is no HTTP involved, by default. However, a similar technique is -being used to make receiving updates efficient. - -Pyrogram uses persistent connections via TCP sockets to interact with the server and instead of actively asking for -updates every time (polling), Pyrogram will simply sit down and wait for the server to send updates by itself -the very moment they are available (server push). - -Can I use the same file_id across different accounts? ------------------------------------------------------ - -No, Telegram doesn't allow this. - -File ids are personal and bound to a specific account; an attempt in using a foreign file id will result in errors such -as ``[400 MEDIA_EMPTY]``. - -The only exception are stickers' file ids; you can use them across different accounts without any problem, like this -one: ``CAADBAADyg4AAvLQYAEYD4F7vcZ43AI``. - -Can I use Bot API's file_id values in Pyrogram? ------------------------------------------------ - -Yes! All file ids you take or might have taken from the Bot API are 100% compatible and re-usable in Pyrogram. -The opposite is also valid, you can take any file id generated by Pyrogram and re-use in the Bot API. - -Can I use multiple clients at once on the same account? -------------------------------------------------------- - -Yes, you can. Both user and bot accounts are able to run multiple sessions in parallel (up to 10 per account). However, -you must pay attention and not use the *same* exact session in more than one client at the same time. In other words: - -- Avoid copying your session file: even if you rename the file, the copied sessions will still point to a specific one - stored in the server. - -- Make sure that only one instance of your script runs, using your session file. - -If you -- even accidentally -- fail to do so, all the previous session copies will immediately stop receiving updates -and eventually the server will start throwing the error ``[406 AUTH_KEY_DUPLICATED]``, inviting you to login again. - -Why is that so? Because the server has recognized two identical sessions are running in two different locations, and -concludes it could possibly be due to a cloned/stolen device. Having the session terminated in such occasions will -protect the user's privacy. - -So, the only correct way to run multiple clients on the same account is authorizing your account (either user or bot) -from the beginning every time, and use one separate session for each parallel client you are going to use. - -I started a client and nothing happens! ---------------------------------------- - -If you are connecting from Russia, China or Iran :doc:`you need a proxy `, because Telegram could be -partially or totally blocked in those countries. More information about this block can be found at -`Wikipedia `_. - -Another possible cause might be network issues, either yours or Telegram's. To confirm this, add the following code on -the top of your script and run it again. You should see some error mentioning a socket timeout or an unreachable network -in a bunch of seconds: - -.. code-block:: python - - import logging - logging.basicConfig(level=logging.INFO) - -Another way to confirm you aren't able to connect to Telegram is by pinging the IP addresses below and see whether ping -fails or not. - -What are the IP addresses of Telegram Data Centers? ---------------------------------------------------- - -The Telegram cloud is currently composed by a decentralized, multi-DC infrastructure (currently 5 DCs, each of which can -work independently) spread in different locations worldwide. However, some of the less busy DCs have been lately -dismissed and their IP addresses are now kept as aliases to the nearest one. - -.. csv-table:: Production Environment - :header: ID, Location, IPv4, IPv6 - :widths: auto - :align: center - - DC1, "MIA, Miami FL, USA", ``149.154.175.53``, ``2001:b28:f23d:f001::a`` - DC2, "AMS, Amsterdam, NL", ``149.154.167.51``, ``2001:67c:4e8:f002::a`` - DC3*, "MIA, Miami FL, USA", ``149.154.175.100``, ``2001:b28:f23d:f003::a`` - DC4, "AMS, Amsterdam, NL", ``149.154.167.91``, ``2001:67c:4e8:f004::a`` - DC5, "SIN, Singapore, SG", ``91.108.56.130``, ``2001:b28:f23f:f005::a`` - -.. csv-table:: Test Environment - :header: ID, Location, IPv4, IPv6 - :widths: auto - :align: center - - DC1, "MIA, Miami FL, USA", ``149.154.175.10``, ``2001:b28:f23d:f001::e`` - DC2, "AMS, Amsterdam, NL", ``149.154.167.40``, ``2001:67c:4e8:f002::e`` - DC3*, "MIA, Miami FL, USA", ``149.154.175.117``, ``2001:b28:f23d:f003::e`` - -.. centered:: More info about the Test Environment can be found :doc:`here `. - -***** Alias DC - -Thanks to `@FrayxRulez `_ for telling about alias DCs. - -I want to migrate my account from DCX to DCY. ---------------------------------------------- - -This question is often asked by people who find their account(s) always being connected to DC1 - USA (for example), but -are connecting from a place far away (e.g DC4 - Europe), thus resulting in slower interactions when using the API -because of the great physical distance between the user and its associated DC. - -When registering an account for the first time, is up to Telegram to decide which DC the new user is going to be created -in, based on the phone number origin. - -Even though Telegram `documentations `_ state the server might -decide to automatically migrate a user in case of prolonged usages from a distant, unusual location and albeit this -mechanism is also `confirmed `_ to exist by Telegram itself, -it's currently not possible to have your account migrated, in any way, simply because the feature was once planned but -not yet implemented. - -Thanks to `@gabriel `_ for confirming the feature was not implemented yet. - -Why is my client reacting slowly in supergroups? ------------------------------------------------- - -This issue affects only some supergroups or only some members within the same supergroup. Mostly, it affects supergroups -whose creator's account (and thus the supergroup itself) lives inside a **different DC**, far away from yours, but could -also depend on where a member is connecting from. - -Because of how Telegram works internally, every single message you receive from and send to other members must pass -through the creator's DC, and in the worst case where you, the creator and another member all belong to three different -DCs, the other member messages have to go through from its DC to the creator's DC and finally to your DC. This process -will inevitably take its time. - - To confirm this theory and see it by yourself, you can test in a supergroup where you are sure all parties live - inside the same DC. In this case the responses will be faster. - -Another reason that makes responses come slowly is that messages are **dispatched by priority**. Depending on the kind -of member, some users receive messages faster than others and for big and busy supergroups the delay might become -noticeable, especially if you are among the lower end of the priority list: - -1. Creator. -2. Administrators. -3. Bots. -4. Mentioned users. -5. Recent online users. -6. Everyone else. - -Thanks to `@Manuel15 `_ for the priority list. - -I keep getting PEER_ID_INVALID error! -------------------------------------- - -The error in question is ``[400 PEER_ID_INVALID]``, and could mean several things: - -- The chat id you tried to use is simply wrong, double check it. -- The chat id refers to a group or channel you are not a member of. -- The chat id argument you passed is in form of a string; you have to convert it into an integer with ``int(chat_id)``. -- The chat id refers to a user or chat your current session hasn't met yet. - -About the last point: in order for you to meet a user and thus communicate with them, you should ask yourself how to -contact people using official apps. The answer is the same for Pyrogram too and involves normal usages such as searching -for usernames, meeting them in a common group, having their phone contacts saved, getting a message mentioning them -(either a forward or a mention in the message text) or obtaining the dialogs list. - -Code hangs when I stop, restart, add/remove_handler ---------------------------------------------------- - -You tried to ``.stop()``, ``.restart()``, ``.add_handler()`` or ``.remove_handler()`` *inside* a running handler, but -that can't be done because the way Pyrogram deals with handlers would make it hang. - -When calling one of the methods above inside an event handler, Pyrogram needs to wait for all running handlers to finish -in order to safely continue. In other words, since your handler is blocking the execution by waiting for the called -method to finish and since Pyrogram needs to wait for your handler to finish, you are left with a deadlock. - -The solution to this problem is to pass ``block=False`` to such methods so that they return immediately and the actual -code called asynchronously. - -UnicodeEncodeError: '' codec can't encode … ------------------------------------------------------ - -Where ```` might be *ascii*, *cp932*, *charmap* or anything else other than **utf-8**. This error usually -shows up when you try to print something and has very little to do with Pyrogram itself as it is strictly related to -your own terminal. To fix it, either find a way to change the encoding settings of your terminal to UTF-8 or switch to a -better terminal altogether. - -Uploading with URLs gives error WEBPAGE_CURL_FAILED ---------------------------------------------------- - -When uploading media files using an URL, the server automatically tries to download the media and uploads it to the -Telegram cloud. This error usually happens in case the provided URL is not publicly accessible by Telegram itself or the -media exceeds 20 MB in size. In such cases, your only option is to download the media yourself and upload from your -local machine. - -sqlite3.OperationalError: database is locked --------------------------------------------- - -This error occurs when more than one process is using the same session file, that is, when you run two or more clients -at the same time using the same session name. - -It could also occur when a background script is still running and you forgot about it. In this case, you either restart -your system or find and kill the process that is locking the database. On Unix based systems, you can do the following: - -#. ``cd`` into your session file directory. -#. ``fuser my_account.session`` to find the process id. -#. ``kill 1234`` to gracefully stop the process. -#. If the last command doesn't help, use ``kill -9 1234`` instead. - -If you want to run multiple clients on the same account, you must authorize your account (either user or bot) -from the beginning every time, and use different session names for each parallel client you are going to use. - -sqlite3.OperationalError: unable to open database file ------------------------------------------------------- - -Stackoverflow to the rescue: https://stackoverflow.com/questions/4636970 - -sqlite3.InterfaceError: Error binding parameter 0 -------------------------------------------------- - -This error occurs when you pass a chat id value of the wrong type when trying to call a method. Most likely, you -accidentally passed the whole user or chat object instead of the id or username. - -.. code-block:: python - - # Wrong. You passed the whole Chat instance - app.send_message(chat, "text") - - # Correct - app.send_message(chat.id, "text") - -My verification code expires immediately! ------------------------------------------ - -That is because you likely shared it across any of your Telegram chats. Yes, that's right: the server keeps scanning the -messages you send and if an active verification code is found it will immediately expire, automatically. - -The reason behind this is to protect unaware users from giving their account access to any potential scammer, but if you -legitimately want to share your account(s) verification codes, consider scrambling them, e.g. ``12345`` → ``1-2-3-4-5``. - -How can avoid Flood Waits? --------------------------- - -Long story short: make less requests, and remember that the API is designed to be used by official apps, by real people; -anything above normal usage could be limited. - -This question is being asked quite a lot of times, but the bottom line is that nobody knows the exact limits and it's -unlikely that such information will be ever disclosed, because otherwise people could easily circumvent them and defeat -their whole purpose. - -Do also note that Telegram wants to be a safe and reliable place and that limits exist to protect itself from abuses. -Having said that, here's some insights about limits: - -- They are tuned by Telegram based on real people usage and can change anytime. -- Some limits are be applied to single sessions, some others apply to the whole account. -- Limits vary based on methods and the arguments passed to methods. For example: log-ins are expensive and thus have - stricter limits; replying to a user command could cause a flood wait in case the user starts flooding, but - such limit will only be applied to that particular chat (i.e.: other users are not affected). -- You can catch Flood Wait exceptions in your code and wait the required seconds before continuing, this way: - - .. code-block:: python - - import time - from pyrogram.errors import FloodWait - - try: - ... # Your code - except FloodWait as e: - time.sleep(e.x) # Wait "x" seconds before continuing - - - More info about error handling can be found `here `_. - -My account has been deactivated/limited! ----------------------------------------- - -First of all, you should understand that Telegram wants to be a safe place for people to stay in, and to pursue this -goal there are automatic protection systems running to prevent flood and spam, as well as a moderation team of humans -who review reports. - -.. centered:: Pyrogram is a tool at your commands; it only does what you tell it to do, the rest is up to you. - -Having said that, here's a list of what Telegram definitely doesn't like: - -- Flood, abusing the API. -- Spam, sending unsolicited messages or adding people to unwanted groups and channels. -- Virtual/VoIP and cheap real numbers, because they are relatively easy to get and likely used for spam/flood. - -And thanks to `@koteeq `_, here's a good explanation of how, probably, the system works: - -.. raw:: html - - -

- -However, you might be right, and your account was deactivated/limited without any good reason. This could happen because -of mistakes by either the automatic systems or a moderator. In such cases you can kindly email Telegram at -recover@telegram.org, contact `@smstelegram`_ on Twitter or use `this form`_. - -Are there any secret easter eggs? ---------------------------------- - -Yes. If you found one, `let me know`_! - -.. _let me know: https://t.me/pyrogram - -.. _@smstelegram: https://twitter.com/smstelegram -.. _this form: https://telegram.org/support - -.. _Bug Report: https://github.com/pyrogram/pyrogram/issues/new?labels=bug&template=bug_report.md -.. _Feature Request: https://github.com/pyrogram/pyrogram/issues/new?labels=enhancement&template=feature_request.md diff --git a/docs/source/faq/client-started-but-nothing-happens.rst b/docs/source/faq/client-started-but-nothing-happens.rst new file mode 100644 index 0000000000..ab85f51832 --- /dev/null +++ b/docs/source/faq/client-started-but-nothing-happens.rst @@ -0,0 +1,11 @@ +Client started, but nothing happens +=================================== + +A possible cause might be network issues, either yours or Telegram's. To check this, add the following code at +the top of your script and run it again. You should see some error mentioning a socket timeout or an unreachable +network: + +.. code-block:: python + + import logging + logging.basicConfig(level=logging.INFO) \ No newline at end of file diff --git a/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst b/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst new file mode 100644 index 0000000000..37d47a6444 --- /dev/null +++ b/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst @@ -0,0 +1,12 @@ +Code hangs when calling stop, restart, add/remove_handler +========================================================= + +You tried to ``.stop()``, ``.restart()``, ``.add_handler()`` or ``.remove_handler()`` inside a running handler, but +that can't be done because the way Pyrogram deals with handlers would make it hang. + +When calling one of the methods above inside an event handler, Pyrogram needs to wait for all running handlers to finish +in order to continue. Since your handler is blocking the execution by waiting for the called method to finish +and since Pyrogram needs to wait for your handler to finish, you are left with a deadlock. + +The solution to this problem is to pass ``block=False`` to such methods so that they return immediately and the actual +code called asynchronously. \ No newline at end of file diff --git a/docs/source/faq/how-to-avoid-flood-waits.rst b/docs/source/faq/how-to-avoid-flood-waits.rst new file mode 100644 index 0000000000..0736e576f2 --- /dev/null +++ b/docs/source/faq/how-to-avoid-flood-waits.rst @@ -0,0 +1,23 @@ +How to avoid Flood Waits? +========================= + +Slow things down and make less requests. Moreover, exact limits are unknown and can change anytime based on normal +usages. + +When a flood wait happens the server will tell you how much time to wait before continuing. +The following shows how to catch the exception in your code and wait the required seconds. + +.. code-block:: python + + import time + from pyrogram.errors import FloodWait + + ... + try: + ... # Your code + except FloodWait as e: + await asyncio.sleep(e.x) # Wait "x" seconds before continuing + ... + + +More info about error handling can be found :doc:`here <../start/errors>`. \ No newline at end of file diff --git a/docs/source/faq/how-to-use-webhooks.rst b/docs/source/faq/how-to-use-webhooks.rst new file mode 100644 index 0000000000..b0dd4008cd --- /dev/null +++ b/docs/source/faq/how-to-use-webhooks.rst @@ -0,0 +1,9 @@ +How to use webhooks? +==================== + +There is no webhook in Pyrogram, simply because there is no HTTP involved. However, a similar technique is +being used to make receiving updates efficient. + +Pyrogram uses persistent connections via TCP sockets to interact with the server and instead of actively asking for +updates every time (polling), Pyrogram will sit down and wait for the server to send updates by itself the very moment +they are available (server push). diff --git a/docs/source/faq/index.rst b/docs/source/faq/index.rst new file mode 100644 index 0000000000..0b16534943 --- /dev/null +++ b/docs/source/faq/index.rst @@ -0,0 +1,47 @@ +Frequently Asked Questions +========================== + +This FAQ page provides answers to common questions about Pyrogram and, to some extent, Telegram in general. + +**Contents** + +- :doc:`why-is-the-api-key-needed-for-bots` +- :doc:`how-to-use-webhooks` +- :doc:`using-the-same-file-id-across-different-accounts` +- :doc:`using-multiple-clients-at-once-on-the-same-account` +- :doc:`client-started-but-nothing-happens` +- :doc:`what-are-the-ip-addresses-of-telegram-data-centers` +- :doc:`migrating-the-account-to-another-data-center` +- :doc:`why-is-the-client-reacting-slowly-in-supergroups-channels` +- :doc:`peer-id-invalid-error` +- :doc:`code-hangs-when-calling-stop-restart-add-remove-handler` +- :doc:`unicodeencodeerror-codec-cant-encode` +- :doc:`uploading-with-urls-gives-error-webpage-curl-failed` +- :doc:`why-is-the-event-handler-triggered-twice-or-more` +- :doc:`sqlite3-operationalerror-database-is-locked` +- :doc:`sqlite3-interfaceerror-error-binding-parameter` +- :doc:`socket-send-raised-exception-oserror-timeouterror` +- :doc:`how-to-avoid-flood-waits` +- :doc:`the-account-has-been-limited-deactivated` + +.. toctree:: + :hidden: + + why-is-the-api-key-needed-for-bots + how-to-use-webhooks + using-the-same-file-id-across-different-accounts + using-multiple-clients-at-once-on-the-same-account + client-started-but-nothing-happens + what-are-the-ip-addresses-of-telegram-data-centers + migrating-the-account-to-another-data-center + why-is-the-client-reacting-slowly-in-supergroups-channels + peer-id-invalid-error + code-hangs-when-calling-stop-restart-add-remove-handler + unicodeencodeerror-codec-cant-encode + uploading-with-urls-gives-error-webpage-curl-failed + why-is-the-event-handler-triggered-twice-or-more + sqlite3-operationalerror-database-is-locked + sqlite3-interfaceerror-error-binding-parameter + socket-send-raised-exception-oserror-timeouterror + how-to-avoid-flood-waits + the-account-has-been-limited-deactivated \ No newline at end of file diff --git a/docs/source/faq/migrating-the-account-to-another-data-center.rst b/docs/source/faq/migrating-the-account-to-another-data-center.rst new file mode 100644 index 0000000000..7ae76a1e36 --- /dev/null +++ b/docs/source/faq/migrating-the-account-to-another-data-center.rst @@ -0,0 +1,10 @@ +Migrating the account to another data center +============================================ + +This question is asked by people who find their account always being connected to one DC (data center), but are +connecting from a place far away, thus resulting in slower interactions when using the API because of the greater +physical distance between the user and the associated DC. + +When registering an account for the first time, is up to Telegram to decide which DC the new user is going to be +created in. It's also up to the server to decide whether to automatically migrate a user in case of prolonged usages +from a distant location. \ No newline at end of file diff --git a/docs/source/faq/peer-id-invalid-error.rst b/docs/source/faq/peer-id-invalid-error.rst new file mode 100644 index 0000000000..197ea8374d --- /dev/null +++ b/docs/source/faq/peer-id-invalid-error.rst @@ -0,0 +1,14 @@ +PEER_ID_INVALID error +===================== + +This error could mean several things: + +- The chat id you tried to use is simply wrong, check it again. +- The chat id refers to a group or channel you are not a member of. +- The chat id argument you passed is in form of a string; you have to convert it into an integer with ``int(chat_id)``. +- The chat id refers to a user or chat your current session hasn't met yet. + +About the last point: in order for you to meet a user and thus communicate with them, you should ask yourself how to +contact people using official apps. The answer is the same for Pyrogram too and involves normal usages such as searching +for usernames, meeting them in a common group, having their phone contacts saved, getting a message mentioning them +or obtaining the dialogs list. \ No newline at end of file diff --git a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst new file mode 100644 index 0000000000..e6a934d2e9 --- /dev/null +++ b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst @@ -0,0 +1,10 @@ +socket.send() raised exception, OSError(), TimeoutError() +========================================================= + +If you get this error chances are you are blocking the event loop for too long. +In general, it means you are executing thread-blocking code that prevents the event loop from +running properly. For example: + +- You are using ``time.sleep()`` instead of ``asyncio.sleep()``. +- You are running processing loops that take too much time to complete. +- You are reading/writing files to disk that take too much time to complete. \ No newline at end of file diff --git a/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst b/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst new file mode 100644 index 0000000000..5d148186b6 --- /dev/null +++ b/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst @@ -0,0 +1,13 @@ +sqlite3.InterfaceError: Error binding parameter +=============================================== + +This error occurs when you pass a chat id value of the wrong type when trying to call a method. Most likely, you +accidentally passed the whole user or chat object instead of the id or username. + +.. code-block:: python + + # Wrong. You passed the whole Chat instance + app.send_message(chat, "text") + + # Correct + app.send_message(chat.id, "text") \ No newline at end of file diff --git a/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst b/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst new file mode 100644 index 0000000000..b5cb2d8293 --- /dev/null +++ b/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst @@ -0,0 +1,17 @@ +sqlite3.OperationalError: database is locked +============================================ + +This error occurs when more than one process is using the same session file, that is, when you run two or more clients +at the same time using the same session name or in case another program has accessed the file. + +For example, it could occur when a background script is still running and you forgot about it. In this case, you either +restart your system or find and kill the process that is locking the database. On Unix based systems, you can try the +following: + +#. ``cd`` into your session file directory. +#. ``fuser my_account.session`` to find the process id. +#. ``kill 1234`` to gracefully stop the process. +#. If the last command doesn't help, use ``kill -9 1234`` instead. + +If you want to run multiple clients on the same account, you must authorize your account (either user or bot) +from the beginning every time, and use different session names for each parallel client you are going to use. \ No newline at end of file diff --git a/docs/source/faq/the-account-has-been-limited-deactivated.rst b/docs/source/faq/the-account-has-been-limited-deactivated.rst new file mode 100644 index 0000000000..79d589eaf8 --- /dev/null +++ b/docs/source/faq/the-account-has-been-limited-deactivated.rst @@ -0,0 +1,16 @@ +The account has been limited/deactivated +======================================== + +Pyrogram is a framework that interfaces with Telegram; it is at your commands, meaning it only does what you tell it to +do, the rest is up to you and Telegram (see `Telegram's ToS`_). + +If you found your account being limited/deactivated, it could be due spam/flood/abuse of the API or the usage of certain +virtual/VoIP numbers. + +If you think your account was limited/deactivated by mistake, you can write to recover@telegram.org, contact +`@SpamBot`_ or use `this form`_. + +.. _@SpamBot: https://t.me/spambot +.. _this form: https://telegram.org/support +.. _Telegram's ToS: https://telegram.org/tos + diff --git a/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst b/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst new file mode 100644 index 0000000000..a4511ce5d1 --- /dev/null +++ b/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst @@ -0,0 +1,7 @@ +UnicodeEncodeError: '...' codec can't encode ... +================================================ + +Where ```` might be *ascii*, *cp932*, *charmap* or anything else other than *utf-8*. This error usually +shows up when you try to print something and has very little to do with Pyrogram itself as it is strictly related to +your own terminal. To fix it, either find a way to change the encoding settings of your terminal to UTF-8 or switch to +another terminal altogether. diff --git a/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst b/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst new file mode 100644 index 0000000000..2b7c5a7e9f --- /dev/null +++ b/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst @@ -0,0 +1,7 @@ +Uploading with URLs gives error WEBPAGE_CURL_FAILED +=================================================== + +When uploading media files using an URL, the server automatically tries to download the media and uploads it to the +Telegram cloud. This error usually happens in case the provided URL is not publicly accessible by Telegram itself or the +media file is too large. In such cases, your only option is to download the media yourself and upload it from your +local machine. \ No newline at end of file diff --git a/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst b/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst new file mode 100644 index 0000000000..ab73b29c1d --- /dev/null +++ b/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst @@ -0,0 +1,7 @@ +Using multiple clients at once on the same account +================================================== + +Both user and bot accounts are able to run multiple sessions in parallel. However, you must not use the same session +in more than one client at the same time. The correct way to run multiple clients on the same account is by authorizing +your account (either user or bot) from the beginning each time, and use one separate session for each parallel client. + diff --git a/docs/source/faq/using-the-same-file-id-across-different-accounts.rst b/docs/source/faq/using-the-same-file-id-across-different-accounts.rst new file mode 100644 index 0000000000..00305ef12d --- /dev/null +++ b/docs/source/faq/using-the-same-file-id-across-different-accounts.rst @@ -0,0 +1,6 @@ +Using the same file_id across different accounts +================================================ + +Telegram file_id strings are bound to the account which generated them. An attempt in using a foreign file id will +result in errors such as ``[400 MEDIA_EMPTY]``. The only exception are stickers' file ids; you can use them across +different accounts without any problem. \ No newline at end of file diff --git a/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst b/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst new file mode 100644 index 0000000000..c951230ba6 --- /dev/null +++ b/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst @@ -0,0 +1,30 @@ +What are the IP addresses of Telegram Data Centers? +=================================================== + +Telegram is currently composed by a decentralized, multi-DC infrastructure (currently 5 DCs, each of which can +work independently) spread across different locations worldwide. However, some of the less busy DCs have been lately +dismissed and their IP addresses are now kept as aliases to the nearest one. + +.. csv-table:: Production Environment + :header: ID, Location, IPv4, IPv6 + :widths: auto + :align: center + + DC1, "MIA, Miami FL, USA", ``149.154.175.53``, ``2001:b28:f23d:f001::a`` + DC2, "AMS, Amsterdam, NL", ``149.154.167.51``, ``2001:67c:4e8:f002::a`` + DC3*, "MIA, Miami FL, USA", ``149.154.175.100``, ``2001:b28:f23d:f003::a`` + DC4, "AMS, Amsterdam, NL", ``149.154.167.91``, ``2001:67c:4e8:f004::a`` + DC5, "SIN, Singapore, SG", ``91.108.56.130``, ``2001:b28:f23f:f005::a`` + +.. csv-table:: Test Environment + :header: ID, Location, IPv4, IPv6 + :widths: auto + :align: center + + DC1, "MIA, Miami FL, USA", ``149.154.175.10``, ``2001:b28:f23d:f001::e`` + DC2, "AMS, Amsterdam, NL", ``149.154.167.40``, ``2001:67c:4e8:f002::e`` + DC3*, "MIA, Miami FL, USA", ``149.154.175.117``, ``2001:b28:f23d:f003::e`` + +.. centered:: More info about the Test Environment can be found :doc:`here <../topics/test-servers>`. + +***** Alias DC \ No newline at end of file diff --git a/docs/source/faq/why-is-the-api-key-needed-for-bots.rst b/docs/source/faq/why-is-the-api-key-needed-for-bots.rst new file mode 100644 index 0000000000..2e062d405d --- /dev/null +++ b/docs/source/faq/why-is-the-api-key-needed-for-bots.rst @@ -0,0 +1,12 @@ +Why is the API key needed for bots? +=================================== + +Requests against the official bot API endpoints are made via JSON/HTTP and are handled by an intermediate server +application that implements the MTProto protocol and uses its own API key to communicate with the MTProto servers. + +.. figure:: //_static/img/mtproto-vs-bot-api.png + :align: center + +Using MTProto is the only way to communicate with the actual Telegram servers, and the main API requires developers to +identify applications by means of a unique key; the bot token identifies a bot as a user and replaces the user's phone +number only. \ No newline at end of file diff --git a/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst b/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst new file mode 100644 index 0000000000..4d19616469 --- /dev/null +++ b/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst @@ -0,0 +1,18 @@ +Why is the client reacting slowly in supergroups/channels? +========================================================== + +Because of how Telegram works internally, every message you receive and send must pass through the creator's DC, and in +the worst case where you, the creator and another member all belong to three different DCs, the other member messages +have to go through from their DC to the creator's DC and finally to your DC. This is applied to each message and member +of a supergroup/channel and the process will inevitably take its time. + +Another reason that makes responses come slowly is that messages are dispatched by priority. Depending on the kind +of member, some users receive messages faster than others and for big and busy supergroups the delay might become +noticeable, especially if you are among the lower end of the priority list: + +1. Creator. +2. Administrators. +3. Bots. +4. Mentioned users. +5. Recent online users. +6. Everyone else. \ No newline at end of file diff --git a/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst b/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst new file mode 100644 index 0000000000..ada12f1de3 --- /dev/null +++ b/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst @@ -0,0 +1,28 @@ +Why is the event handler called twice or more? +============================================== + +The event handler is being called twice or more because one or more message edit events have arrived. +By default, Pyrogram listens to both new and edit message events inside ``on_message`` handlers. To prevent edit events +from calling the handler, use the "not edited" filter ``~filters.edited``. + +For example: + +.. code-block:: python + + ... + + @app.on_message(... & ~filters.edited) + async def handler(client, message): + ... + +Or, avoid handling any edited message altogether this way: + +.. code-block:: python + + ... + + @app.on_message(filters.edited) + async def edited(client, message): + pass + + ... # other handlers \ No newline at end of file diff --git a/docs/source/glossary.rst b/docs/source/glossary.rst deleted file mode 100644 index fa6086ce6c..0000000000 --- a/docs/source/glossary.rst +++ /dev/null @@ -1,86 +0,0 @@ -Pyrogram Glossary -================= - -This page contains a list of common words with brief explanations related to Pyrogram and, to some extent, Telegram in -general. Some words may as well link to dedicated articles in case the topic is covered in a more detailed fashion. - -.. tip:: - - If you think something interesting could be added here, feel free to propose it by opening a `Feature Request`_. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Terms ------ - -.. glossary:: - :sorted: - - API - Application Programming Interface: a set of methods, protocols and tools that make it easier to develop programs - by providing useful building blocks to the developer. - - API key - A secret code used to authenticate and/or authorize a specific application to Telegram in order for it to - control how the API is being used, for example, to prevent abuses of the API. - :doc:`More on API keys `. - - DC - Also known as *data center*, is a place where lots of computer systems are housed and used together in order to - achieve high quality and availability for services. - - RPC - Acronym for Remote Procedure Call, that is, a function which gets executed at some remote place (i.e. Telegram - server) and not in your local machine. - - RPCError - An error caused by an RPC which must be returned in place of the successful result in order to let the caller - know something went wrong. :doc:`More on RPCError `. - - MTProto - The name of the custom-made, open and encrypted protocol by Telegram, implemented in Pyrogram. - :doc:`More on MTProto `. - - MTProto API - The Telegram main API Pyrogram makes use of, which is able to connect both users and normal bots to Telegram - using MTProto as application layer protocol and execute any method Telegram provides from its public TL-schema. - :doc:`More on MTProto API `. - - Bot API - The Telegram Bot API that is able to only connect normal bots only to Telegram using HTTP as application layer - protocol and allows to execute a sub-set of the main Telegram API. - :doc:`More on Bot API `. - - Pyrogrammer - A developer that uses Pyrogram to build Telegram applications. - - Userbot - Also known as *user bot* or *ubot* for short, is a user logged in by third-party Telegram libraries --- such as - Pyrogram --- to automate some behaviours, like sending messages or reacting to text commands or any other event. - Not to be confused with *bot*, that is, a normal Telegram bot created by `@BotFather `_. - - Session - Also known as *login session*, is a strictly personal piece of data created and held by both parties - (client and server) which is used to grant permission into a single account without having to start a new - authorization process from scratch. - - Callback - Also known as *callback function*, is a user-defined generic function that *can be* registered to and then - called-back by the framework when specific events occurs. - - Handler - An object that wraps around a callback function that is *actually meant* to be registered into the framework, - which will then be able to handle a specific kind of events, such as a new incoming message, for example. - :doc:`More on Handlers `. - - Decorator - Also known as *function decorator*, in Python, is a callable object that is used to modify another function. - Decorators in Pyrogram are used to automatically register callback functions for handling updates. - :doc:`More on Decorators `. - -.. _Feature Request: https://github.com/pyrogram/pyrogram/issues/new?labels=enhancement&template=feature_request.md diff --git a/docs/source/index.rst b/docs/source/index.rst index 3834853434..8838c3db17 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -5,7 +5,8 @@ Welcome to Pyrogram @@ -14,15 +15,15 @@ Welcome to Pyrogram
- Source Code + Development • - + Releases • - - Community + + News

@@ -35,16 +36,34 @@ Welcome to Pyrogram @app.on_message(filters.private) async def hello(client, message): - await message.reply_text(f"Hello {message.from_user.mention}") + await message.reply("Hello from Pyrogram!") app.run() -**Pyrogram** is a modern, elegant and easy-to-use Telegram_ framework written from the ground up in Python and C. -It enables you to easily create custom apps for both user and bot identities (bot API alternative) via the -:doc:`MTProto API `. +**Pyrogram** is a modern, elegant and asynchronous :doc:`MTProto API ` framework. +It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity +(bot API alternative) using Python. -.. _Telegram: https://telegram.org +Support +------- + +If you'd like to support Pyrogram, you can consider: + +- `Become a GitHub sponsor `_. +- `Become a LiberaPay patron `_. +- `Become an OpenCollective backer `_. + +Key Features +------------ + +- **Ready**: Install Pyrogram with pip and start building your applications right away. +- **Easy**: Makes the Telegram API simple and intuitive, while still allowing advanced usages. +- **Elegant**: Low-level details are abstracted and re-presented in a more convenient way. +- **Fast**: Boosted up by :doc:`TgCrypto `, a high-performance crypto library written in pure C. +- **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. +- **Async**: Fully asynchronous (also usable synchronously if wanted, for convenience). +- **Powerful**: Full access to Telegram's API to execute any official client action and more. How the Documentation is Organized ---------------------------------- @@ -53,18 +72,11 @@ Contents are organized into sections composed of self-contained topics which can following them in order using the :guilabel:`Next` button at the end of each page. Here below you can, instead, find a list of the most relevant pages for a quick access. -.. admonition :: Cloud Credits - :class: tip - - If you need a cloud server to host your applications, we recommend using **Hetzner Cloud**. Sign up with - `this link `_ to get €20 in cloud credits and help support Pyrogram as - well. - First Steps ^^^^^^^^^^^ .. hlist:: - :columns: 2 + :columns: 1 - :doc:`Quick Start `: Overview to get you started quickly. - :doc:`Calling Methods `: How to call Pyrogram's methods. @@ -75,7 +87,7 @@ API Reference ^^^^^^^^^^^^^ .. hlist:: - :columns: 2 + :columns: 1 - :doc:`Pyrogram Client `: Reference details about the Client class. - :doc:`Available Methods `: List of available high-level methods. @@ -86,16 +98,12 @@ Meta ^^^^ .. hlist:: - :columns: 2 + :columns: 1 - - :doc:`Pyrogram FAQ `: Answers to common Pyrogram questions. - - :doc:`Pyrogram Glossary `: List of words with brief explanations. + - :doc:`Pyrogram FAQ `: Answers to common Pyrogram questions. - :doc:`Support Pyrogram `: Ways to show your appreciation. - - :doc:`About the License `: Information about the Project license. - :doc:`Release Notes `: Release notes for Pyrogram releases. -Last updated on |today| - .. toctree:: :hidden: :caption: Introduction @@ -136,14 +144,13 @@ Last updated on |today| topics/more-on-updates topics/config-file topics/smart-plugins - topics/session-settings + topics/client-settings topics/tgcrypto topics/storage-engines topics/text-formatting topics/serializing topics/proxy topics/scheduling - topics/bots-interaction topics/mtproto-vs-botapi topics/debugging topics/test-servers @@ -154,10 +161,8 @@ Last updated on |today| :hidden: :caption: Meta - faq - glossary + faq/index support - license releases/index .. toctree:: diff --git a/docs/source/intro/install.rst b/docs/source/intro/install.rst index 813961dcac..67a6b9432d 100644 --- a/docs/source/intro/install.rst +++ b/docs/source/intro/install.rst @@ -1,16 +1,9 @@ Install Guide ============= -Being a modern Python library, **Pyrogram** requires Python 3.6+ to be installed in your system. +Being a modern Python framework, Pyrogram requires an up to date version of Python to be installed in your system. We recommend using the latest versions of both Python 3 and pip. -- Get **Python 3** from https://www.python.org/downloads/ (or with your package manager). -- Get **pip** by following the instructions at https://pip.pypa.io/en/latest/installing/. - -.. important:: - - Pyrogram supports **Python 3** only, starting from version 3.6. **PyPy** is supported too. - .. contents:: Contents :backlinks: none :depth: 1 @@ -36,12 +29,7 @@ Install Pyrogram Bleeding Edge ------------- -Pyrogram is always evolving, although new releases on PyPI are published only when enough changes are added, but this -doesn't mean you can't try new features right now! - -In case you'd like to try out the latest Pyrogram features, the `GitHub repo`_ is always kept updated with new changes; -you can install the development version straight from the ``master`` branch using this command (note "master.zip" in -the link): +You can install the development version from the git ``master`` branch using this command: .. code-block:: text @@ -57,6 +45,6 @@ If no error shows up you are good to go. >>> import pyrogram >>> pyrogram.__version__ - '|version|' + 'x.y.z' .. _`Github repo`: http://github.com/pyrogram/pyrogram diff --git a/docs/source/intro/quickstart.rst b/docs/source/intro/quickstart.rst index eeb9848264..0981d14794 100644 --- a/docs/source/intro/quickstart.rst +++ b/docs/source/intro/quickstart.rst @@ -1,49 +1,54 @@ Quick Start =========== -The next few steps serve as a quick start for all new :term:`Pyrogrammers ` that want to see Pyrogram in -action as fast as possible. Let's go! +The next few steps serve as a quick start to see Pyrogram in action as fast as possible. Get Pyrogram Real Fast ---------------------- +.. admonition :: Cloud Credits + :class: tip + + If you need a cloud server to host your applications, try Hetzner Cloud. You can sign up with + `this link `_ to get €20 in cloud credits. + 1. Install Pyrogram with ``pip3 install -U pyrogram``. 2. Get your own Telegram API key from https://my.telegram.org/apps. -3. Open your best text editor and paste the following: +3. Open the text editor of your choice and paste the following: .. code-block:: python + import asyncio from pyrogram import Client api_id = 12345 api_hash = "0123456789abcdef0123456789abcdef" - with Client("my_account", api_id, api_hash) as app: - app.send_message("me", "Greetings from **Pyrogram**!") + async def main(): + async with Client("my_account", api_id, api_hash) as app: + await app.send_message("me", "Greetings from **Pyrogram**!") + + asyncio.run(main()) 4. Replace *api_id* and *api_hash* values with your own. -5. Save the file as ``pyro.py``. +5. Save the file as ``hello.py``. -6. Run the script with ``python3 pyro.py`` +6. Run the script with ``python3 hello.py`` 7. Follow the instructions on your terminal to login. 8. Watch Pyrogram send a message to yourself. -9. Join our `community`_. - -10. Say, "hi!". - Enjoy the API ------------- -That was just a quick overview that barely scratched the surface! -In the next few pages of the introduction, we'll take a much more in-depth look of what we have just done above. +That was just a quick overview. In the next few pages of the introduction, we'll take a much more in-depth look of what +we have just done above. -Feeling eager to continue? You can take a shortcut to :doc:`Calling Methods <../start/invoking>` and come back later to -learn some more details. +If you are feeling eager to continue you can take a shortcut to :doc:`Calling Methods <../start/invoking>` and come back +later to learn some more details. .. _community: https://t.me/Pyrogram diff --git a/docs/source/intro/setup.rst b/docs/source/intro/setup.rst index e4c6e64065..8bffcd86b4 100644 --- a/docs/source/intro/setup.rst +++ b/docs/source/intro/setup.rst @@ -2,7 +2,7 @@ Project Setup ============= We have just :doc:`installed Pyrogram `. In this page we'll discuss what you need to do in order to set up a -project with the library. Let's see how it's done. +project with the framework. .. contents:: Contents :backlinks: none @@ -17,18 +17,13 @@ API Keys The very first step requires you to obtain a valid Telegram API key (API id/hash pair): #. 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 API key consists of two parts: **api_id** and **api_hash**. - -.. important:: - - The API key is personal and must be kept secret. +#. Fill out the form with your details and register a new Telegram application. +#. Done. The API key consists of two parts: **api_id** and **api_hash**. Keep it secret. .. note:: - The API key is unique for each user, but defines a token for a Telegram *application* you are going to build. This - means that you are able to authorize multiple users (and bots too) to access the Telegram database through the - MTProto API by a single API key. + The API key defines a token for a Telegram *application* you are going to build. + This means that you are able to authorize multiple users or bots with a single API key. Configuration ------------- @@ -36,9 +31,9 @@ Configuration Having the API key from the previous step in handy, we can now begin to configure a Pyrogram project. There are two ways to do so, and you can choose what fits better for you: -- First option (recommended): create a new ``config.ini`` file next to your main script, copy-paste the following and - replace the **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: +- First option: create a new ``config.ini`` file next to your main script, copy-paste the following and + replace the *api_id* and *api_hash* values with your own. This method allows you to keep your credentials out of + your code without having to deal with how to load them. .. code-block:: ini @@ -47,8 +42,7 @@ There are two ways to do so, and you can choose what fits better for you: api_hash = 0123456789abcdef0123456789abcdef - Alternatively, you can pass your API key to Pyrogram by simply using the *api_id* and *api_hash* parameters of the - Client class. This way you can have full control on how to store and load your credentials (e.g., you can load the - credentials from the environment variables and directly pass the values into Pyrogram): + Client class. This way you can have full control on how to store and load your credentials: .. code-block:: python diff --git a/docs/source/license.rst b/docs/source/license.rst deleted file mode 100644 index 5f1d25ee0d..0000000000 --- a/docs/source/license.rst +++ /dev/null @@ -1,16 +0,0 @@ -About the License -================= - -.. image:: https://www.gnu.org/graphics/lgplv3-with-text-154x68.png - :align: left - -Pyrogram is free software and is currently licensed under the terms of the -`GNU Lesser General Public License v3 or later (LGPLv3+)`_. In short: you may use, redistribute and/or modify it -provided that modifications are described and licensed for free under LGPLv3+. - -In other words: you can use and integrate Pyrogram into your code (either open source, under the same or a different -license, or even proprietary) for any purpose whatsoever without being required to release the source code of your -applications. Derivative works, including modifications to the library itself can only be redistributed under the same -LGPLv3+ license. - -.. _GNU Lesser General Public License v3 or later (LGPLv3+): https://github.com/pyrogram/pyrogram/blob/develop/COPYING.lesser diff --git a/docs/source/start/auth.rst b/docs/source/start/auth.rst index 23ff9fe276..0e61e59d11 100644 --- a/docs/source/start/auth.rst +++ b/docs/source/start/auth.rst @@ -26,23 +26,20 @@ the :meth:`~pyrogram.Client.run` method: app = Client("my_account") app.run() -This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_) and the -**phone code** you will receive in your devices that are already authorized or via SMS: +This starts an interactive shell asking you to input your **phone number**, including your `Country Code`_ (the plus +``+`` and minus ``-`` symbols can be omitted) and the **phone code** you will receive in your devices that are already +authorized or via SMS: .. code-block:: text - Enter phone number: +39********** - Is "+39**********" correct? (y/n): y - Enter phone code: 32768 - Logged in successfully as Dan + Enter phone number: +1-123-456-7890 + Is "+1-123-456-7890" correct? (y/n): y + Enter phone code: 12345 + Logged in successfully After successfully authorizing yourself, a new file called ``my_account.session`` will be created allowing Pyrogram to -execute 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 is personal and must be kept secret. +execute API calls with your identity. This file is personal and 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. .. note:: diff --git a/docs/source/start/errors.rst b/docs/source/start/errors.rst index 8e592f18c7..5f59deef6c 100644 --- a/docs/source/start/errors.rst +++ b/docs/source/start/errors.rst @@ -1,8 +1,8 @@ Error Handling ============== -Errors are inevitable when working with the API, and they can be correctly handled with ``try...except`` blocks in order -to control the behaviour of your application. Pyrogram errors all live inside the ``errors`` package: +Errors can be correctly handled with ``try...except`` blocks in order to control the behaviour of your application. +Pyrogram errors all live inside the ``errors`` package: .. code-block:: python @@ -25,10 +25,10 @@ This error is raised every time a method call against Telegram's API was unsucce from pyrogram.errors import RPCError -.. warning:: +.. note:: - It must be noted that catching this error is bad practice, especially when no feedback is given (i.e. by - logging/printing the full error traceback), because it makes it impossible to understand what went wrong. + Avoid catching this error everywhere, especially when no feedback is given (i.e. by logging/printing the full error + traceback), because it makes it impossible to understand what went wrong. Error Categories ---------------- @@ -84,9 +84,6 @@ whole category of errors and be sure to also handle these unknown errors. In case a whole class of errors is unknown (that is, an error code that is unknown), Pyrogram will raise a special ``520 UnknownError`` exception. -In both cases, Pyrogram will log them in the ``unknown_errors.txt`` file. Users are invited to report -these unknown errors in the `discussion group `_. - Errors with Values ------------------ diff --git a/docs/source/start/examples/bot_keyboards.rst b/docs/source/start/examples/bot_keyboards.rst index 6e288c4314..a3a549f4df 100644 --- a/docs/source/start/examples/bot_keyboards.rst +++ b/docs/source/start/examples/bot_keyboards.rst @@ -19,7 +19,7 @@ like send_audio(), send_document(), send_location(), etc... with app: app.send_message( - "haskell", # Edit this + "me", # Edit this "This is a ReplyKeyboardMarkup example", reply_markup=ReplyKeyboardMarkup( [ @@ -33,7 +33,7 @@ like send_audio(), send_document(), send_location(), etc... ) app.send_message( - "haskell", # Edit this + "me", # Edit this "This is a InlineKeyboardMarkup example", reply_markup=InlineKeyboardMarkup( [ diff --git a/docs/source/start/examples/echobot.rst b/docs/source/start/examples/echobot.rst index 61dc9929da..2ff578e97d 100644 --- a/docs/source/start/examples/echobot.rst +++ b/docs/source/start/examples/echobot.rst @@ -15,7 +15,7 @@ It uses the ``@on_message`` decorator to register a ``MessageHandler`` and appli @app.on_message(filters.text & filters.private) def echo(client, message): - message.reply_text(message.text) + message.reply(message.text) app.run() # Automatically start() and idle() \ No newline at end of file diff --git a/docs/source/start/examples/hello_world.rst b/docs/source/start/examples/hello_world.rst index e68847798a..997659e237 100644 --- a/docs/source/start/examples/hello_world.rst +++ b/docs/source/start/examples/hello_world.rst @@ -13,9 +13,3 @@ This example demonstrates a basic API usage with app: # Send a message, Markdown is enabled by default app.send_message("me", "Hi there! I'm using **Pyrogram**") - - # Send a location - app.send_location("me", 51.500729, -0.124583) - - # Send a sticker - app.send_sticker("me", "CAADBAADzg4AAvLQYAEz_x2EOgdRwBYE") \ No newline at end of file diff --git a/docs/source/start/examples/inline_queries.rst b/docs/source/start/examples/inline_queries.rst index 023b9c6ed1..09d226ef6b 100644 --- a/docs/source/start/examples/inline_queries.rst +++ b/docs/source/start/examples/inline_queries.rst @@ -26,7 +26,6 @@ It uses the @on_inline_query decorator to register an InlineQueryHandler. ), url="https://docs.pyrogram.org/intro/install", description="How to install Pyrogram", - thumb_url="https://i.imgur.com/JyxrStE.png", reply_markup=InlineKeyboardMarkup( [ [InlineKeyboardButton( @@ -43,7 +42,6 @@ It uses the @on_inline_query decorator to register an InlineQueryHandler. ), url="https://docs.pyrogram.org/start/invoking", description="How to use Pyrogram", - thumb_url="https://i.imgur.com/JyxrStE.png", reply_markup=InlineKeyboardMarkup( [ [InlineKeyboardButton( diff --git a/docs/source/start/examples/use_inline_bots.rst b/docs/source/start/examples/use_inline_bots.rst index 284432d8a0..63e4698506 100644 --- a/docs/source/start/examples/use_inline_bots.rst +++ b/docs/source/start/examples/use_inline_bots.rst @@ -11,8 +11,8 @@ This example shows how to query an inline bot (as user). app = Client("my_account") with app: - # Get bot results for "Fuzz Universe" from the inline bot @vid - bot_results = app.get_inline_bot_results("vid", "Fuzz Universe") + # Get bot results for "hello" from the inline bot @vid + bot_results = app.get_inline_bot_results("vid", "hello") # Send the first result (bot_results.results[0]) to your own chat (Saved Messages) app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id) \ No newline at end of file diff --git a/docs/source/start/examples/welcomebot.rst b/docs/source/start/examples/welcomebot.rst index cdd7f022d7..a742059007 100644 --- a/docs/source/start/examples/welcomebot.rst +++ b/docs/source/start/examples/welcomebot.rst @@ -8,7 +8,7 @@ to make it only work for specific messages in a specific chat. from pyrogram import Client, emoji, filters - TARGET = "PyrogramChat" # Target chat. Can also be a list of multiple chat ids/usernames + TARGET = -100123456789 # Target chat. Can also be a list of multiple chat ids/usernames MENTION = "[{}](tg://user?id={})" # User mention markup MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.org/)'s group chat {}!" # Welcome message diff --git a/docs/source/start/invoking.rst b/docs/source/start/invoking.rst index b8eddb9e62..de1e321ed1 100644 --- a/docs/source/start/invoking.rst +++ b/docs/source/start/invoking.rst @@ -2,7 +2,7 @@ Calling Methods =============== At this point, we have successfully :doc:`installed Pyrogram <../intro/install>` and :doc:`authorized ` our -account; we are now aiming towards the core of the library. It's time to start playing with the API! +account; we are now aiming towards the core of the framework. .. contents:: Contents :backlinks: none @@ -22,44 +22,53 @@ Making API method calls with Pyrogram is very simple. Here's a basic example we app = Client("my_account") - with app: - app.send_message("me", "Hi!") + async def main(): + async with app: + await app.send_message("me", "Hi!") -Basic step-by-step -^^^^^^^^^^^^^^^^^^ + app.run(main()) + +Step-by-step +^^^^^^^^^^^^ -#. Let's begin by importing the Client class: +#. Let's begin by importing the Client class. .. code-block:: python from pyrogram import Client -#. Now instantiate a new Client object, "my_account" is a session name of your choice: +#. Now instantiate a new Client object, "my_account" is a session name of your choice. .. code-block:: python app = Client("my_account") -#. The ``with`` context manager is a shortcut for starting, executing and stopping the Client: +#. Async methods can't be executed at the top level, because they must be inside an async context. + Here we define an async function and put our code inside. Also notice the ``await`` keyword in front of the method + call; this is required for all asynchronous methods. .. code-block:: python - with app: + async def main(): + async with app: + await app.send_message("me", "Hi!") -#. Now, you can call any method you like: +#. Finally, we tell Python to schedule our ``main()`` async function by using Pyrogram's :meth:`~pyrogram.Client.run` + method. .. code-block:: python - app.send_message("me", "Hi!") + app.run(main()) Context Manager --------------- -The ``with`` statement starts a context manager used as a shortcut to automatically call :meth:`~pyrogram.Client.start` -and :meth:`~pyrogram.Client.stop`, which are methods required for Pyrogram to work properly. The context manager does -also gracefully stop the client, even in case of unhandled exceptions in your code. +The ``async with`` statement starts a context manager, which is used as a shortcut for starting, executing and stopping +the Client, asynchronously. It does so by automatically calling :meth:`~pyrogram.Client.start` and +:meth:`~pyrogram.Client.stop` in a more convenient way which also gracefully stops the client, even in case of +unhandled exceptions in your code. -This is how Pyrogram looks without the context manager: +Below there's the same example as above, but without the use of the context manager: .. code-block:: python @@ -67,53 +76,49 @@ This is how Pyrogram looks without the context manager: app = Client("my_account") - app.start() - app.send_message("me", "Hi!") - app.stop() + async def main(): + await app.start() + await app.send_message("me", "Hi!") + await app.stop() -Asynchronous Calls ------------------- + app.run(main()) -In case you want Pyrogram to run asynchronously (e.g.: if you are using third party libraries that require you to call -them with ``await``), use the asynchronous context manager: +Using asyncio.run() +------------------- + +Alternatively to the :meth:`~pyrogram.Client.run` method, you can use Python's ``asyncio.run()`` to execute the main +function, with one little caveat: the Client instance (and possibly other asyncio resources you are going to use) must +be instantiated inside the main function. .. code-block:: python + import asyncio from pyrogram import Client - app = Client("my_account") - async def main(): + app = Client("my_account") + async with app: await app.send_message("me", "Hi!") - app.run(main()) - -Asynchronous step-by-step -^^^^^^^^^^^^^^^^^^^^^^^^^ - -#. Import the Client class and create an instance: - - .. code-block:: python + asyncio.run(main()) - from pyrogram import Client - - app = Client("my_account") +Synchronous Calls +------------------ -#. Async methods can't normally be executed at the top level, because they must be inside an async-defined function; - here we define one and put our code inside; the context manager is also being used differently in asyncio and - method calls require the await keyword: +Pyrogram is an asynchronous framework, but it also provides a convenience way for calling methods without the need +of async/await keywords and the extra boilerplate. In case you want Pyrogram to run synchronously, simply use the +synchronous context manager: - .. code-block:: python +.. code-block:: python - async def main(): - async with app: - await app.send_message("me", "Hi!") + from pyrogram import Client -#. Finally, we tell Python to schedule our ``main()`` async function, which in turn will execute Pyrogram's methods. - Using :meth:`~pyrogram.Client.run` this way is a friendly alternative for the much more verbose - ``asyncio.get_event_loop().run_until_complete(main())``: + app = Client("my_account") - .. code-block:: python + with app: + app.send_message("me", "Hi!") - app.run(main()) +As you can see, the non-async example becomes less cluttered. Use Pyrogram in this non-asynchronous way only when you +want to write something without the boilerplate or in case you want to combine Pyrogram with other libraries that are +not async. \ No newline at end of file diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst index 27dd0316b0..dee5a11589 100644 --- a/docs/source/start/updates.rst +++ b/docs/source/start/updates.rst @@ -1,8 +1,8 @@ Handling Updates ================ -Calling :doc:`API methods ` sequentially is cool, but how to react when, for example, a new message arrives? -This page deals with updates and how to handle such events in Pyrogram. Let's have a look at how they work. +Calling :doc:`API methods ` sequentially is one way to use Pyrogram, but how to react when, for example, a +new message arrives? This page deals with updates and how to handle such events in Pyrogram. .. contents:: Contents :backlinks: none @@ -14,10 +14,9 @@ This page deals with updates and how to handle such events in Pyrogram. Let's ha Defining Updates ---------------- -First, let's define what are these updates. As hinted already, updates are simply events that happen in your Telegram -account (incoming messages, new members join, bot button presses, etc...), which are meant to notify you about a new -specific state that has changed. These updates are handled by registering one or more callback functions in your app -using :doc:`Handlers <../api/handlers>`. +As hinted already, updates are simply events that happen in your Telegram account (incoming messages, new members join, +bot button presses, etc.), which are meant to notify you about a new specific state that has changed. These updates are +handled by registering one or more callback functions in your app using :doc:`Handlers <../api/handlers>`. Each handler deals with a specific event and once a matching update arrives from Telegram, your registered callback function will be called back by the framework and its body executed. @@ -40,50 +39,51 @@ The most elegant way to register a message handler is by using the :meth:`~pyrog app = Client("my_account") - @app.on_message() - def my_handler(client, message): - message.forward("me") - + async def my_handler(client, message): + await message.forward("me") app.run() The defined function ``my_handler``, which accepts the two arguments *(client, message)*, will be the function that gets executed every time a new message arrives. -Asynchronous handlers +In the last line we see again the :meth:`~pyrogram.Client.run` method, this time used without any argument. +Its purpose here is simply to automatically :meth:`~pyrogram.Client.start`, keep the Client online so that it can listen +for updates and :meth:`~pyrogram.Client.stop` it once you hit ``CTRL+C``. + +Synchronous handlers ^^^^^^^^^^^^^^^^^^^^^ -You can also have asynchronous handlers; you only need to define the callback function using ``async def`` and call API -methods by placing ``await`` in front of them: +You can also have synchronous handlers; you only need to define the callback function without using ``async def`` and +call API methods by not placing ``await`` in front of them: .. code-block:: python @app.on_message() - async def my_handler(client, message): - await message.forward("me") + def my_handler(client, message): + message.forward("me") .. note:: - You can mix ``def`` and ``async def`` handlers as much as you need, Pyrogram will still work concurrently and - efficiently regardless of what you choose. + You can mix ``def`` and ``async def`` handlers as much as you like, Pyrogram will still work concurrently and + efficiently regardless of what you choose. However, it is recommended to use Pyrogram in its native, asynchronous + form at all times, unless you want to write something without the boilerplate or in case you want to combine + Pyrogram with other libraries that are not async. Using add_handler() ^^^^^^^^^^^^^^^^^^^ The :meth:`~pyrogram.Client.add_handler` method takes any handler instance that wraps around your defined callback -function and registers it in your Client. It is useful in case you want to programmatically add handlers (or in case, -for some reason, you don't like to use decorators). +function and registers it in your Client. It is useful in case you want to programmatically add handlers. .. code-block:: python from pyrogram import Client from pyrogram.handlers import MessageHandler - - def my_function(client, message): - message.forward("me") - + async def my_function(client, message): + await message.forward("me") app = Client("my_account") @@ -92,12 +92,12 @@ for some reason, you don't like to use decorators). app.run() -The same about asynchronous handlers applies for :meth:`~pyrogram.Client.add_handler`: +The same about synchronous handlers applies for :meth:`~pyrogram.Client.add_handler`: .. code-block:: python - async def my_function(client, message): - await message.forward("me") + def my_function(client, message): + message.forward("me") .. note:: diff --git a/docs/source/support.rst b/docs/source/support.rst index 029eeec043..32dfdb6b71 100644 --- a/docs/source/support.rst +++ b/docs/source/support.rst @@ -1,66 +1,62 @@ Support Pyrogram ================ -As a developer, you probably understand that "open source" doesn't mean "free work". If you wish to tip me for Pyrogram --- or any of my `other works`_ -- you can do so by the ways shown below. Your appreciation means a lot and helps -staying motivated! - ---- `Dan`_ +.. raw:: html ------ + -Star ----- +
+ Fork -Pyrogram is free and open source software, and thus powered by your love and support! If you like the project and have -found it to be useful, give Pyrogram a `Star on GitHub`_. + Star +
-.. raw:: html +
- Star -

+Pyrogram is a free and open source project. +If you enjoy Pyrogram and would like to show your appreciation, consider donating or becoming +a sponsor of the project. You can support Pyrogram via the ways shown below: ----- -Sponsor -------- +GitHub Sponsor +-------------- -You can become a GitHub sponsor: +`Become a GitHub sponsor `_. .. raw:: html - + + Sponsor ----- -Donate ------- +LiberaPay Patron +---------------- -You can donate via PayPal using the button below: +`Become a LiberaPay patron `_. .. raw:: html -
- - - -
+ ----- -Cloud Credits -------------- +OpenCollective Backer +--------------------- + +`Become an OpenCollective backer `_ -If you need a cloud server to host your applications, try **Hetzner Cloud**. You can sign up with -`this link `_ to get €20 in cloud credits and help support Pyrogram and -my `other projects`_. +.. raw:: html -.. _Star on GitHub: https://github.com/pyrogram/pyrogram -.. _other projects: https://github.com/delivrance -.. _other works: https://github.com/delivrance -.. _Dan: https://t.me/haskell + \ No newline at end of file diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst index 9df028ad31..0b0f068323 100644 --- a/docs/source/topics/advanced-usage.rst +++ b/docs/source/topics/advanced-usage.rst @@ -1,9 +1,8 @@ Advanced Usage ============== -Pyrogram's API, which consists of well documented convenience :doc:`methods <../api/methods/index>` and facade -:doc:`types <../api/types/index>`, exists to provide a much easier interface to the undocumented and often confusing -Telegram API. +Pyrogram's API -- which consists of well documented :doc:`methods <../api/methods/index>` and +:doc:`types <../api/types/index>` -- exists to provide an easier interface to the more complex Telegram API. In this section, you'll be shown the alternative way of communicating with Telegram using Pyrogram: the main "raw" Telegram API with its functions and types. @@ -21,25 +20,18 @@ Telegram Raw API If you can't find a high-level method for your needs or if you want complete, low-level access to the whole Telegram API, you have to use the raw :mod:`~pyrogram.raw.functions` and :mod:`~pyrogram.raw.types`. -As already hinted, raw functions and types can be really confusing, mainly because people don't realize soon enough they -accept *only* the right types and that all required parameters must be filled in. This section will therefore explain -some pitfalls to take into consideration when working with the raw API. +As already hinted, raw functions and types can be less convenient. This section will therefore explain some pitfalls to +take into consideration when working with the raw API. -.. hint:: +.. tip:: - Every available high-level methods in Pyrogram is built on top of these raw functions. - - Nothing stops you from using the raw functions only, but they are rather complex and - :doc:`plenty of them <../api/methods/index>` are already re-implemented by providing a much simpler and cleaner - interface which is very similar to the Bot API (yet much more powerful). - - If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_! + Every available high-level method in Pyrogram is built on top of these raw functions. Invoking Functions -^^^^^^^^^^^^^^^^^^ +------------------ Unlike the :doc:`methods <../api/methods/index>` found in Pyrogram's API, which can be called in the usual simple way, -functions to be invoked from the raw Telegram API have a different way of usage and are more complex. +functions to be invoked from the raw Telegram API have a different way of usage. First of all, both :doc:`raw functions <../telegram/functions/index>` and :doc:`raw types <../telegram/types/index>` live in their respective packages (and sub-packages): ``pyrogram.raw.functions``, ``pyrogram.raw.types``. They all exist @@ -61,12 +53,12 @@ Here's some examples: with Client("my_account") as app: app.send( functions.account.UpdateProfile( - first_name="Dan", last_name="Tès", - about="Bio written from Pyrogram" + first_name="First Name", last_name="Last Name", + about="New bio text" ) ) -- Disable links to your account when someone forwards your messages: +- Set online/offline status: .. code-block:: python @@ -74,14 +66,13 @@ Here's some examples: from pyrogram.raw import functions, types with Client("my_account") as app: - app.send( - functions.account.SetPrivacy( - key=types.PrivacyKeyForwards(), - rules=[types.InputPrivacyValueDisallowAll()] - ) - ) + # Set online status + app.send(functions.account.UpdateStatus(offline=False)) + + # Set offline status + app.send(functions.account.UpdateStatus(offline=True)) -- Invite users to your channel/supergroup: +- Get chat info: .. code-block:: python @@ -89,21 +80,18 @@ Here's some examples: from pyrogram.raw import functions, types with Client("my_account") as app: - app.send( - functions.channels.InviteToChannel( - channel=app.resolve_peer(123456789), # ID or Username - users=[ # The users you want to invite - app.resolve_peer(23456789), # By ID - app.resolve_peer("username"), # By username - app.resolve_peer("+393281234567"), # By phone number - ] + r = app.send( + functions.channels.GetFullChannel( + channel=app.resolve_peer("username") ) ) + print(r) + Chat IDs -^^^^^^^^ +-------- -The way Telegram works makes it impossible to directly send a message to a user or a chat by using their IDs only. +The way Telegram works makes it not possible to directly send a message to a user or a chat by using their IDs only. Instead, a pair of ``id`` and ``access_hash`` wrapped in a so called ``InputPeer`` is always needed. Pyrogram allows sending messages with IDs only thanks to cached access hashes. @@ -112,18 +100,17 @@ Whenever an InputPeer is needed you must pass one of these: - :class:`~pyrogram.raw.types.InputPeerUser` - Users - :class:`~pyrogram.raw.types.InputPeerChat` - Basic Chats -- :class:`~pyrogram.raw.types.InputPeerChannel` - Either Channels or Supergroups +- :class:`~pyrogram.raw.types.InputPeerChannel` - Channels & Supergroups -But you don't necessarily have to manually instantiate each object because, luckily for you, Pyrogram already provides +But you don't necessarily have to manually instantiate each object because Pyrogram already provides :meth:`~pyrogram.Client.resolve_peer` as a convenience utility method that returns the correct InputPeer by accepting a peer ID only. Another thing to take into consideration about chat IDs is the way they are represented: they are all integers and all positive within their respective raw types. -Things are different when working with Pyrogram's API because having them in the same space can theoretically lead to -collisions, and that's why Pyrogram (as well as the official Bot API) uses a slightly different representation for each -kind of ID. +Things are different when working with Pyrogram's API because having them in the same space could lead to +collisions, and that's why Pyrogram uses a slightly different representation for each kind of ID. For example, given the ID *123456789*, here's how Pyrogram can tell entities apart: diff --git a/docs/source/topics/bots-interaction.rst b/docs/source/topics/bots-interaction.rst deleted file mode 100644 index 1fad206988..0000000000 --- a/docs/source/topics/bots-interaction.rst +++ /dev/null @@ -1,50 +0,0 @@ -Bots Interaction -================ - -Users can interact with other bots via plain text messages as well as inline queries. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Inline Bots ------------ - -- If a bot accepts inline queries, you can call it by using - :meth:`~pyrogram.Client.get_inline_bot_results` to get the list of its inline results for a query: - - .. code-block:: python - - # Get bot results for "Fuzz Universe" from the inline bot @vid - bot_results = app.get_inline_bot_results("vid", "Fuzz Universe") - - .. figure:: https://i.imgur.com/IAqLs54.png - :width: 90% - :align: center - :figwidth: 60% - - ``get_inline_bot_results()`` is the equivalent action of writing ``@vid Fuzz Universe`` and getting the - results list. - -- After you retrieved the bot results, you can use - :meth:`~pyrogram.Client.send_inline_bot_result` to send a chosen result to any chat: - - .. code-block:: python - - # Send the first result to your own chat - app.send_inline_bot_result( - "me", - bot_results.query_id, - bot_results.results[0].id - ) - - .. figure:: https://i.imgur.com/wwxr7B7.png - :width: 90% - :align: center - :figwidth: 60% - - ``send_inline_bot_result()`` is the equivalent action of choosing a result from the list and sending it - to a chat. diff --git a/docs/source/topics/session-settings.rst b/docs/source/topics/client-settings.rst similarity index 54% rename from docs/source/topics/session-settings.rst rename to docs/source/topics/client-settings.rst index 847427cf25..1b93d99d7b 100644 --- a/docs/source/topics/session-settings.rst +++ b/docs/source/topics/client-settings.rst @@ -1,24 +1,12 @@ -Session Settings -================ +Client Settings +=============== -As you may probably know, Telegram allows users (and bots) having more than one session (authorizations) registered -in the system at the same time. +You can control the way your client appears in the Active Sessions menu of an official client by changing some client +settings. By default you will see something like the following: -Briefly explaining, sessions are simply new logins in your account. They can be reviewed in the settings of an official -app (or by invoking :class:`~pyrogram.api.functions.account.GetAuthorizations` with Pyrogram). They -store some useful information such as the client who's using them and from which country and IP address. - -.. figure:: https://i.imgur.com/YaqtMLO.png - :width: 600 - :align: center - - **A Pyrogram session running on Linux, Python 3.7.** - -That's how a session looks like on the Android app, showing the three main pieces of information. - -- ``app_version``: **Pyrogram 0.13.0** -- ``device_model``: **CPython 3.7.2** -- ``system_version``: **Linux 4.15.0-23-generic** +- Device Model: ``CPython x.y.z`` +- Application: ``Pyrogram x.y.z`` +- System Version: ``Linux x.y.z`` .. contents:: Contents :backlinks: none diff --git a/docs/source/topics/config-file.rst b/docs/source/topics/config-file.rst index 38bb9e3375..1657625acd 100644 --- a/docs/source/topics/config-file.rst +++ b/docs/source/topics/config-file.rst @@ -15,7 +15,7 @@ Introduction ------------ The idea behind using a configuration file is to help keeping your code free of private settings information such as -the API Key and Proxy, without having you to even deal with how to load such settings. The configuration file, usually +the API Key and Proxy, without having you to deal with how to load such settings. The configuration file, usually referred as ``config.ini`` file, is automatically loaded from the root of your working directory; all you need to do is fill in the necessary parts. @@ -23,7 +23,7 @@ fill in the necessary parts. The configuration file is optional, but recommended. If, for any reason, you prefer not to use it, there's always an alternative way to configure Pyrogram via Client's parameters. Doing so, you can have full control on how to store - and load your settings (e.g.: from environment variables). + and load your settings. Settings specified via Client's parameter have higher priority and will override any setting stored in the configuration file. diff --git a/docs/source/topics/create-filters.rst b/docs/source/topics/create-filters.rst index 191eeb05b8..ae7bd5ecf7 100644 --- a/docs/source/topics/create-filters.rst +++ b/docs/source/topics/create-filters.rst @@ -87,7 +87,7 @@ Finally, the filter usage remains the same: Filters with Arguments ---------------------- -A much cooler filter would be one that accepts "pyrogram" or any other string as argument at usage time. +A more flexible filter would be one that accepts "pyrogram" or any other string as argument at usage time. A dynamic filter like this will make use of named arguments for the :meth:`~pyrogram.filters.create` method and the first argument of the callback function, which is a reference to the filter object itself holding the extra data passed via named arguments. diff --git a/docs/source/topics/debugging.rst b/docs/source/topics/debugging.rst index ac0b396fd0..6e6e6d5ed8 100644 --- a/docs/source/topics/debugging.rst +++ b/docs/source/topics/debugging.rst @@ -2,7 +2,7 @@ Debugging ========= When working with the API, chances are you'll stumble upon bugs, get stuck and start wondering how to continue. Nothing -to actually worry about -- that's normal -- and luckily for you, Pyrogram provides some commodities to help you in this. +to actually worry about since Pyrogram provides some commodities to help you in this. .. contents:: Contents :backlinks: none @@ -27,8 +27,8 @@ Consider the following code: .. code-block:: python - dan = app.get_users("haskell") - print(dan) # User + me = app.get_users("me") + print(me) # User This will show a JSON representation of the object returned by :meth:`~pyrogram.Client.get_users`, which is a :class:`~pyrogram.types.User` instance, in this case. The output on your terminal will be something similar to this: @@ -36,9 +36,9 @@ This will show a JSON representation of the object returned by :meth:`~pyrogram. .. code-block:: json { - "_": "pyrogram.User", - "id": 23122162, - "is_self": false, + "_": "User", + "id": 123456789, + "is_self": true, "is_contact": false, "is_mutual_contact": false, "is_deleted": false, @@ -46,19 +46,13 @@ This will show a JSON representation of the object returned by :meth:`~pyrogram. "is_verified": false, "is_restricted": false, "is_support": false, - "is_scam": false, - "first_name": "Dan", - "status": { - "_": "pyrogram.UserStatus", - "user_id": 23122162, - "recently": true - }, - "username": "haskell", - "language_code": "en", + "first_name": "Pyrogram", "photo": { - "_": "pyrogram.ChatPhoto", - "small_file_id": "AQADBAAD8tBgAQAEJjCxGgAEo5IBAAIC", - "big_file_id": "AQADBAAD8tBgAQAEJjCxGgAEpZIBAAEBAg" + "_": "ChatPhoto", + "small_file_id": "AbCdE...EdCbA", + "small_photo_unique_id": "VwXyZ...ZyXwV", + "big_file_id": "AbCdE...EdCbA", + "big_photo_unique_id": "VwXyZ...ZyXwV" } } @@ -69,37 +63,23 @@ Accessing Attributes -------------------- Even though you see a JSON output, it doesn't mean we are dealing with dictionaries; in fact, all Pyrogram types are -full-fledged Python objects and the correct way to access any attribute of them is by using the dot notation ``.``: +fully-fledged Python objects and the correct way to access any attribute of them is by using the dot notation ``.``: .. code-block:: python - dan_photo = dan.photo - print(dan_photo) # ChatPhoto + photo = me.photo + print(photo) # ChatPhoto .. code-block:: json { - "_": "pyrogram.ChatPhoto", - "small_file_id": "AQADBAAD8tBgAQAEJjCxGgAEo5IBAAIC", - "big_file_id": "AQADBAAD8tBgAQAEJjCxGgAEpZIBAAEBAg" + "_": "ChatPhoto", + "small_file_id": "AbCdE...EdCbA", + "small_photo_unique_id": "VwXyZ...ZyXwV", + "big_file_id": "AbCdE...EdCbA", + "big_photo_unique_id": "VwXyZ...ZyXwV" } -However, the bracket notation ``[]`` is also supported, but its usage is discouraged: - -.. warning:: - - Bracket notation in Python is not commonly used for getting/setting object attributes. While it works for Pyrogram - objects, it might not work for anything else and you should not rely on this. - -.. code-block:: python - - dan_photo_big = dan["photo"]["big_file_id"] - print(dan_photo_big) # str - -.. code-block:: text - - AQADBAAD8tBgAQAEJjCxGgAEpZIBAAEBAg - Checking an Object's Type ------------------------- @@ -111,8 +91,8 @@ error. The correct way to get the object type is by using the built-in function .. code-block:: python - dan_status = dan.status - print(type(dan_status)) + status = me.status + print(type(status)) .. code-block:: text @@ -125,8 +105,8 @@ And to check if an object is an instance of a given class, you use the built-in from pyrogram.types import UserStatus - dan_status = dan.status - print(isinstance(dan_status, UserStatus)) + status = me.status + print(isinstance(status, UserStatus)) .. code-block:: text diff --git a/docs/source/topics/more-on-updates.rst b/docs/source/topics/more-on-updates.rst index a636008ace..81a46f3be4 100644 --- a/docs/source/topics/more-on-updates.rst +++ b/docs/source/topics/more-on-updates.rst @@ -24,7 +24,6 @@ group. Dispatching groups hold one or more handlers and are processed sequential For example, take these two handlers: .. code-block:: python - :emphasize-lines: 1, 6 @app.on_message(filters.text | filters.sticker) def text_or_sticker(client, message): diff --git a/docs/source/topics/mtproto-vs-botapi.rst b/docs/source/topics/mtproto-vs-botapi.rst index c73d669219..9681c1eb65 100644 --- a/docs/source/topics/mtproto-vs-botapi.rst +++ b/docs/source/topics/mtproto-vs-botapi.rst @@ -1,10 +1,10 @@ MTProto vs. Bot API =================== -Pyrogram is a framework that acts as a fully-fledged Telegram client based on MTProto, and this very feature makes it -already superior to, what is usually called, the official Bot API, in many respects. This page will therefore show you -why Pyrogram might be a better choice for your project by comparing the two APIs, but first, let's make it clear what -actually is the MTProto and the Bot API. +Pyrogram is a framework written from the ground up that acts as a fully-fledged Telegram client based on the MTProto +API. This means that Pyrogram is able to execute any official client and bot API action and more. This page will +therefore show you why Pyrogram might be a better choice for your project by comparing the two APIs, but first, let's +make it clear what actually is the MTProto and the Bot API. .. contents:: Contents :backlinks: none @@ -19,10 +19,11 @@ What is the MTProto API? `MTProto`_, took alone, is the name of the custom-made, open and encrypted communication protocol created by Telegram itself --- it's the only protocol used to exchange information between a client and the actual Telegram servers. -The MTProto **API** on the other hand, is what people, for convenience, call the main Telegram API as a whole. This API -is able to authorize both users and bots and is built on top of the MTProto encryption protocol by means of -`binary data serialized`_ in a specific way, as described by the `TL language`_, and delivered using UDP, TCP or even -HTTP as transport-layer protocol. +The MTProto API on the other hand, is what people for convenience call the main Telegram API in order to distinguish it +from the Bot API. The main Telegram API is able to authorize both users and bots and is built on top of the MTProto +encryption protocol by means of `binary data serialized`_ in a specific way, as described by the `TL language`_, and +delivered using UDP, TCP or even HTTP as transport-layer protocol. Clients that make use of Telegram's main API, such as +Pyrogram, implement all these details. .. _MTProto: https://core.telegram.org/mtproto .. _binary data serialized: https://core.telegram.org/mtproto/serialize @@ -31,12 +32,12 @@ HTTP as transport-layer protocol. What is the Bot API? -------------------- -The `Bot API`_ is an HTTP(S) interface for building normal bots using a sub-set of the main MTProto API. Bots are special -accounts that are authorized via tokens instead of phone numbers. The Bot API is built yet again on top of the main -Telegram API, but runs on an intermediate server application that in turn communicates with the actual Telegram servers -using MTProto. +The `Bot API`_ is an HTTP(S) interface for building normal bots using a sub-set of the main Telegram API. Bots are +special accounts that are authorized via tokens instead of phone numbers. The Bot API is built yet again on top of the +main Telegram API, but runs on an intermediate server application that in turn communicates with the actual Telegram +servers using MTProto. -.. figure:: https://i.imgur.com/WvwBoZo.png +.. figure:: //_static/img/mtproto-vs-bot-api.png :align: center .. _Bot API: https://core.telegram.org/bots/api @@ -44,8 +45,8 @@ using MTProto. Advantages of the MTProto API ----------------------------- -Here is a list of all the advantages in using MTProto-based libraries -- such as Pyrogram -- instead of the official -HTTP Bot API. Using Pyrogram you can: +Here is a non-exhaustive list of all the advantages in using MTProto-based libraries -- such as Pyrogram -- instead of +the official HTTP Bot API. Using Pyrogram you can: .. hlist:: :columns: 1 @@ -69,7 +70,7 @@ HTTP Bot API. Using Pyrogram you can: .. hlist:: :columns: 1 - - :guilabel:`+` **Run multiple sessions at once, up to 10 per account (either bot or user)** + - :guilabel:`+` **Run multiple sessions at once (for both user and bot identities)** - :guilabel:`--` The Bot API intermediate server will terminate any other session in case you try to use the same bot again in a parallel connection. diff --git a/docs/source/topics/scheduling.rst b/docs/source/topics/scheduling.rst index f96e7b07f2..a67a92548a 100644 --- a/docs/source/topics/scheduling.rst +++ b/docs/source/topics/scheduling.rst @@ -14,8 +14,8 @@ non-asynchronous contexts. For more detailed information, you can visit and lear ----- -Using ``apscheduler`` ---------------------- +Using apscheduler +----------------- - Install with ``pip3 install apscheduler`` - Documentation: https://apscheduler.readthedocs.io diff --git a/docs/source/topics/serializing.rst b/docs/source/topics/serializing.rst index 7e01357330..e12e3f0511 100644 --- a/docs/source/topics/serializing.rst +++ b/docs/source/topics/serializing.rst @@ -24,8 +24,7 @@ If you want a nicely formatted, human readable JSON representation of any object ... with app: - r = app.get_chat("haskell") - + r = app.get_chat("me") print(str(r)) .. tip:: @@ -48,7 +47,7 @@ as the process requires the package to be in scope. ... with app: - r = app.get_chat("haskell") + r = app.get_chat("me") print(repr(r)) print(eval(repr(r)) == r) # True diff --git a/docs/source/topics/smart-plugins.rst b/docs/source/topics/smart-plugins.rst index fece636622..a94e3212fe 100644 --- a/docs/source/topics/smart-plugins.rst +++ b/docs/source/topics/smart-plugins.rst @@ -1,9 +1,9 @@ Smart Plugins ============= -Pyrogram embeds a **smart**, lightweight yet powerful plugin system that is meant to further simplify the organization -of large projects and to provide a way for creating pluggable (modular) components that can be **easily shared** across -different Pyrogram applications with **minimal boilerplate code**. +Pyrogram embeds a smart, lightweight yet powerful plugin system that is meant to further simplify the organization +of large projects and to provide a way for creating pluggable (modular) components that can be easily shared across +different Pyrogram applications with minimal boilerplate code. .. tip:: @@ -74,8 +74,8 @@ after importing your modules, like this: This is already nice and doesn't add *too much* boilerplate code, but things can get boring still; you have to manually ``import``, manually :meth:`~pyrogram.Client.add_handler` and manually instantiate each -:class:`~pyrogram.handlers.MessageHandler` object because **you can't use those cool decorators** for your -functions. So, what if you could? Smart Plugins solve this issue by taking care of handlers registration automatically. +:class:`~pyrogram.handlers.MessageHandler` object because you can't use decorators for your functions. +So, what if you could? Smart Plugins solve this issue by taking care of handlers registration automatically. Using Smart Plugins ------------------- @@ -91,7 +91,6 @@ Setting up your Pyrogram project to accommodate Smart Plugins is pretty straight This is the same example application as shown above, written using the Smart Plugin system. .. code-block:: text - :emphasize-lines: 2, 3 myproject/ plugins/ @@ -102,7 +101,6 @@ Setting up your Pyrogram project to accommodate Smart Plugins is pretty straight - ``plugins/handlers.py`` .. code-block:: python - :emphasize-lines: 4, 9 from pyrogram import Client, filters @@ -164,7 +162,7 @@ found inside each module will be, instead, loaded in the order they are defined, .. note:: Remember: there can be at most one handler, within a group, dealing with a specific update. Plugins with overlapping - filters included a second time will not work. Learn more at :doc:`More on Updates `. + filters included a second time will not work, by design. Learn more at :doc:`More on Updates `. This default loading behaviour is usually enough, but sometimes you want to have more control on what to include (or exclude) and in which exact order to load plugins. The way to do this is to make use of ``include`` and ``exclude`` @@ -300,32 +298,30 @@ In the previous section we've explained how to specify which plugins to load and starts. Here we'll show, instead, how to unload and load again a previously registered plugin at runtime. Each function decorated with the usual ``on_message`` decorator (or any other decorator that deals with Telegram -updates) will be modified in such a way that a special ``handler`` attribute pointing to a tuple of +updates) will be modified in such a way that a special ``handlers`` attribute pointing to a list of tuples of *(handler: Handler, group: int)* is attached to the function object itself. - ``plugins/handlers.py`` .. code-block:: python - :emphasize-lines: 5, 6 @Client.on_message(filters.text & filters.private) def echo(client, message): message.reply(message.text) print(echo) - print(echo.handler) + print(echo.handlers) - Printing ``echo`` will show something like ````. -- Printing ``echo.handler`` will reveal the handler, that is, a tuple containing the actual handler and the group it - was registered on ``(, 0)``. +- Printing ``echo.handlers`` will reveal the handlers, that is, a list of tuples containing the actual handlers and + the groups they were registered on ``[(, 0)]``. Unloading ^^^^^^^^^ In order to unload a plugin, all you need to do is obtain a reference to it by importing the relevant module and call -:meth:`~pyrogram.Client.remove_handler` Client's method with your function's *handler* special attribute preceded by the -star ``*`` operator as argument. Example: +:meth:`~pyrogram.Client.remove_handler` Client's method with your function's *handler* instance: - ``main.py`` @@ -333,16 +329,19 @@ star ``*`` operator as argument. Example: from plugins.handlers import echo - ... + handlers = echo.handlers - app.remove_handler(*echo.handler) + for h in handlers: + app.remove_handler(*h) The star ``*`` operator is used to unpack the tuple into positional arguments so that *remove_handler* will receive exactly what is needed. The same could have been achieved with: .. code-block:: python - handler, group = echo.handler + handlers = echo.handlers + handler, group = handlers[0] + app.remove_handler(handler, group) Loading @@ -359,4 +358,7 @@ using :meth:`~pyrogram.Client.add_handler` instead. Example: ... - app.add_handler(*echo.handler) \ No newline at end of file + handlers = echo.handlers + + for h in handlers: + app.add_handler(*h) \ No newline at end of file diff --git a/docs/source/topics/storage-engines.rst b/docs/source/topics/storage-engines.rst index 1a86cad8b5..8d693647d6 100644 --- a/docs/source/topics/storage-engines.rst +++ b/docs/source/topics/storage-engines.rst @@ -18,28 +18,18 @@ Persisting Sessions In order to make a client reconnect successfully between restarts, that is, without having to start a new authorization process from scratch each time, Pyrogram needs to store the generated session data somewhere. -Other useful data being stored is peers' cache. In short, peers are all those entities you can chat with, such as users -or bots, basic groups, but also channels and supergroups. Because of how Telegram works, a unique pair of **id** and -**access_hash** is needed to contact a peer. This, plus other useful info such as the peer type, is what is stored -inside a session storage. - -So, if you ever wondered how is Pyrogram able to contact peers just by asking for their ids, it's because of this very -reason: the peer *id* is looked up in the internal database and the available *access_hash* is retrieved, which is then -used to correctly invoke API methods. - Different Storage Engines ------------------------- -Let's now talk about how Pyrogram actually stores all the relevant data. Pyrogram offers two different types of storage -engines: a **File Storage** and a **Memory Storage**. These engines are well integrated in the library and require a -minimal effort to set up. Here's how they work: +Pyrogram offers two different types of storage engines: a **File Storage** and a **Memory Storage**. +These engines are well integrated in the framework and require a minimal effort to set up. Here's how they work: File Storage ^^^^^^^^^^^^ -This is the most common storage engine. It is implemented by using **SQLite**, which will store the session and peers -details. The database will be saved to disk as a single portable file and is designed to efficiently store and retrieve -peers whenever they are needed. +This is the most common storage engine. It is implemented by using **SQLite**, which will store the session details. +The database will be saved to disk as a single portable file and is designed to efficiently store and retrieve +data whenever they are needed. To use this type of engine, simply pass any name of your choice to the ``session_name`` parameter of the :obj:`~pyrogram.Client` constructor, as usual: @@ -68,8 +58,8 @@ session name "**:memory:**" to the ``session_name`` parameter of the :obj:`~pyro with Client(":memory:") as app: print(app.get_me()) -This storage engine is still backed by SQLite, but the database exists purely in memory. This means that, once you stop a -client, the entire database is discarded and the session details used for logging in again will be lost forever. +This storage engine is still backed by SQLite, but the database exists purely in memory. This means that, once you stop +a client, the entire database is discarded and the session details used for logging in again will be lost forever. Session Strings --------------- @@ -84,8 +74,8 @@ In case you want to use an in-memory storage, but also want to keep access to th with Client(":memory:") as app: print(app.export_session_string()) -...and save the resulting (quite long) string somewhere. You can use this string as session name the next time you want -to login using the same session; the storage used will still be completely in-memory: +...and save the resulting string. You can use this string as session name the next time you want to login +using the same session; the storage used will still be in-memory: .. code-block:: python @@ -96,11 +86,5 @@ to login using the same session; the storage used will still be completely in-me with Client(session_string) as app: print(app.get_me()) -Session strings are useful when you want to run authorized Pyrogram clients on platforms like -`Heroku `_, where their ephemeral filesystems makes it much harder for a file-based storage -engine to properly work as intended. - -But, why is the session string so long? Can't it be shorter? No, it can't. The session string already packs the bare -minimum data Pyrogram needs to successfully reconnect to an authorized session, and the 2048-bits auth key is the major -contributor to the overall length. Needless to say that this string, as well as any other session storage, represent -strictly personal data. Keep them safe. +Session strings are useful when you want to run authorized Pyrogram clients on platforms where their ephemeral +filesystems makes it harder for a file-based storage engine to properly work as intended. diff --git a/docs/source/topics/test-servers.rst b/docs/source/topics/test-servers.rst index 3ed996eea9..cba5e709f0 100644 --- a/docs/source/topics/test-servers.rst +++ b/docs/source/topics/test-servers.rst @@ -15,8 +15,7 @@ Telegram's test servers without hassle. All you need to do is start a new sessio .. note:: If this is the first time you login into test servers, you will be asked to register your account first. - Don't worry about your contacts and chats, they will be kept untouched inside the production environment; - accounts authorized on test servers reside in a different, parallel instance of a Telegram database. + Accounts registered on test servers reside in a different, parallel instance of a Telegram server. .. contents:: Contents :backlinks: none @@ -28,19 +27,15 @@ Telegram's test servers without hassle. All you need to do is start a new sessio Test Mode in Official Apps -------------------------- -You can also login yourself into test servers using official desktop apps, such as Webogram and TDesktop: +You can also login yourself into test servers using official desktop apps, such as Telegram Web and Telegram Desktop: -- **Webogram**: Login here: https://web.telegram.org/?test=1 -- **TDesktop**: Hold ``Alt+Shift`` and right click on "Add account", then choose "Test server". +- **Telegram Web**: Login here: https://web.telegram.org/?test=1 +- **Telegram Desktop**: Hold ``Alt+Shift`` and right click on "Add account", then choose "Test server". Test Numbers ------------ Beside normal numbers, the test environment allows you to login with reserved test numbers. Valid phone numbers follow the pattern ``99966XYYYY``, where ``X`` is the DC number (1 to 3) and ``YYYY`` are random -numbers. Users with such numbers always get ``XXXXX`` as the confirmation code (the DC number, repeated five times). - -.. important:: - - Do not store any important or private information in such test users' accounts; anyone can make use of the - simplified authorization mechanism and login at any time. +numbers. Users with such numbers always get ``XXXXX`` or ``XXXXXX`` as the confirmation code (the DC number, repeated +five or six times). \ No newline at end of file diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index e3b730e585..df3589a948 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -14,7 +14,7 @@ Text Formatting :class: strike-italic Pyrogram uses a custom Markdown dialect for text formatting which adds some unique features that make writing styled -texts easier in both Markdown and HTML. You can send sophisticated text messages and media captions using a great +texts easier in both Markdown and HTML. You can send sophisticated text messages and media captions using a variety of decorations that can also be nested in order to combine multiple styles together. .. contents:: Contents @@ -36,7 +36,7 @@ list of the basic styles currently supported by Pyrogram. - :underline:`underline` - spoiler - `text URL `_ -- `user text mention `_ +- `user text mention `_ - ``inline fixed-width code`` - .. code-block:: text @@ -66,9 +66,9 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us ||spoiler|| - [text URL](https://docs.pyrogram.org/) + [text URL](https://pyrogram.org/) - [text user mention](tg://user?id=23122162) + [text user mention](tg://user?id=123456789) `inline fixed-width code` @@ -83,14 +83,13 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us .. code-block:: python app.send_message( - "haskell", + "me", ( "**bold**, " "__italic__, " "--underline--, " "~~strike~~, " "||spoiler||, " - "[mention](tg://user?id=23122162), " "[URL](https://pyrogram.org), " "`code`, " "```" @@ -119,9 +118,9 @@ The following tags are currently supported: spoiler - text URL + text URL - inline mention + inline mention inline fixed-width code @@ -136,14 +135,13 @@ The following tags are currently supported: .. code-block:: python app.send_message( - "haskell", + "me", ( "bold, " "italic, " "underline, " "strike, " "spoiler, " - "mention, " "URL, " "code\n\n" "
"
@@ -181,7 +179,7 @@ This means you can combine together both syntaxes in the same text:
 
 .. code-block:: python
 
-    app.send_message("haskell", "**bold**, italic")
+    app.send_message("me", "**bold**, italic")
 
 Result:
 
@@ -192,8 +190,8 @@ If you don't like this behaviour you can always choose to only enable either Mar
 
 .. code-block::
 
-    app.send_message("haskell", "**bold**, italic", parse_mode="markdown")
-    app.send_message("haskell", "**bold**, italic", parse_mode="html")
+    app.send_message("me", "**bold**, italic", parse_mode="markdown")
+    app.send_message("me", "**bold**, italic", parse_mode="html")
 
 Result:
 
@@ -206,7 +204,7 @@ as-is.
 
 .. code-block:: python
 
-    app.send_message("haskell", "**bold**, italic", parse_mode=None)
+    app.send_message("me", "**bold**, italic", parse_mode=None)
 
 Result:
 
diff --git a/docs/source/topics/tgcrypto.rst b/docs/source/topics/tgcrypto.rst
index e0d9beb67f..f6ca211d3e 100644
--- a/docs/source/topics/tgcrypto.rst
+++ b/docs/source/topics/tgcrypto.rst
@@ -1,11 +1,11 @@
 Fast Crypto
 ===========
 
-Pyrogram's speed can be *dramatically* boosted up by TgCrypto_, a high-performance, easy-to-install Telegram Crypto
-Library specifically written in C for Pyrogram [1]_ as a Python extension.
+Pyrogram's speed can be boosted up by TgCrypto_, a high-performance, easy-to-install cryptography library specifically
+written in C for Pyrogram as a Python extension.
 
-TgCrypto is a replacement for the much slower PyAES and implements the crypto algorithms Telegram requires, namely
-**AES-IGE 256 bit** (used in MTProto v2.0) and **AES-CTR 256 bit** (used for CDN encrypted files).
+TgCrypto is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram
+requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC.
 
 Installation
 ------------
@@ -14,10 +14,10 @@ Installation
 
     $ pip3 install -U tgcrypto
 
-.. note:: Being a C extension for Python, TgCrypto is an optional but *highly recommended* dependency; when TgCrypto is
-   not detected in your system, Pyrogram will automatically fall back to PyAES and will show you a warning.
+.. note:: When TgCrypto is not detected in your system, Pyrogram will automatically fall back to a slower Python-only
+    implementation and will show you a warning.
 
-The reason about being an optional package is that TgCrypto requires some extra system tools in order to be compiled.
+The reason about being an optional package is that TgCrypto requires extra system tools in order to be compiled.
 The errors you receive when trying to install TgCrypto are system dependent, but also descriptive enough to understand
 what you should do next:
 
@@ -26,7 +26,4 @@ what you should do next:
 - **Linux**: Install a proper C compiler (``gcc``, ``clang``) and the Python header files (``python3-dev``).
 - **Termux**: Install ``clang`` package.
 
-.. _TgCrypto: https://github.com/pyrogram/tgcrypto
-
-.. [1] Although TgCrypto is intended for Pyrogram, it is shipped as a standalone package and can thus be used for
-   other Python projects too.
+.. _TgCrypto: https://github.com/pyrogram/tgcrypto
\ No newline at end of file
diff --git a/docs/source/topics/use-filters.rst b/docs/source/topics/use-filters.rst
index 7e5219e14f..eda6d7addc 100644
--- a/docs/source/topics/use-filters.rst
+++ b/docs/source/topics/use-filters.rst
@@ -19,16 +19,15 @@ Single Filters
 
 Let's start right away with a simple example:
 
--   This example will show you how to **only** handle messages containing an :class:`~pyrogram.Audio` object and
+-   This example will show you how to **only** handle messages containing a :class:`~pyrogram.types.Sticker` object and
     ignore any other message. Filters are passed as the first argument of the decorator:
 
     .. code-block:: python
-        :emphasize-lines: 4
 
         from pyrogram import filters
 
 
-        @app.on_message(filters.audio)
+        @app.on_message(filters.sticker)
         def my_handler(client, message):
             print(message)
 
@@ -36,7 +35,6 @@ Let's start right away with a simple example:
     callback function itself:
 
     .. code-block:: python
-        :emphasize-lines: 9
 
         from pyrogram import filters
         from pyrogram.handlers import MessageHandler
@@ -46,12 +44,12 @@ Let's start right away with a simple example:
             print(message)
 
 
-        app.add_handler(MessageHandler(my_handler, filters.audio))
+        app.add_handler(MessageHandler(my_handler, filters.sticker))
 
 Combining Filters
 -----------------
 
-Filters can also be used in a more advanced way by inverting and combining more filters together using bitwise
+Filters can be used in a more advanced way by inverting and combining more filters together using bitwise
 operators ``~``, ``&`` and ``|``:
 
 -   Use ``~`` to invert a filter (behaves like the ``not`` operator).
diff --git a/docs/source/topics/voice-calls.rst b/docs/source/topics/voice-calls.rst
index 19950bf40e..aef4030ca8 100644
--- a/docs/source/topics/voice-calls.rst
+++ b/docs/source/topics/voice-calls.rst
@@ -1,8 +1,8 @@
 Voice Calls
 ===========
 
-Both private voice calls and group voice calls are currently supported by third-party libraries that integrate with
-Pyrogram.
+Both private voice calls and group voice calls are currently supported by third-party, external libraries that integrate
+with Pyrogram.
 
 Libraries
 ---------
diff --git a/pyrogram/client.py b/pyrogram/client.py
index c5c72af88c..65514cf6cc 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -32,6 +32,7 @@
 from typing import Union, List, Optional
 
 import pyrogram
+from pyrogram import __version__, __license__
 from pyrogram import raw
 from pyrogram import utils
 from pyrogram.crypto import aes
@@ -281,6 +282,10 @@ async def authorize(self) -> User:
         if self.bot_token:
             return await self.sign_in_bot(self.bot_token)
 
+        print(f"Welcome to Pyrogram (version {__version__})")
+        print(f"Pyrogram is free software and comes with ABSOLUTELY NO WARRANTY. Licensed\n"
+              f"under the terms of the {__license__}.\n")
+
         while True:
             try:
                 if not self.phone_number:
@@ -428,7 +433,6 @@ def set_parse_mode(self, parse_mode: Optional[str] = "combined"):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 10,14,18,22
 
                 from pyrogram import Client
 
@@ -436,23 +440,23 @@ def set_parse_mode(self, parse_mode: Optional[str] = "combined"):
 
                 with app:
                     # Default combined mode: Markdown + HTML
-                    app.send_message("haskell", "1. **markdown** and html")
+                    app.send_message("me", "1. **markdown** and html")
 
                     # Force Markdown-only, HTML is disabled
                     app.set_parse_mode("markdown")
-                    app.send_message("haskell", "2. **markdown** and html")
+                    app.send_message("me", "2. **markdown** and html")
 
                     # Force HTML-only, Markdown is disabled
                     app.set_parse_mode("html")
-                    app.send_message("haskell", "3. **markdown** and html")
+                    app.send_message("me", "3. **markdown** and html")
 
                     # Disable the parser completely
                     app.set_parse_mode(None)
-                    app.send_message("haskell", "4. **markdown** and html")
+                    app.send_message("me", "4. **markdown** and html")
 
                     # Bring back the default combined mode
                     app.set_parse_mode()
-                    app.send_message("haskell", "5. **markdown** and html")
+                    app.send_message("me", "5. **markdown** and html")
         """
 
         self.parse_mode = parse_mode
@@ -937,8 +941,8 @@ async def get_file(
                                 await self.loop.run_in_executor(self.executor, func)
 
                         if len(chunk) < limit:
-                            break        
-                        
+                            break
+
                         r = await session.send(
                             raw.functions.upload.GetFile(
                                 location=location,
diff --git a/pyrogram/connection/transport/tcp/tcp_abridged.py b/pyrogram/connection/transport/tcp/tcp_abridged.py
index cee9783121..0282e66815 100644
--- a/pyrogram/connection/transport/tcp/tcp_abridged.py
+++ b/pyrogram/connection/transport/tcp/tcp_abridged.py
@@ -17,7 +17,6 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
-
 from typing import Optional
 
 from .tcp import TCP
diff --git a/pyrogram/connection/transport/tcp/tcp_full.py b/pyrogram/connection/transport/tcp/tcp_full.py
index 7befddb1af..8c80f454be 100644
--- a/pyrogram/connection/transport/tcp/tcp_full.py
+++ b/pyrogram/connection/transport/tcp/tcp_full.py
@@ -17,9 +17,9 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
-from typing import Optional
 from binascii import crc32
 from struct import pack, unpack
+from typing import Optional
 
 from .tcp import TCP
 
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate.py b/pyrogram/connection/transport/tcp/tcp_intermediate.py
index 659c30e4ce..6b18ab15c7 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate.py
@@ -17,8 +17,8 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
-from typing import Optional
 from struct import pack, unpack
+from typing import Optional
 
 from .tcp import TCP
 
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
index be783f048f..c257fdd54e 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
@@ -18,8 +18,8 @@
 
 import logging
 import os
-from typing import Optional
 from struct import pack, unpack
+from typing import Optional
 
 from pyrogram.crypto import aes
 from .tcp import TCP
diff --git a/pyrogram/errors/rpc_error.py b/pyrogram/errors/rpc_error.py
index 71a7249f66..a9fd66556d 100644
--- a/pyrogram/errors/rpc_error.py
+++ b/pyrogram/errors/rpc_error.py
@@ -39,7 +39,7 @@ def __init__(
         is_unknown: bool = False,
         is_signed: bool = False
     ):
-        super().__init__("[{}{} {}]: {} {}".format(
+        super().__init__("Telegram says: [{}{} {}] - {} {}".format(
             "-" if is_signed else "",
             self.CODE,
             self.ID or self.NAME,
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index b6d27087e7..e583e0638e 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -934,12 +934,3 @@ async def __call__(self, _, message: Message):
                          and message.from_user
                          and message.from_user.is_self
                          and not message.outgoing)))
-
-
-# region dan_filter
-async def dan_filter(_, __, m: Message):
-    return bool(m.from_user and m.from_user.id == 23122162)
-
-
-dan = create(dan_filter)
-# endregion
diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py
index 8cc7dd3066..1e6b91465e 100644
--- a/pyrogram/methods/bots/__init__.py
+++ b/pyrogram/methods/bots/__init__.py
@@ -23,8 +23,8 @@
 from .request_callback_answer import RequestCallbackAnswer
 from .send_game import SendGame
 from .send_inline_bot_result import SendInlineBotResult
-from .set_game_score import SetGameScore
 from .set_bot_commands import SetBotCommands
+from .set_game_score import SetGameScore
 
 
 class Bots(
diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py
index 74aff5daa6..711eafdd41 100644
--- a/pyrogram/methods/chats/get_chat_member.py
+++ b/pyrogram/methods/chats/get_chat_member.py
@@ -47,8 +47,8 @@ async def get_chat_member(
         Example:
             .. code-block:: python
 
-                dan = app.get_chat_member("pyrogramchat", "haskell")
-                print(dan)
+                member = app.get_chat_member(chat_id, "me")
+                print(member)
         """
         chat = await self.resolve_peer(chat_id)
         user = await self.resolve_peer(user_id)
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index d22cc44670..c984107c62 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -57,16 +57,17 @@ async def get_chat_members(
 
             offset (``int``, *optional*):
                 Sequential number of the first member to be returned.
-                Only applicable to supergroups and channels. Defaults to 0 [1]_.
+                Only applicable to supergroups and channels. Defaults to 0.
 
             limit (``int``, *optional*):
                 Limits the number of members to be retrieved.
                 Only applicable to supergroups and channels.
-                Defaults to 200, which is also the maximum server limit allowed per method call.
+                Defaults to 200.
 
             query (``str``, *optional*):
                 Query string to filter members based on their display names and usernames.
-                Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
+                Only applicable to supergroups and channels. Defaults to "" (empty string).
+                A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only
 
             filter (``str``, *optional*):
                 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
@@ -80,11 +81,6 @@ async def get_chat_members(
                 Only applicable to supergroups and channels.
                 Defaults to *"recent"*.
 
-        .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
-            on channels.
-
-        .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
-
         Returns:
             List of :obj:`~pyrogram.types.ChatMember`: On success, a list of chat members is returned.
 
@@ -95,13 +91,13 @@ async def get_chat_members(
             .. code-block:: python
 
                 # Get first 200 recent members
-                app.get_chat_members("pyrogramchat")
+                app.get_chat_members(chat_id)
 
                 # Get all administrators
-                app.get_chat_members("pyrogramchat", filter="administrators")
+                app.get_chat_members(chat_id, filter="administrators")
 
                 # Get all bots
-                app.get_chat_members("pyrogramchat", filter="bots")
+                app.get_chat_members(chat_id, filter="bots")
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py
index 3fc80e5dd7..896b244d16 100644
--- a/pyrogram/methods/chats/get_chat_members_count.py
+++ b/pyrogram/methods/chats/get_chat_members_count.py
@@ -42,7 +42,7 @@ async def get_chat_members_count(
         Example:
             .. code-block:: python
 
-                count = app.get_chat_members_count("pyrogramchat")
+                count = app.get_chat_members_count(chat_id)
                 print(count)
         """
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py
index 3db3935567..c4144384ab 100644
--- a/pyrogram/methods/chats/iter_chat_members.py
+++ b/pyrogram/methods/chats/iter_chat_members.py
@@ -16,7 +16,6 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from string import ascii_lowercase
 from typing import Union, AsyncGenerator, Optional
 
 from pyrogram import raw
@@ -33,10 +32,6 @@ class Filters:
     ADMINISTRATORS = "administrators"
 
 
-QUERIES = [""] + [str(i) for i in range(10)] + list(ascii_lowercase)
-QUERYABLE_FILTERS = (Filters.ALL, Filters.BANNED, Filters.RESTRICTED)
-
-
 class IterChatMembers(Scaffold):
     async def iter_chat_members(
         self,
@@ -57,11 +52,11 @@ async def iter_chat_members(
 
             limit (``int``, *optional*):
                 Limits the number of members to be retrieved.
-                By default, no limit is applied and all members are returned [1]_.
 
             query (``str``, *optional*):
                 Query string to filter members based on their display names and usernames.
-                Defaults to "" (empty string) [2]_.
+                Defaults to "" (empty string).
+                A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
 
             filter (``str``, *optional*):
                 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
@@ -74,11 +69,6 @@ async def iter_chat_members(
                 *"administrators"* - chat administrators only.
                 Defaults to *"recent"*.
 
-        .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
-            on channels.
-
-        .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
-
         Returns:
             ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects.
 
@@ -86,58 +76,52 @@ async def iter_chat_members(
             .. code-block:: python
 
                 # Iterate though all chat members
-                for member in app.iter_chat_members("pyrogramchat"):
+                for member in app.iter_chat_members(chat_id):
                     print(member.user.first_name)
 
                 # Iterate though all administrators
-                for member in app.iter_chat_members("pyrogramchat", filter="administrators"):
+                for member in app.iter_chat_members(chat_id, filter="administrators"):
                     print(member.user.first_name)
 
                 # Iterate though all bots
-                for member in app.iter_chat_members("pyrogramchat", filter="bots"):
+                for member in app.iter_chat_members(chat_id, filter="bots"):
                     print(member.user.first_name)
         """
         current = 0
         yielded = set()
-        queries = [query] if query else QUERIES
         total = limit or (1 << 31) - 1
         limit = min(200, total)
         resolved_chat_id = await self.resolve_peer(chat_id)
+        offset = 0
 
-        if filter not in QUERYABLE_FILTERS:
-            queries = [""]
-
-        for q in queries:
-            offset = 0
-
-            while True:
-                chat_members = await self.get_chat_members(
-                    chat_id=chat_id,
-                    offset=offset,
-                    limit=limit,
-                    query=q,
-                    filter=filter
-                )
+        while True:
+            chat_members = await self.get_chat_members(
+                chat_id=chat_id,
+                offset=offset,
+                limit=limit,
+                query=query,
+                filter=filter
+            )
 
-                if not chat_members:
-                    break
+            if not chat_members:
+                break
 
-                if isinstance(resolved_chat_id, raw.types.InputPeerChat):
-                    total = len(chat_members)
+            if isinstance(resolved_chat_id, raw.types.InputPeerChat):
+                total = len(chat_members)
 
-                offset += len(chat_members)
+            offset += len(chat_members)
 
-                for chat_member in chat_members:
-                    user_id = chat_member.user.id
+            for chat_member in chat_members:
+                user_id = chat_member.user.id
 
-                    if user_id in yielded:
-                        continue
+                if user_id in yielded:
+                    continue
 
-                    yield chat_member
+                yield chat_member
 
-                    yielded.add(chat_member.user.id)
+                yielded.add(chat_member.user.id)
 
-                    current += 1
+                current += 1
 
-                    if current >= total:
-                        return
+                if current >= total:
+                    return
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index fff4d61731..e0a32bdf0a 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -52,7 +52,7 @@ async def set_administrator_title(
         Example:
             .. code-block:: python
 
-                app.set_administrator_title(chat_id, user_id, "ฅ^•ﻌ•^ฅ")
+                app.set_administrator_title(chat_id, user_id, "Admin Title")
         """
         chat_id = await self.resolve_peer(chat_id)
         user_id = await self.resolve_peer(user_id)
diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py
index 19e64925a8..084e775c14 100644
--- a/pyrogram/methods/chats/set_slow_mode.py
+++ b/pyrogram/methods/chats/set_slow_mode.py
@@ -45,10 +45,10 @@ async def set_slow_mode(
             .. code-block:: python
 
                 # Set slow mode to 60 seconds
-                app.set_slow_mode("pyrogramchat", 60)
+                app.set_slow_mode(chat_id, 60)
 
                 # Disable slow mode
-                app.set_slow_mode("pyrogramchat", None)
+                app.set_slow_mode(chat_id, None)
         """
 
         await self.send(
diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py
index 5d00253bcb..79b85b9c54 100644
--- a/pyrogram/methods/contacts/add_contact.py
+++ b/pyrogram/methods/contacts/add_contact.py
@@ -38,7 +38,7 @@ async def add_contact(
             user_id (``int`` | ``str``):
                 Unique identifier (int) or username (str) of the target user.
 
-            first_name (``str``, *optional*):
+            first_name (``str``):
                 User's first name.
 
             last_name (``str``, *optional*):
diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py
index 4039cbe500..9ba190f332 100644
--- a/pyrogram/methods/contacts/import_contacts.py
+++ b/pyrogram/methods/contacts/import_contacts.py
@@ -43,9 +43,9 @@ async def import_contacts(
                 from pyrogram.types import InputPhoneContact
 
                 app.import_contacts([
-                    InputPhoneContact("39123456789", "Foo"),
-                    InputPhoneContact("38987654321", "Bar"),
-                    InputPhoneContact("01234567891", "Baz")])
+                    InputPhoneContact("+1-123-456-7890", "Foo"),
+                    InputPhoneContact("+1-456-789-0123", "Bar"),
+                    InputPhoneContact("+1-789-012-3456", "Baz")])
         """
         imported_contacts = await self.send(
             raw.functions.contacts.ImportContacts(
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index 7845863ccd..4866d82457 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import Union, List, Optional
+from typing import Union, List
 
 from pyrogram import types, utils, raw
 from pyrogram.scaffold import Scaffold
@@ -103,7 +103,8 @@ async def copy_media_group(
                     **await self.parser.parse(
                         captions[i] if isinstance(captions, list) and i < len(captions) and captions[i] else
                         captions if isinstance(captions, str) and i == 0 else
-                        message.caption if message.caption and message.caption != "None" and not type(captions) is str else "")
+                        message.caption if message.caption and message.caption != "None" and not type(
+                            captions) is str else "")
                 )
             )
 
diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py
index 826da89e81..be5da0601b 100644
--- a/pyrogram/methods/messages/download_media.py
+++ b/pyrogram/methods/messages/download_media.py
@@ -92,7 +92,7 @@ async def download_media(
                 app.download_media(message)
 
                 # Download from file id
-                app.download_media("CAADBAADzg4AAvLQYAEz_x2EOgdRwBYE")
+                app.download_media(message.photo.file_id)
 
                 # Keep track of the progress while downloading
                 def progress(current, total):
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index 9218bf6ee2..fc27805980 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -67,7 +67,6 @@ async def forward_messages(
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 2,5
 
                 # Forward a single message
                 app.forward_messages("me", "pyrogram", 20)
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
index 0227cd6e12..98a2f77e6c 100644
--- a/pyrogram/methods/messages/get_history.py
+++ b/pyrogram/methods/messages/get_history.py
@@ -72,13 +72,13 @@ async def get_history(
             .. code-block:: python
 
                 # Get the last 100 messages of a chat
-                app.get_history("pyrogramchat")
+                app.get_history(chat_id)
 
                 # Get the last 3 messages of a chat
-                app.get_history("pyrogramchat", limit=3)
+                app.get_history(chat_id, limit=3)
 
                 # Get 3 messages after skipping the first 5
-                app.get_history("pyrogramchat", offset=5, limit=3)
+                app.get_history(chat_id, offset=5, limit=3)
         """
 
         offset_id = offset_id or (1 if reverse else 0)
diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_history_count.py
index 191a58e083..6552d527f0 100644
--- a/pyrogram/methods/messages/get_history_count.py
+++ b/pyrogram/methods/messages/get_history_count.py
@@ -48,7 +48,7 @@ async def get_history_count(
         Example:
             .. code-block:: python
 
-                app.get_history_count("pyrogramchat")
+                app.get_history_count(chat_id)
         """
 
         r = await self.send(
diff --git a/pyrogram/methods/messages/get_media_group.py b/pyrogram/methods/messages/get_media_group.py
index 83fff12a15..b429224f56 100644
--- a/pyrogram/methods/messages/get_media_group.py
+++ b/pyrogram/methods/messages/get_media_group.py
@@ -50,7 +50,7 @@ async def get_media_group(
                 In case the passed message_id is negative or equal 0. 
                 In case target message doesn't belong to a media group.
         """
-        
+
         # There can be maximum 10 items in a media group. 
         messages = await self.get_messages(chat_id, [msg_id for msg_id in range(message_id - 9, message_id + 10)],
                                            replies=0)
@@ -66,7 +66,7 @@ async def get_media_group(
 
         # There can be maximum 10 items in a media group.
         # The if/else condition to fix the problem of getting correct `media_group_id` when it has `message_id` less then 10.
-        media_group_id = messages[9].media_group_id if len(messages) == 19 else messages[message_id-1].media_group_id
+        media_group_id = messages[9].media_group_id if len(messages) == 19 else messages[message_id - 1].media_group_id
 
         if media_group_id is None:
             raise ValueError("The message doesn't belong to a media group")
diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py
index 39455ec42a..cb4d2abbe0 100644
--- a/pyrogram/methods/messages/get_messages.py
+++ b/pyrogram/methods/messages/get_messages.py
@@ -71,10 +71,10 @@ async def get_messages(
             .. code-block:: python
 
                 # Get one message
-                app.get_messages("pyrogramchat", 51110)
+                app.get_messages(chat_id, 12345)
 
                 # Get more than one message (list of messages)
-                app.get_messages("pyrogramchat", [44625, 51110])
+                app.get_messages(chat_id, [12345, 12346])
 
                 # Get message by ignoring any replied-to message
                 app.get_messages(chat_id, message_id, replies=0)
diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_history.py
index d06d8dcb0c..e7477397da 100644
--- a/pyrogram/methods/messages/read_history.py
+++ b/pyrogram/methods/messages/read_history.py
@@ -47,10 +47,10 @@ async def read_history(
             .. code-block:: python
 
                 # Mark the whole chat as read
-                app.read_history("pyrogramlounge")
+                app.read_history(chat_id)
 
                 # Mark messages as read only up to the given message id
-                app.read_history("pyrogramlounge", 123456)
+                app.read_history(chat_id, 123456)
         """
 
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index bac5d8049b..b016653d75 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -53,6 +53,8 @@ async def search_global(
     ) -> Optional[AsyncGenerator["types.Message", None]]:
         """Search messages globally from all of your chats.
 
+        If you want to get the messages count only, see :meth:`~pyrogram.Client.search_global_count`.
+
         .. note::
 
             Due to server-side limitations, you can only get up to around ~10,000 messages and each message
@@ -91,12 +93,12 @@ async def search_global(
         Example:
             .. code-block:: python
 
-                # Search for "pyrogram". Get the first 420 results
-                for message in app.search_global("pyrogram", limit=420):
+                # Search for "pyrogram". Get the first 50 results
+                for message in app.search_global("pyrogram", limit=50):
                     print(message.text)
 
-                # Search for recent photos from Global. Get the first 69 results
-                for message in app.search_global(filter="photo", limit=69):
+                # Search for recent photos from Global. Get the first 20 results
+                for message in app.search_global(filter="photo", limit=20):
                     print(message.photo)
         """
         try:
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index f8d0cb33d2..b62d4cfe47 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -101,6 +101,8 @@ async def search_messages(
     ) -> Optional[AsyncGenerator["types.Message", None]]:
         """Search for text and media messages inside a specific chat.
 
+        If you want to get the messages count only, see :meth:`~pyrogram.Client.search_messages_count`.
+
         Parameters:
             chat_id (``int`` | ``str``):
                 Unique identifier (int) or username (str) of the target chat.
@@ -142,7 +144,7 @@ async def search_messages(
                 Limits the number of messages to be retrieved.
                 By default, no limit is applied and all messages are returned.
 
-            from_user (``int`` | ``str``):
+            from_user (``int`` | ``str``, *optional*):
                 Unique identifier (int) or username (str) of the target user you want to search for messages from.
 
         Returns:
@@ -151,16 +153,16 @@ async def search_messages(
         Example:
             .. code-block:: python
 
-                # Search for text messages in @pyrogramchat. Get the last 333 results
-                for message in app.search_messages("pyrogramchat", query="dan", limit=333):
+                # Search for text messages in chat. Get the last 120 results
+                for message in app.search_messages(chat_id, query="hello", limit=120):
                     print(message.text)
 
-                # Search for pinned messages in @pyrogramchat
-                for message in app.search_messages("pyrogramchat", filter="pinned"):
+                # Search for pinned messages in chat
+                for message in app.search_messages(chat_id, filter="pinned"):
                     print(message.text)
 
-                # Search for messages containing "hi" sent by @haskell in @pyrogramchat
-                for message in app.search_messages("pyrogramchat", "hi", from_user="haskell"):
+                # Search for messages containing "hello" sent by yourself in chat
+                for message in app.search_messages(chat, "hello", from_user="me"):
                     print(message.text)
         """
         current = 0
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index d1ee9585ff..3a95a95065 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -158,7 +158,7 @@ async def send_animation(
                 app.send_animation("me", "animation.gif")
 
                 # Add caption to the animation
-                app.send_animation("me", "animation.gif", caption="cat")
+                app.send_animation("me", "animation.gif", caption="animation caption")
 
                 # Unsave the animation once is sent
                 app.send_animation("me", "animation.gif", unsave=True)
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index eeb45f6543..6ca16fe161 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -149,18 +149,17 @@ async def send_audio(
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 2,5,8-10,13-16
 
                 # Send audio file by uploading from file
                 app.send_audio("me", "audio.mp3")
 
                 # Add caption to the audio
-                app.send_audio("me", "audio.mp3", caption="shoegaze")
+                app.send_audio("me", "audio.mp3", caption="audio caption")
 
                 # Set audio metadata
                 app.send_audio(
                     "me", "audio.mp3",
-                    title="Printemps émeraude", performer="Alcest", duration=440)
+                    title="Title", performer="Performer", duration=234)
 
                 # Keep track of the progress while uploading
                 def progress(current, total):
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 1f1517e70f..4e7b81495b 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -91,7 +91,7 @@ async def send_cached_media(
         Example:
             .. code-block:: python
 
-                app.send_cached_media("me", "CAADBAADzg4AAvLQYAEz_x2EOgdRwBYE")
+                app.send_cached_media("me", file_id)
         """
 
         r = await self.send(
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index f744fab033..5ce3b01399 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.py
@@ -85,7 +85,7 @@ async def send_contact(
         Example:
             .. code-block:: python
 
-                app.send_contact("me", "+39 123 456 7890", "Dan")
+                app.send_contact("me", "+1-123-456-7890", "Name")
         """
         r = await self.send(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index 6c7f70cd4d..5d89b03cba 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -78,13 +78,13 @@ async def send_dice(
             .. code-block:: python
 
                 # Send a dice
-                app.send_dice("pyrogramlounge")
+                app.send_dice(chat_id)
 
                 # Send a dart
-                app.send_dice("pyrogramlounge", "🎯")
+                app.send_dice(chat_id, "🎯")
 
                 # Send a basketball
-                app.send_dice("pyrogramlounge", "🏀")
+                app.send_dice(chat_id, "🏀")
         """
 
         r = await self.send(
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 3661b2552e..82be26d1d0 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -146,7 +146,7 @@ async def send_document(
                 app.send_document("me", "document.zip")
 
                 # Add caption to the document file
-                app.send_document("me", "document.zip", caption="archive")
+                app.send_document("me", "document.zip", caption="document caption")
 
                 # Keep track of the progress while uploading
                 def progress(current, total):
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index dc8ca7f000..9f4c5e54e1 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -83,7 +83,7 @@ async def send_media_group(
                     [
                         InputMediaPhoto("photo1.jpg"),
                         InputMediaPhoto("photo2.jpg", caption="photo caption"),
-                        InputMediaVideo("video.mp4", caption="a video")
+                        InputMediaVideo("video.mp4", caption="video caption")
                     ]
                 )
         """
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 54fcfe4850..5277ec1fac 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -88,10 +88,9 @@ async def send_message(
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 2,5,8,11,21-23,26-32
 
                 # Simple example
-                app.send_message("haskell", "Thanks for creating **Pyrogram**!")
+                app.send_message("me", "Message sent with **Pyrogram**!")
 
                 # Disable web page previews
                 app.send_message("me", "https://docs.pyrogram.org", disable_web_page_preview=True)
@@ -119,7 +118,7 @@ async def send_message(
                     chat_id, "These are inline buttons",
                     reply_markup=InlineKeyboardMarkup(
                         [
-                            [InlineKeyboardButton("Data", callback_data="hidden_callback_data")],
+                            [InlineKeyboardButton("Data", callback_data="callback_data")],
                             [InlineKeyboardButton("Docs", url="https://docs.pyrogram.org")]
                         ]))
         """
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index 144bba37a5..4aa3ce288a 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -113,7 +113,7 @@ async def send_sticker(
                 app.send_sticker("me", "sticker.webp")
 
                 # Send sticker using file_id
-                app.send_sticker("me", "CAADBAADzg4AAvLQYAEz_x2EOgdRwBYE")
+                app.send_sticker("me", file_id)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index 2356317518..8eff5d9777 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -163,7 +163,7 @@ async def send_video(
                 app.send_video("me", "video.mp4")
 
                 # Add caption to the video
-                app.send_video("me", "video.mp4", caption="recording")
+                app.send_video("me", "video.mp4", caption="video caption")
 
                 # Send self-destructing video
                 app.send_video("me", "video.mp4", ttl_seconds=10)
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 9828ccf898..3782d41be8 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -132,7 +132,7 @@ async def send_voice(
                 app.send_voice("me", "voice.ogg")
 
                 # Add caption to the voice note
-                app.send_voice("me", "voice.ogg", caption="voice note")
+                app.send_voice("me", "voice.ogg", caption="voice caption")
 
                 # Set voice note duration
                 app.send_voice("me", "voice.ogg", duration=20)
diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py
index 45ab2fe71f..6674d229b9 100644
--- a/pyrogram/methods/users/get_common_chats.py
+++ b/pyrogram/methods/users/get_common_chats.py
@@ -42,7 +42,7 @@ async def get_common_chats(self, user_id: Union[int, str]) -> list:
         Example:
             .. code-block:: python
 
-                common = app.get_common_chats("haskell")
+                common = app.get_common_chats(user_id)
                 print(common)
         """
 
diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py
index 0a4686ca2e..fb6f93ca31 100644
--- a/pyrogram/methods/users/get_profile_photos.py
+++ b/pyrogram/methods/users/get_profile_photos.py
@@ -54,13 +54,13 @@ async def get_profile_photos(
             .. code-block:: python
 
                 # Get the first 100 profile photos of a user
-                app.get_profile_photos("haskell")
+                app.get_profile_photos("me")
 
                 # Get only the first profile photo of a user
-                app.get_profile_photos("haskell", limit=1)
+                app.get_profile_photos("me", limit=1)
 
                 # Get 3 profile photos of a user, skip the first 5
-                app.get_profile_photos("haskell", limit=3, offset=5)
+                app.get_profile_photos("me", limit=3, offset=5)
         """
         peer_id = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py
index 10aca0c51f..d27c9da598 100644
--- a/pyrogram/methods/users/get_profile_photos_count.py
+++ b/pyrogram/methods/users/get_profile_photos_count.py
@@ -38,7 +38,7 @@ async def get_profile_photos_count(self, chat_id: Union[int, str]) -> int:
         Example:
             .. code-block:: python
 
-                count = app.get_profile_photos_count("haskell")
+                count = app.get_profile_photos_count("me")
                 print(count)
         """
 
diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py
index 4da15e9b76..3758eaea82 100644
--- a/pyrogram/methods/users/get_users.py
+++ b/pyrogram/methods/users/get_users.py
@@ -47,7 +47,7 @@ async def get_users(
             .. code-block:: python
 
                 # Get information about one user
-                app.get_users("haskell")
+                app.get_users("me")
 
                 # Get information about multiple users at once
                 app.get_users([user1, user2, user3])
diff --git a/pyrogram/methods/users/iter_profile_photos.py b/pyrogram/methods/users/iter_profile_photos.py
index 50af4c442d..3ebd7f5020 100644
--- a/pyrogram/methods/users/iter_profile_photos.py
+++ b/pyrogram/methods/users/iter_profile_photos.py
@@ -54,7 +54,7 @@ async def iter_profile_photos(
         Example:
             .. code-block:: python
 
-                for photo in app.iter_profile_photos("haskell"):
+                for photo in app.iter_profile_photos("me"):
                     print(photo.file_id)
         """
         current = 0
diff --git a/pyrogram/methods/utilities/add_handler.py b/pyrogram/methods/utilities/add_handler.py
index c2f852694c..466e643139 100644
--- a/pyrogram/methods/utilities/add_handler.py
+++ b/pyrogram/methods/utilities/add_handler.py
@@ -42,7 +42,6 @@ def add_handler(self, handler: "Handler", group: int = 0):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 8
 
                 from pyrogram import Client
                 from pyrogram.handlers import MessageHandler
diff --git a/pyrogram/methods/utilities/export_session_string.py b/pyrogram/methods/utilities/export_session_string.py
index 84aceb46bb..545520a26e 100644
--- a/pyrogram/methods/utilities/export_session_string.py
+++ b/pyrogram/methods/utilities/export_session_string.py
@@ -32,7 +32,6 @@ async def export_session_string(self):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 6
 
                 from pyrogram import Client
 
diff --git a/pyrogram/methods/utilities/idle.py b/pyrogram/methods/utilities/idle.py
index 7b41f7af67..0b3c9a1eff 100644
--- a/pyrogram/methods/utilities/idle.py
+++ b/pyrogram/methods/utilities/idle.py
@@ -50,7 +50,6 @@ async def idle():
 
     Example:
         .. code-block:: python
-            :emphasize-lines: 13
 
             from pyrogram import Client, idle
 
diff --git a/pyrogram/methods/utilities/remove_handler.py b/pyrogram/methods/utilities/remove_handler.py
index 97c7f18358..8447f8a9db 100644
--- a/pyrogram/methods/utilities/remove_handler.py
+++ b/pyrogram/methods/utilities/remove_handler.py
@@ -37,7 +37,6 @@ def remove_handler(self, handler: "Handler", group: int = 0):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 11
 
                 from pyrogram import Client
                 from pyrogram.handlers import MessageHandler
diff --git a/pyrogram/methods/utilities/restart.py b/pyrogram/methods/utilities/restart.py
index afd22bb478..9c9e510935 100644
--- a/pyrogram/methods/utilities/restart.py
+++ b/pyrogram/methods/utilities/restart.py
@@ -40,7 +40,6 @@ async def restart(self, block: bool = True):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 8
 
                 from pyrogram import Client
 
diff --git a/pyrogram/methods/utilities/run.py b/pyrogram/methods/utilities/run.py
index 6a55b28cde..53f66f44ba 100644
--- a/pyrogram/methods/utilities/run.py
+++ b/pyrogram/methods/utilities/run.py
@@ -28,16 +28,13 @@ def run(self, coroutine=None):
         """Start the client, idle the main script and finally stop the client.
 
         This is a convenience method that calls :meth:`~pyrogram.Client.start`, :meth:`~pyrogram.idle` and
-        :meth:`~pyrogram.Client.stop` in sequence. It makes running a client less verbose, but is not suitable in case
-        you want to run more than one client in a single main script, since :meth:`~pyrogram.idle` will block after
-        starting the own client.
+        :meth:`~pyrogram.Client.stop` in sequence. It makes running a single client less verbose.
 
         Raises:
             ConnectionError: In case you try to run an already started client.
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 7
 
                 from pyrogram import Client
 
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index 0f08d223c5..62e8acfc5d 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -39,7 +39,6 @@ async def start(self):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 4
 
                 from pyrogram import Client
 
diff --git a/pyrogram/methods/utilities/stop.py b/pyrogram/methods/utilities/stop.py
index 38f0d4c474..4f338d3a2b 100644
--- a/pyrogram/methods/utilities/stop.py
+++ b/pyrogram/methods/utilities/stop.py
@@ -39,7 +39,6 @@ async def stop(self, block: bool = True):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 8
 
                 from pyrogram import Client
 
diff --git a/pyrogram/methods/utilities/stop_transmission.py b/pyrogram/methods/utilities/stop_transmission.py
index a0d04b4c52..6f76f11f47 100644
--- a/pyrogram/methods/utilities/stop_transmission.py
+++ b/pyrogram/methods/utilities/stop_transmission.py
@@ -29,7 +29,6 @@ def stop_transmission(self):
 
         Example:
             .. code-block:: python
-                :emphasize-lines: 9
 
                 from pyrogram import Client
 
@@ -42,6 +41,6 @@ def progress(current, total, client):
                         client.stop_transmission()
 
                 with app:
-                    app.send_document("me", "files.zip", progress=progress, progress_args=(app,))
+                    app.send_document("me", "file.zip", progress=progress, progress_args=(app,))
         """
         raise pyrogram.StopTransmission
diff --git a/pyrogram/raw/core/primitives/vector.py b/pyrogram/raw/core/primitives/vector.py
index 48b2eed91c..a150fba76d 100644
--- a/pyrogram/raw/core/primitives/vector.py
+++ b/pyrogram/raw/core/primitives/vector.py
@@ -33,7 +33,7 @@ class Vector(bytes, TLObject):
     def read_bare(b: BytesIO, size: int) -> Union[int, Any]:
         if size == 4:
             return Int.read(b)
-        
+
         if size == 8:
             return Long.read(b)
 
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 1cf8c1b1fb..8df167a774 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -25,7 +25,6 @@
 from io import BytesIO
 
 import pyrogram
-from pyrogram import __copyright__, __license__, __version__
 from pyrogram import raw
 from pyrogram.connection import Connection
 from pyrogram.crypto import mtproto
@@ -54,8 +53,6 @@ class Session:
     ACKS_THRESHOLD = 8
     PING_INTERVAL = 5
 
-    notice_displayed = False
-
     def __init__(
         self,
         client: "pyrogram.Client",
@@ -65,11 +62,6 @@ def __init__(
         is_media: bool = False,
         is_cdn: bool = False
     ):
-        if not Session.notice_displayed:
-            print(f"Pyrogram v{__version__}, {__copyright__}")
-            print(f"Licensed under the terms of the {__license__}", end="\n\n")
-            Session.notice_displayed = True
-
         self.client = client
         self.dc_id = dc_id
         self.auth_key = auth_key
diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py
index a1f3a662d8..fa6aa050f7 100644
--- a/pyrogram/types/bots_and_keyboards/__init__.py
+++ b/pyrogram/types/bots_and_keyboards/__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 .bot_command import BotCommand
 from .callback_game import CallbackGame
 from .callback_query import CallbackQuery
 from .force_reply import ForceReply
@@ -26,7 +27,6 @@
 from .login_url import LoginUrl
 from .reply_keyboard_markup import ReplyKeyboardMarkup
 from .reply_keyboard_remove import ReplyKeyboardRemove
-from .bot_command import BotCommand
 
 __all__ = [
     "CallbackGame",
diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py
index 9d464eb48e..d22937b929 100644
--- a/pyrogram/types/inline_mode/__init__.py
+++ b/pyrogram/types/inline_mode/__init__.py
@@ -21,9 +21,9 @@
 from .inline_query_result import InlineQueryResult
 from .inline_query_result_animation import InlineQueryResultAnimation
 from .inline_query_result_article import InlineQueryResultArticle
+from .inline_query_result_audio import InlineQueryResultAudio
 from .inline_query_result_photo import InlineQueryResultPhoto
 from .inline_query_result_video import InlineQueryResultVideo
-from .inline_query_result_audio import InlineQueryResultAudio
 
 __all__ = [
     "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 9690baf992..1d70d773e6 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -1370,7 +1370,7 @@ async def reply_contact(
         Example:
             .. code-block:: python
 
-                message.reply_contact(phone_number, "Dan")
+                message.reply_contact("+1-123-456-7890", "Name")
 
         Parameters:
             phone_number (``str``):
diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py
index 9a211fde74..864bf54778 100644
--- a/pyrogram/types/messages_and_media/message_entity.py
+++ b/pyrogram/types/messages_and_media/message_entity.py
@@ -87,7 +87,7 @@ class MessageEntity(Object):
             - "bot_command": ``/start@pyrogrambot``.
             - "url": ``https://pyrogram.org`` (see *url* below).
             - "email": ``do-not-reply@pyrogram.org``.
-            - "phone_number": ``+69-420-1337``.
+            - "phone_number": ``+1-123-456-7890``.
             - "bold": **bold text**.
             - "italic": *italic text*.
             - "underline": underlined text.
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index a925c7dffd..6ccd946524 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -228,7 +228,7 @@ def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat":
             permissions=types.ChatPermissions._parse(getattr(chat, "default_banned_rights", None)),
             members_count=getattr(chat, "participants_count", None),
             dc_id=getattr(getattr(chat, "photo", None), "dc_id", None),
-            has_protected_content=chat.noforwards,
+            has_protected_content=getattr(chat, "noforwards", None),
             client=client
         )
 
@@ -252,7 +252,7 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
             permissions=types.ChatPermissions._parse(getattr(channel, "default_banned_rights", None)),
             members_count=getattr(channel, "participants_count", None),
             dc_id=getattr(getattr(channel, "photo", None), "dc_id", None),
-            has_protected_content=channel.noforwards,
+            has_protected_content=getattr(channel, "noforwards", None),
             client=client
         )
 
diff --git a/setup.py b/setup.py
index c2e2ce96b9..5cbd5eb208 100644
--- a/setup.py
+++ b/setup.py
@@ -133,7 +133,7 @@ def run(self):
 setup(
     name="Pyrogram",
     version=version,
-    description="Telegram MTProto API Client Library and Framework for Python",
+    description="Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots",
     long_description=readme,
     long_description_content_type="text/markdown",
     url="https://github.com/pyrogram",
@@ -153,6 +153,7 @@ def run(self):
         "Programming Language :: Python :: 3.7",
         "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.10",
         "Programming Language :: Python :: Implementation",
         "Programming Language :: Python :: Implementation :: CPython",
         "Programming Language :: Python :: Implementation :: PyPy",
@@ -166,7 +167,7 @@ def run(self):
     keywords="telegram chat messenger mtproto api client library python",
     project_urls={
         "Tracker": "https://github.com/pyrogram/pyrogram/issues",
-        "Community": "https://t.me/Pyrogram",
+        "Community": "https://t.me/pyrogram",
         "Source": "https://github.com/pyrogram/pyrogram",
         "Documentation": "https://docs.pyrogram.org",
     },

From 626a1bd93831eaa6deef61966164de1680660f3a Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 7 Jan 2022 10:23:45 +0100
Subject: [PATCH 040/539] Update copyright year

---
 NOTICE                                                        | 2 +-
 compiler/__init__.py                                          | 2 +-
 compiler/api/__init__.py                                      | 2 +-
 compiler/api/compiler.py                                      | 2 +-
 compiler/docs/__init__.py                                     | 2 +-
 compiler/docs/compiler.py                                     | 2 +-
 compiler/errors/__init__.py                                   | 2 +-
 compiler/errors/compiler.py                                   | 2 +-
 compiler/errors/sort.py                                       | 2 +-
 docs/source/conf.py                                           | 2 +-
 pyrogram/__init__.py                                          | 4 ++--
 pyrogram/client.py                                            | 2 +-
 pyrogram/connection/__init__.py                               | 2 +-
 pyrogram/connection/connection.py                             | 2 +-
 pyrogram/connection/transport/__init__.py                     | 2 +-
 pyrogram/connection/transport/tcp/__init__.py                 | 2 +-
 pyrogram/connection/transport/tcp/tcp.py                      | 2 +-
 pyrogram/connection/transport/tcp/tcp_abridged.py             | 2 +-
 pyrogram/connection/transport/tcp/tcp_abridged_o.py           | 2 +-
 pyrogram/connection/transport/tcp/tcp_full.py                 | 2 +-
 pyrogram/connection/transport/tcp/tcp_intermediate.py         | 2 +-
 pyrogram/connection/transport/tcp/tcp_intermediate_o.py       | 2 +-
 pyrogram/crypto/__init__.py                                   | 2 +-
 pyrogram/crypto/aes.py                                        | 2 +-
 pyrogram/crypto/prime.py                                      | 2 +-
 pyrogram/crypto/rsa.py                                        | 2 +-
 pyrogram/dispatcher.py                                        | 2 +-
 pyrogram/emoji.py                                             | 2 +-
 pyrogram/errors/__init__.py                                   | 2 +-
 pyrogram/errors/rpc_error.py                                  | 2 +-
 pyrogram/file_id.py                                           | 2 +-
 pyrogram/filters.py                                           | 2 +-
 pyrogram/handlers/__init__.py                                 | 2 +-
 pyrogram/handlers/callback_query_handler.py                   | 2 +-
 pyrogram/handlers/chat_join_request_handler.py                | 2 +-
 pyrogram/handlers/chat_member_updated_handler.py              | 2 +-
 pyrogram/handlers/chosen_inline_result_handler.py             | 2 +-
 pyrogram/handlers/deleted_messages_handler.py                 | 2 +-
 pyrogram/handlers/disconnect_handler.py                       | 2 +-
 pyrogram/handlers/handler.py                                  | 2 +-
 pyrogram/handlers/inline_query_handler.py                     | 2 +-
 pyrogram/handlers/message_handler.py                          | 2 +-
 pyrogram/handlers/poll_handler.py                             | 2 +-
 pyrogram/handlers/raw_update_handler.py                       | 2 +-
 pyrogram/handlers/user_status_handler.py                      | 2 +-
 pyrogram/methods/__init__.py                                  | 2 +-
 pyrogram/methods/advanced/__init__.py                         | 2 +-
 pyrogram/methods/advanced/resolve_peer.py                     | 2 +-
 pyrogram/methods/advanced/save_file.py                        | 2 +-
 pyrogram/methods/advanced/send.py                             | 2 +-
 pyrogram/methods/auth/__init__.py                             | 2 +-
 pyrogram/methods/auth/accept_terms_of_service.py              | 2 +-
 pyrogram/methods/auth/check_password.py                       | 2 +-
 pyrogram/methods/auth/connect.py                              | 2 +-
 pyrogram/methods/auth/disconnect.py                           | 2 +-
 pyrogram/methods/auth/get_password_hint.py                    | 2 +-
 pyrogram/methods/auth/initialize.py                           | 2 +-
 pyrogram/methods/auth/log_out.py                              | 2 +-
 pyrogram/methods/auth/recover_password.py                     | 2 +-
 pyrogram/methods/auth/resend_code.py                          | 2 +-
 pyrogram/methods/auth/send_code.py                            | 2 +-
 pyrogram/methods/auth/send_recovery_code.py                   | 2 +-
 pyrogram/methods/auth/sign_in.py                              | 2 +-
 pyrogram/methods/auth/sign_in_bot.py                          | 2 +-
 pyrogram/methods/auth/sign_up.py                              | 2 +-
 pyrogram/methods/auth/terminate.py                            | 2 +-
 pyrogram/methods/bots/__init__.py                             | 2 +-
 pyrogram/methods/bots/answer_callback_query.py                | 2 +-
 pyrogram/methods/bots/answer_inline_query.py                  | 2 +-
 pyrogram/methods/bots/get_game_high_scores.py                 | 2 +-
 pyrogram/methods/bots/get_inline_bot_results.py               | 2 +-
 pyrogram/methods/bots/request_callback_answer.py              | 2 +-
 pyrogram/methods/bots/send_game.py                            | 2 +-
 pyrogram/methods/bots/send_inline_bot_result.py               | 2 +-
 pyrogram/methods/bots/set_bot_commands.py                     | 2 +-
 pyrogram/methods/bots/set_game_score.py                       | 2 +-
 pyrogram/methods/chats/__init__.py                            | 2 +-
 pyrogram/methods/chats/add_chat_members.py                    | 2 +-
 pyrogram/methods/chats/archive_chats.py                       | 2 +-
 pyrogram/methods/chats/ban_chat_member.py                     | 2 +-
 pyrogram/methods/chats/create_channel.py                      | 2 +-
 pyrogram/methods/chats/create_group.py                        | 2 +-
 pyrogram/methods/chats/create_supergroup.py                   | 2 +-
 pyrogram/methods/chats/delete_channel.py                      | 2 +-
 pyrogram/methods/chats/delete_chat_photo.py                   | 2 +-
 pyrogram/methods/chats/delete_supergroup.py                   | 2 +-
 pyrogram/methods/chats/delete_user_history.py                 | 2 +-
 pyrogram/methods/chats/get_chat.py                            | 2 +-
 pyrogram/methods/chats/get_chat_event_log.py                  | 2 +-
 pyrogram/methods/chats/get_chat_member.py                     | 2 +-
 pyrogram/methods/chats/get_chat_members.py                    | 2 +-
 pyrogram/methods/chats/get_chat_members_count.py              | 2 +-
 pyrogram/methods/chats/get_chat_online_count.py               | 2 +-
 pyrogram/methods/chats/get_dialogs.py                         | 2 +-
 pyrogram/methods/chats/get_dialogs_count.py                   | 2 +-
 pyrogram/methods/chats/get_nearby_chats.py                    | 2 +-
 pyrogram/methods/chats/get_send_as_chats.py                   | 2 +-
 pyrogram/methods/chats/iter_chat_members.py                   | 2 +-
 pyrogram/methods/chats/iter_dialogs.py                        | 2 +-
 pyrogram/methods/chats/join_chat.py                           | 2 +-
 pyrogram/methods/chats/leave_chat.py                          | 2 +-
 pyrogram/methods/chats/mark_chat_unread.py                    | 2 +-
 pyrogram/methods/chats/pin_chat_message.py                    | 2 +-
 pyrogram/methods/chats/promote_chat_member.py                 | 2 +-
 pyrogram/methods/chats/restrict_chat_member.py                | 2 +-
 pyrogram/methods/chats/set_administrator_title.py             | 2 +-
 pyrogram/methods/chats/set_chat_description.py                | 2 +-
 pyrogram/methods/chats/set_chat_permissions.py                | 2 +-
 pyrogram/methods/chats/set_chat_photo.py                      | 2 +-
 pyrogram/methods/chats/set_chat_protected_content.py          | 2 +-
 pyrogram/methods/chats/set_chat_title.py                      | 2 +-
 pyrogram/methods/chats/set_send_as_chat.py                    | 2 +-
 pyrogram/methods/chats/set_slow_mode.py                       | 2 +-
 pyrogram/methods/chats/unarchive_chats.py                     | 2 +-
 pyrogram/methods/chats/unban_chat_member.py                   | 2 +-
 pyrogram/methods/chats/unpin_all_chat_messages.py             | 2 +-
 pyrogram/methods/chats/unpin_chat_message.py                  | 2 +-
 pyrogram/methods/chats/update_chat_username.py                | 2 +-
 pyrogram/methods/contacts/__init__.py                         | 2 +-
 pyrogram/methods/contacts/add_contact.py                      | 2 +-
 pyrogram/methods/contacts/delete_contacts.py                  | 2 +-
 pyrogram/methods/contacts/get_contacts.py                     | 2 +-
 pyrogram/methods/contacts/get_contacts_count.py               | 2 +-
 pyrogram/methods/contacts/import_contacts.py                  | 2 +-
 pyrogram/methods/decorators/__init__.py                       | 2 +-
 pyrogram/methods/decorators/on_callback_query.py              | 2 +-
 pyrogram/methods/decorators/on_chat_join_request.py           | 2 +-
 pyrogram/methods/decorators/on_chat_member_updated.py         | 2 +-
 pyrogram/methods/decorators/on_chosen_inline_result.py        | 2 +-
 pyrogram/methods/decorators/on_deleted_messages.py            | 2 +-
 pyrogram/methods/decorators/on_disconnect.py                  | 2 +-
 pyrogram/methods/decorators/on_inline_query.py                | 2 +-
 pyrogram/methods/decorators/on_message.py                     | 2 +-
 pyrogram/methods/decorators/on_poll.py                        | 2 +-
 pyrogram/methods/decorators/on_raw_update.py                  | 2 +-
 pyrogram/methods/decorators/on_user_status.py                 | 2 +-
 pyrogram/methods/invite_links/__init__.py                     | 2 +-
 pyrogram/methods/invite_links/approve_chat_join_request.py    | 2 +-
 pyrogram/methods/invite_links/create_chat_invite_link.py      | 2 +-
 pyrogram/methods/invite_links/decline_chat_join_request.py    | 2 +-
 .../methods/invite_links/delete_chat_admin_invite_links.py    | 2 +-
 pyrogram/methods/invite_links/delete_chat_invite_link.py      | 2 +-
 pyrogram/methods/invite_links/edit_chat_invite_link.py        | 2 +-
 pyrogram/methods/invite_links/export_chat_invite_link.py      | 2 +-
 pyrogram/methods/invite_links/get_chat_admin_invite_links.py  | 2 +-
 .../methods/invite_links/get_chat_admin_invite_links_count.py | 2 +-
 .../methods/invite_links/get_chat_admins_with_invite_links.py | 2 +-
 pyrogram/methods/invite_links/get_chat_invite_link.py         | 2 +-
 pyrogram/methods/invite_links/get_chat_invite_link_members.py | 2 +-
 .../invite_links/get_chat_invite_link_members_count.py        | 2 +-
 pyrogram/methods/invite_links/revoke_chat_invite_link.py      | 2 +-
 pyrogram/methods/messages/__init__.py                         | 2 +-
 pyrogram/methods/messages/copy_media_group.py                 | 2 +-
 pyrogram/methods/messages/copy_message.py                     | 2 +-
 pyrogram/methods/messages/delete_messages.py                  | 2 +-
 pyrogram/methods/messages/download_media.py                   | 2 +-
 pyrogram/methods/messages/edit_inline_caption.py              | 2 +-
 pyrogram/methods/messages/edit_inline_media.py                | 2 +-
 pyrogram/methods/messages/edit_inline_reply_markup.py         | 2 +-
 pyrogram/methods/messages/edit_inline_text.py                 | 2 +-
 pyrogram/methods/messages/edit_message_caption.py             | 2 +-
 pyrogram/methods/messages/edit_message_media.py               | 2 +-
 pyrogram/methods/messages/edit_message_reply_markup.py        | 2 +-
 pyrogram/methods/messages/edit_message_text.py                | 2 +-
 pyrogram/methods/messages/forward_messages.py                 | 2 +-
 pyrogram/methods/messages/get_discussion_message.py           | 2 +-
 pyrogram/methods/messages/get_history.py                      | 2 +-
 pyrogram/methods/messages/get_history_count.py                | 2 +-
 pyrogram/methods/messages/get_media_group.py                  | 2 +-
 pyrogram/methods/messages/get_messages.py                     | 2 +-
 pyrogram/methods/messages/inline_session.py                   | 2 +-
 pyrogram/methods/messages/iter_history.py                     | 2 +-
 pyrogram/methods/messages/read_history.py                     | 2 +-
 pyrogram/methods/messages/retract_vote.py                     | 2 +-
 pyrogram/methods/messages/search_global.py                    | 2 +-
 pyrogram/methods/messages/search_global_count.py              | 2 +-
 pyrogram/methods/messages/search_messages.py                  | 2 +-
 pyrogram/methods/messages/search_messages_count.py            | 2 +-
 pyrogram/methods/messages/send_animation.py                   | 2 +-
 pyrogram/methods/messages/send_audio.py                       | 2 +-
 pyrogram/methods/messages/send_cached_media.py                | 2 +-
 pyrogram/methods/messages/send_chat_action.py                 | 2 +-
 pyrogram/methods/messages/send_contact.py                     | 2 +-
 pyrogram/methods/messages/send_dice.py                        | 2 +-
 pyrogram/methods/messages/send_document.py                    | 2 +-
 pyrogram/methods/messages/send_location.py                    | 2 +-
 pyrogram/methods/messages/send_media_group.py                 | 2 +-
 pyrogram/methods/messages/send_message.py                     | 2 +-
 pyrogram/methods/messages/send_photo.py                       | 2 +-
 pyrogram/methods/messages/send_poll.py                        | 2 +-
 pyrogram/methods/messages/send_reaction.py                    | 2 +-
 pyrogram/methods/messages/send_sticker.py                     | 2 +-
 pyrogram/methods/messages/send_venue.py                       | 2 +-
 pyrogram/methods/messages/send_video.py                       | 2 +-
 pyrogram/methods/messages/send_video_note.py                  | 2 +-
 pyrogram/methods/messages/send_voice.py                       | 2 +-
 pyrogram/methods/messages/stop_poll.py                        | 2 +-
 pyrogram/methods/messages/vote_poll.py                        | 2 +-
 pyrogram/methods/password/__init__.py                         | 2 +-
 pyrogram/methods/password/change_cloud_password.py            | 2 +-
 pyrogram/methods/password/enable_cloud_password.py            | 2 +-
 pyrogram/methods/password/remove_cloud_password.py            | 2 +-
 pyrogram/methods/users/__init__.py                            | 2 +-
 pyrogram/methods/users/block_user.py                          | 2 +-
 pyrogram/methods/users/delete_profile_photos.py               | 2 +-
 pyrogram/methods/users/get_common_chats.py                    | 2 +-
 pyrogram/methods/users/get_me.py                              | 2 +-
 pyrogram/methods/users/get_profile_photos.py                  | 2 +-
 pyrogram/methods/users/get_profile_photos_count.py            | 2 +-
 pyrogram/methods/users/get_users.py                           | 2 +-
 pyrogram/methods/users/iter_profile_photos.py                 | 2 +-
 pyrogram/methods/users/set_profile_photo.py                   | 2 +-
 pyrogram/methods/users/unblock_user.py                        | 2 +-
 pyrogram/methods/users/update_profile.py                      | 2 +-
 pyrogram/methods/users/update_username.py                     | 2 +-
 pyrogram/methods/utilities/__init__.py                        | 2 +-
 pyrogram/methods/utilities/add_handler.py                     | 2 +-
 pyrogram/methods/utilities/export_session_string.py           | 2 +-
 pyrogram/methods/utilities/idle.py                            | 2 +-
 pyrogram/methods/utilities/remove_handler.py                  | 2 +-
 pyrogram/methods/utilities/restart.py                         | 2 +-
 pyrogram/methods/utilities/run.py                             | 2 +-
 pyrogram/methods/utilities/start.py                           | 2 +-
 pyrogram/methods/utilities/stop.py                            | 2 +-
 pyrogram/methods/utilities/stop_transmission.py               | 2 +-
 pyrogram/mime_types.py                                        | 2 +-
 pyrogram/parser/__init__.py                                   | 2 +-
 pyrogram/parser/html.py                                       | 2 +-
 pyrogram/parser/markdown.py                                   | 2 +-
 pyrogram/parser/parser.py                                     | 2 +-
 pyrogram/parser/utils.py                                      | 2 +-
 pyrogram/raw/__init__.py                                      | 2 +-
 pyrogram/raw/core/__init__.py                                 | 2 +-
 pyrogram/raw/core/future_salt.py                              | 2 +-
 pyrogram/raw/core/future_salts.py                             | 2 +-
 pyrogram/raw/core/gzip_packed.py                              | 2 +-
 pyrogram/raw/core/list.py                                     | 2 +-
 pyrogram/raw/core/message.py                                  | 2 +-
 pyrogram/raw/core/msg_container.py                            | 2 +-
 pyrogram/raw/core/primitives/__init__.py                      | 2 +-
 pyrogram/raw/core/primitives/bool.py                          | 2 +-
 pyrogram/raw/core/primitives/bytes.py                         | 2 +-
 pyrogram/raw/core/primitives/double.py                        | 2 +-
 pyrogram/raw/core/primitives/int.py                           | 2 +-
 pyrogram/raw/core/primitives/string.py                        | 2 +-
 pyrogram/raw/core/primitives/vector.py                        | 2 +-
 pyrogram/raw/core/tl_object.py                                | 2 +-
 pyrogram/scaffold.py                                          | 2 +-
 pyrogram/session/__init__.py                                  | 2 +-
 pyrogram/session/auth.py                                      | 2 +-
 pyrogram/session/internals/__init__.py                        | 2 +-
 pyrogram/session/internals/data_center.py                     | 2 +-
 pyrogram/session/internals/msg_factory.py                     | 2 +-
 pyrogram/session/internals/msg_id.py                          | 2 +-
 pyrogram/session/internals/seq_no.py                          | 2 +-
 pyrogram/session/session.py                                   | 2 +-
 pyrogram/storage/__init__.py                                  | 2 +-
 pyrogram/storage/file_storage.py                              | 2 +-
 pyrogram/storage/memory_storage.py                            | 2 +-
 pyrogram/storage/sqlite_storage.py                            | 2 +-
 pyrogram/storage/storage.py                                   | 2 +-
 pyrogram/sync.py                                              | 2 +-
 pyrogram/syncer.py                                            | 2 +-
 pyrogram/types/__init__.py                                    | 2 +-
 pyrogram/types/authorization/__init__.py                      | 2 +-
 pyrogram/types/authorization/sent_code.py                     | 2 +-
 pyrogram/types/authorization/terms_of_service.py              | 2 +-
 pyrogram/types/bots_and_keyboards/__init__.py                 | 2 +-
 pyrogram/types/bots_and_keyboards/bot_command.py              | 2 +-
 pyrogram/types/bots_and_keyboards/callback_game.py            | 2 +-
 pyrogram/types/bots_and_keyboards/callback_query.py           | 2 +-
 pyrogram/types/bots_and_keyboards/force_reply.py              | 2 +-
 pyrogram/types/bots_and_keyboards/game_high_score.py          | 2 +-
 pyrogram/types/bots_and_keyboards/inline_keyboard_button.py   | 2 +-
 pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py   | 2 +-
 pyrogram/types/bots_and_keyboards/keyboard_button.py          | 2 +-
 pyrogram/types/bots_and_keyboards/login_url.py                | 2 +-
 pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py    | 2 +-
 pyrogram/types/bots_and_keyboards/reply_keyboard_remove.py    | 2 +-
 pyrogram/types/inline_mode/__init__.py                        | 2 +-
 pyrogram/types/inline_mode/chosen_inline_result.py            | 2 +-
 pyrogram/types/inline_mode/inline_query.py                    | 2 +-
 pyrogram/types/inline_mode/inline_query_result.py             | 2 +-
 pyrogram/types/inline_mode/inline_query_result_animation.py   | 2 +-
 pyrogram/types/inline_mode/inline_query_result_article.py     | 2 +-
 pyrogram/types/inline_mode/inline_query_result_photo.py       | 2 +-
 pyrogram/types/inline_mode/inline_query_result_video.py       | 2 +-
 pyrogram/types/input_media/__init__.py                        | 2 +-
 pyrogram/types/input_media/input_media.py                     | 2 +-
 pyrogram/types/input_media/input_media_animation.py           | 2 +-
 pyrogram/types/input_media/input_media_audio.py               | 2 +-
 pyrogram/types/input_media/input_media_document.py            | 2 +-
 pyrogram/types/input_media/input_media_photo.py               | 2 +-
 pyrogram/types/input_media/input_media_video.py               | 2 +-
 pyrogram/types/input_media/input_phone_contact.py             | 2 +-
 pyrogram/types/input_message_content/__init__.py              | 2 +-
 pyrogram/types/input_message_content/input_message_content.py | 2 +-
 .../types/input_message_content/input_text_message_content.py | 2 +-
 pyrogram/types/list.py                                        | 2 +-
 pyrogram/types/messages_and_media/__init__.py                 | 2 +-
 pyrogram/types/messages_and_media/animation.py                | 2 +-
 pyrogram/types/messages_and_media/audio.py                    | 2 +-
 pyrogram/types/messages_and_media/contact.py                  | 2 +-
 pyrogram/types/messages_and_media/dice.py                     | 2 +-
 pyrogram/types/messages_and_media/document.py                 | 2 +-
 pyrogram/types/messages_and_media/game.py                     | 2 +-
 pyrogram/types/messages_and_media/location.py                 | 2 +-
 pyrogram/types/messages_and_media/message.py                  | 2 +-
 pyrogram/types/messages_and_media/message_entity.py           | 2 +-
 pyrogram/types/messages_and_media/photo.py                    | 2 +-
 pyrogram/types/messages_and_media/poll.py                     | 2 +-
 pyrogram/types/messages_and_media/poll_option.py              | 2 +-
 pyrogram/types/messages_and_media/reaction.py                 | 2 +-
 pyrogram/types/messages_and_media/sticker.py                  | 2 +-
 pyrogram/types/messages_and_media/stripped_thumbnail.py       | 2 +-
 pyrogram/types/messages_and_media/thumbnail.py                | 2 +-
 pyrogram/types/messages_and_media/venue.py                    | 2 +-
 pyrogram/types/messages_and_media/video.py                    | 2 +-
 pyrogram/types/messages_and_media/video_note.py               | 2 +-
 pyrogram/types/messages_and_media/voice.py                    | 2 +-
 pyrogram/types/messages_and_media/webpage.py                  | 2 +-
 pyrogram/types/object.py                                      | 2 +-
 pyrogram/types/update.py                                      | 2 +-
 pyrogram/types/user_and_chats/__init__.py                     | 2 +-
 pyrogram/types/user_and_chats/chat.py                         | 2 +-
 pyrogram/types/user_and_chats/chat_admin_with_invite_links.py | 2 +-
 pyrogram/types/user_and_chats/chat_event.py                   | 2 +-
 pyrogram/types/user_and_chats/chat_event_filter.py            | 2 +-
 pyrogram/types/user_and_chats/chat_invite_link.py             | 2 +-
 pyrogram/types/user_and_chats/chat_join_request.py            | 2 +-
 pyrogram/types/user_and_chats/chat_member.py                  | 2 +-
 pyrogram/types/user_and_chats/chat_member_updated.py          | 2 +-
 pyrogram/types/user_and_chats/chat_permissions.py             | 2 +-
 pyrogram/types/user_and_chats/chat_photo.py                   | 2 +-
 pyrogram/types/user_and_chats/chat_preview.py                 | 2 +-
 pyrogram/types/user_and_chats/dialog.py                       | 2 +-
 pyrogram/types/user_and_chats/invite_link_importer.py         | 2 +-
 pyrogram/types/user_and_chats/restriction.py                  | 2 +-
 pyrogram/types/user_and_chats/user.py                         | 2 +-
 pyrogram/types/user_and_chats/voice_chat_ended.py             | 2 +-
 pyrogram/types/user_and_chats/voice_chat_members_invited.py   | 2 +-
 pyrogram/types/user_and_chats/voice_chat_scheduled.py         | 2 +-
 pyrogram/types/user_and_chats/voice_chat_started.py           | 2 +-
 pyrogram/utils.py                                             | 2 +-
 setup.py                                                      | 2 +-
 tests/__init__.py                                             | 2 +-
 tests/filters/__init__.py                                     | 2 +-
 tests/filters/test_command.py                                 | 2 +-
 tests/test_file_id.py                                         | 2 +-
 349 files changed, 350 insertions(+), 350 deletions(-)

diff --git a/NOTICE b/NOTICE
index 58defc6402..7a9aaab647 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,5 @@
 Pyrogram - Telegram MTProto API Client Library for Python
-Copyright (C) 2017-2021 Dan 
+Copyright (C) 2017-present Dan 
 
 This file is part of Pyrogram.
 
diff --git a/compiler/__init__.py b/compiler/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/compiler/__init__.py
+++ b/compiler/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/api/__init__.py b/compiler/api/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/compiler/api/__init__.py
+++ b/compiler/api/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index d79fc80160..192d6a6759 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/docs/__init__.py b/compiler/docs/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/compiler/docs/__init__.py
+++ b/compiler/docs/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 65f6743660..cb4de0a6b5 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/errors/__init__.py b/compiler/errors/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/compiler/errors/__init__.py
+++ b/compiler/errors/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/errors/compiler.py b/compiler/errors/compiler.py
index feda92316c..d2c1010456 100644
--- a/compiler/errors/compiler.py
+++ b/compiler/errors/compiler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/compiler/errors/sort.py b/compiler/errors/sort.py
index 69fc0437a8..db94e35162 100644
--- a/compiler/errors/sort.py
+++ b/compiler/errors/sort.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/docs/source/conf.py b/docs/source/conf.py
index ae84c5b806..53ac9012c5 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index c0c7b21916..96ddb664a4 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
@@ -18,7 +18,7 @@
 
 __version__ = "1.2.9"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
-__copyright__ = "Copyright (C) 2017-2021 Dan "
+__copyright__ = "Copyright (C) 2017-present Dan "
 
 from concurrent.futures.thread import ThreadPoolExecutor
 
diff --git a/pyrogram/client.py b/pyrogram/client.py
index 65514cf6cc..ce76920fa9 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/__init__.py b/pyrogram/connection/__init__.py
index 4b63340ee6..4665ce913f 100644
--- a/pyrogram/connection/__init__.py
+++ b/pyrogram/connection/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 3ab52d7105..2173c70b94 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/__init__.py b/pyrogram/connection/transport/__init__.py
index b856583cf0..2d08832a70 100644
--- a/pyrogram/connection/transport/__init__.py
+++ b/pyrogram/connection/transport/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/__init__.py b/pyrogram/connection/transport/tcp/__init__.py
index 6a5456de3f..3e23a88379 100644
--- a/pyrogram/connection/transport/tcp/__init__.py
+++ b/pyrogram/connection/transport/tcp/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py
index 6c3e760315..0b858c0265 100644
--- a/pyrogram/connection/transport/tcp/tcp.py
+++ b/pyrogram/connection/transport/tcp/tcp.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp_abridged.py b/pyrogram/connection/transport/tcp/tcp_abridged.py
index 0282e66815..77d44cf41c 100644
--- a/pyrogram/connection/transport/tcp/tcp_abridged.py
+++ b/pyrogram/connection/transport/tcp/tcp_abridged.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
index 9db148bf2f..12a832f6a9 100644
--- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp_full.py b/pyrogram/connection/transport/tcp/tcp_full.py
index 8c80f454be..8bd89000c8 100644
--- a/pyrogram/connection/transport/tcp/tcp_full.py
+++ b/pyrogram/connection/transport/tcp/tcp_full.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate.py b/pyrogram/connection/transport/tcp/tcp_intermediate.py
index 6b18ab15c7..b6aef335a9 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
index c257fdd54e..5b267661db 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/crypto/__init__.py b/pyrogram/crypto/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/pyrogram/crypto/__init__.py
+++ b/pyrogram/crypto/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py
index 05aca1c087..532cd5e8d0 100644
--- a/pyrogram/crypto/aes.py
+++ b/pyrogram/crypto/aes.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/crypto/prime.py b/pyrogram/crypto/prime.py
index 82d1df758e..e919e22ce4 100644
--- a/pyrogram/crypto/prime.py
+++ b/pyrogram/crypto/prime.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/crypto/rsa.py b/pyrogram/crypto/rsa.py
index 8804f87a60..3fd7d67ba3 100644
--- a/pyrogram/crypto/rsa.py
+++ b/pyrogram/crypto/rsa.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py
index ccd8b9da82..0c425f4de3 100644
--- a/pyrogram/dispatcher.py
+++ b/pyrogram/dispatcher.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/emoji.py b/pyrogram/emoji.py
index 69e44fa574..19dd7e8172 100644
--- a/pyrogram/emoji.py
+++ b/pyrogram/emoji.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/errors/__init__.py b/pyrogram/errors/__init__.py
index c92f24b1eb..0ae393620e 100644
--- a/pyrogram/errors/__init__.py
+++ b/pyrogram/errors/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/errors/rpc_error.py b/pyrogram/errors/rpc_error.py
index a9fd66556d..444447f2bb 100644
--- a/pyrogram/errors/rpc_error.py
+++ b/pyrogram/errors/rpc_error.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/file_id.py b/pyrogram/file_id.py
index ef1319ecae..ee1ccc4a89 100644
--- a/pyrogram/file_id.py
+++ b/pyrogram/file_id.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index e583e0638e..46ca896f4d 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/__init__.py b/pyrogram/handlers/__init__.py
index 1312c6e59d..2b7ef0a201 100644
--- a/pyrogram/handlers/__init__.py
+++ b/pyrogram/handlers/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/callback_query_handler.py b/pyrogram/handlers/callback_query_handler.py
index e28e7216a6..b582d728c8 100644
--- a/pyrogram/handlers/callback_query_handler.py
+++ b/pyrogram/handlers/callback_query_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/chat_join_request_handler.py b/pyrogram/handlers/chat_join_request_handler.py
index f26abefc95..03e2ac674e 100644
--- a/pyrogram/handlers/chat_join_request_handler.py
+++ b/pyrogram/handlers/chat_join_request_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/chat_member_updated_handler.py b/pyrogram/handlers/chat_member_updated_handler.py
index d03eae11f3..8cfdd72696 100644
--- a/pyrogram/handlers/chat_member_updated_handler.py
+++ b/pyrogram/handlers/chat_member_updated_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/chosen_inline_result_handler.py b/pyrogram/handlers/chosen_inline_result_handler.py
index 42b5bb79eb..81691a3577 100644
--- a/pyrogram/handlers/chosen_inline_result_handler.py
+++ b/pyrogram/handlers/chosen_inline_result_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/deleted_messages_handler.py b/pyrogram/handlers/deleted_messages_handler.py
index e41158f93b..a336c6503b 100644
--- a/pyrogram/handlers/deleted_messages_handler.py
+++ b/pyrogram/handlers/deleted_messages_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/disconnect_handler.py b/pyrogram/handlers/disconnect_handler.py
index 2302db5821..c471e8c7e6 100644
--- a/pyrogram/handlers/disconnect_handler.py
+++ b/pyrogram/handlers/disconnect_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/handler.py b/pyrogram/handlers/handler.py
index 78786ab797..c666d042e2 100644
--- a/pyrogram/handlers/handler.py
+++ b/pyrogram/handlers/handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/inline_query_handler.py b/pyrogram/handlers/inline_query_handler.py
index 31f085b35f..0ce58d17a8 100644
--- a/pyrogram/handlers/inline_query_handler.py
+++ b/pyrogram/handlers/inline_query_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/message_handler.py b/pyrogram/handlers/message_handler.py
index f20669afc8..144dbe9111 100644
--- a/pyrogram/handlers/message_handler.py
+++ b/pyrogram/handlers/message_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/poll_handler.py b/pyrogram/handlers/poll_handler.py
index 09940c1252..0151f2b75c 100644
--- a/pyrogram/handlers/poll_handler.py
+++ b/pyrogram/handlers/poll_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/raw_update_handler.py b/pyrogram/handlers/raw_update_handler.py
index 53413c3144..e12e8477e4 100644
--- a/pyrogram/handlers/raw_update_handler.py
+++ b/pyrogram/handlers/raw_update_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/handlers/user_status_handler.py b/pyrogram/handlers/user_status_handler.py
index 23b9af2f97..caebac742b 100644
--- a/pyrogram/handlers/user_status_handler.py
+++ b/pyrogram/handlers/user_status_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/__init__.py b/pyrogram/methods/__init__.py
index ee453ce3bb..ea71f6b178 100644
--- a/pyrogram/methods/__init__.py
+++ b/pyrogram/methods/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/advanced/__init__.py b/pyrogram/methods/advanced/__init__.py
index 934b0b9f21..a3cf461af7 100644
--- a/pyrogram/methods/advanced/__init__.py
+++ b/pyrogram/methods/advanced/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/advanced/resolve_peer.py b/pyrogram/methods/advanced/resolve_peer.py
index 3b3915aca6..2a39780cf2 100644
--- a/pyrogram/methods/advanced/resolve_peer.py
+++ b/pyrogram/methods/advanced/resolve_peer.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py
index 8436156584..b612b1124f 100644
--- a/pyrogram/methods/advanced/save_file.py
+++ b/pyrogram/methods/advanced/save_file.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/advanced/send.py b/pyrogram/methods/advanced/send.py
index 9ac7ec24d6..8ef0849c63 100644
--- a/pyrogram/methods/advanced/send.py
+++ b/pyrogram/methods/advanced/send.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/__init__.py b/pyrogram/methods/auth/__init__.py
index 2227be8102..ce585648da 100644
--- a/pyrogram/methods/auth/__init__.py
+++ b/pyrogram/methods/auth/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py
index c8cfd36d71..5641a8ac72 100644
--- a/pyrogram/methods/auth/accept_terms_of_service.py
+++ b/pyrogram/methods/auth/accept_terms_of_service.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/check_password.py b/pyrogram/methods/auth/check_password.py
index 1dd60f7ebf..1cfa526ba0 100644
--- a/pyrogram/methods/auth/check_password.py
+++ b/pyrogram/methods/auth/check_password.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/connect.py b/pyrogram/methods/auth/connect.py
index 7376ddf60e..82cf661f90 100644
--- a/pyrogram/methods/auth/connect.py
+++ b/pyrogram/methods/auth/connect.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/disconnect.py b/pyrogram/methods/auth/disconnect.py
index 4d516a119e..ddc1e7e1cd 100644
--- a/pyrogram/methods/auth/disconnect.py
+++ b/pyrogram/methods/auth/disconnect.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/get_password_hint.py b/pyrogram/methods/auth/get_password_hint.py
index 44f1439c84..6ba3f280b4 100644
--- a/pyrogram/methods/auth/get_password_hint.py
+++ b/pyrogram/methods/auth/get_password_hint.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py
index 0fb276f7fd..0b7608818b 100644
--- a/pyrogram/methods/auth/initialize.py
+++ b/pyrogram/methods/auth/initialize.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/log_out.py b/pyrogram/methods/auth/log_out.py
index 06c9824bbd..7174545dc5 100644
--- a/pyrogram/methods/auth/log_out.py
+++ b/pyrogram/methods/auth/log_out.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/recover_password.py b/pyrogram/methods/auth/recover_password.py
index 03887f4ed8..db877ec8d6 100644
--- a/pyrogram/methods/auth/recover_password.py
+++ b/pyrogram/methods/auth/recover_password.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/resend_code.py b/pyrogram/methods/auth/resend_code.py
index cf8ce3be6d..18e835f53d 100644
--- a/pyrogram/methods/auth/resend_code.py
+++ b/pyrogram/methods/auth/resend_code.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py
index 62fb256bc6..3f92ccebcb 100644
--- a/pyrogram/methods/auth/send_code.py
+++ b/pyrogram/methods/auth/send_code.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/send_recovery_code.py b/pyrogram/methods/auth/send_recovery_code.py
index 4c28f1cf0b..078799783e 100644
--- a/pyrogram/methods/auth/send_recovery_code.py
+++ b/pyrogram/methods/auth/send_recovery_code.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py
index 6e5e7c46fe..19c0fbc165 100644
--- a/pyrogram/methods/auth/sign_in.py
+++ b/pyrogram/methods/auth/sign_in.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py
index 490ceced27..7cbcb1aca5 100644
--- a/pyrogram/methods/auth/sign_in_bot.py
+++ b/pyrogram/methods/auth/sign_in_bot.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py
index bed07f8509..4b18a73292 100644
--- a/pyrogram/methods/auth/sign_up.py
+++ b/pyrogram/methods/auth/sign_up.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py
index 70166fe428..46b6698263 100644
--- a/pyrogram/methods/auth/terminate.py
+++ b/pyrogram/methods/auth/terminate.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py
index 1e6b91465e..0051c6c3fb 100644
--- a/pyrogram/methods/bots/__init__.py
+++ b/pyrogram/methods/bots/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py
index ccb1f4449a..941389b74b 100644
--- a/pyrogram/methods/bots/answer_callback_query.py
+++ b/pyrogram/methods/bots/answer_callback_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py
index 66bd739ffb..9683e1bb34 100644
--- a/pyrogram/methods/bots/answer_inline_query.py
+++ b/pyrogram/methods/bots/answer_inline_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py
index 59ddb67ec5..cd0b09ba3d 100644
--- a/pyrogram/methods/bots/get_game_high_scores.py
+++ b/pyrogram/methods/bots/get_game_high_scores.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py
index 73b4c5d786..800de93e4c 100644
--- a/pyrogram/methods/bots/get_inline_bot_results.py
+++ b/pyrogram/methods/bots/get_inline_bot_results.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py
index 9d32e60f07..5db9dfe079 100644
--- a/pyrogram/methods/bots/request_callback_answer.py
+++ b/pyrogram/methods/bots/request_callback_answer.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py
index f6e6a3409c..05b9094f58 100644
--- a/pyrogram/methods/bots/send_game.py
+++ b/pyrogram/methods/bots/send_game.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py
index e91aac9789..de00546c13 100644
--- a/pyrogram/methods/bots/send_inline_bot_result.py
+++ b/pyrogram/methods/bots/send_inline_bot_result.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index 3a3c8f54a8..02158c0cb6 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py
index e8af3125ad..edb38dcfe1 100644
--- a/pyrogram/methods/bots/set_game_score.py
+++ b/pyrogram/methods/bots/set_game_score.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py
index 70c02dee15..cba67600af 100644
--- a/pyrogram/methods/chats/__init__.py
+++ b/pyrogram/methods/chats/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py
index 154f1ee1e4..70fb0f97c4 100644
--- a/pyrogram/methods/chats/add_chat_members.py
+++ b/pyrogram/methods/chats/add_chat_members.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py
index df3f69c103..c65b762206 100644
--- a/pyrogram/methods/chats/archive_chats.py
+++ b/pyrogram/methods/chats/archive_chats.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py
index 0d17fec699..bdf1175197 100644
--- a/pyrogram/methods/chats/ban_chat_member.py
+++ b/pyrogram/methods/chats/ban_chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py
index 3e1fab82a6..b3b21eaea3 100644
--- a/pyrogram/methods/chats/create_channel.py
+++ b/pyrogram/methods/chats/create_channel.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py
index f1833d80e6..2117d3699a 100644
--- a/pyrogram/methods/chats/create_group.py
+++ b/pyrogram/methods/chats/create_group.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py
index 866a732b56..2c72e25b30 100644
--- a/pyrogram/methods/chats/create_supergroup.py
+++ b/pyrogram/methods/chats/create_supergroup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py
index 0a47fb43aa..3f9baa4ff6 100644
--- a/pyrogram/methods/chats/delete_channel.py
+++ b/pyrogram/methods/chats/delete_channel.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py
index 7bd82337a9..4311658bd5 100644
--- a/pyrogram/methods/chats/delete_chat_photo.py
+++ b/pyrogram/methods/chats/delete_chat_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py
index 016be5463f..b9d3bdf7d0 100644
--- a/pyrogram/methods/chats/delete_supergroup.py
+++ b/pyrogram/methods/chats/delete_supergroup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py
index 8043432de3..ca9d0c5941 100644
--- a/pyrogram/methods/chats/delete_user_history.py
+++ b/pyrogram/methods/chats/delete_user_history.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py
index 4420b5feb7..d9ecb166ba 100644
--- a/pyrogram/methods/chats/get_chat.py
+++ b/pyrogram/methods/chats/get_chat.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py
index 46c031edb8..3e392a204d 100644
--- a/pyrogram/methods/chats/get_chat_event_log.py
+++ b/pyrogram/methods/chats/get_chat_event_log.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py
index 711eafdd41..9987327c6b 100644
--- a/pyrogram/methods/chats/get_chat_member.py
+++ b/pyrogram/methods/chats/get_chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index c984107c62..07d831a964 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py
index 896b244d16..aa943eea2a 100644
--- a/pyrogram/methods/chats/get_chat_members_count.py
+++ b/pyrogram/methods/chats/get_chat_members_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py
index 5d3d861f87..a8d1321446 100644
--- a/pyrogram/methods/chats/get_chat_online_count.py
+++ b/pyrogram/methods/chats/get_chat_online_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py
index 4e3b11113e..7a9d6a485f 100644
--- a/pyrogram/methods/chats/get_dialogs.py
+++ b/pyrogram/methods/chats/get_dialogs.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py
index 260cc4f6ba..a8598e5fcc 100644
--- a/pyrogram/methods/chats/get_dialogs_count.py
+++ b/pyrogram/methods/chats/get_dialogs_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py
index 22ff4fc07f..dcceb4398b 100644
--- a/pyrogram/methods/chats/get_nearby_chats.py
+++ b/pyrogram/methods/chats/get_nearby_chats.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py
index 6eb6c4a684..4d2fae4824 100644
--- a/pyrogram/methods/chats/get_send_as_chats.py
+++ b/pyrogram/methods/chats/get_send_as_chats.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py
index c4144384ab..e9fa5b8277 100644
--- a/pyrogram/methods/chats/iter_chat_members.py
+++ b/pyrogram/methods/chats/iter_chat_members.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py
index 124eff52f1..2584d98d63 100644
--- a/pyrogram/methods/chats/iter_dialogs.py
+++ b/pyrogram/methods/chats/iter_dialogs.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py
index 41d0aa9313..ca720d6d0b 100644
--- a/pyrogram/methods/chats/join_chat.py
+++ b/pyrogram/methods/chats/join_chat.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py
index 84ab4ebc04..3271a1f952 100644
--- a/pyrogram/methods/chats/leave_chat.py
+++ b/pyrogram/methods/chats/leave_chat.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/mark_chat_unread.py b/pyrogram/methods/chats/mark_chat_unread.py
index a85cfccbcd..4a48c5d6fa 100644
--- a/pyrogram/methods/chats/mark_chat_unread.py
+++ b/pyrogram/methods/chats/mark_chat_unread.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py
index 11983f5727..d4d6b040f8 100644
--- a/pyrogram/methods/chats/pin_chat_message.py
+++ b/pyrogram/methods/chats/pin_chat_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py
index e45b58764c..8ab5fe29e8 100644
--- a/pyrogram/methods/chats/promote_chat_member.py
+++ b/pyrogram/methods/chats/promote_chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index d0cc933831..7c74d68536 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index e0a32bdf0a..382d1faccc 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py
index 0a7bdf7f87..6d2575f207 100644
--- a/pyrogram/methods/chats/set_chat_description.py
+++ b/pyrogram/methods/chats/set_chat_description.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py
index fe208818b1..2c59190657 100644
--- a/pyrogram/methods/chats/set_chat_permissions.py
+++ b/pyrogram/methods/chats/set_chat_permissions.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py
index e111449040..266253d632 100644
--- a/pyrogram/methods/chats/set_chat_photo.py
+++ b/pyrogram/methods/chats/set_chat_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_chat_protected_content.py b/pyrogram/methods/chats/set_chat_protected_content.py
index 8057873da3..d63e381d98 100644
--- a/pyrogram/methods/chats/set_chat_protected_content.py
+++ b/pyrogram/methods/chats/set_chat_protected_content.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py
index 0cc4c6d2e4..62649f3850 100644
--- a/pyrogram/methods/chats/set_chat_title.py
+++ b/pyrogram/methods/chats/set_chat_title.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py
index ccf13952dc..3fc686bbcf 100644
--- a/pyrogram/methods/chats/set_send_as_chat.py
+++ b/pyrogram/methods/chats/set_send_as_chat.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py
index 084e775c14..7e6739bacb 100644
--- a/pyrogram/methods/chats/set_slow_mode.py
+++ b/pyrogram/methods/chats/set_slow_mode.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py
index e49c7afdb3..32867798ce 100644
--- a/pyrogram/methods/chats/unarchive_chats.py
+++ b/pyrogram/methods/chats/unarchive_chats.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py
index 9f81f9c7ce..c7be7b58f6 100644
--- a/pyrogram/methods/chats/unban_chat_member.py
+++ b/pyrogram/methods/chats/unban_chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py
index 2996f511de..3028120ae2 100644
--- a/pyrogram/methods/chats/unpin_all_chat_messages.py
+++ b/pyrogram/methods/chats/unpin_all_chat_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py
index fe4b71a244..83654452cc 100644
--- a/pyrogram/methods/chats/unpin_chat_message.py
+++ b/pyrogram/methods/chats/unpin_chat_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/chats/update_chat_username.py b/pyrogram/methods/chats/update_chat_username.py
index 297d83a24c..a5bf9958d3 100644
--- a/pyrogram/methods/chats/update_chat_username.py
+++ b/pyrogram/methods/chats/update_chat_username.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/__init__.py b/pyrogram/methods/contacts/__init__.py
index b542b665ea..5849ce4389 100644
--- a/pyrogram/methods/contacts/__init__.py
+++ b/pyrogram/methods/contacts/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py
index 79b85b9c54..cceb273d37 100644
--- a/pyrogram/methods/contacts/add_contact.py
+++ b/pyrogram/methods/contacts/add_contact.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py
index 6b73fa7434..273407475a 100644
--- a/pyrogram/methods/contacts/delete_contacts.py
+++ b/pyrogram/methods/contacts/delete_contacts.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py
index 9b546a16f2..98ed11502d 100644
--- a/pyrogram/methods/contacts/get_contacts.py
+++ b/pyrogram/methods/contacts/get_contacts.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py
index f58fb96c63..b29fed7ac1 100644
--- a/pyrogram/methods/contacts/get_contacts_count.py
+++ b/pyrogram/methods/contacts/get_contacts_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py
index 9ba190f332..b7df855439 100644
--- a/pyrogram/methods/contacts/import_contacts.py
+++ b/pyrogram/methods/contacts/import_contacts.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/__init__.py b/pyrogram/methods/decorators/__init__.py
index 384560fe3e..da0ed9ab13 100644
--- a/pyrogram/methods/decorators/__init__.py
+++ b/pyrogram/methods/decorators/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_callback_query.py b/pyrogram/methods/decorators/on_callback_query.py
index 884fbb95f3..fb0b716f60 100644
--- a/pyrogram/methods/decorators/on_callback_query.py
+++ b/pyrogram/methods/decorators/on_callback_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_chat_join_request.py b/pyrogram/methods/decorators/on_chat_join_request.py
index 93d48c1059..0629901814 100644
--- a/pyrogram/methods/decorators/on_chat_join_request.py
+++ b/pyrogram/methods/decorators/on_chat_join_request.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_chat_member_updated.py b/pyrogram/methods/decorators/on_chat_member_updated.py
index 080daa1fc2..9c10debfdd 100644
--- a/pyrogram/methods/decorators/on_chat_member_updated.py
+++ b/pyrogram/methods/decorators/on_chat_member_updated.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_chosen_inline_result.py b/pyrogram/methods/decorators/on_chosen_inline_result.py
index 4e972a06a3..a2775c9bea 100644
--- a/pyrogram/methods/decorators/on_chosen_inline_result.py
+++ b/pyrogram/methods/decorators/on_chosen_inline_result.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_deleted_messages.py b/pyrogram/methods/decorators/on_deleted_messages.py
index d093310c78..3bf88b088a 100644
--- a/pyrogram/methods/decorators/on_deleted_messages.py
+++ b/pyrogram/methods/decorators/on_deleted_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_disconnect.py b/pyrogram/methods/decorators/on_disconnect.py
index b6dd821c32..5e4f75014b 100644
--- a/pyrogram/methods/decorators/on_disconnect.py
+++ b/pyrogram/methods/decorators/on_disconnect.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_inline_query.py b/pyrogram/methods/decorators/on_inline_query.py
index 60463f66d8..4910670e33 100644
--- a/pyrogram/methods/decorators/on_inline_query.py
+++ b/pyrogram/methods/decorators/on_inline_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_message.py b/pyrogram/methods/decorators/on_message.py
index ec23084f7d..634ca2e335 100644
--- a/pyrogram/methods/decorators/on_message.py
+++ b/pyrogram/methods/decorators/on_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_poll.py b/pyrogram/methods/decorators/on_poll.py
index fc49b1925a..2694040372 100644
--- a/pyrogram/methods/decorators/on_poll.py
+++ b/pyrogram/methods/decorators/on_poll.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_raw_update.py b/pyrogram/methods/decorators/on_raw_update.py
index 0ce6bf5df9..f61b156b90 100644
--- a/pyrogram/methods/decorators/on_raw_update.py
+++ b/pyrogram/methods/decorators/on_raw_update.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/decorators/on_user_status.py b/pyrogram/methods/decorators/on_user_status.py
index fda3fb800c..38760c2f4e 100644
--- a/pyrogram/methods/decorators/on_user_status.py
+++ b/pyrogram/methods/decorators/on_user_status.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/__init__.py b/pyrogram/methods/invite_links/__init__.py
index ccdad31297..c2183d9b55 100644
--- a/pyrogram/methods/invite_links/__init__.py
+++ b/pyrogram/methods/invite_links/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py
index 013b64feaf..0bb2f604ca 100644
--- a/pyrogram/methods/invite_links/approve_chat_join_request.py
+++ b/pyrogram/methods/invite_links/approve_chat_join_request.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py
index b90b9b1524..4e6aded0b3 100644
--- a/pyrogram/methods/invite_links/create_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/create_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py
index 5a0f942c1c..3fc01e2690 100644
--- a/pyrogram/methods/invite_links/decline_chat_join_request.py
+++ b/pyrogram/methods/invite_links/decline_chat_join_request.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
index 94a3740890..fda2aadbcb 100644
--- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py
index 987cc78129..eeab4e3537 100644
--- a/pyrogram/methods/invite_links/delete_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py
index ea4be32f55..5c9dc9ff74 100644
--- a/pyrogram/methods/invite_links/edit_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py
index ee59750cbb..061ccdf349 100644
--- a/pyrogram/methods/invite_links/export_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/export_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
index ade3a84be2..8687795d70 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
index 5c99405a53..789f551a2f 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
index 1f2cc1c197..8b048a58b5 100644
--- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link.py b/pyrogram/methods/invite_links/get_chat_invite_link.py
index c5e0339901..a5361bab6f 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members.py b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
index e48422ea30..5d6e920891 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
index bd6a2fcc81..a4f5bbb710 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/invite_links/revoke_chat_invite_link.py b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
index b49a51dd4c..cb3c39cdc4 100644
--- a/pyrogram/methods/invite_links/revoke_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py
index 84cc143db9..6b78eeb8ce 100644
--- a/pyrogram/methods/messages/__init__.py
+++ b/pyrogram/methods/messages/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index 4866d82457..72d8d04bf3 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index 5e8869496d..1295edef44 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py
index ba9da8967e..b9807dc53d 100644
--- a/pyrogram/methods/messages/delete_messages.py
+++ b/pyrogram/methods/messages/delete_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py
index be5da0601b..c1472e9558 100644
--- a/pyrogram/methods/messages/download_media.py
+++ b/pyrogram/methods/messages/download_media.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py
index b291589731..2f009a0586 100644
--- a/pyrogram/methods/messages/edit_inline_caption.py
+++ b/pyrogram/methods/messages/edit_inline_caption.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py
index 13b2736649..6b8c834ad4 100644
--- a/pyrogram/methods/messages/edit_inline_media.py
+++ b/pyrogram/methods/messages/edit_inline_media.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py
index 5966d4b7d2..614da61718 100644
--- a/pyrogram/methods/messages/edit_inline_reply_markup.py
+++ b/pyrogram/methods/messages/edit_inline_reply_markup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py
index e9a79e1407..996dd4f5be 100644
--- a/pyrogram/methods/messages/edit_inline_text.py
+++ b/pyrogram/methods/messages/edit_inline_text.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py
index 53e0911c2d..9abdfbe972 100644
--- a/pyrogram/methods/messages/edit_message_caption.py
+++ b/pyrogram/methods/messages/edit_message_caption.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py
index a0d365dcc9..4e443e71c0 100644
--- a/pyrogram/methods/messages/edit_message_media.py
+++ b/pyrogram/methods/messages/edit_message_media.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py
index aefb87e9e5..2bbe1bc9b0 100644
--- a/pyrogram/methods/messages/edit_message_reply_markup.py
+++ b/pyrogram/methods/messages/edit_message_reply_markup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index 443d71f6af..5d6ba9cfa9 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index fc27805980..caa627d8ad 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py
index cda7ae5212..c7d47261fa 100644
--- a/pyrogram/methods/messages/get_discussion_message.py
+++ b/pyrogram/methods/messages/get_discussion_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
index 98a2f77e6c..d80a6b8b2d 100644
--- a/pyrogram/methods/messages/get_history.py
+++ b/pyrogram/methods/messages/get_history.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_history_count.py
index 6552d527f0..9facdbebac 100644
--- a/pyrogram/methods/messages/get_history_count.py
+++ b/pyrogram/methods/messages/get_history_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/get_media_group.py b/pyrogram/methods/messages/get_media_group.py
index b429224f56..273f5fffcd 100644
--- a/pyrogram/methods/messages/get_media_group.py
+++ b/pyrogram/methods/messages/get_media_group.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py
index cb4d2abbe0..b9c0fbf7ca 100644
--- a/pyrogram/methods/messages/get_messages.py
+++ b/pyrogram/methods/messages/get_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py
index 354cb70f69..c4ac50aa89 100644
--- a/pyrogram/methods/messages/inline_session.py
+++ b/pyrogram/methods/messages/inline_session.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/iter_history.py b/pyrogram/methods/messages/iter_history.py
index 9fecc8743e..2e60dfde90 100644
--- a/pyrogram/methods/messages/iter_history.py
+++ b/pyrogram/methods/messages/iter_history.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_history.py
index e7477397da..881b59ad7c 100644
--- a/pyrogram/methods/messages/read_history.py
+++ b/pyrogram/methods/messages/read_history.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py
index 2f9ec33ced..4baba81157 100644
--- a/pyrogram/methods/messages/retract_vote.py
+++ b/pyrogram/methods/messages/retract_vote.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index b016653d75..c3fb7acbac 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py
index 113ef81362..78b6965402 100644
--- a/pyrogram/methods/messages/search_global_count.py
+++ b/pyrogram/methods/messages/search_global_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index b62d4cfe47..91bd6a5afc 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py
index 02e0c80366..3004eb39ce 100644
--- a/pyrogram/methods/messages/search_messages_count.py
+++ b/pyrogram/methods/messages/search_messages_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 3a95a95065..01856a79ef 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 6ca16fe161..4ce02c31a1 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 4e7b81495b..885824b4de 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py
index f618670d7e..fc79c01553 100644
--- a/pyrogram/methods/messages/send_chat_action.py
+++ b/pyrogram/methods/messages/send_chat_action.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index 5ce3b01399..f396577797 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index 5d89b03cba..dfc9d5b895 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 82be26d1d0..bc407fe2b3 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py
index 1bc3b0326c..d2b6616dae 100644
--- a/pyrogram/methods/messages/send_location.py
+++ b/pyrogram/methods/messages/send_location.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index 9f4c5e54e1..13d4d62a8a 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 5277ec1fac..c0653a38d4 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index ff69558974..c70be84e2f 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index 6fbb0aab95..a412bcdff0 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py
index a65cb5bcee..9e6c353cd1 100644
--- a/pyrogram/methods/messages/send_reaction.py
+++ b/pyrogram/methods/messages/send_reaction.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index 4aa3ce288a..641cc6359a 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py
index 557aa673b4..7941485ebc 100644
--- a/pyrogram/methods/messages/send_venue.py
+++ b/pyrogram/methods/messages/send_venue.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index 8eff5d9777..cccc07ab98 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index 231e149820..1e52f3ab14 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 3782d41be8..80eb386d2c 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py
index 8853c5d6b9..113f1618aa 100644
--- a/pyrogram/methods/messages/stop_poll.py
+++ b/pyrogram/methods/messages/stop_poll.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py
index 0c18bc215a..d6753a275a 100644
--- a/pyrogram/methods/messages/vote_poll.py
+++ b/pyrogram/methods/messages/vote_poll.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/password/__init__.py b/pyrogram/methods/password/__init__.py
index 30f3950c78..e8d42926a4 100644
--- a/pyrogram/methods/password/__init__.py
+++ b/pyrogram/methods/password/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py
index 1f1f4e0364..f950c65a70 100644
--- a/pyrogram/methods/password/change_cloud_password.py
+++ b/pyrogram/methods/password/change_cloud_password.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py
index ad12cdc440..7073af59c2 100644
--- a/pyrogram/methods/password/enable_cloud_password.py
+++ b/pyrogram/methods/password/enable_cloud_password.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py
index 3d792835eb..18ae31e5c1 100644
--- a/pyrogram/methods/password/remove_cloud_password.py
+++ b/pyrogram/methods/password/remove_cloud_password.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py
index d9e61e694c..e8005b83ea 100644
--- a/pyrogram/methods/users/__init__.py
+++ b/pyrogram/methods/users/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py
index 6d7c8cdadb..0efda2b9a8 100644
--- a/pyrogram/methods/users/block_user.py
+++ b/pyrogram/methods/users/block_user.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py
index 7f2c3a729e..64f3ce7763 100644
--- a/pyrogram/methods/users/delete_profile_photos.py
+++ b/pyrogram/methods/users/delete_profile_photos.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py
index 6674d229b9..7969647a0c 100644
--- a/pyrogram/methods/users/get_common_chats.py
+++ b/pyrogram/methods/users/get_common_chats.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py
index 3fab57e34d..b7ebf2d745 100644
--- a/pyrogram/methods/users/get_me.py
+++ b/pyrogram/methods/users/get_me.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py
index fb6f93ca31..fb8c75c497 100644
--- a/pyrogram/methods/users/get_profile_photos.py
+++ b/pyrogram/methods/users/get_profile_photos.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py
index d27c9da598..dcb7ee4b4c 100644
--- a/pyrogram/methods/users/get_profile_photos_count.py
+++ b/pyrogram/methods/users/get_profile_photos_count.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py
index 3758eaea82..43ae008423 100644
--- a/pyrogram/methods/users/get_users.py
+++ b/pyrogram/methods/users/get_users.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/iter_profile_photos.py b/pyrogram/methods/users/iter_profile_photos.py
index 3ebd7f5020..eda77a8889 100644
--- a/pyrogram/methods/users/iter_profile_photos.py
+++ b/pyrogram/methods/users/iter_profile_photos.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py
index 822500edc5..9b1c5c04c5 100644
--- a/pyrogram/methods/users/set_profile_photo.py
+++ b/pyrogram/methods/users/set_profile_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py
index 2492aeba72..4218bb1e55 100644
--- a/pyrogram/methods/users/unblock_user.py
+++ b/pyrogram/methods/users/unblock_user.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py
index a505c70877..4dc81204e4 100644
--- a/pyrogram/methods/users/update_profile.py
+++ b/pyrogram/methods/users/update_profile.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/users/update_username.py b/pyrogram/methods/users/update_username.py
index 865f3ed9eb..ce61402a7f 100644
--- a/pyrogram/methods/users/update_username.py
+++ b/pyrogram/methods/users/update_username.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/__init__.py b/pyrogram/methods/utilities/__init__.py
index 40034e6f0d..80a5f7419d 100644
--- a/pyrogram/methods/utilities/__init__.py
+++ b/pyrogram/methods/utilities/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/add_handler.py b/pyrogram/methods/utilities/add_handler.py
index 466e643139..d0ef15ff64 100644
--- a/pyrogram/methods/utilities/add_handler.py
+++ b/pyrogram/methods/utilities/add_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/export_session_string.py b/pyrogram/methods/utilities/export_session_string.py
index 545520a26e..cd1741bdb4 100644
--- a/pyrogram/methods/utilities/export_session_string.py
+++ b/pyrogram/methods/utilities/export_session_string.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/idle.py b/pyrogram/methods/utilities/idle.py
index 0b3c9a1eff..c708d6f1fb 100644
--- a/pyrogram/methods/utilities/idle.py
+++ b/pyrogram/methods/utilities/idle.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/remove_handler.py b/pyrogram/methods/utilities/remove_handler.py
index 8447f8a9db..12be00b481 100644
--- a/pyrogram/methods/utilities/remove_handler.py
+++ b/pyrogram/methods/utilities/remove_handler.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/restart.py b/pyrogram/methods/utilities/restart.py
index 9c9e510935..e750137fa4 100644
--- a/pyrogram/methods/utilities/restart.py
+++ b/pyrogram/methods/utilities/restart.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/run.py b/pyrogram/methods/utilities/run.py
index 53f66f44ba..40decbbd82 100644
--- a/pyrogram/methods/utilities/run.py
+++ b/pyrogram/methods/utilities/run.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index 62e8acfc5d..a8144d3ff5 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/stop.py b/pyrogram/methods/utilities/stop.py
index 4f338d3a2b..3536caa1e2 100644
--- a/pyrogram/methods/utilities/stop.py
+++ b/pyrogram/methods/utilities/stop.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/methods/utilities/stop_transmission.py b/pyrogram/methods/utilities/stop_transmission.py
index 6f76f11f47..70bd58d450 100644
--- a/pyrogram/methods/utilities/stop_transmission.py
+++ b/pyrogram/methods/utilities/stop_transmission.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/mime_types.py b/pyrogram/mime_types.py
index 819e07738e..2f6c86aa8b 100644
--- a/pyrogram/mime_types.py
+++ b/pyrogram/mime_types.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/parser/__init__.py b/pyrogram/parser/__init__.py
index c1c03d59d7..00c7acae76 100644
--- a/pyrogram/parser/__init__.py
+++ b/pyrogram/parser/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index 805ca02153..c169dd1a06 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py
index 5d14f8e8cb..898ac3d6a9 100644
--- a/pyrogram/parser/markdown.py
+++ b/pyrogram/parser/markdown.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py
index 24663ab6df..2ea9e4f284 100644
--- a/pyrogram/parser/parser.py
+++ b/pyrogram/parser/parser.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/parser/utils.py b/pyrogram/parser/utils.py
index db0fc1756d..0d60402894 100644
--- a/pyrogram/parser/utils.py
+++ b/pyrogram/parser/utils.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/__init__.py b/pyrogram/raw/__init__.py
index deef4038fc..a1435c77c6 100644
--- a/pyrogram/raw/__init__.py
+++ b/pyrogram/raw/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/__init__.py b/pyrogram/raw/core/__init__.py
index 8b284c65d0..95c8123104 100644
--- a/pyrogram/raw/core/__init__.py
+++ b/pyrogram/raw/core/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/future_salt.py b/pyrogram/raw/core/future_salt.py
index 54a1296361..ecef5e2ff3 100644
--- a/pyrogram/raw/core/future_salt.py
+++ b/pyrogram/raw/core/future_salt.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/future_salts.py b/pyrogram/raw/core/future_salts.py
index 9fa2f8e97e..b0ed334356 100644
--- a/pyrogram/raw/core/future_salts.py
+++ b/pyrogram/raw/core/future_salts.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/gzip_packed.py b/pyrogram/raw/core/gzip_packed.py
index 8525338ac8..685594d87a 100644
--- a/pyrogram/raw/core/gzip_packed.py
+++ b/pyrogram/raw/core/gzip_packed.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/list.py b/pyrogram/raw/core/list.py
index 74d39c03bf..780fd92c3e 100644
--- a/pyrogram/raw/core/list.py
+++ b/pyrogram/raw/core/list.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/message.py b/pyrogram/raw/core/message.py
index 6d50ecf318..1357cf8690 100644
--- a/pyrogram/raw/core/message.py
+++ b/pyrogram/raw/core/message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/msg_container.py b/pyrogram/raw/core/msg_container.py
index ddebce0c38..454a150741 100644
--- a/pyrogram/raw/core/msg_container.py
+++ b/pyrogram/raw/core/msg_container.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/__init__.py b/pyrogram/raw/core/primitives/__init__.py
index 575b36966e..88f2fa5363 100644
--- a/pyrogram/raw/core/primitives/__init__.py
+++ b/pyrogram/raw/core/primitives/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/bool.py b/pyrogram/raw/core/primitives/bool.py
index 480a7224ae..02cc12d131 100644
--- a/pyrogram/raw/core/primitives/bool.py
+++ b/pyrogram/raw/core/primitives/bool.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/bytes.py b/pyrogram/raw/core/primitives/bytes.py
index 47f914e08b..eace1feb99 100644
--- a/pyrogram/raw/core/primitives/bytes.py
+++ b/pyrogram/raw/core/primitives/bytes.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/double.py b/pyrogram/raw/core/primitives/double.py
index 232f35c9b7..bb7878bf1e 100644
--- a/pyrogram/raw/core/primitives/double.py
+++ b/pyrogram/raw/core/primitives/double.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/int.py b/pyrogram/raw/core/primitives/int.py
index aed653ad76..5d5ec177d1 100644
--- a/pyrogram/raw/core/primitives/int.py
+++ b/pyrogram/raw/core/primitives/int.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/string.py b/pyrogram/raw/core/primitives/string.py
index c5d19205d6..66f992717b 100644
--- a/pyrogram/raw/core/primitives/string.py
+++ b/pyrogram/raw/core/primitives/string.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/primitives/vector.py b/pyrogram/raw/core/primitives/vector.py
index a150fba76d..c6c6e8e5d4 100644
--- a/pyrogram/raw/core/primitives/vector.py
+++ b/pyrogram/raw/core/primitives/vector.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/raw/core/tl_object.py b/pyrogram/raw/core/tl_object.py
index f0dd596a3f..b094f7d035 100644
--- a/pyrogram/raw/core/tl_object.py
+++ b/pyrogram/raw/core/tl_object.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/scaffold.py b/pyrogram/scaffold.py
index 2bd2308690..d68ddf787b 100644
--- a/pyrogram/scaffold.py
+++ b/pyrogram/scaffold.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/__init__.py b/pyrogram/session/__init__.py
index 96e06e0f58..b414049b2b 100644
--- a/pyrogram/session/__init__.py
+++ b/pyrogram/session/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py
index 6b1ad9530d..d4083b2179 100644
--- a/pyrogram/session/auth.py
+++ b/pyrogram/session/auth.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/internals/__init__.py b/pyrogram/session/internals/__init__.py
index 7f8ef15b82..31dcc80f12 100644
--- a/pyrogram/session/internals/__init__.py
+++ b/pyrogram/session/internals/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py
index 3c9e95675c..4fce19aa24 100644
--- a/pyrogram/session/internals/data_center.py
+++ b/pyrogram/session/internals/data_center.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/internals/msg_factory.py b/pyrogram/session/internals/msg_factory.py
index 2adb22b34a..837f17d0e4 100644
--- a/pyrogram/session/internals/msg_factory.py
+++ b/pyrogram/session/internals/msg_factory.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/internals/msg_id.py b/pyrogram/session/internals/msg_id.py
index 1af7d42f0a..871a10b6c8 100644
--- a/pyrogram/session/internals/msg_id.py
+++ b/pyrogram/session/internals/msg_id.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/internals/seq_no.py b/pyrogram/session/internals/seq_no.py
index 0725809c97..0abc4a2f72 100644
--- a/pyrogram/session/internals/seq_no.py
+++ b/pyrogram/session/internals/seq_no.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 8df167a774..751d6e0008 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/storage/__init__.py b/pyrogram/storage/__init__.py
index a73bd5d4df..2a43309a1b 100644
--- a/pyrogram/storage/__init__.py
+++ b/pyrogram/storage/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py
index 8910a2563b..8ba8910cea 100644
--- a/pyrogram/storage/file_storage.py
+++ b/pyrogram/storage/file_storage.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/storage/memory_storage.py b/pyrogram/storage/memory_storage.py
index 5f097a1c50..1035356dc9 100644
--- a/pyrogram/storage/memory_storage.py
+++ b/pyrogram/storage/memory_storage.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py
index 73bbb53408..106896f601 100644
--- a/pyrogram/storage/sqlite_storage.py
+++ b/pyrogram/storage/sqlite_storage.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py
index 3690cafd73..578dee1755 100644
--- a/pyrogram/storage/storage.py
+++ b/pyrogram/storage/storage.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/sync.py b/pyrogram/sync.py
index d94d490c41..6db937b3a7 100644
--- a/pyrogram/sync.py
+++ b/pyrogram/sync.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/syncer.py b/pyrogram/syncer.py
index dbd8dc6495..3ff1bfc9fd 100644
--- a/pyrogram/syncer.py
+++ b/pyrogram/syncer.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/__init__.py b/pyrogram/types/__init__.py
index bad120f105..e0859bbabd 100644
--- a/pyrogram/types/__init__.py
+++ b/pyrogram/types/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/authorization/__init__.py b/pyrogram/types/authorization/__init__.py
index d5b491da57..b31ad26a53 100644
--- a/pyrogram/types/authorization/__init__.py
+++ b/pyrogram/types/authorization/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/authorization/sent_code.py b/pyrogram/types/authorization/sent_code.py
index 1f4399013f..a471445af2 100644
--- a/pyrogram/types/authorization/sent_code.py
+++ b/pyrogram/types/authorization/sent_code.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/authorization/terms_of_service.py b/pyrogram/types/authorization/terms_of_service.py
index db465e643a..7e1376ea1d 100644
--- a/pyrogram/types/authorization/terms_of_service.py
+++ b/pyrogram/types/authorization/terms_of_service.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py
index fa6aa050f7..ccf84993c7 100644
--- a/pyrogram/types/bots_and_keyboards/__init__.py
+++ b/pyrogram/types/bots_and_keyboards/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/bot_command.py b/pyrogram/types/bots_and_keyboards/bot_command.py
index f2db126a53..66412f09cf 100644
--- a/pyrogram/types/bots_and_keyboards/bot_command.py
+++ b/pyrogram/types/bots_and_keyboards/bot_command.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/callback_game.py b/pyrogram/types/bots_and_keyboards/callback_game.py
index a89cbbd780..3bd89270ff 100644
--- a/pyrogram/types/bots_and_keyboards/callback_game.py
+++ b/pyrogram/types/bots_and_keyboards/callback_game.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py
index 8887594eb7..8cdd424a64 100644
--- a/pyrogram/types/bots_and_keyboards/callback_query.py
+++ b/pyrogram/types/bots_and_keyboards/callback_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/force_reply.py b/pyrogram/types/bots_and_keyboards/force_reply.py
index c52bb76651..025176f2e3 100644
--- a/pyrogram/types/bots_and_keyboards/force_reply.py
+++ b/pyrogram/types/bots_and_keyboards/force_reply.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/game_high_score.py b/pyrogram/types/bots_and_keyboards/game_high_score.py
index b9a77d332c..7de78ce9e6 100644
--- a/pyrogram/types/bots_and_keyboards/game_high_score.py
+++ b/pyrogram/types/bots_and_keyboards/game_high_score.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
index 019999fbc2..9779ec3960 100644
--- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
+++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py
index 1571f1ba32..e0fd323059 100644
--- a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py
+++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/keyboard_button.py b/pyrogram/types/bots_and_keyboards/keyboard_button.py
index 204c696a72..626df749c0 100644
--- a/pyrogram/types/bots_and_keyboards/keyboard_button.py
+++ b/pyrogram/types/bots_and_keyboards/keyboard_button.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/login_url.py b/pyrogram/types/bots_and_keyboards/login_url.py
index 52ef8dc8ee..a0af5a1af0 100644
--- a/pyrogram/types/bots_and_keyboards/login_url.py
+++ b/pyrogram/types/bots_and_keyboards/login_url.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
index 21fa6ceb0d..b619216a13 100644
--- a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
+++ b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/bots_and_keyboards/reply_keyboard_remove.py b/pyrogram/types/bots_and_keyboards/reply_keyboard_remove.py
index 9bf16528f9..479efe9027 100644
--- a/pyrogram/types/bots_and_keyboards/reply_keyboard_remove.py
+++ b/pyrogram/types/bots_and_keyboards/reply_keyboard_remove.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py
index d22937b929..c1f5b87f87 100644
--- a/pyrogram/types/inline_mode/__init__.py
+++ b/pyrogram/types/inline_mode/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/chosen_inline_result.py b/pyrogram/types/inline_mode/chosen_inline_result.py
index 578ef64a1b..623d737933 100644
--- a/pyrogram/types/inline_mode/chosen_inline_result.py
+++ b/pyrogram/types/inline_mode/chosen_inline_result.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query.py b/pyrogram/types/inline_mode/inline_query.py
index 5c718c33c9..2522b6934f 100644
--- a/pyrogram/types/inline_mode/inline_query.py
+++ b/pyrogram/types/inline_mode/inline_query.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query_result.py b/pyrogram/types/inline_mode/inline_query_result.py
index 919b7df565..48d633c141 100644
--- a/pyrogram/types/inline_mode/inline_query_result.py
+++ b/pyrogram/types/inline_mode/inline_query_result.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py
index 45af1ed38a..2281ae1cfd 100644
--- a/pyrogram/types/inline_mode/inline_query_result_animation.py
+++ b/pyrogram/types/inline_mode/inline_query_result_animation.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query_result_article.py b/pyrogram/types/inline_mode/inline_query_result_article.py
index 0b5e6008b5..73260dd9cc 100644
--- a/pyrogram/types/inline_mode/inline_query_result_article.py
+++ b/pyrogram/types/inline_mode/inline_query_result_article.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py
index f86c671898..679ee42947 100644
--- a/pyrogram/types/inline_mode/inline_query_result_photo.py
+++ b/pyrogram/types/inline_mode/inline_query_result_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/inline_mode/inline_query_result_video.py b/pyrogram/types/inline_mode/inline_query_result_video.py
index cf035408df..cd5d845437 100644
--- a/pyrogram/types/inline_mode/inline_query_result_video.py
+++ b/pyrogram/types/inline_mode/inline_query_result_video.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/__init__.py b/pyrogram/types/input_media/__init__.py
index 655a968c73..a03d1e21f4 100644
--- a/pyrogram/types/input_media/__init__.py
+++ b/pyrogram/types/input_media/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media.py b/pyrogram/types/input_media/input_media.py
index 16a72bdadd..8e2f3a7b1a 100644
--- a/pyrogram/types/input_media/input_media.py
+++ b/pyrogram/types/input_media/input_media.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py
index 9c5767fe78..76c146c510 100644
--- a/pyrogram/types/input_media/input_media_animation.py
+++ b/pyrogram/types/input_media/input_media_animation.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py
index 3a66b5ee58..4816659d5a 100644
--- a/pyrogram/types/input_media/input_media_audio.py
+++ b/pyrogram/types/input_media/input_media_audio.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py
index 3146006048..3b3a38fdf6 100644
--- a/pyrogram/types/input_media/input_media_document.py
+++ b/pyrogram/types/input_media/input_media_document.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media_photo.py b/pyrogram/types/input_media/input_media_photo.py
index e84a7616c0..f733a7b0bc 100644
--- a/pyrogram/types/input_media/input_media_photo.py
+++ b/pyrogram/types/input_media/input_media_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py
index 1199d86265..48c79f411d 100644
--- a/pyrogram/types/input_media/input_media_video.py
+++ b/pyrogram/types/input_media/input_media_video.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_media/input_phone_contact.py b/pyrogram/types/input_media/input_phone_contact.py
index e0169a5d81..0608cf2179 100644
--- a/pyrogram/types/input_media/input_phone_contact.py
+++ b/pyrogram/types/input_media/input_phone_contact.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_message_content/__init__.py b/pyrogram/types/input_message_content/__init__.py
index 233f53b07a..b445f3ba6a 100644
--- a/pyrogram/types/input_message_content/__init__.py
+++ b/pyrogram/types/input_message_content/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_message_content/input_message_content.py b/pyrogram/types/input_message_content/input_message_content.py
index 99bed67de9..2b46393259 100644
--- a/pyrogram/types/input_message_content/input_message_content.py
+++ b/pyrogram/types/input_message_content/input_message_content.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/input_message_content/input_text_message_content.py b/pyrogram/types/input_message_content/input_text_message_content.py
index a053d818bf..ef54c0b23a 100644
--- a/pyrogram/types/input_message_content/input_text_message_content.py
+++ b/pyrogram/types/input_message_content/input_text_message_content.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/list.py b/pyrogram/types/list.py
index fe91c4c6d0..da87d5275f 100644
--- a/pyrogram/types/list.py
+++ b/pyrogram/types/list.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py
index 9f31dde066..944d7e6e99 100644
--- a/pyrogram/types/messages_and_media/__init__.py
+++ b/pyrogram/types/messages_and_media/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/animation.py b/pyrogram/types/messages_and_media/animation.py
index 96a57469e1..ce901734e6 100644
--- a/pyrogram/types/messages_and_media/animation.py
+++ b/pyrogram/types/messages_and_media/animation.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/audio.py b/pyrogram/types/messages_and_media/audio.py
index e590d2e367..60b37a59e7 100644
--- a/pyrogram/types/messages_and_media/audio.py
+++ b/pyrogram/types/messages_and_media/audio.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/contact.py b/pyrogram/types/messages_and_media/contact.py
index fe6f55fd60..cec03329a5 100644
--- a/pyrogram/types/messages_and_media/contact.py
+++ b/pyrogram/types/messages_and_media/contact.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/dice.py b/pyrogram/types/messages_and_media/dice.py
index aa67470cc4..2c683ec828 100644
--- a/pyrogram/types/messages_and_media/dice.py
+++ b/pyrogram/types/messages_and_media/dice.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/document.py b/pyrogram/types/messages_and_media/document.py
index 76ebed9b0f..333d38abb7 100644
--- a/pyrogram/types/messages_and_media/document.py
+++ b/pyrogram/types/messages_and_media/document.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/game.py b/pyrogram/types/messages_and_media/game.py
index 5e76f5b6a3..1452d79eb3 100644
--- a/pyrogram/types/messages_and_media/game.py
+++ b/pyrogram/types/messages_and_media/game.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/location.py b/pyrogram/types/messages_and_media/location.py
index 6cd0e9f189..664890cb76 100644
--- a/pyrogram/types/messages_and_media/location.py
+++ b/pyrogram/types/messages_and_media/location.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 1d70d773e6..02bf2d3d98 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py
index 864bf54778..2595fc66bc 100644
--- a/pyrogram/types/messages_and_media/message_entity.py
+++ b/pyrogram/types/messages_and_media/message_entity.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/photo.py b/pyrogram/types/messages_and_media/photo.py
index a512d17b82..fc496cd455 100644
--- a/pyrogram/types/messages_and_media/photo.py
+++ b/pyrogram/types/messages_and_media/photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py
index 832b81e258..8d46557d65 100644
--- a/pyrogram/types/messages_and_media/poll.py
+++ b/pyrogram/types/messages_and_media/poll.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/poll_option.py b/pyrogram/types/messages_and_media/poll_option.py
index 25eff66387..a40926b077 100644
--- a/pyrogram/types/messages_and_media/poll_option.py
+++ b/pyrogram/types/messages_and_media/poll_option.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/reaction.py b/pyrogram/types/messages_and_media/reaction.py
index 9d4baa54fa..83dda5829b 100644
--- a/pyrogram/types/messages_and_media/reaction.py
+++ b/pyrogram/types/messages_and_media/reaction.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py
index b7e4ecb5f4..be494e3078 100644
--- a/pyrogram/types/messages_and_media/sticker.py
+++ b/pyrogram/types/messages_and_media/sticker.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/stripped_thumbnail.py b/pyrogram/types/messages_and_media/stripped_thumbnail.py
index 9c832ffb80..e9756607b9 100644
--- a/pyrogram/types/messages_and_media/stripped_thumbnail.py
+++ b/pyrogram/types/messages_and_media/stripped_thumbnail.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/thumbnail.py b/pyrogram/types/messages_and_media/thumbnail.py
index 1a55c18ce4..b9cb93e127 100644
--- a/pyrogram/types/messages_and_media/thumbnail.py
+++ b/pyrogram/types/messages_and_media/thumbnail.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/venue.py b/pyrogram/types/messages_and_media/venue.py
index bdf385e504..8a26f60061 100644
--- a/pyrogram/types/messages_and_media/venue.py
+++ b/pyrogram/types/messages_and_media/venue.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/video.py b/pyrogram/types/messages_and_media/video.py
index b64dcfb6b9..1cdf055fc0 100644
--- a/pyrogram/types/messages_and_media/video.py
+++ b/pyrogram/types/messages_and_media/video.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/video_note.py b/pyrogram/types/messages_and_media/video_note.py
index 9a5685fc8a..3a9e8a616f 100644
--- a/pyrogram/types/messages_and_media/video_note.py
+++ b/pyrogram/types/messages_and_media/video_note.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/voice.py b/pyrogram/types/messages_and_media/voice.py
index 640ad8ccf6..4175b7ba1e 100644
--- a/pyrogram/types/messages_and_media/voice.py
+++ b/pyrogram/types/messages_and_media/voice.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/messages_and_media/webpage.py b/pyrogram/types/messages_and_media/webpage.py
index 08432eabfc..34e51d88cc 100644
--- a/pyrogram/types/messages_and_media/webpage.py
+++ b/pyrogram/types/messages_and_media/webpage.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py
index daeb89af74..015eeca89a 100644
--- a/pyrogram/types/object.py
+++ b/pyrogram/types/object.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/update.py b/pyrogram/types/update.py
index 1937c94b93..d3e45b4abd 100644
--- a/pyrogram/types/update.py
+++ b/pyrogram/types/update.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py
index 22455486b8..4667628a0e 100644
--- a/pyrogram/types/user_and_chats/__init__.py
+++ b/pyrogram/types/user_and_chats/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 6ccd946524..a9d396eb21 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_admin_with_invite_links.py b/pyrogram/types/user_and_chats/chat_admin_with_invite_links.py
index c7e617e941..385a38da43 100644
--- a/pyrogram/types/user_and_chats/chat_admin_with_invite_links.py
+++ b/pyrogram/types/user_and_chats/chat_admin_with_invite_links.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py
index 3d0bbe19d1..374dac50f9 100644
--- a/pyrogram/types/user_and_chats/chat_event.py
+++ b/pyrogram/types/user_and_chats/chat_event.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_event_filter.py b/pyrogram/types/user_and_chats/chat_event_filter.py
index edd003eba8..d88300bae5 100644
--- a/pyrogram/types/user_and_chats/chat_event_filter.py
+++ b/pyrogram/types/user_and_chats/chat_event_filter.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_invite_link.py b/pyrogram/types/user_and_chats/chat_invite_link.py
index 1f8a9256fc..9dddea4835 100644
--- a/pyrogram/types/user_and_chats/chat_invite_link.py
+++ b/pyrogram/types/user_and_chats/chat_invite_link.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_join_request.py b/pyrogram/types/user_and_chats/chat_join_request.py
index 4ed7c1ed38..a7001da5d9 100644
--- a/pyrogram/types/user_and_chats/chat_join_request.py
+++ b/pyrogram/types/user_and_chats/chat_join_request.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index a6f2f4ccb9..ff55081587 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_member_updated.py b/pyrogram/types/user_and_chats/chat_member_updated.py
index a8d7abcafb..5fa7d84e6c 100644
--- a/pyrogram/types/user_and_chats/chat_member_updated.py
+++ b/pyrogram/types/user_and_chats/chat_member_updated.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_permissions.py b/pyrogram/types/user_and_chats/chat_permissions.py
index a5bc3011b1..e209625af3 100644
--- a/pyrogram/types/user_and_chats/chat_permissions.py
+++ b/pyrogram/types/user_and_chats/chat_permissions.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_photo.py b/pyrogram/types/user_and_chats/chat_photo.py
index 959d1732e0..b3aba61dd0 100644
--- a/pyrogram/types/user_and_chats/chat_photo.py
+++ b/pyrogram/types/user_and_chats/chat_photo.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/chat_preview.py b/pyrogram/types/user_and_chats/chat_preview.py
index f4a8540fda..e251c86581 100644
--- a/pyrogram/types/user_and_chats/chat_preview.py
+++ b/pyrogram/types/user_and_chats/chat_preview.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/dialog.py b/pyrogram/types/user_and_chats/dialog.py
index 6c4a408a14..7259a89a57 100644
--- a/pyrogram/types/user_and_chats/dialog.py
+++ b/pyrogram/types/user_and_chats/dialog.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/invite_link_importer.py b/pyrogram/types/user_and_chats/invite_link_importer.py
index 4517ae3c8d..f933cfa2b0 100644
--- a/pyrogram/types/user_and_chats/invite_link_importer.py
+++ b/pyrogram/types/user_and_chats/invite_link_importer.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/restriction.py b/pyrogram/types/user_and_chats/restriction.py
index e3acd250be..8f7a1b7269 100644
--- a/pyrogram/types/user_and_chats/restriction.py
+++ b/pyrogram/types/user_and_chats/restriction.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index cc0c2036ce..8579ba157d 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/voice_chat_ended.py b/pyrogram/types/user_and_chats/voice_chat_ended.py
index febb813729..b6b05feaf3 100644
--- a/pyrogram/types/user_and_chats/voice_chat_ended.py
+++ b/pyrogram/types/user_and_chats/voice_chat_ended.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/voice_chat_members_invited.py b/pyrogram/types/user_and_chats/voice_chat_members_invited.py
index 0a093cbf92..0fd4249ba5 100644
--- a/pyrogram/types/user_and_chats/voice_chat_members_invited.py
+++ b/pyrogram/types/user_and_chats/voice_chat_members_invited.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/voice_chat_scheduled.py b/pyrogram/types/user_and_chats/voice_chat_scheduled.py
index fc7a5f1e5f..82d2125e7f 100644
--- a/pyrogram/types/user_and_chats/voice_chat_scheduled.py
+++ b/pyrogram/types/user_and_chats/voice_chat_scheduled.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/types/user_and_chats/voice_chat_started.py b/pyrogram/types/user_and_chats/voice_chat_started.py
index 6ac546dce9..e260e784fb 100644
--- a/pyrogram/types/user_and_chats/voice_chat_started.py
+++ b/pyrogram/types/user_and_chats/voice_chat_started.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index 9d53d8bfba..6a0c8bac91 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/setup.py b/setup.py
index 5cbd5eb208..1a24654ce8 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/tests/__init__.py b/tests/__init__.py
index 4ad4f32b47..46887cb7a5 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/tests/filters/__init__.py b/tests/filters/__init__.py
index 56187dd8b2..e93649f521 100644
--- a/tests/filters/__init__.py
+++ b/tests/filters/__init__.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/tests/filters/test_command.py b/tests/filters/test_command.py
index 19e21d9dd5..234ed69fc3 100644
--- a/tests/filters/test_command.py
+++ b/tests/filters/test_command.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #
diff --git a/tests/test_file_id.py b/tests/test_file_id.py
index 493590ab11..96152e48ca 100644
--- a/tests/test_file_id.py
+++ b/tests/test_file_id.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2021 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #

From 44228f247271e0f3f678fe800716a26cc72b8e4b Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 7 Jan 2022 10:26:55 +0100
Subject: [PATCH 041/539] Update Pyrogram to v1.3.0

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 96ddb664a4..a0d4345815 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.2.9"
+__version__ = "1.3.0"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From cb6cef37e644edd3effa6fca58b79772daeee8b4 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 7 Jan 2022 12:21:24 +0100
Subject: [PATCH 042/539] Update copyright year

---
 pyrogram/crypto/mtproto.py                    | 26 +++++++++----------
 .../inline_mode/inline_query_result_audio.py  |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py
index 2fc3b9f848..c893e3e538 100644
--- a/pyrogram/crypto/mtproto.py
+++ b/pyrogram/crypto/mtproto.py
@@ -1,20 +1,20 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès 
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
 #
-# This file is part of Pyrogram.
+#  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 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.
+#  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 .
+#  You should have received a copy of the GNU Lesser General Public License
+#  along with Pyrogram.  If not, see .
 
 import bisect
 from hashlib import sha256
diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py
index 6ca8c34c19..e36ecb1124 100644
--- a/pyrogram/types/inline_mode/inline_query_result_audio.py
+++ b/pyrogram/types/inline_mode/inline_query_result_audio.py
@@ -1,5 +1,5 @@
 #  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-2020 Dan 
+#  Copyright (C) 2017-present Dan 
 #
 #  This file is part of Pyrogram.
 #

From 2ca38d0ee9cbd7abbdc8ac9e95b624adf3df8eb1 Mon Sep 17 00:00:00 2001
From: Lorenzo Delmonte 
Date: Fri, 7 Jan 2022 12:31:15 +0100
Subject: [PATCH 043/539] Fix typo in OpenCollective link (#856)

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e51ee0eb0b..455908676c 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ If you'd like to support Pyrogram, you can consider:
 
 - [Become a GitHub sponsor](https://github.com/sponsors/delivrance).
 - [Become a LiberaPay patron](https://liberapay.com/delivrance).
-- [Become an OpenCollective backer](https://opencollective.com/pyrogram>).
+- [Become an OpenCollective backer](https://opencollective.com/pyrogram).
 
 ### Key Features
 

From 1d7c57e6699bc178b8f60eef7009a95fae634741 Mon Sep 17 00:00:00 2001
From: SUBIN <64341611+subinps@users.noreply.github.com>
Date: Fri, 7 Jan 2022 21:35:34 +0530
Subject: [PATCH 044/539] Add missing parameter protect_content (#859)

---
 pyrogram/methods/messages/send_cached_media.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 885824b4de..84fe9b17ee 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -35,6 +35,7 @@ async def send_cached_media(
         disable_notification: bool = None,
         reply_to_message_id: int = None,
         schedule_date: int = None,
+        protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
             "types.ReplyKeyboardMarkup",
@@ -80,6 +81,9 @@ async def send_cached_media(
 
             schedule_date (``int``, *optional*):
                 Date when the message will be automatically sent. Unix time.
+            
+            protect_content (``bool``, *optional*):
+                Protects the contents of the sent message from forwarding and saving.
 
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
@@ -102,6 +106,7 @@ async def send_cached_media(
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
                 schedule_date=schedule_date,
+                noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None,
                 **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
             )

From 7fb35fbad51a4b01dc4c3251772e13054713c506 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 7 Jan 2022 17:06:45 +0100
Subject: [PATCH 045/539] Update Pyrogram to v1.3.1

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index a0d4345815..5728696fc8 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.0"
+__version__ = "1.3.1"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From fbdc6613f26a378dc7c033a90fc63ca3235556e9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 10 Jan 2022 14:31:17 +0100
Subject: [PATCH 046/539] Fix can_send_other_messages permission being inverted
 Fixes #868

---
 .../methods/chats/set_chat_permissions.py     | 22 +++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py
index 2c59190657..2ff2b67831 100644
--- a/pyrogram/methods/chats/set_chat_permissions.py
+++ b/pyrogram/methods/chats/set_chat_permissions.py
@@ -67,17 +67,17 @@ async def set_chat_permissions(
                 peer=await self.resolve_peer(chat_id),
                 banned_rights=raw.types.ChatBannedRights(
                     until_date=0,
-                    send_messages=True if not permissions.can_send_messages else None,
-                    send_media=True if not permissions.can_send_media_messages else None,
-                    send_stickers=permissions.can_send_other_messages,
-                    send_gifs=permissions.can_send_other_messages,
-                    send_games=permissions.can_send_other_messages,
-                    send_inline=permissions.can_send_other_messages,
-                    embed_links=True if not permissions.can_add_web_page_previews else None,
-                    send_polls=True if not permissions.can_send_polls else None,
-                    change_info=True if not permissions.can_change_info else None,
-                    invite_users=True if not permissions.can_invite_users else None,
-                    pin_messages=True if not permissions.can_pin_messages else None,
+                    send_messages=not permissions.can_send_messages,
+                    send_media=not permissions.can_send_media_messages,
+                    send_stickers=not permissions.can_send_other_messages,
+                    send_gifs=not permissions.can_send_other_messages,
+                    send_games=not permissions.can_send_other_messages,
+                    send_inline=not permissions.can_send_other_messages,
+                    embed_links=not permissions.can_add_web_page_previews,
+                    send_polls=not permissions.can_send_polls,
+                    change_info=not permissions.can_change_info,
+                    invite_users=not permissions.can_invite_users,
+                    pin_messages=not permissions.can_pin_messages,
                 )
             )
         )

From c7da4a8495676d8872611623345cbfadc8a26262 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 10 Jan 2022 14:32:10 +0100
Subject: [PATCH 047/539] Update Pyrogram to v1.3.2

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 5728696fc8..fad89499b9 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.1"
+__version__ = "1.3.2"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From de9705f1268cba58845d07415b3d8081d449decd Mon Sep 17 00:00:00 2001
From: Sam <25792361+sam01101@users.noreply.github.com>
Date: Tue, 11 Jan 2022 23:40:37 +0800
Subject: [PATCH 048/539] Fix core types and compiler (#871)

- Add missing ID to FutureSalts
- Have vector flags read to None instead of [] for non-existent lists
---
 compiler/api/compiler.py          | 2 +-
 pyrogram/raw/core/future_salts.py | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 192d6a6759..c173a93193 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -447,7 +447,7 @@ def start(format: bool = False):
                     )
 
                     read_types += "\n        "
-                    read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else []\n        ".format(
+                    read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else None\n        ".format(
                         arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", index
                     )
                 else:
diff --git a/pyrogram/raw/core/future_salts.py b/pyrogram/raw/core/future_salts.py
index b0ed334356..31eb16e277 100644
--- a/pyrogram/raw/core/future_salts.py
+++ b/pyrogram/raw/core/future_salts.py
@@ -48,6 +48,7 @@ def read(data: BytesIO, *args: Any) -> "FutureSalts":
 
     def write(self, *args: Any) -> bytes:
         b = BytesIO()
+        b.write(Int(self.ID, False))
 
         b.write(Long(self.req_msg_id))
         b.write(Int(self.now))

From 10c512d39cad34f453a179b336d04b98b12bc463 Mon Sep 17 00:00:00 2001
From: Danipulok <45077699+Danipulok@users.noreply.github.com>
Date: Tue, 11 Jan 2022 17:42:04 +0200
Subject: [PATCH 049/539] Remove unnecessary method call in get_media_group
 (#860)

---
 pyrogram/methods/messages/get_media_group.py | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/pyrogram/methods/messages/get_media_group.py b/pyrogram/methods/messages/get_media_group.py
index 273f5fffcd..3b33bfd4a9 100644
--- a/pyrogram/methods/messages/get_media_group.py
+++ b/pyrogram/methods/messages/get_media_group.py
@@ -51,13 +51,10 @@ async def get_media_group(
                 In case target message doesn't belong to a media group.
         """
 
-        # There can be maximum 10 items in a media group. 
-        messages = await self.get_messages(chat_id, [msg_id for msg_id in range(message_id - 9, message_id + 10)],
-                                           replies=0)
-
         if message_id <= 0:
             raise ValueError("Passed message_id is negative or equal to zero.")
 
+        # Get messages with id from `id - 9` to `id + 10` to get all possible media group messages.
         messages = await self.get_messages(
             chat_id=chat_id,
             message_ids=[msg_id for msg_id in range(message_id - 9, message_id + 10)],
@@ -65,7 +62,7 @@ async def get_media_group(
         )
 
         # There can be maximum 10 items in a media group.
-        # The if/else condition to fix the problem of getting correct `media_group_id` when it has `message_id` less then 10.
+        # If/else condition to fix the problem of getting correct `media_group_id` when `message_id` is less than 10.
         media_group_id = messages[9].media_group_id if len(messages) == 19 else messages[message_id - 1].media_group_id
 
         if media_group_id is None:

From 5ec9743a1a8480449f5a38c7ff38d26f652f0201 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 16:43:24 +0100
Subject: [PATCH 050/539] Minor style fix

---
 pyrogram/raw/core/future_salts.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyrogram/raw/core/future_salts.py b/pyrogram/raw/core/future_salts.py
index 31eb16e277..88216387f2 100644
--- a/pyrogram/raw/core/future_salts.py
+++ b/pyrogram/raw/core/future_salts.py
@@ -48,6 +48,7 @@ def read(data: BytesIO, *args: Any) -> "FutureSalts":
 
     def write(self, *args: Any) -> bytes:
         b = BytesIO()
+
         b.write(Int(self.ID, False))
 
         b.write(Long(self.req_msg_id))

From 14ae9d314b647e262d37fd057ebc6cfa932afce1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 16:44:09 +0100
Subject: [PATCH 051/539] Update Pyrogram to v1.3.3

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index fad89499b9..02eef373ef 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.2"
+__version__ = "1.3.3"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 527ec23c20164736203eb5a7e3109368c9629aed Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 16:58:07 +0100
Subject: [PATCH 052/539] Revert reading non-existent flag vectors from None to
 []

---
 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 c173a93193..192d6a6759 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -447,7 +447,7 @@ def start(format: bool = False):
                     )
 
                     read_types += "\n        "
-                    read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else None\n        ".format(
+                    read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else []\n        ".format(
                         arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", index
                     )
                 else:

From db9489b318114ff45c977392655d55cb8a28aab9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 16:58:36 +0100
Subject: [PATCH 053/539] Update Pyrogram to v1.3.4

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 02eef373ef..6d1a462cb7 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.3"
+__version__ = "1.3.4"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From a6299f8401fa5fcdc504380899518c5a4870a12c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 17:24:17 +0100
Subject: [PATCH 054/539] Use a proper condition check when dealing with flag
 vectors When reading flag vectors, non-existent vectors are being translated
 to [] (empty list). When writing them, the flag condition was strictly
 checking for None and an empty list [] would result in an empty vector being
 serialized, which should not happen. Related to #871.

---
 compiler/api/compiler.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 192d6a6759..150fa49d37 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -408,7 +408,7 @@ def start(format: bool = False):
                     flag = FLAGS_RE_2.match(i[1])
 
                     if flag:
-                        if flag.group(2) == "true":
+                        if flag.group(2) == "true" or flag.group(2).startswith("Vector"):
                             write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} else 0")
                         else:
                             write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0")
@@ -441,7 +441,7 @@ def start(format: bool = False):
                     sub_type = arg_type.split("<")[1][:-1]
 
                     write_types += "\n        "
-                    write_types += f"if self.{arg_name} is not None:\n            "
+                    write_types += f"if self.{arg_name}:\n            "
                     write_types += "b.write(Vector(self.{}{}))\n        ".format(
                         arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
                     )

From e67fd6efbb93e5ba6307fe4c20ea8051c5583d85 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 11 Jan 2022 17:25:01 +0100
Subject: [PATCH 055/539] Update Pyrogram to v.1.3.5

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 6d1a462cb7..2c85c00fbf 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.4"
+__version__ = "1.3.5"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 1162e89f26cc5f623ba6edb851129afd8ce2cab7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 20 Jan 2022 09:43:29 +0100
Subject: [PATCH 056/539] Better handling of expiring server salts

---
 pyrogram/session/session.py | 62 +++++--------------------------------
 1 file changed, 7 insertions(+), 55 deletions(-)

diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 751d6e0008..6455e958a1 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -19,8 +19,6 @@
 import asyncio
 import logging
 import os
-import time
-from datetime import datetime, timedelta
 from hashlib import sha1
 from io import BytesIO
 
@@ -33,7 +31,7 @@
     SecurityCheckMismatch
 )
 from pyrogram.raw.all import layer
-from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalt, FutureSalts
+from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts
 from .internals import MsgId, MsgFactory
 
 log = logging.getLogger(__name__)
@@ -76,7 +74,7 @@ def __init__(
         self.session_id = os.urandom(8)
         self.msg_factory = MsgFactory()
 
-        self.current_salt = None
+        self.salt = 0
 
         self.pending_acks = set()
 
@@ -87,9 +85,6 @@ def __init__(
         self.ping_task = None
         self.ping_task_event = asyncio.Event()
 
-        self.next_salt_task = None
-        self.next_salt_task_event = asyncio.Event()
-
         self.network_task = None
 
         self.is_connected = asyncio.Event()
@@ -111,19 +106,7 @@ async def start(self):
 
                 self.network_task = self.loop.create_task(self.network_worker())
 
-                self.current_salt = FutureSalt(0, 0, 0)
-                self.current_salt = FutureSalt(
-                    0, 0,
-                    (await self._send(
-                        raw.functions.Ping(ping_id=0),
-                        timeout=self.START_TIMEOUT
-                    )).new_server_salt
-                )
-                self.current_salt = (await self._send(
-                    raw.functions.GetFutureSalts(num=1),
-                    timeout=self.START_TIMEOUT)).salts[0]
-
-                self.next_salt_task = self.loop.create_task(self.next_salt_worker())
+                await self._send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT)
 
                 if not self.is_cdn:
                     await self._send(
@@ -168,16 +151,11 @@ async def stop(self):
         self.is_connected.clear()
 
         self.ping_task_event.set()
-        self.next_salt_task_event.set()
 
         if self.ping_task is not None:
             await self.ping_task
 
-        if self.next_salt_task is not None:
-            await self.next_salt_task
-
         self.ping_task_event.clear()
-        self.next_salt_task_event.clear()
 
         self.connection.close()
 
@@ -288,35 +266,6 @@ async def ping_worker(self):
 
         log.info("PingTask stopped")
 
-    async def next_salt_worker(self):
-        log.info("NextSaltTask started")
-
-        while True:
-            now = datetime.fromtimestamp(time.perf_counter() - MsgId.reference_clock + MsgId.server_time)
-
-            # Seconds to wait until middle-overlap, which is
-            # 15 minutes before/after the current/next salt end/start time
-            valid_until = datetime.fromtimestamp(self.current_salt.valid_until)
-            dt = (valid_until - now).total_seconds() - 900
-
-            minutes, seconds = divmod(int(dt), 60)
-            log.info(f"Next salt in {minutes:.0f}m {seconds:.0f}s (at {now + timedelta(seconds=dt)})")
-
-            try:
-                await asyncio.wait_for(self.next_salt_task_event.wait(), dt)
-            except asyncio.TimeoutError:
-                pass
-            else:
-                break
-
-            try:
-                self.current_salt = (await self._send(raw.functions.GetFutureSalts(num=1))).salts[0]
-            except (OSError, TimeoutError, RPCError):
-                self.connection.close()
-                break
-
-        log.info("NextSaltTask stopped")
-
     async def network_worker(self):
         log.info("NetworkTask started")
 
@@ -352,7 +301,7 @@ async def _send(self, data: TLObject, wait_response: bool = True, timeout: float
             pyrogram.crypto_executor,
             mtproto.pack,
             message,
-            self.current_salt.salt,
+            self.salt,
             self.session_id,
             self.auth_key,
             self.auth_key_id
@@ -381,6 +330,9 @@ async def _send(self, data: TLObject, wait_response: bool = True, timeout: float
                 RPCError.raise_it(result, type(data))
             elif isinstance(result, raw.types.BadMsgNotification):
                 raise BadMsgNotification(result.error_code)
+            elif isinstance(result, raw.types.BadServerSalt):
+                self.salt = result.new_server_salt
+                return await self._send(data, wait_response, timeout)
             else:
                 return result
 

From 23b02087c27f8fb5f43fded650df9f3d14381c1c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 20 Jan 2022 09:44:21 +0100
Subject: [PATCH 057/539] Update Pyrogram to v1.3.6

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 2c85c00fbf..b3b2ccdf8a 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.5"
+__version__ = "1.3.6"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 7d444381c743a2c7ce587b3b7fc4f32afa3e02aa Mon Sep 17 00:00:00 2001
From: Alisson Lauffer 
Date: Fri, 21 Jan 2022 06:26:52 -0300
Subject: [PATCH 058/539] Fix spoiler html unparsing (#862)

- The current spoiler implementaion unparses both strikethrough and spoiler tags with , making them indistinguishable
---
 pyrogram/parser/html.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index c169dd1a06..b70a189f57 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -155,10 +155,10 @@ def unparse(text: str, entities: list):
             start = entity.offset
             end = start + entity.length
 
-            if entity_type in ("bold", "italic", "underline", "strikethrough", "spoiler"):
+            if entity_type in ("bold", "italic", "underline", "strikethrough"):
                 start_tag = f"<{entity_type[0]}>"
                 end_tag = f""
-            elif entity_type in ("code", "pre", "blockquote"):
+            elif entity_type in ("code", "pre", "blockquote", "spoiler"):
                 start_tag = f"<{entity_type}>"
                 end_tag = f""
             elif entity_type == "text_link":

From 4af9e30cfd6f2ef8157f041744050c568e4fa20f Mon Sep 17 00:00:00 2001
From: Shrimadhav U K 
Date: Sat, 29 Jan 2022 15:43:09 +0530
Subject: [PATCH 059/539] Fix caption being "None" when passing None (#879)

---
 pyrogram/parser/parser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py
index 2ea9e4f284..d294e04d51 100644
--- a/pyrogram/parser/parser.py
+++ b/pyrogram/parser/parser.py
@@ -31,7 +31,7 @@ def __init__(self, client: Optional["pyrogram.Client"]):
         self.markdown = Markdown(client)
 
     async def parse(self, text: str, mode: Optional[str] = object):
-        text = str(text).strip()
+        text = str(text if text else "").strip()
 
         if mode == object:
             if self.client:

From 244606eed619682ce4c089c40181e9c31c28f7e8 Mon Sep 17 00:00:00 2001
From: W4RR10R <46273006+arunpt@users.noreply.github.com>
Date: Sat, 29 Jan 2022 16:06:15 +0530
Subject: [PATCH 060/539] Add approve() and decline() bound methods to
 ChatJoinRequest (#863)

* Bound method approve() and decline()

* Style fixes

Co-authored-by: ArUn Pt <46273006+CW4RR10R@users.noreply.github.com>
Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 .../types/user_and_chats/chat_join_request.py | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/pyrogram/types/user_and_chats/chat_join_request.py b/pyrogram/types/user_and_chats/chat_join_request.py
index a7001da5d9..fe051de4f7 100644
--- a/pyrogram/types/user_and_chats/chat_join_request.py
+++ b/pyrogram/types/user_and_chats/chat_join_request.py
@@ -80,3 +80,59 @@ def _parse(
             invite_link=types.ChatInviteLink._parse(client, update.invite, users),
             client=client
         )
+
+    async def approve(self) -> bool:
+        """Bound method *approve* of :obj:`~pyrogram.types.ChatJoinRequest`.
+        
+        Use as a shortcut for:
+        
+        .. code-block:: python
+
+            client.approve_chat_join_request(
+                chat_id=request.chat.id,
+                user_id=request.from_user.id
+            )
+            
+        Example:
+            .. code-block:: python
+
+                request.approve()
+                
+        Returns:
+            ``bool``: True on success.
+        
+        Raises:
+            RPCError: In case of a Telegram RPC error.
+        """
+        return await self._client.approve_chat_join_request(
+            chat_id=self.chat.id,
+            user_id=self.from_user.id
+        )
+
+    async def decline(self) -> bool:
+        """Bound method *decline* of :obj:`~pyrogram.types.ChatJoinRequest`.
+        
+        Use as a shortcut for:
+        
+        .. code-block:: python
+
+            client.decline_chat_join_request(
+                chat_id=request.chat.id,
+                user_id=request.from_user.id
+            )
+            
+        Example:
+            .. code-block:: python
+
+                request.decline()
+                
+        Returns:
+            ``bool``: True on success.
+        
+        Raises:
+            RPCError: In case of a Telegram RPC error.
+        """
+        return await self._client.decline_chat_join_request(
+            chat_id=self.chat.id,
+            user_id=self.from_user.id
+        )

From 149685f9d3802130af31721171f9c7db4dabec57 Mon Sep 17 00:00:00 2001
From: Mahesh <44301650+Mahesh0253@users.noreply.github.com>
Date: Sat, 29 Jan 2022 16:24:00 +0530
Subject: [PATCH 061/539] Add placeholder in ForceReply & ReplyKeyboardMarkup
 (#717)

* Added placeholder

* Fix docs
---
 pyrogram/types/bots_and_keyboards/force_reply.py    | 13 ++++++++++---
 .../bots_and_keyboards/reply_keyboard_markup.py     | 13 ++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/pyrogram/types/bots_and_keyboards/force_reply.py b/pyrogram/types/bots_and_keyboards/force_reply.py
index 025176f2e3..4cb137d845 100644
--- a/pyrogram/types/bots_and_keyboards/force_reply.py
+++ b/pyrogram/types/bots_and_keyboards/force_reply.py
@@ -36,24 +36,31 @@ class ForceReply(Object):
             Use this parameter if you want to force reply from specific users only. Targets:
             1) users that are @mentioned in the text of the Message object;
             2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
+
+        placeholder (``str``, *optional*):
+            The placeholder to be shown in the input field when the reply is active; 1-64 characters.
     """
 
     def __init__(
         self,
-        selective: bool = None
+        selective: bool = None,
+        placeholder: str = None
     ):
         super().__init__()
 
         self.selective = selective
+        self.placeholder = placeholder
 
     @staticmethod
     def read(b):
         return ForceReply(
-            selective=b.selective
+            selective=b.selective,
+            placeholder=b.placeholder
         )
 
     async def write(self, _: "pyrogram.Client"):
         return raw.types.ReplyKeyboardForceReply(
             single_use=True,
-            selective=self.selective or None
+            selective=self.selective or None,
+            placeholder=self.placeholder or None
         )
diff --git a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
index b619216a13..b62f6dcff7 100644
--- a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
+++ b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py
@@ -47,6 +47,9 @@ class ReplyKeyboardMarkup(Object):
             2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
             Example: A user requests to change the bot's language, bot replies to the request with a keyboard to
             select the new language. Other users in the group don't see the keyboard.
+
+        placeholder (``str``, *optional*):
+            The placeholder to be shown in the input field when the keyboard is active; 1-64 characters.
     """
 
     def __init__(
@@ -54,7 +57,8 @@ def __init__(
         keyboard: List[List[Union["types.KeyboardButton", str]]],
         resize_keyboard: bool = None,
         one_time_keyboard: bool = None,
-        selective: bool = None
+        selective: bool = None,
+        placeholder: str = None
     ):
         super().__init__()
 
@@ -62,6 +66,7 @@ def __init__(
         self.resize_keyboard = resize_keyboard
         self.one_time_keyboard = one_time_keyboard
         self.selective = selective
+        self.placeholder = placeholder
 
     @staticmethod
     def read(kb):
@@ -79,7 +84,8 @@ def read(kb):
             keyboard=keyboard,
             resize_keyboard=kb.resize,
             one_time_keyboard=kb.single_use,
-            selective=kb.selective
+            selective=kb.selective,
+            placeholder=kb.placeholder
         )
 
     async def write(self, _: "pyrogram.Client"):
@@ -93,5 +99,6 @@ async def write(self, _: "pyrogram.Client"):
             ) for i in self.keyboard],
             resize=self.resize_keyboard or None,
             single_use=self.one_time_keyboard or None,
-            selective=self.selective or None
+            selective=self.selective or None,
+            placeholder=self.placeholder or None
         )

From b1250e65751da992369cae8701eee5caa39c3fe7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 29 Jan 2022 13:02:32 +0100
Subject: [PATCH 062/539] Fix accessing non-existent attribute Closes #865

---
 pyrogram/types/user_and_chats/chat.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index a9d396eb21..6dc3fb8264 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -247,7 +247,8 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
             is_fake=getattr(channel, "fake", None),
             title=channel.title,
             username=getattr(channel, "username", None),
-            photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id, channel.access_hash),
+            photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id,
+                                         getattr(channel, "access_hash", 0)),
             restrictions=types.List([types.Restriction._parse(r) for r in restriction_reason]) or None,
             permissions=types.ChatPermissions._parse(getattr(channel, "default_banned_rights", None)),
             members_count=getattr(channel, "participants_count", None),

From 3e79d7dfce9a4b259a2ee1833eb5b0d47560e9ba Mon Sep 17 00:00:00 2001
From: Pietro De Nicolao 
Date: Sat, 29 Jan 2022 13:39:25 +0100
Subject: [PATCH 063/539] Add py.typed file for enhanced type hinting (#838)

Fixes #781

* fix: add py.typed file

Comply with PEP 561 and enable type checkers.
Fixes #781.

* chore: add py.typed to package_data in setup.py

* Style fixes

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/py.typed | 0
 setup.py          | 3 +++
 2 files changed, 3 insertions(+)
 create mode 100644 pyrogram/py.typed

diff --git a/pyrogram/py.typed b/pyrogram/py.typed
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/setup.py b/setup.py
index 1a24654ce8..66ede5066d 100644
--- a/setup.py
+++ b/setup.py
@@ -172,6 +172,9 @@ def run(self):
         "Documentation": "https://docs.pyrogram.org",
     },
     python_requires="~=3.6",
+    package_data = {
+        "pyrogram": ["py.typed"],
+    },
     packages=find_packages(exclude=["compiler*", "tests*"]),
     zip_safe=False,
     install_requires=requires,

From f1298dfdc67c51bf31cf436db1512749b5447e60 Mon Sep 17 00:00:00 2001
From: Roj 
Date: Sat, 29 Jan 2022 16:08:15 +0300
Subject: [PATCH 064/539] Add video_start_ts parameter to set_chat_photo (#770)

* Add `video_start_ts` parameter to `set_chat_photo`

* Docstrings update

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/methods/chats/set_chat_photo.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py
index 266253d632..a1fee7f62f 100644
--- a/pyrogram/methods/chats/set_chat_photo.py
+++ b/pyrogram/methods/chats/set_chat_photo.py
@@ -31,7 +31,8 @@ async def set_chat_photo(
         chat_id: Union[int, str],
         *,
         photo: Union[str, BinaryIO] = None,
-        video: Union[str, BinaryIO] = None
+        video: Union[str, BinaryIO] = None,
+        video_start_ts: float = None,
     ) -> bool:
         """Set a new chat photo or video (H.264/MPEG-4 AVC video, max 5 seconds).
 
@@ -54,6 +55,9 @@ async def set_chat_photo(
                 from your local machine or a binary file-like object with its attribute
                 ".name" set for in-memory uploads.
 
+            video_start_ts (``float``, *optional*):
+                The timestamp in seconds of the video frame to use as photo profile preview.
+
         Returns:
             ``bool``: True on success.
 
@@ -82,7 +86,8 @@ async def set_chat_photo(
             if os.path.isfile(photo):
                 photo = raw.types.InputChatUploadedPhoto(
                     file=await self.save_file(photo),
-                    video=await self.save_file(video)
+                    video=await self.save_file(video),
+                    video_start_ts=video_start_ts,
                 )
             else:
                 photo = utils.get_input_media_from_file_id(photo, FileType.PHOTO)
@@ -90,14 +95,15 @@ async def set_chat_photo(
         else:
             photo = raw.types.InputChatUploadedPhoto(
                 file=await self.save_file(photo),
-                video=await self.save_file(video)
+                video=await self.save_file(video),
+                video_start_ts=video_start_ts,
             )
 
         if isinstance(peer, raw.types.InputPeerChat):
             await self.send(
                 raw.functions.messages.EditChatPhoto(
                     chat_id=peer.chat_id,
-                    photo=photo
+                    photo=photo,
                 )
             )
         elif isinstance(peer, raw.types.InputPeerChannel):

From 333d22afcad3d94268f0370b06950f40977d97e8 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 29 Jan 2022 14:45:35 +0100
Subject: [PATCH 065/539] Update API schema to Layer 137

---
 compiler/api/source/main_api.tl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 3cfee8a5e0..824fab45d1 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -1291,7 +1291,7 @@ messageUserReaction#932844fa user_id:long reaction:string = MessageUserReaction;
 
 messages.messageReactionsList#a366923c flags:# count:int reactions:Vector users:Vector next_offset:flags.0?string = messages.MessageReactionsList;
 
-availableReaction#21d7c4b flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document = AvailableReaction;
+availableReaction#c077ec01 flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction;
 
 messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions;
 messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions;
@@ -1728,4 +1728,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 136
\ No newline at end of file
+// LAYER 137
\ No newline at end of file

From c7888437e881d6188c710fe405f0ae8334755611 Mon Sep 17 00:00:00 2001
From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com>
Date: Sat, 29 Jan 2022 18:50:51 +0100
Subject: [PATCH 066/539] Fixed error while unparsing consecutive entities
 (#885)

---
 pyrogram/parser/html.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index b70a189f57..81c761ac94 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -175,10 +175,7 @@ def unparse(text: str, entities: list):
             entities_offsets.append((start_tag, start,))
             entities_offsets.append((end_tag, end,))
 
-        # sorting by offset (desc)
-        entities_offsets.sort(key=lambda x: -x[1])
-
-        for entity, offset in entities_offsets:
+        for entity, offset in reversed(entities_offsets):
             text = text[:offset] + entity + text[offset:]
 
         return utils.remove_surrogates(text)

From 6f9e77bc2c54ca6bc928592645c48317a74981f5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 20:42:44 +0100
Subject: [PATCH 067/539] Do not handle messages with a pending ack

---
 pyrogram/session/session.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 6455e958a1..c156c95377 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -208,7 +208,9 @@ async def handle_packet(self, packet):
                 MsgId.set_server_time(msg.msg_id / (2 ** 32))
 
             if msg.seq_no % 2 != 0:
-                if msg.msg_id not in self.pending_acks:
+                if msg.msg_id in self.pending_acks:
+                    continue
+                else:
                     self.pending_acks.add(msg.msg_id)
 
             if isinstance(msg.body, (raw.types.MsgDetailedInfo, raw.types.MsgNewDetailedInfo)):

From 3a911956b064372c79c9856c2115909f946e4269 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 20:45:04 +0100
Subject: [PATCH 068/539] Update message for automatic sleeps

---
 pyrogram/session/session.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index c156c95377..05d1fd4a3f 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -366,7 +366,8 @@ async def send(
                 if amount > sleep_threshold >= 0:
                     raise
 
-                log.warning(f'[{self.client.session_name}] Sleeping for {amount}s (required by "{query}")')
+                log.warning(f'[{self.client.session_name}] Waiting for {amount} seconds before continuing '
+                            f'(required by "{query}")')
 
                 await asyncio.sleep(amount)
             except (OSError, TimeoutError, InternalServerError, ServiceUnavailable) as e:

From a8cc77d903fe0f92303d360b067983509bac835c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 20:46:53 +0100
Subject: [PATCH 069/539] Update Pyrogram to v1.3.7

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index b3b2ccdf8a..81670ac9b2 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.6"
+__version__ = "1.3.7"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From afad3a7704d122fdc4fc941f6e2746da3c988cb2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 21:26:30 +0100
Subject: [PATCH 070/539] Switch from issue templates to issue forms

---
 .github/ISSUE_TEMPLATE/bug_report.md       | 28 ------------
 .github/ISSUE_TEMPLATE/bug_report.yml      | 51 ++++++++++++++++++++++
 .github/ISSUE_TEMPLATE/feature_request.md  | 14 ------
 .github/ISSUE_TEMPLATE/feature_request.yml | 20 +++++++++
 4 files changed, 71 insertions(+), 42 deletions(-)
 delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md
 create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml
 delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md
 create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml

diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index e3bc5909d1..0000000000
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,28 +0,0 @@
----
-name: Bug Report
-about: Create a bug report affecting the framework or the documentation
----
-
-
-
-## Checklist
-- [ ] I am sure the error is coming from Pyrogram's code and not elsewhere.
-- [ ] I have searched in the issue tracker for similar bug reports, including closed ones.
-- [ ] I ran `pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip` and reproduced the issue using the latest development version.
-
-## Description
-A **clear** and **concise** description of the problem. Code snippets must be
-[minimal, reproducible](https://stackoverflow.com/help/minimal-reproducible-example) and properly formatted.
-
-``` python
-from pyrogram import Client
-...
-```
-
-## Traceback
-The full traceback (if applicable).
-
-```
-Traceback (most recent call last):
-  File "main.py", line 1, in 
-```
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000000..b03ff7dc5e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,51 @@
+name: Bug report
+description: Report issues affecting the framework or the documentation
+body:
+  - type: checkboxes
+    attributes:
+      label: Checklist
+      options:
+        - label: I am sure the error is coming from Pyrogram's code and not elsewhere
+          required: true
+        - label: I have searched in the issue tracker for similar bug reports, including closed ones
+          required: true
+        - label: I ran `pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip` and reproduced the issue using the latest development version
+          required: true
+
+  - type: textarea
+    attributes:
+      label: Description
+      description: Provide a clear and concise description of the issue
+      placeholder: Description...
+    validations:
+      required: true
+
+  - type: textarea
+    attributes:
+      label: Steps to reproduce
+      description: Explain precisely how to reproduce the issue
+      placeholder: |
+        1.
+        2.
+        3.
+    validations:
+      required: true
+
+  - type: textarea
+    attributes:
+      label: Code example
+      description: Provide a [minimal, reproducible](https://stackoverflow.com/help/minimal-reproducible-example) and properly formatted example (if applicable)
+      placeholder: |
+        from pyrogram import Client
+        ...
+      render: python
+
+  - type: textarea
+    attributes:
+      label: Logs
+      description: Provide the complete traceback (if applicable)
+      placeholder: |
+        Traceback (most recent call last):
+        File "main.py", line 1, in 
+        ...
+      render: shell
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index bf5e6a21f3..0000000000
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,14 +0,0 @@
----
-name: Feature Request
-about: Suggest ideas, new features or enhancements
-labels: "enhancement"
----
-
-
-
-## Checklist
-- [ ] I believe the idea is awesome and would benefit the framework.
-- [ ] I have searched in the issue tracker for similar requests, including closed ones.
-
-## Description
-A detailed description of the request.
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
new file mode 100644
index 0000000000..59202d14a9
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -0,0 +1,20 @@
+name: Feature request
+description: Suggest ideas, new features or enhancements
+labels: [enhancement]
+body:
+  - type: checkboxes
+    attributes:
+      label: Checklist
+      options:
+        - label: I believe the idea is awesome and would benefit the framework
+          required: true
+        - label: I have searched in the issue tracker for similar requests, including closed ones
+          required: true
+
+  - type: textarea
+    attributes:
+      label: Description
+      description: Provide a detailed description of the request
+      placeholder: Description...
+    validations:
+      required: true
\ No newline at end of file

From 51cf103c1533c21638dc6c2dd8d353e0ddbbbb47 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 21:27:58 +0100
Subject: [PATCH 071/539] Update emoji.py

---
 pyrogram/emoji.py | 1102 +++++++++++++++++++++++++--------------------
 1 file changed, 608 insertions(+), 494 deletions(-)

diff --git a/pyrogram/emoji.py b/pyrogram/emoji.py
index 19dd7e8172..d135faf74d 100644
--- a/pyrogram/emoji.py
+++ b/pyrogram/emoji.py
@@ -26,6 +26,7 @@
 FACE_WITH_TEARS_OF_JOY = "\U0001f602"
 SLIGHTLY_SMILING_FACE = "\U0001f642"
 UPSIDE_DOWN_FACE = "\U0001f643"
+MELTING_FACE = "\U0001fae0"
 WINKING_FACE = "\U0001f609"
 SMILING_FACE_WITH_SMILING_EYES = "\U0001f60a"
 SMILING_FACE_WITH_HALO = "\U0001f607"
@@ -44,19 +45,25 @@
 ZANY_FACE = "\U0001f92a"
 SQUINTING_FACE_WITH_TONGUE = "\U0001f61d"
 MONEY_MOUTH_FACE = "\U0001f911"
-HUGGING_FACE = "\U0001f917"
+SMILING_FACE_WITH_OPEN_HANDS = "\U0001f917"
 FACE_WITH_HAND_OVER_MOUTH = "\U0001f92d"
+FACE_WITH_OPEN_EYES_AND_HAND_OVER_MOUTH = "\U0001fae2"
+FACE_WITH_PEEKING_EYE = "\U0001fae3"
 SHUSHING_FACE = "\U0001f92b"
 THINKING_FACE = "\U0001f914"
+SALUTING_FACE = "\U0001fae1"
 ZIPPER_MOUTH_FACE = "\U0001f910"
 FACE_WITH_RAISED_EYEBROW = "\U0001f928"
 NEUTRAL_FACE = "\U0001f610"
 EXPRESSIONLESS_FACE = "\U0001f611"
 FACE_WITHOUT_MOUTH = "\U0001f636"
+DOTTED_LINE_FACE = "\U0001fae5"
+FACE_IN_CLOUDS = "\U0001f636\u200d\U0001f32b\ufe0f"
 SMIRKING_FACE = "\U0001f60f"
 UNAMUSED_FACE = "\U0001f612"
 FACE_WITH_ROLLING_EYES = "\U0001f644"
 GRIMACING_FACE = "\U0001f62c"
+FACE_EXHALING = "\U0001f62e\u200d\U0001f4a8"
 LYING_FACE = "\U0001f925"
 RELIEVED_FACE = "\U0001f60c"
 PENSIVE_FACE = "\U0001f614"
@@ -72,7 +79,8 @@
 HOT_FACE = "\U0001f975"
 COLD_FACE = "\U0001f976"
 WOOZY_FACE = "\U0001f974"
-DIZZY_FACE = "\U0001f635"
+FACE_WITH_CROSSED_OUT_EYES = "\U0001f635"
+FACE_WITH_SPIRAL_EYES = "\U0001f635\u200d\U0001f4ab"
 EXPLODING_HEAD = "\U0001f92f"
 COWBOY_HAT_FACE = "\U0001f920"
 PARTYING_FACE = "\U0001f973"
@@ -81,6 +89,7 @@
 NERD_FACE = "\U0001f913"
 FACE_WITH_MONOCLE = "\U0001f9d0"
 CONFUSED_FACE = "\U0001f615"
+FACE_WITH_DIAGONAL_MOUTH = "\U0001fae4"
 WORRIED_FACE = "\U0001f61f"
 SLIGHTLY_FROWNING_FACE = "\U0001f641"
 FROWNING_FACE = "\u2639\ufe0f"
@@ -89,6 +98,7 @@
 ASTONISHED_FACE = "\U0001f632"
 FLUSHED_FACE = "\U0001f633"
 PLEADING_FACE = "\U0001f97a"
+FACE_HOLDING_BACK_TEARS = "\U0001f979"
 FROWNING_FACE_WITH_OPEN_MOUTH = "\U0001f626"
 ANGUISHED_FACE = "\U0001f627"
 FEARFUL_FACE = "\U0001f628"
@@ -105,7 +115,7 @@
 TIRED_FACE = "\U0001f62b"
 YAWNING_FACE = "\U0001f971"
 FACE_WITH_STEAM_FROM_NOSE = "\U0001f624"
-POUTING_FACE = "\U0001f621"
+ENRAGED_FACE = "\U0001f621"
 ANGRY_FACE = "\U0001f620"
 FACE_WITH_SYMBOLS_ON_MOUTH = "\U0001f92c"
 SMILING_FACE_WITH_HORNS = "\U0001f608"
@@ -144,6 +154,8 @@
 HEART_DECORATION = "\U0001f49f"
 HEART_EXCLAMATION = "\u2763\ufe0f"
 BROKEN_HEART = "\U0001f494"
+HEART_ON_FIRE = "\u2764\ufe0f\u200d\U0001f525"
+MENDING_HEART = "\u2764\ufe0f\u200d\U0001fa79"
 RED_HEART = "\u2764\ufe0f"
 ORANGE_HEART = "\U0001f9e1"
 YELLOW_HEART = "\U0001f49b"
@@ -197,6 +209,30 @@
 VULCAN_SALUTE_MEDIUM_SKIN_TONE = "\U0001f596\U0001f3fd"
 VULCAN_SALUTE_MEDIUM_DARK_SKIN_TONE = "\U0001f596\U0001f3fe"
 VULCAN_SALUTE_DARK_SKIN_TONE = "\U0001f596\U0001f3ff"
+RIGHTWARDS_HAND = "\U0001faf1"
+RIGHTWARDS_HAND_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fb"
+RIGHTWARDS_HAND_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fc"
+RIGHTWARDS_HAND_MEDIUM_SKIN_TONE = "\U0001faf1\U0001f3fd"
+RIGHTWARDS_HAND_MEDIUM_DARK_SKIN_TONE = "\U0001faf1\U0001f3fe"
+RIGHTWARDS_HAND_DARK_SKIN_TONE = "\U0001faf1\U0001f3ff"
+LEFTWARDS_HAND = "\U0001faf2"
+LEFTWARDS_HAND_LIGHT_SKIN_TONE = "\U0001faf2\U0001f3fb"
+LEFTWARDS_HAND_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf2\U0001f3fc"
+LEFTWARDS_HAND_MEDIUM_SKIN_TONE = "\U0001faf2\U0001f3fd"
+LEFTWARDS_HAND_MEDIUM_DARK_SKIN_TONE = "\U0001faf2\U0001f3fe"
+LEFTWARDS_HAND_DARK_SKIN_TONE = "\U0001faf2\U0001f3ff"
+PALM_DOWN_HAND = "\U0001faf3"
+PALM_DOWN_HAND_LIGHT_SKIN_TONE = "\U0001faf3\U0001f3fb"
+PALM_DOWN_HAND_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf3\U0001f3fc"
+PALM_DOWN_HAND_MEDIUM_SKIN_TONE = "\U0001faf3\U0001f3fd"
+PALM_DOWN_HAND_MEDIUM_DARK_SKIN_TONE = "\U0001faf3\U0001f3fe"
+PALM_DOWN_HAND_DARK_SKIN_TONE = "\U0001faf3\U0001f3ff"
+PALM_UP_HAND = "\U0001faf4"
+PALM_UP_HAND_LIGHT_SKIN_TONE = "\U0001faf4\U0001f3fb"
+PALM_UP_HAND_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf4\U0001f3fc"
+PALM_UP_HAND_MEDIUM_SKIN_TONE = "\U0001faf4\U0001f3fd"
+PALM_UP_HAND_MEDIUM_DARK_SKIN_TONE = "\U0001faf4\U0001f3fe"
+PALM_UP_HAND_DARK_SKIN_TONE = "\U0001faf4\U0001f3ff"
 OK_HAND = "\U0001f44c"
 OK_HAND_LIGHT_SKIN_TONE = "\U0001f44c\U0001f3fb"
 OK_HAND_MEDIUM_LIGHT_SKIN_TONE = "\U0001f44c\U0001f3fc"
@@ -227,6 +263,12 @@
 CROSSED_FINGERS_MEDIUM_SKIN_TONE = "\U0001f91e\U0001f3fd"
 CROSSED_FINGERS_MEDIUM_DARK_SKIN_TONE = "\U0001f91e\U0001f3fe"
 CROSSED_FINGERS_DARK_SKIN_TONE = "\U0001f91e\U0001f3ff"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED = "\U0001faf0"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED_LIGHT_SKIN_TONE = "\U0001faf0\U0001f3fb"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf0\U0001f3fc"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED_MEDIUM_SKIN_TONE = "\U0001faf0\U0001f3fd"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED_MEDIUM_DARK_SKIN_TONE = "\U0001faf0\U0001f3fe"
+HAND_WITH_INDEX_FINGER_AND_THUMB_CROSSED_DARK_SKIN_TONE = "\U0001faf0\U0001f3ff"
 LOVE_YOU_GESTURE = "\U0001f91f"
 LOVE_YOU_GESTURE_LIGHT_SKIN_TONE = "\U0001f91f\U0001f3fb"
 LOVE_YOU_GESTURE_MEDIUM_LIGHT_SKIN_TONE = "\U0001f91f\U0001f3fc"
@@ -281,6 +323,12 @@
 INDEX_POINTING_UP_MEDIUM_SKIN_TONE = "\u261d\U0001f3fd"
 INDEX_POINTING_UP_MEDIUM_DARK_SKIN_TONE = "\u261d\U0001f3fe"
 INDEX_POINTING_UP_DARK_SKIN_TONE = "\u261d\U0001f3ff"
+INDEX_POINTING_AT_THE_VIEWER = "\U0001faf5"
+INDEX_POINTING_AT_THE_VIEWER_LIGHT_SKIN_TONE = "\U0001faf5\U0001f3fb"
+INDEX_POINTING_AT_THE_VIEWER_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf5\U0001f3fc"
+INDEX_POINTING_AT_THE_VIEWER_MEDIUM_SKIN_TONE = "\U0001faf5\U0001f3fd"
+INDEX_POINTING_AT_THE_VIEWER_MEDIUM_DARK_SKIN_TONE = "\U0001faf5\U0001f3fe"
+INDEX_POINTING_AT_THE_VIEWER_DARK_SKIN_TONE = "\U0001faf5\U0001f3ff"
 THUMBS_UP = "\U0001f44d"
 THUMBS_UP_LIGHT_SKIN_TONE = "\U0001f44d\U0001f3fb"
 THUMBS_UP_MEDIUM_LIGHT_SKIN_TONE = "\U0001f44d\U0001f3fc"
@@ -329,6 +377,12 @@
 RAISING_HANDS_MEDIUM_SKIN_TONE = "\U0001f64c\U0001f3fd"
 RAISING_HANDS_MEDIUM_DARK_SKIN_TONE = "\U0001f64c\U0001f3fe"
 RAISING_HANDS_DARK_SKIN_TONE = "\U0001f64c\U0001f3ff"
+HEART_HANDS = "\U0001faf6"
+HEART_HANDS_LIGHT_SKIN_TONE = "\U0001faf6\U0001f3fb"
+HEART_HANDS_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf6\U0001f3fc"
+HEART_HANDS_MEDIUM_SKIN_TONE = "\U0001faf6\U0001f3fd"
+HEART_HANDS_MEDIUM_DARK_SKIN_TONE = "\U0001faf6\U0001f3fe"
+HEART_HANDS_DARK_SKIN_TONE = "\U0001faf6\U0001f3ff"
 OPEN_HANDS = "\U0001f450"
 OPEN_HANDS_LIGHT_SKIN_TONE = "\U0001f450\U0001f3fb"
 OPEN_HANDS_MEDIUM_LIGHT_SKIN_TONE = "\U0001f450\U0001f3fc"
@@ -342,6 +396,31 @@
 PALMS_UP_TOGETHER_MEDIUM_DARK_SKIN_TONE = "\U0001f932\U0001f3fe"
 PALMS_UP_TOGETHER_DARK_SKIN_TONE = "\U0001f932\U0001f3ff"
 HANDSHAKE = "\U0001f91d"
+HANDSHAKE_LIGHT_SKIN_TONE = "\U0001f91d\U0001f3fb"
+HANDSHAKE_MEDIUM_LIGHT_SKIN_TONE = "\U0001f91d\U0001f3fc"
+HANDSHAKE_MEDIUM_SKIN_TONE = "\U0001f91d\U0001f3fd"
+HANDSHAKE_MEDIUM_DARK_SKIN_TONE = "\U0001f91d\U0001f3fe"
+HANDSHAKE_DARK_SKIN_TONE = "\U0001f91d\U0001f3ff"
+HANDSHAKE_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fb\u200d\U0001faf2\U0001f3fc"
+HANDSHAKE_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = "\U0001faf1\U0001f3fb\u200d\U0001faf2\U0001f3fd"
+HANDSHAKE_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = "\U0001faf1\U0001f3fb\u200d\U0001faf2\U0001f3fe"
+HANDSHAKE_LIGHT_SKIN_TONE_DARK_SKIN_TONE = "\U0001faf1\U0001f3fb\u200d\U0001faf2\U0001f3ff"
+HANDSHAKE_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fc\u200d\U0001faf2\U0001f3fb"
+HANDSHAKE_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = "\U0001faf1\U0001f3fc\u200d\U0001faf2\U0001f3fd"
+HANDSHAKE_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = "\U0001faf1\U0001f3fc\u200d\U0001faf2\U0001f3fe"
+HANDSHAKE_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = "\U0001faf1\U0001f3fc\u200d\U0001faf2\U0001f3ff"
+HANDSHAKE_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fd\u200d\U0001faf2\U0001f3fb"
+HANDSHAKE_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fd\u200d\U0001faf2\U0001f3fc"
+HANDSHAKE_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = "\U0001faf1\U0001f3fd\u200d\U0001faf2\U0001f3fe"
+HANDSHAKE_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = "\U0001faf1\U0001f3fd\u200d\U0001faf2\U0001f3ff"
+HANDSHAKE_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fe\u200d\U0001faf2\U0001f3fb"
+HANDSHAKE_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3fe\u200d\U0001faf2\U0001f3fc"
+HANDSHAKE_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = "\U0001faf1\U0001f3fe\u200d\U0001faf2\U0001f3fd"
+HANDSHAKE_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = "\U0001faf1\U0001f3fe\u200d\U0001faf2\U0001f3ff"
+HANDSHAKE_DARK_SKIN_TONE_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3ff\u200d\U0001faf2\U0001f3fb"
+HANDSHAKE_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = "\U0001faf1\U0001f3ff\u200d\U0001faf2\U0001f3fc"
+HANDSHAKE_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = "\U0001faf1\U0001f3ff\u200d\U0001faf2\U0001f3fd"
+HANDSHAKE_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = "\U0001faf1\U0001f3ff\u200d\U0001faf2\U0001f3fe"
 FOLDED_HANDS = "\U0001f64f"
 FOLDED_HANDS_LIGHT_SKIN_TONE = "\U0001f64f\U0001f3fb"
 FOLDED_HANDS_MEDIUM_LIGHT_SKIN_TONE = "\U0001f64f\U0001f3fc"
@@ -413,6 +492,7 @@
 EYE = "\U0001f441\ufe0f"
 TONGUE = "\U0001f445"
 MOUTH = "\U0001f444"
+BITING_LIP = "\U0001fae6"
 BABY = "\U0001f476"
 BABY_LIGHT_SKIN_TONE = "\U0001f476\U0001f3fb"
 BABY_MEDIUM_LIGHT_SKIN_TONE = "\U0001f476\U0001f3fc"
@@ -461,6 +541,18 @@
 PERSON_MEDIUM_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fd"
 PERSON_MEDIUM_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fe"
 PERSON_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3ff"
+MAN_BEARD = "\U0001f9d4\u200d\u2642\ufe0f"
+MAN_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fb\u200d\u2642\ufe0f"
+MAN_MEDIUM_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fc\u200d\u2642\ufe0f"
+MAN_MEDIUM_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fd\u200d\u2642\ufe0f"
+MAN_MEDIUM_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fe\u200d\u2642\ufe0f"
+MAN_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3ff\u200d\u2642\ufe0f"
+WOMAN_BEARD = "\U0001f9d4\u200d\u2640\ufe0f"
+WOMAN_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fb\u200d\u2640\ufe0f"
+WOMAN_MEDIUM_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fc\u200d\u2640\ufe0f"
+WOMAN_MEDIUM_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fd\u200d\u2640\ufe0f"
+WOMAN_MEDIUM_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fe\u200d\u2640\ufe0f"
+WOMAN_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3ff\u200d\u2640\ufe0f"
 MAN_RED_HAIR = "\U0001f468\u200d\U0001f9b0"
 MAN_LIGHT_SKIN_TONE_RED_HAIR = "\U0001f468\U0001f3fb\u200d\U0001f9b0"
 MAN_MEDIUM_LIGHT_SKIN_TONE_RED_HAIR = "\U0001f468\U0001f3fc\u200d\U0001f9b0"
@@ -1115,6 +1207,12 @@
 WOMAN_CONSTRUCTION_WORKER_MEDIUM_SKIN_TONE = "\U0001f477\U0001f3fd\u200d\u2640\ufe0f"
 WOMAN_CONSTRUCTION_WORKER_MEDIUM_DARK_SKIN_TONE = "\U0001f477\U0001f3fe\u200d\u2640\ufe0f"
 WOMAN_CONSTRUCTION_WORKER_DARK_SKIN_TONE = "\U0001f477\U0001f3ff\u200d\u2640\ufe0f"
+PERSON_WITH_CROWN = "\U0001fac5"
+PERSON_WITH_CROWN_LIGHT_SKIN_TONE = "\U0001fac5\U0001f3fb"
+PERSON_WITH_CROWN_MEDIUM_LIGHT_SKIN_TONE = "\U0001fac5\U0001f3fc"
+PERSON_WITH_CROWN_MEDIUM_SKIN_TONE = "\U0001fac5\U0001f3fd"
+PERSON_WITH_CROWN_MEDIUM_DARK_SKIN_TONE = "\U0001fac5\U0001f3fe"
+PERSON_WITH_CROWN_DARK_SKIN_TONE = "\U0001fac5\U0001f3ff"
 PRINCE = "\U0001f934"
 PRINCE_LIGHT_SKIN_TONE = "\U0001f934\U0001f3fb"
 PRINCE_MEDIUM_LIGHT_SKIN_TONE = "\U0001f934\U0001f3fc"
@@ -1199,6 +1297,18 @@
 PREGNANT_WOMAN_MEDIUM_SKIN_TONE = "\U0001f930\U0001f3fd"
 PREGNANT_WOMAN_MEDIUM_DARK_SKIN_TONE = "\U0001f930\U0001f3fe"
 PREGNANT_WOMAN_DARK_SKIN_TONE = "\U0001f930\U0001f3ff"
+PREGNANT_MAN = "\U0001fac3"
+PREGNANT_MAN_LIGHT_SKIN_TONE = "\U0001fac3\U0001f3fb"
+PREGNANT_MAN_MEDIUM_LIGHT_SKIN_TONE = "\U0001fac3\U0001f3fc"
+PREGNANT_MAN_MEDIUM_SKIN_TONE = "\U0001fac3\U0001f3fd"
+PREGNANT_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001fac3\U0001f3fe"
+PREGNANT_MAN_DARK_SKIN_TONE = "\U0001fac3\U0001f3ff"
+PREGNANT_PERSON = "\U0001fac4"
+PREGNANT_PERSON_LIGHT_SKIN_TONE = "\U0001fac4\U0001f3fb"
+PREGNANT_PERSON_MEDIUM_LIGHT_SKIN_TONE = "\U0001fac4\U0001f3fc"
+PREGNANT_PERSON_MEDIUM_SKIN_TONE = "\U0001fac4\U0001f3fd"
+PREGNANT_PERSON_MEDIUM_DARK_SKIN_TONE = "\U0001fac4\U0001f3fe"
+PREGNANT_PERSON_DARK_SKIN_TONE = "\U0001fac4\U0001f3ff"
 BREAST_FEEDING = "\U0001f931"
 BREAST_FEEDING_LIGHT_SKIN_TONE = "\U0001f931\U0001f3fb"
 BREAST_FEEDING_MEDIUM_LIGHT_SKIN_TONE = "\U0001f931\U0001f3fc"
@@ -1379,6 +1489,7 @@
 ZOMBIE = "\U0001f9df"
 MAN_ZOMBIE = "\U0001f9df\u200d\u2642\ufe0f"
 WOMAN_ZOMBIE = "\U0001f9df\u200d\u2640\ufe0f"
+TROLL = "\U0001f9cc"
 PERSON_GETTING_MASSAGE = "\U0001f486"
 PERSON_GETTING_MASSAGE_LIGHT_SKIN_TONE = "\U0001f486\U0001f3fb"
 PERSON_GETTING_MASSAGE_MEDIUM_LIGHT_SKIN_TONE = "\U0001f486\U0001f3fc"
@@ -1775,6 +1886,8 @@
 WOMAN_CARTWHEELING_MEDIUM_DARK_SKIN_TONE = "\U0001f938\U0001f3fe\u200d\u2640\ufe0f"
 WOMAN_CARTWHEELING_DARK_SKIN_TONE = "\U0001f938\U0001f3ff\u200d\u2640\ufe0f"
 PEOPLE_WRESTLING = "\U0001f93c"
+MEN_WRESTLING = "\U0001f93c\u200d\u2642\ufe0f"
+WOMEN_WRESTLING = "\U0001f93c\u200d\u2640\ufe0f"
 PERSON_PLAYING_WATER_POLO = "\U0001f93d"
 PERSON_PLAYING_WATER_POLO_LIGHT_SKIN_TONE = "\U0001f93d\U0001f3fb"
 PERSON_PLAYING_WATER_POLO_MEDIUM_LIGHT_SKIN_TONE = "\U0001f93d\U0001f3fc"
@@ -2028,21 +2141,388 @@
     "\U0001f468\U0001f3ff\u200d\U0001f91d\u200d\U0001f468\U0001f3fe"
 MEN_HOLDING_HANDS_DARK_SKIN_TONE = "\U0001f46c\U0001f3ff"
 KISS = "\U0001f48f"
+KISS_LIGHT_SKIN_TONE = "\U0001f48f\U0001f3fb"
+KISS_MEDIUM_LIGHT_SKIN_TONE = "\U0001f48f\U0001f3fc"
+KISS_MEDIUM_SKIN_TONE = "\U0001f48f\U0001f3fd"
+KISS_MEDIUM_DARK_SKIN_TONE = "\U0001f48f\U0001f3fe"
+KISS_DARK_SKIN_TONE = "\U0001f48f\U0001f3ff"
+KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
+KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
+KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
+KISS_PERSON_PERSON_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
+KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
+KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
+KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
+KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
+KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
+KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
+KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
+KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
+KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
+KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
+KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
+KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
+KISS_PERSON_PERSON_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
+KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
+KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
+KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
 KISS_WOMAN_MAN = "\U0001f469\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468"
+KISS_WOMAN_MAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_WOMAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_WOMAN_MAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_WOMAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_WOMAN_MAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
 KISS_MAN_MAN = "\U0001f468\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468"
+KISS_MAN_MAN_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_MAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_MAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_MAN_MAN_MEDIUM_SKIN_TONE = "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_MAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
+KISS_MAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
+KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
+KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
+KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
+KISS_MAN_MAN_DARK_SKIN_TONE = "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
 KISS_WOMAN_WOMAN = "\U0001f469\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469"
+KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
+KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
+KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
+KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
+KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
+KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
+KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
+KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
+KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
+KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
+KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
+KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
+KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
+KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
+KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
+KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
+KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
+KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
+KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
+KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
+KISS_WOMAN_WOMAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
+KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
+KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
+KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
+KISS_WOMAN_WOMAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
 COUPLE_WITH_HEART = "\U0001f491"
+COUPLE_WITH_HEART_LIGHT_SKIN_TONE = "\U0001f491\U0001f3fb"
+COUPLE_WITH_HEART_MEDIUM_LIGHT_SKIN_TONE = "\U0001f491\U0001f3fc"
+COUPLE_WITH_HEART_MEDIUM_SKIN_TONE = "\U0001f491\U0001f3fd"
+COUPLE_WITH_HEART_MEDIUM_DARK_SKIN_TONE = "\U0001f491\U0001f3fe"
+COUPLE_WITH_HEART_DARK_SKIN_TONE = "\U0001f491\U0001f3ff"
+COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
+COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
+COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
+COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
+COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
+COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
+COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
+COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
+COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
 COUPLE_WITH_HEART_WOMAN_MAN = "\U0001f469\u200d\u2764\ufe0f\u200d\U0001f468"
-COUPLE_WITH_HEART_MAN_MAN = "\U0001f468\u200d\u2764\ufe0f\u200d\U0001f468"
-COUPLE_WITH_HEART_WOMAN_WOMAN = "\U0001f469\u200d\u2764\ufe0f\u200d\U0001f469"
-FAMILY = "\U0001f46a"
-FAMILY_MAN_WOMAN_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f466"
-FAMILY_MAN_WOMAN_GIRL = "\U0001f468\u200d\U0001f469\u200d\U0001f467"
-FAMILY_MAN_WOMAN_GIRL_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f466"
-FAMILY_MAN_WOMAN_BOY_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f466\u200d\U0001f466"
-FAMILY_MAN_WOMAN_GIRL_GIRL = "\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f467"
-FAMILY_MAN_MAN_BOY = "\U0001f468\u200d\U0001f468\u200d\U0001f466"
-FAMILY_MAN_MAN_GIRL = "\U0001f468\u200d\U0001f468\u200d\U0001f467"
+COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_MAN_MAN = "\U0001f468\u200d\u2764\ufe0f\u200d\U0001f468"
+COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE = "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
+COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
+COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
+COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
+COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE = "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_WOMAN = "\U0001f469\u200d\u2764\ufe0f\u200d\U0001f469"
+COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
+COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
+COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
+COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
+COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
+    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
+COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
+FAMILY = "\U0001f46a"
+FAMILY_MAN_WOMAN_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f466"
+FAMILY_MAN_WOMAN_GIRL = "\U0001f468\u200d\U0001f469\u200d\U0001f467"
+FAMILY_MAN_WOMAN_GIRL_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f466"
+FAMILY_MAN_WOMAN_BOY_BOY = "\U0001f468\u200d\U0001f469\u200d\U0001f466\u200d\U0001f466"
+FAMILY_MAN_WOMAN_GIRL_GIRL = "\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f467"
+FAMILY_MAN_MAN_BOY = "\U0001f468\u200d\U0001f468\u200d\U0001f466"
+FAMILY_MAN_MAN_GIRL = "\U0001f468\u200d\U0001f468\u200d\U0001f467"
 FAMILY_MAN_MAN_GIRL_BOY = "\U0001f468\u200d\U0001f468\u200d\U0001f467\u200d\U0001f466"
 FAMILY_MAN_MAN_BOY_BOY = "\U0001f468\u200d\U0001f468\u200d\U0001f466\u200d\U0001f466"
 FAMILY_MAN_MAN_GIRL_GIRL = "\U0001f468\u200d\U0001f468\u200d\U0001f467\u200d\U0001f467"
@@ -2176,6 +2656,7 @@
 SHARK = "\U0001f988"
 OCTOPUS = "\U0001f419"
 SPIRAL_SHELL = "\U0001f41a"
+CORAL = "\U0001fab8"
 SNAIL = "\U0001f40c"
 BUTTERFLY = "\U0001f98b"
 BUG = "\U0001f41b"
@@ -2195,6 +2676,7 @@
 BOUQUET = "\U0001f490"
 CHERRY_BLOSSOM = "\U0001f338"
 WHITE_FLOWER = "\U0001f4ae"
+LOTUS = "\U0001fab7"
 ROSETTE = "\U0001f3f5\ufe0f"
 ROSE = "\U0001f339"
 WILTED_FLOWER = "\U0001f940"
@@ -2215,6 +2697,8 @@
 MAPLE_LEAF = "\U0001f341"
 FALLEN_LEAF = "\U0001f342"
 LEAF_FLUTTERING_IN_WIND = "\U0001f343"
+EMPTY_NEST = "\U0001fab9"
+NEST_WITH_EGGS = "\U0001faba"
 GRAPES = "\U0001f347"
 MELON = "\U0001f348"
 WATERMELON = "\U0001f349"
@@ -2248,6 +2732,7 @@
 ONION = "\U0001f9c5"
 MUSHROOM = "\U0001f344"
 PEANUTS = "\U0001f95c"
+BEANS = "\U0001fad8"
 CHESTNUT = "\U0001f330"
 BREAD = "\U0001f35e"
 CROISSANT = "\U0001f950"
@@ -2333,6 +2818,7 @@
 CLINKING_BEER_MUGS = "\U0001f37b"
 CLINKING_GLASSES = "\U0001f942"
 TUMBLER_GLASS = "\U0001f943"
+POURING_LIQUID = "\U0001fad7"
 CUP_WITH_STRAW = "\U0001f964"
 BUBBLE_TEA = "\U0001f9cb"
 BEVERAGE_BOX = "\U0001f9c3"
@@ -2343,6 +2829,7 @@
 FORK_AND_KNIFE = "\U0001f374"
 SPOON = "\U0001f944"
 KITCHEN_KNIFE = "\U0001f52a"
+JAR = "\U0001fad9"
 AMPHORA = "\U0001f3fa"
 GLOBE_SHOWING_EUROPE_AFRICA = "\U0001f30d"
 GLOBE_SHOWING_AMERICAS = "\U0001f30e"
@@ -2405,6 +2892,7 @@
 BRIDGE_AT_NIGHT = "\U0001f309"
 HOT_SPRINGS = "\u2668\ufe0f"
 CAROUSEL_HORSE = "\U0001f3a0"
+PLAYGROUND_SLIDE = "\U0001f6dd"
 FERRIS_WHEEL = "\U0001f3a1"
 ROLLER_COASTER = "\U0001f3a2"
 BARBER_POLE = "\U0001f488"
@@ -2453,12 +2941,14 @@
 RAILWAY_TRACK = "\U0001f6e4\ufe0f"
 OIL_DRUM = "\U0001f6e2\ufe0f"
 FUEL_PUMP = "\u26fd"
+WHEEL = "\U0001f6de"
 POLICE_CAR_LIGHT = "\U0001f6a8"
 HORIZONTAL_TRAFFIC_LIGHT = "\U0001f6a5"
 VERTICAL_TRAFFIC_LIGHT = "\U0001f6a6"
 STOP_SIGN = "\U0001f6d1"
 CONSTRUCTION = "\U0001f6a7"
 ANCHOR = "\u2693"
+RING_BUOY = "\U0001f6df"
 SAILBOAT = "\u26f5"
 CANOE = "\U0001f6f6"
 SPEEDBOAT = "\U0001f6a4"
@@ -2613,13 +3103,14 @@
 SKIS = "\U0001f3bf"
 SLED = "\U0001f6f7"
 CURLING_STONE = "\U0001f94c"
-DIRECT_HIT = "\U0001f3af"
+BULLSEYE = "\U0001f3af"
 YO_YO = "\U0001fa80"
 KITE = "\U0001fa81"
 POOL_8_BALL = "\U0001f3b1"
 CRYSTAL_BALL = "\U0001f52e"
 MAGIC_WAND = "\U0001fa84"
 NAZAR_AMULET = "\U0001f9ff"
+HAMSA = "\U0001faac"
 VIDEO_GAME = "\U0001f3ae"
 JOYSTICK = "\U0001f579\ufe0f"
 SLOT_MACHINE = "\U0001f3b0"
@@ -2627,6 +3118,7 @@
 PUZZLE_PIECE = "\U0001f9e9"
 TEDDY_BEAR = "\U0001f9f8"
 PINATA = "\U0001fa85"
+MIRROR_BALL = "\U0001faa9"
 NESTING_DOLLS = "\U0001fa86"
 SPADE_SUIT = "\u2660\ufe0f"
 HEART_SUIT = "\u2665\ufe0f"
@@ -2722,6 +3214,7 @@
 PAGER = "\U0001f4df"
 FAX_MACHINE = "\U0001f4e0"
 BATTERY = "\U0001f50b"
+LOW_BATTERY = "\U0001faab"
 ELECTRIC_PLUG = "\U0001f50c"
 LAPTOP = "\U0001f4bb"
 DESKTOP_COMPUTER = "\U0001f5a5\ufe0f"
@@ -2833,7 +3326,7 @@
 HAMMER_AND_WRENCH = "\U0001f6e0\ufe0f"
 DAGGER = "\U0001f5e1\ufe0f"
 CROSSED_SWORDS = "\u2694\ufe0f"
-PISTOL = "\U0001f52b"
+WATER_PISTOL = "\U0001f52b"
 BOOMERANG = "\U0001fa83"
 BOW_AND_ARROW = "\U0001f3f9"
 SHIELD = "\U0001f6e1\ufe0f"
@@ -2862,7 +3355,9 @@
 DROP_OF_BLOOD = "\U0001fa78"
 PILL = "\U0001f48a"
 ADHESIVE_BANDAGE = "\U0001fa79"
+CRUTCH = "\U0001fa7c"
 STETHOSCOPE = "\U0001fa7a"
+X_RAY = "\U0001fa7b"
 DOOR = "\U0001f6aa"
 ELEVATOR = "\U0001f6d7"
 MIRROR = "\U0001fa9e"
@@ -2883,6 +3378,7 @@
 ROLL_OF_PAPER = "\U0001f9fb"
 BUCKET = "\U0001faa3"
 SOAP = "\U0001f9fc"
+BUBBLES = "\U0001fae7"
 TOOTHBRUSH = "\U0001faa5"
 SPONGE = "\U0001f9fd"
 FIRE_EXTINGUISHER = "\U0001f9ef"
@@ -2893,6 +3389,7 @@
 FUNERAL_URN = "\u26b1\ufe0f"
 MOAI = "\U0001f5ff"
 PLACARD = "\U0001faa7"
+IDENTIFICATION_CARD = "\U0001faaa"
 ATM_SIGN = "\U0001f3e7"
 LITTER_IN_BIN_SIGN = "\U0001f6ae"
 POTABLE_WATER = "\U0001f6b0"
@@ -2996,13 +3493,14 @@
 PLUS = "\u2795"
 MINUS = "\u2796"
 DIVIDE = "\u2797"
+HEAVY_EQUALS_SIGN = "\U0001f7f0"
 INFINITY = "\u267e\ufe0f"
 DOUBLE_EXCLAMATION_MARK = "\u203c\ufe0f"
 EXCLAMATION_QUESTION_MARK = "\u2049\ufe0f"
-QUESTION_MARK = "\u2753"
+RED_QUESTION_MARK = "\u2753"
 WHITE_QUESTION_MARK = "\u2754"
 WHITE_EXCLAMATION_MARK = "\u2755"
-EXCLAMATION_MARK = "\u2757"
+RED_EXCLAMATION_MARK = "\u2757"
 WAVY_DASH = "\u3030\ufe0f"
 CURRENCY_EXCHANGE = "\U0001f4b1"
 HEAVY_DOLLAR_SIGN = "\U0001f4b2"
@@ -3408,498 +3906,114 @@
 REGIONAL_INDICATOR_SYMBOL_LETTER_X = "\U0001f1fd"
 REGIONAL_INDICATOR_SYMBOL_LETTER_Y = "\U0001f1fe"
 REGIONAL_INDICATOR_SYMBOL_LETTER_Z = "\U0001f1ff"
-FACE_EXHALING = "\U0001f62e\u200d\U0001f4a8"
-FACE_WITH_SPIRAL_EYES = "\U0001f635\u200d\U0001f4ab"
-FACE_IN_CLOUDS = "\U0001f636\u200d\U0001f32b"
-HEART_ON_FIRE = "\u2764\ufe0f\u200d\U0001f525"
-MENDING_HEART = "\u2764\ufe0f\u200d\U0001fa79"
-WOMAN_BEARD = "\U0001f9d4\u200d\u2640\ufe0f"
-WOMAN_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fb\u200d\u2640\ufe0f"
-WOMAN_MEDIUM_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fc\u200d\u2640\ufe0f"
-WOMAN_MEDIUM_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fd\u200d\u2640\ufe0f"
-WOMAN_MEDIUM_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fe\u200d\u2640\ufe0f"
-WOMAN_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3ff\u200d\u2640\ufe0f"
-MAN_BEARD = "\U0001f9d4\u200d\u2642\ufe0f"
-MAN_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fb\u200d\u2642\ufe0f"
-MAN_MEDIUM_LIGHT_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fc\u200d\u2642\ufe0f"
-MAN_MEDIUM_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fd\u200d\u2642\ufe0f"
-MAN_MEDIUM_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3fe\u200d\u2642\ufe0f"
-MAN_DARK_SKIN_TONE_BEARD = "\U0001f9d4\U0001f3ff\u200d\u2642\ufe0f"
-COUPLE_WITH_HEART_LIGHT_SKIN_TONE = "\U0001f491\U0001f3fb"
-COUPLE_WITH_HEART_MEDIUM_LIGHT_SKIN_TONE = "\U0001f491\U0001f3fc"
-COUPLE_WITH_HEART_MEDIUM_SKIN_TONE = "\U0001f491\U0001f3fd"
-COUPLE_WITH_HEART_MEDIUM_DARK_SKIN_TONE = "\U0001f491\U0001f3fe"
-COUPLE_WITH_HEART_DARK_SKIN_TONE = "\U0001f491\U0001f3ff"
-KISS_LIGHT_SKIN_TONE = "\U0001f48f\U0001f3fb"
-KISS_MEDIUM_LIGHT_SKIN_TONE = "\U0001f48f\U0001f3fc"
-KISS_MEDIUM_SKIN_TONE = "\U0001f48f\U0001f3fd"
-KISS_MEDIUM_DARK_SKIN_TONE = "\U0001f48f\U0001f3fe"
-KISS_DARK_SKIN_TONE = "\U0001f48f\U0001f3ff"
-COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_MAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE = "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_MAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_MAN_MAN_DARK_SKIN_TONE = "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_WOMAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_MAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f468\U0001f3ff"
-COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fb"
-COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fc"
-COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fd"
-COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3fe"
-COUPLE_WITH_HEART_WOMAN_WOMAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f469\U0001f3ff"
-COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
-COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
-COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
-COUPLE_WITH_HEART_PERSON_PERSON_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
-COUPLE_WITH_HEART_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3ff"
-COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fb"
-COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fc"
-COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fd"
-COUPLE_WITH_HEART_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f9d1\U0001f3fe"
-KISS_MAN_MAN_LIGHT_SKIN_TONE = "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_MAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_MAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_MAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_MAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_MAN_MAN_MEDIUM_SKIN_TONE = "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_MAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_MAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE = "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_MAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_MAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_MAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_MAN_MAN_DARK_SKIN_TONE = "\U0001f468\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_MAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_WOMAN_MAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_WOMAN_MAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE = "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
-KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
-KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
-KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
-KISS_WOMAN_WOMAN_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
-KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_WOMAN_MAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
-KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
-KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
-KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
-KISS_WOMAN_WOMAN_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
-KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_WOMAN_MAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_WOMAN_MAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
-KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
-KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE = "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
-KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
-KISS_WOMAN_WOMAN_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
-KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_WOMAN_MAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
-KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
-KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
-KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
-KISS_WOMAN_WOMAN_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
-KISS_WOMAN_MAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fb"
-KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fc"
-KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fd"
-KISS_WOMAN_MAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3fe"
-KISS_WOMAN_MAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f3ff"
-KISS_WOMAN_WOMAN_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fb"
-KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fc"
-KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fd"
-KISS_WOMAN_WOMAN_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3fe"
-KISS_WOMAN_WOMAN_DARK_SKIN_TONE = "\U0001f469\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f3ff"
-KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
-KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
-KISS_PERSON_PERSON_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
-KISS_PERSON_PERSON_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fb\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
-KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
-KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
-KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
-KISS_PERSON_PERSON_MEDIUM_LIGHT_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fc\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
-KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
-KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
-KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
-KISS_PERSON_PERSON_MEDIUM_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fd\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
-KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
-KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
-KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
-KISS_PERSON_PERSON_MEDIUM_DARK_SKIN_TONE_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3fe\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3ff"
-KISS_PERSON_PERSON_DARK_SKIN_TONE_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fb"
-KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_LIGHT_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fc"
-KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fd"
-KISS_PERSON_PERSON_DARK_SKIN_TONE_MEDIUM_DARK_SKIN_TONE = \
-    "\U0001f9d1\U0001f3ff\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f9d1\U0001f3fe"
-TAG_TILDE = "\U000e007e"
-TAG_PERCENT_SIGN = "\U000e0025"
-ZERO_WIDTH_JOINER = "\u200d"
-TAG_LATIN_SMALL_LETTER_E = "\U000e0065"
-TAG_LATIN_CAPITAL_LETTER_I = "\U000e0049"
-TAG_LATIN_SMALL_LETTER_N = "\U000e006e"
-TAG_LATIN_CAPITAL_LETTER_S = "\U000e0053"
 TAG_RIGHT_CURLY_BRACKET = "\U000e007d"
-TAG_DIGIT_FIVE = "\U000e0035"
-TAG_LATIN_CAPITAL_LETTER_V = "\U000e0056"
-TAG_LATIN_CAPITAL_LETTER_Z = "\U000e005a"
-TAG_LATIN_CAPITAL_LETTER_M = "\U000e004d"
-TAG_LATIN_CAPITAL_LETTER_W = "\U000e0057"
-TAG_LATIN_SMALL_LETTER_D = "\U000e0064"
-TAG_LATIN_CAPITAL_LETTER_F = "\U000e0046"
-TAG_LATIN_SMALL_LETTER_U = "\U000e0075"
-TAG_LATIN_SMALL_LETTER_B = "\U000e0062"
-VARIATION_SELECTOR_16 = "\ufe0f"
+DIGIT_FIVE = "5\ufe0f"
+TAG_LATIN_CAPITAL_LETTER_U = "\U000e0055"
+TAG_LATIN_CAPITAL_LETTER_Q = "\U000e0051"
+TAG_LATIN_CAPITAL_LETTER_K = "\U000e004b"
+COMBINING_ENCLOSING_KEYCAP = "\u20e3"
+TAG_LATIN_CAPITAL_LETTER_C = "\U000e0043"
+TAG_ASTERISK = "\U000e002a"
 TAG_FULL_STOP = "\U000e002e"
-DIGIT_FOUR = "4\ufe0f"
-TAG_LATIN_SMALL_LETTER_F = "\U000e0066"
+TAG_CIRCUMFLEX_ACCENT = "\U000e005e"
 DIGIT_ONE = "1\ufe0f"
-TAG_LATIN_CAPITAL_LETTER_B = "\U000e0042"
-TAG_DIGIT_SEVEN = "\U000e0037"
-TAG_DIGIT_ONE = "\U000e0031"
-TAG_COMMERCIAL_AT = "\U000e0040"
-TAG_LATIN_SMALL_LETTER_Z = "\U000e007a"
-TAG_LATIN_SMALL_LETTER_K = "\U000e006b"
-TAG_LATIN_SMALL_LETTER_V = "\U000e0076"
-TAG_LATIN_CAPITAL_LETTER_C = "\U000e0043"
-TAG_LATIN_SMALL_LETTER_X = "\U000e0078"
-TAG_LATIN_SMALL_LETTER_C = "\U000e0063"
-TAG_SOLIDUS = "\U000e002f"
 TAG_COMMA = "\U000e002c"
-TAG_LATIN_CAPITAL_LETTER_P = "\U000e0050"
-TAG_LATIN_SMALL_LETTER_M = "\U000e006d"
-TAG_LATIN_CAPITAL_LETTER_J = "\U000e004a"
-TAG_LATIN_SMALL_LETTER_P = "\U000e0070"
-TAG_LATIN_SMALL_LETTER_I = "\U000e0069"
-TAG_COLON = "\U000e003a"
-TAG_LATIN_SMALL_LETTER_A = "\U000e0061"
+DIGIT_ZERO = "0\ufe0f"
+TAG_EQUALS_SIGN = "\U000e003d"
+TAG_LATIN_CAPITAL_LETTER_O = "\U000e004f"
+TAG_COMMERCIAL_AT = "\U000e0040"
+DIGIT_EIGHT = "8\ufe0f"
 TAG_NUMBER_SIGN = "\U000e0023"
-TAG_LATIN_CAPITAL_LETTER_X = "\U000e0058"
 TAG_LATIN_CAPITAL_LETTER_T = "\U000e0054"
-NUMBER_SIGN = "#\ufe0f"
+TAG_LATIN_CAPITAL_LETTER_N = "\U000e004e"
+DIGIT_SIX = "6\ufe0f"
+TAG_PERCENT_SIGN = "\U000e0025"
+VARIATION_SELECTOR_16 = "\ufe0f"
+TAG_LATIN_CAPITAL_LETTER_W = "\U000e0057"
 TAG_DOLLAR_SIGN = "\U000e0024"
-TAG_LATIN_CAPITAL_LETTER_Y = "\U000e0059"
-TAG_LATIN_CAPITAL_LETTER_E = "\U000e0045"
-TAG_LATIN_SMALL_LETTER_O = "\U000e006f"
-TAG_DIGIT_FOUR = "\U000e0034"
-TAG_HYPHEN_MINUS = "\U000e002d"
-TAG_RIGHT_PARENTHESIS = "\U000e0029"
-TAG_CIRCUMFLEX_ACCENT = "\U000e005e"
-TAG_LATIN_CAPITAL_LETTER_Q = "\U000e0051"
+TAG_LOW_LINE = "\U000e005f"
+TAG_DIGIT_EIGHT = "\U000e0038"
+TAG_LATIN_CAPITAL_LETTER_M = "\U000e004d"
+TAG_LATIN_CAPITAL_LETTER_A = "\U000e0041"
 TAG_REVERSE_SOLIDUS = "\U000e005c"
-TAG_LATIN_CAPITAL_LETTER_R = "\U000e0052"
-TAG_QUOTATION_MARK = "\U000e0022"
+TAG_SOLIDUS = "\U000e002f"
+TAG_LATIN_CAPITAL_LETTER_H = "\U000e0048"
 TAG_DIGIT_NINE = "\U000e0039"
-CANCEL_TAG = "\U000e007f"
-TAG_ASTERISK = "\U000e002a"
+TAG_LEFT_CURLY_BRACKET = "\U000e007b"
+TAG_LATIN_CAPITAL_LETTER_E = "\U000e0045"
+TAG_LATIN_SMALL_LETTER_W = "\U000e0077"
+TAG_DIGIT_ZERO = "\U000e0030"
+TAG_LATIN_CAPITAL_LETTER_B = "\U000e0042"
+TAG_LATIN_CAPITAL_LETTER_F = "\U000e0046"
+TAG_LATIN_CAPITAL_LETTER_Y = "\U000e0059"
+TAG_TILDE = "\U000e007e"
+TAG_LATIN_SMALL_LETTER_P = "\U000e0070"
+TAG_LATIN_CAPITAL_LETTER_Z = "\U000e005a"
+TAG_GREATER_THAN_SIGN = "\U000e003e"
+TAG_LATIN_SMALL_LETTER_S = "\U000e0073"
+TAG_LATIN_SMALL_LETTER_G = "\U000e0067"
+TAG_APOSTROPHE = "\U000e0027"
+TAG_RIGHT_PARENTHESIS = "\U000e0029"
+TAG_DIGIT_THREE = "\U000e0033"
 TAG_LEFT_PARENTHESIS = "\U000e0028"
+TAG_DIGIT_SEVEN = "\U000e0037"
+TAG_LATIN_SMALL_LETTER_O = "\U000e006f"
+TAG_DIGIT_SIX = "\U000e0036"
+TAG_DIGIT_TWO = "\U000e0032"
+TAG_LATIN_SMALL_LETTER_F = "\U000e0066"
+TAG_LATIN_SMALL_LETTER_K = "\U000e006b"
+TAG_LATIN_SMALL_LETTER_Y = "\U000e0079"
+TAG_SPACE = "\U000e0020"
+TAG_LATIN_SMALL_LETTER_I = "\U000e0069"
+DIGIT_TWO = "2\ufe0f"
+TAG_DIGIT_ONE = "\U000e0031"
 TAG_RIGHT_SQUARE_BRACKET = "\U000e005d"
-DIGIT_SIX = "6\ufe0f"
-DIGIT_FIVE = "5\ufe0f"
+TAG_LATIN_SMALL_LETTER_R = "\U000e0072"
+HASH_SIGN = "#\ufe0f"
+TAG_SEMICOLON = "\U000e003b"
+TAG_LATIN_CAPITAL_LETTER_L = "\U000e004c"
+TAG_HYPHEN_MINUS = "\U000e002d"
 ASTERISK = "*\ufe0f"
+TAG_LATIN_SMALL_LETTER_A = "\U000e0061"
+TAG_EXCLAMATION_MARK = "\U000e0021"
+TAG_LATIN_CAPITAL_LETTER_V = "\U000e0056"
+TAG_LATIN_SMALL_LETTER_C = "\U000e0063"
+TAG_GRAVE_ACCENT = "\U000e0060"
+ZERO_WIDTH_JOINER = "\u200d"
 TAG_LATIN_CAPITAL_LETTER_G = "\U000e0047"
-DIGIT_ZERO = "0\ufe0f"
+DIGIT_NINE = "9\ufe0f"
 TAG_VERTICAL_LINE = "\U000e007c"
-TAG_PLUS_SIGN = "\U000e002b"
-TAG_LEFT_SQUARE_BRACKET = "\U000e005b"
-TAG_DIGIT_EIGHT = "\U000e0038"
-TAG_SPACE = "\U000e0020"
+TAG_LATIN_SMALL_LETTER_Z = "\U000e007a"
+TAG_LATIN_CAPITAL_LETTER_X = "\U000e0058"
 TAG_LATIN_SMALL_LETTER_J = "\U000e006a"
-TAG_LATIN_CAPITAL_LETTER_H = "\U000e0048"
-DIGIT_THREE = "3\ufe0f"
-TAG_LATIN_CAPITAL_LETTER_L = "\U000e004c"
-TAG_LATIN_CAPITAL_LETTER_D = "\U000e0044"
-TAG_LATIN_CAPITAL_LETTER_U = "\U000e0055"
-TAG_LESS_THAN_SIGN = "\U000e003c"
-TAG_EXCLAMATION_MARK = "\U000e0021"
-TAG_APOSTROPHE = "\U000e0027"
-TAG_GREATER_THAN_SIGN = "\U000e003e"
-TAG_LATIN_SMALL_LETTER_T = "\U000e0074"
-DIGIT_NINE = "9\ufe0f"
-TAG_LATIN_SMALL_LETTER_S = "\U000e0073"
-TAG_LATIN_SMALL_LETTER_Q = "\U000e0071"
-DIGIT_TWO = "2\ufe0f"
+TAG_LATIN_CAPITAL_LETTER_P = "\U000e0050"
 TAG_AMPERSAND = "\U000e0026"
-COMBINING_ENCLOSING_KEYCAP = "\u20e3"
-TAG_LATIN_SMALL_LETTER_H = "\U000e0068"
-TAG_LATIN_SMALL_LETTER_R = "\U000e0072"
-TAG_SEMICOLON = "\U000e003b"
-TAG_LATIN_CAPITAL_LETTER_O = "\U000e004f"
-TAG_LOW_LINE = "\U000e005f"
+TAG_LATIN_SMALL_LETTER_L = "\U000e006c"
+TAG_LATIN_SMALL_LETTER_X = "\U000e0078"
 DIGIT_SEVEN = "7\ufe0f"
-TAG_GRAVE_ACCENT = "\U000e0060"
-TAG_LATIN_SMALL_LETTER_W = "\U000e0077"
-TAG_EQUALS_SIGN = "\U000e003d"
-TAG_LATIN_SMALL_LETTER_G = "\U000e0067"
-TAG_LATIN_CAPITAL_LETTER_A = "\U000e0041"
-TAG_DIGIT_THREE = "\U000e0033"
-TAG_LEFT_CURLY_BRACKET = "\U000e007b"
+TAG_LATIN_CAPITAL_LETTER_J = "\U000e004a"
+TAG_LATIN_SMALL_LETTER_T = "\U000e0074"
 TAG_QUESTION_MARK = "\U000e003f"
-TAG_LATIN_SMALL_LETTER_L = "\U000e006c"
-TAG_DIGIT_SIX = "\U000e0036"
-TAG_LATIN_CAPITAL_LETTER_N = "\U000e004e"
-TAG_DIGIT_TWO = "\U000e0032"
-TAG_LATIN_CAPITAL_LETTER_K = "\U000e004b"
-TAG_DIGIT_ZERO = "\U000e0030"
-DIGIT_EIGHT = "8\ufe0f"
-TAG_LATIN_SMALL_LETTER_Y = "\U000e0079"
+TAG_LATIN_SMALL_LETTER_B = "\U000e0062"
+TAG_LEFT_SQUARE_BRACKET = "\U000e005b"
+TAG_LATIN_SMALL_LETTER_D = "\U000e0064"
+TAG_LATIN_SMALL_LETTER_E = "\U000e0065"
+TAG_LATIN_SMALL_LETTER_M = "\U000e006d"
+TAG_LESS_THAN_SIGN = "\U000e003c"
+TAG_DIGIT_FIVE = "\U000e0035"
+TAG_LATIN_CAPITAL_LETTER_D = "\U000e0044"
+TAG_LATIN_SMALL_LETTER_N = "\U000e006e"
+TAG_PLUS_SIGN = "\U000e002b"
+TAG_COLON = "\U000e003a"
+DIGIT_THREE = "3\ufe0f"
+TAG_LATIN_SMALL_LETTER_Q = "\U000e0071"
+TAG_LATIN_CAPITAL_LETTER_R = "\U000e0052"
+TAG_LATIN_CAPITAL_LETTER_S = "\U000e0053"
+DIGIT_FOUR = "4\ufe0f"
+TAG_LATIN_CAPITAL_LETTER_I = "\U000e0049"
+TAG_QUOTATION_MARK = "\U000e0022"
+CANCEL_TAG = "\U000e007f"
+TAG_LATIN_SMALL_LETTER_V = "\U000e0076"
+TAG_LATIN_SMALL_LETTER_H = "\U000e0068"
+TAG_LATIN_SMALL_LETTER_U = "\U000e0075"
+TAG_DIGIT_FOUR = "\U000e0034"

From aaaa97c77af397c462f1452ea2ec57ee1e84c412 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 31 Jan 2022 21:28:51 +0100
Subject: [PATCH 072/539] Document ApiCallError RPC error

---
 compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv b/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
index 72b79cb565..eaa426a814 100644
--- a/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
+++ b/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
@@ -1,2 +1,3 @@
 id	message
-Timeout	Telegram is having internal problems. Please try again later.
\ No newline at end of file
+Timeout	Telegram is having internal problems. Please try again later.
+ApiCallError	Telegram is having internal problems. Please try again later.
\ No newline at end of file

From b9424c745558b7e771a738ba4fd3de9cb3ed2cf7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 1 Feb 2022 11:01:02 +0100
Subject: [PATCH 073/539] Add ChatJoinRequest bound methods docs

---
 compiler/docs/compiler.py                |  5 +++++
 compiler/docs/template/bound-methods.rst | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index cb4de0a6b5..c1a4588603 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -544,6 +544,11 @@ def get_title_list(s: str) -> list:
         inline_query="""
         InlineQuery
             InlineQuery.answer
+        """,
+        chat_join_request="""
+        ChatJoinRequest
+            ChatJoinRequest.approve
+            ChatJoinRequest.decline
         """
     )
 
diff --git a/compiler/docs/template/bound-methods.rst b/compiler/docs/template/bound-methods.rst
index ebaa2ab899..33261d42b2 100644
--- a/compiler/docs/template/bound-methods.rst
+++ b/compiler/docs/template/bound-methods.rst
@@ -91,3 +91,17 @@ InlineQuery
     :hidden:
 
     {inline_query_toctree}
+
+ChatJoinRequest
+---------------
+
+.. hlist::
+    :columns: 2
+
+    {chat_join_request_hlist}
+
+.. toctree::
+    :hidden:
+
+    {chat_join_request_toctree}
+

From b676297ca921c8608fc44d350b2a5abf0da6b1ef Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 1 Feb 2022 11:36:46 +0100
Subject: [PATCH 074/539] Update API schema to Layer 138

---
 compiler/api/source/main_api.tl | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 824fab45d1..9d5d811bfb 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -168,7 +168,7 @@ messageActionGroupCallScheduled#b3a07661 call:InputGroupCall schedule_date:int =
 messageActionSetChatTheme#aa786345 emoticon:string = MessageAction;
 messageActionChatJoinedByRequest#ebbca3cb = MessageAction;
 
-dialog#2c171f72 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 folder_id:flags.4?int = Dialog;
+dialog#a8edd0f5 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
 dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
 
 photoEmpty#2331b22d id:long = Photo;
@@ -544,7 +544,7 @@ inputStickerSetAnimatedEmoji#28703c8 = InputStickerSet;
 inputStickerSetDice#e67f520e emoticon:string = InputStickerSet;
 inputStickerSetAnimatedEmojiAnimations#cde3739 = InputStickerSet;
 
-stickerSet#d7df217a flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int count:int hash:int = StickerSet;
+stickerSet#d7df217a flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true gifs:flags.6?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int count:int hash:int = StickerSet;
 
 messages.stickerSet#b60a24a6 set:StickerSet packs:Vector documents:Vector = messages.StickerSet;
 messages.stickerSetNotModified#d3f924eb = messages.StickerSet;
@@ -1285,17 +1285,20 @@ auth.loggedOut#c3a2835f flags:# future_auth_token:flags.0?bytes = auth.LoggedOut
 
 reactionCount#6fb250d1 flags:# chosen:flags.0?true reaction:string count:int = ReactionCount;
 
-messageReactions#87b6e36 flags:# min:flags.0?true can_see_list:flags.2?true results:Vector recent_reactons:flags.1?Vector = MessageReactions;
+messageReactions#4f2b9479 flags:# min:flags.0?true can_see_list:flags.2?true results:Vector recent_reactions:flags.1?Vector = MessageReactions;
 
-messageUserReaction#932844fa user_id:long reaction:string = MessageUserReaction;
-
-messages.messageReactionsList#a366923c flags:# count:int reactions:Vector users:Vector next_offset:flags.0?string = messages.MessageReactionsList;
+messages.messageReactionsList#31bd492d flags:# count:int reactions:Vector chats:Vector users:Vector next_offset:flags.0?string = messages.MessageReactionsList;
 
 availableReaction#c077ec01 flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction;
 
 messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions;
 messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions;
 
+messages.translateNoResult#67ca4737 = messages.TranslatedText;
+messages.translateResultText#a214f7d0 text:string = messages.TranslatedText;
+
+messagePeerReaction#51b67eff flags:# big:flags.0?true unread:flags.1?true peer_id:Peer reaction:string = MessagePeerReaction;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1574,12 +1577,15 @@ messages.hideChatJoinRequest#7fe7e815 flags:# approved:flags.0?true peer:InputPe
 messages.hideAllChatJoinRequests#e085f4ea flags:# approved:flags.0?true peer:InputPeer link:flags.1?string = Updates;
 messages.toggleNoForwards#b11eafa2 peer:InputPeer enabled:Bool = Updates;
 messages.saveDefaultSendAs#ccfddf96 peer:InputPeer send_as:InputPeer = Bool;
-messages.sendReaction#25690ce4 flags:# peer:InputPeer msg_id:int reaction:flags.0?string = Updates;
+messages.sendReaction#25690ce4 flags:# big:flags.1?true peer:InputPeer msg_id:int reaction:flags.0?string = Updates;
 messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector = Updates;
 messages.getMessageReactionsList#e0ee6b77 flags:# peer:InputPeer id:int reaction:flags.0?string offset:flags.1?string limit:int = messages.MessageReactionsList;
 messages.setChatAvailableReactions#14050ea6 peer:InputPeer available_reactions:Vector = Updates;
 messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions;
 messages.setDefaultReaction#d960c4d4 reaction:string = Bool;
+messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?int text:flags.1?string from_lang:flags.2?string to_lang:string = messages.TranslatedText;
+messages.getUnreadReactions#e85bae1a peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
+messages.readReactions#82e251d7 peer:InputPeer = messages.AffectedHistory;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1728,4 +1734,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 137
\ No newline at end of file
+// LAYER 138
\ No newline at end of file

From 05bfaa3d876d7a8486d7598cd7dc8c674e6c267e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 1 Feb 2022 11:38:58 +0100
Subject: [PATCH 075/539] Add support for video stickers Add Sticker.is_video
 attribute

---
 pyrogram/types/messages_and_media/message.py | 16 ++++++++--------
 pyrogram/types/messages_and_media/sticker.py |  6 ++++++
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 02bf2d3d98..1f6e432a16 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -674,6 +674,14 @@ async def _parse(
                             video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
                             animation = types.Animation._parse(client, doc, video_attributes, file_name)
                             media_type = "animation"
+                        elif raw.types.DocumentAttributeSticker in attributes:
+                            sticker = await types.Sticker._parse(
+                                client, doc,
+                                attributes.get(raw.types.DocumentAttributeImageSize, None),
+                                attributes[raw.types.DocumentAttributeSticker],
+                                file_name
+                            )
+                            media_type = "sticker"
                         elif raw.types.DocumentAttributeVideo in attributes:
                             video_attributes = attributes[raw.types.DocumentAttributeVideo]
 
@@ -683,14 +691,6 @@ async def _parse(
                             else:
                                 video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
                                 media_type = "video"
-                        elif raw.types.DocumentAttributeSticker in attributes:
-                            sticker = await types.Sticker._parse(
-                                client, doc,
-                                attributes.get(raw.types.DocumentAttributeImageSize, None),
-                                attributes[raw.types.DocumentAttributeSticker],
-                                file_name
-                            )
-                            media_type = "sticker"
                         else:
                             document = types.Document._parse(client, doc, file_name)
                             media_type = "document"
diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py
index be494e3078..bd08792ff0 100644
--- a/pyrogram/types/messages_and_media/sticker.py
+++ b/pyrogram/types/messages_and_media/sticker.py
@@ -46,6 +46,9 @@ class Sticker(Object):
         is_animated (``bool``):
             True, if the sticker is animated
 
+        is_video (``bool``):
+            True, if the sticker is a video sticker
+
         file_name (``str``, *optional*):
             Sticker file name.
 
@@ -79,6 +82,7 @@ def __init__(
         width: int,
         height: int,
         is_animated: bool,
+        is_video: bool,
         file_name: str = None,
         mime_type: str = None,
         file_size: int = None,
@@ -98,6 +102,7 @@ def __init__(
         self.width = width
         self.height = height
         self.is_animated = is_animated
+        self.is_video = is_video
         self.emoji = emoji
         self.set_name = set_name
         self.thumbs = thumbs
@@ -167,6 +172,7 @@ async def _parse(
             width=image_size_attributes.w if image_size_attributes else 512,
             height=image_size_attributes.h if image_size_attributes else 512,
             is_animated=sticker.mime_type == "application/x-tgsticker",
+            is_video=sticker.mime_type == "video/webm",
             # TODO: mask_position
             set_name=set_name,
             emoji=sticker_attributes.alt or None,

From 855e69e3f881c8140781c1d5e42e3098b2134dd2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 1 Feb 2022 12:07:30 +0100
Subject: [PATCH 076/539] Update Pyrogram to v1.4.0

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 81670ac9b2..2b551c08ae 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.3.7"
+__version__ = "1.4.0"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From b3f849df762df799b43dcde109ef6516a1a50281 Mon Sep 17 00:00:00 2001
From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com>
Date: Thu, 3 Feb 2022 15:26:17 +0100
Subject: [PATCH 077/539] Fix entities unparsing in other scenarios (#892)

---
 pyrogram/parser/html.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index 81c761ac94..b1ce5c5d46 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -174,8 +174,17 @@ def unparse(text: str, entities: list):
 
             entities_offsets.append((start_tag, start,))
             entities_offsets.append((end_tag, end,))
-
-        for entity, offset in reversed(entities_offsets):
+            
+        entities_offsets = map(
+            lambda x: x[1],
+            sorted(
+                enumerate(entities_offsets),
+                key = lambda x: (x[1][1], x[0]),
+                reverse = True
+            )
+        )
+
+        for entity, offset in entities_offsets:
             text = text[:offset] + entity + text[offset:]
 
         return utils.remove_surrogates(text)

From 89c49111b0edc1ca7c586b19d10700f115ffaf6a Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 3 Feb 2022 15:27:15 +0100
Subject: [PATCH 078/539] Update Pyrogram to v1.4.1

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 2b551c08ae..d9b7d0e7d7 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.0"
+__version__ = "1.4.1"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 462e5d11a5df5c3114be06015bb0f9369e239b84 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 01:05:36 +0100
Subject: [PATCH 079/539] Improve stability in case of connection failures

---
 pyrogram/connection/connection.py        | 26 +++++++-----
 pyrogram/connection/transport/tcp/tcp.py |  2 +-
 pyrogram/session/session.py              | 53 ++++++++++--------------
 3 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 2173c70b94..62e68751eb 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -37,7 +37,7 @@ class Connection:
         4: TCPIntermediateO
     }
 
-    def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3):
+    def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 1):
         self.dc_id = dc_id
         self.test_mode = test_mode
         self.ipv6 = ipv6
@@ -47,6 +47,7 @@ def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media:
         self.mode = self.MODES.get(mode, TCPAbridged)
 
         self.protocol = None  # type: TCP
+        self.is_connected = asyncio.Event()
 
     async def connect(self):
         for i in range(Connection.MAX_RETRIES):
@@ -56,8 +57,8 @@ async def connect(self):
                 log.info("Connecting...")
                 await self.protocol.connect(self.address)
             except OSError as e:
-                log.warning(f"Unable to connect due to network issues: {e}")
-                self.protocol.close()
+                log.warning(f"Connection failed due to network issues: {e}")
+                await self.protocol.close()
                 await asyncio.sleep(1)
             else:
                 log.info("Connected! {} DC{}{} - IPv{} - {}".format(
@@ -69,18 +70,23 @@ async def connect(self):
                 ))
                 break
         else:
-            log.warning("Connection failed! Trying again...")
+            log.warning("Couldn't connect. Trying again...")
             raise TimeoutError
 
-    def close(self):
-        self.protocol.close()
+        self.is_connected.set()
+
+    async def close(self):
+        await self.protocol.close()
+        self.is_connected.clear()
         log.info("Disconnected")
 
+    async def reconnect(self):
+        await self.close()
+        await self.connect()
+
     async def send(self, data: bytes):
-        try:
-            await self.protocol.send(data)
-        except Exception:
-            raise OSError
+        await self.is_connected.wait()
+        await self.protocol.send(data)
 
     async def recv(self) -> Optional[bytes]:
         return await self.protocol.recv()
diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py
index 0b858c0265..386ca32997 100644
--- a/pyrogram/connection/transport/tcp/tcp.py
+++ b/pyrogram/connection/transport/tcp/tcp.py
@@ -82,7 +82,7 @@ async def connect(self, address: tuple):
         self.socket.connect(address)
         self.reader, self.writer = await asyncio.open_connection(sock=self.socket)
 
-    def close(self):
+    async def close(self):
         try:
             self.writer.close()
         except AttributeError:
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 05d1fd4a3f..7ee5d6baff 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -83,7 +83,6 @@ def __init__(
         self.stored_msg_ids = []
 
         self.ping_task = None
-        self.ping_task_event = asyncio.Event()
 
         self.network_task = None
 
@@ -150,17 +149,23 @@ async def start(self):
     async def stop(self):
         self.is_connected.clear()
 
-        self.ping_task_event.set()
+        if self.ping_task:
+            self.ping_task.cancel()
 
-        if self.ping_task is not None:
-            await self.ping_task
+            try:
+                await self.ping_task
+            except asyncio.CancelledError:
+                pass
 
-        self.ping_task_event.clear()
+        if self.network_task:
+            self.network_task.cancel()
 
-        self.connection.close()
+            try:
+                await self.network_task
+            except asyncio.CancelledError:
+                pass
 
-        if self.network_task:
-            await self.network_task
+        await self.connection.close()
 
         for i in self.results.values():
             i.event.set()
@@ -189,7 +194,7 @@ async def handle_packet(self, packet):
                 self.stored_msg_ids
             )
         except SecurityCheckMismatch:
-            self.connection.close()
+            await self.connection.close()
             return
 
         messages = (
@@ -247,46 +252,32 @@ async def handle_packet(self, packet):
                 self.pending_acks.clear()
 
     async def ping_worker(self):
-        log.info("PingTask started")
-
         while True:
-            try:
-                await asyncio.wait_for(self.ping_task_event.wait(), self.PING_INTERVAL)
-            except asyncio.TimeoutError:
-                pass
-            else:
-                break
-
             try:
                 await self._send(
                     raw.functions.PingDelayDisconnect(
-                        ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10
+                        ping_id=0,
+                        disconnect_delay=self.WAIT_TIMEOUT + 10
                     ), False
                 )
             except (OSError, TimeoutError, RPCError):
                 pass
 
-        log.info("PingTask stopped")
+            await asyncio.sleep(self.PING_INTERVAL)
 
     async def network_worker(self):
-        log.info("NetworkTask started")
-
         while True:
             packet = await self.connection.recv()
 
-            if packet is None or len(packet) == 4:
-                if packet:
-                    log.warning(f'Server sent "{Int.read(BytesIO(packet))}"')
-
-                if self.is_connected.is_set():
-                    self.loop.create_task(self.restart())
+            if not packet:
+                await self.connection.reconnect()
+                continue
 
-                break
+            if len(packet) == 4:
+                log.warning(f'Server sent "{Int.read(BytesIO(packet))}"')
 
             self.loop.create_task(self.handle_packet(packet))
 
-        log.info("NetworkTask stopped")
-
     async def _send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT):
         message = self.msg_factory(data)
         msg_id = message.msg_id

From 921d87304f1582d4de341ca8b1259595c0ab8ef9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 01:08:11 +0100
Subject: [PATCH 080/539] Do not consume async gens, turn them to gens instead

---
 pyrogram/sync.py | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/pyrogram/sync.py b/pyrogram/sync.py
index 6db937b3a7..a3e0d2b545 100644
--- a/pyrogram/sync.py
+++ b/pyrogram/sync.py
@@ -30,8 +30,23 @@ def async_to_sync(obj, name):
     function = getattr(obj, name)
     main_loop = asyncio.get_event_loop()
 
-    async def consume_generator(coroutine):
-        return types.List([i async for i in coroutine])
+    def async_to_sync_gen(agen, loop, is_main_thread):
+        async def anext(agen):
+            try:
+                return await agen.__anext__(), False
+            except StopAsyncIteration:
+                return None, True
+
+        while True:
+            if is_main_thread:
+                item, done = loop.run_until_complete(anext(agen))
+            else:
+                item, done = asyncio.run_coroutine_threadsafe(anext(agen), loop).result()
+
+            if done:
+                break
+
+            yield item
 
     @functools.wraps(function)
     def async_to_sync_wrap(*args, **kwargs):
@@ -51,7 +66,7 @@ def async_to_sync_wrap(*args, **kwargs):
                     return loop.run_until_complete(coroutine)
 
                 if inspect.isasyncgen(coroutine):
-                    return loop.run_until_complete(consume_generator(coroutine))
+                    return async_to_sync_gen(coroutine, loop, True)
         else:
             if inspect.iscoroutine(coroutine):
                 if loop.is_running():
@@ -66,7 +81,7 @@ async def coro_wrapper():
                 if loop.is_running():
                     return coroutine
                 else:
-                    return asyncio.run_coroutine_threadsafe(consume_generator(coroutine), main_loop).result()
+                    return async_to_sync_gen(coroutine, main_loop, False)
 
     setattr(obj, name, async_to_sync_wrap)
 

From 7fbb4d8997a28d804371833d92e2dcf4bac0ea41 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 01:09:06 +0100
Subject: [PATCH 081/539] Update Pyrogram to v1.4.2

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index d9b7d0e7d7..a828ae2a6a 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.1"
+__version__ = "1.4.2"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 5d155b896c8cfb10728cb9eff935973281460e36 Mon Sep 17 00:00:00 2001
From: Stark Programmer <88478059+StarkBotsIndustries@users.noreply.github.com>
Date: Thu, 10 Feb 2022 06:52:43 +0530
Subject: [PATCH 082/539] Add missing await keyword (#898)

---
 pyrogram/session/auth.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py
index d4083b2179..f33ffba935 100644
--- a/pyrogram/session/auth.py
+++ b/pyrogram/session/auth.py
@@ -258,4 +258,4 @@ async def create(self):
             else:
                 return auth_key
             finally:
-                self.connection.close()
+                await self.connection.close()

From 2c1d3ee2a4385f9bca18ea0876828678bb91c8e4 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 02:23:36 +0100
Subject: [PATCH 083/539] Update Pyrogram to v1.4.3

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index a828ae2a6a..d015fb215d 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.2"
+__version__ = "1.4.3"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 03629d5ee9f4e90bee26b91811594615476c55eb Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 04:25:36 +0100
Subject: [PATCH 084/539] Always try to reconnect within Connection

---
 pyrogram/connection/connection.py | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 62e68751eb..04578b0ee6 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -27,8 +27,6 @@
 
 
 class Connection:
-    MAX_RETRIES = 3
-
     MODES = {
         0: TCPFull,
         1: TCPAbridged,
@@ -50,7 +48,7 @@ def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media:
         self.is_connected = asyncio.Event()
 
     async def connect(self):
-        for i in range(Connection.MAX_RETRIES):
+        while True:
             self.protocol = self.mode(self.ipv6, self.proxy)
 
             try:
@@ -69,9 +67,6 @@ async def connect(self):
                     self.mode.__name__,
                 ))
                 break
-        else:
-            log.warning("Couldn't connect. Trying again...")
-            raise TimeoutError
 
         self.is_connected.set()
 

From f23422cb25e382be0c2e8dcce20a11637494f5ea Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 04:25:54 +0100
Subject: [PATCH 085/539] Update Pyrogram to v1.4.4

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index d015fb215d..49d8d34130 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.3"
+__version__ = "1.4.4"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 5889c67fb51b61fcc20549840d1f1c099b3a58ac Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 05:34:21 +0100
Subject: [PATCH 086/539] Initialize session on reconnection

---
 pyrogram/session/session.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 7ee5d6baff..89171ed4a1 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -271,6 +271,27 @@ async def network_worker(self):
 
             if not packet:
                 await self.connection.reconnect()
+
+                try:
+                    await self._send(
+                        raw.functions.InvokeWithLayer(
+                            layer=layer,
+                            query=raw.functions.InitConnection(
+                                api_id=self.client.api_id,
+                                app_version=self.client.app_version,
+                                device_model=self.client.device_model,
+                                system_version=self.client.system_version,
+                                system_lang_code=self.client.lang_code,
+                                lang_code=self.client.lang_code,
+                                lang_pack="",
+                                query=raw.functions.help.GetConfig(),
+                            )
+                        ),
+                        wait_response=False
+                    )
+                except (OSError, TimeoutError, RPCError):
+                    pass
+
                 continue
 
             if len(packet) == 4:

From 0d112407400040a90e72dc8325eccd832174d8ea Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 05:34:40 +0100
Subject: [PATCH 087/539] Update Pyrogram to v.1.4.5

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 49d8d34130..3396e56a4f 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.4"
+__version__ = "1.4.5"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From dc6c816c80934a4f3e4953e7faca327b2585ac55 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 06:44:42 +0100
Subject: [PATCH 088/539] Revert some of the last changes

---
 pyrogram/connection/connection.py        | 31 +++++-----
 pyrogram/connection/transport/tcp/tcp.py |  2 +-
 pyrogram/session/auth.py                 |  2 +-
 pyrogram/session/session.py              | 72 ++++++++++--------------
 4 files changed, 47 insertions(+), 60 deletions(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 04578b0ee6..2173c70b94 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -27,6 +27,8 @@
 
 
 class Connection:
+    MAX_RETRIES = 3
+
     MODES = {
         0: TCPFull,
         1: TCPAbridged,
@@ -35,7 +37,7 @@ class Connection:
         4: TCPIntermediateO
     }
 
-    def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 1):
+    def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3):
         self.dc_id = dc_id
         self.test_mode = test_mode
         self.ipv6 = ipv6
@@ -45,18 +47,17 @@ def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media:
         self.mode = self.MODES.get(mode, TCPAbridged)
 
         self.protocol = None  # type: TCP
-        self.is_connected = asyncio.Event()
 
     async def connect(self):
-        while True:
+        for i in range(Connection.MAX_RETRIES):
             self.protocol = self.mode(self.ipv6, self.proxy)
 
             try:
                 log.info("Connecting...")
                 await self.protocol.connect(self.address)
             except OSError as e:
-                log.warning(f"Connection failed due to network issues: {e}")
-                await self.protocol.close()
+                log.warning(f"Unable to connect due to network issues: {e}")
+                self.protocol.close()
                 await asyncio.sleep(1)
             else:
                 log.info("Connected! {} DC{}{} - IPv{} - {}".format(
@@ -67,21 +68,19 @@ async def connect(self):
                     self.mode.__name__,
                 ))
                 break
+        else:
+            log.warning("Connection failed! Trying again...")
+            raise TimeoutError
 
-        self.is_connected.set()
-
-    async def close(self):
-        await self.protocol.close()
-        self.is_connected.clear()
+    def close(self):
+        self.protocol.close()
         log.info("Disconnected")
 
-    async def reconnect(self):
-        await self.close()
-        await self.connect()
-
     async def send(self, data: bytes):
-        await self.is_connected.wait()
-        await self.protocol.send(data)
+        try:
+            await self.protocol.send(data)
+        except Exception:
+            raise OSError
 
     async def recv(self) -> Optional[bytes]:
         return await self.protocol.recv()
diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py
index 386ca32997..0b858c0265 100644
--- a/pyrogram/connection/transport/tcp/tcp.py
+++ b/pyrogram/connection/transport/tcp/tcp.py
@@ -82,7 +82,7 @@ async def connect(self, address: tuple):
         self.socket.connect(address)
         self.reader, self.writer = await asyncio.open_connection(sock=self.socket)
 
-    async def close(self):
+    def close(self):
         try:
             self.writer.close()
         except AttributeError:
diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py
index f33ffba935..d4083b2179 100644
--- a/pyrogram/session/auth.py
+++ b/pyrogram/session/auth.py
@@ -258,4 +258,4 @@ async def create(self):
             else:
                 return auth_key
             finally:
-                await self.connection.close()
+                self.connection.close()
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 89171ed4a1..05d1fd4a3f 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -83,6 +83,7 @@ def __init__(
         self.stored_msg_ids = []
 
         self.ping_task = None
+        self.ping_task_event = asyncio.Event()
 
         self.network_task = None
 
@@ -149,23 +150,17 @@ async def start(self):
     async def stop(self):
         self.is_connected.clear()
 
-        if self.ping_task:
-            self.ping_task.cancel()
+        self.ping_task_event.set()
 
-            try:
-                await self.ping_task
-            except asyncio.CancelledError:
-                pass
+        if self.ping_task is not None:
+            await self.ping_task
 
-        if self.network_task:
-            self.network_task.cancel()
+        self.ping_task_event.clear()
 
-            try:
-                await self.network_task
-            except asyncio.CancelledError:
-                pass
+        self.connection.close()
 
-        await self.connection.close()
+        if self.network_task:
+            await self.network_task
 
         for i in self.results.values():
             i.event.set()
@@ -194,7 +189,7 @@ async def handle_packet(self, packet):
                 self.stored_msg_ids
             )
         except SecurityCheckMismatch:
-            await self.connection.close()
+            self.connection.close()
             return
 
         messages = (
@@ -252,53 +247,46 @@ async def handle_packet(self, packet):
                 self.pending_acks.clear()
 
     async def ping_worker(self):
+        log.info("PingTask started")
+
         while True:
+            try:
+                await asyncio.wait_for(self.ping_task_event.wait(), self.PING_INTERVAL)
+            except asyncio.TimeoutError:
+                pass
+            else:
+                break
+
             try:
                 await self._send(
                     raw.functions.PingDelayDisconnect(
-                        ping_id=0,
-                        disconnect_delay=self.WAIT_TIMEOUT + 10
+                        ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10
                     ), False
                 )
             except (OSError, TimeoutError, RPCError):
                 pass
 
-            await asyncio.sleep(self.PING_INTERVAL)
+        log.info("PingTask stopped")
 
     async def network_worker(self):
+        log.info("NetworkTask started")
+
         while True:
             packet = await self.connection.recv()
 
-            if not packet:
-                await self.connection.reconnect()
+            if packet is None or len(packet) == 4:
+                if packet:
+                    log.warning(f'Server sent "{Int.read(BytesIO(packet))}"')
 
-                try:
-                    await self._send(
-                        raw.functions.InvokeWithLayer(
-                            layer=layer,
-                            query=raw.functions.InitConnection(
-                                api_id=self.client.api_id,
-                                app_version=self.client.app_version,
-                                device_model=self.client.device_model,
-                                system_version=self.client.system_version,
-                                system_lang_code=self.client.lang_code,
-                                lang_code=self.client.lang_code,
-                                lang_pack="",
-                                query=raw.functions.help.GetConfig(),
-                            )
-                        ),
-                        wait_response=False
-                    )
-                except (OSError, TimeoutError, RPCError):
-                    pass
+                if self.is_connected.is_set():
+                    self.loop.create_task(self.restart())
 
-                continue
-
-            if len(packet) == 4:
-                log.warning(f'Server sent "{Int.read(BytesIO(packet))}"')
+                break
 
             self.loop.create_task(self.handle_packet(packet))
 
+        log.info("NetworkTask stopped")
+
     async def _send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT):
         message = self.msg_factory(data)
         msg_id = message.msg_id

From ed2db45a03dc9a2391fee8f40e9ff059c109c291 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 06:45:59 +0100
Subject: [PATCH 089/539] Make Connection.send() raise the actual exception

---
 pyrogram/connection/connection.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 2173c70b94..e90ff9c41b 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -77,10 +77,7 @@ def close(self):
         log.info("Disconnected")
 
     async def send(self, data: bytes):
-        try:
-            await self.protocol.send(data)
-        except Exception:
-            raise OSError
+        await self.protocol.send(data)
 
     async def recv(self) -> Optional[bytes]:
         return await self.protocol.recv()

From 22f2b1dd99fd163f44697bfd2ebe269772f5e960 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 06:46:28 +0100
Subject: [PATCH 090/539] Update Pyrogram to v1.4.6

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 3396e56a4f..52d4614954 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.5"
+__version__ = "1.4.6"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 84b0e15e2b06a9dac2b7f8755e1f7ac896bc9ee1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 20:14:09 +0100
Subject: [PATCH 091/539] Revert "Make Connection.send() raise the actual
 exception"

This reverts commit ed2db45a03dc9a2391fee8f40e9ff059c109c291.
---
 pyrogram/connection/connection.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index e90ff9c41b..2173c70b94 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -77,7 +77,10 @@ def close(self):
         log.info("Disconnected")
 
     async def send(self, data: bytes):
-        await self.protocol.send(data)
+        try:
+            await self.protocol.send(data)
+        except Exception:
+            raise OSError
 
     async def recv(self) -> Optional[bytes]:
         return await self.protocol.recv()

From 9279b67319b8d39898212d53d6b725a92e963fff Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 20:15:48 +0100
Subject: [PATCH 092/539] Display a more meaningful error message

---
 pyrogram/connection/connection.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py
index 2173c70b94..618c92a510 100644
--- a/pyrogram/connection/connection.py
+++ b/pyrogram/connection/connection.py
@@ -79,8 +79,8 @@ def close(self):
     async def send(self, data: bytes):
         try:
             await self.protocol.send(data)
-        except Exception:
-            raise OSError
+        except Exception as e:
+            raise OSError(e)
 
     async def recv(self) -> Optional[bytes]:
         return await self.protocol.recv()

From 7edfda7f417c661344eac11e7a09613cc882afcf Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 10 Feb 2022 20:16:34 +0100
Subject: [PATCH 093/539] Update Pyrogram to v1.4.7

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 52d4614954..304ce76d3c 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.6"
+__version__ = "1.4.7"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 325569d73f0f012c755ddeb7f0a72145384e998a Mon Sep 17 00:00:00 2001
From: Nik <31286021+nikisalli@users.noreply.github.com>
Date: Sun, 13 Feb 2022 11:32:34 +0100
Subject: [PATCH 094/539] Fix custom List __repr__ (#901)

---
 pyrogram/raw/core/list.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/raw/core/list.py b/pyrogram/raw/core/list.py
index 780fd92c3e..a7bbc16b2e 100644
--- a/pyrogram/raw/core/list.py
+++ b/pyrogram/raw/core/list.py
@@ -23,4 +23,4 @@
 
 class List(TList[Any], TLObject):
     def __repr__(self) -> str:
-        return f"pyrogram.api.core.List([{','.join(TLObject.__repr__(i) for i in self)}])"
+        return f"pyrogram.raw.core.List([{','.join(TLObject.__repr__(i) for i in self)}])"

From d9d7a867b5f6af4c2a4630524b96917825a7f618 Mon Sep 17 00:00:00 2001
From: Gor <47748749+ke1io@users.noreply.github.com>
Date: Sun, 13 Feb 2022 14:37:14 +0400
Subject: [PATCH 095/539] Add 406 CHANNEL_PRIVATE error (#899)

---
 compiler/errors/source/406_NOT_ACCEPTABLE.tsv | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler/errors/source/406_NOT_ACCEPTABLE.tsv b/compiler/errors/source/406_NOT_ACCEPTABLE.tsv
index c1c5b7efb5..c2df2384dd 100644
--- a/compiler/errors/source/406_NOT_ACCEPTABLE.tsv
+++ b/compiler/errors/source/406_NOT_ACCEPTABLE.tsv
@@ -1,5 +1,6 @@
 id	message
 AUTH_KEY_DUPLICATED	The same authorization key (session file) was used in more than one place simultaneously. You must delete your session file and log in again with your phone number or bot token
+CHANNEL_PRIVATE	The channel/supergroup is not accessible
 FILEREF_UPGRADE_NEEDED	The file reference has expired and you must use a refreshed one by obtaining the original media message
 FRESH_CHANGE_ADMINS_FORBIDDEN	You were just elected admin, you can't add or modify other admins yet
 FRESH_CHANGE_PHONE_FORBIDDEN	You can't change your phone number because your session was logged-in recently

From 54f8ca25fb40f3ef953b6aded34ee1839d87ae81 Mon Sep 17 00:00:00 2001
From: Sam <25792361+sam01101@users.noreply.github.com>
Date: Sun, 13 Feb 2022 18:37:43 +0800
Subject: [PATCH 096/539] Add 400 CHANNEL_ADD_INVALID error (#894)

* Add RPC Error: CHANNEL_ADD_INVALID

* Update 400_BAD_REQUEST.tsv

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 compiler/errors/source/400_BAD_REQUEST.tsv | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv
index d6754027ee..e5c74e010c 100644
--- a/compiler/errors/source/400_BAD_REQUEST.tsv
+++ b/compiler/errors/source/400_BAD_REQUEST.tsv
@@ -45,6 +45,7 @@ CALL_PROTOCOL_FLAGS_INVALID	Call protocol flags invalid
 CDN_METHOD_INVALID	The method can't be used on CDN DCs
 CHANNELS_ADMIN_PUBLIC_TOO_MUCH	You are an administrator of too many public channels
 CHANNELS_TOO_MUCH	You have joined too many channels or supergroups, leave some and try again
+CHANNEL_ADD_INVALID	Internal error.
 CHANNEL_BANNED	The channel is banned
 CHANNEL_INVALID	The channel parameter is invalid
 CHANNEL_PRIVATE	The channel/supergroup is not accessible
@@ -348,4 +349,4 @@ WEBDOCUMENT_URL_EMPTY	The web document URL is empty
 WEBDOCUMENT_URL_INVALID	The web document URL is invalid
 WEBPAGE_CURL_FAILED	Telegram server could not fetch the provided URL
 WEBPAGE_MEDIA_EMPTY	The URL doesn't contain any valid media
-YOU_BLOCKED_USER	You blocked this user
\ No newline at end of file
+YOU_BLOCKED_USER	You blocked this user

From bca7e6461e6519d1b360e68102df45fc5ceec66e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 17 Feb 2022 11:41:14 +0100
Subject: [PATCH 097/539] Add reply_to_message_id and reply_to_top_message_id
 to Message

---
 pyrogram/types/messages_and_media/message.py | 32 ++++++++++++++------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 1f6e432a16..93f0671237 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -95,6 +95,12 @@ class Message(Object, Update):
         forward_date (``int``, *optional*):
             For forwarded messages, date the original message was sent in Unix time.
 
+        reply_to_message_id (``int``, *optional*):
+            The id of the message which this message directly replied to.
+
+        reply_to_top_message_id (``int``, *optional*):
+            The id of the first message which started this message thread.
+
         reply_to_message (:obj:`~pyrogram.types.Message`, *optional*):
             For replies, the original message. Note that the Message object in this field will not contain
             further reply_to_message fields even if it itself is a reply.
@@ -308,6 +314,8 @@ def __init__(
         forward_from_message_id: int = None,
         forward_signature: str = None,
         forward_date: int = None,
+        reply_to_message_id: int = None,
+        reply_to_top_message_id: int = None,
         reply_to_message: "Message" = None,
         mentioned: bool = None,
         empty: bool = None,
@@ -380,6 +388,8 @@ def __init__(
         self.forward_from_message_id = forward_from_message_id
         self.forward_signature = forward_signature
         self.forward_date = forward_date
+        self.reply_to_message_id = reply_to_message_id
+        self.reply_to_top_message_id = reply_to_top_message_id
         self.reply_to_message = reply_to_message
         self.mentioned = mentioned
         self.empty = empty
@@ -792,15 +802,19 @@ async def _parse(
                 client=client
             )
 
-            if message.reply_to and replies:
-                try:
-                    parsed_message.reply_to_message = await client.get_messages(
-                        parsed_message.chat.id,
-                        reply_to_message_ids=message.id,
-                        replies=replies - 1
-                    )
-                except MessageIdsEmpty:
-                    pass
+            if message.reply_to:
+                if replies:
+                    try:
+                        parsed_message.reply_to_message = await client.get_messages(
+                            parsed_message.chat.id,
+                            reply_to_message_ids=message.id,
+                            replies=replies - 1
+                        )
+                    except MessageIdsEmpty:
+                        pass
+
+                parsed_message.reply_to_message_id = message.reply_to.reply_to_msg_id
+                parsed_message.reply_to_top_message_id = message.reply_to.reply_to_top_id
 
             return parsed_message
 

From bf233e3b5b18d98fb94438c593c0998e1baeb002 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 17 Feb 2022 11:42:42 +0100
Subject: [PATCH 098/539] Update Filters.reply to check for
 Message.reply_to_message_id

---
 pyrogram/filters.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index 46ca896f4d..2a44fd4f9a 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -218,7 +218,7 @@ async def text_filter(_, __, m: Message):
 
 # region reply_filter
 async def reply_filter(_, __, m: Message):
-    return bool(m.reply_to_message)
+    return bool(m.reply_to_message_id)
 
 
 reply = create(reply_filter)

From e0eccfa8fbc458c015d979ddf27dd2dad92b4238 Mon Sep 17 00:00:00 2001
From: blank X 
Date: Sat, 26 Feb 2022 10:13:08 +0000
Subject: [PATCH 099/539] Respect `file_name` if file passed is a file object
 (#912)

Fixes #911
---
 pyrogram/methods/messages/send_animation.py | 4 ++--
 pyrogram/methods/messages/send_audio.py     | 4 ++--
 pyrogram/methods/messages/send_document.py  | 4 ++--
 pyrogram/methods/messages/send_video.py     | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 01856a79ef..963d0681b9 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -201,7 +201,7 @@ def progress(current, total):
                 thumb = await self.save_file(thumb)
                 file = await self.save_file(animation, progress=progress, progress_args=progress_args)
                 media = raw.types.InputMediaUploadedDocument(
-                    mime_type=self.guess_mime_type(animation.name) or "video/mp4",
+                    mime_type=self.guess_mime_type(file_name or animation.name) or "video/mp4",
                     file=file,
                     thumb=thumb,
                     attributes=[
@@ -211,7 +211,7 @@ def progress(current, total):
                             w=width,
                             h=height
                         ),
-                        raw.types.DocumentAttributeFilename(file_name=animation.name),
+                        raw.types.DocumentAttributeFilename(file_name=file_name or animation.name),
                         raw.types.DocumentAttributeAnimated()
                     ]
                 )
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 4ce02c31a1..921b7890c7 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -197,7 +197,7 @@ def progress(current, total):
                 thumb = await self.save_file(thumb)
                 file = await self.save_file(audio, progress=progress, progress_args=progress_args)
                 media = raw.types.InputMediaUploadedDocument(
-                    mime_type=self.guess_mime_type(audio.name) or "audio/mpeg",
+                    mime_type=self.guess_mime_type(file_name or audio.name) or "audio/mpeg",
                     file=file,
                     thumb=thumb,
                     attributes=[
@@ -206,7 +206,7 @@ def progress(current, total):
                             performer=performer,
                             title=title
                         ),
-                        raw.types.DocumentAttributeFilename(file_name=audio.name)
+                        raw.types.DocumentAttributeFilename(file_name=file_name or audio.name)
                     ]
                 )
 
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index bc407fe2b3..c3765a1726 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -180,11 +180,11 @@ def progress(current, total):
                 thumb = await self.save_file(thumb)
                 file = await self.save_file(document, progress=progress, progress_args=progress_args)
                 media = raw.types.InputMediaUploadedDocument(
-                    mime_type=self.guess_mime_type(document.name) or "application/zip",
+                    mime_type=self.guess_mime_type(file_name or document.name) or "application/zip",
                     file=file,
                     thumb=thumb,
                     attributes=[
-                        raw.types.DocumentAttributeFilename(file_name=document.name)
+                        raw.types.DocumentAttributeFilename(file_name=file_name or document.name)
                     ]
                 )
 
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index cccc07ab98..e9448a2209 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -207,7 +207,7 @@ def progress(current, total):
                 thumb = await self.save_file(thumb)
                 file = await self.save_file(video, progress=progress, progress_args=progress_args)
                 media = raw.types.InputMediaUploadedDocument(
-                    mime_type=self.guess_mime_type(video.name) or "video/mp4",
+                    mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
                     file=file,
                     ttl_seconds=ttl_seconds,
                     thumb=thumb,
@@ -218,7 +218,7 @@ def progress(current, total):
                             w=width,
                             h=height
                         ),
-                        raw.types.DocumentAttributeFilename(file_name=video.name)
+                        raw.types.DocumentAttributeFilename(file_name=file_name or video.name)
                     ]
                 )
 

From 4dc771b64ad44b982e3eb0145505ec54d94281f9 Mon Sep 17 00:00:00 2001
From: scrazzz <70033559+scrazzz@users.noreply.github.com>
Date: Sat, 26 Feb 2022 13:13:52 +0300
Subject: [PATCH 100/539] Fix docstring for `message.reply_photo` (#903)

---
 pyrogram/types/messages_and_media/message.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 93f0671237..355a83a534 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -1904,7 +1904,7 @@ async def reply_photo(
                 If *reply_to_message_id* is passed, this parameter will be ignored.
                 Defaults to ``True`` in group chats and ``False`` in private chats.
 
-            caption (``bool``, *optional*):
+            caption (``str``, *optional*):
                 Photo caption, 0-1024 characters.
 
             parse_mode (``str``, *optional*):

From 748222131ddbdefa82a1530817f62ec955d67eab Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 28 Feb 2022 12:49:52 +0100
Subject: [PATCH 101/539] Update Pyrogram to v1.4.8

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 304ce76d3c..76aa3afbf6 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.7"
+__version__ = "1.4.8"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 5ee6f3d2c715c916c02ac1e1682a2c5638ea3b84 Mon Sep 17 00:00:00 2001
From: "Mr. Developer" <77911154+MrBotDeveloper@users.noreply.github.com>
Date: Mon, 7 Mar 2022 17:43:22 +0530
Subject: [PATCH 102/539] Add some missing parameters to Message.reply_text

---
 pyrogram/types/messages_and_media/message.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 355a83a534..df5f2dd1d1 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -863,7 +863,9 @@ async def reply_text(
         disable_web_page_preview: bool = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        reply_markup=None
+        schedule_date: int = None,
+        protect_content: bool = None,
+        reply_markup = None
     ) -> "Message":
         """Bound method *reply_text* of :obj:`~pyrogram.types.Message`.
 
@@ -913,6 +915,12 @@ async def reply_text(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
+            schedule_date (``int``, *optional*):
+                Date when the message will be automatically sent. Unix time.
+
+            protect_content (``bool``, *optional*):
+                Protects the contents of the sent message from forwarding and saving.
+
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
@@ -937,6 +945,8 @@ async def reply_text(
             disable_web_page_preview=disable_web_page_preview,
             disable_notification=disable_notification,
             reply_to_message_id=reply_to_message_id,
+            schedule_date=schedule_date,
+            protect_content=protect_content,
             reply_markup=reply_markup
         )
 

From 8d7b62654c099433ccb8280272d78ef168e073e8 Mon Sep 17 00:00:00 2001
From: Nick <64551534+null-nick@users.noreply.github.com>
Date: Fri, 11 Mar 2022 12:14:59 +0100
Subject: [PATCH 103/539] Update API schema to Layer 139 (#936)

---
 compiler/api/source/main_api.tl | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 9d5d811bfb..5bd7dfb568 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -213,6 +213,8 @@ inputReportReasonOther#c1e4a2b1 = ReportReason;
 inputReportReasonCopyright#9b89f93a = ReportReason;
 inputReportReasonGeoIrrelevant#dbd4feed = ReportReason;
 inputReportReasonFake#f5ddd6e7 = ReportReason;
+inputReportReasonIllegalDrugs#a8eb2be = ReportReason;
+inputReportReasonPersonalDetails#9ec7863d = ReportReason;
 
 userFull#cf366521 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string = UserFull;
 
@@ -544,7 +546,7 @@ inputStickerSetAnimatedEmoji#28703c8 = InputStickerSet;
 inputStickerSetDice#e67f520e emoticon:string = InputStickerSet;
 inputStickerSetAnimatedEmojiAnimations#cde3739 = InputStickerSet;
 
-stickerSet#d7df217a flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true gifs:flags.6?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int count:int hash:int = StickerSet;
+stickerSet#d7df217a flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true videos:flags.6?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int count:int hash:int = StickerSet;
 
 messages.stickerSet#b60a24a6 set:StickerSet packs:Vector documents:Vector = messages.StickerSet;
 messages.stickerSetNotModified#d3f924eb = messages.StickerSet;
@@ -1204,7 +1206,7 @@ peerBlocked#e8fd8014 peer_id:Peer date:int = PeerBlocked;
 stats.messageStats#8999f295 views_graph:StatsGraph = stats.MessageStats;
 
 groupCallDiscarded#7780bcb4 id:long access_hash:long duration:int = GroupCall;
-groupCall#d597650c flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true schedule_start_subscribed:flags.8?true can_start_video:flags.9?true record_video_active:flags.11?true id:long access_hash:long participants_count:int title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int schedule_date:flags.7?int unmuted_video_count:flags.10?int unmuted_video_limit:int version:int = GroupCall;
+groupCall#d597650c flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true schedule_start_subscribed:flags.8?true can_start_video:flags.9?true record_video_active:flags.11?true rtmp_stream:flags.12?true listeners_hidden:flags.13?true id:long access_hash:long participants_count:int title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int schedule_date:flags.7?int unmuted_video_count:flags.10?int unmuted_video_limit:int version:int = GroupCall;
 
 inputGroupCall#d8aa840f id:long access_hash:long = InputGroupCall;
 
@@ -1299,6 +1301,12 @@ messages.translateResultText#a214f7d0 text:string = messages.TranslatedText;
 
 messagePeerReaction#51b67eff flags:# big:flags.0?true unread:flags.1?true peer_id:Peer reaction:string = MessagePeerReaction;
 
+groupCallStreamChannel#80eb48af channel:int scale:int last_timestamp_ms:long = GroupCallStreamChannel;
+
+phone.groupCallStreamChannels#d0e482b2 channels:Vector = phone.GroupCallStreamChannels;
+
+phone.groupCallStreamRtmpUrl#2dbf3432 url:string key:string = phone.GroupCallStreamRtmpUrl;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1427,6 +1435,7 @@ contacts.addContact#e8f463d0 flags:# add_phone_privacy_exception:flags.0?true id
 contacts.acceptContact#f831a20f id:InputUser = Updates;
 contacts.getLocated#d348bc44 flags:# background:flags.1?true geo_point:InputGeoPoint self_expires:flags.0?int = Updates;
 contacts.blockFromReplies#29a8962c flags:# delete_message:flags.0?true delete_history:flags.1?true report_spam:flags.2?true msg_id:int = Updates;
+contacts.resolvePhone#8af94344 phone:string = contacts.ResolvedPeer;
 
 messages.getMessages#63c66506 id:Vector = messages.Messages;
 messages.getDialogs#a0f4cb4f flags:# exclude_pinned:flags.0?true folder_id:flags.1?int offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:long = messages.Dialogs;
@@ -1586,6 +1595,7 @@ messages.setDefaultReaction#d960c4d4 reaction:string = Bool;
 messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?int text:flags.1?string from_lang:flags.2?string to_lang:string = messages.TranslatedText;
 messages.getUnreadReactions#e85bae1a peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
 messages.readReactions#82e251d7 peer:InputPeer = messages.AffectedHistory;
+messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = messages.Messages;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1682,7 +1692,7 @@ payments.getSavedInfo#227d824b = payments.SavedInfo;
 payments.clearSavedInfo#d83d70c1 flags:# credentials:flags.0?true info:flags.1?true = Bool;
 payments.getBankCardData#2e79d779 number:string = payments.BankCardData;
 
-stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet;
+stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet;
 stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet;
 stickers.changeStickerPosition#ffb6d4ca sticker:InputDocument position:int = messages.StickerSet;
 stickers.addStickerToSet#8653febe stickerset:InputStickerSet sticker:InputStickerSetItem = messages.StickerSet;
@@ -1699,7 +1709,7 @@ phone.discardCall#b2cbc1c0 flags:# video:flags.0?true peer:InputPhoneCall durati
 phone.setCallRating#59ead627 flags:# user_initiative:flags.0?true peer:InputPhoneCall rating:int comment:string = Updates;
 phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool;
 phone.sendSignalingData#ff7a9383 peer:InputPhoneCall data:bytes = Bool;
-phone.createGroupCall#48cdc6d8 flags:# peer:InputPeer random_id:int title:flags.0?string schedule_date:flags.1?int = Updates;
+phone.createGroupCall#48cdc6d8 flags:# rtmp_stream:flags.2?true peer:InputPeer random_id:int title:flags.0?string schedule_date:flags.1?int = Updates;
 phone.joinGroupCall#b132ff7b flags:# muted:flags.0?true video_stopped:flags.2?true call:InputGroupCall join_as:InputPeer invite_hash:flags.1?string params:DataJSON = Updates;
 phone.leaveGroupCall#500377f9 call:InputGroupCall source:int = Updates;
 phone.inviteToGroupCall#7b393160 call:InputGroupCall users:Vector = Updates;
@@ -1718,6 +1728,8 @@ phone.startScheduledGroupCall#5680e342 call:InputGroupCall = Updates;
 phone.saveDefaultGroupCallJoinAs#575e1f8c peer:InputPeer join_as:InputPeer = Bool;
 phone.joinGroupCallPresentation#cbea6bc4 call:InputGroupCall params:DataJSON = Updates;
 phone.leaveGroupCallPresentation#1c50d144 call:InputGroupCall = Updates;
+phone.getGroupCallStreamChannels#1ab21940 call:InputGroupCall = phone.GroupCallStreamChannels;
+phone.getGroupCallStreamRtmpUrl#deb3abbf peer:InputPeer revoke:Bool = phone.GroupCallStreamRtmpUrl;
 
 langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference;
 langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector;
@@ -1734,4 +1746,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 138
\ No newline at end of file
+// LAYER 139
\ No newline at end of file

From d0e2235835e8ecdf557df7a876502a16be654eba Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 11 Mar 2022 12:29:05 +0100
Subject: [PATCH 104/539] Improve the RLE codec

---
 pyrogram/file_id.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/pyrogram/file_id.py b/pyrogram/file_id.py
index ee1ccc4a89..95f6ccbf1a 100644
--- a/pyrogram/file_id.py
+++ b/pyrogram/file_id.py
@@ -63,20 +63,20 @@ def rle_encode(s: bytes) -> bytes:
     Returns:
         ``bytes``: The encoded bytes
     """
-    r = b""
-    n = 0
+    r: bytes = b""
+    n: int = 0
 
     for b in s:
-        if b == 0:
+        if not b:
             n += 1
         else:
-            if n > 0:
+            if n:
                 r += bytes([0, n])
                 n = 0
 
             r += bytes([b])
 
-    if n > 0:
+    if n:
         r += bytes([0, n])
 
     return r
@@ -92,17 +92,19 @@ def rle_decode(s: bytes) -> bytes:
     Returns:
         ``bytes``: The encoded bytes
     """
-    r = b""
-    i = 0
+    r: bytes = b""
+    z: bool = False
 
-    while i < len(s):
-        if s[i] != 0:
-            r += bytes([s[i]])
-        else:
-            r += b"\x00" * s[i + 1]
-            i += 1
+    for b in s:
+        if not b:
+            z = True
+            continue
 
-        i += 1
+        if z:
+            r += b"\x00" * b
+            z = False
+        else:
+            r += bytes([b])
 
     return r
 

From 58eb10a676053669279b79ddc576c6ff4087daa3 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 14 Mar 2022 12:07:34 +0100
Subject: [PATCH 105/539] Remove unneeded try...except block

---
 pyrogram/client.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index ce76920fa9..7d3dbd3701 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -251,10 +251,7 @@ def __enter__(self):
         return self.start()
 
     def __exit__(self, *args):
-        try:
-            self.stop()
-        except ConnectionError:
-            pass
+        self.stop()
 
     async def __aenter__(self):
         return await self.start()

From 8ee5ea02b19228a40910ae641cef1a49aa603780 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 19 Mar 2022 20:57:17 +0100
Subject: [PATCH 106/539] Update pin_chat_message to return Message instead of
 bool

---
 pyrogram/methods/chats/pin_chat_message.py   | 16 +++++++++++-----
 pyrogram/types/messages_and_media/message.py |  4 ++--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py
index d4d6b040f8..016a19a7b2 100644
--- a/pyrogram/methods/chats/pin_chat_message.py
+++ b/pyrogram/methods/chats/pin_chat_message.py
@@ -18,7 +18,7 @@
 
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, types
 from pyrogram.scaffold import Scaffold
 
 
@@ -29,7 +29,7 @@ async def pin_chat_message(
         message_id: int,
         disable_notification: bool = False,
         both_sides: bool = False,
-    ) -> bool:
+    ) -> "types.Message":
         """Pin a message in a group, channel or your own chat.
         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.
@@ -50,7 +50,7 @@ async def pin_chat_message(
                 Applicable to private chats only. Defaults to False.
 
         Returns:
-            ``bool``: True on success.
+            :obj:`~pyrogram.types.Message`: On success, the service message is returned.
 
         Example:
             .. code-block:: python
@@ -61,7 +61,7 @@ async def pin_chat_message(
                 # Pin without notification
                 app.pin_chat_message(chat_id, message_id, disable_notification=True)
         """
-        await self.send(
+        r = await self.send(
             raw.functions.messages.UpdatePinnedMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
@@ -70,4 +70,10 @@ async def pin_chat_message(
             )
         )
 
-        return True
+        users = {u.id: u for u in r.users}
+        chats = {c.id: c for c in r.chats}
+
+        for i in r.updates:
+            if isinstance(i, (raw.types.UpdateNewMessage,
+                              raw.types.UpdateNewChannelMessage)):
+                return await types.Message._parse(self, i.message, users, chats)
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index df5f2dd1d1..ea54231d70 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -3423,7 +3423,7 @@ async def vote(
             options=option
         )
 
-    async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> bool:
+    async def pin(self, disable_notification: bool = False, both_sides: bool = False) -> "types.Message":
         """Bound method *pin* of :obj:`~pyrogram.types.Message`.
 
         Use as a shortcut for:
@@ -3450,7 +3450,7 @@ async def pin(self, disable_notification: bool = False, both_sides: bool = False
                 Applicable to private chats only. Defaults to False.
 
         Returns:
-            True on success.
+            :obj:`~pyrogram.types.Message`: On success, the service message is returned.
 
         Raises:
             RPCError: In case of a Telegram RPC error.

From 65a53aeeb3141718d1bb5efd40b0a10db24165e2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 19 Mar 2022 21:00:36 +0100
Subject: [PATCH 107/539] Update Pyrogram to v1.4.9

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 76aa3afbf6..ebb3b16355 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.8"
+__version__ = "1.4.9"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From aa41ac5fd252146735f32f460c44fab27fcf01e7 Mon Sep 17 00:00:00 2001
From: Andrea Maugeri 
Date: Mon, 28 Mar 2022 11:48:15 +0200
Subject: [PATCH 108/539] Fix issue in set_bot_commands (#778)

---
 pyrogram/methods/bots/set_bot_commands.py     | 26 ++++---
 pyrogram/types/bots_and_keyboards/__init__.py |  3 +-
 .../types/bots_and_keyboards/bot_command.py   | 74 ++++++++++++++++++-
 3 files changed, 91 insertions(+), 12 deletions(-)

diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index 02158c0cb6..769a430156 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -16,17 +16,23 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import Optional, List
+from typing import List, Optional
 
-from pyrogram import raw
-from pyrogram import types
+from pyrogram import raw, types
 from pyrogram.scaffold import Scaffold
 
 
 class SetBotCommands(Scaffold):
-    async def set_bot_commands(self, commands: Optional[List[types.BotCommand]]):
+    async def set_bot_commands(
+        self,
+        commands: Optional[List[types.BotCommand]],
+        scope: types.BotCommandScope = types.BotCommandScope(
+            types.BotCommandScope.DEFAULT
+        ),
+        lang_code: str = "",
+    ):
         """Set the bot commands list.
-        
+
         The commands passed will overwrite any command set previously.
         This method can be used by the own bot only.
 
@@ -40,20 +46,22 @@ async def set_bot_commands(self, commands: Optional[List[types.BotCommand]]):
 
         Example:
             .. code-block:: python
-                
+
                 from pyrogram.types import BotCommand
-                
+
                 # Set new commands
                 app.set_bot_commands([
                     BotCommand("start", "Start the bot"),
                     BotCommand("settings", "Bot settings")])
-                
+
                 # Remove commands
                 app.set_bot_commands(None)
         """
 
         return await self.send(
             raw.functions.bots.SetBotCommands(
-                commands=[c.write() for c in commands or []]
+                commands=[c.write() for c in commands or []],
+                scope=scope.write(),
+                lang_code=lang_code,
             )
         )
diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py
index ccf84993c7..d69c70fa7f 100644
--- a/pyrogram/types/bots_and_keyboards/__init__.py
+++ b/pyrogram/types/bots_and_keyboards/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from .bot_command import BotCommand
+from .bot_command import BotCommand, BotCommandScope
 from .callback_game import CallbackGame
 from .callback_query import CallbackQuery
 from .force_reply import ForceReply
@@ -40,4 +40,5 @@
     "ReplyKeyboardRemove",
     "LoginUrl",
     "BotCommand",
+    "BotCommandScope",
 ]
diff --git a/pyrogram/types/bots_and_keyboards/bot_command.py b/pyrogram/types/bots_and_keyboards/bot_command.py
index 66412f09cf..82cdc67ef8 100644
--- a/pyrogram/types/bots_and_keyboards/bot_command.py
+++ b/pyrogram/types/bots_and_keyboards/bot_command.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 from pyrogram import raw
+
 from ..object import Object
 
 
@@ -26,7 +27,7 @@ class BotCommand(Object):
     Parameters:
         command (``str``):
             The bot command, for example: "/start".
-            
+
         description (``str``):
             Description of the bot command.
     """
@@ -40,5 +41,74 @@ def __init__(self, command: str, description: str):
     def write(self):
         return raw.types.BotCommand(
             command=self.command,
-            description=self.description
+            description=self.description,
         )
+
+
+class BotCommandScope(Object):
+    """
+    Represents a scope where the bot commands, specified
+    using bots.setBotCommands will be valid.
+
+    Parameters:
+        scope (``str``):
+
+            - DEFAULT: The commands will be valid in all chats (default value)
+
+            - PRIVATE: The specified bot commands will only be valid in all private
+            chats with users.
+
+            - GROUP: The specified bot commands will be valid in all groups and supergroups
+
+            - GROUP_ADMINS: The specified bot commands will be valid only for chat
+            administrators, in all groups and supergroups.
+
+            - PEER: The specified bot commands will be valid only in a specific dialog
+
+            - PEER_ADMINS: The specified bot commands will be valid for all admins of the
+            specified group or supergroup.
+
+            - PEER_USER: The specified bot commands will be valid only for a specific user
+            in the specified chat
+    """
+
+    DEFAULT = "default"
+    PRIVATE = "users"
+    GROUP = "chats"
+    GROUP_ADMINS = "chat_admins"
+    PEER = "peer"
+    PEER_ADMINS = "peer_admins"
+    PEER_USER = "peer_user"
+
+    raw_scopes = {
+        DEFAULT: raw.types.BotCommandScopeDefault,
+        PRIVATE: raw.types.BotCommandScopeUsers,
+        GROUP: raw.types.BotCommandScopeChats,
+        GROUP_ADMINS: raw.types.BotCommandScopeChatAdmins,
+        PEER: lambda peer: raw.types.BotCommandScopePeer(peer),
+        PEER_ADMINS: lambda peer: raw.types.BotCommandScopePeerAdmins(peer),
+        PEER_USER: lambda peer, user_id: raw.types.BotCommandScopePeerUser(
+            peer, user_id
+        ),
+    }
+
+    def __init__(
+        self,
+        scope: str,
+        peer: raw.types.InputPeerUser = None,
+        user_id: raw.types.InputUser = None,
+    ):
+        super().__init__()
+        self.scope = scope
+        self.peer = peer
+        self.user_id = user_id
+
+    def write(self):
+
+        if self.scope in ["peer", "peer_admins"]:
+            return self.raw_scopes[self.scope](self.peer)
+
+        elif self.scope == "peer_user":
+            return self.raw_scopes[self.scopes](self.peer, self.user_id)
+
+        return self.raw_scopes[self.scope]()

From 7bfcd5ac5fc02710384b2166a924340c08495075 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 28 Mar 2022 13:23:12 +0200
Subject: [PATCH 109/539] Revamp bot commands and bot command scopes Closes
 #777

---
 compiler/docs/compiler.py                     | 17 +++-
 compiler/docs/template/types.rst              | 21 ++++-
 pyrogram/methods/bots/__init__.py             |  6 +-
 pyrogram/methods/bots/delete_bot_commands.py  | 61 ++++++++++++++
 pyrogram/methods/bots/get_bot_commands.py     | 62 ++++++++++++++
 pyrogram/methods/bots/set_bot_commands.py     | 37 +++++----
 pyrogram/types/bots_and_keyboards/__init__.py | 17 +++-
 .../types/bots_and_keyboards/bot_command.py   | 81 +++----------------
 .../bots_and_keyboards/bot_command_scope.py   | 73 +++++++++++++++++
 ...t_command_scope_all_chat_administrators.py | 32 ++++++++
 .../bot_command_scope_all_group_chats.py      | 32 ++++++++
 .../bot_command_scope_all_private_chats.py    | 32 ++++++++
 .../bot_command_scope_chat.py                 | 43 ++++++++++
 .../bot_command_scope_chat_administrators.py  | 43 ++++++++++
 .../bot_command_scope_chat_member.py          | 48 +++++++++++
 .../bot_command_scope_default.py              | 33 ++++++++
 16 files changed, 543 insertions(+), 95 deletions(-)
 create mode 100644 pyrogram/methods/bots/delete_bot_commands.py
 create mode 100644 pyrogram/methods/bots/get_bot_commands.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_all_chat_administrators.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_all_group_chats.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_all_private_chats.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_chat.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_chat_administrators.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_chat_member.py
 create mode 100644 pyrogram/types/bots_and_keyboards/bot_command_scope_default.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index c1a4588603..118c0e636f 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -288,6 +288,8 @@ def get_title_list(s: str) -> list:
             set_game_score
             get_game_high_scores
             set_bot_commands
+            get_bot_commands
+            delete_bot_commands
         """,
         authorization="""
         Authorization
@@ -395,8 +397,8 @@ def get_title_list(s: str) -> list:
             VoiceChatEnded
             VoiceChatMembersInvited
         """,
-        bots_keyboard="""
-        Bots & Keyboards
+        bot_keyboards="""
+        Bot keyboards
             ReplyKeyboardMarkup
             KeyboardButton
             ReplyKeyboardRemove
@@ -407,7 +409,18 @@ def get_title_list(s: str) -> list:
             CallbackQuery
             GameHighScore
             CallbackGame
+        """,
+        bot_commands="""
+        Bot commands
             BotCommand
+            BotCommandScope
+            BotCommandScopeDefault
+            BotCommandScopeAllPrivateChats
+            BotCommandScopeAllGroupChats
+            BotCommandScopeAllChatAdministrators
+            BotCommandScopeChat
+            BotCommandScopeChatAdministrators
+            BotCommandScopeChatMember
         """,
         input_media="""
         Input Media
diff --git a/compiler/docs/template/types.rst b/compiler/docs/template/types.rst
index 2651c3559a..2011a61100 100644
--- a/compiler/docs/template/types.rst
+++ b/compiler/docs/template/types.rst
@@ -51,18 +51,31 @@ Messages & Media
 
     {messages_media}
 
-Bots & Keyboards
-----------------
+Bot keyboards
+-------------
+
+.. autosummary::
+    :nosignatures:
+
+    {bot_keyboards}
+
+.. toctree::
+    :hidden:
+
+    {bot_keyboards}
+
+Bot commands
+-------------
 
 .. autosummary::
     :nosignatures:
 
-    {bots_keyboard}
+    {bot_commands}
 
 .. toctree::
     :hidden:
 
-    {bots_keyboard}
+    {bot_commands}
 
 Input Media
 -----------
diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py
index 0051c6c3fb..54854b8e3d 100644
--- a/pyrogram/methods/bots/__init__.py
+++ b/pyrogram/methods/bots/__init__.py
@@ -18,6 +18,8 @@
 
 from .answer_callback_query import AnswerCallbackQuery
 from .answer_inline_query import AnswerInlineQuery
+from .delete_bot_commands import DeleteBotCommands
+from .get_bot_commands import GetBotCommands
 from .get_game_high_scores import GetGameHighScores
 from .get_inline_bot_results import GetInlineBotResults
 from .request_callback_answer import RequestCallbackAnswer
@@ -36,6 +38,8 @@ class Bots(
     SendGame,
     SetGameScore,
     GetGameHighScores,
-    SetBotCommands
+    SetBotCommands,
+    GetBotCommands,
+    DeleteBotCommands
 ):
     pass
diff --git a/pyrogram/methods/bots/delete_bot_commands.py b/pyrogram/methods/bots/delete_bot_commands.py
new file mode 100644
index 0000000000..edb82debed
--- /dev/null
+++ b/pyrogram/methods/bots/delete_bot_commands.py
@@ -0,0 +1,61 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw, types
+from pyrogram.scaffold import Scaffold
+
+
+class DeleteBotCommands(Scaffold):
+    async def delete_bot_commands(
+        self: "pyrogram.Client",
+        scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
+        language_code: str = "",
+    ):
+        """Delete the list of the bot's commands for the given scope and user language.
+        After deletion, higher level commands will be shown to affected users.
+
+        The commands passed will overwrite any command set previously.
+        This method can be used by the own bot only.
+
+        Parameters:
+            scope (:obj:`~pyrogram.types.BotCommandScope`, *optional*):
+                An object describing the scope of users for which the commands are relevant.
+                Defaults to :obj:`~pyrogram.types.BotCommandScopeDefault`.
+
+            language_code (``str``, *optional*):
+                A two-letter ISO 639-1 language code.
+                If empty, commands will be applied to all users from the given scope, for whose language there are no
+                dedicated commands.
+
+        Returns:
+            ``bool``: On success, True is returned.
+
+        Example:
+            .. code-block:: python
+
+                # Delete commands
+                app.delete_bot_commands()
+        """
+
+        return await self.send(
+            raw.functions.bots.ResetBotCommands(
+                scope=await scope.write(self),
+                lang_code=language_code,
+            )
+        )
diff --git a/pyrogram/methods/bots/get_bot_commands.py b/pyrogram/methods/bots/get_bot_commands.py
new file mode 100644
index 0000000000..c92bd21ea0
--- /dev/null
+++ b/pyrogram/methods/bots/get_bot_commands.py
@@ -0,0 +1,62 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw, types
+from pyrogram.scaffold import Scaffold
+
+
+class GetBotCommands(Scaffold):
+    async def get_bot_commands(
+        self: "pyrogram.Client",
+        scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
+        language_code: str = "",
+    ):
+        """Get the current list of the bot's commands for the given scope and user language.
+        Returns Array of BotCommand on success. If commands aren't set, an empty list is returned.
+
+        The commands passed will overwrite any command set previously.
+        This method can be used by the own bot only.
+
+        Parameters:
+            scope (:obj:`~pyrogram.types.BotCommandScope`, *optional*):
+                An object describing the scope of users for which the commands are relevant.
+                Defaults to :obj:`~pyrogram.types.BotCommandScopeDefault`.
+
+            language_code (``str``, *optional*):
+                A two-letter ISO 639-1 language code.
+                If empty, commands will be applied to all users from the given scope, for whose language there are no
+                dedicated commands.
+
+        Returns:
+            List of :obj:`~pyrogram.types.BotCommand`: On success, the list of bot commands is returned.
+
+        Example:
+            .. code-block:: python
+
+                # Get commands
+                commands = app.get_bot_commands()
+                print(commands)
+        """
+
+        return await self.send(
+            raw.functions.bots.GetBotCommands(
+                scope=await scope.write(self),
+                lang_code=language_code,
+            )
+        )
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index 769a430156..c346151591 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -16,22 +16,21 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import List, Optional
+from typing import List
 
+import pyrogram
 from pyrogram import raw, types
 from pyrogram.scaffold import Scaffold
 
 
 class SetBotCommands(Scaffold):
     async def set_bot_commands(
-        self,
-        commands: Optional[List[types.BotCommand]],
-        scope: types.BotCommandScope = types.BotCommandScope(
-            types.BotCommandScope.DEFAULT
-        ),
-        lang_code: str = "",
+        self: "pyrogram.Client",
+        commands: List["types.BotCommand"],
+        scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
+        language_code: str = "",
     ):
-        """Set the bot commands list.
+        """Set the list of the bot's commands.
 
         The commands passed will overwrite any command set previously.
         This method can be used by the own bot only.
@@ -39,10 +38,19 @@ async def set_bot_commands(
         Parameters:
             commands (List of :obj:`~pyrogram.types.BotCommand`):
                 A list of bot commands.
-                Pass None to remove all commands.
+                At most 100 commands can be specified.
+
+            scope (:obj:`~pyrogram.types.BotCommandScope`, *optional*):
+                An object describing the scope of users for which the commands are relevant.
+                Defaults to :obj:`~pyrogram.types.BotCommandScopeDefault`.
+
+            language_code (``str``, *optional*):
+                A two-letter ISO 639-1 language code.
+                If empty, commands will be applied to all users from the given scope, for whose language there are no
+                dedicated commands.
 
         Returns:
-            ``bool``: True on success, False otherwise.
+            ``bool``: On success, True is returned.
 
         Example:
             .. code-block:: python
@@ -53,15 +61,12 @@ async def set_bot_commands(
                 app.set_bot_commands([
                     BotCommand("start", "Start the bot"),
                     BotCommand("settings", "Bot settings")])
-
-                # Remove commands
-                app.set_bot_commands(None)
         """
 
         return await self.send(
             raw.functions.bots.SetBotCommands(
-                commands=[c.write() for c in commands or []],
-                scope=scope.write(),
-                lang_code=lang_code,
+                commands=[c.write() for c in commands],
+                scope=await scope.write(self),
+                lang_code=language_code,
             )
         )
diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py
index d69c70fa7f..37e6dfe831 100644
--- a/pyrogram/types/bots_and_keyboards/__init__.py
+++ b/pyrogram/types/bots_and_keyboards/__init__.py
@@ -16,7 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from .bot_command import BotCommand, BotCommandScope
+from .bot_command import BotCommand
+from .bot_command_scope import BotCommandScope
+from .bot_command_scope_all_chat_administrators import BotCommandScopeAllChatAdministrators
+from .bot_command_scope_all_group_chats import BotCommandScopeAllGroupChats
+from .bot_command_scope_all_private_chats import BotCommandScopeAllPrivateChats
+from .bot_command_scope_chat import BotCommandScopeChat
+from .bot_command_scope_chat_administrators import BotCommandScopeChatAdministrators
+from .bot_command_scope_chat_member import BotCommandScopeChatMember
+from .bot_command_scope_default import BotCommandScopeDefault
 from .callback_game import CallbackGame
 from .callback_query import CallbackQuery
 from .force_reply import ForceReply
@@ -41,4 +49,11 @@
     "LoginUrl",
     "BotCommand",
     "BotCommandScope",
+    "BotCommandScopeAllChatAdministrators",
+    "BotCommandScopeAllGroupChats",
+    "BotCommandScopeAllPrivateChats",
+    "BotCommandScopeChat",
+    "BotCommandScopeChatAdministrators",
+    "BotCommandScopeChatMember",
+    "BotCommandScopeDefault",
 ]
diff --git a/pyrogram/types/bots_and_keyboards/bot_command.py b/pyrogram/types/bots_and_keyboards/bot_command.py
index 82cdc67ef8..88f459dcc4 100644
--- a/pyrogram/types/bots_and_keyboards/bot_command.py
+++ b/pyrogram/types/bots_and_keyboards/bot_command.py
@@ -26,10 +26,11 @@ class BotCommand(Object):
 
     Parameters:
         command (``str``):
-            The bot command, for example: "/start".
+            Text of the command; 1-32 characters.
+            Can contain only lowercase English letters, digits and underscores.
 
         description (``str``):
-            Description of the bot command.
+            Description of the command; 1-256 characters.
     """
 
     def __init__(self, command: str, description: str):
@@ -38,77 +39,15 @@ def __init__(self, command: str, description: str):
         self.command = command
         self.description = description
 
-    def write(self):
+    def write(self) -> "raw.types.BotCommand":
         return raw.types.BotCommand(
             command=self.command,
             description=self.description,
         )
 
-
-class BotCommandScope(Object):
-    """
-    Represents a scope where the bot commands, specified
-    using bots.setBotCommands will be valid.
-
-    Parameters:
-        scope (``str``):
-
-            - DEFAULT: The commands will be valid in all chats (default value)
-
-            - PRIVATE: The specified bot commands will only be valid in all private
-            chats with users.
-
-            - GROUP: The specified bot commands will be valid in all groups and supergroups
-
-            - GROUP_ADMINS: The specified bot commands will be valid only for chat
-            administrators, in all groups and supergroups.
-
-            - PEER: The specified bot commands will be valid only in a specific dialog
-
-            - PEER_ADMINS: The specified bot commands will be valid for all admins of the
-            specified group or supergroup.
-
-            - PEER_USER: The specified bot commands will be valid only for a specific user
-            in the specified chat
-    """
-
-    DEFAULT = "default"
-    PRIVATE = "users"
-    GROUP = "chats"
-    GROUP_ADMINS = "chat_admins"
-    PEER = "peer"
-    PEER_ADMINS = "peer_admins"
-    PEER_USER = "peer_user"
-
-    raw_scopes = {
-        DEFAULT: raw.types.BotCommandScopeDefault,
-        PRIVATE: raw.types.BotCommandScopeUsers,
-        GROUP: raw.types.BotCommandScopeChats,
-        GROUP_ADMINS: raw.types.BotCommandScopeChatAdmins,
-        PEER: lambda peer: raw.types.BotCommandScopePeer(peer),
-        PEER_ADMINS: lambda peer: raw.types.BotCommandScopePeerAdmins(peer),
-        PEER_USER: lambda peer, user_id: raw.types.BotCommandScopePeerUser(
-            peer, user_id
-        ),
-    }
-
-    def __init__(
-        self,
-        scope: str,
-        peer: raw.types.InputPeerUser = None,
-        user_id: raw.types.InputUser = None,
-    ):
-        super().__init__()
-        self.scope = scope
-        self.peer = peer
-        self.user_id = user_id
-
-    def write(self):
-
-        if self.scope in ["peer", "peer_admins"]:
-            return self.raw_scopes[self.scope](self.peer)
-
-        elif self.scope == "peer_user":
-            return self.raw_scopes[self.scopes](self.peer, self.user_id)
-
-        return self.raw_scopes[self.scope]()
+    @staticmethod
+    def read(c: "raw.types.BotCommand") -> "BotCommand":
+        return BotCommand(
+            command=c.command,
+            description=c.description
+        )
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope.py b/pyrogram/types/bots_and_keyboards/bot_command_scope.py
new file mode 100644
index 0000000000..2db638e9a7
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope.py
@@ -0,0 +1,73 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from ..object import Object
+
+
+class BotCommandScope(Object):
+    """Represents the scope to which bot commands are applied.
+
+    Currently, the following 7 scopes are supported:
+
+    - :obj:`~pyrogram.types.BotCommandScopeDefault`
+    - :obj:`~pyrogram.types.BotCommandScopeAllPrivateChats`
+    - :obj:`~pyrogram.types.BotCommandScopeAllGroupChats`
+    - :obj:`~pyrogram.types.BotCommandScopeAllChatAdministrators`
+    - :obj:`~pyrogram.types.BotCommandScopeChat`
+    - :obj:`~pyrogram.types.BotCommandScopeChatAdministrators`
+    - :obj:`~pyrogram.types.BotCommandScopeChatMember`
+
+    **Determining list of commands**
+
+    The following algorithm is used to determine the list of commands for a particular user viewing the bot menu.
+    The first list of commands which is set is returned:
+
+    **Commands in the chat with the bot**:
+
+    - BotCommandScopeChat + language_code
+    - BotCommandScopeChat
+    - BotCommandScopeAllPrivateChats + language_code
+    - BotCommandScopeAllPrivateChats
+    - BotCommandScopeDefault + language_code
+    - BotCommandScopeDefault
+
+    **Commands in group and supergroup chats**
+
+    - BotCommandScopeChatMember + language_code
+    - BotCommandScopeChatMember
+    - BotCommandScopeChatAdministrators + language_code (administrators only)
+    - BotCommandScopeChatAdministrators (administrators only)
+    - BotCommandScopeChat + language_code
+    - BotCommandScopeChat
+    - BotCommandScopeAllChatAdministrators + language_code (administrators only)
+    - BotCommandScopeAllChatAdministrators (administrators only)
+    - BotCommandScopeAllGroupChats + language_code
+    - BotCommandScopeAllGroupChats
+    - BotCommandScopeDefault + language_code
+    - BotCommandScopeDefault
+    """
+
+    def __init__(self, type: str):
+        super().__init__()
+
+        self.type = type
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        raise NotImplementedError
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_all_chat_administrators.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_chat_administrators.py
new file mode 100644
index 0000000000..0cc6339c77
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_chat_administrators.py
@@ -0,0 +1,32 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeAllChatAdministrators(BotCommandScope):
+    """Represents the scope of bot commands, covering all group and supergroup chat administrators.
+    """
+
+    def __init__(self):
+        super().__init__("all_chat_administrators")
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopeChatAdmins()
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_all_group_chats.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_group_chats.py
new file mode 100644
index 0000000000..5f8457f61d
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_group_chats.py
@@ -0,0 +1,32 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeAllGroupChats(BotCommandScope):
+    """Represents the scope of bot commands, covering all group and supergroup chats.
+    """
+
+    def __init__(self):
+        super().__init__("all_group_chats")
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopeChats()
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_all_private_chats.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_private_chats.py
new file mode 100644
index 0000000000..14b80f0dcd
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_all_private_chats.py
@@ -0,0 +1,32 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeAllPrivateChats(BotCommandScope):
+    """Represents the scope of bot commands, covering all private chats.
+    """
+
+    def __init__(self):
+        super().__init__("all_private_chats")
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopeUsers()
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_chat.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat.py
new file mode 100644
index 0000000000..28912383b7
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat.py
@@ -0,0 +1,43 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Union
+
+import pyrogram
+from pyrogram import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeChat(BotCommandScope):
+    """Represents the scope of bot commands, covering a specific chat.
+
+    Parameters:
+        chat_id (``int`` | ``str``):
+            Unique identifier for the target chat or username of the target supergroup (in the format
+            @supergroupusername).
+    """
+
+    def __init__(self, chat_id: Union[int, str]):
+        super().__init__("chat")
+
+        self.chat_id = chat_id
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopePeer(
+            peer=await client.resolve_peer(self.chat_id)
+        )
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_administrators.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_administrators.py
new file mode 100644
index 0000000000..6f42a29f2b
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_administrators.py
@@ -0,0 +1,43 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Union
+
+import pyrogram
+from pyrogram import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeChatAdministrators(BotCommandScope):
+    """Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat.
+
+    Parameters:
+        chat_id (``int`` | ``str``):
+            Unique identifier for the target chat or username of the target supergroup (in the format
+            @supergroupusername).
+    """
+
+    def __init__(self, chat_id: Union[int, str]):
+        super().__init__("chat_administrators")
+
+        self.chat_id = chat_id
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopePeerAdmins(
+            peer=await client.resolve_peer(self.chat_id)
+        )
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_member.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_member.py
new file mode 100644
index 0000000000..8d91df1413
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_chat_member.py
@@ -0,0 +1,48 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Union
+
+import pyrogram
+from pyrogram import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeChatMember(BotCommandScope):
+    """Represents the scope of bot commands, covering a specific member of a group or supergroup chat.
+
+    Parameters:
+        chat_id (``int`` | ``str``):
+            Unique identifier for the target chat or username of the target supergroup (in the format
+            @supergroupusername).
+
+        user_id (``int`` | ``str``):
+            Unique identifier of the target user.
+    """
+
+    def __init__(self, chat_id: Union[int, str], user_id: Union[int, str]):
+        super().__init__("chat_member")
+
+        self.chat_id = chat_id
+        self.user_id = user_id
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopePeerUser(
+            peer=await client.resolve_peer(self.chat_id),
+            user_id=await client.resolve_peer(self.user_id)
+        )
diff --git a/pyrogram/types/bots_and_keyboards/bot_command_scope_default.py b/pyrogram/types/bots_and_keyboards/bot_command_scope_default.py
new file mode 100644
index 0000000000..d11ab012f8
--- /dev/null
+++ b/pyrogram/types/bots_and_keyboards/bot_command_scope_default.py
@@ -0,0 +1,33 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .bot_command_scope import BotCommandScope
+
+
+class BotCommandScopeDefault(BotCommandScope):
+    """Represents the default scope of bot commands.
+    Default commands are used if no commands with a narrower scope are specified for the user.
+    """
+
+    def __init__(self):
+        super().__init__("default")
+
+    async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope":
+        return raw.types.BotCommandScopeDefault()

From 190760cf0eb3e90bc682b05fe54932295211c2cf Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 28 Mar 2022 13:25:59 +0200
Subject: [PATCH 110/539] Update Pyrogram to v1.4.10

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index ebb3b16355..8c1336c30e 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.9"
+__version__ = "1.4.10"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 06ee482b2331e94c6494248a59d10ab53ba15a24 Mon Sep 17 00:00:00 2001
From: andrew-ld <43882924+andrew-ld@users.noreply.github.com>
Date: Mon, 28 Mar 2022 20:10:52 +0200
Subject: [PATCH 111/539] Faster RLE codec implementation (#938)

* faster pyrogram lre encode implementation

* Update file_id.py

* optimized rle decode

Co-authored-by: andrew (from workstation) 
Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/file_id.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/pyrogram/file_id.py b/pyrogram/file_id.py
index 95f6ccbf1a..1a54a49d61 100644
--- a/pyrogram/file_id.py
+++ b/pyrogram/file_id.py
@@ -21,6 +21,7 @@
 import struct
 from enum import IntEnum
 from io import BytesIO
+from typing import List
 
 from pyrogram.raw.core import Bytes, String
 
@@ -63,7 +64,7 @@ def rle_encode(s: bytes) -> bytes:
     Returns:
         ``bytes``: The encoded bytes
     """
-    r: bytes = b""
+    r: List[int] = []
     n: int = 0
 
     for b in s:
@@ -71,15 +72,15 @@ def rle_encode(s: bytes) -> bytes:
             n += 1
         else:
             if n:
-                r += bytes([0, n])
+                r.extend((0, n))
                 n = 0
 
-            r += bytes([b])
+            r.append(b)
 
     if n:
-        r += bytes([0, n])
+        r.extend((0, n))
 
-    return r
+    return bytes(r)
 
 
 def rle_decode(s: bytes) -> bytes:
@@ -87,12 +88,12 @@ def rle_decode(s: bytes) -> bytes:
 
     Parameters:
         s (``bytes``):
-            Bytes to encode
+            Bytes to decode
 
     Returns:
-        ``bytes``: The encoded bytes
+        ``bytes``: The decoded bytes
     """
-    r: bytes = b""
+    r: List[int] = []
     z: bool = False
 
     for b in s:
@@ -101,12 +102,12 @@ def rle_decode(s: bytes) -> bytes:
             continue
 
         if z:
-            r += b"\x00" * b
+            r.extend((0,) * b)
             z = False
         else:
-            r += bytes([b])
+            r.append(b)
 
-    return r
+    return bytes(r)
 
 
 class FileType(IntEnum):

From e50b58980a68a589617f9dcfce0c52f1830b32c5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 28 Mar 2022 20:13:46 +0200
Subject: [PATCH 112/539] Update Pyrogram to v1.4.11

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 8c1336c30e..654ff35355 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.10"
+__version__ = "1.4.11"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 0825b977ea8936b650f6710d386b54fddd9ec673 Mon Sep 17 00:00:00 2001
From: Krishna-singhal <65902764+Krishna-Singhal@users.noreply.github.com>
Date: Tue, 29 Mar 2022 00:33:37 +0530
Subject: [PATCH 113/539] Add bound method Message.react (#937)

* Bound method `react` to send reaction

* Update message.py

* Update message.py

* Update compiler.py

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 compiler/docs/compiler.py                    |  1 +
 pyrogram/types/messages_and_media/message.py | 36 ++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 118c0e636f..75c37a7f55 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -518,6 +518,7 @@ def get_title_list(s: str) -> list:
             Message.reply_video_note
             Message.reply_voice
             Message.get_media_group
+            Message.react
         """,
         chat="""
         Chat
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index ea54231d70..597fe60581 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -3286,6 +3286,42 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None,
         else:
             await self.reply(button, quote=quote)
 
+    async def react(self, emoji: str = "") -> bool:
+        """Bound method *react* of :obj:`~pyrogram.types.Message`.
+
+        Use as a shortcut for:
+
+        .. code-block:: python
+
+            client.send_reaction(
+                chat_id=chat_id,
+                message_id=message.message_id,
+                emoji="🔥"
+            )
+
+        Example:
+            .. code-block:: python
+
+                message.react(emoji="🔥")
+
+        Parameters:
+            emoji (``str``, *optional*):
+                Reaction emoji.
+                Pass "" as emoji (default) to retract the reaction.
+
+        Returns:
+            ``bool``: On success, True is returned.
+
+        Raises:
+            RPCError: In case of a Telegram RPC error.
+        """
+
+        return await self._client.send_reaction(
+            chat_id=self.chat.id,
+            message_id=self.message_id,
+            emoji=emoji
+        )
+
     async def retract_vote(
         self,
     ) -> "types.Poll":

From 71f3125c6b592868a13fbc645176188a05861686 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 28 Mar 2022 21:04:25 +0200
Subject: [PATCH 114/539] Update Pyrogram to v1.4.12

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 654ff35355..009c75c269 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.11"
+__version__ = "1.4.12"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 688c24bc3ec12674ad691cd68510fd0c0333725c Mon Sep 17 00:00:00 2001
From: Nick <64551534+null-nick@users.noreply.github.com>
Date: Mon, 11 Apr 2022 11:16:26 +0200
Subject: [PATCH 115/539] Update API schema to Layer 140 (#949)

---
 compiler/api/source/main_api.tl | 73 +++++++++++++++++++++++++++++----
 1 file changed, 64 insertions(+), 9 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 5bd7dfb568..cb4bf0ac1c 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -88,7 +88,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType;
 storage.fileWebp#1081464c = storage.FileType;
 
 userEmpty#d3bc4b7a id:long = User;
-user#3ff6ecb0 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User;
+user#3ff6ecb0 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User;
 
 userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto;
 userProfilePhoto#82d1f706 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto;
@@ -101,13 +101,13 @@ userStatusLastWeek#7bf09fc = UserStatus;
 userStatusLastMonth#77ebc742 = UserStatus;
 
 chatEmpty#29562865 id:long = Chat;
-chat#41cbf256 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true deactivated:flags.5?true call_active:flags.23?true call_not_empty:flags.24?true noforwards:flags.25?true id:long title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat;
+chat#41cbf256 flags:# creator:flags.0?true left:flags.2?true deactivated:flags.5?true call_active:flags.23?true call_not_empty:flags.24?true noforwards:flags.25?true id:long title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat;
 chatForbidden#6592a1a7 id:long title:string = Chat;
 channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
 channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat;
 
 chatFull#d18ee226 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?Vector = ChatFull;
-channelFull#e13c3d20 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?Vector = ChatFull;
+channelFull#ea68a619 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?Vector = ChatFull;
 
 chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant;
 chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant;
@@ -167,6 +167,8 @@ messageActionSetMessagesTTL#aa1afbfd period:int = MessageAction;
 messageActionGroupCallScheduled#b3a07661 call:InputGroupCall schedule_date:int = MessageAction;
 messageActionSetChatTheme#aa786345 emoticon:string = MessageAction;
 messageActionChatJoinedByRequest#ebbca3cb = MessageAction;
+messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction;
+messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction;
 
 dialog#a8edd0f5 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
 dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
@@ -196,9 +198,9 @@ inputNotifyUsers#193b4417 = InputNotifyPeer;
 inputNotifyChats#4a95e84e = InputNotifyPeer;
 inputNotifyBroadcasts#b1db7c7e = InputNotifyPeer;
 
-inputPeerNotifySettings#9c3d198e flags:# show_previews:flags.0?Bool silent:flags.1?Bool mute_until:flags.2?int sound:flags.3?string = InputPeerNotifySettings;
+inputPeerNotifySettings#df1f002b flags:# show_previews:flags.0?Bool silent:flags.1?Bool mute_until:flags.2?int sound:flags.3?NotificationSound = InputPeerNotifySettings;
 
-peerNotifySettings#af509d20 flags:# show_previews:flags.0?Bool silent:flags.1?Bool mute_until:flags.2?int sound:flags.3?string = PeerNotifySettings;
+peerNotifySettings#a83b0426 flags:# show_previews:flags.0?Bool silent:flags.1?Bool mute_until:flags.2?int ios_sound:flags.3?NotificationSound android_sound:flags.4?NotificationSound other_sound:flags.5?NotificationSound = PeerNotifySettings;
 
 peerSettings#a518110d flags:# report_spam:flags.0?true add_contact:flags.1?true block_contact:flags.2?true share_contact:flags.3?true need_contacts_exception:flags.4?true report_geo:flags.5?true autoarchived:flags.7?true invite_members:flags.8?true request_chat_broadcast:flags.10?true geo_distance:flags.6?int request_chat_title:flags.9?string request_chat_date:flags.9?int = PeerSettings;
 
@@ -216,7 +218,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason;
 inputReportReasonIllegalDrugs#a8eb2be = ReportReason;
 inputReportReasonPersonalDetails#9ec7863d = ReportReason;
 
-userFull#cf366521 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string = UserFull;
+userFull#8c72ea81 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights = UserFull;
 
 contact#145ade0b user_id:long mutual:Bool = Contact;
 
@@ -362,6 +364,10 @@ updateBotCommands#4d712f2e peer:Peer bot_id:long commands:Vector = U
 updatePendingJoinRequests#7063c3db peer:Peer requests_pending:int recent_requesters:Vector = Update;
 updateBotChatInviteRequester#11dfa986 peer:Peer date:int user_id:long about:string invite:ExportedChatInvite qts:int = Update;
 updateMessageReactions#154798c3 peer:Peer msg_id:int reactions:MessageReactions = Update;
+updateAttachMenuBots#17b7a20b = Update;
+updateWebViewResultSent#1592b79d query_id:long = Update;
+updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update;
+updateSavedRingtones#74d8be99 = Update;
 
 updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
 
@@ -553,7 +559,7 @@ messages.stickerSetNotModified#d3f924eb = messages.StickerSet;
 
 botCommand#c27ac8c7 command:string description:string = BotCommand;
 
-botInfo#1b74b335 user_id:long description:string commands:Vector = BotInfo;
+botInfo#e4169b5d user_id:long description:string commands:Vector menu_button:BotMenuButton = BotInfo;
 
 keyboardButton#a2fa4880 text:string = KeyboardButton;
 keyboardButtonUrl#258aff05 text:string url:string = KeyboardButton;
@@ -568,6 +574,8 @@ inputKeyboardButtonUrlAuth#d02e7fd4 flags:# request_write_access:flags.0?true te
 keyboardButtonRequestPoll#bbc7515d flags:# quiz:flags.0?Bool text:string = KeyboardButton;
 inputKeyboardButtonUserProfile#e988037b text:string user_id:InputUser = KeyboardButton;
 keyboardButtonUserProfile#308660c1 text:string user_id:long = KeyboardButton;
+keyboardButtonWebView#13767230 text:string url:string = KeyboardButton;
+keyboardButtonSimpleWebView#a0c0505c text:string url:string = KeyboardButton;
 
 keyboardButtonRow#77608b83 buttons:Vector = KeyboardButtonRow;
 
@@ -1307,6 +1315,38 @@ phone.groupCallStreamChannels#d0e482b2 channels:Vector =
 
 phone.groupCallStreamRtmpUrl#2dbf3432 url:string key:string = phone.GroupCallStreamRtmpUrl;
 
+attachMenuBotIconColor#4576f3f0 name:string color:int = AttachMenuBotIconColor;
+
+attachMenuBotIcon#b2a7386b flags:# name:string icon:Document colors:flags.0?Vector = AttachMenuBotIcon;
+
+attachMenuBot#e93cb772 flags:# inactive:flags.0?true bot_id:long short_name:string icons:Vector = AttachMenuBot;
+
+attachMenuBotsNotModified#f1d88a5c = AttachMenuBots;
+attachMenuBots#3c4301c0 hash:long bots:Vector users:Vector = AttachMenuBots;
+
+attachMenuBotsBot#93bf667f bot:AttachMenuBot users:Vector = AttachMenuBotsBot;
+
+webViewResultUrl#c14557c query_id:long url:string = WebViewResult;
+
+simpleWebViewResultUrl#882f76bb url:string = SimpleWebViewResult;
+
+webViewMessageSent#c94511c flags:# msg_id:flags.0?InputBotInlineMessageID = WebViewMessageSent;
+
+botMenuButtonDefault#7533a588 = BotMenuButton;
+botMenuButtonCommands#4258c205 = BotMenuButton;
+botMenuButton#c7b57ce6 text:string url:string = BotMenuButton;
+
+account.savedRingtonesNotModified#fbf6e8b1 = account.SavedRingtones;
+account.savedRingtones#c1e92cc5 hash:long ringtones:Vector = account.SavedRingtones;
+
+notificationSoundDefault#97e8bebe = NotificationSound;
+notificationSoundNone#6f0c34df = NotificationSound;
+notificationSoundLocal#830b9ae4 title:string data:string = NotificationSound;
+notificationSoundRingtone#ff6c8049 id:long = NotificationSound;
+
+account.savedRingtone#b7263f6d = account.SavedRingtone;
+account.savedRingtoneConverted#1f307eb7 document:Document = account.SavedRingtone;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1410,6 +1450,9 @@ account.declinePasswordReset#4c9409f6 = Bool;
 account.getChatThemes#d638de89 hash:long = account.Themes;
 account.setAuthorizationTTL#bf899aa0 authorization_ttl_days:int = Bool;
 account.changeAuthorizationSettings#40f48462 flags:# hash:long encrypted_requests_disabled:flags.0?Bool call_requests_disabled:flags.1?Bool = Bool;
+account.getSavedRingtones#e1902288 hash:long = account.SavedRingtones;
+account.saveRingtone#3dea5b03 id:InputDocument unsave:Bool = account.SavedRingtone;
+account.uploadRingtone#831a83a2 file:InputFile file_name:string mime_type:string = Document;
 
 users.getUsers#d91a548 id:Vector = Vector;
 users.getFullUser#b60f5918 id:InputUser = users.UserFull;
@@ -1596,6 +1639,14 @@ messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?in
 messages.getUnreadReactions#e85bae1a peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
 messages.readReactions#82e251d7 peer:InputPeer = messages.AffectedHistory;
 messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = messages.Messages;
+messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots;
+messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
+messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool;
+messages.requestWebView#fa04dff flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int = WebViewResult;
+messages.prolongWebView#d22ad148 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int = Bool;
+messages.requestSimpleWebView#6abb2f73 flags:# bot:InputUser url:string theme_params:flags.0?DataJSON = SimpleWebViewResult;
+messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
+messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1663,7 +1714,7 @@ channels.editBanned#96e6cd81 channel:InputChannel participant:InputPeer banned_r
 channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector max_id:long min_id:long limit:int = channels.AdminLogResults;
 channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = Bool;
 channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool;
-channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool;
+channels.deleteHistory#9baa9647 flags:# for_everyone:flags.0?true channel:InputChannel max_id:int = Updates;
 channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates;
 channels.getLeftChannels#8341ecc0 offset:int = messages.Chats;
 channels.getGroupsForDiscussion#f5dad378 = messages.Chats;
@@ -1683,6 +1734,10 @@ bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool;
 bots.setBotCommands#517165a scope:BotCommandScope lang_code:string commands:Vector = Bool;
 bots.resetBotCommands#3d8de0f9 scope:BotCommandScope lang_code:string = Bool;
 bots.getBotCommands#e34c0dd6 scope:BotCommandScope lang_code:string = Vector;
+bots.setBotMenuButton#4504d54f user_id:InputUser button:BotMenuButton = Bool;
+bots.getBotMenuButton#9c60eb28 user_id:InputUser = BotMenuButton;
+bots.setBotBroadcastDefaultAdminRights#788464e1 admin_rights:ChatAdminRights = Bool;
+bots.setBotGroupDefaultAdminRights#925ec9ea admin_rights:ChatAdminRights = Bool;
 
 payments.getPaymentForm#8a333c8d flags:# peer:InputPeer msg_id:int theme_params:flags.0?DataJSON = payments.PaymentForm;
 payments.getPaymentReceipt#2478d1cc peer:InputPeer msg_id:int = payments.PaymentReceipt;
@@ -1746,4 +1801,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 139
\ No newline at end of file
+// LAYER 140

From a4fe5fbfc89fd9ab815144feda697b8f4d09bed5 Mon Sep 17 00:00:00 2001
From: dogghi <75123663+doggyhaha@users.noreply.github.com>
Date: Mon, 11 Apr 2022 11:21:28 +0200
Subject: [PATCH 116/539] Add missing on_chat_join_request decorator to docs
 (#947)

---
 docs/source/api/decorators.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/docs/source/api/decorators.rst b/docs/source/api/decorators.rst
index fa0e7ad337..130f15ceb6 100644
--- a/docs/source/api/decorators.rst
+++ b/docs/source/api/decorators.rst
@@ -40,6 +40,7 @@ Index
     - :meth:`~Client.on_inline_query`
     - :meth:`~Client.on_chosen_inline_result`
     - :meth:`~Client.on_chat_member_updated`
+    - :meth:`~Client.on_chat_join_request`
     - :meth:`~Client.on_deleted_messages`
     - :meth:`~Client.on_user_status`
     - :meth:`~Client.on_poll`
@@ -57,8 +58,9 @@ Details
 .. autodecorator:: pyrogram.Client.on_inline_query()
 .. autodecorator:: pyrogram.Client.on_chosen_inline_result()
 .. autodecorator:: pyrogram.Client.on_chat_member_updated()
+.. autodecorator:: pyrogram.Client.on_chat_join_request()
 .. autodecorator:: pyrogram.Client.on_deleted_messages()
 .. autodecorator:: pyrogram.Client.on_user_status()
 .. autodecorator:: pyrogram.Client.on_poll()
 .. autodecorator:: pyrogram.Client.on_disconnect()
-.. autodecorator:: pyrogram.Client.on_raw_update()
\ No newline at end of file
+.. autodecorator:: pyrogram.Client.on_raw_update()

From 8b92ac8b7ff01533cd8aca11a722c9484da3b755 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 12:46:29 +0200
Subject: [PATCH 117/539] Add support for multiple TL flags

---
 compiler/api/compiler.py | 42 +++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 150fa49d37..b8cf8b0c60 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -34,9 +34,9 @@
 LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
 COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$", re.MULTILINE)
 ARGS_RE = re.compile(r"[^{](\w+):([\w?!.<>#]+)")
-FLAGS_RE = re.compile(r"flags\.(\d+)\?")
-FLAGS_RE_2 = re.compile(r"flags\.(\d+)\?([\w<>.]+)")
-FLAGS_RE_3 = re.compile(r"flags:#")
+FLAGS_RE = re.compile(r"flags(\d?).(\d+)\?")
+FLAGS_RE_2 = re.compile(r"flags(\d?)\.(\d+)\?([\w<>.]+)")
+FLAGS_RE_3 = re.compile(r"flags(\d?):#")
 INT_RE = re.compile(r"int(\d+)")
 
 CORE_TYPES = ["int", "long", "int128", "int256", "double", "bytes", "string", "Bool", "true"]
@@ -131,10 +131,9 @@ def sort_args(args):
     for i in flags:
         args.remove(i)
 
-    try:
-        args.remove(("flags", "#"))
-    except ValueError:
-        pass
+    for i in args[:]:
+        if re.match(r"flags\d?", i[0]):
+            args.remove(i)
 
     return args + flags
 
@@ -401,42 +400,45 @@ def start(format: bool = False):
         for arg_name, arg_type in c.args:
             flag = FLAGS_RE_2.match(arg_type)
 
-            if arg_name == "flags" and arg_type == "#":
+            if re.match(r"flags\d?", arg_name) and arg_type == "#":
                 write_flags = []
 
                 for i in c.args:
                     flag = FLAGS_RE_2.match(i[1])
 
                     if flag:
-                        if flag.group(2) == "true" or flag.group(2).startswith("Vector"):
-                            write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} else 0")
+                        if arg_name != f"flags{flag.group(1)}":
+                            continue
+
+                        if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
+                            write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
                         else:
-                            write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0")
+                            write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
 
                 write_flags = "\n        ".join([
-                    "flags = 0",
+                    f"{arg_name} = 0",
                     "\n        ".join(write_flags),
-                    "b.write(Int(flags))\n        "
+                    f"b.write(Int({arg_name}))\n        "
                 ])
 
                 write_types += write_flags
-                read_types += "flags = Int.read(b)\n        "
+                read_types += f"\n        {arg_name} = Int.read(b)\n        "
 
                 continue
 
             if flag:
-                index, flag_type = flag.groups()
+                number, index, flag_type = flag.groups()
 
                 if flag_type == "true":
                     read_types += "\n        "
-                    read_types += f"{arg_name} = True if flags & (1 << {index}) else False"
+                    read_types += f"{arg_name} = True if flags{number} & (1 << {index}) else False"
                 elif flag_type in CORE_TYPES:
                     write_types += "\n        "
                     write_types += f"if self.{arg_name} is not None:\n            "
                     write_types += f"b.write({flag_type.title()}(self.{arg_name}))\n        "
 
                     read_types += "\n        "
-                    read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags & (1 << {index}) else None"
+                    read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags{number} & (1 << {index}) else None"
                 elif "vector" in flag_type.lower():
                     sub_type = arg_type.split("<")[1][:-1]
 
@@ -447,8 +449,8 @@ def start(format: bool = False):
                     )
 
                     read_types += "\n        "
-                    read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else []\n        ".format(
-                        arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", index
+                    read_types += "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n        ".format(
+                        arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", number, index
                     )
                 else:
                     write_types += "\n        "
@@ -456,7 +458,7 @@ def start(format: bool = False):
                     write_types += f"b.write(self.{arg_name}.write())\n        "
 
                     read_types += "\n        "
-                    read_types += f"{arg_name} = TLObject.read(b) if flags & (1 << {index}) else None\n        "
+                    read_types += f"{arg_name} = TLObject.read(b) if flags{number} & (1 << {index}) else None\n        "
             else:
                 if arg_type in CORE_TYPES:
                     write_types += "\n        "

From 2017493c9e949cb2eec4e70c077e14341776bcc1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 12:54:19 +0200
Subject: [PATCH 118/539] Update Pyrogram to v1.4.13

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 009c75c269..dccbe3ba49 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.12"
+__version__ = "1.4.13"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 849321e5ca7eb2e636aa9a497bd08ed71f0b89da Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 14:27:20 +0200
Subject: [PATCH 119/539] Remove unneeded parts

---
 compiler/api/compiler.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index b8cf8b0c60..4f83cf0a6f 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -361,14 +361,12 @@ def start(format: bool = False):
 
         for i, arg in enumerate(sorted_args):
             arg_name, arg_type = arg
-            is_optional = FLAGS_RE.match(arg_type)
-            flag_number = is_optional.group(1) if is_optional else -1
             arg_type = arg_type.split("?")[-1]
 
             docstring_args.append(
                 "{}{}: {}".format(
                     arg_name,
-                    " (optional)".format(flag_number) if is_optional else "",
+                    " (optional)",
                     get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
                 )
             )
@@ -413,7 +411,8 @@ def start(format: bool = False):
                         if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
                             write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
                         else:
-                            write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
+                            write_flags.append(
+                                f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
 
                 write_flags = "\n        ".join([
                     f"{arg_name} = 0",

From e8250bd576a23dbe60e2dfe4a929aff1565713ed Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 14:29:17 +0200
Subject: [PATCH 120/539] Add missing backslash to the pattern

---
 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 4f83cf0a6f..cc8be2d7b4 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -34,7 +34,7 @@
 LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
 COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$", re.MULTILINE)
 ARGS_RE = re.compile(r"[^{](\w+):([\w?!.<>#]+)")
-FLAGS_RE = re.compile(r"flags(\d?).(\d+)\?")
+FLAGS_RE = re.compile(r"flags(\d?)\.(\d+)\?")
 FLAGS_RE_2 = re.compile(r"flags(\d?)\.(\d+)\?([\w<>.]+)")
 FLAGS_RE_3 = re.compile(r"flags(\d?):#")
 INT_RE = re.compile(r"int(\d+)")

From 82b029c3bf66ce11cde0bfafda6359964feb10f6 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 14:34:29 +0200
Subject: [PATCH 121/539] Use Optional[Type] instead of Union[Type, None]

---
 compiler/api/compiler.py             | 2 +-
 compiler/api/template/combinator.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index cc8be2d7b4..adc6cfff70 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -115,7 +115,7 @@ def get_type_hint(type: str) -> str:
         type = f"List[{get_type_hint(sub_type)}]"
 
     if is_core:
-        return f"Union[None, {type}] = None" if is_flag else type
+        return f"Optional[{type}] = None" if is_flag else type
     else:
         ns, name = type.split(".") if "." in type else ("", type)
         type = f'"raw.base.' + ".".join([ns, name]).strip(".") + '"'
diff --git a/compiler/api/template/combinator.txt b/compiler/api/template/combinator.txt
index e0275dd104..7c02a1a8e5 100644
--- a/compiler/api/template/combinator.txt
+++ b/compiler/api/template/combinator.txt
@@ -5,7 +5,7 @@ from io import BytesIO
 from pyrogram.raw.core.primitives import Int, Long, Int128, Int256, Bool, Bytes, String, Double, Vector
 from pyrogram.raw.core import TLObject
 from pyrogram import raw
-from typing import List, Union, Any
+from typing import List, Optional, Any
 
 {warning}
 

From d6c80ff0f97992c7a2473d3a80e2518130322770 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 14:52:59 +0200
Subject: [PATCH 122/539] Fix non-flags parameters with the same name "flags"
 being treated as TL flags

---
 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 adc6cfff70..a65149948f 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -132,7 +132,7 @@ def sort_args(args):
         args.remove(i)
 
     for i in args[:]:
-        if re.match(r"flags\d?", i[0]):
+        if re.match(r"flags\d?", i[0]) and i[1] == "#":
             args.remove(i)
 
     return args + flags

From 16de8b7325b530349d06c862b26c6305d5065cbc Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 14:53:31 +0200
Subject: [PATCH 123/539] Update Pyrogram to v1.4.14

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index dccbe3ba49..c5e1570da3 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.13"
+__version__ = "1.4.14"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 0c0a4b5a5c8f20a0df9dcea843271d3ab0009c68 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 11 Apr 2022 15:17:16 +0200
Subject: [PATCH 124/539] Remove unneeded parameter hide_via from
 send_inline_bot_result

---
 pyrogram/methods/bots/send_inline_bot_result.py | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py
index de00546c13..ead95810b5 100644
--- a/pyrogram/methods/bots/send_inline_bot_result.py
+++ b/pyrogram/methods/bots/send_inline_bot_result.py
@@ -29,8 +29,7 @@ async def send_inline_bot_result(
         query_id: int,
         result_id: str,
         disable_notification: bool = None,
-        reply_to_message_id: int = None,
-        hide_via: bool = None
+        reply_to_message_id: int = None
     ):
         """Send an inline bot result.
         Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
@@ -54,9 +53,6 @@ async def send_inline_bot_result(
             reply_to_message_id (``bool``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            hide_via (``bool``):
-                Sends the message with *via @bot* hidden.
-
         Returns:
             :obj:`~pyrogram.types.Message`: On success, the sent inline result message is returned.
 
@@ -72,7 +68,6 @@ async def send_inline_bot_result(
                 id=result_id,
                 random_id=self.rnd_id(),
                 silent=disable_notification or None,
-                reply_to_msg_id=reply_to_message_id,
-                hide_via=hide_via or None
+                reply_to_msg_id=reply_to_message_id
             )
         )

From 874709c2585c10c073544755756f642e1976054c Mon Sep 17 00:00:00 2001
From: Tofik Denianto <77754555+tofikdn@users.noreply.github.com>
Date: Tue, 12 Apr 2022 04:52:32 +0700
Subject: [PATCH 125/539] Remove hide_via param from reply_inline_bot_result
 (#952)

---
 pyrogram/types/messages_and_media/message.py | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 597fe60581..e6aa25268a 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -1668,8 +1668,7 @@ async def reply_inline_bot_result(
         result_id: str,
         quote: bool = None,
         disable_notification: bool = None,
-        reply_to_message_id: int = None,
-        hide_via: bool = None
+        reply_to_message_id: int = None
     ) -> "Message":
         """Bound method *reply_inline_bot_result* of :obj:`~pyrogram.types.Message`.
 
@@ -1707,9 +1706,6 @@ async def reply_inline_bot_result(
             reply_to_message_id (``bool``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            hide_via (``bool``):
-                Sends the message with *via @bot* hidden.
-
         Returns:
             On success, the sent Message is returned.
 
@@ -1727,8 +1723,7 @@ async def reply_inline_bot_result(
             query_id=query_id,
             result_id=result_id,
             disable_notification=disable_notification,
-            reply_to_message_id=reply_to_message_id,
-            hide_via=hide_via
+            reply_to_message_id=reply_to_message_id
         )
 
     async def reply_location(

From 69a50fb3b2f77c5f14619ddf5ce8d6762bfd38d7 Mon Sep 17 00:00:00 2001
From: Danstiv <50794055+Danstiv@users.noreply.github.com>
Date: Tue, 12 Apr 2022 19:01:40 +0700
Subject: [PATCH 126/539] Fix TLObject.__repr__ (#953)

* Fix __repr__ method

* Style fixes

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/raw/core/tl_object.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pyrogram/raw/core/tl_object.py b/pyrogram/raw/core/tl_object.py
index b094f7d035..7cb75b0eb5 100644
--- a/pyrogram/raw/core/tl_object.py
+++ b/pyrogram/raw/core/tl_object.py
@@ -53,6 +53,9 @@ def __str__(self) -> str:
         return dumps(self, indent=4, default=TLObject.default, ensure_ascii=False)
 
     def __repr__(self) -> str:
+        if not hasattr(self, "QUALNAME"):
+            return repr(self)
+
         return "pyrogram.raw.{}({})".format(
             self.QUALNAME,
             ", ".join(

From cb3d389b9d291ff2fa056fa5a737773382e13b19 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 12 Apr 2022 14:03:09 +0200
Subject: [PATCH 127/539] Update Pyrogram to v1.4.15

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index c5e1570da3..eea5848293 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.14"
+__version__ = "1.4.15"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From acc2c72d6de913e6899fabea35950dd5401cb12f Mon Sep 17 00:00:00 2001
From: Shohih Abdul <50512936+DoellBarr@users.noreply.github.com>
Date: Fri, 15 Apr 2022 01:34:55 +0700
Subject: [PATCH 128/539] Improve type hinting for join_chat method (#957)

---
 pyrogram/methods/chats/join_chat.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py
index ca720d6d0b..3f1a09f998 100644
--- a/pyrogram/methods/chats/join_chat.py
+++ b/pyrogram/methods/chats/join_chat.py
@@ -27,7 +27,7 @@ class JoinChat(Scaffold):
     async def join_chat(
         self,
         chat_id: Union[int, str]
-    ):
+    ) -> "types.Chat":
         """Join a group chat or channel.
 
         Parameters:

From 7a5ab4bffa85dc25e43ee7a088341c88f3a5ae05 Mon Sep 17 00:00:00 2001
From: Marco Burro 
Date: Fri, 15 Apr 2022 11:35:21 +0200
Subject: [PATCH 129/539] Fix inline query results typing (#958)

---
 pyrogram/methods/bots/answer_inline_query.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py
index 9683e1bb34..24e7a30c78 100644
--- a/pyrogram/methods/bots/answer_inline_query.py
+++ b/pyrogram/methods/bots/answer_inline_query.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import List
+from typing import Iterable
 
 from pyrogram import raw
 from pyrogram import types
@@ -27,7 +27,7 @@ class AnswerInlineQuery(Scaffold):
     async def answer_inline_query(
         self,
         inline_query_id: str,
-        results: List["types.InlineQueryResult"],
+        results: Iterable["types.InlineQueryResult"],
         cache_time: int = 300,
         is_gallery: bool = False,
         is_personal: bool = False,

From 1c225776c921c054f271b9f9df6fe4a08e2284e2 Mon Sep 17 00:00:00 2001
From: Mahesh <44301650+Mahesh0253@users.noreply.github.com>
Date: Fri, 15 Apr 2022 17:25:03 +0530
Subject: [PATCH 130/539] Removed unnecessary create_task (#706)

---
 pyrogram/methods/advanced/save_file.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py
index b612b1124f..3f6ebb68af 100644
--- a/pyrogram/methods/advanced/save_file.py
+++ b/pyrogram/methods/advanced/save_file.py
@@ -103,7 +103,7 @@ async def worker(session):
                     return
 
                 try:
-                    await self.loop.create_task(session.send(data))
+                    await session.send(data)
                 except Exception as e:
                     log.error(e)
 

From abc84b829af6a78c273ab4b0e530c3794fd84f73 Mon Sep 17 00:00:00 2001
From: Stark Programmer <88478059+StarkBotsIndustries@users.noreply.github.com>
Date: Sat, 16 Apr 2022 22:03:26 +0530
Subject: [PATCH 131/539] Add bound method Chat.unpin_all_messages (#959)

---
 compiler/docs/compiler.py             |  1 +
 pyrogram/types/user_and_chats/chat.py | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 75c37a7f55..fdee4e8fcf 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -539,6 +539,7 @@ def get_title_list(s: str) -> list:
             Chat.leave
             Chat.mark_unread
             Chat.set_protected_content
+            Chat.unpin_all_messages
         """,
         user="""
         User
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 6dc3fb8264..7ca8f2085e 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -1047,3 +1047,23 @@ async def set_protected_content(self, enabled: bool) -> bool:
             self.id,
             enabled=enabled
         )
+
+    async def unpin_all_messages(self) -> bool:
+        """Bound method *unpin_all_messages* of :obj:`~pyrogram.types.Chat`.
+
+        Use as a shortcut for:
+
+        .. code-block:: python
+
+            client.unpin_all_chat_messages(chat_id)
+
+        Example:
+            .. code-block:: python
+
+                chat.unpin_all_messages()
+
+        Returns:
+            ``bool``: On success, True is returned.
+        """
+
+        return await self._client.unpin_all_chat_messages(self.id)

From 42fdb03d243badad7ae72606219c874a57ca13e2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 16 Apr 2022 20:01:38 +0200
Subject: [PATCH 132/539] Revert "Remove unneeded parts"

This reverts commit 849321e5ca7eb2e636aa9a497bd08ed71f0b89da.
---
 compiler/api/compiler.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index a65149948f..97dbdf0a60 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -361,12 +361,14 @@ def start(format: bool = False):
 
         for i, arg in enumerate(sorted_args):
             arg_name, arg_type = arg
+            is_optional = FLAGS_RE.match(arg_type)
+            flag_number = is_optional.group(1) if is_optional else -1
             arg_type = arg_type.split("?")[-1]
 
             docstring_args.append(
                 "{}{}: {}".format(
                     arg_name,
-                    " (optional)",
+                    " (optional)".format(flag_number) if is_optional else "",
                     get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
                 )
             )
@@ -411,8 +413,7 @@ def start(format: bool = False):
                         if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
                             write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
                         else:
-                            write_flags.append(
-                                f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
+                            write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
 
                 write_flags = "\n        ".join([
                     f"{arg_name} = 0",

From 1885acd59437f5d99a5021747950b1826925f7e5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 16 Apr 2022 20:02:10 +0200
Subject: [PATCH 133/539] Reformat code

---
 compiler/api/compiler.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 97dbdf0a60..5736c68d49 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -413,7 +413,8 @@ def start(format: bool = False):
                         if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
                             write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
                         else:
-                            write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
+                            write_flags.append(
+                                f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
 
                 write_flags = "\n        ".join([
                     f"{arg_name} = 0",

From fde55a4a7f2fbd964ca51920db801e6614571e35 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 17 Apr 2022 17:36:58 +0200
Subject: [PATCH 134/539] Improve interoperability with threads

---
 pyrogram/sync.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/sync.py b/pyrogram/sync.py
index a3e0d2b545..41c23e3b80 100644
--- a/pyrogram/sync.py
+++ b/pyrogram/sync.py
@@ -58,7 +58,7 @@ def async_to_sync_wrap(*args, **kwargs):
             loop = asyncio.new_event_loop()
             asyncio.set_event_loop(loop)
 
-        if threading.current_thread() is threading.main_thread():
+        if threading.current_thread() is threading.main_thread() or not main_loop.is_running():
             if loop.is_running():
                 return coroutine
             else:

From 499822118f9647b1db419d08a5b46f4bfdd4263c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 17 Apr 2022 17:42:14 +0200
Subject: [PATCH 135/539] Update Pyrogram to v1.4.16

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index eea5848293..e102a89dab 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "1.4.15"
+__version__ = "1.4.16"
 __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 976c2c47a2215b6923861da60843c909e51527ee Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 136/539] Rename update- to set_username and set_chat_username

---
 compiler/docs/compiler.py                            |  4 ++--
 pyrogram/methods/chats/__init__.py                   |  4 ++--
 ...{update_chat_username.py => set_chat_username.py} | 11 ++++++-----
 pyrogram/methods/users/__init__.py                   |  4 ++--
 .../users/{update_username.py => set_username.py}    | 12 ++++++------
 5 files changed, 18 insertions(+), 17 deletions(-)
 rename pyrogram/methods/chats/{update_chat_username.py => set_chat_username.py} (86%)
 rename pyrogram/methods/users/{update_username.py => set_username.py} (83%)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index fdee4e8fcf..7ce7bc96c4 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -212,7 +212,7 @@ def get_title_list(s: str) -> list:
             get_dialogs
             iter_dialogs
             get_dialogs_count
-            update_chat_username
+            set_chat_username
             get_nearby_chats
             archive_chats
             unarchive_chats
@@ -240,7 +240,7 @@ def get_title_list(s: str) -> list:
             iter_profile_photos
             set_profile_photo
             delete_profile_photos
-            update_username
+            set_username
             update_profile
             block_user
             unblock_user
diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py
index cba67600af..6eedbd32e6 100644
--- a/pyrogram/methods/chats/__init__.py
+++ b/pyrogram/methods/chats/__init__.py
@@ -50,13 +50,13 @@
 from .set_chat_photo import SetChatPhoto
 from .set_chat_protected_content import SetChatProtectedContent
 from .set_chat_title import SetChatTitle
+from .set_chat_username import SetChatUsername
 from .set_send_as_chat import SetSendAsChat
 from .set_slow_mode import SetSlowMode
 from .unarchive_chats import UnarchiveChats
 from .unban_chat_member import UnbanChatMember
 from .unpin_all_chat_messages import UnpinAllChatMessages
 from .unpin_chat_message import UnpinChatMessage
-from .update_chat_username import UpdateChatUsername
 
 
 class Chats(
@@ -79,7 +79,7 @@ class Chats(
     GetChatMembersCount,
     IterDialogs,
     IterChatMembers,
-    UpdateChatUsername,
+    SetChatUsername,
     SetChatPermissions,
     GetDialogsCount,
     ArchiveChats,
diff --git a/pyrogram/methods/chats/update_chat_username.py b/pyrogram/methods/chats/set_chat_username.py
similarity index 86%
rename from pyrogram/methods/chats/update_chat_username.py
rename to pyrogram/methods/chats/set_chat_username.py
index a5bf9958d3..8496dda326 100644
--- a/pyrogram/methods/chats/update_chat_username.py
+++ b/pyrogram/methods/chats/set_chat_username.py
@@ -22,19 +22,20 @@
 from pyrogram.scaffold import Scaffold
 
 
-class UpdateChatUsername(Scaffold):
-    async def update_chat_username(
+class SetChatUsername(Scaffold):
+    async def set_chat_username(
         self,
         chat_id: Union[int, str],
         username: Optional[str]
     ) -> bool:
-        """Update a channel or a supergroup username.
+        """Set a channel or a supergroup username.
 
-        To update your own username (for users only, not bots) you can use :meth:`~pyrogram.Client.update_username`.
+        To set your own username (for users only, not bots) you can use :meth:`~pyrogram.Client.set_username`.
 
         Parameters:
             chat_id (``int`` | ``str``)
                 Unique identifier (int) or username (str) of the target chat.
+
             username (``str`` | ``None``):
                 Username to set. Pass "" (empty string) or None to remove the username.
 
@@ -47,7 +48,7 @@ async def update_chat_username(
         Example:
             .. code-block:: python
 
-                app.update_chat_username(chat_id, "new_username")
+                app.set_chat_username(chat_id, "new_username")
         """
 
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py
index e8005b83ea..6cd81bc363 100644
--- a/pyrogram/methods/users/__init__.py
+++ b/pyrogram/methods/users/__init__.py
@@ -25,9 +25,9 @@
 from .get_users import GetUsers
 from .iter_profile_photos import IterProfilePhotos
 from .set_profile_photo import SetProfilePhoto
+from .set_username import SetUsername
 from .unblock_user import UnblockUser
 from .update_profile import UpdateProfile
-from .update_username import UpdateUsername
 
 
 class Users(
@@ -38,7 +38,7 @@ class Users(
     DeleteProfilePhotos,
     GetUsers,
     GetMe,
-    UpdateUsername,
+    SetUsername,
     GetProfilePhotosCount,
     IterProfilePhotos,
     UnblockUser,
diff --git a/pyrogram/methods/users/update_username.py b/pyrogram/methods/users/set_username.py
similarity index 83%
rename from pyrogram/methods/users/update_username.py
rename to pyrogram/methods/users/set_username.py
index ce61402a7f..881f2ae685 100644
--- a/pyrogram/methods/users/update_username.py
+++ b/pyrogram/methods/users/set_username.py
@@ -22,16 +22,16 @@
 from pyrogram.scaffold import Scaffold
 
 
-class UpdateUsername(Scaffold):
-    async def update_username(
+class SetUsername(Scaffold):
+    async def set_username(
         self,
         username: Optional[str]
     ) -> bool:
-        """Update your own username.
+        """Set your own username.
 
         This method only works for users, not bots. Bot usernames must be changed via Bot Support or by recreating
-        them from scratch using BotFather. To update a channel or supergroup username you can use
-        :meth:`~pyrogram.Client.update_chat_username`.
+        them from scratch using BotFather. To set a channel or supergroup username you can use
+        :meth:`~pyrogram.Client.set_chat_username`.
 
         Parameters:
             username (``str`` | ``None``):
@@ -43,7 +43,7 @@ async def update_username(
         Example:
             .. code-block:: python
 
-                app.update_username("new_username")
+                app.set_username("new_username")
         """
 
         return bool(

From 9661b804b6114e2164a1aac44c180fa833c44f15 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 137/539] Revamp ChatMember, add ChatPrivileges and support for
 banned chats

---
 compiler/docs/compiler.py                     |   1 +
 pyrogram/methods/chats/iter_chat_members.py   |   6 +-
 pyrogram/methods/chats/promote_chat_member.py |  96 ++----
 .../methods/chats/restrict_chat_member.py     |  22 +-
 .../methods/chats/set_administrator_title.py  |  35 +-
 pyrogram/types/user_and_chats/__init__.py     |   4 +-
 pyrogram/types/user_and_chats/chat_member.py  | 323 ++++++------------
 .../types/user_and_chats/chat_permissions.py  |   2 +-
 .../types/user_and_chats/chat_privileges.py   | 112 ++++++
 pyrogram/types/user_and_chats/user.py         |   4 +-
 10 files changed, 276 insertions(+), 329 deletions(-)
 create mode 100644 pyrogram/types/user_and_chats/chat_privileges.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 7ce7bc96c4..53ceb91cef 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -361,6 +361,7 @@ def get_title_list(s: str) -> list:
             ChatPhoto
             ChatMember
             ChatPermissions
+            ChatPrivileges
             ChatInviteLink
             ChatAdminWithInviteLinks
             ChatEvent
diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py
index e9fa5b8277..3661d5064f 100644
--- a/pyrogram/methods/chats/iter_chat_members.py
+++ b/pyrogram/methods/chats/iter_chat_members.py
@@ -112,14 +112,14 @@ async def iter_chat_members(
             offset += len(chat_members)
 
             for chat_member in chat_members:
-                user_id = chat_member.user.id
+                peer_id = chat_member.user.id if chat_member.user else chat_member.chat.id
 
-                if user_id in yielded:
+                if peer_id in yielded:
                     continue
 
                 yield chat_member
 
-                yielded.add(chat_member.user.id)
+                yielded.add(peer_id)
 
                 current += 1
 
diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py
index 8ab5fe29e8..b1d43867f3 100644
--- a/pyrogram/methods/chats/promote_chat_member.py
+++ b/pyrogram/methods/chats/promote_chat_member.py
@@ -18,7 +18,7 @@
 
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, types
 from pyrogram.scaffold import Scaffold
 
 
@@ -27,17 +27,7 @@ async def promote_chat_member(
         self,
         chat_id: Union[int, str],
         user_id: Union[int, str],
-        is_anonymous: bool = False,
-        can_manage_chat: bool = True,
-        can_change_info: bool = False,
-        can_post_messages: bool = False,
-        can_edit_messages: bool = False,
-        can_delete_messages: bool = False,
-        can_restrict_members: bool = False,
-        can_invite_users: bool = False,
-        can_pin_messages: bool = False,
-        can_promote_members: bool = False,
-        can_manage_voice_chats: bool = False
+        privileges: "types.ChatPrivileges" = types.ChatPrivileges(),
     ) -> bool:
         """Promote or demote a user in a supergroup or a channel.
 
@@ -52,42 +42,8 @@ async def promote_chat_member(
                 Unique identifier (int) or username (str) of the target user.
                 For a contact that exists in your Telegram address book you can use his phone number (str).
 
-            is_anonymous (``bool``, *optional*):
-                Pass True, if the administrator's presence in the chat is hidden.
-
-            can_manage_chat (``bool``, *optional*):
-                Pass True, if the administrator can access the chat event log, chat statistics, message statistics
-                in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode.
-                Implied by any other administrator privilege.
-
-            can_change_info (``bool``, *optional*):
-                Pass True, if the administrator can change chat title, photo and other settings.
-
-            can_post_messages (``bool``, *optional*):
-                Pass True, if the administrator can create channel posts, channels only.
-
-            can_edit_messages (``bool``, *optional*):
-                Pass True, if the administrator can edit messages of other users and can pin messages, channels only.
-
-            can_delete_messages (``bool``, *optional*):
-                Pass True, if the administrator can delete messages of other users.
-
-            can_restrict_members (``bool``, *optional*):
-                Pass True, if the administrator can restrict, ban or unban chat members.
-
-            can_invite_users (``bool``, *optional*):
-                Pass True, if the administrator can invite new users to the chat.
-
-            can_pin_messages (``bool``, *optional*):
-                Pass True, if the administrator can pin messages, supergroups only.
-
-            can_promote_members (``bool``, *optional*):
-                Pass True, if the administrator can add new administrators with a subset of his own privileges or
-                demote administrators that he has promoted, directly or indirectly (promoted by administrators that
-                were appointed by him).
-
-            can_manage_voice_chats (``bool``, *optional*):
-                Pass True, if the administration can manage voice chats (also called group calls).
+            privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
+                New user privileges.
 
         Returns:
             ``bool``: True on success.
@@ -95,27 +51,41 @@ async def promote_chat_member(
         Example:
             .. code-block:: python
 
-                # Promote chat member to supergroup admin
+                # Promote chat member to admin
                 app.promote_chat_member(chat_id, user_id)
         """
+        chat_id = await self.resolve_peer(chat_id)
+        user_id = await self.resolve_peer(user_id)
+
+        raw_chat_member = (await self.send(
+            raw.functions.channels.GetParticipant(
+                channel=chat_id,
+                participant=user_id
+            )
+        )).participant
+
+        rank = None
+        if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
+            rank = raw_chat_member.rank
+
         await self.send(
             raw.functions.channels.EditAdmin(
-                channel=await self.resolve_peer(chat_id),
-                user_id=await self.resolve_peer(user_id),
+                channel=chat_id,
+                user_id=user_id,
                 admin_rights=raw.types.ChatAdminRights(
-                    anonymous=is_anonymous or None,
-                    change_info=can_change_info or None,
-                    post_messages=can_post_messages or None,
-                    edit_messages=can_edit_messages or None,
-                    delete_messages=can_delete_messages or None,
-                    ban_users=can_restrict_members or None,
-                    invite_users=can_invite_users or None,
-                    pin_messages=can_pin_messages or None,
-                    add_admins=can_promote_members or None,
-                    manage_call=can_manage_voice_chats or None,
-                    other=can_manage_chat or None
+                    anonymous=privileges.is_anonymous,
+                    change_info=privileges.can_change_info,
+                    post_messages=privileges.can_post_messages,
+                    edit_messages=privileges.can_edit_messages,
+                    delete_messages=privileges.can_delete_messages,
+                    ban_users=privileges.can_restrict_members,
+                    invite_users=privileges.can_invite_users,
+                    pin_messages=privileges.can_pin_messages,
+                    add_admins=privileges.can_promote_members,
+                    manage_call=privileges.can_manage_voice_chats,
+                    other=privileges.can_manage_chat
                 ),
-                rank=""
+                rank=rank or ""
             )
         )
 
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index 7c74d68536..7a759185d2 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -77,17 +77,17 @@ async def restrict_chat_member(
                 participant=await self.resolve_peer(user_id),
                 banned_rights=raw.types.ChatBannedRights(
                     until_date=until_date,
-                    send_messages=True if not permissions.can_send_messages else None,
-                    send_media=True if not permissions.can_send_media_messages else None,
-                    send_stickers=True if not permissions.can_send_other_messages else None,
-                    send_gifs=True if not permissions.can_send_other_messages else None,
-                    send_games=True if not permissions.can_send_other_messages else None,
-                    send_inline=True if not permissions.can_send_other_messages else None,
-                    embed_links=True if not permissions.can_add_web_page_previews else None,
-                    send_polls=True if not permissions.can_send_polls else None,
-                    change_info=True if not permissions.can_change_info else None,
-                    invite_users=True if not permissions.can_invite_users else None,
-                    pin_messages=True if not permissions.can_pin_messages else None,
+                    send_messages=not permissions.can_send_messages,
+                    send_media=not permissions.can_send_media_messages,
+                    send_stickers=not permissions.can_send_other_messages,
+                    send_gifs=not permissions.can_send_other_messages,
+                    send_games=not permissions.can_send_other_messages,
+                    send_inline=not permissions.can_send_other_messages,
+                    embed_links=not permissions.can_add_web_page_previews,
+                    send_polls=not permissions.can_send_polls,
+                    change_info=not permissions.can_change_info,
+                    invite_users=not permissions.can_invite_users,
+                    pin_messages=not permissions.can_pin_messages,
                 )
             )
         )
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index 382d1faccc..f59cf28a35 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -65,45 +65,12 @@ async def set_administrator_title(
         )).participant
 
         if isinstance(r, raw.types.ChannelParticipantCreator):
-            admin_rights = raw.types.ChatAdminRights(
-                change_info=True,
-                post_messages=True,
-                edit_messages=True,
-                delete_messages=True,
-                ban_users=True,
-                invite_users=True,
-                pin_messages=True,
-                add_admins=True,
-            )
+            admin_rights = raw.types.ChatAdminRights()
         elif isinstance(r, raw.types.ChannelParticipantAdmin):
             admin_rights = r.admin_rights
         else:
             raise ValueError("Custom titles can only be applied to owners or administrators of supergroups")
 
-        if not admin_rights.change_info:
-            admin_rights.change_info = None
-
-        if not admin_rights.post_messages:
-            admin_rights.post_messages = None
-
-        if not admin_rights.edit_messages:
-            admin_rights.edit_messages = None
-
-        if not admin_rights.delete_messages:
-            admin_rights.delete_messages = None
-
-        if not admin_rights.ban_users:
-            admin_rights.ban_users = None
-
-        if not admin_rights.invite_users:
-            admin_rights.invite_users = None
-
-        if not admin_rights.pin_messages:
-            admin_rights.pin_messages = None
-
-        if not admin_rights.add_admins:
-            admin_rights.add_admins = None
-
         await self.send(
             raw.functions.channels.EditAdmin(
                 channel=chat_id,
diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py
index 4667628a0e..15ddf8c9e3 100644
--- a/pyrogram/types/user_and_chats/__init__.py
+++ b/pyrogram/types/user_and_chats/__init__.py
@@ -27,6 +27,7 @@
 from .chat_permissions import ChatPermissions
 from .chat_photo import ChatPhoto
 from .chat_preview import ChatPreview
+from .chat_privileges import ChatPrivileges
 from .dialog import Dialog
 from .invite_link_importer import InviteLinkImporter
 from .restriction import Restriction
@@ -55,5 +56,6 @@
     "VoiceChatMembersInvited",
     "ChatMemberUpdated",
     "VoiceChatScheduled",
-    "ChatJoinRequest"
+    "ChatJoinRequest",
+    "ChatPrivileges"
 ]
diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index ff55081587..65324dbd57 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Union, Dict
+
 import pyrogram
-from pyrogram import raw
-from pyrogram import types
+from pyrogram import raw, types, utils
 from ..object import Object
 
 
@@ -26,14 +27,21 @@ class ChatMember(Object):
     """Contains information about one member of a chat.
 
     Parameters:
-        user (:obj:`~pyrogram.types.User`):
-            Information about the user.
-
         status (``str``):
             The member's status in the chat.
             Can be "creator", "administrator", "member", "restricted", "left" or "banned".
 
-        title (``str``, *optional*):
+        user (:obj:`~pyrogram.types.User`, *optional*):
+            Information about the user.
+
+        chat (:obj:`~pyrogram.types.Chat`, *optional*):
+            Information about the chat (useful in case of banned channel senders).
+
+        joined_date (``int``, *optional*):
+            Date when the user joined, unix time.
+            Not available for the owner.
+
+        custom_title (``str``, *optional*):
             A custom title that will be shown to all members instead of "Owner" or "Admin".
             Creator (owner) and administrators only. Can be None in case there's no custom title set.
 
@@ -41,10 +49,6 @@ class ChatMember(Object):
             Restricted and banned only.
             Date when restrictions will be lifted for this user; unix time.
 
-        joined_date (``int``, *optional*):
-            Date when the user joined, unix time.
-            Not available for creator.
-
         invited_by (:obj:`~pyrogram.types.User`, *optional*):
             Administrators and self member only. Information about the user who invited this member.
             In case the user joined by himself this will be the same as "user".
@@ -58,268 +62,159 @@ class ChatMember(Object):
         is_member (``bool``, *optional*):
             Restricted only. True, if the user is a member of the chat at the moment of the request.
 
-        is_anonymous (``bool``, *optional*):
-            True, if the user's presence in the chat is hidden.
-            Owner and administrators only.
-
         can_be_edited (``bool``, *optional*):
-            Administrators only.
-            True, if you are allowed to edit administrator privileges of the user.
-
-        can_manage_chat (``bool``, *optional*):
-            Administrators only.
-            True, if the administrator can access the chat event log, chat statistics, message statistics in channels,
-            see channel members, see anonymous administrators in supergroups and ignore slow mode.
-            Implied by any other administrator privilege.
-
-        can_post_messages (``bool``, *optional*):
-            Administrators only. Channels only.
-            True, if the administrator can post messages in the channel.
-
-        can_edit_messages (``bool``, *optional*):
-            Administrators only. Channels only.
-            True, if the administrator can edit messages of other users and can pin messages.
-
-        can_delete_messages (``bool``, *optional*):
-            Administrators only.
-            True, if the administrator can delete messages of other users.
-
-        can_restrict_members (``bool``, *optional*):
-            Administrators only.
-            True, if the administrator can restrict, ban or unban chat members.
-
-        can_promote_members (``bool``, *optional*):
-            Administrators only.
-            True, if the administrator can add new administrators with a subset of his own privileges or demote
-            administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed
-            by the user).
+            True, if the you are allowed to edit administrator privileges of the user.
 
-        can_change_info (``bool``, *optional*):
-            Administrators and restricted only.
-            True, if the user is allowed to change the chat title, photo and other settings.
+        permissions (:obj:`~pyrogram.types.ChatPermissions`, *optional*):
+            Restricted only. Restricted actions that a non-administrator user is allowed to take.
 
-        can_invite_users (``bool``, *optional*):
-            Administrators and restricted only.
-            True, if the user is allowed to invite new users to the chat.
-
-        can_pin_messages (``bool``, *optional*):
-            Administrators and restricted only. Groups and supergroups only.
-            True, if the user is allowed to pin messages.
-
-        can_manage_voice_chats (``bool``, *optional*):
-            Administrators only. Groups and supergroups only.
-            True, if the administrator can manage voice chats (also called group calls).
-
-        can_send_messages (``bool``, *optional*):
-            Restricted only.
-            True, if the user is allowed to send text messages, contacts, locations and venues.
-
-        can_send_media_messages (``bool``, *optional*):
-            Restricted only.
-            True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
-
-        can_send_stickers (``bool``, *optional*):
-            True, if the user is allowed to send stickers, implies can_send_media_messages.
-
-        can_send_animations (``bool``, *optional*):
-            True, if the user is allowed to send animations (GIFs), implies can_send_media_messages.
-
-        can_send_games (``bool``, *optional*):
-            True, if the user is allowed to send games, implies can_send_media_messages.
-
-        can_use_inline_bots (``bool``, *optional*):
-            True, if the user is allowed to use inline bots, implies can_send_media_messages.
-
-        can_add_web_page_previews (``bool``, *optional*):
-            Restricted only.
-            True, if the user is allowed to add web page previews to their messages.
-
-        can_send_polls (``bool``, *optional*):
-            Restricted only.
-            True, if the user is allowed to send polls.
+        privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
+            Administrators only. Privileged actions that an administrator is able to take.
     """
 
     def __init__(
         self,
         *,
         client: "pyrogram.Client" = None,
-        user: "types.User",
         status: str,
-        title: str = None,
+        user: "types.User" = None,
+        chat: "types.Chat" = None,
+        custom_title: str = None,
         until_date: int = None,
         joined_date: int = None,
         invited_by: "types.User" = None,
         promoted_by: "types.User" = None,
         restricted_by: "types.User" = None,
         is_member: bool = None,
-        is_anonymous: bool = None,
-
-        # Admin permissions
         can_be_edited: bool = None,
-        can_manage_chat: bool = None,
-        can_post_messages: bool = None,  # Channels only
-        can_edit_messages: bool = None,  # Channels only
-        can_delete_messages: bool = None,
-        can_restrict_members: bool = None,
-        can_promote_members: bool = None,
-        can_change_info: bool = None,
-        can_invite_users: bool = None,
-        can_pin_messages: bool = None,  # Groups and supergroups only
-        can_manage_voice_chats: bool = None,
-
-        # Restricted user permissions
-        can_send_messages: bool = None,  # Text, contacts, locations and venues
-        can_send_media_messages: bool = None,  # Audios, documents, photos, videos, video notes and voice notes
-        can_send_stickers: bool = None,
-        can_send_animations: bool = None,
-        can_send_games: bool = None,
-        can_use_inline_bots: bool = None,
-        can_add_web_page_previews: bool = None,
-        can_send_polls: bool = None
+        permissions: "types.ChatPermissions" = None,
+        privileges: "types.ChatPrivileges" = None
     ):
         super().__init__(client)
 
-        self.user = user
         self.status = status
-        self.title = title
+        self.user = user
+        self.chat = chat
+        self.custom_title = custom_title
         self.until_date = until_date
         self.joined_date = joined_date
         self.invited_by = invited_by
         self.promoted_by = promoted_by
         self.restricted_by = restricted_by
         self.is_member = is_member
-        self.is_anonymous = is_anonymous
-
         self.can_be_edited = can_be_edited
-        self.can_manage_chat = can_manage_chat
-        self.can_post_messages = can_post_messages
-        self.can_edit_messages = can_edit_messages
-        self.can_delete_messages = can_delete_messages
-        self.can_restrict_members = can_restrict_members
-        self.can_promote_members = can_promote_members
-        self.can_change_info = can_change_info
-        self.can_invite_users = can_invite_users
-        self.can_pin_messages = can_pin_messages
-        self.can_manage_voice_chats = can_manage_voice_chats
-
-        self.can_send_messages = can_send_messages
-        self.can_send_media_messages = can_send_media_messages
-        self.can_send_stickers = can_send_stickers
-        self.can_send_animations = can_send_animations
-        self.can_send_games = can_send_games
-        self.can_use_inline_bots = can_use_inline_bots
-        self.can_add_web_page_previews = can_add_web_page_previews
-        self.can_send_polls = can_send_polls
+        self.permissions = permissions
+        self.privileges = privileges
 
     @staticmethod
-    def _parse(client, member, users, chats) -> "ChatMember":
-        if not isinstance(member, (raw.types.ChannelParticipantBanned, raw.types.ChannelParticipantLeft)):
-            user = types.User._parse(client, users[member.user_id])
-        else:
-            if isinstance(member.peer, raw.types.PeerUser):
-                user = types.User._parse(client, users[member.peer.user_id])
-            else:
-                user = None
-
-        invited_by = (
-            types.User._parse(client, users[member.inviter_id])
-            if getattr(member, "inviter_id", None) else None
-        )
-
-        if isinstance(member, (raw.types.ChannelParticipant,
-                               raw.types.ChannelParticipantSelf,
-                               raw.types.ChatParticipant)):
+    def _parse(
+        client: "pyrogram.Client",
+        member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
+        users: Dict[int, "raw.base.User"],
+        chats: Dict[int, "raw.base.Chat"]
+    ) -> "ChatMember":
+        # Chat participants
+        if isinstance(member, raw.types.ChatParticipant):
             return ChatMember(
-                user=user,
                 status="member",
+                user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
-                invited_by=invited_by,
+                invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
-
-        if isinstance(member, raw.types.ChatParticipantCreator):
+        elif isinstance(member, raw.types.ChatParticipantAdmin):
             return ChatMember(
-                user=user,
-                status="creator",
+                status="administrator",
+                user=types.User._parse(client, users[member.user_id]),
+                joined_date=member.date,
+                invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
-
-        if isinstance(member, raw.types.ChatParticipantAdmin):
+        elif isinstance(member, raw.types.ChatParticipantCreator):
             return ChatMember(
-                user=user,
-                status="administrator",
-                joined_date=member.date,
-                invited_by=invited_by,
+                status="owner",
+                user=types.User._parse(client, users[member.user_id]),
                 client=client
             )
 
-        if isinstance(member, raw.types.ChannelParticipantCreator):
-            permissions = member.admin_rights
-
+        # Channel participants
+        if isinstance(member, raw.types.ChannelParticipant):
             return ChatMember(
-                user=user,
-                status="creator",
-                title=member.rank,
-                invited_by=invited_by,
-                can_change_info=permissions.change_info,
-                can_manage_chat=permissions.other,
-                can_post_messages=permissions.post_messages,
-                can_edit_messages=permissions.edit_messages,
-                can_delete_messages=permissions.delete_messages,
-                can_restrict_members=permissions.ban_users,
-                can_invite_users=permissions.invite_users,
-                can_pin_messages=permissions.pin_messages,
-                can_promote_members=permissions.add_admins,
-                can_manage_voice_chats=permissions.manage_call,
-                is_anonymous=permissions.anonymous,
+                status="member",
+                user=types.User._parse(client, users[member.user_id]),
+                joined_date=member.date,
                 client=client
             )
-
-        if isinstance(member, raw.types.ChannelParticipantAdmin):
-            permissions = member.admin_rights
-
+        elif isinstance(member, raw.types.ChannelParticipantAdmin):
             return ChatMember(
-                user=user,
                 status="administrator",
-                title=member.rank,
+                user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
-                invited_by=invited_by,
                 promoted_by=types.User._parse(client, users[member.promoted_by]),
+                invited_by=types.User._parse(client, users[member.inviter_id]),
+                custom_title=member.rank,
                 can_be_edited=member.can_edit,
-                can_manage_chat=permissions.other,
-                can_change_info=permissions.change_info,
-                can_post_messages=permissions.post_messages,
-                can_edit_messages=permissions.edit_messages,
-                can_delete_messages=permissions.delete_messages,
-                can_restrict_members=permissions.ban_users,
-                can_invite_users=permissions.invite_users,
-                can_pin_messages=permissions.pin_messages,
-                can_promote_members=permissions.add_admins,
-                can_manage_voice_chats=permissions.manage_call,
-                is_anonymous=permissions.anonymous,
+                privileges=types.ChatPrivileges._parse(member.admin_rights),
                 client=client
             )
+        elif isinstance(member, raw.types.ChannelParticipantBanned):
+            peer = member.peer
+            peer_id = utils.get_raw_peer_id(peer)
 
-        if isinstance(member, raw.types.ChannelParticipantBanned):
-            denied_permissions = member.banned_rights
+            user = (
+                types.User._parse(client, users[peer_id])
+                if isinstance(peer, raw.types.PeerUser) else None
+            )
+
+            chat = (
+                types.Chat._parse_chat(client, chats[peer_id])
+                if not isinstance(peer, raw.types.PeerUser) else None
+            )
 
             return ChatMember(
-                user=user,
                 status="banned" if member.banned_rights.view_messages else "restricted",
-                until_date=denied_permissions.until_date,
+                user=user,
+                chat=chat,
+                until_date=member.banned_rights.until_date,
                 joined_date=member.date,
                 is_member=not member.left,
                 restricted_by=types.User._parse(client, users[member.kicked_by]),
-                can_send_messages=not denied_permissions.send_messages,
-                can_send_media_messages=not denied_permissions.send_media,
-                can_send_stickers=not denied_permissions.send_stickers,
-                can_send_animations=not denied_permissions.send_gifs,
-                can_send_games=not denied_permissions.send_games,
-                can_use_inline_bots=not denied_permissions.send_inline,
-                can_add_web_page_previews=not denied_permissions.embed_links,
-                can_send_polls=not denied_permissions.send_polls,
-                can_change_info=not denied_permissions.change_info,
-                can_invite_users=not denied_permissions.invite_users,
-                can_pin_messages=not denied_permissions.pin_messages,
+                permissions=types.ChatPermissions._parse(member.banned_rights),
+                client=client
+            )
+        elif isinstance(member, raw.types.ChannelParticipantCreator):
+            return ChatMember(
+                status="owner",
+                user=types.User._parse(client, users[member.user_id]),
+                custom_title=member.rank,
+                privileges=types.ChatPrivileges._parse(member.admin_rights),
+                client=client
+            )
+        elif isinstance(member, raw.types.ChannelParticipantLeft):
+            peer = member.peer
+            peer_id = utils.get_raw_peer_id(peer)
+
+            user = (
+                types.User._parse(client, users[peer_id])
+                if isinstance(peer, raw.types.PeerUser) else None
+            )
+
+            chat = (
+                types.Chat._parse_chat(client, chats[peer_id])
+                if not isinstance(peer, raw.types.PeerUser) else None
+            )
+
+            return ChatMember(
+                status="left",
+                user=user,
+                chat=chat,
+                client=client
+            )
+        elif isinstance(member, raw.types.ChannelParticipantSelf):
+            return ChatMember(
+                status="member",
+                user=types.User._parse(client, users[member.user_id]),
+                joined_date=member.date,
+                invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
diff --git a/pyrogram/types/user_and_chats/chat_permissions.py b/pyrogram/types/user_and_chats/chat_permissions.py
index e209625af3..d920394c67 100644
--- a/pyrogram/types/user_and_chats/chat_permissions.py
+++ b/pyrogram/types/user_and_chats/chat_permissions.py
@@ -79,7 +79,7 @@ def __init__(
         self.can_pin_messages = can_pin_messages
 
     @staticmethod
-    def _parse(denied_permissions: "raw.types.ChatBannedRights") -> "ChatPermissions":
+    def _parse(denied_permissions: "raw.base.ChatBannedRights") -> "ChatPermissions":
         if isinstance(denied_permissions, raw.types.ChatBannedRights):
             return ChatPermissions(
                 can_send_messages=not denied_permissions.send_messages,
diff --git a/pyrogram/types/user_and_chats/chat_privileges.py b/pyrogram/types/user_and_chats/chat_privileges.py
new file mode 100644
index 0000000000..403bb9572b
--- /dev/null
+++ b/pyrogram/types/user_and_chats/chat_privileges.py
@@ -0,0 +1,112 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from ..object import Object
+
+
+class ChatPrivileges(Object):
+    """Describes privileged actions an administrator is able to take in a chat.
+
+    Parameters:
+        can_manage_chat (``bool``, *optional*):
+            True, if the administrator can access the chat event log, chat statistics, message statistics in channels,
+            see channel members, see anonymous administrators in supergroups and ignore slow mode.
+            Implied by any other administrator privilege.
+
+        can_delete_messages (``bool``, *optional*):
+            True, if the administrator can delete messages of other users.
+
+        can_manage_voice_chats (``bool``, *optional*):
+            Groups and supergroups only.
+            True, if the administrator can manage voice chats (also called group calls).
+
+        can_restrict_members (``bool``, *optional*):
+            True, if the administrator can restrict, ban or unban chat members.
+
+        can_promote_members (``bool``, *optional*):
+            True, if the administrator can add new administrators with a subset of his own privileges or demote
+            administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed
+            by the user).
+
+        can_change_info (``bool``, *optional*):
+            True, if the user is allowed to change the chat title, photo and other settings.
+
+        can_post_messages (``bool``, *optional*):
+            Channels only.
+            True, if the administrator can post messages in the channel.
+
+        can_edit_messages (``bool``, *optional*):
+            Channels only.
+            True, if the administrator can edit messages of other users and can pin messages.
+
+        can_invite_users (``bool``, *optional*):
+            True, if the user is allowed to invite new users to the chat.
+
+        can_pin_messages (``bool``, *optional*):
+            Groups and supergroups only.
+            True, if the user is allowed to pin messages.
+
+        is_anonymous (``bool``, *optional*):
+            True, if the user's presence in the chat is hidden.
+    """
+
+    def __init__(
+        self,
+        *,
+        can_manage_chat: bool = True,
+        can_delete_messages: bool = False,
+        can_manage_voice_chats: bool = False,  # Groups and supergroups only
+        can_restrict_members: bool = False,
+        can_promote_members: bool = False,
+        can_change_info: bool = False,
+        can_post_messages: bool = False,  # Channels only
+        can_edit_messages: bool = False,  # Channels only
+        can_invite_users: bool = False,
+        can_pin_messages: bool = False,  # Groups and supergroups only
+        is_anonymous: bool = False
+    ):
+        super().__init__(None)
+
+        self.can_manage_chat: bool = can_manage_chat
+        self.can_delete_messages: bool = can_delete_messages
+        self.can_manage_voice_chats: bool = can_manage_voice_chats
+        self.can_restrict_members: bool = can_restrict_members
+        self.can_promote_members: bool = can_promote_members
+        self.can_change_info: bool = can_change_info
+        self.can_post_messages: bool = can_post_messages
+        self.can_edit_messages: bool = can_edit_messages
+        self.can_invite_users: bool = can_invite_users
+        self.can_pin_messages: bool = can_pin_messages
+        self.is_anonymous: bool = is_anonymous
+
+    @staticmethod
+    def _parse(admin_rights: "raw.base.ChatAdminRights") -> "ChatPrivileges":
+        return ChatPrivileges(
+            can_manage_chat=admin_rights.other,
+            can_delete_messages=admin_rights.delete_messages,
+            can_manage_voice_chats=admin_rights.manage_call,
+            can_restrict_members=admin_rights.ban_users,
+            can_promote_members=admin_rights.add_admins,
+            can_change_info=admin_rights.change_info,
+            can_post_messages=admin_rights.post_messages,
+            can_edit_messages=admin_rights.edit_messages,
+            can_invite_users=admin_rights.invite_users,
+            can_pin_messages=admin_rights.pin_messages,
+            is_anonymous=admin_rights.anonymous
+        )
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index 8579ba157d..ac141033e2 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -206,8 +206,8 @@ def mention(self):
         return Link(f"tg://user?id={self.id}", self.first_name, self._client.parse_mode)
 
     @staticmethod
-    def _parse(client, user: "raw.types.User") -> Optional["User"]:
-        if user is None:
+    def _parse(client, user: "raw.base.User") -> Optional["User"]:
+        if user is None or isinstance(user, raw.types.UserEmpty):
             return None
 
         return User(

From bbad58a83f5ec9e295233c97743365c99757eec1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 138/539] Add enumerations

---
 docs/source/api/enums/ChatAction.rst          |   8 +
 docs/source/api/enums/ChatEventAction.rst     |   8 +
 docs/source/api/enums/ChatMemberStatus.rst    |   8 +
 docs/source/api/enums/ChatMembersFilter.rst   |   8 +
 docs/source/api/enums/ChatType.rst            |   8 +
 docs/source/api/enums/MessageEntityType.rst   |   8 +
 docs/source/api/enums/MessageMedia.rst        |   8 +
 docs/source/api/enums/MessageService.rst      |   8 +
 docs/source/api/enums/MessagesFilter.rst      |   8 +
 docs/source/api/enums/ParseMode.rst           |   8 +
 docs/source/api/enums/PollType.rst            |   8 +
 docs/source/api/enums/SentCodeType.rst        |   8 +
 docs/source/api/enums/UserStatus.rst          |   8 +
 docs/source/api/enums/cleanup.html            |   9 +
 docs/source/api/enums/index.rst               |  45 ++++
 docs/source/index.rst                         |   2 +
 pyrogram/__init__.py                          |   2 +-
 pyrogram/client.py                            |  48 ++---
 pyrogram/enums/__init__.py                    |  31 +++
 pyrogram/enums/auto_name.py                   |  24 +++
 pyrogram/enums/chat_action.py                 |  72 +++++++
 pyrogram/enums/chat_event_action.py           | 127 ++++++++++++
 pyrogram/enums/chat_member_status.py          |  43 ++++
 pyrogram/enums/chat_members_filter.py         |  42 ++++
 pyrogram/enums/chat_type.py                   |  40 ++++
 pyrogram/enums/message_entity_type.py         |  81 ++++++++
 pyrogram/enums/message_media.py               |  70 +++++++
 pyrogram/enums/message_service.py             |  70 +++++++
 pyrogram/enums/messages_filter.py             |  75 +++++++
 pyrogram/enums/parse_mode.py                  |  37 ++++
 pyrogram/enums/poll_type.py                   |  31 +++
 pyrogram/enums/sent_code_type.py              |  39 ++++
 pyrogram/enums/user_status.py                 |  43 ++++
 pyrogram/filters.py                           |   7 +-
 pyrogram/methods/chats/get_chat_members.py    |  14 +-
 pyrogram/methods/messages/copy_message.py     |   9 +-
 .../methods/messages/edit_inline_caption.py   |   9 +-
 pyrogram/methods/messages/edit_inline_text.py |   9 +-
 .../methods/messages/edit_message_caption.py  |   9 +-
 .../methods/messages/edit_message_text.py     |   9 +-
 pyrogram/methods/messages/search_global.py    |  51 +----
 .../methods/messages/search_global_count.py   |  30 +--
 pyrogram/methods/messages/search_messages.py  |  67 +-----
 .../methods/messages/search_messages_count.py |  33 +--
 pyrogram/methods/messages/send_animation.py   |   9 +-
 pyrogram/methods/messages/send_audio.py       |   9 +-
 .../methods/messages/send_cached_media.py     |   9 +-
 pyrogram/methods/messages/send_chat_action.py |  62 ++----
 pyrogram/methods/messages/send_document.py    |   9 +-
 pyrogram/methods/messages/send_message.py     |   9 +-
 pyrogram/methods/messages/send_photo.py       |   9 +-
 pyrogram/methods/messages/send_poll.py        |  12 +-
 pyrogram/methods/messages/send_video.py       |   9 +-
 pyrogram/methods/messages/send_voice.py       |   9 +-
 pyrogram/parser/html.py                       |   6 +-
 pyrogram/parser/markdown.py                   |  10 +-
 pyrogram/parser/parser.py                     |  28 +--
 pyrogram/scaffold.py                          |   6 +-
 pyrogram/types/authorization/sent_code.py     |  40 +---
 .../bots_and_keyboards/callback_query.py      |  16 +-
 .../bots_and_keyboards/game_high_score.py     |   2 +-
 .../inline_keyboard_button.py                 |   2 +-
 pyrogram/types/inline_mode/inline_query.py    |  19 +-
 .../inline_query_result_animation.py          |   9 +-
 .../inline_mode/inline_query_result_audio.py  |  13 +-
 .../inline_mode/inline_query_result_photo.py  |   9 +-
 .../inline_mode/inline_query_result_video.py  |   9 +-
 .../input_media/input_media_animation.py      |   8 +-
 .../types/input_media/input_media_audio.py    |   8 +-
 .../types/input_media/input_media_document.py |   8 +-
 .../types/input_media/input_media_photo.py    |   8 +-
 .../types/input_media/input_media_video.py    |   8 +-
 .../input_text_message_content.py             |   9 +-
 pyrogram/types/messages_and_media/message.py  | 166 ++++++---------
 .../messages_and_media/message_entity.py      | 102 ++-------
 pyrogram/types/messages_and_media/poll.py     |  10 +-
 pyrogram/types/object.py                      |   4 +
 pyrogram/types/user_and_chats/chat.py         |  34 ++-
 pyrogram/types/user_and_chats/chat_event.py   | 194 ++++++------------
 .../types/user_and_chats/chat_event_filter.py |   8 +-
 pyrogram/types/user_and_chats/chat_member.py  |  37 ++--
 .../user_and_chats/invite_link_importer.py    |   2 +-
 pyrogram/types/user_and_chats/user.py         |  43 ++--
 83 files changed, 1377 insertions(+), 869 deletions(-)
 create mode 100644 docs/source/api/enums/ChatAction.rst
 create mode 100644 docs/source/api/enums/ChatEventAction.rst
 create mode 100644 docs/source/api/enums/ChatMemberStatus.rst
 create mode 100644 docs/source/api/enums/ChatMembersFilter.rst
 create mode 100644 docs/source/api/enums/ChatType.rst
 create mode 100644 docs/source/api/enums/MessageEntityType.rst
 create mode 100644 docs/source/api/enums/MessageMedia.rst
 create mode 100644 docs/source/api/enums/MessageService.rst
 create mode 100644 docs/source/api/enums/MessagesFilter.rst
 create mode 100644 docs/source/api/enums/ParseMode.rst
 create mode 100644 docs/source/api/enums/PollType.rst
 create mode 100644 docs/source/api/enums/SentCodeType.rst
 create mode 100644 docs/source/api/enums/UserStatus.rst
 create mode 100644 docs/source/api/enums/cleanup.html
 create mode 100644 docs/source/api/enums/index.rst
 create mode 100644 pyrogram/enums/__init__.py
 create mode 100644 pyrogram/enums/auto_name.py
 create mode 100644 pyrogram/enums/chat_action.py
 create mode 100644 pyrogram/enums/chat_event_action.py
 create mode 100644 pyrogram/enums/chat_member_status.py
 create mode 100644 pyrogram/enums/chat_members_filter.py
 create mode 100644 pyrogram/enums/chat_type.py
 create mode 100644 pyrogram/enums/message_entity_type.py
 create mode 100644 pyrogram/enums/message_media.py
 create mode 100644 pyrogram/enums/message_service.py
 create mode 100644 pyrogram/enums/messages_filter.py
 create mode 100644 pyrogram/enums/parse_mode.py
 create mode 100644 pyrogram/enums/poll_type.py
 create mode 100644 pyrogram/enums/sent_code_type.py
 create mode 100644 pyrogram/enums/user_status.py

diff --git a/docs/source/api/enums/ChatAction.rst b/docs/source/api/enums/ChatAction.rst
new file mode 100644
index 0000000000..b66df5fd73
--- /dev/null
+++ b/docs/source/api/enums/ChatAction.rst
@@ -0,0 +1,8 @@
+ChatAction
+==========
+
+.. autoclass:: pyrogram.enums.ChatAction()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatEventAction.rst b/docs/source/api/enums/ChatEventAction.rst
new file mode 100644
index 0000000000..0403e781db
--- /dev/null
+++ b/docs/source/api/enums/ChatEventAction.rst
@@ -0,0 +1,8 @@
+ChatEventAction
+===============
+
+.. autoclass:: pyrogram.enums.ChatEventAction()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatMemberStatus.rst b/docs/source/api/enums/ChatMemberStatus.rst
new file mode 100644
index 0000000000..bff23eda66
--- /dev/null
+++ b/docs/source/api/enums/ChatMemberStatus.rst
@@ -0,0 +1,8 @@
+ChatMemberStatus
+================
+
+.. autoclass:: pyrogram.enums.ChatMemberStatus()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatMembersFilter.rst b/docs/source/api/enums/ChatMembersFilter.rst
new file mode 100644
index 0000000000..5a970ffc6e
--- /dev/null
+++ b/docs/source/api/enums/ChatMembersFilter.rst
@@ -0,0 +1,8 @@
+ChatMembersFilter
+=================
+
+.. autoclass:: pyrogram.enums.ChatMembersFilter()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatType.rst b/docs/source/api/enums/ChatType.rst
new file mode 100644
index 0000000000..dd653055fa
--- /dev/null
+++ b/docs/source/api/enums/ChatType.rst
@@ -0,0 +1,8 @@
+ChatType
+========
+
+.. autoclass:: pyrogram.enums.ChatType()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageEntityType.rst b/docs/source/api/enums/MessageEntityType.rst
new file mode 100644
index 0000000000..c7a8965f12
--- /dev/null
+++ b/docs/source/api/enums/MessageEntityType.rst
@@ -0,0 +1,8 @@
+MessageEntityType
+=================
+
+.. autoclass:: pyrogram.enums.MessageEntityType()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageMedia.rst b/docs/source/api/enums/MessageMedia.rst
new file mode 100644
index 0000000000..f42693f0c1
--- /dev/null
+++ b/docs/source/api/enums/MessageMedia.rst
@@ -0,0 +1,8 @@
+MessageMedia
+============
+
+.. autoclass:: pyrogram.enums.MessageMedia()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageService.rst b/docs/source/api/enums/MessageService.rst
new file mode 100644
index 0000000000..7b7ee4e212
--- /dev/null
+++ b/docs/source/api/enums/MessageService.rst
@@ -0,0 +1,8 @@
+MessageService
+==============
+
+.. autoclass:: pyrogram.enums.MessageService()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessagesFilter.rst b/docs/source/api/enums/MessagesFilter.rst
new file mode 100644
index 0000000000..090907076a
--- /dev/null
+++ b/docs/source/api/enums/MessagesFilter.rst
@@ -0,0 +1,8 @@
+MessagesFilter
+==============
+
+.. autoclass:: pyrogram.enums.MessagesFilter()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ParseMode.rst b/docs/source/api/enums/ParseMode.rst
new file mode 100644
index 0000000000..1bcc74da04
--- /dev/null
+++ b/docs/source/api/enums/ParseMode.rst
@@ -0,0 +1,8 @@
+ParseMode
+=========
+
+.. autoclass:: pyrogram.enums.ParseMode()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/PollType.rst b/docs/source/api/enums/PollType.rst
new file mode 100644
index 0000000000..d00f9ce8a8
--- /dev/null
+++ b/docs/source/api/enums/PollType.rst
@@ -0,0 +1,8 @@
+PollType
+========
+
+.. autoclass:: pyrogram.enums.PollType()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/SentCodeType.rst b/docs/source/api/enums/SentCodeType.rst
new file mode 100644
index 0000000000..d738b195b1
--- /dev/null
+++ b/docs/source/api/enums/SentCodeType.rst
@@ -0,0 +1,8 @@
+SentCodeType
+============
+
+.. autoclass:: pyrogram.enums.SentCodeType()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/UserStatus.rst b/docs/source/api/enums/UserStatus.rst
new file mode 100644
index 0000000000..c9a77e1bf9
--- /dev/null
+++ b/docs/source/api/enums/UserStatus.rst
@@ -0,0 +1,8 @@
+UserStatus
+==========
+
+.. autoclass:: pyrogram.enums.UserStatus()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/cleanup.html b/docs/source/api/enums/cleanup.html
new file mode 100644
index 0000000000..bb9db7801a
--- /dev/null
+++ b/docs/source/api/enums/cleanup.html
@@ -0,0 +1,9 @@
+
\ No newline at end of file
diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst
new file mode 100644
index 0000000000..7dfa1f3c24
--- /dev/null
+++ b/docs/source/api/enums/index.rst
@@ -0,0 +1,45 @@
+Enumerations
+============
+
+This page is about Pyrogram enumerations.
+Enumerations are types that hold a group of related values to be used whenever a constant value is required.
+They will help you deal with those values in a type-safe way and also enable code completion so that you can be sure
+to apply only a valid value among the expected ones.
+
+-----
+
+.. currentmodule:: pyrogram.enums
+
+.. autosummary::
+    :nosignatures:
+
+    ChatAction
+    ChatEventAction
+    ChatMemberStatus
+    ChatMembersFilter
+    ChatType
+    MessageEntityType
+    MessageMedia
+    MessageService
+    MessagesFilter
+    ParseMode
+    PollType
+    SentCodeType
+    UserStatus
+
+.. toctree::
+    :hidden:
+
+    ChatAction
+    ChatEventAction
+    ChatMemberStatus
+    ChatMembersFilter
+    ChatType
+    MessageEntityType
+    MessageMedia
+    MessageService
+    MessagesFilter
+    ParseMode
+    PollType
+    SentCodeType
+    UserStatus
\ No newline at end of file
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 8838c3db17..910d031f1f 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -92,6 +92,7 @@ API Reference
     - :doc:`Pyrogram Client `: Reference details about the Client class.
     - :doc:`Available Methods `: List of available high-level methods.
     - :doc:`Available Types `: List of available high-level types.
+    - :doc:`Enumerations `: List of available enumerations.
     - :doc:`Bound Methods `: List of convenient bound methods.
 
 Meta
@@ -130,6 +131,7 @@ Meta
     api/methods/index
     api/types/index
     api/bound-methods/index
+    api/enums/index
     api/handlers
     api/decorators
     api/errors/index
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index e102a89dab..5e5ea69c39 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -37,7 +37,7 @@ class ContinuePropagation(StopAsyncIteration):
 
 import asyncio
 
-from . import raw, types, filters, handlers, emoji
+from . import raw, types, filters, handlers, emoji, enums
 from .client import Client
 from .sync import idle
 
diff --git a/pyrogram/client.py b/pyrogram/client.py
index 7d3dbd3701..cf3b8ec3b9 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -33,6 +33,7 @@
 
 import pyrogram
 from pyrogram import __version__, __license__
+from pyrogram import enums
 from pyrogram import raw
 from pyrogram import utils
 from pyrogram.crypto import aes
@@ -146,7 +147,7 @@ class Client(Methods, Scaffold):
             Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*.
             This is an alternative way to setup plugins if you don't want to use the *config.ini* file.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             The parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
             to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser
             completely.
@@ -197,7 +198,7 @@ def __init__(
         workdir: str = Scaffold.WORKDIR,
         config_file: str = Scaffold.CONFIG_FILE,
         plugins: dict = None,
-        parse_mode: str = Scaffold.PARSE_MODES[0],
+        parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
         no_updates: bool = None,
         takeout: bool = None,
         sleep_threshold: int = Session.SLEEP_THRESHOLD,
@@ -394,44 +395,21 @@ async def authorize(self) -> User:
 
         return signed_up
 
-    @property
-    def parse_mode(self):
-        return self._parse_mode
-
-    @parse_mode.setter
-    def parse_mode(self, parse_mode: Optional[str] = "combined"):
-        if isinstance(parse_mode, str):
-            parse_mode = parse_mode.lower()
-
-        if parse_mode not in self.PARSE_MODES:
-            raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
-                ", ".join(f'"{m}"' for m in self.PARSE_MODES[:-1]),
-                parse_mode
-            ))
-
-        self._parse_mode = parse_mode
-
-    # TODO: redundant, remove in next major version
-    def set_parse_mode(self, parse_mode: Optional[str] = "combined"):
+    def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]):
         """Set the parse mode to be used globally by the client.
 
         When setting the parse mode with this method, all other methods having a *parse_mode* parameter will follow the
-        global value by default. The default value *"combined"* enables both Markdown and HTML styles to be used and
-        combined together.
+        global value by default.
 
         Parameters:
-            parse_mode (``str``):
-                The new parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
-                to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser
-                completely.
-
-        Raises:
-            ValueError: In case the provided *parse_mode* is not a valid parse mode.
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`):
+                By default, texts are parsed using both Markdown and HTML styles.
+                You can combine both syntaxes together.
 
         Example:
             .. code-block:: python
 
-                from pyrogram import Client
+                from pyrogram import Client, enums
 
                 app = Client("my_account")
 
@@ -440,19 +418,19 @@ def set_parse_mode(self, parse_mode: Optional[str] = "combined"):
                     app.send_message("me", "1. **markdown** and html")
 
                     # Force Markdown-only, HTML is disabled
-                    app.set_parse_mode("markdown")
+                    app.set_parse_mode(enums.ParseMode.MARKDOWN)
                     app.send_message("me", "2. **markdown** and html")
 
                     # Force HTML-only, Markdown is disabled
-                    app.set_parse_mode("html")
+                    app.set_parse_mode(enums.ParseMode.HTML)
                     app.send_message("me", "3. **markdown** and html")
 
                     # Disable the parser completely
-                    app.set_parse_mode(None)
+                    app.set_parse_mode(enums.ParseMode.DISABLED)
                     app.send_message("me", "4. **markdown** and html")
 
                     # Bring back the default combined mode
-                    app.set_parse_mode()
+                    app.set_parse_mode(enums.ParseMode.DEFAULT)
                     app.send_message("me", "5. **markdown** and html")
         """
 
diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py
new file mode 100644
index 0000000000..50c85f608e
--- /dev/null
+++ b/pyrogram/enums/__init__.py
@@ -0,0 +1,31 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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_action import ChatAction
+from .chat_event_action import ChatEventAction
+from .chat_member_status import ChatMemberStatus
+from .chat_members_filter import ChatMembersFilter
+from .chat_type import ChatType
+from .message_entity_type import MessageEntityType
+from .message_media import MessageMedia
+from .message_service import MessageService
+from .messages_filter import MessagesFilter
+from .parse_mode import ParseMode
+from .poll_type import PollType
+from .sent_code_type import SentCodeType
+from .user_status import UserStatus
diff --git a/pyrogram/enums/auto_name.py b/pyrogram/enums/auto_name.py
new file mode 100644
index 0000000000..b1d10d1077
--- /dev/null
+++ b/pyrogram/enums/auto_name.py
@@ -0,0 +1,24 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import Enum
+
+
+class AutoName(Enum):
+    def _generate_next_value_(self, *args):
+        return self.lower()
diff --git a/pyrogram/enums/chat_action.py b/pyrogram/enums/chat_action.py
new file mode 100644
index 0000000000..167937e002
--- /dev/null
+++ b/pyrogram/enums/chat_action.py
@@ -0,0 +1,72 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class ChatAction(AutoName):
+    """Chat action enumeration used in :obj:`~pyrogram.types.ChatEvent`."""
+
+    TYPING = raw.types.SendMessageTypingAction
+    "Typing text message"
+
+    UPLOAD_PHOTO = raw.types.SendMessageUploadPhotoAction
+    "Uploading photo"
+
+    RECORD_VIDEO = raw.types.SendMessageRecordVideoAction
+    "Recording video"
+
+    UPLOAD_VIDEO = raw.types.SendMessageUploadVideoAction
+    "Uploading video"
+
+    RECORD_AUDIO = raw.types.SendMessageRecordAudioAction
+    "Recording audio"
+
+    UPLOAD_AUDIO = raw.types.SendMessageUploadAudioAction
+    "Uploading audio"
+
+    UPLOAD_DOCUMENT = raw.types.SendMessageUploadDocumentAction
+    "Uploading document"
+
+    FIND_LOCATION = raw.types.SendMessageGeoLocationAction
+    "Finding location"
+
+    RECORD_VIDEO_NOTE = raw.types.SendMessageRecordRoundAction
+    "Recording video note"
+
+    UPLOAD_VIDEO_NOTE = raw.types.SendMessageUploadRoundAction
+    "Uploading video note"
+
+    PLAYING = raw.types.SendMessageGamePlayAction
+    "Playing game"
+
+    CHOOSE_CONTACT = raw.types.SendMessageChooseContactAction
+    "Choosing contact"
+
+    SPEAKING = raw.types.SpeakingInGroupCallAction
+    "Speaking in group call"
+
+    IMPORT_HISTORY = raw.types.SendMessageHistoryImportAction
+    "Importing history"
+
+    CHOOSE_STICKER = raw.types.SendMessageChooseStickerAction
+    "Choosing sticker"
+
+    CANCEL = raw.types.SendMessageCancelAction
+    "Cancel ongoing chat action"
diff --git a/pyrogram/enums/chat_event_action.py b/pyrogram/enums/chat_event_action.py
new file mode 100644
index 0000000000..9b73de913c
--- /dev/null
+++ b/pyrogram/enums/chat_event_action.py
@@ -0,0 +1,127 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class ChatEventAction(AutoName):
+    """Chat event action enumeration used in :meth:`~pyrogram.Client.get_chat_event_log`."""
+
+    DESCRIPTION_CHANGED = auto()
+    "The chat description has been changed (see ``old_description`` and ``new_description``)"
+
+    HISTORY_TTL_CHANGED = auto()
+    "The history time-to-live has been changed (see ``old_history_ttl`` and ``new_history_ttl``)"
+
+    LINKED_CHAT_CHANGED = auto()
+    "The linked chat has been changed (see ``old_linked_chat`` and ``new_linked_chat``)"
+
+    # LOCATION_CHANGED = auto()
+    ""
+
+    PHOTO_CHANGED = auto()
+    "The chat photo has been changed (see ``old_photo`` and ``new_photo``)"
+
+    # STICKER_SET_CHANGED = auto()
+    ""
+
+    TITLE_CHANGED = auto()
+    "the chat title has been changed (see ``old_title`` and ``new_title``)"
+
+    USERNAME_CHANGED = auto()
+    "the chat username has been changed (see ``old_username`` and ``new_username``)"
+
+    CHAT_PERMISSIONS_CHANGED = auto()
+    "the default chat permissions has been changed (see ``old_chat_permissions`` and ``new_chat_permissions``)"
+
+    MESSAGE_DELETED = auto()
+    "a message has been deleted (see ``deleted_message``)"
+
+    # VOICE_CHAT_DISCARDED = auto()
+    ""
+
+    MESSAGE_EDITED = auto()
+    "a message has been edited (see ``old_message`` and ``new_message``)"
+
+    INVITE_LINK_EDITED = auto()
+    "An invite link has been edited (see ``old_invite_link`` and ``new_invite`` link)"
+
+    INVITE_LINK_REVOKED = auto()
+    "An invite link has been revoked (see ``revoked_invite_link``)"
+
+    INVITE_LINK_DELETED = auto()
+    "An invite link has been deleted (see ``deleted_invite_link``)"
+
+    MEMBER_INVITED = auto()
+    "a member has been invited by someone (see ``invited_member``)"
+
+    MEMBER_JOINED = auto()
+    "a member joined by themselves. (see ``user``)"
+
+    # MEMBER_JOINED_BY_LINK = auto()
+    ""
+
+    MEMBER_LEFT = auto()
+    "a member left by themselves. (see ``user``)"
+
+    # MEMBER_MUTED = auto()
+    ""
+
+    ADMINISTRATOR_PRIVILEGES_CHANGED = auto()
+    "a chat member has been promoted/demoted or their administrator privileges has changed (see ``old_administrator_privileges`` and ``new_administrator_privileges``)"
+
+    MEMBER_PERMISSIONS_CHANGED = auto()
+    "a chat member has been restricted/unrestricted or banned/unbanned, or their permissions has changed (see ``old_member_permissions`` and ``new_member_permissions``)"
+
+    # MEMBER_UNMUTED = auto()
+    ""
+
+    # MEMBER_VOLUME_CHANGED = auto()
+    ""
+
+    # VOICE_CHAT_STARTED = auto()
+    ""
+
+    POLL_STOPPED = auto()
+    "a poll has been stopped (see ``stopped_poll``)"
+
+    # VOICE_CHAT_SETTINGS_CHANGED = auto()
+    ""
+
+    INVITES_ENABLED = auto()
+    "the chat invitation has been enabled or disabled (see ``invites_enabled``)"
+
+    HISTORY_HIDDEN = auto()
+    "the chat history has been hidden or unhidden (see ``history_hidden``)"
+
+    SIGNATURES_ENABLED = auto()
+    "the message signatures have been enabled or disabled (see ``signatures_enabled``)"
+
+    SLOW_MODE_CHANGED = auto()
+    "the slow mode has been changes (see ``old_slow_mode`` and ``new_slow_mode``)"
+
+    MESSAGE_PINNED = auto()
+    "a message has been pinned (see ``pinned_message``)"
+
+    MESSAGE_UNPINNED = auto()
+    "a message has been unpinned (see ``unpinned_message``)"
+
+    UNKNOWN = auto()
+    "Unknown chat event action"
diff --git a/pyrogram/enums/chat_member_status.py b/pyrogram/enums/chat_member_status.py
new file mode 100644
index 0000000000..7fa9e8eca8
--- /dev/null
+++ b/pyrogram/enums/chat_member_status.py
@@ -0,0 +1,43 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class ChatMemberStatus(AutoName):
+    """Chat member status enumeration used in :obj:`~pyrogram.types.ChatMember`."""
+
+    OWNER = auto()
+    "Chat owner"
+
+    ADMINISTRATOR = auto()
+    "Chat administrator"
+
+    MEMBER = auto()
+    "Chat member"
+
+    RESTRICTED = auto()
+    "Restricted chat member"
+
+    LEFT = auto()
+    "Left chat member"
+
+    BANNED = auto()
+    "Banned chat member"
diff --git a/pyrogram/enums/chat_members_filter.py b/pyrogram/enums/chat_members_filter.py
new file mode 100644
index 0000000000..089f3d4bb9
--- /dev/null
+++ b/pyrogram/enums/chat_members_filter.py
@@ -0,0 +1,42 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class ChatMembersFilter(AutoName):
+    """Chat members filter enumeration used in :meth:`~pyrogram.Client.get_chat_members`"""
+
+    ANY = raw.types.ChannelParticipantsSearch
+    "Any kind of member"
+
+    BANNED = raw.types.ChannelParticipantsKicked
+    "Banned members"
+
+    RESTRICTED = raw.types.ChannelParticipantsBanned
+    "Restricted members"
+
+    BOTS = raw.types.ChannelParticipantsBots
+    "Bots"
+
+    RECENT = raw.types.ChannelParticipantsRecent
+    "Recently active members"
+
+    ADMINISTRATORS = raw.types.ChannelParticipantsAdmins
+    "Administrators"
diff --git a/pyrogram/enums/chat_type.py b/pyrogram/enums/chat_type.py
new file mode 100644
index 0000000000..5750e16d7c
--- /dev/null
+++ b/pyrogram/enums/chat_type.py
@@ -0,0 +1,40 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class ChatType(AutoName):
+    """Chat type enumeration used in :obj:`~pyrogram.types.Chat`."""
+
+    PRIVATE = auto()
+    "Chat is a private chat with a user"
+
+    BOT = auto()
+    "Chat is a private chat with a bot"
+
+    GROUP = auto()
+    "Chat is a basic group"
+
+    SUPERGROUP = auto()
+    "Chat is a supergroup"
+
+    CHANNEL = auto()
+    "Chat is a channel"
diff --git a/pyrogram/enums/message_entity_type.py b/pyrogram/enums/message_entity_type.py
new file mode 100644
index 0000000000..34655d37f9
--- /dev/null
+++ b/pyrogram/enums/message_entity_type.py
@@ -0,0 +1,81 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class MessageEntityType(AutoName):
+    """Message entity type enumeration used in :obj:`~pyrogram.types.MessageEntity`."""
+
+    MENTION = raw.types.MessageEntityMention
+    "``@username``"
+
+    HASHTAG = raw.types.MessageEntityHashtag
+    "``#hashtag``"
+
+    CASHTAG = raw.types.MessageEntityCashtag
+    "``$USD``"
+
+    BOT_COMMAND = raw.types.MessageEntityBotCommand
+    "``/start@pyrogrambot``"
+
+    URL = raw.types.MessageEntityUrl
+    "``https://pyrogram.org`` (see ``url``)"
+
+    EMAIL = raw.types.MessageEntityEmail
+    "``do-not-reply@pyrogram.org``"
+
+    PHONE_NUMBER = raw.types.MessageEntityPhone
+    "``+1-123-456-7890``"
+
+    BOLD = raw.types.MessageEntityBold
+    "Bold text"
+
+    ITALIC = raw.types.MessageEntityItalic
+    "Italic text"
+
+    UNDERLINE = raw.types.MessageEntityUnderline
+    "Underlined text"
+
+    STRIKETHROUGH = raw.types.MessageEntityStrike
+    "Strikethrough text"
+
+    SPOILER = raw.types.MessageEntitySpoiler
+    "Spoiler text"
+
+    CODE = raw.types.MessageEntityCode
+    "Monowidth string"
+
+    PRE = raw.types.MessageEntityPre
+    "Monowidth block (see ``language``)"
+
+    BLOCKQUOTE = raw.types.MessageEntityBlockquote
+    "Blockquote text"
+
+    TEXT_LINK = raw.types.MessageEntityTextUrl
+    "For clickable text URLs"
+
+    TEXT_MENTION = raw.types.MessageEntityMentionName
+    "for users without usernames (see ``user``)"
+
+    BANK_CARD = raw.types.MessageEntityBankCard
+    "Bank card text"
+
+    UNKNOWN = raw.types.MessageEntityUnknown
+    "Unknown message entity type"
diff --git a/pyrogram/enums/message_media.py b/pyrogram/enums/message_media.py
new file mode 100644
index 0000000000..b7dfd03bc6
--- /dev/null
+++ b/pyrogram/enums/message_media.py
@@ -0,0 +1,70 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class MessageMedia(AutoName):
+    """Message media enumeration used in :obj:`~pyrogram.types.Message`."""
+
+    AUDIO = auto()
+    "Audio media"
+
+    DOCUMENT = auto()
+    "Document media"
+
+    PHOTO = auto()
+    "Photo media"
+
+    STICKER = auto()
+    "Sticker media"
+
+    VIDEO = auto()
+    "Video media"
+
+    ANIMATION = auto()
+    "Animation media"
+
+    VOICE = auto()
+    "Voice media"
+
+    VIDEO_NOTE = auto()
+    "Video note media"
+
+    CONTACT = auto()
+    "Contact media"
+
+    LOCATION = auto()
+    "Location media"
+
+    VENUE = auto()
+    "Venue media"
+
+    POLL = auto()
+    "Poll media"
+
+    WEB_PAGE = auto()
+    "Web page media"
+
+    DICE = auto()
+    "Dice media"
+
+    GAME = auto()
+    "Game media"
diff --git a/pyrogram/enums/message_service.py b/pyrogram/enums/message_service.py
new file mode 100644
index 0000000000..b38e471793
--- /dev/null
+++ b/pyrogram/enums/message_service.py
@@ -0,0 +1,70 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class MessageService(AutoName):
+    """Message service enumeration used in :obj:`~pyrogram.types.Message`."""
+
+    NEW_CHAT_MEMBERS = auto()
+    "New members join"
+
+    LEFT_CHAT_MEMBERS = auto()
+    "Left chat members"
+
+    NEW_CHAT_TITLE = auto()
+    "New chat title"
+
+    NEW_CHAT_PHOTO = auto()
+    "New chat photo"
+
+    DELETE_CHAT_PHOTO = auto()
+    "Deleted chat photo"
+
+    GROUP_CHAT_CREATED = auto()
+    "Group chat created"
+
+    CHANNEL_CHAT_CREATED = auto()
+    "Channel chat created"
+
+    MIGRATE_TO_CHAT_ID = auto()
+    "Migrated to chat id"
+
+    MIGRATE_FROM_CHAT_ID = auto()
+    "Migrated from chat id"
+
+    PINNED_MESSAGE = auto()
+    "Pinned message"
+
+    GAME_HIGH_SCORE = auto()
+    "Game high score"
+
+    VOICE_CHAT_STARTED = auto()
+    "Voice chat started"
+
+    VOICE_CHAT_ENDED = auto()
+    "Voice chat ended"
+
+    VOICE_CHAT_SCHEDULED = auto()
+    "Voice chat scheduled"
+
+    VOICE_CHAT_MEMBERS_INVITED = auto()
+    "Voice chat members invited"
diff --git a/pyrogram/enums/messages_filter.py b/pyrogram/enums/messages_filter.py
new file mode 100644
index 0000000000..64d856aa98
--- /dev/null
+++ b/pyrogram/enums/messages_filter.py
@@ -0,0 +1,75 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class MessagesFilter(AutoName):
+    """Messages filter enumeration used in used in :meth:`~pyrogram.Client.search_messages` and used in :meth:`~pyrogram.Client.search_global`"""
+
+    ANY = raw.types.InputMessagesFilterEmpty
+    "Any kind of message"
+
+    PHOTO = raw.types.InputMessagesFilterPhotos
+    "Photo messages"
+
+    VIDEO = raw.types.InputMessagesFilterVideo
+    "Video messages"
+
+    PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo
+    "Photo and video messages"
+
+    DOCUMENT = raw.types.InputMessagesFilterDocument
+    "Document messages"
+
+    URL = raw.types.InputMessagesFilterUrl
+    "Messages containing URLs"
+
+    ANIMATION = raw.types.InputMessagesFilterGif
+    "Animation messages"
+
+    VOICE_NOTE = raw.types.InputMessagesFilterVoice
+    "Voice note messages"
+
+    VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo
+    "Video note messages"
+
+    AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo
+    "Audio and video note messages"
+
+    AUDIO = raw.types.InputMessagesFilterMusic
+    "Audio messages (music)"
+
+    CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos
+    "Chat photo messages"
+
+    PHONE_CALL = raw.types.InputMessagesFilterPhoneCalls
+    "Phone call messages"
+
+    MENTION = raw.types.InputMessagesFilterMyMentions
+    "Messages containing mentions"
+
+    LOCATION = raw.types.InputMessagesFilterGeo
+    "Location messages"
+
+    CONTACT = raw.types.InputMessagesFilterContacts
+    "Contact messages"
+
+    PINNED = raw.types.InputMessagesFilterPinned
+    "Pinned messages"
diff --git a/pyrogram/enums/parse_mode.py b/pyrogram/enums/parse_mode.py
new file mode 100644
index 0000000000..26dc165a25
--- /dev/null
+++ b/pyrogram/enums/parse_mode.py
@@ -0,0 +1,37 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class ParseMode(AutoName):
+    """Parse mode enumeration used in various places to set a specific parse mode"""
+
+    DEFAULT = auto()
+    "Default mode. Markdown and HTML combined"
+
+    MARKDOWN = auto()
+    "Markdown only mode"
+
+    HTML = auto()
+    "HTML only mode"
+
+    DISABLED = auto()
+    "Disabled mode"
diff --git a/pyrogram/enums/poll_type.py b/pyrogram/enums/poll_type.py
new file mode 100644
index 0000000000..384592dee3
--- /dev/null
+++ b/pyrogram/enums/poll_type.py
@@ -0,0 +1,31 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class PollType(AutoName):
+    """Poll type enumeration used in :obj:`~pyrogram.types.Poll`."""
+
+    QUIZ = auto()
+    "Quiz poll"
+
+    REGULAR = auto()
+    "Regular poll"
diff --git a/pyrogram/enums/sent_code_type.py b/pyrogram/enums/sent_code_type.py
new file mode 100644
index 0000000000..73ae724cf2
--- /dev/null
+++ b/pyrogram/enums/sent_code_type.py
@@ -0,0 +1,39 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class SentCodeType(AutoName):
+    """Sent code type enumeration used in :obj:`~pyrogram.types.SentCode`."""
+
+    APP = raw.types.auth.SentCodeTypeApp
+    "The code was sent through the telegram app."
+
+    CALL = raw.types.auth.SentCodeTypeCall
+    "The code will be sent via a phone call. A synthesized voice will tell the user which verification code to input."
+
+    FLASH_CALL = raw.types.auth.SentCodeTypeFlashCall
+    "The code will be sent via a flash phone call, that will be closed immediately."
+
+    MISSED_CALL = raw.types.auth.SentCodeTypeMissedCall
+    "Missed call"
+
+    SMS = raw.types.auth.SentCodeTypeSms
+    "The code was sent via SMS."
diff --git a/pyrogram/enums/user_status.py b/pyrogram/enums/user_status.py
new file mode 100644
index 0000000000..c7c25234cb
--- /dev/null
+++ b/pyrogram/enums/user_status.py
@@ -0,0 +1,43 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 enum import auto
+
+from .auto_name import AutoName
+
+
+class UserStatus(AutoName):
+    """User status enumeration used in :obj:`~pyrogram.types.User`."""
+
+    ONLINE = auto()
+    """User is online"""
+
+    OFFLINE = auto()
+    """User is offline"""
+
+    RECENTLY = auto()
+    """User was seen recently"""
+
+    LAST_WEEK = auto()
+    """User was seen last week"""
+
+    LAST_MONTH = auto()
+    """User was seen last month"""
+
+    LONG_AGO = auto()
+    """User was seen long ago"""
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index 2a44fd4f9a..276d70c299 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -21,6 +21,7 @@
 from typing import Callable, Union, List, Pattern
 
 import pyrogram
+from pyrogram import enums
 from pyrogram.types import Message, CallbackQuery, InlineQuery, InlineKeyboardMarkup, ReplyKeyboardMarkup, Update
 
 
@@ -438,7 +439,7 @@ async def dice_filter(_, __, m: Message):
 
 # region private_filter
 async def private_filter(_, __, m: Message):
-    return bool(m.chat and m.chat.type in {"private", "bot"})
+    return bool(m.chat and m.chat.type in {enums.ChatType.PRIVATE, enums.ChatType.BOT})
 
 
 private = create(private_filter)
@@ -449,7 +450,7 @@ async def private_filter(_, __, m: Message):
 
 # region group_filter
 async def group_filter(_, __, m: Message):
-    return bool(m.chat and m.chat.type in {"group", "supergroup"})
+    return bool(m.chat and m.chat.type in {enums.ChatType.GROUP, enums.ChatType.SUPERGROUP})
 
 
 group = create(group_filter)
@@ -460,7 +461,7 @@ async def group_filter(_, __, m: Message):
 
 # region channel_filter
 async def channel_filter(_, __, m: Message):
-    return bool(m.chat and m.chat.type == "channel")
+    return bool(m.chat and m.chat.type == enums.ChatType.CHANNEL)
 
 
 channel = create(channel_filter)
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index 07d831a964..4c8ae60229 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -19,22 +19,12 @@
 import logging
 from typing import Union, List
 
-from pyrogram import raw
-from pyrogram import types
+from pyrogram import raw, types, enums
 from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class Filters:
-    ALL = "all"
-    BANNED = "banned"
-    RESTRICTED = "restricted"
-    BOTS = "bots"
-    RECENT = "recent"
-    ADMINISTRATORS = "administrators"
-
-
 class GetChatMembers(Scaffold):
     async def get_chat_members(
         self,
@@ -42,7 +32,7 @@ async def get_chat_members(
         offset: int = 0,
         limit: int = 200,
         query: str = "",
-        filter: str = Filters.RECENT
+        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
     ) -> List["types.ChatMember"]:
         """Get a chunk of the members list of a chat.
 
diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index 1295edef44..07c0c5faed 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -19,7 +19,7 @@
 import logging
 from typing import Union, List, Optional
 
-from pyrogram import types
+from pyrogram import types, enums
 from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
@@ -32,7 +32,7 @@ async def copy_message(
         from_chat_id: Union[int, str],
         message_id: int,
         caption: str = None,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
@@ -69,12 +69,9 @@ async def copy_message(
                 If not specified, the original caption is kept.
                 Pass "" (empty string) to remove the caption.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the new caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py
index 2f009a0586..ed99b62d70 100644
--- a/pyrogram/methods/messages/edit_inline_caption.py
+++ b/pyrogram/methods/messages/edit_inline_caption.py
@@ -18,7 +18,7 @@
 
 from typing import Optional
 
-from pyrogram import types
+from pyrogram import types, enums
 from pyrogram.scaffold import Scaffold
 
 
@@ -27,7 +27,7 @@ async def edit_inline_caption(
         self,
         inline_message_id: str,
         caption: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> bool:
         """Edit the caption of inline media messages.
@@ -39,12 +39,9 @@ async def edit_inline_caption(
             caption (``str``):
                 New caption of the media message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
                 An InlineKeyboardMarkup object.
diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py
index 996dd4f5be..af4b555574 100644
--- a/pyrogram/methods/messages/edit_inline_text.py
+++ b/pyrogram/methods/messages/edit_inline_text.py
@@ -18,7 +18,7 @@
 
 from typing import Optional
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.scaffold import Scaffold
@@ -30,7 +30,7 @@ async def edit_inline_text(
         self,
         inline_message_id: str,
         text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         disable_web_page_preview: bool = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> bool:
@@ -43,12 +43,9 @@ async def edit_inline_text(
             text (``str``):
                 New text of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             disable_web_page_preview (``bool``, *optional*):
                 Disables link previews for links in this message.
diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py
index 9abdfbe972..e368d4f57c 100644
--- a/pyrogram/methods/messages/edit_message_caption.py
+++ b/pyrogram/methods/messages/edit_message_caption.py
@@ -18,7 +18,7 @@
 
 from typing import Union, List, Optional
 
-from pyrogram import types
+from pyrogram import types, enums
 from pyrogram.scaffold import Scaffold
 
 
@@ -28,7 +28,7 @@ async def edit_message_caption(
         chat_id: Union[int, str],
         message_id: int,
         caption: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> "types.Message":
@@ -46,12 +46,9 @@ async def edit_message_caption(
             caption (``str``):
                 New caption of the media message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index 5d6ba9cfa9..c58429a257 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -18,7 +18,7 @@
 
 from typing import Union, List, Optional
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.scaffold import Scaffold
@@ -30,7 +30,7 @@ async def edit_message_text(
         chat_id: Union[int, str],
         message_id: int,
         text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         entities: List["types.MessageEntity"] = None,
         disable_web_page_preview: bool = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
@@ -49,12 +49,9 @@ async def edit_message_text(
             text (``str``):
                 New text of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in message text, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index c3fb7acbac..2c22b26f79 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -18,37 +18,17 @@
 
 from typing import AsyncGenerator, Optional
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.scaffold import Scaffold
 
 
-class Filters:
-    EMPTY = raw.types.InputMessagesFilterEmpty()
-    PHOTO = raw.types.InputMessagesFilterPhotos()
-    VIDEO = raw.types.InputMessagesFilterVideo()
-    PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo()
-    DOCUMENT = raw.types.InputMessagesFilterDocument()
-    URL = raw.types.InputMessagesFilterUrl()
-    ANIMATION = raw.types.InputMessagesFilterGif()
-    VOICE_NOTE = raw.types.InputMessagesFilterVoice()
-    AUDIO = raw.types.InputMessagesFilterMusic()
-    CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos()
-    AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
-    VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
-    LOCATION = raw.types.InputMessagesFilterGeo()
-    CONTACT = raw.types.InputMessagesFilterContacts()
-
-
-POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), Filters.__dict__.keys())))
-
-
 class SearchGlobal(Scaffold):
     async def search_global(
         self,
         query: str = "",
-        filter: str = "empty",
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
         limit: int = 0,
     ) -> Optional[AsyncGenerator["types.Message", None]]:
         """Search messages globally from all of your chats.
@@ -65,23 +45,9 @@ async def search_global(
                 Text query string.
                 Use "@" to search for mentions.
             
-            filter (``str``, *optional*):
-                Pass a filter in order to search for specific kind of messages only:
-
-                - ``"empty"``: Search for all kind of messages (default).
-                - ``"photo"``: Search for photos.
-                - ``"video"``: Search for video.
-                - ``"photo_video"``: Search for either photo or video.
-                - ``"document"``: Search for documents (generic files).
-                - ``"url"``: Search for messages containing URLs (web links).
-                - ``"animation"``: Search for animations (GIFs).
-                - ``"voice_note"``: Search for voice notes.
-                - ``"audio"``: Search for audio files (music).
-                - ``"chat_photo"``: Search for chat photos.
-                - ``"audio_video_note"``: Search for either audio or video notes.
-                - ``"video_note"``: Search for video notes.
-                - ``"location"``: Search for location messages.
-                - ``"contact"``: Search for contact messages.
+            filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
+                Pass a filter in order to search for specific kind of messages only.
+                Defaults to any message (no filter).
 
             limit (``int``, *optional*):
                 Limits the number of messages to be retrieved.
@@ -101,11 +67,6 @@ async def search_global(
                 for message in app.search_global(filter="photo", limit=20):
                     print(message.photo)
         """
-        try:
-            filter = Filters.__dict__[filter.upper()]
-        except KeyError:
-            raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
-                filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
         current = 0
         # There seems to be an hard limit of 10k, beyond which Telegram starts spitting one message at a time.
         total = abs(limit) or (1 << 31)
@@ -121,7 +82,7 @@ async def search_global(
                 await self.send(
                     raw.functions.messages.SearchGlobal(
                         q=query,
-                        filter=filter,
+                        filter=filter.value(),
                         min_date=0,
                         max_date=0,
                         offset_rate=offset_date,
diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py
index 78b6965402..d8da0163e5 100644
--- a/pyrogram/methods/messages/search_global_count.py
+++ b/pyrogram/methods/messages/search_global_count.py
@@ -16,16 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram.scaffold import Scaffold
-from .search_messages import Filters, POSSIBLE_VALUES
 
 
 class SearchGlobalCount(Scaffold):
     async def search_global_count(
         self,
         query: str = "",
-        filter: str = "empty",
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
     ) -> int:
         """Get the count of messages resulting from a global search.
 
@@ -36,37 +35,16 @@ async def search_global_count(
                 Text query string.
                 Use "@" to search for mentions.
 
-            filter (``str``, *optional*):
+            filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
                 Pass a filter in order to search for specific kind of messages only:
 
-                - ``"empty"``: Search for all kind of messages (default).
-                - ``"photo"``: Search for photos.
-                - ``"video"``: Search for video.
-                - ``"photo_video"``: Search for either photo or video.
-                - ``"document"``: Search for documents (generic files).
-                - ``"url"``: Search for messages containing URLs (web links).
-                - ``"animation"``: Search for animations (GIFs).
-                - ``"voice_note"``: Search for voice notes.
-                - ``"audio"``: Search for audio files (music).
-                - ``"chat_photo"``: Search for chat photos.
-                - ``"audio_video_note"``: Search for either audio or video notes.
-                - ``"video_note"``: Search for video notes.
-                - ``"location"``: Search for location messages.
-                - ``"contact"``: Search for contact messages.
-
         Returns:
             ``int``: On success, the messages count is returned.
         """
-        try:
-            filter = Filters.__dict__[filter.upper()]
-        except KeyError:
-            raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
-                filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
-
         r = await self.send(
             raw.functions.messages.SearchGlobal(
                 q=query,
-                filter=filter,
+                filter=filter.value(),
                 min_date=0,
                 max_date=0,
                 offset_rate=0,
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index 91bd6a5afc..07728193e4 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -18,56 +18,25 @@
 
 from typing import Union, List, AsyncGenerator, Optional
 
-from pyrogram import raw
-from pyrogram import types
-from pyrogram import utils
+from pyrogram import raw, types, utils, enums
 from pyrogram.scaffold import Scaffold
 
 
-class Filters:
-    EMPTY = raw.types.InputMessagesFilterEmpty()
-    PHOTO = raw.types.InputMessagesFilterPhotos()
-    VIDEO = raw.types.InputMessagesFilterVideo()
-    PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo()
-    DOCUMENT = raw.types.InputMessagesFilterDocument()
-    URL = raw.types.InputMessagesFilterUrl()
-    ANIMATION = raw.types.InputMessagesFilterGif()
-    VOICE_NOTE = raw.types.InputMessagesFilterVoice()
-    AUDIO = raw.types.InputMessagesFilterMusic()
-    CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos()
-    PHONE_CALL = raw.types.InputMessagesFilterPhoneCalls()
-    AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
-    VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
-    MENTION = raw.types.InputMessagesFilterMyMentions()
-    LOCATION = raw.types.InputMessagesFilterGeo()
-    CONTACT = raw.types.InputMessagesFilterContacts()
-    PINNED = raw.types.InputMessagesFilterPinned()
-
-
-POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), Filters.__dict__.keys())))
-
-
 # noinspection PyShadowingBuiltins
 async def get_chunk(
     client: Scaffold,
     chat_id: Union[int, str],
     query: str = "",
-    filter: str = "empty",
+    filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
     offset: int = 0,
     limit: int = 100,
     from_user: Union[int, str] = None
 ) -> List["types.Message"]:
-    try:
-        filter = Filters.__dict__[filter.upper()]
-    except KeyError:
-        raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
-            filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
-
     r = await client.send(
         raw.functions.messages.Search(
             peer=await client.resolve_peer(chat_id),
             q=query,
-            filter=filter,
+            filter=filter.value(),
             min_date=0,
             max_date=0,
             offset_id=0,
@@ -95,7 +64,7 @@ async def search_messages(
         chat_id: Union[int, str],
         query: str = "",
         offset: int = 0,
-        filter: str = "empty",
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
         limit: int = 0,
         from_user: Union[int, str] = None
     ) -> Optional[AsyncGenerator["types.Message", None]]:
@@ -119,26 +88,9 @@ async def search_messages(
                 Sequential number of the first message to be returned.
                 Defaults to 0.
 
-            filter (``str``, *optional*):
-                Pass a filter in order to search for specific kind of messages only:
-
-                - ``"empty"``: Search for all kind of messages (default).
-                - ``"photo"``: Search for photos.
-                - ``"video"``: Search for video.
-                - ``"photo_video"``: Search for either photo or video.
-                - ``"document"``: Search for documents (generic files).
-                - ``"url"``: Search for messages containing URLs (web links).
-                - ``"animation"``: Search for animations (GIFs).
-                - ``"voice_note"``: Search for voice notes.
-                - ``"audio"``: Search for audio files (music).
-                - ``"chat_photo"``: Search for chat photos.
-                - ``"phone_call"``: Search for phone calls.
-                - ``"audio_video_note"``: Search for either audio or video notes.
-                - ``"video_note"``: Search for video notes.
-                - ``"mention"``: Search for messages containing mentions to yourself.
-                - ``"location"``: Search for location messages.
-                - ``"contact"``: Search for contact messages.
-                - ``"pinned"``: Search for pinned messages.
+            filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
+                Pass a filter in order to search for specific kind of messages only.
+                Defaults to any message (no filter).
 
             limit (``int``, *optional*):
                 Limits the number of messages to be retrieved.
@@ -153,18 +105,21 @@ async def search_messages(
         Example:
             .. code-block:: python
 
+                from pyrogram import enums
+
                 # Search for text messages in chat. Get the last 120 results
                 for message in app.search_messages(chat_id, query="hello", limit=120):
                     print(message.text)
 
                 # Search for pinned messages in chat
-                for message in app.search_messages(chat_id, filter="pinned"):
+                for message in app.search_messages(chat_id, filter=enums.MessagesFilter.PINNED):
                     print(message.text)
 
                 # Search for messages containing "hello" sent by yourself in chat
                 for message in app.search_messages(chat, "hello", from_user="me"):
                     print(message.text)
         """
+
         current = 0
         total = abs(limit) or (1 << 31) - 1
         limit = min(100, total)
diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py
index 3004eb39ce..87e0a74572 100644
--- a/pyrogram/methods/messages/search_messages_count.py
+++ b/pyrogram/methods/messages/search_messages_count.py
@@ -18,9 +18,8 @@
 
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram.scaffold import Scaffold
-from .search_messages import Filters, POSSIBLE_VALUES
 
 
 class SearchMessagesCount(Scaffold):
@@ -28,7 +27,7 @@ async def search_messages_count(
         self,
         chat_id: Union[int, str],
         query: str = "",
-        filter: str = "empty",
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
         from_user: Union[int, str] = None
     ) -> int:
         """Get the count of messages resulting from a search inside a chat.
@@ -47,44 +46,20 @@ async def search_messages_count(
                 When passed while searching for media messages, the query will be applied to captions.
                 Defaults to "" (empty string).
 
-            filter (``str``, *optional*):
+            filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
                 Pass a filter in order to search for specific kind of messages only:
 
-                - ``"empty"``: Search for all kind of messages (default).
-                - ``"photo"``: Search for photos.
-                - ``"video"``: Search for video.
-                - ``"photo_video"``: Search for either photo or video.
-                - ``"document"``: Search for documents (generic files).
-                - ``"url"``: Search for messages containing URLs (web links).
-                - ``"animation"``: Search for animations (GIFs).
-                - ``"voice_note"``: Search for voice notes.
-                - ``"audio"``: Search for audio files (music).
-                - ``"chat_photo"``: Search for chat photos.
-                - ``"phone_call"``: Search for phone calls.
-                - ``"audio_video_note"``: Search for either audio or video notes.
-                - ``"video_note"``: Search for video notes.
-                - ``"mention"``: Search for messages containing mentions to yourself.
-                - ``"location"``: Search for location messages.
-                - ``"contact"``: Search for contact messages.
-                - ``"pinned"``: Search for pinned messages.
-
             from_user (``int`` | ``str``, *optional*):
                 Unique identifier (int) or username (str) of the target user you want to search for messages from.
 
         Returns:
             ``int``: On success, the messages count is returned.
         """
-        try:
-            filter = Filters.__dict__[filter.upper()]
-        except KeyError:
-            raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
-                filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
-
         r = await self.send(
             raw.functions.messages.Search(
                 peer=await self.resolve_peer(chat_id),
                 q=query,
-                filter=filter,
+                filter=filter.value(),
                 min_date=0,
                 max_date=0,
                 offset_id=0,
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 963d0681b9..3777b3eab1 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -20,7 +20,7 @@
 import re
 from typing import Union, BinaryIO, List, Optional
 
-from pyrogram import StopTransmission
+from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
@@ -36,7 +36,7 @@ async def send_animation(
         animation: Union[str, BinaryIO],
         caption: str = "",
         unsave: bool = False,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         width: int = 0,
@@ -78,12 +78,9 @@ async def send_animation(
                 By default, the server will save into your own collection any new animation you send.
                 Pass True to automatically unsave the sent animation. Defaults to False.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 921b7890c7..e00930af1d 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -20,7 +20,7 @@
 import re
 from typing import Union, BinaryIO, List, Optional
 
-from pyrogram import StopTransmission
+from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
@@ -35,7 +35,7 @@ async def send_audio(
         chat_id: Union[int, str],
         audio: Union[str, BinaryIO],
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         performer: str = None,
@@ -75,12 +75,9 @@ async def send_audio(
             caption (``str``, *optional*):
                 Audio caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 84fe9b17ee..5c8951212f 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -18,7 +18,7 @@
 
 from typing import Union, List, Optional
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.scaffold import Scaffold
@@ -30,7 +30,7 @@ async def send_cached_media(
         chat_id: Union[int, str],
         file_id: str,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
@@ -62,12 +62,9 @@ async def send_cached_media(
             caption (``str``, *optional*):
                 Media caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py
index fc79c01553..bbff1d4421 100644
--- a/pyrogram/methods/messages/send_chat_action.py
+++ b/pyrogram/methods/messages/send_chat_action.py
@@ -16,37 +16,19 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-import json
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram.scaffold import Scaffold
 
 
-class ChatAction:
-    TYPING = raw.types.SendMessageTypingAction
-    UPLOAD_PHOTO = raw.types.SendMessageUploadPhotoAction
-    RECORD_VIDEO = raw.types.SendMessageRecordVideoAction
-    UPLOAD_VIDEO = raw.types.SendMessageUploadVideoAction
-    RECORD_AUDIO = raw.types.SendMessageRecordAudioAction
-    UPLOAD_AUDIO = raw.types.SendMessageUploadAudioAction
-    UPLOAD_DOCUMENT = raw.types.SendMessageUploadDocumentAction
-    FIND_LOCATION = raw.types.SendMessageGeoLocationAction
-    RECORD_VIDEO_NOTE = raw.types.SendMessageRecordRoundAction
-    UPLOAD_VIDEO_NOTE = raw.types.SendMessageUploadRoundAction
-    PLAYING = raw.types.SendMessageGamePlayAction
-    CHOOSE_CONTACT = raw.types.SendMessageChooseContactAction
-    SPEAKING = raw.types.SpeakingInGroupCallAction
-    IMPORT_HISTORY = raw.types.SendMessageHistoryImportAction
-    CHOOSE_STICKER = raw.types.SendMessageChooseStickerAction
-    CANCEL = raw.types.SendMessageCancelAction
-
-
-POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), ChatAction.__dict__.keys())))
-
-
 class SendChatAction(Scaffold):
-    async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
+    async def send_chat_action(
+        self,
+        chat_id: Union[int, str],
+        action: "pyrogram.enums.ChatAction"
+    ) -> bool:
         """Tell the other party that something is happening on your side.
 
         Parameters:
@@ -55,14 +37,8 @@ async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
                 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).
 
-            action (``str``):
-                Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
-                text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
-                *"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
-                *"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
-                *"choose_contact"* for contacts, *"playing"* for games, *"speaking"* for speaking in group calls or
-                *"import_history"* for importing history, *"choose_sticker"* for stickers or
-                *"cancel"* to cancel any chat action currently displayed.
+            action (:obj:`~pyrogram.enums.ChatAction`):
+                Type of action to broadcast.
 
         Returns:
             ``bool``: On success, True is returned.
@@ -73,29 +49,27 @@ async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
         Example:
             .. code-block:: python
 
+                from pyrogram import enums
+
                 # Send "typing" chat action
-                app.send_chat_action(chat_id, "typing")
+                app.send_chat_action(chat_id, enums.ChatAction.TYPING)
 
                 # Send "upload_video" chat action
-                app.send_chat_action(chat_id, "upload_video")
+                app.send_chat_action(chat_id, enums.ChatAction.UPLOAD_VIDEO)
 
                 # Send "playing" chat action
-                app.send_chat_action(chat_id, "playing")
+                app.send_chat_action(chat_id, enums.ChatAction.PLAYING)
 
                 # Cancel any current chat action
-                app.send_chat_action(chat_id, "cancel")
+                app.send_chat_action(chat_id, enums.ChatAction.CANCEL)
         """
 
-        try:
-            action = ChatAction.__dict__[action.upper()]
-        except KeyError:
-            raise ValueError("Invalid chat action '{}'. Possible values are: {}".format(
-                action, json.dumps(POSSIBLE_VALUES, indent=4))) from None
+        action_name = action.name.lower()
 
-        if "Upload" in action.__name__ or "History" in action.__name__:
-            action = action(progress=0)
+        if "upload" in action_name or "history" in action_name:
+            action = action.value(progress=0)
         else:
-            action = action()
+            action = action.value()
 
         return await self.send(
             raw.functions.messages.SetTyping(
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index c3765a1726..4a35f8a5e9 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -20,7 +20,7 @@
 import re
 from typing import Union, BinaryIO, List, Optional
 
-from pyrogram import StopTransmission
+from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
@@ -36,7 +36,7 @@ async def send_document(
         document: Union[str, BinaryIO],
         thumb: Union[str, BinaryIO] = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         file_name: str = None,
         force_document: bool = None,
@@ -77,12 +77,9 @@ async def send_document(
             caption (``str``, *optional*):
                 Document caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index c0653a38d4..575aea33e7 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -18,7 +18,7 @@
 
 from typing import Union, List, Optional
 
-from pyrogram import raw, utils
+from pyrogram import raw, utils, enums
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -28,7 +28,7 @@ async def send_message(
         self,
         chat_id: Union[int, str],
         text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         entities: List["types.MessageEntity"] = None,
         disable_web_page_preview: bool = None,
         disable_notification: bool = None,
@@ -53,12 +53,9 @@ async def send_message(
             text (``str``):
                 Text of the message to be sent.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in message text, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index c70be84e2f..442b45aec5 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -21,7 +21,7 @@
 from typing import Union, BinaryIO, List, Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
@@ -35,7 +35,7 @@ async def send_photo(
         chat_id: Union[int, str],
         photo: Union[str, BinaryIO],
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         ttl_seconds: int = None,
         disable_notification: bool = None,
@@ -69,12 +69,9 @@ async def send_photo(
             caption (``str``, *optional*):
                 Photo caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index a412bcdff0..df27c0573f 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -19,7 +19,7 @@
 from typing import Union, List
 
 from pyrogram import raw
-from pyrogram import types
+from pyrogram import types, enums
 from pyrogram.scaffold import Scaffold
 
 
@@ -31,7 +31,7 @@ async def send_poll(
         options: List[str],
         is_anonymous: bool = True,
         allows_multiple_answers: bool = None,
-        type: str = "regular",
+        type: "enums.PollType" = enums.PollType.REGULAR,
         correct_option_id: int = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
@@ -62,9 +62,9 @@ async def send_poll(
                 True, if the poll needs to be anonymous.
                 Defaults to True.
 
-            type (``str``, *optional*):
-                Poll type, "quiz" or "regular".
-                Defaults to "regular"
+            type (:obj`~pyrogram.enums.PollType`, *optional*):
+                Poll type, :obj:`~pyrogram.enums.PollType.QUIZ` or :obj:`~pyrogram.enums.PollType.REGULAR`.
+                Defaults to :obj:`~pyrogram.enums.PollType.REGULAR`.
 
             allows_multiple_answers (``bool``, *optional*):
                 True, if the poll allows multiple answers, ignored for polls in quiz mode.
@@ -112,7 +112,7 @@ async def send_poll(
                         ],
                         multiple_choice=allows_multiple_answers or None,
                         public_voters=not is_anonymous or None,
-                        quiz=type == "quiz" or None
+                        quiz=type == enums.PollType.QUIZ or None
                     ),
                     correct_answers=None if correct_option_id is None else [bytes([correct_option_id])]
                 ),
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index e9448a2209..f6dc00eebe 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -20,7 +20,7 @@
 import re
 from typing import Union, BinaryIO, List, Optional
 
-from pyrogram import StopTransmission
+from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
@@ -35,7 +35,7 @@ async def send_video(
         chat_id: Union[int, str],
         video: Union[str, BinaryIO],
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         ttl_seconds: int = None,
         duration: int = 0,
@@ -75,12 +75,9 @@ async def send_video(
             caption (``str``, *optional*):
                 Video caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 80eb386d2c..c7e960fd04 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -20,7 +20,7 @@
 import re
 from typing import Union, BinaryIO, List, Optional
 
-from pyrogram import StopTransmission
+from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
@@ -35,7 +35,7 @@ async def send_voice(
         chat_id: Union[int, str],
         voice: Union[str, BinaryIO],
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         disable_notification: bool = None,
@@ -69,12 +69,9 @@ async def send_voice(
             caption (``str``, *optional*):
                 Voice message caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index b1ce5c5d46..c5f3c1e12d 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -174,13 +174,13 @@ def unparse(text: str, entities: list):
 
             entities_offsets.append((start_tag, start,))
             entities_offsets.append((end_tag, end,))
-            
+
         entities_offsets = map(
             lambda x: x[1],
             sorted(
                 enumerate(entities_offsets),
-                key = lambda x: (x[1][1], x[0]),
-                reverse = True
+                key=lambda x: (x[1][1], x[0]),
+                reverse=True
             )
         )
 
diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py
index 898ac3d6a9..8b24d06302 100644
--- a/pyrogram/parser/markdown.py
+++ b/pyrogram/parser/markdown.py
@@ -147,8 +147,14 @@ def unparse(text: str, entities: list):
             entities_offsets.append((start_tag, start,))
             entities_offsets.append((end_tag, end,))
 
-        # sorting by offset (desc)
-        entities_offsets.sort(key=lambda x: -x[1])
+        entities_offsets = map(
+            lambda x: x[1],
+            sorted(
+                enumerate(entities_offsets),
+                key=lambda x: (x[1][1], x[0]),
+                reverse=True
+            )
+        )
 
         for entity, offset in entities_offsets:
             text = text[:offset] + entity + text[offset:]
diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py
index d294e04d51..884e17558e 100644
--- a/pyrogram/parser/parser.py
+++ b/pyrogram/parser/parser.py
@@ -16,10 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from collections import OrderedDict
 from typing import Optional
 
 import pyrogram
+from pyrogram import enums
 from .html import HTML
 from .markdown import Markdown
 
@@ -30,36 +30,26 @@ def __init__(self, client: Optional["pyrogram.Client"]):
         self.html = HTML(client)
         self.markdown = Markdown(client)
 
-    async def parse(self, text: str, mode: Optional[str] = object):
+    async def parse(self, text: str, mode: Optional[str] = None):
         text = str(text if text else "").strip()
 
-        if mode == object:
+        if mode is None:
             if self.client:
                 mode = self.client.parse_mode
             else:
-                mode = "combined"
-
-        if mode is None:
-            return OrderedDict([
-                ("message", text),
-                ("entities", [])
-            ])
-
-        mode = mode.lower()
+                mode = enums.ParseMode.DEFAULT
 
-        if mode == "combined":
+        if mode == enums.ParseMode.DEFAULT:
             return await self.markdown.parse(text)
 
-        if mode in ["markdown", "md"]:
+        if mode == enums.ParseMode.MARKDOWN:
             return await self.markdown.parse(text, True)
 
-        if mode == "html":
+        if mode == enums.ParseMode.HTML:
             return await self.html.parse(text)
 
-        raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
-            ", ".join(f'"{m}"' for m in pyrogram.Client.PARSE_MODES[:-1]),
-            mode
-        ))
+        if mode == enums.ParseMode.DISABLED:
+            return {"message": text, "entities": []}
 
     @staticmethod
     def unparse(text: str, entities: list, is_html: bool):
diff --git a/pyrogram/scaffold.py b/pyrogram/scaffold.py
index d68ddf787b..d87d1522c8 100644
--- a/pyrogram/scaffold.py
+++ b/pyrogram/scaffold.py
@@ -26,7 +26,7 @@
 from pathlib import Path
 
 import pyrogram
-from pyrogram import __version__
+from pyrogram import __version__, enums
 from pyrogram.parser import Parser
 from pyrogram.session.internals import MsgId
 from .mime_types import mime_types
@@ -46,8 +46,6 @@ class Scaffold:
     WORKDIR = PARENT_DIR
     CONFIG_FILE = PARENT_DIR / "config.ini"
 
-    PARSE_MODES = ["combined", "markdown", "md", "html", None]
-
     mimetypes = MimeTypes()
     mimetypes.readfp(StringIO(mime_types))
 
@@ -90,7 +88,7 @@ def __init__(self):
         self.rnd_id = MsgId
 
         self.parser = Parser(self)
-        self.parse_mode = "combined"
+        self.parse_mode = enums.ParseMode.DEFAULT
 
         self.session = None
 
diff --git a/pyrogram/types/authorization/sent_code.py b/pyrogram/types/authorization/sent_code.py
index a471445af2..b0ac9eebc6 100644
--- a/pyrogram/types/authorization/sent_code.py
+++ b/pyrogram/types/authorization/sent_code.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram import raw
+from pyrogram import raw, enums
 from ..object import Object
 
 
@@ -24,29 +24,25 @@ class SentCode(Object):
     """Contains info on a sent confirmation code.
 
     Parameters:
-        type (``str``):
+        type (:obj:`~pyrogram.enums.SentCodeType`):
             Type of the current sent code.
-            Can be *"app"* (code sent via Telegram), *"sms"* (code sent via SMS), *"call"* (code sent via voice call) or
-            *"flash_call"* (code is in the last 5 digits of the caller's phone number).
 
         phone_code_hash (``str``):
             Confirmation code identifier useful for the next authorization steps (either
             :meth:`~pyrogram.Client.sign_in` or :meth:`~pyrogram.Client.sign_up`).
 
-        next_type (``str``):
+        next_type (:obj:`~pyrogram.enums.SentCodeType`, *optional*):
             Type of the next code to be sent with :meth:`~pyrogram.Client.resend_code`.
-            Can be *"sms"* (code will be sent via SMS), *"call"* (code will be sent via voice call) or *"flash_call"*
-            (code will be in the last 5 digits of caller's phone number).
 
-        timeout (``int``):
+        timeout (``int``, *optional*):
             Delay in seconds before calling :meth:`~pyrogram.Client.resend_code`.
     """
 
     def __init__(
         self, *,
-        type: str,
+        type: "enums.SentCodeType",
         phone_code_hash: str,
-        next_type: str = None,
+        next_type: "enums.SentCodeType" = None,
         timeout: int = None
     ):
         super().__init__()
@@ -58,29 +54,9 @@ def __init__(
 
     @staticmethod
     def _parse(sent_code: raw.types.auth.SentCode) -> "SentCode":
-        type = sent_code.type
-
-        if isinstance(type, raw.types.auth.SentCodeTypeApp):
-            type = "app"
-        elif isinstance(type, raw.types.auth.SentCodeTypeSms):
-            type = "sms"
-        elif isinstance(type, raw.types.auth.SentCodeTypeCall):
-            type = "call"
-        elif isinstance(type, raw.types.auth.SentCodeTypeFlashCall):
-            type = "flash_call"
-
-        next_type = sent_code.next_type
-
-        if isinstance(next_type, raw.types.auth.CodeTypeSms):
-            next_type = "sms"
-        elif isinstance(next_type, raw.types.auth.CodeTypeCall):
-            next_type = "call"
-        elif isinstance(next_type, raw.types.auth.CodeTypeFlashCall):
-            next_type = "flash_call"
-
         return SentCode(
-            type=type,
+            type=enums.SentCodeType(type(sent_code.type)),
             phone_code_hash=sent_code.phone_code_hash,
-            next_type=next_type,
+            next_type=enums.SentCodeType(type(sent_code.next_type)) if sent_code.next_type else None,
             timeout=sent_code.timeout
         )
diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py
index 8cdd424a64..e5db872359 100644
--- a/pyrogram/types/bots_and_keyboards/callback_query.py
+++ b/pyrogram/types/bots_and_keyboards/callback_query.py
@@ -21,7 +21,7 @@
 from typing import Union, List, Match, Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from ..object import Object
 from ..update import Update
@@ -171,7 +171,7 @@ async def answer(self, text: str = None, show_alert: bool = None, url: str = Non
     async def edit_message_text(
         self,
         text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         disable_web_page_preview: bool = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> Union["types.Message", bool]:
@@ -183,12 +183,9 @@ async def edit_message_text(
             text (``str``):
                 New text of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             disable_web_page_preview (``bool``, *optional*):
                 Disables link previews for links in this message.
@@ -224,7 +221,7 @@ async def edit_message_text(
     async def edit_message_caption(
         self,
         caption: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> Union["types.Message", bool]:
         """Edit the caption of media messages attached to callback queries.
@@ -235,12 +232,9 @@ async def edit_message_caption(
             caption (``str``):
                 New caption of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
                 An InlineKeyboardMarkup object.
diff --git a/pyrogram/types/bots_and_keyboards/game_high_score.py b/pyrogram/types/bots_and_keyboards/game_high_score.py
index 7de78ce9e6..295b83fb23 100644
--- a/pyrogram/types/bots_and_keyboards/game_high_score.py
+++ b/pyrogram/types/bots_and_keyboards/game_high_score.py
@@ -32,7 +32,7 @@ class GameHighScore(Object):
         score (``int``):
             Score.
 
-        position (``position``, *optional*):
+        position (``int``, *optional*):
             Position in high score table for the game.
     """
 
diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
index 9779ec3960..de6a04207c 100644
--- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
+++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
@@ -43,7 +43,7 @@ class InlineKeyboardButton(Object):
              An HTTP URL used to automatically authorize the user. Can be used as a replacement for
              the `Telegram Login Widget `_.
 
-        user_id (``id``, *optional*):
+        user_id (``int``, *optional*):
             User id, for links to the user profile.
 
         switch_inline_query (``str``, *optional*):
diff --git a/pyrogram/types/inline_mode/inline_query.py b/pyrogram/types/inline_mode/inline_query.py
index 2522b6934f..6f671059d0 100644
--- a/pyrogram/types/inline_mode/inline_query.py
+++ b/pyrogram/types/inline_mode/inline_query.py
@@ -20,7 +20,7 @@
 
 import pyrogram
 from pyrogram import raw
-from pyrogram import types
+from pyrogram import types, enums
 from ..object import Object
 from ..update import Update
 
@@ -43,11 +43,8 @@ class InlineQuery(Object, Update):
         offset (``str``):
             Offset of the results to be returned, can be controlled by the bot.
 
-        chat_type (``str``, *optional*):
+        chat_type (:obj:`~pyrogram.enums.ChatType`, *optional*):
             Type of the chat, from which the inline query was sent.
-            Can be either "sender" for a private chat with the inline query sender, "private", "group", "supergroup", or
-            "channel". The chat type should be always known for requests sent from official clients and most
-            third-party clients, unless the request was sent from a secret chat.
 
         location (:obj:`~pyrogram.types.Location`. *optional*):
             Sender location, only for bots that request user location.
@@ -65,7 +62,7 @@ def __init__(
         from_user: "types.User",
         query: str,
         offset: str,
-        chat_type: str,
+        chat_type: "enums.ChatType",
         location: "types.Location" = None,
         matches: List[Match] = None
     ):
@@ -85,15 +82,15 @@ def _parse(client, inline_query: raw.types.UpdateBotInlineQuery, users: dict) ->
         chat_type = None
 
         if isinstance(peer_type, raw.types.InlineQueryPeerTypeSameBotPM):
-            chat_type = "sender"
+            chat_type = enums.ChatType.BOT
         elif isinstance(peer_type, raw.types.InlineQueryPeerTypePM):
-            chat_type = "private"
+            chat_type = enums.ChatType.PRIVATE
         elif isinstance(peer_type, raw.types.InlineQueryPeerTypeChat):
-            chat_type = "group"
+            chat_type = enums.ChatType.GROUP
         elif isinstance(peer_type, raw.types.InlineQueryPeerTypeMegagroup):
-            chat_type = "supergroup"
+            chat_type = enums.ChatType.SUPERGROUP
         elif isinstance(peer_type, raw.types.InlineQueryPeerTypeBroadcast):
-            chat_type = "channel"
+            chat_type = enums.ChatType.CHANNEL
 
         return InlineQuery(
             id=str(inline_query.query_id),
diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py
index 2281ae1cfd..4a170a1834 100644
--- a/pyrogram/types/inline_mode/inline_query_result_animation.py
+++ b/pyrogram/types/inline_mode/inline_query_result_animation.py
@@ -19,7 +19,7 @@
 from typing import Optional, List
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from .inline_query_result import InlineQueryResult
 
 
@@ -52,12 +52,9 @@ class InlineQueryResultAnimation(InlineQueryResult):
         caption (``str``, *optional*):
             Caption of the photo to be sent, 0-1024 characters.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -77,7 +74,7 @@ def __init__(
         title: str = None,
         description: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None,
         input_message_content: "types.InputMessageContent" = None
diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py
index e36ecb1124..06ab5f944e 100644
--- a/pyrogram/types/inline_mode/inline_query_result_audio.py
+++ b/pyrogram/types/inline_mode/inline_query_result_audio.py
@@ -16,10 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import Union, List
+from typing import Union, List, Optional
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from .inline_query_result import InlineQueryResult
 
 
@@ -50,13 +50,10 @@ class InlineQueryResultAudio(InlineQueryResult):
         caption (``str``, *optional*):
             Caption of the audio to be sent, 0-1024 characters.
             
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
-            
+
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
             
@@ -75,7 +72,7 @@ def __init__(
         performer: str = "",
         audio_duration: int = 0,
         caption: str = "",
-        parse_mode: Union[str, None] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None,
         input_message_content: "types.InputMessageContent" = None
diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py
index 679ee42947..110b604661 100644
--- a/pyrogram/types/inline_mode/inline_query_result_photo.py
+++ b/pyrogram/types/inline_mode/inline_query_result_photo.py
@@ -19,7 +19,7 @@
 from typing import Optional, List
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from .inline_query_result import InlineQueryResult
 
 
@@ -52,12 +52,9 @@ class InlineQueryResultPhoto(InlineQueryResult):
         caption (``str``, *optional*):
             Caption of the photo to be sent, 0-1024 characters.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -77,7 +74,7 @@ def __init__(
         title: str = None,
         description: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None,
         input_message_content: "types.InputMessageContent" = None
diff --git a/pyrogram/types/inline_mode/inline_query_result_video.py b/pyrogram/types/inline_mode/inline_query_result_video.py
index cd5d845437..5f71111f4f 100644
--- a/pyrogram/types/inline_mode/inline_query_result_video.py
+++ b/pyrogram/types/inline_mode/inline_query_result_video.py
@@ -19,7 +19,7 @@
 from typing import Optional, List
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from .inline_query_result import InlineQueryResult
 
 
@@ -63,12 +63,9 @@ class InlineQueryResultVideo(InlineQueryResult):
         caption (``str``, *optional*):
             Caption of the video to be sent, 0-1024 characters.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -93,7 +90,7 @@ def __init__(
         video_duration: int = 0,
         description: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None,
         input_message_content: "types.InputMessageContent" = None
diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py
index 76c146c510..04aa940edc 100644
--- a/pyrogram/types/input_media/input_media_animation.py
+++ b/pyrogram/types/input_media/input_media_animation.py
@@ -20,6 +20,7 @@
 
 from .input_media import InputMedia
 from ..messages_and_media import MessageEntity
+from ... import enums
 
 
 class InputMediaAnimation(InputMedia):
@@ -43,12 +44,9 @@ class InputMediaAnimation(InputMedia):
             Caption of the animation to be sent, 0-1024 characters.
             If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -68,7 +66,7 @@ def __init__(
         media: Union[str, BinaryIO],
         thumb: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List[MessageEntity] = None,
         width: int = 0,
         height: int = 0,
diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py
index 4816659d5a..b4bb7575be 100644
--- a/pyrogram/types/input_media/input_media_audio.py
+++ b/pyrogram/types/input_media/input_media_audio.py
@@ -20,6 +20,7 @@
 
 from .input_media import InputMedia
 from ..messages_and_media import MessageEntity
+from ... import enums
 
 
 class InputMediaAudio(InputMedia):
@@ -45,12 +46,9 @@ class InputMediaAudio(InputMedia):
             Caption of the audio to be sent, 0-1024 characters.
             If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -70,7 +68,7 @@ def __init__(
         media: Union[str, BinaryIO],
         thumb: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List[MessageEntity] = None,
         duration: int = 0,
         performer: str = "",
diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py
index 3b3a38fdf6..91dfc7d673 100644
--- a/pyrogram/types/input_media/input_media_document.py
+++ b/pyrogram/types/input_media/input_media_document.py
@@ -20,6 +20,7 @@
 
 from .input_media import InputMedia
 from ..messages_and_media import MessageEntity
+from ... import enums
 
 
 class InputMediaDocument(InputMedia):
@@ -43,12 +44,9 @@ class InputMediaDocument(InputMedia):
             Caption of the document to be sent, 0-1024 characters.
             If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -59,7 +57,7 @@ def __init__(
         media: Union[str, BinaryIO],
         thumb: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List[MessageEntity] = None
     ):
         super().__init__(media, caption, parse_mode, caption_entities)
diff --git a/pyrogram/types/input_media/input_media_photo.py b/pyrogram/types/input_media/input_media_photo.py
index f733a7b0bc..ce8b41a218 100644
--- a/pyrogram/types/input_media/input_media_photo.py
+++ b/pyrogram/types/input_media/input_media_photo.py
@@ -20,6 +20,7 @@
 
 from .input_media import InputMedia
 from ..messages_and_media import MessageEntity
+from ... import enums
 
 
 class InputMediaPhoto(InputMedia):
@@ -38,12 +39,9 @@ class InputMediaPhoto(InputMedia):
             Caption of the photo to be sent, 0-1024 characters.
             If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -53,7 +51,7 @@ def __init__(
         self,
         media: Union[str, BinaryIO],
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List[MessageEntity] = None
     ):
         super().__init__(media, caption, parse_mode, caption_entities)
diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py
index 48c79f411d..bad4e3ef3a 100644
--- a/pyrogram/types/input_media/input_media_video.py
+++ b/pyrogram/types/input_media/input_media_video.py
@@ -20,6 +20,7 @@
 
 from .input_media import InputMedia
 from ..messages_and_media import MessageEntity
+from ... import enums
 
 
 class InputMediaVideo(InputMedia):
@@ -44,12 +45,9 @@ class InputMediaVideo(InputMedia):
             Caption of the video to be sent, 0-1024 characters.
             If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -72,7 +70,7 @@ def __init__(
         media: Union[str, BinaryIO],
         thumb: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List[MessageEntity] = None,
         width: int = 0,
         height: int = 0,
diff --git a/pyrogram/types/input_message_content/input_text_message_content.py b/pyrogram/types/input_message_content/input_text_message_content.py
index ef54c0b23a..7c88f996ba 100644
--- a/pyrogram/types/input_message_content/input_text_message_content.py
+++ b/pyrogram/types/input_message_content/input_text_message_content.py
@@ -19,7 +19,7 @@
 from typing import Optional, List
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from .input_message_content import InputMessageContent
 
 
@@ -30,12 +30,9 @@ class InputTextMessageContent(InputMessageContent):
         message_text (``str``):
             Text of the message to be sent, 1-4096 characters.
 
-        parse_mode (``str``, *optional*):
+        parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
-            Pass "markdown" or "md" to enable Markdown-style parsing only.
-            Pass "html" to enable HTML-style parsing only.
-            Pass None to completely disable style parsing.
 
         entities (List of :obj:`~pyrogram.types.MessageEntity`):
             List of special entities that appear in message text, which can be specified instead of *parse_mode*.
@@ -47,7 +44,7 @@ class InputTextMessageContent(InputMessageContent):
     def __init__(
         self,
         message_text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         entities: List["types.MessageEntity"] = None,
         disable_web_page_preview: bool = None
     ):
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index e6aa25268a..2c2f7e053d 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -21,7 +21,7 @@
 from typing import List, Match, Union, BinaryIO, Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import MessageIdsEmpty, PeerIdInvalid
@@ -112,17 +112,15 @@ class Message(Object, Update):
             The message is empty.
             A message can be empty in case it was deleted or you tried to retrieve a message that doesn't exist yet.
 
-        service (``str``, *optional*):
-            The message is a service message. This field will contain the name of the service message.
-            A service message has one and only one of these fields set: new_chat_members, left_chat_member,
-            new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, channel_chat_created,
-            migrate_to_chat_id, migrate_from_chat_id, pinned_message, game_high_score, voice_chat_started,
-            voice_chat_ended, voice_chat_scheduled, voice_chat_members_invited.
+        service (:obj:`~pyrogram.enums.MessageService`, *optional*):
+            The message is a service message.
+            This field will contain the enumeration type of the service message.
+            You can use ``service = getattr(message, message.service.value)`` to access the service message.
 
-        media (``str``, *optional*):
-            The message is a media message. This field will contain the name of the media message.
-            A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation,
-            voice, video_note, contact, location, venue, poll, web_page, dice, game.
+        media (:obj:`~pyrogram.enums.MessageMedia`, *optional*):
+            The message is a media message.
+            This field will contain the enumeration type of the media message.
+            You can use ``media = getattr(message, message.media.value)`` to access the media message.
 
         edit_date (``int``, *optional*):
             Date the message was last edited in Unix time.
@@ -319,7 +317,7 @@ def __init__(
         reply_to_message: "Message" = None,
         mentioned: bool = None,
         empty: bool = None,
-        service: str = None,
+        service: "enums.MessageService" = None,
         scheduled: bool = None,
         from_scheduled: bool = None,
         media: str = None,
@@ -497,47 +495,47 @@ async def _parse(
 
             if isinstance(action, raw.types.MessageActionChatAddUser):
                 new_chat_members = [types.User._parse(client, users[i]) for i in action.users]
-                service_type = "new_chat_members"
+                service_type = enums.MessageService.NEW_CHAT_MEMBERS
             elif isinstance(action, raw.types.MessageActionChatJoinedByLink):
                 new_chat_members = [types.User._parse(client, users[utils.get_raw_peer_id(message.from_id)])]
-                service_type = "new_chat_members"
+                service_type = enums.MessageService.NEW_CHAT_MEMBERS
             elif isinstance(action, raw.types.MessageActionChatDeleteUser):
                 left_chat_member = types.User._parse(client, users[action.user_id])
-                service_type = "left_chat_member"
+                service_type = enums.MessageService.LEFT_CHAT_MEMBERS
             elif isinstance(action, raw.types.MessageActionChatEditTitle):
                 new_chat_title = action.title
-                service_type = "new_chat_title"
+                service_type = enums.MessageService.NEW_CHAT_TITLE
             elif isinstance(action, raw.types.MessageActionChatDeletePhoto):
                 delete_chat_photo = True
-                service_type = "delete_chat_photo"
+                service_type = enums.MessageService.DELETE_CHAT_PHOTO
             elif isinstance(action, raw.types.MessageActionChatMigrateTo):
                 migrate_to_chat_id = action.channel_id
-                service_type = "migrate_to_chat_id"
+                service_type = enums.MessageService.MIGRATE_TO_CHAT_ID
             elif isinstance(action, raw.types.MessageActionChannelMigrateFrom):
                 migrate_from_chat_id = action.chat_id
-                service_type = "migrate_from_chat_id"
+                service_type = enums.MessageService.MIGRATE_FROM_CHAT_ID
             elif isinstance(action, raw.types.MessageActionChatCreate):
                 group_chat_created = True
-                service_type = "group_chat_created"
+                service_type = enums.MessageService.GROUP_CHAT_CREATED
             elif isinstance(action, raw.types.MessageActionChannelCreate):
                 channel_chat_created = True
-                service_type = "channel_chat_created"
+                service_type = enums.MessageService.CHANNEL_CHAT_CREATED
             elif isinstance(action, raw.types.MessageActionChatEditPhoto):
                 new_chat_photo = types.Photo._parse(client, action.photo)
-                service_type = "new_chat_photo"
+                service_type = enums.MessageService.NEW_CHAT_PHOTO
             elif isinstance(action, raw.types.MessageActionGroupCallScheduled):
                 voice_chat_scheduled = types.VoiceChatScheduled._parse(action)
-                service_type = "voice_chat_scheduled"
+                service_type = enums.MessageService.VOICE_CHAT_SCHEDULED
             elif isinstance(action, raw.types.MessageActionGroupCall):
                 if action.duration:
                     voice_chat_ended = types.VoiceChatEnded._parse(action)
-                    service_type = "voice_chat_ended"
+                    service_type = enums.MessageService.VOICE_CHAT_ENDED
                 else:
                     voice_chat_started = types.VoiceChatStarted()
-                    service_type = "voice_chat_started"
+                    service_type = enums.MessageService.VOICE_CHAT_STARTED
             elif isinstance(action, raw.types.MessageActionInviteToGroupCall):
                 voice_chat_members_invited = types.VoiceChatMembersInvited._parse(client, action, users)
-                service_type = "voice_chat_members_invited"
+                service_type = enums.MessageService.VOICE_CHAT_MEMBERS_INVITED
 
             from_user = types.User._parse(client, users.get(user_id, None))
             sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
@@ -574,7 +572,7 @@ async def _parse(
                         replies=0
                     )
 
-                    parsed_message.service = "pinned_message"
+                    parsed_message.service = enums.MessageService.PINNED_MESSAGE
                 except MessageIdsEmpty:
                     pass
 
@@ -589,7 +587,7 @@ async def _parse(
                             replies=0
                         )
 
-                        parsed_message.service = "game_high_score"
+                        parsed_message.service = enums.MessageService.GAME_HIGH_SCORE
                     except MessageIdsEmpty:
                         pass
 
@@ -646,19 +644,19 @@ async def _parse(
             if media:
                 if isinstance(media, raw.types.MessageMediaPhoto):
                     photo = types.Photo._parse(client, media.photo, media.ttl_seconds)
-                    media_type = "photo"
+                    media_type = enums.MessageMedia.PHOTO
                 elif isinstance(media, raw.types.MessageMediaGeo):
                     location = types.Location._parse(client, media.geo)
-                    media_type = "location"
+                    media_type = enums.MessageMedia.LOCATION
                 elif isinstance(media, raw.types.MessageMediaContact):
                     contact = types.Contact._parse(client, media)
-                    media_type = "contact"
+                    media_type = enums.MessageMedia.CONTACT
                 elif isinstance(media, raw.types.MessageMediaVenue):
                     venue = types.Venue._parse(client, media)
-                    media_type = "venue"
+                    media_type = enums.MessageMedia.VENUE
                 elif isinstance(media, raw.types.MessageMediaGame):
                     game = types.Game._parse(client, message)
-                    media_type = "game"
+                    media_type = enums.MessageMedia.GAME
                 elif isinstance(media, raw.types.MessageMediaDocument):
                     doc = media.document
 
@@ -676,14 +674,14 @@ async def _parse(
 
                             if audio_attributes.voice:
                                 voice = types.Voice._parse(client, doc, audio_attributes)
-                                media_type = "voice"
+                                media_type = enums.MessageMedia.VOICE
                             else:
                                 audio = types.Audio._parse(client, doc, audio_attributes, file_name)
-                                media_type = "audio"
+                                media_type = enums.MessageMedia.AUDIO
                         elif raw.types.DocumentAttributeAnimated in attributes:
                             video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
                             animation = types.Animation._parse(client, doc, video_attributes, file_name)
-                            media_type = "animation"
+                            media_type = enums.MessageMedia.ANIMATION
                         elif raw.types.DocumentAttributeSticker in attributes:
                             sticker = await types.Sticker._parse(
                                 client, doc,
@@ -691,31 +689,31 @@ async def _parse(
                                 attributes[raw.types.DocumentAttributeSticker],
                                 file_name
                             )
-                            media_type = "sticker"
+                            media_type = enums.MessageMedia.STICKER
                         elif raw.types.DocumentAttributeVideo in attributes:
                             video_attributes = attributes[raw.types.DocumentAttributeVideo]
 
                             if video_attributes.round_message:
                                 video_note = types.VideoNote._parse(client, doc, video_attributes)
-                                media_type = "video_note"
+                                media_type = enums.MessageMedia.VIDEO_NOTE
                             else:
                                 video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
-                                media_type = "video"
+                                media_type = enums.MessageMedia.VIDEO
                         else:
                             document = types.Document._parse(client, doc, file_name)
-                            media_type = "document"
+                            media_type = enums.MessageMedia.DOCUMENT
                 elif isinstance(media, raw.types.MessageMediaWebPage):
                     if isinstance(media.webpage, raw.types.WebPage):
                         web_page = types.WebPage._parse(client, media.webpage)
-                        media_type = "web_page"
+                        media_type = enums.MessageMedia.WEB_PAGE
                     else:
                         media = None
                 elif isinstance(media, raw.types.MessageMediaPoll):
                     poll = types.Poll._parse(client, media)
-                    media_type = "poll"
+                    media_type = enums.MessageMedia.POLL
                 elif isinstance(media, raw.types.MessageMediaDice):
                     dice = types.Dice._parse(client, media)
-                    media_type = "dice"
+                    media_type = enums.MessageMedia.DICE
                 else:
                     media = None
 
@@ -820,7 +818,10 @@ async def _parse(
 
     @property
     def link(self) -> str:
-        if self.chat.type in ("group", "supergroup", "channel") and self.chat.username:
+        if (
+            self.chat.type in (enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)
+            and self.chat.username
+        ):
             return f"https://t.me/{self.chat.username}/{self.message_id}"
         else:
             return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.message_id}"
@@ -858,7 +859,7 @@ async def reply_text(
         self,
         text: str,
         quote: bool = None,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         entities: List["types.MessageEntity"] = None,
         disable_web_page_preview: bool = None,
         disable_notification: bool = None,
@@ -895,12 +896,9 @@ async def reply_text(
                 If *reply_to_message_id* is passed, this parameter will be ignored.
                 Defaults to ``True`` in group chats and ``False`` in private chats.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in message text, which can be specified instead of *parse_mode*.
@@ -957,7 +955,7 @@ async def reply_animation(
         animation: Union[str, BinaryIO],
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         width: int = 0,
@@ -1005,12 +1003,9 @@ async def reply_animation(
             caption (``str``, *optional*):
                 Animation caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -1099,7 +1094,7 @@ async def reply_audio(
         audio: Union[str, BinaryIO],
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         performer: str = None,
@@ -1147,12 +1142,9 @@ async def reply_audio(
             caption (``str``, *optional*):
                 Audio caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -1241,7 +1233,7 @@ async def reply_cached_media(
         file_id: str,
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
@@ -1281,12 +1273,9 @@ async def reply_cached_media(
             caption (``bool``, *optional*):
                 Media caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -1454,7 +1443,7 @@ async def reply_document(
         quote: bool = None,
         thumb: str = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         file_name: str = None,
         force_document: bool = None,
@@ -1507,12 +1496,9 @@ async def reply_document(
             caption (``str``, *optional*):
                 Document caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -1867,7 +1853,7 @@ async def reply_photo(
         photo: Union[str, BinaryIO],
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         ttl_seconds: int = None,
         disable_notification: bool = None,
@@ -1912,12 +1898,9 @@ async def reply_photo(
             caption (``str``, *optional*):
                 Photo caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -2295,7 +2278,7 @@ async def reply_video(
         video: Union[str, BinaryIO],
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         ttl_seconds: int = None,
         duration: int = 0,
@@ -2345,12 +2328,9 @@ async def reply_video(
             caption (``str``, *optional*):
                 Video caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -2567,7 +2547,7 @@ async def reply_voice(
         voice: Union[str, BinaryIO],
         quote: bool = None,
         caption: str = "",
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         duration: int = 0,
         disable_notification: bool = None,
@@ -2612,12 +2592,9 @@ async def reply_voice(
             caption (``str``, *optional*):
                 Voice message caption, 0-1024 characters.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -2689,7 +2666,7 @@ async def reply_voice(
     async def edit_text(
         self,
         text: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         entities: List["types.MessageEntity"] = None,
         disable_web_page_preview: bool = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
@@ -2717,12 +2694,9 @@ async def edit_text(
             text (``str``):
                 New text of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in message text, which can be specified instead of *parse_mode*.
@@ -2754,7 +2728,7 @@ async def edit_text(
     async def edit_caption(
         self,
         caption: str,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> "Message":
@@ -2779,12 +2753,9 @@ async def edit_caption(
             caption (``str``):
                 New caption of the message.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
@@ -2938,7 +2909,7 @@ async def copy(
         self,
         chat_id: Union[int, str],
         caption: str = None,
-        parse_mode: Optional[str] = object,
+        parse_mode: Optional["enums.ParseMode"] = None,
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
@@ -2979,12 +2950,9 @@ async def copy(
                 If not specified, the original caption is kept.
                 Pass "" (empty string) to remove the caption.
 
-            parse_mode (``str``, *optional*):
+            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                 By default, texts are parsed using both Markdown and HTML styles.
                 You can combine both syntaxes together.
-                Pass "markdown" or "md" to enable Markdown-style parsing only.
-                Pass "html" to enable HTML-style parsing only.
-                Pass None to completely disable style parsing.
 
             caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
                 List of special entities that appear in the new caption, which can be specified instead of *parse_mode*.
diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py
index 2595fc66bc..dbd6a98264 100644
--- a/pyrogram/types/messages_and_media/message_entity.py
+++ b/pyrogram/types/messages_and_media/message_entity.py
@@ -16,87 +16,22 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from enum import Enum, auto
 from typing import Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from ..object import Object
 
 
-class AutoName(Enum):
-    def _generate_next_value_(self, *args):
-        return self.lower()
-
-
-class MessageEntityType(AutoName):
-    MENTION = auto()
-    HASHTAG = auto()
-    CASHTAG = auto()
-    BOT_COMMAND = auto()
-    URL = auto()
-    EMAIL = auto()
-    PHONE_NUMBER = auto()
-    BOLD = auto()
-    ITALIC = auto()
-    UNDERLINE = auto()
-    STRIKETHROUGH = auto()
-    SPOILER = auto()
-    CODE = auto()
-    PRE = auto()
-    TEXT_LINK = auto()
-    TEXT_MENTION = auto()
-    BLOCKQUOTE = auto()
-
-
-RAW_ENTITIES_TO_TYPE = {
-    raw.types.MessageEntityMention: MessageEntityType.MENTION,
-    raw.types.MessageEntityHashtag: MessageEntityType.HASHTAG,
-    raw.types.MessageEntityCashtag: MessageEntityType.CASHTAG,
-    raw.types.MessageEntityBotCommand: MessageEntityType.BOT_COMMAND,
-    raw.types.MessageEntityUrl: MessageEntityType.URL,
-    raw.types.MessageEntityEmail: MessageEntityType.EMAIL,
-    raw.types.MessageEntityBold: MessageEntityType.BOLD,
-    raw.types.MessageEntityItalic: MessageEntityType.ITALIC,
-    raw.types.MessageEntityCode: MessageEntityType.CODE,
-    raw.types.MessageEntityPre: MessageEntityType.PRE,
-    raw.types.MessageEntityUnderline: MessageEntityType.UNDERLINE,
-    raw.types.MessageEntityStrike: MessageEntityType.STRIKETHROUGH,
-    raw.types.MessageEntitySpoiler: MessageEntityType.SPOILER,
-    raw.types.MessageEntityBlockquote: MessageEntityType.BLOCKQUOTE,
-    raw.types.MessageEntityTextUrl: MessageEntityType.TEXT_LINK,
-    raw.types.MessageEntityMentionName: MessageEntityType.TEXT_MENTION,
-    raw.types.MessageEntityPhone: MessageEntityType.PHONE_NUMBER
-}
-
-TYPE_TO_RAW_ENTITIES = {v.value: k for k, v in RAW_ENTITIES_TO_TYPE.items()}
-
-
 class MessageEntity(Object):
     """One special entity in a text message.
+    
     For example, hashtags, usernames, URLs, etc.
 
     Parameters:
-        type (``str``):
-            Type of the entity. Can be:
-
-            - "mention": ``@username``.
-            - "hashtag": ``#hashtag``.
-            - "cashtag": ``$PYRO``.
-            - "bot_command": ``/start@pyrogrambot``.
-            - "url": ``https://pyrogram.org`` (see *url* below).
-            - "email": ``do-not-reply@pyrogram.org``.
-            - "phone_number": ``+1-123-456-7890``.
-            - "bold": **bold text**.
-            - "italic": *italic text*.
-            - "underline": underlined text.
-            - "strikethrough": strikethrough text.
-            - "spoiler": spoiler text.
-            - "code": monowidth string.
-            - "pre": monowidth block (see *language* below).
-            - "text_link": for clickable text URLs.
-            - "text_mention": for users without usernames (see *user* below).
+        type (:obj:`~pyrogram.enums.MessageEntityType`):
+            Type of the entity.
 
         offset (``int``):
             Offset in UTF-16 code units to the start of the entity.
@@ -118,7 +53,7 @@ def __init__(
         self,
         *,
         client: "pyrogram.Client" = None,
-        type: str,
+        type: "enums.MessageEntityType",
         offset: int,
         length: int,
         url: str = None,
@@ -135,14 +70,9 @@ def __init__(
         self.language = language
 
     @staticmethod
-    def _parse(client, entity, users: dict) -> Optional["MessageEntity"]:
-        type = RAW_ENTITIES_TO_TYPE.get(entity.__class__, None)
-
-        if type is None:
-            return None
-
+    def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["MessageEntity"]:
         return MessageEntity(
-            type=type.value,
+            type=enums.MessageEntityType(entity.__class__),
             offset=entity.offset,
             length=entity.length,
             url=getattr(entity, "url", None),
@@ -166,15 +96,9 @@ async def write(self):
         if self.language is None:
             args.pop("language")
 
-        try:
-            entity = TYPE_TO_RAW_ENTITIES[self.type]
-
-            if entity is raw.types.MessageEntityMentionName:
-                entity = raw.types.InputMessageEntityMentionName
-        except KeyError as e:
-            raise ValueError(f"Invalid message entity type {e}")
-        else:
-            try:
-                return entity(**args)
-            except TypeError as e:
-                raise TypeError(f"{entity.QUALNAME}'s {e}")
+        entity = self.type.value
+
+        if entity is raw.types.MessageEntityMentionName:
+            entity = raw.types.InputMessageEntityMentionName
+
+        return entity(**args)
diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py
index 8d46557d65..9d4c5118cb 100644
--- a/pyrogram/types/messages_and_media/poll.py
+++ b/pyrogram/types/messages_and_media/poll.py
@@ -19,7 +19,7 @@
 from typing import List, Union
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from ..object import Object
 from ..update import Update
@@ -47,8 +47,8 @@ class Poll(Object, Update):
         is_anonymous (``bool``, *optional*):
             True, if the poll is anonymous
 
-        type (``str``, *optional*):
-            Poll type, currently can be "regular" or "quiz".
+        type (:obj:`~pyrogram.enums.PollType`, *optional*):
+            Poll type.
 
         allows_multiple_answers (``bool``, *optional*):
             True, if the poll allows multiple answers.
@@ -67,7 +67,7 @@ def __init__(
         total_voter_count: int,
         is_closed: bool,
         is_anonymous: bool = None,
-        type: str = None,
+        type: "enums.PollType" = None,
         allows_multiple_answers: bool = None,
         # correct_option_id: int,
         chosen_option: int = None
@@ -118,7 +118,7 @@ def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.Up
             total_voter_count=media_poll.results.total_voters,
             is_closed=poll.closed,
             is_anonymous=not poll.public_voters,
-            type="quiz" if poll.quiz else "regular",
+            type=enums.PollType.QUIZ if poll.quiz else enums.PollType.REGULAR,
             allows_multiple_answers=poll.multiple_choice,
             chosen_option=chosen_option,
             client=client
diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py
index 015eeca89a..a0925779e2 100644
--- a/pyrogram/types/object.py
+++ b/pyrogram/types/object.py
@@ -18,6 +18,7 @@
 
 import typing
 from datetime import datetime
+from enum import Enum
 from json import dumps
 
 import pyrogram
@@ -52,6 +53,9 @@ def default(obj: "Object"):
         if isinstance(obj, typing.Match):
             return repr(obj)
 
+        if isinstance(obj, Enum):
+            return str(obj)
+
         return {
             "_": obj.__class__.__name__,
             **{
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 7ca8f2085e..2282b1e073 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -19,7 +19,7 @@
 from typing import Union, List, Generator, Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
 from ..object import Object
@@ -32,8 +32,8 @@ class Chat(Object):
         id (``int``):
             Unique identifier for this chat.
 
-        type (``str``):
-            Type of chat, can be either "private", "bot", "group", "supergroup" or "channel".
+        type (:obj:`~pyrogram.enums.ChatType`):
+            Type of chat.
 
         is_verified (``bool``, *optional*):
             True, if this chat has been verified by Telegram. Supergroups, channels and bots only.
@@ -135,7 +135,7 @@ def __init__(
         *,
         client: "pyrogram.Client" = None,
         id: int,
-        type: str,
+        type: "enums.ChatType",
         is_verified: bool = None,
         is_restricted: bool = None,
         is_creator: bool = None,
@@ -200,7 +200,7 @@ def _parse_user_chat(client, user: raw.types.User) -> "Chat":
 
         return Chat(
             id=peer_id,
-            type="bot" if user.bot else "private",
+            type=enums.ChatType.BOT if user.bot else enums.ChatType.PRIVATE,
             is_verified=getattr(user, "verified", None),
             is_restricted=getattr(user, "restricted", None),
             is_scam=getattr(user, "scam", None),
@@ -221,7 +221,7 @@ def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat":
 
         return Chat(
             id=peer_id,
-            type="group",
+            type=enums.ChatType.GROUP,
             title=chat.title,
             is_creator=getattr(chat, "creator", None),
             photo=types.ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id, 0),
@@ -239,7 +239,7 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
 
         return Chat(
             id=peer_id,
-            type="supergroup" if getattr(channel, "megagroup", None) else "channel",
+            type=enums.ChatType.SUPERGROUP if getattr(channel, "megagroup", None) else enums.ChatType.CHANNEL,
             is_verified=getattr(channel, "verified", None),
             is_restricted=getattr(channel, "restricted", None),
             is_creator=getattr(channel, "creator", None),
@@ -842,7 +842,7 @@ async def get_members(
         offset: int = 0,
         limit: int = 200,
         query: str = "",
-        filter: str = "all"
+        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
     ) -> List["types.ChatMember"]:
         """Bound method *get_members* of :obj:`~pyrogram.types.Chat`.
 
@@ -930,17 +930,9 @@ def iter_members(
                 Query string to filter members based on their display names and usernames.
                 Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
 
-            filter (``str``, *optional*):
+            filter (:obj:`~pyrogram.enums.ChatMembersFilter`, *optional*):
                 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
-                and channels. It can be any of the followings:
-                *"all"* - all kind of members,
-                *"banned"* - banned members only,
-                *"restricted"* - restricted members only,
-                *"bots"* - bots only,
-                *"recent"* - recent members only,
-                *"administrators"* - chat administrators only.
-                Only applicable to supergroups and channels.
-                Defaults to *"recent"*.
+                and channels.
 
         .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
             on channels.
@@ -950,16 +942,18 @@ def iter_members(
         Example:
             .. code-block:: python
 
+                from pyrogram import enums
+
                 # Get first 200 recent members
                 for member in chat.get_members():
                     print(member.user.first_name)
 
                 # Get all administrators
-                for member in chat.iter_members(filter="administrators"):
+                for member in chat.iter_members(filter=enums.ChatMembersFilter.ADMINISTRATORS):
                     print(member.user.first_name)
 
                 # Get first 3 bots
-                for member in chat.iter_members(filter="bots", limit=3):
+                for member in chat.iter_members(filter=enums.ChatMembersFilter.BOTS, limit=3):
                     print(member.user.first_name)
 
         Returns:
diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py
index 374dac50f9..3abfd1f9d6 100644
--- a/pyrogram/types/user_and_chats/chat_event.py
+++ b/pyrogram/types/user_and_chats/chat_event.py
@@ -70,6 +70,8 @@ class ChatEventAction(AutoName):
 class ChatEvent(Object):
     """A chat event from the recent actions log (also known as admin log).
 
+    See ``action`` to know which kind of event this is and the relative attributes to get the event content.
+
     Parameters:
         id (``int``):
             Chat event identifier.
@@ -77,171 +79,99 @@ class ChatEvent(Object):
         date (``int``):
             Date of the event. Unix time.
 
-        action (``str``):
-            Event action. Can be:
-
-            - "description_changed": the chat description has been changed
-              (see *old_description* and *new_description* below).
-
-            - "history_ttl_changed": the history time-to-live has been changed
-              (see *old_history_ttl* and *new_history_ttl* below).
-
-            - "linked_chat_changed": the linked chat has been changed
-              (see *old_linked_chat* and *new_linked_chat* below).
-
-            - "photo_changed": the chat photo has been changed
-              (see *old_photo* and *new_photo* below).
-
-            - "title_changed": the chat title has been changed
-              (see *old_title* and *new_title* below).
-
-            - "username_changed": the chat username has been changed
-              (see *old_username* and *new_username* below).
-
-            - "chat_permissions_changed": the default chat permissions has been changed
-              (see *old_chat_permissions* and *new_chat_permissions* below).
-
-            - "message_deleted": a message has been deleted
-              (see *deleted_message* below).
-
-            - "message_edited": a message has been edited
-              (see *old_message* and *new_message* below).
-
-            - "member_invited": a member has been invited by someone
-              (see *invited_member* below).
-
-            - "member_joined": a member joined by themselves.
-              (see *user* below)
-
-            - "member_left": a member left by themselves.
-              (see *user* below).
-
-            - "admin_rights_changed": a chat member has been promoted/demoted or their administrator rights has changed
-              (see *old_admin_rights* and *new_admin_rights* below).
-
-            - "member_permissions_changed": a chat member has been restricted/unrestricted or banned/unbanned, or their
-              permissions has changed (see *old_member_permissions* and *new_member_permissions* below).
-
-            - "poll_stopped": a poll has been stopped
-              (see *stopped_poll* below).
-
-            - "invites_enabled": the chat invitation has been enabled or disabled
-              (see *invites_enabled* below).
-
-            - "history_hidden": the chat history has been hidden or unhidden
-              (see *history_hidden* below).
-
-            - "signatures_enabled": the message signatures have been enabled or disabled
-              (see *signatures_enabled* below).
-
-            - "slow_mode_changed": the slow mode has been changes
-              (see *old_slow_mode* and *new_slow_mode* below).
-
-            - "message_pinned": a message has been pinned
-              (see *pinned_message* below).
-
-            - "message_unpinned": a message has been unpinned
-              (see *unpinned_message* below).
-
-            - "invite_link_edited": an invite link has been edited
-              (see *edited_invite_link* below).
-
-            - "invite_link_revoked": an invite link has been revoked
-              (see *revoked_invite_link* below).
-
-            - "invite_link_deleted": an invite link has been deleted
-              (see *deleted_invite_link* below).
+        action (:obj:`~pyrogram.enums.ChatEventAction`):
+            Event action.
 
         user (:obj:`~pyrogram.types.User`):
             User that triggered the event.
 
         old_description, new_description (``str``, *optional*):
             Previous and new chat description.
-            For "description_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.DESCRIPTION_CHANGED` action only.
 
         old_history_ttl, new_history_ttl (``int``, *optional*):
             Previous and new chat history TTL.
-            For "history_ttl_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.HISTORY_TTL_CHANGED` action only.
 
         old_linked_chat, new_linked_chat (:obj:`~pyrogram.types.Chat`, *optional*):
             Previous and new linked chat.
-            For "linked_chat_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.LINKED_CHAT_CHANGED` action only.
 
         old_photo, new_photo (:obj:`~pyrogram.types.Photo`, *optional*):
             Previous and new chat photo.
-            For "photo_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.PHOTO_CHANGED` action only.
 
         old_title, new_title (``str``, *optional*):
             Previous and new chat title.
-            For "title_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.TITLE_CHANGED` action only.
 
         old_username, new_username (``str``, *optional*):
             Previous and new chat username.
-            For "username_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.USERNAME_CHANGED` action only.
 
         old_chat_permissions, new_chat_permissions (:obj:`~pyrogram.types.ChatPermissions`, *optional*):
             Previous and new default chat permissions.
-            For "chat_permissions_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.CHAT_PERMISSIONS_CHANGED` action only.
 
         deleted_message (:obj:`~pyrogram.types.Message`, *optional*):
             Deleted message.
-            For "deleted_message" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_DELETED` action only.
 
         old_message, new_message (:obj:`~pyrogram.types.Message`, *optional*):
             Previous and new message before it has been edited.
-            For "message_edited" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_EDITED` action only.
 
         invited_member (:obj:`~pyrogram.types.ChatMember`, *optional*):
             New invited chat member.
-            For "member_invited" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MEMBER_INVITED` action only.
 
-        old_admin_rights, new_admin_rights (:obj:`~pyrogram.types.ChatMember`, *optional*):
-            Previous and new administrator rights.
-            For "admin_rights_changed" only.
+        old_administrator_privileges, new_administrator_privileges (:obj:`~pyrogram.types.ChatMember`, *optional*):
+            Previous and new administrator privileges.
+            For :obj:`~pyrogram.enums.ChatEventAction.ADMINISTRATOR_PRIVILEGES_CHANGED` action only.
 
         old_member_permissions, new_member_permissions (:obj:`~pyrogram.types.ChatMember`, *optional*):
             Previous and new member permissions.
-            For "member_permissions_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MEMBER_PERMISSIONS_CHANGED` action only.
 
         stopped_poll (:obj:`~pyrogram.types.Message`, *optional*):
             Message containing the stopped poll.
-            For "poll_stopped" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.POLL_STOPPED` action only.
 
         invites_enabled (``bool``, *optional*):
             If chat invites were enabled (True) or disabled (False).
-            For "invites_enabled" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.INVITES_ENABLED` action only.
 
         history_hidden (``bool``, *optional*):
             If chat history has been hidden (True) or unhidden (False).
-            For "history_hidden" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.HISTORY_HIDDEN` action only.
 
         signatures_enabled (``bool``, *optional*):
             If message signatures were enabled (True) or disabled (False).
-            For "signatures_enabled" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.SIGNATURES_ENABLED` action only.
 
         old_slow_mode, new_slow_mode (``int``, *optional*):
             Previous and new slow mode value in seconds.
-            For "slow_mode_changed" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.SLOW_MODE_CHANGED` action only.
 
         pinned_message (:obj:`~pyrogram.types.Message`, *optional*):
             Pinned message.
-            For "message_pinned" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_PINNED` action only.
 
         unpinned_message (:obj:`~pyrogram.types.Message`, *optional*):
             Unpinned message.
-            For "unpinned_message" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_UNPINNED` action only.
 
         old_invite_link, new_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
             Previous and new edited invite link.
-            For "invite_link_edited" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_EDITED` action only.
 
         revoked_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
             Revoked invite link.
-            For "invite_link_revoked" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_REVOKED` action only.
 
         deleted_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
             Deleted invite link.
-            For "invite_link_deleted" only.
+            For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_DELETED` action only.
     """
 
     def __init__(
@@ -279,8 +209,8 @@ def __init__(
 
         invited_member: "types.ChatMember" = None,
 
-        old_admin_rights: "types.ChatMember" = None,
-        new_admin_rights: "types.ChatMember" = None,
+        old_administrator_privileges: "types.ChatMember" = None,
+        new_administrator_privileges: "types.ChatMember" = None,
 
         old_member_permissions: "types.ChatMember" = None,
         new_member_permissions: "types.ChatMember" = None,
@@ -339,8 +269,8 @@ def __init__(
 
         self.invited_member = invited_member
 
-        self.old_admin_rights = old_admin_rights
-        self.new_admin_rights = new_admin_rights
+        self.old_administrator_privileges = old_administrator_privileges
+        self.new_administrator_privileges = new_administrator_privileges
 
         self.old_member_permissions = old_member_permissions
         self.new_member_permissions = new_member_permissions
@@ -405,8 +335,8 @@ async def _parse(
 
         invited_member: Optional[types.ChatMember] = None
 
-        old_admin_rights: Optional[types.ChatMember] = None
-        new_admin_rights: Optional[types.ChatMember] = None
+        old_administrator_privileges: Optional[types.ChatMember] = None
+        new_administrator_privileges: Optional[types.ChatMember] = None
 
         old_member_permissions: Optional[types.ChatMember] = None
         new_member_permissions: Optional[types.ChatMember] = None
@@ -433,102 +363,102 @@ async def _parse(
         if isinstance(action, raw.types.ChannelAdminLogEventActionChangeAbout):
             old_description = action.prev_value
             new_description = action.new_value
-            action = ChatEventAction.DESCRIPTION_CHANGED.value
+            action = ChatEventAction.DESCRIPTION_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeHistoryTTL):
             old_history_ttl = action.prev_value
             new_history_ttl = action.new_value
-            action = ChatEventAction.HISTORY_TTL_CHANGED.value
+            action = ChatEventAction.HISTORY_TTL_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeLinkedChat):
             old_linked_chat = types.Chat._parse_chat(client, chats[action.prev_value])
             new_linked_chat = types.Chat._parse_chat(client, chats[action.new_value])
-            action = ChatEventAction.LINKED_CHAT_CHANGED.value
+            action = ChatEventAction.LINKED_CHAT_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangePhoto):
             old_photo = types.Photo._parse(client, action.prev_photo)
             new_photo = types.Photo._parse(client, action.new_photo)
-            action = ChatEventAction.PHOTO_CHANGED.value
+            action = ChatEventAction.PHOTO_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeTitle):
             old_title = action.prev_value
             new_title = action.new_value
-            action = ChatEventAction.TITLE_CHANGED.value
+            action = ChatEventAction.TITLE_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeUsername):
             old_username = action.prev_value
             new_username = action.new_value
-            action = ChatEventAction.USERNAME_CHANGED.value
+            action = ChatEventAction.USERNAME_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionDefaultBannedRights):
             old_chat_permissions = types.ChatPermissions._parse(action.prev_banned_rights)
             new_chat_permissions = types.ChatPermissions._parse(action.new_banned_rights)
-            action = ChatEventAction.CHAT_PERMISSIONS_CHANGED.value
+            action = ChatEventAction.CHAT_PERMISSIONS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionDeleteMessage):
             deleted_message = await types.Message._parse(client, action.message, users, chats)
-            action = ChatEventAction.MESSAGE_DELETED.value
+            action = ChatEventAction.MESSAGE_DELETED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionEditMessage):
             old_message = await types.Message._parse(client, action.prev_message, users, chats)
             new_message = await types.Message._parse(client, action.new_message, users, chats)
-            action = ChatEventAction.MESSAGE_EDITED.value
+            action = ChatEventAction.MESSAGE_EDITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantInvite):
             invited_member = types.ChatMember._parse(client, action.participant, users, chats)
-            action = ChatEventAction.MEMBER_INVITED.value
+            action = ChatEventAction.MEMBER_INVITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleAdmin):
-            old_admin_rights = types.ChatMember._parse(client, action.prev_participant, users, chats)
-            new_admin_rights = types.ChatMember._parse(client, action.new_participant, users, chats)
-            action = ChatEventAction.ADMIN_RIGHTS_CHANGED.value
+            old_administrator_privileges = types.ChatMember._parse(client, action.prev_participant, users, chats)
+            new_administrator_privileges = types.ChatMember._parse(client, action.new_participant, users, chats)
+            action = ChatEventAction.ADMIN_RIGHTS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleBan):
             old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users, chats)
             new_member_permissions = types.ChatMember._parse(client, action.new_participant, users, chats)
-            action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED.value
+            action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionStopPoll):
             stopped_poll = await types.Message._parse(client, action.message, users, chats)
-            action = ChatEventAction.POLL_STOPPED.value
+            action = ChatEventAction.POLL_STOPPED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantJoin):
-            action = ChatEventAction.MEMBER_JOINED.value
+            action = ChatEventAction.MEMBER_JOINED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantLeave):
-            action = ChatEventAction.MEMBER_LEFT.value
+            action = ChatEventAction.MEMBER_LEFT
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleInvites):
             invites_enabled = action.new_value
-            action = ChatEventAction.INVITES_ENABLED.value
+            action = ChatEventAction.INVITES_ENABLED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionTogglePreHistoryHidden):
             history_hidden = action.new_value
-            action = ChatEventAction.HISTORY_HIDDEN.value
+            action = ChatEventAction.HISTORY_HIDDEN
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSignatures):
             signatures_enabled = action.new_value
-            action = ChatEventAction.SIGNATURES_ENABLED.value
+            action = ChatEventAction.SIGNATURES_ENABLED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSlowMode):
             old_slow_mode = action.prev_value
             new_slow_mode = action.new_value
-            action = ChatEventAction.SLOW_MODE_CHANGED.value
+            action = ChatEventAction.SLOW_MODE_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned):
             message = action.message
 
             if message.pinned:
                 pinned_message = await types.Message._parse(client, message, users, chats)
-                action = ChatEventAction.MESSAGE_PINNED.value
+                action = ChatEventAction.MESSAGE_PINNED
             else:
                 unpinned_message = await types.Message._parse(client, message, users, chats)
-                action = ChatEventAction.MESSAGE_UNPINNED.value
+                action = ChatEventAction.MESSAGE_UNPINNED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit):
             old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users)
             new_invite_link = types.ChatInviteLink._parse(client, action.new_invite, users)
-            action = ChatEventAction.INVITE_LINK_EDITED.value
+            action = ChatEventAction.INVITE_LINK_EDITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteRevoke):
             revoked_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
@@ -536,10 +466,10 @@ async def _parse(
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteDelete):
             deleted_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
-            action = ChatEventAction.INVITE_LINK_DELETED.value
+            action = ChatEventAction.INVITE_LINK_DELETED
 
         else:
-            action = f"{ChatEventAction.UNKNOWN.value}-{action.QUALNAME}"
+            action = f"{ChatEventAction.UNKNOWN}-{action.QUALNAME}"
 
         return ChatEvent(
             id=event.id,
@@ -574,8 +504,8 @@ async def _parse(
 
             invited_member=invited_member,
 
-            old_admin_rights=old_admin_rights,
-            new_admin_rights=new_admin_rights,
+            old_administrator_privileges=old_administrator_privileges,
+            new_administrator_privileges=new_administrator_privileges,
 
             old_member_permissions=old_member_permissions,
             new_member_permissions=new_member_permissions,
diff --git a/pyrogram/types/user_and_chats/chat_event_filter.py b/pyrogram/types/user_and_chats/chat_event_filter.py
index d88300bae5..7edc3a07eb 100644
--- a/pyrogram/types/user_and_chats/chat_event_filter.py
+++ b/pyrogram/types/user_and_chats/chat_event_filter.py
@@ -28,7 +28,7 @@ class ChatEventFilter(Object):
             True, if member restricted/unrestricted/banned/unbanned events should be returned.
             Defaults to False.
 
-        admin_rights (``bool``, *optional*):
+        new_privileges (``bool``, *optional*):
             True, if member promotion/demotion events should be returned.
             Defaults to False.
 
@@ -74,7 +74,7 @@ class ChatEventFilter(Object):
     def __init__(
         self, *,
         new_restrictions: bool = False,
-        admin_rights: bool = False,
+        new_privileges: bool = False,
         new_members: bool = False,
         chat_info: bool = False,
         chat_settings: bool = False,
@@ -88,7 +88,7 @@ def __init__(
         super().__init__()
 
         self.new_restrictions = new_restrictions
-        self.admin_rights = admin_rights
+        self.new_privileges = new_privileges
         self.new_members = new_members
         self.chat_info = chat_info
         self.chat_settings = chat_settings
@@ -123,7 +123,7 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
             kick = True
             unkick = True
 
-        if self.admin_rights:
+        if self.new_privileges:
             promote = True
             demote = True
 
diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index 65324dbd57..dc00354f90 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -19,7 +19,7 @@
 from typing import Union, Dict
 
 import pyrogram
-from pyrogram import raw, types, utils
+from pyrogram import raw, types, utils, enums
 from ..object import Object
 
 
@@ -27,9 +27,8 @@ class ChatMember(Object):
     """Contains information about one member of a chat.
 
     Parameters:
-        status (``str``):
+        status (:obj:`~pyrogram.enums.ChatMemberStatus`):
             The member's status in the chat.
-            Can be "creator", "administrator", "member", "restricted", "left" or "banned".
 
         user (:obj:`~pyrogram.types.User`, *optional*):
             Information about the user.
@@ -76,7 +75,7 @@ def __init__(
         self,
         *,
         client: "pyrogram.Client" = None,
-        status: str,
+        status: "enums.ChatMemberStatus",
         user: "types.User" = None,
         chat: "types.Chat" = None,
         custom_title: str = None,
@@ -108,15 +107,15 @@ def __init__(
 
     @staticmethod
     def _parse(
-        client: "pyrogram.Client",
-        member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
-        users: Dict[int, "raw.base.User"],
-        chats: Dict[int, "raw.base.Chat"]
+            client: "pyrogram.Client",
+            member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
+            users: Dict[int, "raw.base.User"],
+            chats: Dict[int, "raw.base.Chat"]
     ) -> "ChatMember":
         # Chat participants
         if isinstance(member, raw.types.ChatParticipant):
             return ChatMember(
-                status="member",
+                status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
                 invited_by=types.User._parse(client, users[member.inviter_id]),
@@ -124,7 +123,7 @@ def _parse(
             )
         elif isinstance(member, raw.types.ChatParticipantAdmin):
             return ChatMember(
-                status="administrator",
+                status=enums.ChatMemberStatus.ADMINISTRATOR,
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
                 invited_by=types.User._parse(client, users[member.inviter_id]),
@@ -132,7 +131,7 @@ def _parse(
             )
         elif isinstance(member, raw.types.ChatParticipantCreator):
             return ChatMember(
-                status="owner",
+                status=enums.ChatMemberStatus.OWNER,
                 user=types.User._parse(client, users[member.user_id]),
                 client=client
             )
@@ -140,14 +139,14 @@ def _parse(
         # Channel participants
         if isinstance(member, raw.types.ChannelParticipant):
             return ChatMember(
-                status="member",
+                status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
                 client=client
             )
         elif isinstance(member, raw.types.ChannelParticipantAdmin):
             return ChatMember(
-                status="administrator",
+                status=enums.ChatMemberStatus.ADMINISTRATOR,
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
                 promoted_by=types.User._parse(client, users[member.promoted_by]),
@@ -172,7 +171,11 @@ def _parse(
             )
 
             return ChatMember(
-                status="banned" if member.banned_rights.view_messages else "restricted",
+                status=(
+                    enums.ChatMemberStatus.BANNED
+                    if member.banned_rights.view_messages
+                    else enums.ChatMemberStatus.RESTRICTED
+                ),
                 user=user,
                 chat=chat,
                 until_date=member.banned_rights.until_date,
@@ -184,7 +187,7 @@ def _parse(
             )
         elif isinstance(member, raw.types.ChannelParticipantCreator):
             return ChatMember(
-                status="owner",
+                status=enums.ChatMemberStatus.OWNER,
                 user=types.User._parse(client, users[member.user_id]),
                 custom_title=member.rank,
                 privileges=types.ChatPrivileges._parse(member.admin_rights),
@@ -205,14 +208,14 @@ def _parse(
             )
 
             return ChatMember(
-                status="left",
+                status=enums.ChatMemberStatus.LEFT,
                 user=user,
                 chat=chat,
                 client=client
             )
         elif isinstance(member, raw.types.ChannelParticipantSelf):
             return ChatMember(
-                status="member",
+                status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=member.date,
                 invited_by=types.User._parse(client, users[member.inviter_id]),
diff --git a/pyrogram/types/user_and_chats/invite_link_importer.py b/pyrogram/types/user_and_chats/invite_link_importer.py
index f933cfa2b0..db8569f558 100644
--- a/pyrogram/types/user_and_chats/invite_link_importer.py
+++ b/pyrogram/types/user_and_chats/invite_link_importer.py
@@ -39,7 +39,7 @@ def __init__(self, *, date, user):
         self.user = user
 
     @staticmethod
-    def _parse(client, invite_importers: "raw.types.ChatInviteImporters"):
+    def _parse(client, invite_importers: "raw.types.messages.ChatInviteImporters"):
         importers = types.List()
 
         d = {i.id: i for i in invite_importers.users}
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index ac141033e2..f4678a3541 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -20,6 +20,7 @@
 from typing import List, Optional
 
 import pyrogram
+from pyrogram import enums
 from pyrogram import raw
 from pyrogram import types
 from ..object import Object
@@ -28,9 +29,9 @@
 
 class Link(str):
     HTML = "{text}"
-    MD = "[{text}]({url})"
+    MARKDOWN = "[{text}]({url})"
 
-    def __init__(self, url: str, text: str, style: str):
+    def __init__(self, url: str, text: str, style: enums.ParseMode):
         super().__init__()
 
         self.url = url
@@ -38,13 +39,11 @@ def __init__(self, url: str, text: str, style: str):
         self.style = style
 
     @staticmethod
-    def format(url: str, text: str, style: str):
-        if style in ["md", "markdown"]:
-            fmt = Link.MD
-        elif style in ["combined", "html", None]:
-            fmt = Link.HTML
+    def format(url: str, text: str, style: enums.ParseMode):
+        if style == enums.ParseMode.MARKDOWN:
+            fmt = Link.MARKDOWN
         else:
-            raise ValueError(f"{style} is not a valid style/parse mode")
+            fmt = Link.HTML
 
         return fmt.format(url=url, text=html.escape(text))
 
@@ -103,16 +102,8 @@ class User(Object, Update):
         last_name (``str``, *optional*):
             User's or bot's last name.
 
-        status (``str``, *optional*):
-            User's Last Seen & Online status.
-            Can be one of the following:
-            "*online*", user is online right now.
-            "*offline*", user is currently offline.
-            "*recently*", user with hidden last seen time who was online between 1 second and 2-3 days ago.
-            "*within_week*", user with hidden last seen time who was online between 2-3 and seven days ago.
-            "*within_month*", user with hidden last seen time who was online between 6-7 days and a month ago.
-            "*long_time_ago*", blocked user or user with hidden last seen time who was online more than a month ago.
-            *None*, for bots.
+        status (:obj:`~pyrogram.enums.UserStatus`, *optional*):
+            User's last seen & online status. *None*, for bots.
 
         last_online_date (``int``, *optional*):
             Last online date of a user, unix time. Only available in case status is "*offline*".
@@ -237,17 +228,17 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]:
     @staticmethod
     def _parse_status(user_status: "raw.base.UserStatus", is_bot: bool = False):
         if isinstance(user_status, raw.types.UserStatusOnline):
-            status, date = "online", user_status.expires
+            status, date = enums.UserStatus.ONLINE, user_status.expires
         elif isinstance(user_status, raw.types.UserStatusOffline):
-            status, date = "offline", user_status.was_online
+            status, date = enums.UserStatus.OFFLINE, user_status.was_online
         elif isinstance(user_status, raw.types.UserStatusRecently):
-            status, date = "recently", None
+            status, date = enums.UserStatus.RECENTLY, None
         elif isinstance(user_status, raw.types.UserStatusLastWeek):
-            status, date = "within_week", None
+            status, date = enums.UserStatus.LAST_WEEK, None
         elif isinstance(user_status, raw.types.UserStatusLastMonth):
-            status, date = "within_month", None
+            status, date = enums.UserStatus.LAST_MONTH, None
         else:
-            status, date = "long_time_ago", None
+            status, date = enums.UserStatus.LONG_AGO, None
 
         last_online_date = None
         next_offline_date = None
@@ -255,10 +246,10 @@ def _parse_status(user_status: "raw.base.UserStatus", is_bot: bool = False):
         if is_bot:
             status = None
 
-        if status == "online":
+        if status == enums.UserStatus.ONLINE:
             next_offline_date = date
 
-        if status == "offline":
+        if status == enums.UserStatus.OFFLINE:
             last_online_date = date
 
         return {

From b697826b5a72980ff41c9196d84d1a4385b01374 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 139/539] Replace integer timestamps with datetime objects

---
 docs/source/conf.py                           |   6 +-
 pyrogram/methods/chats/ban_chat_member.py     |  17 +--
 pyrogram/methods/chats/get_dialogs.py         |  11 +-
 .../methods/chats/restrict_chat_member.py     |  17 +--
 .../invite_links/create_chat_invite_link.py   |  11 +-
 .../invite_links/edit_chat_invite_link.py     |  13 +-
 pyrogram/methods/messages/copy_media_group.py |   9 +-
 pyrogram/methods/messages/copy_message.py     |   7 +-
 pyrogram/methods/messages/forward_messages.py |  11 +-
 pyrogram/methods/messages/get_history.py      |   9 +-
 pyrogram/methods/messages/iter_history.py     |   7 +-
 pyrogram/methods/messages/send_animation.py   |   9 +-
 pyrogram/methods/messages/send_audio.py       |   9 +-
 .../methods/messages/send_cached_media.py     |   9 +-
 pyrogram/methods/messages/send_contact.py     |   9 +-
 pyrogram/methods/messages/send_dice.py        |   9 +-
 pyrogram/methods/messages/send_document.py    |   9 +-
 pyrogram/methods/messages/send_location.py    |   9 +-
 pyrogram/methods/messages/send_media_group.py |   9 +-
 pyrogram/methods/messages/send_message.py     |  14 ++-
 pyrogram/methods/messages/send_photo.py       |   9 +-
 pyrogram/methods/messages/send_poll.py        |   9 +-
 pyrogram/methods/messages/send_sticker.py     |   9 +-
 pyrogram/methods/messages/send_venue.py       |   9 +-
 pyrogram/methods/messages/send_video.py       |   9 +-
 pyrogram/methods/messages/send_video_note.py  |   9 +-
 pyrogram/methods/messages/send_voice.py       |   9 +-
 pyrogram/parser/parser.py                     |   2 +-
 .../types/messages_and_media/animation.py     |  11 +-
 pyrogram/types/messages_and_media/audio.py    |  11 +-
 pyrogram/types/messages_and_media/document.py |  11 +-
 pyrogram/types/messages_and_media/message.py  |  57 ++++-----
 pyrogram/types/messages_and_media/photo.py    |  11 +-
 pyrogram/types/messages_and_media/sticker.py  |  11 +-
 pyrogram/types/messages_and_media/video.py    |  11 +-
 .../types/messages_and_media/video_note.py    |  11 +-
 pyrogram/types/messages_and_media/voice.py    |  12 +-
 pyrogram/types/object.py                      |   8 +-
 pyrogram/types/user_and_chats/chat.py         |  17 +--
 pyrogram/types/user_and_chats/chat_event.py   | 114 ++++++------------
 .../types/user_and_chats/chat_invite_link.py  |  25 ++--
 .../types/user_and_chats/chat_join_request.py |   9 +-
 pyrogram/types/user_and_chats/chat_member.py  |  31 ++---
 .../user_and_chats/chat_member_updated.py     |  11 +-
 .../user_and_chats/invite_link_importer.py    |  16 ++-
 pyrogram/types/user_and_chats/user.py         |  21 ++--
 .../user_and_chats/voice_chat_scheduled.py    |  12 +-
 pyrogram/utils.py                             |  13 +-
 48 files changed, 359 insertions(+), 333 deletions(-)

diff --git a/docs/source/conf.py b/docs/source/conf.py
index 53ac9012c5..cb273c070f 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -18,7 +18,6 @@
 
 import os
 import sys
-from datetime import datetime
 
 sys.path.insert(0, os.path.abspath("../.."))
 
@@ -38,9 +37,14 @@
     "sphinx.ext.autodoc",
     "sphinx.ext.napoleon",
     "sphinx.ext.autosummary",
+    "sphinx.ext.intersphinx",
     "sphinx_copybutton"
 ]
 
+intersphinx_mapping = {
+    "python": ("https://docs.python.org/3", None)
+}
+
 master_doc = "index"
 source_suffix = ".rst"
 autodoc_member_order = "bysource"
diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py
index bdf1175197..3edcb164ce 100644
--- a/pyrogram/methods/chats/ban_chat_member.py
+++ b/pyrogram/methods/chats/ban_chat_member.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -28,7 +29,7 @@ async def ban_chat_member(
         self,
         chat_id: Union[int, str],
         user_id: Union[int, str],
-        until_date: int = 0
+        until_date: datetime = datetime.fromtimestamp(0)
     ) -> Union["types.Message", bool]:
         """Ban a user from a group, a supergroup or a channel.
         In the case of supergroups and channels, the user will not be able to return to the group on their own using
@@ -48,10 +49,10 @@ async def ban_chat_member(
                 Unique identifier (int) or username (str) of the target user.
                 For a contact that exists in your Telegram address book you can use his phone number (str).
 
-            until_date (``int``, *optional*):
-                Date when the user will be unbanned, unix time.
+            until_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the user will be unbanned.
                 If user is banned for more than 366 days or less than 30 seconds from the current time they are
-                considered to be banned forever. Defaults to 0 (ban forever).
+                considered to be banned forever. Defaults to epoch (ban forever).
 
         Returns:
             :obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
@@ -60,13 +61,13 @@ async def ban_chat_member(
         Example:
             .. code-block:: python
 
-                from time import time
+                from datetime import datetime, timedelta
 
                 # Ban chat member forever
                 app.ban_chat_member(chat_id, user_id)
 
                 # Ban chat member and automatically unban after 24h
-                app.ban_chat_member(chat_id, user_id, int(time.time() + 86400))
+                app.ban_chat_member(chat_id, user_id, datetime.now() + timedelta(days=1))
         """
         chat_peer = await self.resolve_peer(chat_id)
         user_peer = await self.resolve_peer(user_id)
@@ -77,7 +78,7 @@ async def ban_chat_member(
                     channel=chat_peer,
                     participant=user_peer,
                     banned_rights=raw.types.ChatBannedRights(
-                        until_date=until_date,
+                        until_date=utils.datetime_to_timestamp(until_date),
                         view_messages=True,
                         send_messages=True,
                         send_media=True,
diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py
index 7a9d6a485f..9fb907caba 100644
--- a/pyrogram/methods/chats/get_dialogs.py
+++ b/pyrogram/methods/chats/get_dialogs.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
+from datetime import datetime
 from typing import List
 
 from pyrogram import raw
@@ -30,7 +31,7 @@
 class GetDialogs(Scaffold):
     async def get_dialogs(
         self,
-        offset_date: int = 0,
+        offset_date: datetime = datetime.fromtimestamp(0),
         limit: int = 100,
         pinned_only: bool = False
     ) -> List["types.Dialog"]:
@@ -40,9 +41,9 @@ async def get_dialogs(
         For a more convenient way of getting a user's dialogs see :meth:`~pyrogram.Client.iter_dialogs`.
 
         Parameters:
-            offset_date (``int``):
-                The offset date in Unix time taken from the top message of a :obj:`~pyrogram.types.Dialog`.
-                Defaults to 0. Valid for non-pinned dialogs only.
+            offset_date (:py:obj:`~datetime.datetime`):
+                The offset date taken from the top message of a :obj:`~pyrogram.types.Dialog`.
+                Defaults to epoch. Valid for non-pinned dialogs only.
 
             limit (``str``, *optional*):
                 Limits the number of dialogs to be retrieved.
@@ -73,7 +74,7 @@ async def get_dialogs(
         else:
             r = await self.send(
                 raw.functions.messages.GetDialogs(
-                    offset_date=offset_date,
+                    offset_date=utils.datetime_to_timestamp(offset_date),
                     offset_id=0,
                     offset_peer=raw.types.InputPeerEmpty(),
                     limit=limit,
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index 7a759185d2..22eee519c1 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -29,7 +30,7 @@ async def restrict_chat_member(
         chat_id: Union[int, str],
         user_id: Union[int, str],
         permissions: "types.ChatPermissions",
-        until_date: int = 0
+        until_date: datetime = datetime.fromtimestamp(0)
     ) -> "types.Chat":
         """Restrict a user in a supergroup.
 
@@ -47,10 +48,10 @@ async def restrict_chat_member(
             permissions (:obj:`~pyrogram.types.ChatPermissions`):
                 New user permissions.
 
-            until_date (``int``, *optional*):
-                Date when the user will be unbanned, unix time.
+            until_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the user will be unbanned.
                 If user is banned for more than 366 days or less than 30 seconds from the current time they are
-                considered to be banned forever. Defaults to 0 (ban forever).
+                considered to be banned forever. Defaults to epoch (ban forever).
 
         Returns:
             :obj:`~pyrogram.types.Chat`: On success, a chat object is returned.
@@ -58,7 +59,7 @@ async def restrict_chat_member(
         Example:
             .. code-block:: python
 
-                from time import time
+                from datetime import datetime, timedelta
 
                 from pyrogram.types import ChatPermissions
 
@@ -66,7 +67,7 @@ async def restrict_chat_member(
                 app.restrict_chat_member(chat_id, user_id, ChatPermissions())
 
                 # Chat member muted for 24h
-                app.restrict_chat_member(chat_id, user_id, ChatPermissions(), int(time() + 86400))
+                app.restrict_chat_member(chat_id, user_id, ChatPermissions(), datetime.now() + timedelta(days=1))
 
                 # Chat member can only send text messages
                 app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
@@ -76,7 +77,7 @@ async def restrict_chat_member(
                 channel=await self.resolve_peer(chat_id),
                 participant=await self.resolve_peer(user_id),
                 banned_rights=raw.types.ChatBannedRights(
-                    until_date=until_date,
+                    until_date=utils.datetime_to_timestamp(until_date),
                     send_messages=not permissions.can_send_messages,
                     send_media=not permissions.can_send_media_messages,
                     send_stickers=not permissions.can_send_other_messages,
diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py
index 4e6aded0b3..eec25787a4 100644
--- a/pyrogram/methods/invite_links/create_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/create_chat_invite_link.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -28,7 +29,7 @@ async def create_chat_invite_link(
         self,
         chat_id: Union[int, str],
         name: str = None,
-        expire_date: int = None,
+        expire_date: datetime = None,
         member_limit: int = None,
         creates_join_request: bool = None
     ) -> "types.ChatInviteLink":
@@ -46,8 +47,8 @@ async def create_chat_invite_link(
             name (``str``, *optional*):
                 Invite link name.
 
-            expire_date (``int``, *optional*):
-                Point in time (Unix timestamp) when the link will expire.
+            expire_date (:py:obj:`~datetime.datetime`, *optional*):
+                Point in time when the link will expire.
                 Defaults to None (no expiration date).
 
             member_limit (``int``, *optional*):
@@ -74,7 +75,7 @@ async def create_chat_invite_link(
         r = await self.send(
             raw.functions.messages.ExportChatInvite(
                 peer=await self.resolve_peer(chat_id),
-                expire_date=expire_date,
+                expire_date=utils.datetime_to_timestamp(expire_date),
                 usage_limit=member_limit,
                 title=name,
                 request_needed=creates_join_request
diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py
index 5c9dc9ff74..9a37536084 100644
--- a/pyrogram/methods/invite_links/edit_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -29,7 +30,7 @@ async def edit_chat_invite_link(
         chat_id: Union[int, str],
         invite_link: str,
         name: str = None,
-        expire_date: int = None,
+        expire_date: datetime = None,
         member_limit: int = None,
         creates_join_request: bool = None
     ) -> "types.ChatInviteLink":
@@ -48,9 +49,9 @@ async def edit_chat_invite_link(
             name (``str``, *optional*):
                 Invite link name.
 
-            expire_date (``int``, *optional*):
-                Point in time (Unix timestamp) when the link will expire.
-                Defaults to None (no change), pass 0 to set no expiration date.
+            expire_date (:py:obj:`~datetime.datetime`, *optional*):
+                Point in time when the link will expire.
+                Defaults to None (no change), pass ``datetime.fromtimestamp(0)`` to set no expiration date.
 
             member_limit (``int``, *optional*):
                 Maximum number of users that can be members of the chat simultaneously after joining the chat via this
@@ -77,7 +78,7 @@ async def edit_chat_invite_link(
             raw.functions.messages.EditExportedChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link,
-                expire_date=expire_date,
+                expire_date=utils.datetime_to_timestamp(expire_date),
                 usage_limit=member_limit,
                 title=name,
                 request_needed=creates_join_request
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index 72d8d04bf3..06aa6c202a 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.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 datetime import datetime
 from typing import Union, List
 
 from pyrogram import types, utils, raw
@@ -31,7 +32,7 @@ async def copy_media_group(
         captions: Union[List[str], str] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
     ) -> List["types.Message"]:
         """Copy a media group by providing one of the message ids.
 
@@ -65,8 +66,8 @@ async def copy_media_group(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
         Returns:
             List of :obj:`~pyrogram.types.Message`: On success, a list of copied messages is returned.
@@ -114,7 +115,7 @@ async def copy_media_group(
                 multi_media=multi_media,
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
-                schedule_date=schedule_date
+                schedule_date=utils.datetime_to_timestamp(schedule_date)
             ),
             sleep_threshold=60
         )
diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index 07c0c5faed..ee40945bab 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
+from datetime import datetime
 from typing import Union, List, Optional
 
 from pyrogram import types, enums
@@ -36,7 +37,7 @@ async def copy_message(
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -83,8 +84,8 @@ async def copy_message(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index caa627d8ad..acddd6e65e 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -16,9 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union, Iterable, List
 
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
@@ -30,7 +31,7 @@ async def forward_messages(
         from_chat_id: Union[int, str],
         message_ids: Union[int, Iterable[int]],
         disable_notification: bool = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None
     ) -> Union["types.Message", List["types.Message"]]:
         """Forward messages of any kind.
@@ -54,8 +55,8 @@ async def forward_messages(
                 Sends the message silently.
                 Users will receive a notification with no sound.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -85,7 +86,7 @@ async def forward_messages(
                 id=message_ids,
                 silent=disable_notification or None,
                 random_id=[self.rnd_id() for _ in message_ids],
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content
             )
         )
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
index d80a6b8b2d..a461b72007 100644
--- a/pyrogram/methods/messages/get_history.py
+++ b/pyrogram/methods/messages/get_history.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
+from datetime import datetime
 from typing import Union, List
 
 from pyrogram import raw
@@ -34,7 +35,7 @@ async def get_history(
         limit: int = 100,
         offset: int = 0,
         offset_id: int = 0,
-        offset_date: int = 0,
+        offset_date: datetime = datetime.fromtimestamp(0),
         reverse: bool = False
     ) -> List["types.Message"]:
         """Retrieve a chunk of the history of a chat.
@@ -59,8 +60,8 @@ async def get_history(
             offset_id (``int``, *optional*):
                 Pass a message identifier as offset to retrieve only older messages starting from that message.
 
-            offset_date (``int``, *optional*):
-                Pass a date in Unix time as offset to retrieve only older messages starting from that date.
+            offset_date (:py:obj:`~datetime.datetime`, *optional*):
+                Pass a date as offset to retrieve only older messages starting from that date.
 
             reverse (``bool``, *optional*):
                 Pass True to retrieve the messages in reversed order (from older to most recent).
@@ -89,7 +90,7 @@ async def get_history(
                 raw.functions.messages.GetHistory(
                     peer=await self.resolve_peer(chat_id),
                     offset_id=offset_id,
-                    offset_date=offset_date,
+                    offset_date=utils.datetime_to_timestamp(offset_date),
                     add_offset=offset * (-1 if reverse else 1) - (limit if reverse else 0),
                     limit=limit,
                     max_id=0,
diff --git a/pyrogram/methods/messages/iter_history.py b/pyrogram/methods/messages/iter_history.py
index 2e60dfde90..b9dd20098c 100644
--- a/pyrogram/methods/messages/iter_history.py
+++ b/pyrogram/methods/messages/iter_history.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 datetime import datetime
 from typing import Union, Optional, AsyncGenerator
 
 from pyrogram import types
@@ -29,7 +30,7 @@ async def iter_history(
         limit: int = 0,
         offset: int = 0,
         offset_id: int = 0,
-        offset_date: int = 0,
+        offset_date: datetime = datetime.fromtimestamp(0),
         reverse: bool = False
     ) -> Optional[AsyncGenerator["types.Message", None]]:
         """Iterate through a chat history sequentially.
@@ -55,8 +56,8 @@ async def iter_history(
             offset_id (``int``, *optional*):
                 Identifier of the first message to be returned.
 
-            offset_date (``int``, *optional*):
-                Pass a date in Unix time as offset to retrieve only older messages starting from that date.
+            offset_date (:py:obj:`~datetime.datetime`, *optional*):
+                Pass a date as offset to retrieve only older messages starting from that date.
 
             reverse (``bool``, *optional*):
                 Pass True to retrieve the messages in reversed order (from older to most recent).
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 3777b3eab1..4e6a9f407b 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, List, Optional
 
 from pyrogram import StopTransmission, enums
@@ -45,7 +46,7 @@ async def send_animation(
         file_name: str = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -111,8 +112,8 @@ async def send_animation(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -222,7 +223,7 @@ def progress(current, total):
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index e00930af1d..6cef5b47dd 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -27,6 +27,7 @@
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
 from pyrogram.scaffold import Scaffold
+from datetime import datetime
 
 
 class SendAudio(Scaffold):
@@ -44,7 +45,7 @@ async def send_audio(
         file_name: str = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -108,8 +109,8 @@ async def send_audio(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -216,7 +217,7 @@ def progress(current, total):
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 5c8951212f..60832553fb 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.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 datetime import datetime
 from typing import Union, List, Optional
 
 from pyrogram import raw, enums
@@ -34,7 +35,7 @@ async def send_cached_media(
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -76,8 +77,8 @@ async def send_cached_media(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
             
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -102,7 +103,7 @@ async def send_cached_media(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None,
                 **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index f396577797..f9c84f4c9f 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.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 datetime import datetime
 from typing import Union
 
 from pyrogram import raw
@@ -33,7 +34,7 @@ async def send_contact(
         vcard: str = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -69,8 +70,8 @@ async def send_contact(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -100,7 +101,7 @@ async def send_contact(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None
             )
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index dfc9d5b895..9c7f5d1a70 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -21,6 +21,7 @@
 from pyrogram import raw
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
+from datetime import datetime
 
 
 class SendDice(Scaffold):
@@ -30,7 +31,7 @@ async def send_dice(
         emoji: str = "🎲",
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -61,8 +62,8 @@ async def send_dice(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -94,7 +95,7 @@ async def send_dice(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None,
                 message=""
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 4a35f8a5e9..5844d2d232 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, List, Optional
 
 from pyrogram import StopTransmission, enums
@@ -42,7 +43,7 @@ async def send_document(
         force_document: bool = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -100,8 +101,8 @@ async def send_document(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -194,7 +195,7 @@ def progress(current, total):
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py
index d2b6616dae..6c33c1b4fc 100644
--- a/pyrogram/methods/messages/send_location.py
+++ b/pyrogram/methods/messages/send_location.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 datetime import datetime
 from typing import Union
 
 from pyrogram import raw
@@ -31,7 +32,7 @@ async def send_location(
         longitude: float,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -61,8 +62,8 @@ async def send_location(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -92,7 +93,7 @@ async def send_location(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None
             )
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index 13d4d62a8a..04c91c3b44 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -19,6 +19,7 @@
 import logging
 import os
 import re
+from datetime import datetime
 from typing import Union, List
 
 from pyrogram import raw
@@ -43,7 +44,7 @@ async def send_media_group(
         ]],
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
     ) -> List["types.Message"]:
         """Send a group of photos or videos as an album.
@@ -64,8 +65,8 @@ async def send_media_group(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -381,7 +382,7 @@ async def send_media_group(
                 multi_media=multi_media,
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content
             ),
             sleep_threshold=60
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 575aea33e7..a094ba9214 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -22,6 +22,8 @@
 from pyrogram import types
 from pyrogram.scaffold import Scaffold
 
+from datetime import datetime
+
 
 class SendMessage(Scaffold):
     async def send_message(
@@ -33,7 +35,7 @@ async def send_message(
         disable_web_page_preview: bool = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -70,8 +72,8 @@ async def send_message(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -129,7 +131,7 @@ async def send_message(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 reply_markup=await reply_markup.write(self) if reply_markup else None,
                 message=message,
                 entities=entities,
@@ -150,11 +152,11 @@ async def send_message(
                 message_id=r.id,
                 chat=types.Chat(
                     id=peer_id,
-                    type="private",
+                    type=enums.ChatType.PRIVATE,
                     client=self
                 ),
                 text=message,
-                date=r.date,
+                date=utils.timestamp_to_datetime(r.date),
                 outgoing=r.out,
                 reply_markup=reply_markup,
                 entities=[
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index 442b45aec5..bf7b482cbe 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, List, Optional
 
 import pyrogram
@@ -40,7 +41,7 @@ async def send_photo(
         ttl_seconds: int = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -88,8 +89,8 @@ async def send_photo(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -172,7 +173,7 @@ async def send_photo(
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index df27c0573f..a02c52663c 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.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 datetime import datetime
 from typing import Union, List
 
 from pyrogram import raw
@@ -35,7 +36,7 @@ async def send_poll(
         correct_option_id: int = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -81,8 +82,8 @@ async def send_poll(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -120,7 +121,7 @@ async def send_poll(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None
             )
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index 641cc6359a..76571d9999 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, Optional
 
 from pyrogram import StopTransmission
@@ -36,7 +37,7 @@ async def send_sticker(
         sticker: Union[str, BinaryIO],
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -69,8 +70,8 @@ async def send_sticker(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -153,7 +154,7 @@ async def send_sticker(
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             message=""
diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py
index 7941485ebc..5293cf01df 100644
--- a/pyrogram/methods/messages/send_venue.py
+++ b/pyrogram/methods/messages/send_venue.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 datetime import datetime
 from typing import Union
 
 from pyrogram import raw
@@ -35,7 +36,7 @@ async def send_venue(
         foursquare_type: str = "",
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -78,8 +79,8 @@ async def send_venue(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -116,7 +117,7 @@ async def send_venue(
                 silent=disable_notification or None,
                 reply_to_msg_id=reply_to_message_id,
                 random_id=self.rnd_id(),
-                schedule_date=schedule_date,
+                schedule_date=utils.datetime_to_timestamp(schedule_date),
                 noforwards=protect_content,
                 reply_markup=await reply_markup.write(self) if reply_markup else None
             )
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index f6dc00eebe..96f2a9c3bb 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, List, Optional
 
 from pyrogram import StopTransmission, enums
@@ -46,7 +47,7 @@ async def send_video(
         supports_streaming: bool = True,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -117,8 +118,8 @@ async def send_video(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -228,7 +229,7 @@ def progress(current, total):
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index 1e52f3ab14..c2f0a159ab 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 import os
+from datetime import datetime
 from typing import Union, BinaryIO, Optional
 
 from pyrogram import StopTransmission
@@ -38,7 +39,7 @@ async def send_video_note(
         thumb: Union[str, BinaryIO] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -83,8 +84,8 @@ async def send_video_note(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -177,7 +178,7 @@ async def send_video_note(
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             message=""
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index c7e960fd04..79fefcab1d 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -18,6 +18,7 @@
 
 import os
 import re
+from datetime import datetime
 from typing import Union, BinaryIO, List, Optional
 
 from pyrogram import StopTransmission, enums
@@ -40,7 +41,7 @@ async def send_voice(
         duration: int = 0,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -86,8 +87,8 @@ async def send_voice(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -178,7 +179,7 @@ async def send_voice(
                             silent=disable_notification or None,
                             reply_to_msg_id=reply_to_message_id,
                             random_id=self.rnd_id(),
-                            schedule_date=schedule_date,
+                            schedule_date=utils.datetime_to_timestamp(schedule_date),
                             noforwards=protect_content,
                             reply_markup=await reply_markup.write(self) if reply_markup else None,
                             **await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py
index 884e17558e..35a15d0c68 100644
--- a/pyrogram/parser/parser.py
+++ b/pyrogram/parser/parser.py
@@ -30,7 +30,7 @@ def __init__(self, client: Optional["pyrogram.Client"]):
         self.html = HTML(client)
         self.markdown = Markdown(client)
 
-    async def parse(self, text: str, mode: Optional[str] = None):
+    async def parse(self, text: str, mode: Optional[enums.ParseMode] = None):
         text = str(text if text else "").strip()
 
         if mode is None:
diff --git a/pyrogram/types/messages_and_media/animation.py b/pyrogram/types/messages_and_media/animation.py
index ce901734e6..1e7bf4cf39 100644
--- a/pyrogram/types/messages_and_media/animation.py
+++ b/pyrogram/types/messages_and_media/animation.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
@@ -54,8 +55,8 @@ class Animation(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the animation was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the animation was sent.
 
         thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
             Animation thumbnails.
@@ -73,7 +74,7 @@ def __init__(
         file_name: str = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None,
+        date: datetime = None,
         thumbs: List["types.Thumbnail"] = None
     ):
         super().__init__(client)
@@ -114,7 +115,7 @@ def _parse(
             mime_type=animation.mime_type,
             file_size=animation.size,
             file_name=file_name,
-            date=animation.date,
+            date=utils.timestamp_to_datetime(animation.date),
             thumbs=types.Thumbnail._parse(client, animation),
             client=client
         )
diff --git a/pyrogram/types/messages_and_media/audio.py b/pyrogram/types/messages_and_media/audio.py
index 60b37a59e7..e474282f0b 100644
--- a/pyrogram/types/messages_and_media/audio.py
+++ b/pyrogram/types/messages_and_media/audio.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
@@ -54,8 +55,8 @@ class Audio(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the audio was originally sent, in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the audio was originally sent.
 
         thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
             Thumbnails of the music file album cover.
@@ -73,7 +74,7 @@ def __init__(
         file_name: str = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None,
+        date: datetime = None,
         thumbs: List["types.Thumbnail"] = None
     ):
         super().__init__(client)
@@ -114,7 +115,7 @@ def _parse(
             mime_type=audio.mime_type,
             file_size=audio.size,
             file_name=file_name,
-            date=audio.date,
+            date=utils.timestamp_to_datetime(audio.date),
             thumbs=types.Thumbnail._parse(client, audio),
             client=client
         )
diff --git a/pyrogram/types/messages_and_media/document.py b/pyrogram/types/messages_and_media/document.py
index 333d38abb7..95ebe3f289 100644
--- a/pyrogram/types/messages_and_media/document.py
+++ b/pyrogram/types/messages_and_media/document.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
@@ -45,8 +46,8 @@ class Document(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the document was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the document was sent.
 
         thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
             Document thumbnails as defined by sender.
@@ -61,7 +62,7 @@ def __init__(
         file_name: str = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None,
+        date: datetime = None,
         thumbs: List["types.Thumbnail"] = None
     ):
         super().__init__(client)
@@ -91,7 +92,7 @@ def _parse(client, document: "raw.types.Document", file_name: str) -> "Document"
             file_name=file_name,
             mime_type=document.mime_type,
             file_size=document.size,
-            date=document.date,
+            date=utils.timestamp_to_datetime(document.date),
             thumbs=types.Thumbnail._parse(client, document),
             client=client
         )
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 2c2f7e053d..86c340aea6 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -17,6 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 import logging
+from datetime import datetime
 from functools import partial
 from typing import List, Match, Union, BinaryIO, Optional
 
@@ -71,8 +72,8 @@ class Message(Object, Update):
             The supergroup itself for messages from anonymous group administrators.
             The linked channel for messages automatically forwarded to the discussion group.
 
-        date (``int``, *optional*):
-            Date the message was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the message was sent.
 
         chat (:obj:`~pyrogram.types.Chat`, *optional*):
             Conversation the message belongs to.
@@ -92,8 +93,8 @@ class Message(Object, Update):
         forward_signature (``str``, *optional*):
             For messages forwarded from channels, signature of the post author if present.
 
-        forward_date (``int``, *optional*):
-            For forwarded messages, date the original message was sent in Unix time.
+        forward_date (:py:obj:`~datetime.datetime`, *optional*):
+            For forwarded messages, date the original message was sent.
 
         reply_to_message_id (``int``, *optional*):
             The id of the message which this message directly replied to.
@@ -122,8 +123,8 @@ class Message(Object, Update):
             This field will contain the enumeration type of the media message.
             You can use ``media = getattr(message, message.media.value)`` to access the media message.
 
-        edit_date (``int``, *optional*):
-            Date the message was last edited in Unix time.
+        edit_date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the message was last edited.
 
         media_group_id (``str``, *optional*):
             The unique identifier of a media message group this message belongs to.
@@ -304,14 +305,14 @@ def __init__(
         message_id: int,
         from_user: "types.User" = None,
         sender_chat: "types.Chat" = None,
-        date: int = None,
+        date: datetime = None,
         chat: "types.Chat" = None,
         forward_from: "types.User" = None,
         forward_sender_name: str = None,
         forward_from_chat: "types.Chat" = None,
         forward_from_message_id: int = None,
         forward_signature: str = None,
-        forward_date: int = None,
+        forward_date: datetime = None,
         reply_to_message_id: int = None,
         reply_to_top_message_id: int = None,
         reply_to_message: "Message" = None,
@@ -321,7 +322,7 @@ def __init__(
         scheduled: bool = None,
         from_scheduled: bool = None,
         media: str = None,
-        edit_date: int = None,
+        edit_date: datetime = None,
         media_group_id: str = None,
         author_signature: str = None,
         has_protected_content: bool = None,
@@ -542,7 +543,7 @@ async def _parse(
 
             parsed_message = Message(
                 message_id=message.id,
-                date=message.date,
+                date=utils.timestamp_to_datetime(message.date),
                 chat=types.Chat._parse(client, message, users, chats, is_chat=True),
                 from_user=from_user,
                 sender_chat=sender_chat,
@@ -607,7 +608,7 @@ async def _parse(
             forward_header = message.fwd_from  # type: raw.types.MessageFwdHeader
 
             if forward_header:
-                forward_date = forward_header.date
+                forward_date = utils.timestamp_to_datetime(forward_header.date)
 
                 if forward_header.from_id:
                     raw_peer_id = utils.get_raw_peer_id(forward_header.from_id)
@@ -739,7 +740,7 @@ async def _parse(
 
             parsed_message = Message(
                 message_id=message.id,
-                date=message.date,
+                date=utils.timestamp_to_datetime(message.date),
                 chat=types.Chat._parse(client, message, users, chats, is_chat=True),
                 from_user=from_user,
                 sender_chat=sender_chat,
@@ -775,7 +776,7 @@ async def _parse(
                 scheduled=is_scheduled,
                 from_scheduled=message.from_scheduled,
                 media=media_type,
-                edit_date=message.edit_date,
+                edit_date=utils.timestamp_to_datetime(message.edit_date),
                 media_group_id=message.grouped_id,
                 photo=photo,
                 location=location,
@@ -864,7 +865,7 @@ async def reply_text(
         disable_web_page_preview: bool = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup = None
     ) -> "Message":
@@ -913,8 +914,8 @@ async def reply_text(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
@@ -1449,7 +1450,7 @@ async def reply_document(
         force_document: bool = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
             "types.ReplyKeyboardMarkup",
@@ -1519,8 +1520,8 @@ async def reply_document(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
             
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
@@ -1982,7 +1983,7 @@ async def reply_poll(
         correct_option_id: int = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
             "types.ReplyKeyboardMarkup",
@@ -2042,8 +2043,8 @@ async def reply_poll(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
             
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
@@ -2859,7 +2860,7 @@ async def forward(
         self,
         chat_id: Union[int, str],
         disable_notification: bool = None,
-        schedule_date: int = None
+        schedule_date: datetime = None
     ) -> Union["types.Message", List["types.Message"]]:
         """Bound method *forward* of :obj:`~pyrogram.types.Message`.
 
@@ -2888,8 +2889,8 @@ async def forward(
                 Sends the message silently.
                 Users will receive a notification with no sound.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
         Returns:
             On success, the forwarded Message is returned.
@@ -2913,7 +2914,7 @@ async def copy(
         caption_entities: List["types.MessageEntity"] = None,
         disable_notification: bool = None,
         reply_to_message_id: int = None,
-        schedule_date: int = None,
+        schedule_date: datetime = None,
         protect_content: bool = None,
         reply_markup: Union[
             "types.InlineKeyboardMarkup",
@@ -2964,8 +2965,8 @@ async def copy(
             reply_to_message_id (``int``, *optional*):
                 If the message is a reply, ID of the original message.
 
-            schedule_date (``int``, *optional*):
-                Date when the message will be automatically sent. Unix time.
+            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the message will be automatically sent.
 
             protect_content (``bool``, *optional*):
                 Protects the contents of the sent message from forwarding and saving.
diff --git a/pyrogram/types/messages_and_media/photo.py b/pyrogram/types/messages_and_media/photo.py
index fc496cd455..d6ad92263d 100644
--- a/pyrogram/types/messages_and_media/photo.py
+++ b/pyrogram/types/messages_and_media/photo.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource
 from ..object import Object
@@ -45,8 +46,8 @@ class Photo(Object):
         file_size (``int``):
             File size.
 
-        date (``int``):
-            Date the photo was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`):
+            Date the photo was sent.
 
         ttl_seconds (``int``, *optional*):
             Time-to-live seconds, for secret photos.
@@ -64,7 +65,7 @@ def __init__(
         width: int,
         height: int,
         file_size: int,
-        date: int,
+        date: datetime,
         ttl_seconds: int = None,
         thumbs: List["types.Thumbnail"] = None
     ):
@@ -122,7 +123,7 @@ def _parse(client, photo: "raw.types.Photo", ttl_seconds: int = None) -> "Photo"
                 width=main.w,
                 height=main.h,
                 file_size=main.size,
-                date=photo.date,
+                date=utils.timestamp_to_datetime(photo.date),
                 ttl_seconds=ttl_seconds,
                 thumbs=types.Thumbnail._parse(client, photo),
                 client=client
diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py
index bd08792ff0..fa6e0be3fb 100644
--- a/pyrogram/types/messages_and_media/sticker.py
+++ b/pyrogram/types/messages_and_media/sticker.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.errors import StickersetInvalid
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
@@ -58,8 +59,8 @@ class Sticker(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the sticker was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the sticker was sent.
 
         emoji (``str``, *optional*):
             Emoji associated with the sticker.
@@ -86,7 +87,7 @@ def __init__(
         file_name: str = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None,
+        date: datetime = None,
         emoji: str = None,
         set_name: str = None,
         thumbs: List["types.Thumbnail"] = None
@@ -179,7 +180,7 @@ async def _parse(
             file_size=sticker.size,
             mime_type=sticker.mime_type,
             file_name=file_name,
-            date=sticker.date,
+            date=utils.timestamp_to_datetime(sticker.date),
             thumbs=types.Thumbnail._parse(client, sticker),
             client=client
         )
diff --git a/pyrogram/types/messages_and_media/video.py b/pyrogram/types/messages_and_media/video.py
index 1cdf055fc0..b50f9fca78 100644
--- a/pyrogram/types/messages_and_media/video.py
+++ b/pyrogram/types/messages_and_media/video.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
@@ -60,8 +61,8 @@ class Video(Object):
         ttl_seconds (``int``. *optional*):
             Time-to-live seconds, for secret photos.
 
-        date (``int``, *optional*):
-            Date the video was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the video was sent.
 
         thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
             Video thumbnails.
@@ -81,7 +82,7 @@ def __init__(
         file_size: int = None,
         supports_streaming: bool = None,
         ttl_seconds: int = None,
-        date: int = None,
+        date: datetime = None,
         thumbs: List["types.Thumbnail"] = None
     ):
         super().__init__(client)
@@ -126,7 +127,7 @@ def _parse(
             mime_type=video.mime_type,
             supports_streaming=video_attributes.supports_streaming,
             file_size=video.size,
-            date=video.date,
+            date=utils.timestamp_to_datetime(video.date),
             ttl_seconds=ttl_seconds,
             thumbs=types.Thumbnail._parse(client, video),
             client=client
diff --git a/pyrogram/types/messages_and_media/video_note.py b/pyrogram/types/messages_and_media/video_note.py
index 3a9e8a616f..450d536db1 100644
--- a/pyrogram/types/messages_and_media/video_note.py
+++ b/pyrogram/types/messages_and_media/video_note.py
@@ -19,10 +19,11 @@
 from typing import List
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
+from datetime import datetime
 
 
 class VideoNote(Object):
@@ -48,8 +49,8 @@ class VideoNote(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the video note was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the video note was sent.
 
         thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
             Video thumbnails.
@@ -66,7 +67,7 @@ def __init__(
         thumbs: List["types.Thumbnail"] = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None
+        date: datetime = None
     ):
         super().__init__(client)
 
@@ -101,7 +102,7 @@ def _parse(
             duration=video_attributes.duration,
             file_size=video_note.size,
             mime_type=video_note.mime_type,
-            date=video_note.date,
+            date=utils.timestamp_to_datetime(video_note.date),
             thumbs=types.Thumbnail._parse(client, video_note),
             client=client
         )
diff --git a/pyrogram/types/messages_and_media/voice.py b/pyrogram/types/messages_and_media/voice.py
index 4175b7ba1e..8d1c15f657 100644
--- a/pyrogram/types/messages_and_media/voice.py
+++ b/pyrogram/types/messages_and_media/voice.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 datetime import datetime
+
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
 
@@ -45,8 +47,8 @@ class Voice(Object):
         file_size (``int``, *optional*):
             File size.
 
-        date (``int``, *optional*):
-            Date the voice was sent in Unix time.
+        date (:py:obj:`~datetime.datetime`, *optional*):
+            Date the voice was sent.
     """
 
     def __init__(
@@ -59,7 +61,7 @@ def __init__(
         waveform: bytes = None,
         mime_type: str = None,
         file_size: int = None,
-        date: int = None
+        date: datetime = None
     ):
         super().__init__(client)
 
@@ -89,6 +91,6 @@ def _parse(client, voice: "raw.types.Document", attributes: "raw.types.DocumentA
             mime_type=voice.mime_type,
             file_size=voice.size,
             waveform=attributes.waveform,
-            date=voice.date,
+            date=utils.timestamp_to_datetime(voice.date),
             client=client
         )
diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py
index a0925779e2..a3641b1614 100644
--- a/pyrogram/types/object.py
+++ b/pyrogram/types/object.py
@@ -56,14 +56,14 @@ def default(obj: "Object"):
         if isinstance(obj, Enum):
             return str(obj)
 
+        if isinstance(obj, datetime):
+            return str(obj)
+
         return {
             "_": obj.__class__.__name__,
             **{
                 attr: (
-                    "*" * 9
-                    if attr == "phone_number" else
-                    str(datetime.fromtimestamp(getattr(obj, attr)))
-                    if attr.endswith("date") else
+                    "*" * 9 if attr == "phone_number" else
                     getattr(obj, attr)
                 )
                 for attr in filter(lambda x: not x.startswith("_"), obj.__dict__)
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 2282b1e073..870391a49d 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.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 datetime import datetime
 from typing import Union, List, Generator, Optional
 
 import pyrogram
@@ -513,7 +514,7 @@ async def set_photo(self, photo: str) -> bool:
     async def ban_member(
         self,
         user_id: Union[int, str],
-        until_date: int = 0
+        until_date: datetime = datetime.fromtimestamp(0)
     ) -> Union["types.Message", bool]:
         """Bound method *ban_member* of :obj:`~pyrogram.types.Chat`.
 
@@ -541,10 +542,10 @@ async def ban_member(
                 Unique identifier (int) or username (str) of the target user.
                 For a contact that exists in your Telegram address book you can use his phone number (str).
 
-            until_date (``int``, *optional*):
-                Date when the user will be unbanned, unix time.
+            until_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the user will be unbanned.
                 If user is banned for more than 366 days or less than 30 seconds from the current time they are
-                considered to be banned forever. Defaults to 0 (ban forever).
+                considered to be banned forever. Defaults to epoch (ban forever).
 
         Returns:
             :obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable), otherwise, in
@@ -601,7 +602,7 @@ async def restrict_member(
         self,
         user_id: Union[int, str],
         permissions: "types.ChatPermissions",
-        until_date: int = 0,
+        until_date: datetime = datetime.fromtimestamp(0),
     ) -> "types.Chat":
         """Bound method *unban_member* of :obj:`~pyrogram.types.Chat`.
 
@@ -628,10 +629,10 @@ async def restrict_member(
             permissions (:obj:`~pyrogram.types.ChatPermissions`):
                 New user permissions.
 
-            until_date (``int``, *optional*):
-                Date when the user will be unbanned, unix time.
+            until_date (:py:obj:`~datetime.datetime`, *optional*):
+                Date when the user will be unbanned.
                 If user is banned for more than 366 days or less than 30 seconds from the current time they are
-                considered to be banned forever. Defaults to 0 (ban forever).
+                considered to be banned forever. Defaults to epoch (ban forever).
 
         Returns:
             :obj:`~pyrogram.types.Chat`: On success, a chat object is returned.
diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py
index 3abfd1f9d6..fa539be868 100644
--- a/pyrogram/types/user_and_chats/chat_event.py
+++ b/pyrogram/types/user_and_chats/chat_event.py
@@ -16,57 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from enum import Enum, auto
+from datetime import datetime
 from typing import List, Optional
 
 import pyrogram
 from pyrogram import raw
-from pyrogram import types
+from pyrogram import types, utils, enums
 from ..object import Object
 
 
-class AutoName(Enum):
-    def _generate_next_value_(self, *args):
-        return self.lower()
-
-
-class ChatEventAction(AutoName):
-    DESCRIPTION_CHANGED = auto()
-    HISTORY_TTL_CHANGED = auto()
-    LINKED_CHAT_CHANGED = auto()
-    # LOCATION_CHANGED = auto()
-    PHOTO_CHANGED = auto()
-    # STICKER_SET_CHANGED = auto()
-    TITLE_CHANGED = auto()
-    USERNAME_CHANGED = auto()
-    CHAT_PERMISSIONS_CHANGED = auto()
-    MESSAGE_DELETED = auto()
-    # VOICE_CHAT_DISCARDED = auto()
-    MESSAGE_EDITED = auto()
-    INVITE_LINK_EDITED = auto()
-    INVITE_LINK_REVOKED = auto()
-    INVITE_LINK_DELETED = auto()
-    MEMBER_INVITED = auto()
-    MEMBER_JOINED = auto()
-    # MEMBER_JOINED_BY_LINK = auto()
-    MEMBER_LEFT = auto()
-    # MEMBER_MUTED = auto()
-    ADMIN_RIGHTS_CHANGED = auto()
-    MEMBER_PERMISSIONS_CHANGED = auto()
-    # MEMBER_UNMUTED = auto()
-    # MEMBER_VOLUME_CHANGED = auto()
-    # VOICE_CHAT_STARTED = auto()
-    POLL_STOPPED = auto()
-    # VOICE_CHAT_SETTINGS_CHANGED = auto()
-    INVITES_ENABLED = auto()
-    HISTORY_HIDDEN = auto()
-    SIGNATURES_ENABLED = auto()
-    SLOW_MODE_CHANGED = auto()
-    MESSAGE_PINNED = auto()
-    MESSAGE_UNPINNED = auto()
-    UNKNOWN = auto()
-
-
 class ChatEvent(Object):
     """A chat event from the recent actions log (also known as admin log).
 
@@ -76,8 +34,8 @@ class ChatEvent(Object):
         id (``int``):
             Chat event identifier.
 
-        date (``int``):
-            Date of the event. Unix time.
+        date (:py:obj:`~datetime.datetime`):
+            Date of the event.
 
         action (:obj:`~pyrogram.enums.ChatEventAction`):
             Event action.
@@ -177,7 +135,7 @@ class ChatEvent(Object):
     def __init__(
         self, *,
         id: int,
-        date: int,
+        date: datetime,
         user: "types.User",
         action: str,
 
@@ -232,7 +190,7 @@ def __init__(
         old_invite_link: "types.ChatInviteLink" = None,
         new_invite_link: "types.ChatInviteLink" = None,
         revoked_invite_link: "types.ChatInviteLink" = None,
-        deleted_invite_link: "types.ChatInviteLink" = None,
+        deleted_invite_link: "types.ChatInviteLink" = None
     ):
         super().__init__()
 
@@ -296,10 +254,10 @@ def __init__(
 
     @staticmethod
     async def _parse(
-        client: "pyrogram.Client",
-        event: "raw.base.ChannelAdminLogEvent",
-        users: List["raw.base.User"],
-        chats: List["raw.base.Chat"]
+            client: "pyrogram.Client",
+            event: "raw.base.ChannelAdminLogEvent",
+            users: List["raw.base.User"],
+            chats: List["raw.base.Chat"]
     ):
         users = {i.id: i for i in users}
         chats = {i.id: i for i in chats}
@@ -363,117 +321,117 @@ async def _parse(
         if isinstance(action, raw.types.ChannelAdminLogEventActionChangeAbout):
             old_description = action.prev_value
             new_description = action.new_value
-            action = ChatEventAction.DESCRIPTION_CHANGED
+            action = enums.ChatEventAction.DESCRIPTION_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeHistoryTTL):
             old_history_ttl = action.prev_value
             new_history_ttl = action.new_value
-            action = ChatEventAction.HISTORY_TTL_CHANGED
+            action = enums.ChatEventAction.HISTORY_TTL_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeLinkedChat):
             old_linked_chat = types.Chat._parse_chat(client, chats[action.prev_value])
             new_linked_chat = types.Chat._parse_chat(client, chats[action.new_value])
-            action = ChatEventAction.LINKED_CHAT_CHANGED
+            action = enums.ChatEventAction.LINKED_CHAT_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangePhoto):
             old_photo = types.Photo._parse(client, action.prev_photo)
             new_photo = types.Photo._parse(client, action.new_photo)
-            action = ChatEventAction.PHOTO_CHANGED
+            action = enums.ChatEventAction.PHOTO_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeTitle):
             old_title = action.prev_value
             new_title = action.new_value
-            action = ChatEventAction.TITLE_CHANGED
+            action = enums.ChatEventAction.TITLE_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeUsername):
             old_username = action.prev_value
             new_username = action.new_value
-            action = ChatEventAction.USERNAME_CHANGED
+            action = enums.ChatEventAction.USERNAME_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionDefaultBannedRights):
             old_chat_permissions = types.ChatPermissions._parse(action.prev_banned_rights)
             new_chat_permissions = types.ChatPermissions._parse(action.new_banned_rights)
-            action = ChatEventAction.CHAT_PERMISSIONS_CHANGED
+            action = enums.ChatEventAction.CHAT_PERMISSIONS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionDeleteMessage):
             deleted_message = await types.Message._parse(client, action.message, users, chats)
-            action = ChatEventAction.MESSAGE_DELETED
+            action = enums.ChatEventAction.MESSAGE_DELETED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionEditMessage):
             old_message = await types.Message._parse(client, action.prev_message, users, chats)
             new_message = await types.Message._parse(client, action.new_message, users, chats)
-            action = ChatEventAction.MESSAGE_EDITED
+            action = enums.ChatEventAction.MESSAGE_EDITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantInvite):
             invited_member = types.ChatMember._parse(client, action.participant, users, chats)
-            action = ChatEventAction.MEMBER_INVITED
+            action = enums.ChatEventAction.MEMBER_INVITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleAdmin):
             old_administrator_privileges = types.ChatMember._parse(client, action.prev_participant, users, chats)
             new_administrator_privileges = types.ChatMember._parse(client, action.new_participant, users, chats)
-            action = ChatEventAction.ADMIN_RIGHTS_CHANGED
+            action = enums.ChatEventAction.ADMIN_RIGHTS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleBan):
             old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users, chats)
             new_member_permissions = types.ChatMember._parse(client, action.new_participant, users, chats)
-            action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED
+            action = enums.ChatEventAction.MEMBER_PERMISSIONS_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionStopPoll):
             stopped_poll = await types.Message._parse(client, action.message, users, chats)
-            action = ChatEventAction.POLL_STOPPED
+            action = enums.ChatEventAction.POLL_STOPPED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantJoin):
-            action = ChatEventAction.MEMBER_JOINED
+            action = enums.ChatEventAction.MEMBER_JOINED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantLeave):
-            action = ChatEventAction.MEMBER_LEFT
+            action = enums.ChatEventAction.MEMBER_LEFT
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleInvites):
             invites_enabled = action.new_value
-            action = ChatEventAction.INVITES_ENABLED
+            action = enums.ChatEventAction.INVITES_ENABLED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionTogglePreHistoryHidden):
             history_hidden = action.new_value
-            action = ChatEventAction.HISTORY_HIDDEN
+            action = enums.ChatEventAction.HISTORY_HIDDEN
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSignatures):
             signatures_enabled = action.new_value
-            action = ChatEventAction.SIGNATURES_ENABLED
+            action = enums.ChatEventAction.SIGNATURES_ENABLED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSlowMode):
             old_slow_mode = action.prev_value
             new_slow_mode = action.new_value
-            action = ChatEventAction.SLOW_MODE_CHANGED
+            action = enums.ChatEventAction.SLOW_MODE_CHANGED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned):
             message = action.message
 
             if message.pinned:
                 pinned_message = await types.Message._parse(client, message, users, chats)
-                action = ChatEventAction.MESSAGE_PINNED
+                action = enums.ChatEventAction.MESSAGE_PINNED
             else:
                 unpinned_message = await types.Message._parse(client, message, users, chats)
-                action = ChatEventAction.MESSAGE_UNPINNED
+                action = enums.ChatEventAction.MESSAGE_UNPINNED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit):
             old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users)
             new_invite_link = types.ChatInviteLink._parse(client, action.new_invite, users)
-            action = ChatEventAction.INVITE_LINK_EDITED
+            action = enums.ChatEventAction.INVITE_LINK_EDITED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteRevoke):
             revoked_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
-            action = ChatEventAction.INVITE_LINK_REVOKED
+            action = enums.ChatEventAction.INVITE_LINK_REVOKED
 
         elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteDelete):
             deleted_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
-            action = ChatEventAction.INVITE_LINK_DELETED
+            action = enums.ChatEventAction.INVITE_LINK_DELETED
 
         else:
-            action = f"{ChatEventAction.UNKNOWN}-{action.QUALNAME}"
+            action = f"{enums.ChatEventAction.UNKNOWN}-{action.QUALNAME}"
 
         return ChatEvent(
             id=event.id,
-            date=event.date,
+            date=utils.timestamp_to_datetime(event.date),
             user=user,
             action=action,
             old_description=old_description,
diff --git a/pyrogram/types/user_and_chats/chat_invite_link.py b/pyrogram/types/user_and_chats/chat_invite_link.py
index 9dddea4835..7aaa56a8cf 100644
--- a/pyrogram/types/user_and_chats/chat_invite_link.py
+++ b/pyrogram/types/user_and_chats/chat_invite_link.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Dict
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from ..object import Object
 
@@ -32,8 +33,8 @@ class ChatInviteLink(Object):
             The invite link. If the link was created by another chat administrator, then the second part of the
             link will be replaced with "...".
 
-        date (``int``):
-            The date in Unix timestamp when the link was created.
+        date (:py:obj:`~datetime.datetime`):
+            The date when the link was created.
 
         is_primary (``bool``):
             True, if the link is primary.
@@ -50,8 +51,11 @@ class ChatInviteLink(Object):
         creates_join_request (``bool``, *optional*):
             True, if users joining the chat via the link need to be approved by chat administrators.
 
-        expire_date (``int``, *optional*):
-            Point in time (Unix timestamp) when the link will expire or has been expired.
+        start_date (:py:obj:`~datetime.datetime`, *optional*):
+            Point in time when the link has been edited.
+
+        expire_date (:py:obj:`~datetime.datetime`, *optional*):
+            Point in time when the link will expire or has been expired.
 
         member_limit (``int``, *optional*):
             Maximum number of users that can be members of the chat simultaneously after joining the chat via this
@@ -67,14 +71,14 @@ class ChatInviteLink(Object):
     def __init__(
         self, *,
         invite_link: str,
-        date: int,
+        date: datetime,
         is_primary: bool = None,
         is_revoked: bool = None,
         creator: "types.User" = None,
         name: str = None,
         creates_join_request: bool = None,
-        start_date: int = None,
-        expire_date: int = None,
+        start_date: datetime = None,
+        expire_date: datetime = None,
         member_limit: int = None,
         member_count: int = None,
         pending_join_request_count: int = None
@@ -108,13 +112,14 @@ def _parse(
 
         return ChatInviteLink(
             invite_link=invite.link,
-            date=invite.date,
+            date=utils.timestamp_to_datetime(invite.date),
             is_primary=invite.permanent,
             is_revoked=invite.revoked,
             creator=creator,
             name=invite.title,
             creates_join_request=invite.request_needed,
-            expire_date=invite.expire_date,
+            start_date=utils.timestamp_to_datetime(invite.start_date),
+            expire_date=utils.timestamp_to_datetime(invite.expire_date),
             member_limit=invite.usage_limit,
             member_count=invite.usage,
             pending_join_request_count=invite.requested
diff --git a/pyrogram/types/user_and_chats/chat_join_request.py b/pyrogram/types/user_and_chats/chat_join_request.py
index fe051de4f7..ee9da3ef2c 100644
--- a/pyrogram/types/user_and_chats/chat_join_request.py
+++ b/pyrogram/types/user_and_chats/chat_join_request.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 datetime import datetime
 from typing import Dict
 
 import pyrogram
@@ -35,8 +36,8 @@ class ChatJoinRequest(Object, Update):
         from_user (:obj:`~pyrogram.types.User`):
             User that sent the join request.
 
-        date (``int``):
-            Date the request was sent in Unix time
+        date (:py:obj:`~datetime.datetime`):
+            Date the request was sent.
 
         bio (``str``, *optional*):
             Bio of the user.
@@ -51,7 +52,7 @@ def __init__(
         client: "pyrogram.Client" = None,
         chat: "types.Chat",
         from_user: "types.User",
-        date: int,
+        date: datetime,
         bio: str = None,
         invite_link: "types.ChatInviteLink" = None
     ):
@@ -75,7 +76,7 @@ def _parse(
         return ChatJoinRequest(
             chat=types.Chat._parse_chat(client, chats[chat_id]),
             from_user=types.User._parse(client, users[update.user_id]),
-            date=update.date,
+            date=utils.timestamp_to_datetime(update.date),
             bio=update.about,
             invite_link=types.ChatInviteLink._parse(client, update.invite, users),
             client=client
diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index dc00354f90..06f45b8d34 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.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 datetime import datetime
 from typing import Union, Dict
 
 import pyrogram
@@ -36,17 +37,17 @@ class ChatMember(Object):
         chat (:obj:`~pyrogram.types.Chat`, *optional*):
             Information about the chat (useful in case of banned channel senders).
 
-        joined_date (``int``, *optional*):
-            Date when the user joined, unix time.
+        joined_date (:py:obj:`~datetime.datetime`, *optional*):
+            Date when the user joined..
             Not available for the owner.
 
         custom_title (``str``, *optional*):
             A custom title that will be shown to all members instead of "Owner" or "Admin".
             Creator (owner) and administrators only. Can be None in case there's no custom title set.
 
-        until_date (``int``, *optional*):
+        until_date (:py:obj:`~datetime.datetime`, *optional*):
             Restricted and banned only.
-            Date when restrictions will be lifted for this user; unix time.
+            Date when restrictions will be lifted for this user.
 
         invited_by (:obj:`~pyrogram.types.User`, *optional*):
             Administrators and self member only. Information about the user who invited this member.
@@ -79,8 +80,8 @@ def __init__(
         user: "types.User" = None,
         chat: "types.Chat" = None,
         custom_title: str = None,
-        until_date: int = None,
-        joined_date: int = None,
+        until_date: datetime = None,
+        joined_date: datetime = None,
         invited_by: "types.User" = None,
         promoted_by: "types.User" = None,
         restricted_by: "types.User" = None,
@@ -109,15 +110,15 @@ def __init__(
     def _parse(
             client: "pyrogram.Client",
             member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
-            users: Dict[int, "raw.base.User"],
-            chats: Dict[int, "raw.base.Chat"]
+        users: Dict[int, "raw.base.User"],
+        chats: Dict[int, "raw.base.Chat"]
     ) -> "ChatMember":
         # Chat participants
         if isinstance(member, raw.types.ChatParticipant):
             return ChatMember(
                 status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
-                joined_date=member.date,
+                joined_date=utils.timestamp_to_datetime(member.date),
                 invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
@@ -125,7 +126,7 @@ def _parse(
             return ChatMember(
                 status=enums.ChatMemberStatus.ADMINISTRATOR,
                 user=types.User._parse(client, users[member.user_id]),
-                joined_date=member.date,
+                joined_date=utils.timestamp_to_datetime(member.date),
                 invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
@@ -141,14 +142,14 @@ def _parse(
             return ChatMember(
                 status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
-                joined_date=member.date,
+                joined_date=utils.timestamp_to_datetime(member.date),
                 client=client
             )
         elif isinstance(member, raw.types.ChannelParticipantAdmin):
             return ChatMember(
                 status=enums.ChatMemberStatus.ADMINISTRATOR,
                 user=types.User._parse(client, users[member.user_id]),
-                joined_date=member.date,
+                joined_date=utils.timestamp_to_datetime(member.date),
                 promoted_by=types.User._parse(client, users[member.promoted_by]),
                 invited_by=types.User._parse(client, users[member.inviter_id]),
                 custom_title=member.rank,
@@ -178,8 +179,8 @@ def _parse(
                 ),
                 user=user,
                 chat=chat,
-                until_date=member.banned_rights.until_date,
-                joined_date=member.date,
+                until_date=utils.timestamp_to_datetime(member.banned_rights.until_date),
+                joined_date=utils.timestamp_to_datetime(member.date),
                 is_member=not member.left,
                 restricted_by=types.User._parse(client, users[member.kicked_by]),
                 permissions=types.ChatPermissions._parse(member.banned_rights),
@@ -217,7 +218,7 @@ def _parse(
             return ChatMember(
                 status=enums.ChatMemberStatus.MEMBER,
                 user=types.User._parse(client, users[member.user_id]),
-                joined_date=member.date,
+                joined_date=utils.timestamp_to_datetime(member.date),
                 invited_by=types.User._parse(client, users[member.inviter_id]),
                 client=client
             )
diff --git a/pyrogram/types/user_and_chats/chat_member_updated.py b/pyrogram/types/user_and_chats/chat_member_updated.py
index 5fa7d84e6c..f8b6638db9 100644
--- a/pyrogram/types/user_and_chats/chat_member_updated.py
+++ b/pyrogram/types/user_and_chats/chat_member_updated.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Dict, Union
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, utils
 from pyrogram import types
 from ..object import Object
 from ..update import Update
@@ -35,8 +36,8 @@ class ChatMemberUpdated(Object, Update):
         from_user (:obj:`~pyrogram.types.User`):
             Performer of the action, which resulted in the change.
 
-        date (``int``):
-            Date the change was done in Unix time.
+        date (:py:obj:`~datetime.datetime`):
+            Date the change was done.
 
         old_chat_member (:obj:`~pyrogram.types.ChatMember`, *optional*):
             Previous information about the chat member.
@@ -54,7 +55,7 @@ def __init__(
         client: "pyrogram.Client" = None,
         chat: "types.Chat",
         from_user: "types.User",
-        date: int,
+        date: datetime,
         old_chat_member: "types.ChatMember",
         new_chat_member: "types.ChatMember",
         invite_link: "types.ChatInviteLink" = None,
@@ -93,7 +94,7 @@ def _parse(
         return ChatMemberUpdated(
             chat=types.Chat._parse_chat(client, chats[chat_id]),
             from_user=types.User._parse(client, users[update.actor_id]),
-            date=update.date,
+            date=utils.timestamp_to_datetime(update.date),
             old_chat_member=old_chat_member,
             new_chat_member=new_chat_member,
             invite_link=invite_link,
diff --git a/pyrogram/types/user_and_chats/invite_link_importer.py b/pyrogram/types/user_and_chats/invite_link_importer.py
index db8569f558..34e5f397f4 100644
--- a/pyrogram/types/user_and_chats/invite_link_importer.py
+++ b/pyrogram/types/user_and_chats/invite_link_importer.py
@@ -16,7 +16,9 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram import raw
+from datetime import datetime
+
+from pyrogram import raw, utils
 from pyrogram import types
 from ..object import Object
 
@@ -25,14 +27,18 @@ class InviteLinkImporter(Object):
     """The date and user of when someone has joined with an invite link.
 
     Parameters:
-        date (``int``):
-            The unix time of when this user used the given link
+        date (:py:obj:`~datetime.datetime`):
+            The time of when this user used the given link
 
         user (:obj:`~pyrogram.types.User`):
             The user that has used the given invite link
     """
 
-    def __init__(self, *, date, user):
+    def __init__(
+        self, *,
+        date: datetime,
+        user: "types.User"
+    ):
         super().__init__(None)
 
         self.date = date
@@ -47,7 +53,7 @@ def _parse(client, invite_importers: "raw.types.messages.ChatInviteImporters"):
         for j in invite_importers.importers:
             importers.append(
                 InviteLinkImporter(
-                    date=j.date,
+                    date=utils.timestamp_to_datetime(j.date),
                     user=types.User._parse(client=None, user=d[j.user_id])
                 )
             )
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index f4678a3541..2ec09fb583 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -17,10 +17,11 @@
 #  along with Pyrogram.  If not, see .
 
 import html
+from datetime import datetime
 from typing import List, Optional
 
 import pyrogram
-from pyrogram import enums
+from pyrogram import enums, utils
 from pyrogram import raw
 from pyrogram import types
 from ..object import Object
@@ -103,13 +104,13 @@ class User(Object, Update):
             User's or bot's last name.
 
         status (:obj:`~pyrogram.enums.UserStatus`, *optional*):
-            User's last seen & online status. *None*, for bots.
+            User's last seen & online status. ``None``, for bots.
 
-        last_online_date (``int``, *optional*):
-            Last online date of a user, unix time. Only available in case status is "*offline*".
+        last_online_date (:py:obj:`~datetime.datetime`, *optional*):
+            Last online date of a user. Only available in case status is :obj:`~pyrogram.enums.UserStatus.OFFLINE`.
 
-        next_offline_date (``int``, *optional*):
-            Date when a user will automatically go offline, unix time. Only available in case status is "*online*".
+        next_offline_date (:py:obj:`~datetime.datetime`, *optional*):
+            Date when a user will automatically go offline. Only available in case status is :obj:`~pyrogram.enums.UserStatus.ONLINE`.
 
         username (``str``, *optional*):
             User's or bot's username.
@@ -158,8 +159,8 @@ def __init__(
         first_name: str = None,
         last_name: str = None,
         status: str = None,
-        last_online_date: int = None,
-        next_offline_date: int = None,
+        last_online_date: datetime = None,
+        next_offline_date: datetime = None,
         username: str = None,
         language_code: str = None,
         dc_id: int = None,
@@ -247,10 +248,10 @@ def _parse_status(user_status: "raw.base.UserStatus", is_bot: bool = False):
             status = None
 
         if status == enums.UserStatus.ONLINE:
-            next_offline_date = date
+            next_offline_date = utils.timestamp_to_datetime(date)
 
         if status == enums.UserStatus.OFFLINE:
-            last_online_date = date
+            last_online_date = utils.timestamp_to_datetime(date)
 
         return {
             "status": status,
diff --git a/pyrogram/types/user_and_chats/voice_chat_scheduled.py b/pyrogram/types/user_and_chats/voice_chat_scheduled.py
index 82d2125e7f..0bb00bc509 100644
--- a/pyrogram/types/user_and_chats/voice_chat_scheduled.py
+++ b/pyrogram/types/user_and_chats/voice_chat_scheduled.py
@@ -16,7 +16,9 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram import raw
+from datetime import datetime
+
+from pyrogram import raw, utils
 from ..object import Object
 
 
@@ -24,13 +26,13 @@ class VoiceChatScheduled(Object):
     """A service message about a voice chat scheduled in the chat.
 
     Parameters:
-        start_date (``int``):
-            Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator.
+        start_date (:py:obj:`~datetime.datetime`):
+            Point in time when the voice chat is supposed to be started by a chat administrator.
     """
 
     def __init__(
         self, *,
-        start_date: int
+        start_date: datetime
     ):
         super().__init__()
 
@@ -38,4 +40,4 @@ def __init__(
 
     @staticmethod
     def _parse(action: "raw.types.MessageActionGroupCallScheduled") -> "VoiceChatScheduled":
-        return VoiceChatScheduled(start_date=action.schedule_date)
+        return VoiceChatScheduled(start_date=utils.timestamp_to_datetime(action.schedule_date))
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index 6a0c8bac91..94a549467f 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -23,11 +23,12 @@
 import os
 import struct
 from concurrent.futures.thread import ThreadPoolExecutor
+from datetime import datetime
 from getpass import getpass
 from typing import Union, List, Dict, Optional
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, PHOTO_TYPES, DOCUMENT_TYPES
 
@@ -294,7 +295,7 @@ def compute_password_check(r: raw.types.account.Password, password: str) -> raw.
 async def parse_text_entities(
     client: "pyrogram.Client",
     text: str,
-    parse_mode: str,
+    parse_mode: enums.ParseMode,
     entities: List["types.MessageEntity"]
 ) -> Dict[str, raw.base.MessageEntity]:
     if entities:
@@ -310,3 +311,11 @@ async def parse_text_entities(
         "message": text,
         "entities": entities
     }
+
+
+def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]:
+    return datetime.fromtimestamp(ts) if ts else None
+
+
+def datetime_to_timestamp(dt: Optional[datetime]) -> Optional[int]:
+    return int(dt.timestamp()) if dt else None

From 274650cda9741fb9da6ae41098a9611e64567210 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 140/539] Rename Message.message_id to Message.id

---
 pyrogram/methods/chats/iter_dialogs.py        |   2 +-
 pyrogram/methods/messages/iter_history.py     |   2 +-
 pyrogram/methods/messages/search_global.py    |   2 +-
 pyrogram/methods/messages/send_message.py     |   2 +-
 .../bots_and_keyboards/callback_query.py      |   6 +-
 pyrogram/types/messages_and_media/message.py  | 100 +++++++++---------
 pyrogram/utils.py                             |   8 +-
 7 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py
index 2584d98d63..4553e3d47e 100644
--- a/pyrogram/methods/chats/iter_dialogs.py
+++ b/pyrogram/methods/chats/iter_dialogs.py
@@ -93,7 +93,7 @@ async def iter_dialogs(
 
             last = dialogs[-1]
 
-            offset_id = last.top_message.message_id
+            offset_id = last.top_message.id
             offset_date = last.top_message.date
             offset_peer = await self.resolve_peer(last.chat.id)
 
diff --git a/pyrogram/methods/messages/iter_history.py b/pyrogram/methods/messages/iter_history.py
index b9dd20098c..c5eda28871 100644
--- a/pyrogram/methods/messages/iter_history.py
+++ b/pyrogram/methods/messages/iter_history.py
@@ -89,7 +89,7 @@ async def iter_history(
             if not messages:
                 return
 
-            offset_id = messages[-1].message_id + (1 if reverse else 0)
+            offset_id = messages[-1].id + (1 if reverse else 0)
 
             for message in messages:
                 yield message
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index 2c22b26f79..6dff7bf0af 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -102,7 +102,7 @@ async def search_global(
 
             offset_date = last.date
             offset_peer = await self.resolve_peer(last.chat.id)
-            offset_id = last.message_id
+            offset_id = last.id
 
             for message in messages:
                 yield message
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index a094ba9214..34063625dd 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -149,7 +149,7 @@ async def send_message(
             )
 
             return types.Message(
-                message_id=r.id,
+                id=r.id,
                 chat=types.Chat(
                     id=peer_id,
                     type=enums.ChatType.PRIVATE,
diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py
index e5db872359..436b6076ea 100644
--- a/pyrogram/types/bots_and_keyboards/callback_query.py
+++ b/pyrogram/types/bots_and_keyboards/callback_query.py
@@ -203,7 +203,7 @@ async def edit_message_text(
         if self.inline_message_id is None:
             return await self._client.edit_message_text(
                 chat_id=self.message.chat.id,
-                message_id=self.message.message_id,
+                message_id=self.message.id,
                 text=text,
                 parse_mode=parse_mode,
                 disable_web_page_preview=disable_web_page_preview,
@@ -274,7 +274,7 @@ async def edit_message_media(
         if self.inline_message_id is None:
             return await self._client.edit_message_media(
                 chat_id=self.message.chat.id,
-                message_id=self.message.message_id,
+                message_id=self.message.id,
                 media=media,
                 reply_markup=reply_markup
             )
@@ -307,7 +307,7 @@ async def edit_message_reply_markup(
         if self.inline_message_id is None:
             return await self._client.edit_message_reply_markup(
                 chat_id=self.message.chat.id,
-                message_id=self.message.message_id,
+                message_id=self.message.id,
                 reply_markup=reply_markup
             )
         else:
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 86c340aea6..56ffd691bd 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -60,7 +60,7 @@ class Message(Object, Update):
     """A message.
 
     Parameters:
-        message_id (``int``):
+        id (``int``):
             Unique message identifier inside this chat.
 
         from_user (:obj:`~pyrogram.types.User`, *optional*):
@@ -302,7 +302,7 @@ def __init__(
         self,
         *,
         client: "pyrogram.Client" = None,
-        message_id: int,
+        id: int,
         from_user: "types.User" = None,
         sender_chat: "types.Chat" = None,
         date: datetime = None,
@@ -376,7 +376,7 @@ def __init__(
     ):
         super().__init__(client)
 
-        self.message_id = message_id
+        self.id = id
         self.from_user = from_user
         self.sender_chat = sender_chat
         self.date = date
@@ -453,7 +453,7 @@ async def _parse(
         replies: int = 1
     ):
         if isinstance(message, raw.types.MessageEmpty):
-            return Message(message_id=message.id, empty=True, client=client)
+            return Message(id=message.id, empty=True, client=client)
 
         from_id = utils.get_raw_peer_id(message.from_id)
         peer_id = utils.get_raw_peer_id(message.peer_id)
@@ -542,7 +542,7 @@ async def _parse(
             sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
 
             parsed_message = Message(
-                message_id=message.id,
+                id=message.id,
                 date=utils.timestamp_to_datetime(message.date),
                 chat=types.Chat._parse(client, message, users, chats, is_chat=True),
                 from_user=from_user,
@@ -739,7 +739,7 @@ async def _parse(
                          for r in message.reactions.results] if message.reactions else None
 
             parsed_message = Message(
-                message_id=message.id,
+                id=message.id,
                 date=utils.timestamp_to_datetime(message.date),
                 chat=types.Chat._parse(client, message, users, chats, is_chat=True),
                 from_user=from_user,
@@ -823,9 +823,9 @@ def link(self) -> str:
             self.chat.type in (enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)
             and self.chat.username
         ):
-            return f"https://t.me/{self.chat.username}/{self.message_id}"
+            return f"https://t.me/{self.chat.username}/{self.id}"
         else:
-            return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.message_id}"
+            return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.id}"
 
     async def get_media_group(self) -> List["types.Message"]:
         """Bound method *get_media_group* of :obj:`~pyrogram.types.Message`.
@@ -836,7 +836,7 @@ async def get_media_group(self) -> List["types.Message"]:
 
             client.get_media_group(
                 chat_id=message.chat.id,
-                message_id=message.message_id
+                message_id=message.id
             )
             
         Example:
@@ -853,7 +853,7 @@ async def get_media_group(self) -> List["types.Message"]:
 
         return await self._client.get_media_group(
             chat_id=self.chat.id,
-            message_id=self.message_id
+            message_id=self.id
         )
 
     async def reply_text(
@@ -880,7 +880,7 @@ async def reply_text(
             client.send_message(
                 chat_id=message.chat.id,
                 text="hello",
-                reply_to_message_id=message.message_id
+                reply_to_message_id=message.id
             )
 
         Example:
@@ -934,7 +934,7 @@ async def reply_text(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_message(
             chat_id=self.chat.id,
@@ -1071,7 +1071,7 @@ async def reply_animation(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_animation(
             chat_id=self.chat.id,
@@ -1210,7 +1210,7 @@ async def reply_audio(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_audio(
             chat_id=self.chat.id,
@@ -1302,7 +1302,7 @@ async def reply_cached_media(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_cached_media(
             chat_id=self.chat.id,
@@ -1425,7 +1425,7 @@ async def reply_contact(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_contact(
             chat_id=self.chat.id,
@@ -1561,7 +1561,7 @@ async def reply_document(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_document(
             chat_id=self.chat.id,
@@ -1639,7 +1639,7 @@ async def reply_game(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_game(
             chat_id=self.chat.id,
@@ -1703,7 +1703,7 @@ async def reply_inline_bot_result(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_inline_bot_result(
             chat_id=self.chat.id,
@@ -1777,7 +1777,7 @@ async def reply_location(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_location(
             chat_id=self.chat.id,
@@ -1840,7 +1840,7 @@ async def reply_media_group(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_media_group(
             chat_id=self.chat.id,
@@ -1956,7 +1956,7 @@ async def reply_photo(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_photo(
             chat_id=self.chat.id,
@@ -2060,7 +2060,7 @@ async def reply_poll(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_poll(
             chat_id=self.chat.id,
@@ -2164,7 +2164,7 @@ async def reply_sticker(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_sticker(
             chat_id=self.chat.id,
@@ -2259,7 +2259,7 @@ async def reply_venue(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_venue(
             chat_id=self.chat.id,
@@ -2404,7 +2404,7 @@ async def reply_video(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_video(
             chat_id=self.chat.id,
@@ -2528,7 +2528,7 @@ async def reply_video_note(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_video_note(
             chat_id=self.chat.id,
@@ -2648,7 +2648,7 @@ async def reply_voice(
             quote = self.chat.type != "private"
 
         if reply_to_message_id is None and quote:
-            reply_to_message_id = self.message_id
+            reply_to_message_id = self.id
 
         return await self._client.send_voice(
             chat_id=self.chat.id,
@@ -2682,7 +2682,7 @@ async def edit_text(
 
             client.edit_message_text(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 text="hello"
             )
 
@@ -2716,7 +2716,7 @@ async def edit_text(
         """
         return await self._client.edit_message_text(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             text=text,
             parse_mode=parse_mode,
             entities=entities,
@@ -2741,7 +2741,7 @@ async def edit_caption(
 
             client.edit_message_caption(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 caption="hello"
             )
 
@@ -2772,7 +2772,7 @@ async def edit_caption(
         """
         return await self._client.edit_message_caption(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             caption=caption,
             parse_mode=parse_mode,
             caption_entities=caption_entities,
@@ -2792,7 +2792,7 @@ async def edit_media(
 
             client.edit_message_media(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 media=media
             )
 
@@ -2816,7 +2816,7 @@ async def edit_media(
         """
         return await self._client.edit_message_media(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             media=media,
             reply_markup=reply_markup
         )
@@ -2830,7 +2830,7 @@ async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = N
 
             client.edit_message_reply_markup(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 reply_markup=inline_reply_markup
             )
 
@@ -2852,7 +2852,7 @@ async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = N
         """
         return await self._client.edit_message_reply_markup(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             reply_markup=reply_markup
         )
 
@@ -2871,7 +2871,7 @@ async def forward(
             client.forward_messages(
                 chat_id=chat_id,
                 from_chat_id=message.chat.id,
-                message_ids=message.message_id
+                message_ids=message.id
             )
 
         Example:
@@ -2901,7 +2901,7 @@ async def forward(
         return await self._client.forward_messages(
             chat_id=chat_id,
             from_chat_id=self.chat.id,
-            message_ids=self.message_id,
+            message_ids=self.id,
             disable_notification=disable_notification,
             schedule_date=schedule_date
         )
@@ -2932,7 +2932,7 @@ async def copy(
             client.copy_message(
                 chat_id=chat_id,
                 from_chat_id=message.chat.id,
-                message_id=message.message_id
+                message_id=message.id
             )
 
         Example:
@@ -2985,10 +2985,10 @@ async def copy(
         """
         if self.service:
             log.warning(f"Service messages cannot be copied. "
-                        f"chat_id: {self.chat.id}, message_id: {self.message_id}")
+                        f"chat_id: {self.chat.id}, message_id: {self.id}")
         elif self.game and not await self._client.storage.is_bot():
             log.warning(f"Users cannot send messages with Game media type. "
-                        f"chat_id: {self.chat.id}, message_id: {self.message_id}")
+                        f"chat_id: {self.chat.id}, message_id: {self.id}")
         elif self.empty:
             log.warning(f"Empty messages cannot be copied. ")
         elif self.text:
@@ -3102,7 +3102,7 @@ async def delete(self, revoke: bool = True):
 
             client.delete_messages(
                 chat_id=chat_id,
-                message_ids=message.message_id
+                message_ids=message.id
             )
 
         Example:
@@ -3125,7 +3125,7 @@ async def delete(self, revoke: bool = True):
         """
         return await self._client.delete_messages(
             chat_id=self.chat.id,
-            message_ids=self.message_id,
+            message_ids=self.id,
             revoke=revoke
         )
 
@@ -3140,7 +3140,7 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None,
 
             client.request_callback_answer(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 callback_data=message.reply_markup[i][j].callback_data
             )
 
@@ -3235,7 +3235,7 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None,
             if button.callback_data:
                 return await self._client.request_callback_answer(
                     chat_id=self.chat.id,
-                    message_id=self.message_id,
+                    message_id=self.id,
                     callback_data=button.callback_data,
                     timeout=timeout
                 )
@@ -3314,7 +3314,7 @@ async def retract_vote(
 
         return await self._client.retract_vote(
             chat_id=self.chat.id,
-            message_id=self.message_id
+            message_id=self.id
         )
 
     async def download(
@@ -3397,7 +3397,7 @@ async def vote(
 
             client.vote_poll(
                 chat_id=message.chat.id,
-                message_id=message.message_id,
+                message_id=message.id,
                 option=1
             )
 
@@ -3419,7 +3419,7 @@ async def vote(
 
         return await self._client.vote_poll(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             options=option
         )
 
@@ -3457,7 +3457,7 @@ async def pin(self, disable_notification: bool = False, both_sides: bool = False
         """
         return await self._client.pin_chat_message(
             chat_id=self.chat.id,
-            message_id=self.message_id,
+            message_id=self.id,
             disable_notification=disable_notification,
             both_sides=both_sides
         )
@@ -3487,5 +3487,5 @@ async def unpin(self) -> bool:
         """
         return await self._client.unpin_chat_message(
             chat_id=self.chat.id,
-            message_id=self.message_id
+            message_id=self.id
         )
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index 94a549467f..60f6ca9d8a 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -115,10 +115,10 @@ async def parse_messages(client, messages: "raw.types.messages.Messages", replie
             )
 
             for message in parsed_messages:
-                reply_id = messages_with_replies.get(message.message_id, None)
+                reply_id = messages_with_replies.get(message.id, None)
 
                 for reply in reply_messages:
-                    if reply.message_id == reply_id:
+                    if reply.id == reply_id:
                         message.reply_to_message = reply
 
     return types.List(parsed_messages)
@@ -133,10 +133,10 @@ def parse_deleted_messages(client, update) -> List["types.Message"]:
     for message in messages:
         parsed_messages.append(
             types.Message(
-                message_id=message,
+                id=message,
                 chat=types.Chat(
                     id=get_channel_id(channel_id),
-                    type="channel",
+                    type=enums.ChatType.CHANNEL,
                     client=client
                 ) if channel_id is not None else None,
                 client=client

From 4ebf5cf7e970187aded2f981de5ab4e0c522e144 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 141/539] Remove ability to access attributes via bracket
 notation

---
 pyrogram/raw/core/tl_object.py | 6 ------
 pyrogram/types/object.py       | 6 ------
 2 files changed, 12 deletions(-)

diff --git a/pyrogram/raw/core/tl_object.py b/pyrogram/raw/core/tl_object.py
index 7cb75b0eb5..ff67566ea8 100644
--- a/pyrogram/raw/core/tl_object.py
+++ b/pyrogram/raw/core/tl_object.py
@@ -78,11 +78,5 @@ def __eq__(self, other: Any) -> bool:
     def __len__(self) -> int:
         return len(self.write())
 
-    def __getitem__(self, item: Any) -> Any:
-        return getattr(self, item)
-
-    def __setitem__(self, key: Any, value: Any) -> Any:
-        setattr(self, key, value)
-
     def __call__(self, *args: Any, **kwargs: Any) -> Any:
         pass
diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py
index a3641b1614..601bcd6e6f 100644
--- a/pyrogram/types/object.py
+++ b/pyrogram/types/object.py
@@ -94,12 +94,6 @@ def __eq__(self, other: "Object") -> bool:
 
         return True
 
-    def __getitem__(self, item):
-        return getattr(self, item)
-
-    def __setitem__(self, key, value):
-        setattr(self, key, value)
-
     def __getstate__(self):
         new_dict = self.__dict__.copy()
         new_dict.pop("_client", None)

From 32624ef5e6954804db88fc1723654bc27bc5a665 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 142/539] Improve type hints

---
 compiler/api/template/combinator.txt          |   2 +-
 pyrogram/client.py                            |  58 ++++-
 pyrogram/filters.py                           |   2 +-
 pyrogram/handlers/callback_query_handler.py   |   6 +-
 .../handlers/chat_join_request_handler.py     |   6 +-
 .../handlers/chat_member_updated_handler.py   |   6 +-
 .../handlers/chosen_inline_result_handler.py  |   6 +-
 pyrogram/handlers/deleted_messages_handler.py |   2 +-
 pyrogram/handlers/disconnect_handler.py       |   6 +-
 pyrogram/handlers/inline_query_handler.py     |   6 +-
 pyrogram/handlers/message_handler.py          |   6 +-
 pyrogram/handlers/poll_handler.py             |   6 +-
 pyrogram/handlers/raw_update_handler.py       |   6 +-
 pyrogram/handlers/user_status_handler.py      |   6 +-
 pyrogram/methods/advanced/resolve_peer.py     |   6 +-
 pyrogram/methods/advanced/save_file.py        |  12 +-
 pyrogram/methods/advanced/send.py             |   6 +-
 .../methods/auth/accept_terms_of_service.py   |   9 +-
 pyrogram/methods/auth/check_password.py       |   9 +-
 pyrogram/methods/auth/connect.py              |   8 +-
 pyrogram/methods/auth/disconnect.py           |   8 +-
 pyrogram/methods/auth/get_password_hint.py    |   8 +-
 pyrogram/methods/auth/initialize.py           |   8 +-
 pyrogram/methods/auth/log_out.py              |   8 +-
 pyrogram/methods/auth/recover_password.py     |   9 +-
 pyrogram/methods/auth/resend_code.py          |  10 +-
 pyrogram/methods/auth/send_code.py            |   9 +-
 pyrogram/methods/auth/send_recovery_code.py   |   8 +-
 pyrogram/methods/auth/sign_in.py              |   6 +-
 pyrogram/methods/auth/sign_in_bot.py          |   9 +-
 pyrogram/methods/auth/sign_up.py              |   6 +-
 pyrogram/methods/auth/terminate.py            |   8 +-
 .../methods/bots/answer_callback_query.py     |   6 +-
 pyrogram/methods/bots/answer_inline_query.py  |   6 +-
 pyrogram/methods/bots/get_game_high_scores.py |   6 +-
 .../methods/bots/get_inline_bot_results.py    |   6 +-
 .../methods/bots/request_callback_answer.py   |   6 +-
 pyrogram/methods/bots/send_game.py            |   6 +-
 .../methods/bots/send_inline_bot_result.py    |   6 +-
 pyrogram/methods/bots/set_bot_commands.py     |   7 +-
 pyrogram/methods/bots/set_game_score.py       |   6 +-
 pyrogram/methods/chats/add_chat_members.py    |   6 +-
 pyrogram/methods/chats/archive_chats.py       |   6 +-
 pyrogram/methods/chats/ban_chat_member.py     |   6 +-
 pyrogram/methods/chats/create_channel.py      |   7 +-
 pyrogram/methods/chats/create_group.py        |   6 +-
 pyrogram/methods/chats/create_supergroup.py   |   7 +-
 pyrogram/methods/chats/delete_channel.py      |   9 +-
 pyrogram/methods/chats/delete_chat_photo.py   |   6 +-
 pyrogram/methods/chats/delete_supergroup.py   |   9 +-
 pyrogram/methods/chats/delete_user_history.py |   6 +-
 pyrogram/methods/chats/get_chat.py            |   6 +-
 pyrogram/methods/chats/get_chat_event_log.py  |   6 +-
 pyrogram/methods/chats/get_chat_member.py     |   6 +-
 pyrogram/methods/chats/get_chat_members.py    |  18 +-
 .../methods/chats/get_chat_members_count.py   |   6 +-
 .../methods/chats/get_chat_online_count.py    |   9 +-
 pyrogram/methods/chats/get_dialogs.py         |   6 +-
 pyrogram/methods/chats/get_dialogs_count.py   |   9 +-
 pyrogram/methods/chats/get_nearby_chats.py    |   6 +-
 pyrogram/methods/chats/get_send_as_chats.py   |   6 +-
 pyrogram/methods/chats/iter_chat_members.py   |   6 +-
 pyrogram/methods/chats/iter_dialogs.py        |   6 +-
 pyrogram/methods/chats/join_chat.py           |   6 +-
 pyrogram/methods/chats/leave_chat.py          |   6 +-
 pyrogram/methods/chats/mark_chat_unread.py    |   6 +-
 pyrogram/methods/chats/pin_chat_message.py    |   6 +-
 pyrogram/methods/chats/promote_chat_member.py |   6 +-
 .../methods/chats/restrict_chat_member.py     |   6 +-
 .../methods/chats/set_administrator_title.py  |   6 +-
 .../methods/chats/set_chat_description.py     |   6 +-
 .../methods/chats/set_chat_permissions.py     |   6 +-
 pyrogram/methods/chats/set_chat_photo.py      |   6 +-
 .../chats/set_chat_protected_content.py       |   6 +-
 pyrogram/methods/chats/set_chat_title.py      |   6 +-
 pyrogram/methods/chats/set_chat_username.py   |   6 +-
 pyrogram/methods/chats/set_send_as_chat.py    |   6 +-
 pyrogram/methods/chats/set_slow_mode.py       |   6 +-
 pyrogram/methods/chats/unarchive_chats.py     |   6 +-
 pyrogram/methods/chats/unban_chat_member.py   |   6 +-
 .../methods/chats/unpin_all_chat_messages.py  |   6 +-
 pyrogram/methods/chats/unpin_chat_message.py  |   6 +-
 pyrogram/methods/contacts/add_contact.py      |   6 +-
 pyrogram/methods/contacts/delete_contacts.py  |   6 +-
 pyrogram/methods/contacts/get_contacts.py     |   8 +-
 .../methods/contacts/get_contacts_count.py    |   8 +-
 pyrogram/methods/contacts/import_contacts.py  |   6 +-
 .../methods/decorators/on_callback_query.py   |   5 +-
 .../decorators/on_chat_join_request.py        |   5 +-
 .../decorators/on_chat_member_updated.py      |   5 +-
 .../decorators/on_chosen_inline_result.py     |   5 +-
 .../methods/decorators/on_deleted_messages.py |   5 +-
 pyrogram/methods/decorators/on_disconnect.py  |   5 +-
 .../methods/decorators/on_inline_query.py     |   5 +-
 pyrogram/methods/decorators/on_message.py     |   5 +-
 pyrogram/methods/decorators/on_poll.py        |   5 +-
 pyrogram/methods/decorators/on_raw_update.py  |   5 +-
 pyrogram/methods/decorators/on_user_status.py |   5 +-
 .../invite_links/approve_chat_join_request.py |   6 +-
 .../invite_links/create_chat_invite_link.py   |   6 +-
 .../invite_links/decline_chat_join_request.py |   6 +-
 .../delete_chat_admin_invite_links.py         |   6 +-
 .../invite_links/delete_chat_invite_link.py   |   6 +-
 .../invite_links/edit_chat_invite_link.py     |   6 +-
 .../invite_links/export_chat_invite_link.py   |   6 +-
 .../get_chat_admin_invite_links.py            |   6 +-
 .../get_chat_admin_invite_links_count.py      |   6 +-
 .../get_chat_admins_with_invite_links.py      |   6 +-
 .../invite_links/get_chat_invite_link.py      |   6 +-
 .../get_chat_invite_link_members.py           |   6 +-
 .../get_chat_invite_link_members_count.py     |   6 +-
 .../invite_links/revoke_chat_invite_link.py   |   6 +-
 pyrogram/methods/messages/copy_media_group.py |   6 +-
 pyrogram/methods/messages/copy_message.py     |   6 +-
 pyrogram/methods/messages/delete_messages.py  |   6 +-
 pyrogram/methods/messages/download_media.py   |  12 +-
 .../methods/messages/edit_inline_caption.py   |   6 +-
 .../methods/messages/edit_inline_media.py     |   6 +-
 .../messages/edit_inline_reply_markup.py      |   6 +-
 pyrogram/methods/messages/edit_inline_text.py |   6 +-
 .../methods/messages/edit_message_caption.py  |   6 +-
 .../methods/messages/edit_message_media.py    |   6 +-
 .../messages/edit_message_reply_markup.py     |   6 +-
 .../methods/messages/edit_message_text.py     |   6 +-
 pyrogram/methods/messages/forward_messages.py |   6 +-
 .../messages/get_discussion_message.py        |   6 +-
 pyrogram/methods/messages/get_history.py      |   6 +-
 .../methods/messages/get_history_count.py     |   6 +-
 pyrogram/methods/messages/get_media_group.py  |   6 +-
 pyrogram/methods/messages/get_messages.py     |   6 +-
 pyrogram/methods/messages/iter_history.py     |   6 +-
 pyrogram/methods/messages/read_history.py     |   6 +-
 pyrogram/methods/messages/retract_vote.py     |   6 +-
 pyrogram/methods/messages/search_global.py    |   6 +-
 .../methods/messages/search_global_count.py   |   6 +-
 pyrogram/methods/messages/search_messages.py  |   8 +-
 .../methods/messages/search_messages_count.py |   6 +-
 pyrogram/methods/messages/send_animation.py   |  12 +-
 pyrogram/methods/messages/send_audio.py       |  14 +-
 .../methods/messages/send_cached_media.py     |   6 +-
 pyrogram/methods/messages/send_chat_action.py |   5 +-
 pyrogram/methods/messages/send_contact.py     |   8 +-
 pyrogram/methods/messages/send_dice.py        |  10 +-
 pyrogram/methods/messages/send_document.py    |  12 +-
 pyrogram/methods/messages/send_location.py    |   8 +-
 pyrogram/methods/messages/send_media_group.py |   6 +-
 pyrogram/methods/messages/send_message.py     |   9 +-
 pyrogram/methods/messages/send_photo.py       |  11 +-
 pyrogram/methods/messages/send_poll.py        |   8 +-
 pyrogram/methods/messages/send_reaction.py    |   6 +-
 pyrogram/methods/messages/send_sticker.py     |  12 +-
 pyrogram/methods/messages/send_venue.py       |   8 +-
 pyrogram/methods/messages/send_video.py       |  12 +-
 pyrogram/methods/messages/send_video_note.py  |  12 +-
 pyrogram/methods/messages/send_voice.py       |  12 +-
 pyrogram/methods/messages/stop_poll.py        |   6 +-
 pyrogram/methods/messages/vote_poll.py        |   6 +-
 .../methods/password/change_cloud_password.py |   6 +-
 .../methods/password/enable_cloud_password.py |   6 +-
 .../methods/password/remove_cloud_password.py |   6 +-
 pyrogram/methods/users/block_user.py          |   6 +-
 .../methods/users/delete_profile_photos.py    |   6 +-
 pyrogram/methods/users/get_common_chats.py    |   9 +-
 pyrogram/methods/users/get_me.py              |   8 +-
 pyrogram/methods/users/get_profile_photos.py  |   6 +-
 .../methods/users/get_profile_photos_count.py |   9 +-
 pyrogram/methods/users/get_users.py           |   6 +-
 pyrogram/methods/users/iter_profile_photos.py |   6 +-
 pyrogram/methods/users/set_profile_photo.py   |   6 +-
 pyrogram/methods/users/set_username.py        |   6 +-
 pyrogram/methods/users/unblock_user.py        |   6 +-
 pyrogram/methods/users/update_profile.py      |   6 +-
 pyrogram/methods/utilities/add_handler.py     |  10 +-
 .../utilities/export_session_string.py        |   8 +-
 pyrogram/methods/utilities/remove_handler.py  |  10 +-
 pyrogram/methods/utilities/restart.py         |   9 +-
 pyrogram/methods/utilities/run.py             |   9 +-
 pyrogram/methods/utilities/start.py           |   8 +-
 pyrogram/methods/utilities/stop.py            |   9 +-
 .../methods/utilities/stop_transmission.py    |   3 +-
 pyrogram/scaffold.py                          | 201 ------------------
 .../inline_mode/inline_query_result_audio.py  |   2 +-
 pyrogram/types/messages_and_media/__init__.py |   2 +-
 pyrogram/types/messages_and_media/message.py  |  40 ++--
 .../types/messages_and_media/video_note.py    |   2 +-
 pyrogram/types/object.py                      |   7 +-
 pyrogram/types/user_and_chats/chat_event.py   |   8 +-
 pyrogram/types/user_and_chats/chat_member.py  |   4 +-
 pyrogram/utils.py                             |   2 +-
 189 files changed, 729 insertions(+), 815 deletions(-)
 delete mode 100644 pyrogram/scaffold.py

diff --git a/compiler/api/template/combinator.txt b/compiler/api/template/combinator.txt
index 7c02a1a8e5..fa7a76976b 100644
--- a/compiler/api/template/combinator.txt
+++ b/compiler/api/template/combinator.txt
@@ -27,7 +27,7 @@ class {name}(TLObject):  # type: ignore
         {read_types}
         return {name}({return_arguments})
 
-    def write(self) -> bytes:
+    def write(self, *args) -> bytes:
         b = BytesIO()
         b.write(Int(self.ID, False))
 
diff --git a/pyrogram/client.py b/pyrogram/client.py
index cf3b8ec3b9..cfef3a8d94 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -21,15 +21,19 @@
 import inspect
 import logging
 import os
+import platform
 import re
 import shutil
+import sys
 import tempfile
 from concurrent.futures.thread import ThreadPoolExecutor
 from configparser import ConfigParser
 from hashlib import sha256
 from importlib import import_module
+from io import StringIO
+from mimetypes import MimeTypes
 from pathlib import Path
-from typing import Union, List, Optional
+from typing import Union, List, Optional, Callable
 
 import pyrogram
 from pyrogram import __version__, __license__
@@ -51,12 +55,14 @@
 from pyrogram.utils import ainput
 from .dispatcher import Dispatcher
 from .file_id import FileId, FileType, ThumbnailSource
-from .scaffold import Scaffold
+from .mime_types import mime_types
+from .parser import Parser
+from .session.internals import MsgId
 
 log = logging.getLogger(__name__)
 
 
-class Client(Methods, Scaffold):
+class Client(Methods):
     """Pyrogram Client, the main means for interacting with Telegram.
 
     Parameters:
@@ -177,10 +183,26 @@ class Client(Methods, Scaffold):
             terminal environments.
     """
 
+    APP_VERSION = f"Pyrogram {__version__}"
+    DEVICE_MODEL = f"{platform.python_implementation()} {platform.python_version()}"
+    SYSTEM_VERSION = f"{platform.system()} {platform.release()}"
+
+    LANG_CODE = "en"
+
+    PARENT_DIR = Path(sys.argv[0]).parent
+
+    INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:joinchat/|\+))([\w-]+)$")
+    WORKERS = min(32, (os.cpu_count() or 0) + 4)  # os.cpu_count() can be None
+    WORKDIR = PARENT_DIR
+    CONFIG_FILE = PARENT_DIR / "config.ini"
+
+    mimetypes = MimeTypes()
+    mimetypes.readfp(StringIO(mime_types))
+
     def __init__(
         self,
         session_name: Union[str, Storage],
-        api_id: Union[int, str] = None,
+        api_id: int = None,
         api_hash: str = None,
         app_version: str = None,
         device_model: str = None,
@@ -194,9 +216,9 @@ def __init__(
         phone_code: str = None,
         password: str = None,
         force_sms: bool = False,
-        workers: int = Scaffold.WORKERS,
-        workdir: str = Scaffold.WORKDIR,
-        config_file: str = Scaffold.CONFIG_FILE,
+        workers: int = WORKERS,
+        workdir: str = WORKDIR,
+        config_file: str = CONFIG_FILE,
         plugins: dict = None,
         parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
         no_updates: bool = None,
@@ -207,7 +229,7 @@ def __init__(
         super().__init__()
 
         self.session_name = session_name
-        self.api_id = int(api_id) if api_id else None
+        self.api_id = api_id
         self.api_hash = api_hash
         self.app_version = app_version
         self.device_model = device_model
@@ -246,6 +268,24 @@ def __init__(
             raise ValueError("Unknown storage engine")
 
         self.dispatcher = Dispatcher(self)
+
+        self.rnd_id = MsgId
+
+        self.parser = Parser(self)
+        self.parse_mode = enums.ParseMode.DEFAULT
+
+        self.session = None
+
+        self.media_sessions = {}
+        self.media_sessions_lock = asyncio.Lock()
+
+        self.is_connected = None
+        self.is_initialized = None
+
+        self.takeout_id = None
+
+        self.disconnect_handler = None
+
         self.loop = asyncio.get_event_loop()
 
     def __enter__(self):
@@ -790,7 +830,7 @@ async def get_file(
         self,
         file_id: FileId,
         file_size: int,
-        progress: callable,
+        progress: Callable,
         progress_args: tuple = ()
     ) -> str:
         dc_id = file_id.dc_id
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index 276d70c299..2eeef95c59 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -127,7 +127,7 @@ def create(func: Callable, name: str = None, **kwargs) -> Filter:
     Custom filters give you extra control over which updates are allowed or not to be processed by your handlers.
 
     Parameters:
-        func (``callable``):
+        func (``Callable``):
             A function that accepts three positional arguments *(filter, client, update)* and returns a boolean: True if the
             update should be handled, False otherwise. 
             The *filter* argument refers to the filter itself and can be used to access keyword arguments (read below). 
diff --git a/pyrogram/handlers/callback_query_handler.py b/pyrogram/handlers/callback_query_handler.py
index b582d728c8..b924fffa26 100644
--- a/pyrogram/handlers/callback_query_handler.py
+++ b/pyrogram/handlers/callback_query_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class CallbackQueryHandler(Handler):
     :meth:`~pyrogram.Client.on_callback_query` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new CallbackQuery arrives. It takes *(client, callback_query)*
             as positional arguments (look at the section below for a detailed description).
 
@@ -43,5 +45,5 @@ class CallbackQueryHandler(Handler):
             The received callback query.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/chat_join_request_handler.py b/pyrogram/handlers/chat_join_request_handler.py
index 03e2ac674e..54b8b86abb 100644
--- a/pyrogram/handlers/chat_join_request_handler.py
+++ b/pyrogram/handlers/chat_join_request_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class ChatJoinRequestHandler(Handler):
     :meth:`~pyrogram.Client.on_chat_join_request` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new ChatJoinRequest event arrives. It takes
             *(client, chat_join_request)* as positional arguments (look at the section below for a detailed
             description).
@@ -43,5 +45,5 @@ class ChatJoinRequestHandler(Handler):
             The received chat join request.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/chat_member_updated_handler.py b/pyrogram/handlers/chat_member_updated_handler.py
index 8cfdd72696..a89e7e2b57 100644
--- a/pyrogram/handlers/chat_member_updated_handler.py
+++ b/pyrogram/handlers/chat_member_updated_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class ChatMemberUpdatedHandler(Handler):
     :meth:`~pyrogram.Client.on_chat_member_updated` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new ChatMemberUpdated event arrives. It takes
             *(client, chat_member_updated)* as positional arguments (look at the section below for a detailed
             description).
@@ -43,5 +45,5 @@ class ChatMemberUpdatedHandler(Handler):
             The received chat member update.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/chosen_inline_result_handler.py b/pyrogram/handlers/chosen_inline_result_handler.py
index 81691a3577..1c04f8f44b 100644
--- a/pyrogram/handlers/chosen_inline_result_handler.py
+++ b/pyrogram/handlers/chosen_inline_result_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class ChosenInlineResultHandler(Handler):
     :meth:`~pyrogram.Client.on_chosen_inline_result` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new chosen inline result arrives.
             It takes *(client, chosen_inline_result)* as positional arguments (look at the section below for a
             detailed description).
@@ -44,5 +46,5 @@ class ChosenInlineResultHandler(Handler):
             The received chosen inline result.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/deleted_messages_handler.py b/pyrogram/handlers/deleted_messages_handler.py
index a336c6503b..ab9f834705 100644
--- a/pyrogram/handlers/deleted_messages_handler.py
+++ b/pyrogram/handlers/deleted_messages_handler.py
@@ -32,7 +32,7 @@ class DeletedMessagesHandler(Handler):
     :meth:`~pyrogram.Client.on_deleted_messages` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when one or more messages have been deleted.
             It takes *(client, messages)* as positional arguments (look at the section below for a detailed description).
 
diff --git a/pyrogram/handlers/disconnect_handler.py b/pyrogram/handlers/disconnect_handler.py
index c471e8c7e6..7420afd67a 100644
--- a/pyrogram/handlers/disconnect_handler.py
+++ b/pyrogram/handlers/disconnect_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class DisconnectHandler(Handler):
     :meth:`~pyrogram.Client.on_disconnect` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a disconnection occurs. It takes *(client)*
             as positional argument (look at the section below for a detailed description).
 
@@ -37,5 +39,5 @@ class DisconnectHandler(Handler):
             is established.
     """
 
-    def __init__(self, callback: callable):
+    def __init__(self, callback: Callable):
         super().__init__(callback)
diff --git a/pyrogram/handlers/inline_query_handler.py b/pyrogram/handlers/inline_query_handler.py
index 0ce58d17a8..f5ea23bc57 100644
--- a/pyrogram/handlers/inline_query_handler.py
+++ b/pyrogram/handlers/inline_query_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class InlineQueryHandler(Handler):
     :meth:`~pyrogram.Client.on_inline_query` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new InlineQuery arrives. It takes *(client, inline_query)*
             as positional arguments (look at the section below for a detailed description).
 
@@ -43,5 +45,5 @@ class InlineQueryHandler(Handler):
             The received inline query.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/message_handler.py b/pyrogram/handlers/message_handler.py
index 144dbe9111..63a334fc0d 100644
--- a/pyrogram/handlers/message_handler.py
+++ b/pyrogram/handlers/message_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class MessageHandler(Handler):
     :meth:`~pyrogram.Client.on_message` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new Message arrives. It takes *(client, message)*
             as positional arguments (look at the section below for a detailed description).
 
@@ -43,5 +45,5 @@ class MessageHandler(Handler):
             The received message.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/poll_handler.py b/pyrogram/handlers/poll_handler.py
index 0151f2b75c..332ca7ea28 100644
--- a/pyrogram/handlers/poll_handler.py
+++ b/pyrogram/handlers/poll_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -28,7 +30,7 @@ class PollHandler(Handler):
     :meth:`~pyrogram.Client.on_poll` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new poll update arrives. It takes *(client, poll)*
             as positional arguments (look at the section below for a detailed description).
 
@@ -44,5 +46,5 @@ class PollHandler(Handler):
             The received poll.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/handlers/raw_update_handler.py b/pyrogram/handlers/raw_update_handler.py
index e12e8477e4..d957083b57 100644
--- a/pyrogram/handlers/raw_update_handler.py
+++ b/pyrogram/handlers/raw_update_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -27,7 +29,7 @@ class RawUpdateHandler(Handler):
     :meth:`~pyrogram.Client.on_raw_update` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             A function that will be called when a new update is received from the server. It takes
             *(client, update, users, chats)* as positional arguments (look at the section below for
             a detailed description).
@@ -61,5 +63,5 @@ class RawUpdateHandler(Handler):
         - :obj:`~pyrogram.raw.types.ChannelForbidden`
     """
 
-    def __init__(self, callback: callable):
+    def __init__(self, callback: Callable):
         super().__init__(callback)
diff --git a/pyrogram/handlers/user_status_handler.py b/pyrogram/handlers/user_status_handler.py
index caebac742b..f10871e874 100644
--- a/pyrogram/handlers/user_status_handler.py
+++ b/pyrogram/handlers/user_status_handler.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Callable
+
 from .handler import Handler
 
 
@@ -26,7 +28,7 @@ class UserStatusHandler(Handler):
     For a nicer way to register this handler, have a look at the :meth:`~pyrogram.Client.on_user_status` decorator.
 
     Parameters:
-        callback (``callable``):
+        callback (``Callable``):
             Pass a function that will be called when a new user status update arrives. It takes *(client, user)*
             as positional arguments (look at the section below for a detailed description).
 
@@ -41,5 +43,5 @@ class UserStatusHandler(Handler):
             The user containing the updated status.
     """
 
-    def __init__(self, callback: callable, filters=None):
+    def __init__(self, callback: Callable, filters=None):
         super().__init__(callback, filters)
diff --git a/pyrogram/methods/advanced/resolve_peer.py b/pyrogram/methods/advanced/resolve_peer.py
index 2a39780cf2..db4def9aa2 100644
--- a/pyrogram/methods/advanced/resolve_peer.py
+++ b/pyrogram/methods/advanced/resolve_peer.py
@@ -20,17 +20,17 @@
 import re
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import utils
 from pyrogram.errors import PeerIdInvalid
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class ResolvePeer(Scaffold):
+class ResolvePeer:
     async def resolve_peer(
-        self,
+        self: "pyrogram.Client",
         peer_id: Union[int, str]
     ) -> Union[raw.base.InputPeer, raw.base.InputUser, raw.base.InputChannel]:
         """Get the InputPeer of a known peer id.
diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py
index 3f6ebb68af..9c92651dba 100644
--- a/pyrogram/methods/advanced/save_file.py
+++ b/pyrogram/methods/advanced/save_file.py
@@ -25,23 +25,23 @@
 import os
 from hashlib import md5
 from pathlib import PurePath
-from typing import Union, BinaryIO
+from typing import Union, BinaryIO, Callable
 
+import pyrogram
 from pyrogram import StopTransmission
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 from pyrogram.session import Session
 
 log = logging.getLogger(__name__)
 
 
-class SaveFile(Scaffold):
+class SaveFile:
     async def save_file(
-        self,
+        self: "pyrogram.Client",
         path: Union[str, BinaryIO],
         file_id: int = None,
         file_part: int = 0,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ):
         """Upload a file onto Telegram servers, without actually sending the message to anyone.
@@ -64,7 +64,7 @@ async def save_file(
             file_part (``int``, *optional*):
                 In case a file part expired, pass the file_id and the file_part to retry uploading that specific chunk.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/advanced/send.py b/pyrogram/methods/advanced/send.py
index 8ef0849c63..6e5551cd97 100644
--- a/pyrogram/methods/advanced/send.py
+++ b/pyrogram/methods/advanced/send.py
@@ -18,17 +18,17 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram.raw.core import TLObject
-from pyrogram.scaffold import Scaffold
 from pyrogram.session import Session
 
 log = logging.getLogger(__name__)
 
 
-class Send(Scaffold):
+class Send:
     async def send(
-        self,
+        self: "pyrogram.Client",
         data: TLObject,
         retries: int = Session.MAX_RETRIES,
         timeout: float = Session.WAIT_TIMEOUT,
diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py
index 5641a8ac72..ea041d6c36 100644
--- a/pyrogram/methods/auth/accept_terms_of_service.py
+++ b/pyrogram/methods/auth/accept_terms_of_service.py
@@ -16,12 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class AcceptTermsOfService(Scaffold):
-    async def accept_terms_of_service(self, terms_of_service_id: str) -> bool:
+class AcceptTermsOfService:
+    async def accept_terms_of_service(
+        self: "pyrogram.Client",
+        terms_of_service_id: str
+    ) -> bool:
         """Accept the given terms of service.
 
         Parameters:
diff --git a/pyrogram/methods/auth/check_password.py b/pyrogram/methods/auth/check_password.py
index 1cfa526ba0..1f1d142ced 100644
--- a/pyrogram/methods/auth/check_password.py
+++ b/pyrogram/methods/auth/check_password.py
@@ -18,16 +18,19 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 from pyrogram.utils import compute_password_check
 
 log = logging.getLogger(__name__)
 
 
-class CheckPassword(Scaffold):
-    async def check_password(self, password: str) -> "types.User":
+class CheckPassword:
+    async def check_password(
+        self: "pyrogram.Client",
+        password: str
+    ) -> "types.User":
         """Check your Two-Step Verification password and log in.
 
         Parameters:
diff --git a/pyrogram/methods/auth/connect.py b/pyrogram/methods/auth/connect.py
index 82cf661f90..191a0e9376 100644
--- a/pyrogram/methods/auth/connect.py
+++ b/pyrogram/methods/auth/connect.py
@@ -16,12 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 from pyrogram.session import Session
 
 
-class Connect(Scaffold):
-    async def connect(self) -> bool:
+class Connect:
+    async def connect(
+        self: "pyrogram.Client",
+    ) -> bool:
         """
         Connect the client to Telegram servers.
 
diff --git a/pyrogram/methods/auth/disconnect.py b/pyrogram/methods/auth/disconnect.py
index ddc1e7e1cd..daa07b8353 100644
--- a/pyrogram/methods/auth/disconnect.py
+++ b/pyrogram/methods/auth/disconnect.py
@@ -16,11 +16,13 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 
 
-class Disconnect(Scaffold):
-    async def disconnect(self):
+class Disconnect:
+    async def disconnect(
+        self: "pyrogram.Client",
+    ):
         """Disconnect the client from Telegram servers.
 
         Raises:
diff --git a/pyrogram/methods/auth/get_password_hint.py b/pyrogram/methods/auth/get_password_hint.py
index 6ba3f280b4..d900210681 100644
--- a/pyrogram/methods/auth/get_password_hint.py
+++ b/pyrogram/methods/auth/get_password_hint.py
@@ -18,14 +18,16 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetPasswordHint(Scaffold):
-    async def get_password_hint(self) -> str:
+class GetPasswordHint:
+    async def get_password_hint(
+        self: "pyrogram.Client",
+    ) -> str:
         """Get your Two-Step Verification password hint.
 
         Returns:
diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py
index 0b7608818b..2ee15b6102 100644
--- a/pyrogram/methods/auth/initialize.py
+++ b/pyrogram/methods/auth/initialize.py
@@ -18,14 +18,16 @@
 
 import logging
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 from pyrogram.syncer import Syncer
 
 log = logging.getLogger(__name__)
 
 
-class Initialize(Scaffold):
-    async def initialize(self):
+class Initialize:
+    async def initialize(
+        self: "pyrogram.Client",
+    ):
         """Initialize the client by starting up workers.
 
         This method will start updates and download workers.
diff --git a/pyrogram/methods/auth/log_out.py b/pyrogram/methods/auth/log_out.py
index 7174545dc5..2f8ad019b7 100644
--- a/pyrogram/methods/auth/log_out.py
+++ b/pyrogram/methods/auth/log_out.py
@@ -18,14 +18,16 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class LogOut(Scaffold):
-    async def log_out(self):
+class LogOut:
+    async def log_out(
+        self: "pyrogram.Client",
+    ):
         """Log out from Telegram and delete the *\\*.session* file.
 
         When you log out, the current client is stopped and the storage session deleted.
diff --git a/pyrogram/methods/auth/recover_password.py b/pyrogram/methods/auth/recover_password.py
index db877ec8d6..600ac86a0b 100644
--- a/pyrogram/methods/auth/recover_password.py
+++ b/pyrogram/methods/auth/recover_password.py
@@ -18,15 +18,18 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class RecoverPassword(Scaffold):
-    async def recover_password(self, recovery_code: str) -> "types.User":
+class RecoverPassword:
+    async def recover_password(
+        self: "pyrogram.Client",
+        recovery_code: str
+    ) -> "types.User":
         """Recover your password with a recovery code and log in.
 
         Parameters:
diff --git a/pyrogram/methods/auth/resend_code.py b/pyrogram/methods/auth/resend_code.py
index 18e835f53d..d17cc395f8 100644
--- a/pyrogram/methods/auth/resend_code.py
+++ b/pyrogram/methods/auth/resend_code.py
@@ -18,15 +18,19 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class ResendCode(Scaffold):
-    async def resend_code(self, phone_number: str, phone_code_hash: str) -> "types.SentCode":
+class ResendCode:
+    async def resend_code(
+        self: "pyrogram.Client",
+        phone_number: str,
+        phone_code_hash: str
+    ) -> "types.SentCode":
         """Re-send the confirmation code using a different type.
 
         The type of the code to be re-sent is specified in the *next_type* attribute of the
diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py
index 3f92ccebcb..3d42fa6b92 100644
--- a/pyrogram/methods/auth/send_code.py
+++ b/pyrogram/methods/auth/send_code.py
@@ -18,17 +18,20 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram.errors import PhoneMigrate, NetworkMigrate
-from pyrogram.scaffold import Scaffold
 from pyrogram.session import Session, Auth
 
 log = logging.getLogger(__name__)
 
 
-class SendCode(Scaffold):
-    async def send_code(self, phone_number: str) -> "types.SentCode":
+class SendCode:
+    async def send_code(
+        self: "pyrogram.Client",
+        phone_number: str
+    ) -> "types.SentCode":
         """Send the confirmation code to the given phone number.
 
         Parameters:
diff --git a/pyrogram/methods/auth/send_recovery_code.py b/pyrogram/methods/auth/send_recovery_code.py
index 078799783e..40d2b7ddb2 100644
--- a/pyrogram/methods/auth/send_recovery_code.py
+++ b/pyrogram/methods/auth/send_recovery_code.py
@@ -18,14 +18,16 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class SendRecoveryCode(Scaffold):
-    async def send_recovery_code(self) -> str:
+class SendRecoveryCode:
+    async def send_recovery_code(
+        self: "pyrogram.Client",
+    ) -> str:
         """Send a code to your email to recover your password.
 
         Returns:
diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py
index 19c0fbc165..d8079c95c5 100644
--- a/pyrogram/methods/auth/sign_in.py
+++ b/pyrogram/methods/auth/sign_in.py
@@ -19,16 +19,16 @@
 import logging
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class SignIn(Scaffold):
+class SignIn:
     async def sign_in(
-        self,
+        self: "pyrogram.Client",
         phone_number: str,
         phone_code_hash: str,
         phone_code: str
diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py
index 7cbcb1aca5..db4515a4ef 100644
--- a/pyrogram/methods/auth/sign_in_bot.py
+++ b/pyrogram/methods/auth/sign_in_bot.py
@@ -18,17 +18,20 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram.errors import UserMigrate
-from pyrogram.scaffold import Scaffold
 from pyrogram.session import Session, Auth
 
 log = logging.getLogger(__name__)
 
 
-class SignInBot(Scaffold):
-    async def sign_in_bot(self, bot_token: str) -> "types.User":
+class SignInBot:
+    async def sign_in_bot(
+        self: "pyrogram.Client",
+        bot_token: str
+    ) -> "types.User":
         """Authorize a bot using its bot token generated by BotFather.
 
         Parameters:
diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py
index 4b18a73292..4e769ab1b4 100644
--- a/pyrogram/methods/auth/sign_up.py
+++ b/pyrogram/methods/auth/sign_up.py
@@ -18,16 +18,16 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class SignUp(Scaffold):
+class SignUp:
     async def sign_up(
-        self,
+        self: "pyrogram.Client",
         phone_number: str,
         phone_code_hash: str,
         first_name: str,
diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py
index 46b6698263..d8cca6ba81 100644
--- a/pyrogram/methods/auth/terminate.py
+++ b/pyrogram/methods/auth/terminate.py
@@ -18,15 +18,17 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 from pyrogram.syncer import Syncer
 
 log = logging.getLogger(__name__)
 
 
-class Terminate(Scaffold):
-    async def terminate(self):
+class Terminate:
+    async def terminate(
+        self: "pyrogram.Client",
+    ):
         """Terminate the client by shutting down workers.
 
         This method does the opposite of :meth:`~pyrogram.Client.initialize`.
diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py
index 941389b74b..73d5ce5569 100644
--- a/pyrogram/methods/bots/answer_callback_query.py
+++ b/pyrogram/methods/bots/answer_callback_query.py
@@ -16,13 +16,13 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class AnswerCallbackQuery(Scaffold):
+class AnswerCallbackQuery:
     async def answer_callback_query(
-        self,
+        self: "pyrogram.Client",
         callback_query_id: str,
         text: str = None,
         show_alert: bool = None,
diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py
index 24e7a30c78..1751171d53 100644
--- a/pyrogram/methods/bots/answer_inline_query.py
+++ b/pyrogram/methods/bots/answer_inline_query.py
@@ -18,14 +18,14 @@
 
 from typing import Iterable
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class AnswerInlineQuery(Scaffold):
+class AnswerInlineQuery:
     async def answer_inline_query(
-        self,
+        self: "pyrogram.Client",
         inline_query_id: str,
         results: Iterable["types.InlineQueryResult"],
         cache_time: int = 300,
diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py
index cd0b09ba3d..e4a2ed150c 100644
--- a/pyrogram/methods/bots/get_game_high_scores.py
+++ b/pyrogram/methods/bots/get_game_high_scores.py
@@ -18,14 +18,14 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetGameHighScores(Scaffold):
+class GetGameHighScores:
     async def get_game_high_scores(
-        self,
+        self: "pyrogram.Client",
         user_id: Union[int, str],
         chat_id: Union[int, str],
         message_id: int = None
diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py
index 800de93e4c..2c41fec7ec 100644
--- a/pyrogram/methods/bots/get_inline_bot_results.py
+++ b/pyrogram/methods/bots/get_inline_bot_results.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram.errors import UnknownError
-from pyrogram.scaffold import Scaffold
 
 
-class GetInlineBotResults(Scaffold):
+class GetInlineBotResults:
     async def get_inline_bot_results(
-        self,
+        self: "pyrogram.Client",
         bot: Union[int, str],
         query: str = "",
         offset: str = "",
diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py
index 5db9dfe079..ff6ae0d3ef 100644
--- a/pyrogram/methods/bots/request_callback_answer.py
+++ b/pyrogram/methods/bots/request_callback_answer.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class RequestCallbackAnswer(Scaffold):
+class RequestCallbackAnswer:
     async def request_callback_answer(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         callback_data: Union[str, bytes],
diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py
index 05b9094f58..7f9e856bb0 100644
--- a/pyrogram/methods/bots/send_game.py
+++ b/pyrogram/methods/bots/send_game.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SendGame(Scaffold):
+class SendGame:
     async def send_game(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         game_short_name: str,
         disable_notification: bool = None,
diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py
index ead95810b5..299aaaf6f7 100644
--- a/pyrogram/methods/bots/send_inline_bot_result.py
+++ b/pyrogram/methods/bots/send_inline_bot_result.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SendInlineBotResult(Scaffold):
+class SendInlineBotResult:
     async def send_inline_bot_result(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         query_id: int,
         result_id: str,
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index c346151591..8c9baa2e6a 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -19,11 +19,11 @@
 from typing import List
 
 import pyrogram
-from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
+from pyrogram import raw
+from pyrogram import types
 
 
-class SetBotCommands(Scaffold):
+class SetBotCommands:
     async def set_bot_commands(
         self: "pyrogram.Client",
         commands: List["types.BotCommand"],
@@ -31,7 +31,6 @@ async def set_bot_commands(
         language_code: str = "",
     ):
         """Set the list of the bot's commands.
-
         The commands passed will overwrite any command set previously.
         This method can be used by the own bot only.
 
diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py
index edb38dcfe1..ef644b60db 100644
--- a/pyrogram/methods/bots/set_game_score.py
+++ b/pyrogram/methods/bots/set_game_score.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SetGameScore(Scaffold):
+class SetGameScore:
     async def set_game_score(
-        self,
+        self: "pyrogram.Client",
         user_id: Union[int, str],
         score: int,
         force: bool = None,
diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py
index 70fb0f97c4..cda789aaba 100644
--- a/pyrogram/methods/chats/add_chat_members.py
+++ b/pyrogram/methods/chats/add_chat_members.py
@@ -18,13 +18,13 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class AddChatMembers(Scaffold):
+class AddChatMembers:
     async def add_chat_members(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_ids: Union[Union[int, str], List[Union[int, str]]],
         forward_limit: int = 100
diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py
index c65b762206..aa5b50d5ec 100644
--- a/pyrogram/methods/chats/archive_chats.py
+++ b/pyrogram/methods/chats/archive_chats.py
@@ -18,13 +18,13 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class ArchiveChats(Scaffold):
+class ArchiveChats:
     async def archive_chats(
-        self,
+        self: "pyrogram.Client",
         chat_ids: Union[int, str, List[Union[int, str]]],
     ) -> bool:
         """Archive one or more chats.
diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py
index 3edcb164ce..c01b70462e 100644
--- a/pyrogram/methods/chats/ban_chat_member.py
+++ b/pyrogram/methods/chats/ban_chat_member.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class BanChatMember(Scaffold):
+class BanChatMember:
     async def ban_chat_member(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
         until_date: datetime = datetime.fromtimestamp(0)
diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py
index b3b21eaea3..5920d5ff70 100644
--- a/pyrogram/methods/chats/create_channel.py
+++ b/pyrogram/methods/chats/create_channel.py
@@ -15,15 +15,14 @@
 #
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
-
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class CreateChannel(Scaffold):
+class CreateChannel:
     async def create_channel(
-        self,
+        self: "pyrogram.Client",
         title: str,
         description: str = ""
     ) -> "types.Chat":
diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py
index 2117d3699a..d01a2e683d 100644
--- a/pyrogram/methods/chats/create_group.py
+++ b/pyrogram/methods/chats/create_group.py
@@ -18,14 +18,14 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class CreateGroup(Scaffold):
+class CreateGroup:
     async def create_group(
-        self,
+        self: "pyrogram.Client",
         title: str,
         users: Union[Union[int, str], List[Union[int, str]]]
     ) -> "types.Chat":
diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py
index 2c72e25b30..348fc72609 100644
--- a/pyrogram/methods/chats/create_supergroup.py
+++ b/pyrogram/methods/chats/create_supergroup.py
@@ -15,15 +15,14 @@
 #
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
-
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class CreateSupergroup(Scaffold):
+class CreateSupergroup:
     async def create_supergroup(
-        self,
+        self: "pyrogram.Client",
         title: str,
         description: str = ""
     ) -> "types.Chat":
diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py
index 3f9baa4ff6..246c930af8 100644
--- a/pyrogram/methods/chats/delete_channel.py
+++ b/pyrogram/methods/chats/delete_channel.py
@@ -18,12 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteChannel(Scaffold):
-    async def delete_channel(self, chat_id: Union[int, str]) -> bool:
+class DeleteChannel:
+    async def delete_channel(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str]
+    ) -> bool:
         """Delete a channel.
 
         Parameters:
diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py
index 4311658bd5..0b4d6488c6 100644
--- a/pyrogram/methods/chats/delete_chat_photo.py
+++ b/pyrogram/methods/chats/delete_chat_photo.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteChatPhoto(Scaffold):
+class DeleteChatPhoto:
     async def delete_chat_photo(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> bool:
         """Delete a chat photo.
diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py
index b9d3bdf7d0..5f6e8168ea 100644
--- a/pyrogram/methods/chats/delete_supergroup.py
+++ b/pyrogram/methods/chats/delete_supergroup.py
@@ -18,12 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteSupergroup(Scaffold):
-    async def delete_supergroup(self, chat_id: Union[int, str]) -> bool:
+class DeleteSupergroup:
+    async def delete_supergroup(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str]
+    ) -> bool:
         """Delete a supergroup.
 
         Parameters:
diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py
index ca9d0c5941..867100bb6e 100644
--- a/pyrogram/methods/chats/delete_user_history.py
+++ b/pyrogram/methods/chats/delete_user_history.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteUserHistory(Scaffold):
+class DeleteUserHistory:
     async def delete_user_history(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
     ) -> bool:
diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py
index d9ecb166ba..99e5756647 100644
--- a/pyrogram/methods/chats/get_chat.py
+++ b/pyrogram/methods/chats/get_chat.py
@@ -18,15 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class GetChat(Scaffold):
+class GetChat:
     async def get_chat(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> Union["types.Chat", "types.ChatPreview"]:
         """Get up to date information about a chat.
diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py
index 3e392a204d..db27709094 100644
--- a/pyrogram/methods/chats/get_chat_event_log.py
+++ b/pyrogram/methods/chats/get_chat_event_log.py
@@ -18,14 +18,14 @@
 
 from typing import Union, List, AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatEventLog(Scaffold):
+class GetChatEventLog:
     async def get_chat_event_log(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         query: str = "",
         offset_id: int = 0,
diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py
index 9987327c6b..9717d01953 100644
--- a/pyrogram/methods/chats/get_chat_member.py
+++ b/pyrogram/methods/chats/get_chat_member.py
@@ -18,15 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram.errors import UserNotParticipant
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatMember(Scaffold):
+class GetChatMember:
     async def get_chat_member(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str]
     ) -> "types.ChatMember":
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index 4c8ae60229..7e6b8898fc 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -19,15 +19,15 @@
 import logging
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw, types, enums
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetChatMembers(Scaffold):
+class GetChatMembers:
     async def get_chat_members(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         offset: int = 0,
         limit: int = 200,
@@ -105,17 +105,17 @@ async def get_chat_members(
         elif isinstance(peer, raw.types.InputPeerChannel):
             filter = filter.lower()
 
-            if filter == Filters.ALL:
+            if filter == enums.ChatMembersFilter.ANY:
                 filter = raw.types.ChannelParticipantsSearch(q=query)
-            elif filter == Filters.BANNED:
+            elif filter == enums.ChatMembersFilter.BANNED:
                 filter = raw.types.ChannelParticipantsKicked(q=query)
-            elif filter == Filters.RESTRICTED:
+            elif filter == enums.ChatMembersFilter.RESTRICTED:
                 filter = raw.types.ChannelParticipantsBanned(q=query)
-            elif filter == Filters.BOTS:
+            elif filter == enums.ChatMembersFilter.BOTS:
                 filter = raw.types.ChannelParticipantsBots()
-            elif filter == Filters.RECENT:
+            elif filter == enums.ChatMembersFilter.RECENT:
                 filter = raw.types.ChannelParticipantsRecent()
-            elif filter == Filters.ADMINISTRATORS:
+            elif filter == enums.ChatMembersFilter.ADMINISTRATORS:
                 filter = raw.types.ChannelParticipantsAdmins()
             else:
                 raise ValueError(f'Invalid filter "{filter}"')
diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py
index aa943eea2a..a7dae4be05 100644
--- a/pyrogram/methods/chats/get_chat_members_count.py
+++ b/pyrogram/methods/chats/get_chat_members_count.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatMembersCount(Scaffold):
+class GetChatMembersCount:
     async def get_chat_members_count(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> int:
         """Get the number of members in a chat.
diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py
index a8d1321446..3f8e5d6aee 100644
--- a/pyrogram/methods/chats/get_chat_online_count.py
+++ b/pyrogram/methods/chats/get_chat_online_count.py
@@ -18,12 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatOnlineCount(Scaffold):
-    async def get_chat_online_count(self, chat_id: Union[int, str]) -> int:
+class GetChatOnlineCount:
+    async def get_chat_online_count(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str]
+    ) -> int:
         """Get the number of members that are currently online in a chat.
 
         Parameters:
diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py
index 9fb907caba..7276c80b64 100644
--- a/pyrogram/methods/chats/get_dialogs.py
+++ b/pyrogram/methods/chats/get_dialogs.py
@@ -20,17 +20,17 @@
 from datetime import datetime
 from typing import List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetDialogs(Scaffold):
+class GetDialogs:
     async def get_dialogs(
-        self,
+        self: "pyrogram.Client",
         offset_date: datetime = datetime.fromtimestamp(0),
         limit: int = 100,
         pinned_only: bool = False
diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py
index a8598e5fcc..3f869909fc 100644
--- a/pyrogram/methods/chats/get_dialogs_count.py
+++ b/pyrogram/methods/chats/get_dialogs_count.py
@@ -16,12 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetDialogsCount(Scaffold):
-    async def get_dialogs_count(self, pinned_only: bool = False) -> int:
+class GetDialogsCount:
+    async def get_dialogs_count(
+        self: "pyrogram.Client",
+        pinned_only: bool = False
+    ) -> int:
         """Get the total count of your dialogs.
 
         pinned_only (``bool``, *optional*):
diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py
index dcceb4398b..0dff05aae2 100644
--- a/pyrogram/methods/chats/get_nearby_chats.py
+++ b/pyrogram/methods/chats/get_nearby_chats.py
@@ -18,15 +18,15 @@
 
 from typing import List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class GetNearbyChats(Scaffold):
+class GetNearbyChats:
     async def get_nearby_chats(
-        self,
+        self: "pyrogram.Client",
         latitude: float,
         longitude: float
     ) -> List["types.Chat"]:
diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py
index 4d2fae4824..147da217ce 100644
--- a/pyrogram/methods/chats/get_send_as_chats.py
+++ b/pyrogram/methods/chats/get_send_as_chats.py
@@ -18,14 +18,14 @@
 
 from typing import List, Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetSendAsChats(Scaffold):
+class GetSendAsChats:
     async def get_send_as_chats(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> List["types.Chat"]:
         """Get the list of "send_as" chats available.
diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py
index 3661d5064f..f3ccf06c81 100644
--- a/pyrogram/methods/chats/iter_chat_members.py
+++ b/pyrogram/methods/chats/iter_chat_members.py
@@ -18,9 +18,9 @@
 
 from typing import Union, AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
 class Filters:
@@ -32,9 +32,9 @@ class Filters:
     ADMINISTRATORS = "administrators"
 
 
-class IterChatMembers(Scaffold):
+class IterChatMembers:
     async def iter_chat_members(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         limit: int = 0,
         query: str = "",
diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py
index 4553e3d47e..009bdfa8c2 100644
--- a/pyrogram/methods/chats/iter_dialogs.py
+++ b/pyrogram/methods/chats/iter_dialogs.py
@@ -18,13 +18,13 @@
 
 from typing import AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import types, raw, utils
-from pyrogram.scaffold import Scaffold
 
 
-class IterDialogs(Scaffold):
+class IterDialogs:
     async def iter_dialogs(
-        self,
+        self: "pyrogram.Client",
         limit: int = 0
     ) -> Optional[AsyncGenerator["types.Dialog", None]]:
         """Iterate through a user's dialogs sequentially.
diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py
index 3f1a09f998..c1a850af92 100644
--- a/pyrogram/methods/chats/join_chat.py
+++ b/pyrogram/methods/chats/join_chat.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class JoinChat(Scaffold):
+class JoinChat:
     async def join_chat(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> "types.Chat":
         """Join a group chat or channel.
diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py
index 3271a1f952..56369e1ce7 100644
--- a/pyrogram/methods/chats/leave_chat.py
+++ b/pyrogram/methods/chats/leave_chat.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class LeaveChat(Scaffold):
+class LeaveChat:
     async def leave_chat(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         delete: bool = False
     ):
diff --git a/pyrogram/methods/chats/mark_chat_unread.py b/pyrogram/methods/chats/mark_chat_unread.py
index 4a48c5d6fa..32251e2a7d 100644
--- a/pyrogram/methods/chats/mark_chat_unread.py
+++ b/pyrogram/methods/chats/mark_chat_unread.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram.raw import functions
-from pyrogram.scaffold import Scaffold
 
 
-class MarkChatUnread(Scaffold):
+class MarkChatUnread:
     async def mark_chat_unread(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
     ) -> bool:
         """Mark a chat as unread.
diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py
index 016a19a7b2..9e34e1aa6c 100644
--- a/pyrogram/methods/chats/pin_chat_message.py
+++ b/pyrogram/methods/chats/pin_chat_message.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class PinChatMessage(Scaffold):
+class PinChatMessage:
     async def pin_chat_message(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         disable_notification: bool = False,
diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py
index b1d43867f3..63a844bb2a 100644
--- a/pyrogram/methods/chats/promote_chat_member.py
+++ b/pyrogram/methods/chats/promote_chat_member.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class PromoteChatMember(Scaffold):
+class PromoteChatMember:
     async def promote_chat_member(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
         privileges: "types.ChatPrivileges" = types.ChatPrivileges(),
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index 22eee519c1..a8ab21730d 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class RestrictChatMember(Scaffold):
+class RestrictChatMember:
     async def restrict_chat_member(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
         permissions: "types.ChatPermissions",
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index f59cf28a35..ed59b342f5 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetAdministratorTitle(Scaffold):
+class SetAdministratorTitle:
     async def set_administrator_title(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
         title: str,
diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py
index 6d2575f207..440b405013 100644
--- a/pyrogram/methods/chats/set_chat_description.py
+++ b/pyrogram/methods/chats/set_chat_description.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatDescription(Scaffold):
+class SetChatDescription:
     async def set_chat_description(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         description: str
     ) -> bool:
diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py
index 2ff2b67831..dfbd5d917d 100644
--- a/pyrogram/methods/chats/set_chat_permissions.py
+++ b/pyrogram/methods/chats/set_chat_permissions.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatPermissions(Scaffold):
+class SetChatPermissions:
     async def set_chat_permissions(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         permissions: "types.ChatPermissions",
     ) -> "types.Chat":
diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py
index a1fee7f62f..1097b2377b 100644
--- a/pyrogram/methods/chats/set_chat_photo.py
+++ b/pyrogram/methods/chats/set_chat_photo.py
@@ -19,15 +19,15 @@
 import os
 from typing import Union, BinaryIO
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import utils
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatPhoto(Scaffold):
+class SetChatPhoto:
     async def set_chat_photo(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         *,
         photo: Union[str, BinaryIO] = None,
diff --git a/pyrogram/methods/chats/set_chat_protected_content.py b/pyrogram/methods/chats/set_chat_protected_content.py
index d63e381d98..1372481c99 100644
--- a/pyrogram/methods/chats/set_chat_protected_content.py
+++ b/pyrogram/methods/chats/set_chat_protected_content.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram.raw import functions
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatProtectedContent(Scaffold):
+class SetChatProtectedContent:
     async def set_chat_protected_content(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         enabled: bool
     ) -> bool:
diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py
index 62649f3850..ac30b078fe 100644
--- a/pyrogram/methods/chats/set_chat_title.py
+++ b/pyrogram/methods/chats/set_chat_title.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatTitle(Scaffold):
+class SetChatTitle:
     async def set_chat_title(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         title: str
     ) -> bool:
diff --git a/pyrogram/methods/chats/set_chat_username.py b/pyrogram/methods/chats/set_chat_username.py
index 8496dda326..c63207aa33 100644
--- a/pyrogram/methods/chats/set_chat_username.py
+++ b/pyrogram/methods/chats/set_chat_username.py
@@ -18,13 +18,13 @@
 
 from typing import Union, Optional
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetChatUsername(Scaffold):
+class SetChatUsername:
     async def set_chat_username(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         username: Optional[str]
     ) -> bool:
diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py
index 3fc686bbcf..dabb4066f8 100644
--- a/pyrogram/methods/chats/set_send_as_chat.py
+++ b/pyrogram/methods/chats/set_send_as_chat.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetSendAsChat(Scaffold):
+class SetSendAsChat:
     async def set_send_as_chat(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         send_as_chat_id: Union[int, str]
     ) -> bool:
diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py
index 7e6739bacb..3bc00cb21a 100644
--- a/pyrogram/methods/chats/set_slow_mode.py
+++ b/pyrogram/methods/chats/set_slow_mode.py
@@ -18,13 +18,13 @@
 
 from typing import Union, Optional
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetSlowMode(Scaffold):
+class SetSlowMode:
     async def set_slow_mode(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         seconds: Optional[int]
     ) -> bool:
diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py
index 32867798ce..a6b77d1845 100644
--- a/pyrogram/methods/chats/unarchive_chats.py
+++ b/pyrogram/methods/chats/unarchive_chats.py
@@ -18,13 +18,13 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UnarchiveChats(Scaffold):
+class UnarchiveChats:
     async def unarchive_chats(
-        self,
+        self: "pyrogram.Client",
         chat_ids: Union[int, str, List[Union[int, str]]],
     ) -> bool:
         """Unarchive one or more chats.
diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py
index c7be7b58f6..9176fe3361 100644
--- a/pyrogram/methods/chats/unban_chat_member.py
+++ b/pyrogram/methods/chats/unban_chat_member.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UnbanChatMember(Scaffold):
+class UnbanChatMember:
     async def unban_chat_member(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str]
     ) -> bool:
diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py
index 3028120ae2..bd75c40d6c 100644
--- a/pyrogram/methods/chats/unpin_all_chat_messages.py
+++ b/pyrogram/methods/chats/unpin_all_chat_messages.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UnpinAllChatMessages(Scaffold):
+class UnpinAllChatMessages:
     async def unpin_all_chat_messages(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
     ) -> bool:
         """Use this method to clear the list of pinned messages in a chat.
diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py
index 83654452cc..cf3f9e9d5e 100644
--- a/pyrogram/methods/chats/unpin_chat_message.py
+++ b/pyrogram/methods/chats/unpin_chat_message.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UnpinChatMessage(Scaffold):
+class UnpinChatMessage:
     async def unpin_chat_message(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int = 0
     ) -> bool:
diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py
index cceb273d37..72bdd88acf 100644
--- a/pyrogram/methods/contacts/add_contact.py
+++ b/pyrogram/methods/contacts/add_contact.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class AddContact(Scaffold):
+class AddContact:
     async def add_contact(
-        self,
+        self: "pyrogram.Client",
         user_id: Union[int, str],
         first_name: str,
         last_name: str = "",
diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py
index 273407475a..e6ef32583b 100644
--- a/pyrogram/methods/contacts/delete_contacts.py
+++ b/pyrogram/methods/contacts/delete_contacts.py
@@ -18,13 +18,13 @@
 
 from typing import List, Union
 
+import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteContacts(Scaffold):
+class DeleteContacts:
     async def delete_contacts(
-        self,
+        self: "pyrogram.Client",
         user_ids: Union[int, str, List[Union[int, str]]]
     ) -> Union["types.User", List["types.User"], None]:
         """Delete contacts from your Telegram address book.
diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py
index 98ed11502d..0b41c3d6cb 100644
--- a/pyrogram/methods/contacts/get_contacts.py
+++ b/pyrogram/methods/contacts/get_contacts.py
@@ -19,15 +19,17 @@
 import logging
 from typing import List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetContacts(Scaffold):
-    async def get_contacts(self) -> List["types.User"]:
+class GetContacts:
+    async def get_contacts(
+        self: "pyrogram.Client"
+    ) -> List["types.User"]:
         """Get contacts from your Telegram address book.
 
         Returns:
diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py
index b29fed7ac1..b7e5d371c8 100644
--- a/pyrogram/methods/contacts/get_contacts_count.py
+++ b/pyrogram/methods/contacts/get_contacts_count.py
@@ -16,12 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetContactsCount(Scaffold):
-    async def get_contacts_count(self) -> int:
+class GetContactsCount:
+    async def get_contacts_count(
+        self: "pyrogram.Client"
+    ) -> int:
         """Get the total count of contacts from your Telegram address book.
 
         Returns:
diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py
index b7df855439..7a6e31420f 100644
--- a/pyrogram/methods/contacts/import_contacts.py
+++ b/pyrogram/methods/contacts/import_contacts.py
@@ -18,14 +18,14 @@
 
 from typing import List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class ImportContacts(Scaffold):
+class ImportContacts:
     async def import_contacts(
-        self,
+        self: "pyrogram.Client",
         contacts: List["types.InputPhoneContact"]
     ):
         """Import contacts to your Telegram address book.
diff --git a/pyrogram/methods/decorators/on_callback_query.py b/pyrogram/methods/decorators/on_callback_query.py
index fb0b716f60..07e15a3e78 100644
--- a/pyrogram/methods/decorators/on_callback_query.py
+++ b/pyrogram/methods/decorators/on_callback_query.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnCallbackQuery(Scaffold):
+class OnCallbackQuery:
     def on_callback_query(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling callback queries.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_chat_join_request.py b/pyrogram/methods/decorators/on_chat_join_request.py
index 0629901814..57fb709cb5 100644
--- a/pyrogram/methods/decorators/on_chat_join_request.py
+++ b/pyrogram/methods/decorators/on_chat_join_request.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnChatJoinRequest(Scaffold):
+class OnChatJoinRequest:
     def on_chat_join_request(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling chat join requests.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_chat_member_updated.py b/pyrogram/methods/decorators/on_chat_member_updated.py
index 9c10debfdd..c2f0e888a8 100644
--- a/pyrogram/methods/decorators/on_chat_member_updated.py
+++ b/pyrogram/methods/decorators/on_chat_member_updated.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnChatMemberUpdated(Scaffold):
+class OnChatMemberUpdated:
     def on_chat_member_updated(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling event changes on chat members.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_chosen_inline_result.py b/pyrogram/methods/decorators/on_chosen_inline_result.py
index a2775c9bea..090f6c0425 100644
--- a/pyrogram/methods/decorators/on_chosen_inline_result.py
+++ b/pyrogram/methods/decorators/on_chosen_inline_result.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnChosenInlineResult(Scaffold):
+class OnChosenInlineResult:
     def on_chosen_inline_result(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling chosen inline results.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_deleted_messages.py b/pyrogram/methods/decorators/on_deleted_messages.py
index 3bf88b088a..9565c11329 100644
--- a/pyrogram/methods/decorators/on_deleted_messages.py
+++ b/pyrogram/methods/decorators/on_deleted_messages.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnDeletedMessages(Scaffold):
+class OnDeletedMessages:
     def on_deleted_messages(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling deleted messages.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_disconnect.py b/pyrogram/methods/decorators/on_disconnect.py
index 5e4f75014b..ae54800f86 100644
--- a/pyrogram/methods/decorators/on_disconnect.py
+++ b/pyrogram/methods/decorators/on_disconnect.py
@@ -19,11 +19,10 @@
 from typing import Callable
 
 import pyrogram
-from pyrogram.scaffold import Scaffold
 
 
-class OnDisconnect(Scaffold):
-    def on_disconnect(self=None) -> callable:
+class OnDisconnect:
+    def on_disconnect(self=None) -> Callable:
         """Decorator for handling disconnections.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_inline_query.py b/pyrogram/methods/decorators/on_inline_query.py
index 4910670e33..6b53a464de 100644
--- a/pyrogram/methods/decorators/on_inline_query.py
+++ b/pyrogram/methods/decorators/on_inline_query.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnInlineQuery(Scaffold):
+class OnInlineQuery:
     def on_inline_query(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling inline queries.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_message.py b/pyrogram/methods/decorators/on_message.py
index 634ca2e335..e9a3dfdd85 100644
--- a/pyrogram/methods/decorators/on_message.py
+++ b/pyrogram/methods/decorators/on_message.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnMessage(Scaffold):
+class OnMessage:
     def on_message(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling messages.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_poll.py b/pyrogram/methods/decorators/on_poll.py
index 2694040372..6990c456b6 100644
--- a/pyrogram/methods/decorators/on_poll.py
+++ b/pyrogram/methods/decorators/on_poll.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnPoll(Scaffold):
+class OnPoll:
     def on_poll(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling poll updates.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_raw_update.py b/pyrogram/methods/decorators/on_raw_update.py
index f61b156b90..dffc50b924 100644
--- a/pyrogram/methods/decorators/on_raw_update.py
+++ b/pyrogram/methods/decorators/on_raw_update.py
@@ -19,14 +19,13 @@
 from typing import Callable
 
 import pyrogram
-from pyrogram.scaffold import Scaffold
 
 
-class OnRawUpdate(Scaffold):
+class OnRawUpdate:
     def on_raw_update(
         self=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling raw updates.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
diff --git a/pyrogram/methods/decorators/on_user_status.py b/pyrogram/methods/decorators/on_user_status.py
index 38760c2f4e..a4328c37f1 100644
--- a/pyrogram/methods/decorators/on_user_status.py
+++ b/pyrogram/methods/decorators/on_user_status.py
@@ -20,15 +20,14 @@
 
 import pyrogram
 from pyrogram.filters import Filter
-from pyrogram.scaffold import Scaffold
 
 
-class OnUserStatus(Scaffold):
+class OnUserStatus:
     def on_user_status(
         self=None,
         filters=None,
         group: int = 0
-    ) -> callable:
+    ) -> Callable:
         """Decorator for handling user status updates.
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
         :obj:`~pyrogram.handlers.UserStatusHandler`.
diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py
index 0bb2f604ca..a18a1c146a 100644
--- a/pyrogram/methods/invite_links/approve_chat_join_request.py
+++ b/pyrogram/methods/invite_links/approve_chat_join_request.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class ApproveChatJoinRequest(Scaffold):
+class ApproveChatJoinRequest:
     async def approve_chat_join_request(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: int,
     ) -> bool:
diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py
index eec25787a4..15ca034162 100644
--- a/pyrogram/methods/invite_links/create_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/create_chat_invite_link.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class CreateChatInviteLink(Scaffold):
+class CreateChatInviteLink:
     async def create_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         name: str = None,
         expire_date: datetime = None,
diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py
index 3fc01e2690..d7c3d2f2e0 100644
--- a/pyrogram/methods/invite_links/decline_chat_join_request.py
+++ b/pyrogram/methods/invite_links/decline_chat_join_request.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeclineChatJoinRequest(Scaffold):
+class DeclineChatJoinRequest:
     async def decline_chat_join_request(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: int,
     ) -> bool:
diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
index fda2aadbcb..c051717830 100644
--- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteChatAdminInviteLinks(Scaffold):
+class DeleteChatAdminInviteLinks:
     async def delete_chat_admin_invite_links(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         admin_id: Union[int, str],
     ) -> bool:
diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py
index eeab4e3537..19f4b49b3c 100644
--- a/pyrogram/methods/invite_links/delete_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteChatInviteLink(Scaffold):
+class DeleteChatInviteLink:
     async def delete_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str,
     ) -> bool:
diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py
index 9a37536084..4a6755d6ea 100644
--- a/pyrogram/methods/invite_links/edit_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class EditChatInviteLink(Scaffold):
+class EditChatInviteLink:
     async def edit_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str,
         name: str = None,
diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py
index 061ccdf349..9734470fea 100644
--- a/pyrogram/methods/invite_links/export_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/export_chat_invite_link.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class ExportChatInviteLink(Scaffold):
+class ExportChatInviteLink:
     async def export_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
     ) -> "types.ChatInviteLink":
         """Generate a new primary invite link for a chat; any previously generated primary link is revoked.
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
index 8687795d70..0c2660828a 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
@@ -18,14 +18,14 @@
 
 from typing import Union, Optional, AsyncGenerator
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatAdminInviteLinks(Scaffold):
+class GetChatAdminInviteLinks:
     async def get_chat_admin_invite_links(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         admin_id: Union[int, str],
         revoked: bool = False,
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
index 789f551a2f..419c76a776 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatAdminInviteLinksCount(Scaffold):
+class GetChatAdminInviteLinksCount:
     async def get_chat_admin_invite_links_count(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         admin_id: Union[int, str],
         revoked: bool = False,
diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
index 8b048a58b5..0f41925a10 100644
--- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatAdminsWithInviteLinks(Scaffold):
+class GetChatAdminsWithInviteLinks:
     async def get_chat_admins_with_invite_links(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
     ):
         """Get the list of the administrators that have exported invite links in a chat.
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link.py b/pyrogram/methods/invite_links/get_chat_invite_link.py
index a5361bab6f..0fe0da8e9e 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatInviteLink(Scaffold):
+class GetChatInviteLink:
     async def get_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str,
     ) -> "types.ChatInviteLink":
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members.py b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
index 5d6e920891..8269a3465b 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
@@ -18,14 +18,14 @@
 
 from typing import Union, Optional, AsyncGenerator
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatInviteLinkMembers(Scaffold):
+class GetChatInviteLinkMembers:
     async def get_chat_invite_link_members(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str,
         limit: int = 0
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
index a4f5bbb710..c37258fe3c 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetChatInviteLinkMembersCount(Scaffold):
+class GetChatInviteLinkMembersCount:
     async def get_chat_invite_link_members_count(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str
     ) -> int:
diff --git a/pyrogram/methods/invite_links/revoke_chat_invite_link.py b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
index cb3c39cdc4..64af8e5f73 100644
--- a/pyrogram/methods/invite_links/revoke_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class RevokeChatInviteLink(Scaffold):
+class RevokeChatInviteLink:
     async def revoke_chat_invite_link(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         invite_link: str,
     ) -> "types.ChatInviteLink":
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index 06aa6c202a..367cf47c57 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.py
@@ -19,13 +19,13 @@
 from datetime import datetime
 from typing import Union, List
 
+import pyrogram
 from pyrogram import types, utils, raw
-from pyrogram.scaffold import Scaffold
 
 
-class CopyMediaGroup(Scaffold):
+class CopyMediaGroup:
     async def copy_media_group(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         from_chat_id: Union[int, str],
         message_id: int,
diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index ee40945bab..94c11d4b50 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -20,15 +20,15 @@
 from datetime import datetime
 from typing import Union, List, Optional
 
+import pyrogram
 from pyrogram import types, enums
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class CopyMessage(Scaffold):
+class CopyMessage:
     async def copy_message(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         from_chat_id: Union[int, str],
         message_id: int,
diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py
index b9807dc53d..30438944fb 100644
--- a/pyrogram/methods/messages/delete_messages.py
+++ b/pyrogram/methods/messages/delete_messages.py
@@ -18,13 +18,13 @@
 
 from typing import Union, Iterable
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteMessages(Scaffold):
+class DeleteMessages:
     async def delete_messages(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_ids: Union[int, Iterable[int]],
         revoke: bool = True
diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py
index c1472e9558..d75ba281a0 100644
--- a/pyrogram/methods/messages/download_media.py
+++ b/pyrogram/methods/messages/download_media.py
@@ -20,22 +20,22 @@
 import os
 import time
 from datetime import datetime
-from typing import Union, Optional
+from typing import Union, Optional, Callable
 
+import pyrogram
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, PHOTO_TYPES
-from pyrogram.scaffold import Scaffold
 
 DEFAULT_DOWNLOAD_DIR = "downloads/"
 
 
-class DownloadMedia(Scaffold):
+class DownloadMedia:
     async def download_media(
-        self,
+        self: "pyrogram.Client",
         message: Union["types.Message", str],
         file_name: str = DEFAULT_DOWNLOAD_DIR,
         block: bool = True,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional[str]:
         """Download the media from a message.
@@ -55,7 +55,7 @@ async def download_media(
                 Blocks the code execution until the file has been downloaded.
                 Defaults to True.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py
index ed99b62d70..3068098ed9 100644
--- a/pyrogram/methods/messages/edit_inline_caption.py
+++ b/pyrogram/methods/messages/edit_inline_caption.py
@@ -18,13 +18,13 @@
 
 from typing import Optional
 
+import pyrogram
 from pyrogram import types, enums
-from pyrogram.scaffold import Scaffold
 
 
-class EditInlineCaption(Scaffold):
+class EditInlineCaption:
     async def edit_inline_caption(
-        self,
+        self: "pyrogram.Client",
         inline_message_id: str,
         caption: str,
         parse_mode: Optional["enums.ParseMode"] = None,
diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py
index 6b8c834ad4..0613bd7368 100644
--- a/pyrogram/methods/messages/edit_inline_media.py
+++ b/pyrogram/methods/messages/edit_inline_media.py
@@ -19,17 +19,17 @@
 import os
 import re
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 from .inline_session import get_session
 
 
-class EditInlineMedia(Scaffold):
+class EditInlineMedia:
     async def edit_inline_media(
-        self,
+        self: "pyrogram.Client",
         inline_message_id: str,
         media: "types.InputMedia",
         reply_markup: "types.InlineKeyboardMarkup" = None
diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py
index 614da61718..b3760c6751 100644
--- a/pyrogram/methods/messages/edit_inline_reply_markup.py
+++ b/pyrogram/methods/messages/edit_inline_reply_markup.py
@@ -16,16 +16,16 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 from .inline_session import get_session
 
 
-class EditInlineReplyMarkup(Scaffold):
+class EditInlineReplyMarkup:
     async def edit_inline_reply_markup(
-        self,
+        self: "pyrogram.Client",
         inline_message_id: str,
         reply_markup: "types.InlineKeyboardMarkup" = None
     ) -> bool:
diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py
index af4b555574..ae4cab3661 100644
--- a/pyrogram/methods/messages/edit_inline_text.py
+++ b/pyrogram/methods/messages/edit_inline_text.py
@@ -18,16 +18,16 @@
 
 from typing import Optional
 
+import pyrogram
 from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 from .inline_session import get_session
 
 
-class EditInlineText(Scaffold):
+class EditInlineText:
     async def edit_inline_text(
-        self,
+        self: "pyrogram.Client",
         inline_message_id: str,
         text: str,
         parse_mode: Optional["enums.ParseMode"] = None,
diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py
index e368d4f57c..fc92b02f1f 100644
--- a/pyrogram/methods/messages/edit_message_caption.py
+++ b/pyrogram/methods/messages/edit_message_caption.py
@@ -18,13 +18,13 @@
 
 from typing import Union, List, Optional
 
+import pyrogram
 from pyrogram import types, enums
-from pyrogram.scaffold import Scaffold
 
 
-class EditMessageCaption(Scaffold):
+class EditMessageCaption:
     async def edit_message_caption(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         caption: str,
diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py
index 4e443e71c0..1593bfb6f8 100644
--- a/pyrogram/methods/messages/edit_message_media.py
+++ b/pyrogram/methods/messages/edit_message_media.py
@@ -20,16 +20,16 @@
 import re
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class EditMessageMedia(Scaffold):
+class EditMessageMedia:
     async def edit_message_media(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         media: "types.InputMedia",
diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py
index 2bbe1bc9b0..91b6fcd3e2 100644
--- a/pyrogram/methods/messages/edit_message_reply_markup.py
+++ b/pyrogram/methods/messages/edit_message_reply_markup.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class EditMessageReplyMarkup(Scaffold):
+class EditMessageReplyMarkup:
     async def edit_message_reply_markup(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         reply_markup: "types.InlineKeyboardMarkup" = None,
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index c58429a257..0f409cfe0a 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -18,15 +18,15 @@
 
 from typing import Union, List, Optional
 
+import pyrogram
 from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class EditMessageText(Scaffold):
+class EditMessageText:
     async def edit_message_text(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         text: str,
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index acddd6e65e..12ed56aa97 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union, Iterable, List
 
+import pyrogram
 from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class ForwardMessages(Scaffold):
+class ForwardMessages:
     async def forward_messages(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         from_chat_id: Union[int, str],
         message_ids: Union[int, Iterable[int]],
diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py
index c7d47261fa..f1de459234 100644
--- a/pyrogram/methods/messages/get_discussion_message.py
+++ b/pyrogram/methods/messages/get_discussion_message.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetDiscussionMessage(Scaffold):
+class GetDiscussionMessage:
     async def get_discussion_message(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
     ) -> "types.Message":
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
index a461b72007..a67d971e65 100644
--- a/pyrogram/methods/messages/get_history.py
+++ b/pyrogram/methods/messages/get_history.py
@@ -20,17 +20,17 @@
 from datetime import datetime
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetHistory(Scaffold):
+class GetHistory:
     async def get_history(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         limit: int = 100,
         offset: int = 0,
diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_history_count.py
index 9facdbebac..a76c10b51d 100644
--- a/pyrogram/methods/messages/get_history_count.py
+++ b/pyrogram/methods/messages/get_history_count.py
@@ -19,15 +19,15 @@
 import logging
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetHistoryCount(Scaffold):
+class GetHistoryCount:
     async def get_history_count(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> int:
         """Get the total count of messages in a chat.
diff --git a/pyrogram/methods/messages/get_media_group.py b/pyrogram/methods/messages/get_media_group.py
index 3b33bfd4a9..b50d4785af 100644
--- a/pyrogram/methods/messages/get_media_group.py
+++ b/pyrogram/methods/messages/get_media_group.py
@@ -19,15 +19,15 @@
 import logging
 from typing import Union, List
 
+import pyrogram
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class GetMediaGroup(Scaffold):
+class GetMediaGroup:
     async def get_media_group(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int
     ) -> List["types.Message"]:
diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py
index b9c0fbf7ca..e9e408b5e2 100644
--- a/pyrogram/methods/messages/get_messages.py
+++ b/pyrogram/methods/messages/get_messages.py
@@ -19,10 +19,10 @@
 import logging
 from typing import Union, Iterable, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
@@ -30,9 +30,9 @@
 # TODO: Rewrite using a flag for replied messages and have message_ids non-optional
 
 
-class GetMessages(Scaffold):
+class GetMessages:
     async def get_messages(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_ids: Union[int, Iterable[int]] = None,
         reply_to_message_ids: Union[int, Iterable[int]] = None,
diff --git a/pyrogram/methods/messages/iter_history.py b/pyrogram/methods/messages/iter_history.py
index c5eda28871..4914cd1d41 100644
--- a/pyrogram/methods/messages/iter_history.py
+++ b/pyrogram/methods/messages/iter_history.py
@@ -19,13 +19,13 @@
 from datetime import datetime
 from typing import Union, Optional, AsyncGenerator
 
+import pyrogram
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class IterHistory(Scaffold):
+class IterHistory:
     async def iter_history(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         limit: int = 0,
         offset: int = 0,
diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_history.py
index 881b59ad7c..66b8bf50f7 100644
--- a/pyrogram/methods/messages/read_history.py
+++ b/pyrogram/methods/messages/read_history.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class ReadHistory(Scaffold):
+class ReadHistory:
     async def read_history(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         max_id: int = 0
     ) -> bool:
diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py
index 4baba81157..f49807cd7a 100644
--- a/pyrogram/methods/messages/retract_vote.py
+++ b/pyrogram/methods/messages/retract_vote.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class RetractVote(Scaffold):
+class RetractVote:
     async def retract_vote(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int
     ) -> "types.Poll":
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index 6dff7bf0af..3f0d4e9ff3 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -18,15 +18,15 @@
 
 from typing import AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class SearchGlobal(Scaffold):
+class SearchGlobal:
     async def search_global(
-        self,
+        self: "pyrogram.Client",
         query: str = "",
         filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
         limit: int = 0,
diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py
index d8da0163e5..c848546ef3 100644
--- a/pyrogram/methods/messages/search_global_count.py
+++ b/pyrogram/methods/messages/search_global_count.py
@@ -16,13 +16,13 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw, enums
-from pyrogram.scaffold import Scaffold
 
 
-class SearchGlobalCount(Scaffold):
+class SearchGlobalCount:
     async def search_global_count(
-        self,
+        self: "pyrogram.Client",
         query: str = "",
         filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
     ) -> int:
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index 07728193e4..b448a1c204 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -18,13 +18,13 @@
 
 from typing import Union, List, AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import raw, types, utils, enums
-from pyrogram.scaffold import Scaffold
 
 
 # noinspection PyShadowingBuiltins
 async def get_chunk(
-    client: Scaffold,
+    client,
     chat_id: Union[int, str],
     query: str = "",
     filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
@@ -57,10 +57,10 @@ async def get_chunk(
     return await utils.parse_messages(client, r)
 
 
-class SearchMessages(Scaffold):
+class SearchMessages:
     # noinspection PyShadowingBuiltins
     async def search_messages(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         query: str = "",
         offset: int = 0,
diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py
index 87e0a74572..85c25d0618 100644
--- a/pyrogram/methods/messages/search_messages_count.py
+++ b/pyrogram/methods/messages/search_messages_count.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw, enums
-from pyrogram.scaffold import Scaffold
 
 
-class SearchMessagesCount(Scaffold):
+class SearchMessagesCount:
     async def search_messages_count(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         query: str = "",
         filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 4e6a9f407b..2e84fe8267 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -19,20 +19,20 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, List, Optional
+from typing import Union, BinaryIO, List, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendAnimation(Scaffold):
+class SendAnimation:
     async def send_animation(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         animation: Union[str, BinaryIO],
         caption: str = "",
@@ -54,7 +54,7 @@ async def send_animation(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send animation files (animation or H.264/MPEG-4 AVC video without sound).
@@ -122,7 +122,7 @@ async def send_animation(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 6cef5b47dd..47e914a8b4 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -18,21 +18,21 @@
 
 import os
 import re
-from typing import Union, BinaryIO, List, Optional
+from datetime import datetime
+from typing import Union, BinaryIO, List, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
-from datetime import datetime
 
 
-class SendAudio(Scaffold):
+class SendAudio:
     async def send_audio(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         audio: Union[str, BinaryIO],
         caption: str = "",
@@ -53,7 +53,7 @@ async def send_audio(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send audio files.
@@ -119,7 +119,7 @@ async def send_audio(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 60832553fb..4763e94d46 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -19,15 +19,15 @@
 from datetime import datetime
 from typing import Union, List, Optional
 
+import pyrogram
 from pyrogram import raw, enums
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class SendCachedMedia(Scaffold):
+class SendCachedMedia:
     async def send_cached_media(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         file_id: str,
         caption: str = "",
diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py
index bbff1d4421..9145653e7a 100644
--- a/pyrogram/methods/messages/send_chat_action.py
+++ b/pyrogram/methods/messages/send_chat_action.py
@@ -20,12 +20,11 @@
 
 import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SendChatAction(Scaffold):
+class SendChatAction:
     async def send_chat_action(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         action: "pyrogram.enums.ChatAction"
     ) -> bool:
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index f9c84f4c9f..6285b502ff 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+import pyrogram
+from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SendContact(Scaffold):
+class SendContact:
     async def send_contact(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         phone_number: str,
         first_name: str,
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index 9c7f5d1a70..c3a6bb42fb 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -16,17 +16,17 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union, Optional
 
-from pyrogram import raw
+import pyrogram
+from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
-from datetime import datetime
 
 
-class SendDice(Scaffold):
+class SendDice:
     async def send_dice(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         emoji: str = "🎲",
         disable_notification: bool = None,
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 5844d2d232..79f6e160ef 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -19,20 +19,20 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, List, Optional
+from typing import Union, BinaryIO, List, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendDocument(Scaffold):
+class SendDocument:
     async def send_document(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         document: Union[str, BinaryIO],
         thumb: Union[str, BinaryIO] = None,
@@ -51,7 +51,7 @@ async def send_document(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send generic files.
@@ -111,7 +111,7 @@ async def send_document(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py
index 6c33c1b4fc..3e9bf37c75 100644
--- a/pyrogram/methods/messages/send_location.py
+++ b/pyrogram/methods/messages/send_location.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+import pyrogram
+from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SendLocation(Scaffold):
+class SendLocation:
     async def send_location(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         latitude: float,
         longitude: float,
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index 04c91c3b44..ccb6136163 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -22,19 +22,19 @@
 from datetime import datetime
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class SendMediaGroup(Scaffold):
+class SendMediaGroup:
     # TODO: Add progress parameter
     async def send_media_group(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         media: List[Union[
             "types.InputMediaPhoto",
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 34063625dd..70544178f9 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -16,18 +16,17 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from datetime import datetime
 from typing import Union, List, Optional
 
+import pyrogram
 from pyrogram import raw, utils, enums
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
-
-from datetime import datetime
 
 
-class SendMessage(Scaffold):
+class SendMessage:
     async def send_message(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         text: str,
         parse_mode: Optional["enums.ParseMode"] = None,
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index bf7b482cbe..5cacfb39c3 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -19,7 +19,7 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, List, Optional
+from typing import Union, BinaryIO, List, Optional, Callable
 
 import pyrogram
 from pyrogram import raw, enums
@@ -27,12 +27,11 @@
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendPhoto(Scaffold):
+class SendPhoto:
     async def send_photo(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         photo: Union[str, BinaryIO],
         caption: str = "",
@@ -49,7 +48,7 @@ async def send_photo(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send photos.
@@ -99,7 +98,7 @@ async def send_photo(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index a02c52663c..10545256eb 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union, List
 
-from pyrogram import raw
+import pyrogram
+from pyrogram import raw, utils
 from pyrogram import types, enums
-from pyrogram.scaffold import Scaffold
 
 
-class SendPoll(Scaffold):
+class SendPoll:
     async def send_poll(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         question: str,
         options: List[str],
diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py
index 9e6c353cd1..b096934fc2 100644
--- a/pyrogram/methods/messages/send_reaction.py
+++ b/pyrogram/methods/messages/send_reaction.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SendReaction(Scaffold):
+class SendReaction:
     async def send_reaction(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         emoji: str = ""
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index 76571d9999..460cfc6304 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -19,20 +19,20 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, Optional
+from typing import Union, BinaryIO, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendSticker(Scaffold):
+class SendSticker:
     async def send_sticker(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         sticker: Union[str, BinaryIO],
         disable_notification: bool = None,
@@ -45,7 +45,7 @@ async def send_sticker(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send static .webp or animated .tgs stickers.
@@ -80,7 +80,7 @@ async def send_sticker(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py
index 5293cf01df..4dd81f7a3f 100644
--- a/pyrogram/methods/messages/send_venue.py
+++ b/pyrogram/methods/messages/send_venue.py
@@ -19,14 +19,14 @@
 from datetime import datetime
 from typing import Union
 
-from pyrogram import raw
+import pyrogram
+from pyrogram import raw, utils
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class SendVenue(Scaffold):
+class SendVenue:
     async def send_venue(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         latitude: float,
         longitude: float,
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index 96f2a9c3bb..9fd8521358 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -19,20 +19,20 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, List, Optional
+from typing import Union, BinaryIO, List, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendVideo(Scaffold):
+class SendVideo:
     async def send_video(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         video: Union[str, BinaryIO],
         caption: str = "",
@@ -55,7 +55,7 @@ async def send_video(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send video files.
@@ -128,7 +128,7 @@ async def send_video(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index c2f0a159ab..b4fd8891f5 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -18,20 +18,20 @@
 
 import os
 from datetime import datetime
-from typing import Union, BinaryIO, Optional
+from typing import Union, BinaryIO, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendVideoNote(Scaffold):
+class SendVideoNote:
     async def send_video_note(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         video_note: Union[str, BinaryIO],
         duration: int = 0,
@@ -47,7 +47,7 @@ async def send_video_note(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send video messages.
@@ -94,7 +94,7 @@ async def send_video_note(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 79fefcab1d..5179866e0d 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -19,20 +19,20 @@
 import os
 import re
 from datetime import datetime
-from typing import Union, BinaryIO, List, Optional
+from typing import Union, BinaryIO, List, Optional, Callable
 
+import pyrogram
 from pyrogram import StopTransmission, enums
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
 from pyrogram.errors import FilePartMissing
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class SendVoice(Scaffold):
+class SendVoice:
     async def send_voice(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         voice: Union[str, BinaryIO],
         caption: str = "",
@@ -49,7 +49,7 @@ async def send_voice(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> Optional["types.Message"]:
         """Send audio files.
@@ -97,7 +97,7 @@ async def send_voice(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py
index 113f1618aa..3fdba750d3 100644
--- a/pyrogram/methods/messages/stop_poll.py
+++ b/pyrogram/methods/messages/stop_poll.py
@@ -18,14 +18,14 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class StopPoll(Scaffold):
+class StopPoll:
     async def stop_poll(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: int,
         reply_markup: "types.InlineKeyboardMarkup" = None
diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py
index d6753a275a..70a5036574 100644
--- a/pyrogram/methods/messages/vote_poll.py
+++ b/pyrogram/methods/messages/vote_poll.py
@@ -18,14 +18,14 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class VotePoll(Scaffold):
+class VotePoll:
     async def vote_poll(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         message_id: id,
         options: Union[int, List[int]]
diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py
index f950c65a70..a0e8296382 100644
--- a/pyrogram/methods/password/change_cloud_password.py
+++ b/pyrogram/methods/password/change_cloud_password.py
@@ -18,14 +18,14 @@
 
 import os
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 from pyrogram.utils import compute_password_hash, compute_password_check, btoi, itob
 
 
-class ChangeCloudPassword(Scaffold):
+class ChangeCloudPassword:
     async def change_cloud_password(
-        self,
+        self: "pyrogram.Client",
         current_password: str,
         new_password: str,
         new_hint: str = ""
diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py
index 7073af59c2..840acfdd49 100644
--- a/pyrogram/methods/password/enable_cloud_password.py
+++ b/pyrogram/methods/password/enable_cloud_password.py
@@ -18,14 +18,14 @@
 
 import os
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 from pyrogram.utils import compute_password_hash, btoi, itob
 
 
-class EnableCloudPassword(Scaffold):
+class EnableCloudPassword:
     async def enable_cloud_password(
-        self,
+        self: "pyrogram.Client",
         password: str,
         hint: str = "",
         email: str = None
diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py
index 18ae31e5c1..1a1c9a0b56 100644
--- a/pyrogram/methods/password/remove_cloud_password.py
+++ b/pyrogram/methods/password/remove_cloud_password.py
@@ -16,14 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 from pyrogram.utils import compute_password_check
 
 
-class RemoveCloudPassword(Scaffold):
+class RemoveCloudPassword:
     async def remove_cloud_password(
-        self,
+        self: "pyrogram.Client",
         password: str
     ) -> bool:
         """Turn off the Two-Step Verification security feature (Cloud Password) on your account.
diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py
index 0efda2b9a8..b1d96537fb 100644
--- a/pyrogram/methods/users/block_user.py
+++ b/pyrogram/methods/users/block_user.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class BlockUser(Scaffold):
+class BlockUser:
     async def block_user(
-        self,
+        self: "pyrogram.Client",
         user_id: Union[int, str]
     ) -> bool:
         """Block a user.
diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py
index 64f3ce7763..a1df82eb7a 100644
--- a/pyrogram/methods/users/delete_profile_photos.py
+++ b/pyrogram/methods/users/delete_profile_photos.py
@@ -18,15 +18,15 @@
 
 from typing import List, Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import utils
 from pyrogram.file_id import FileType
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteProfilePhotos(Scaffold):
+class DeleteProfilePhotos:
     async def delete_profile_photos(
-        self,
+        self: "pyrogram.Client",
         photo_ids: Union[str, List[str]]
     ) -> bool:
         """Delete your own profile photos.
diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py
index 7969647a0c..e083e3c981 100644
--- a/pyrogram/methods/users/get_common_chats.py
+++ b/pyrogram/methods/users/get_common_chats.py
@@ -18,13 +18,16 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetCommonChats(Scaffold):
-    async def get_common_chats(self, user_id: Union[int, str]) -> list:
+class GetCommonChats:
+    async def get_common_chats(
+        self: "pyrogram.Client",
+        user_id: Union[int, str]
+    ) -> list:
         """Get the common chats you have with a user.
 
         Parameters:
diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py
index b7ebf2d745..17ffe3b837 100644
--- a/pyrogram/methods/users/get_me.py
+++ b/pyrogram/methods/users/get_me.py
@@ -16,13 +16,15 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetMe(Scaffold):
-    async def get_me(self) -> "types.User":
+class GetMe:
+    async def get_me(
+        self: "pyrogram.Client"
+    ) -> "types.User":
         """Get your own user identity.
 
         Returns:
diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py
index fb8c75c497..62341550dd 100644
--- a/pyrogram/methods/users/get_profile_photos.py
+++ b/pyrogram/methods/users/get_profile_photos.py
@@ -18,15 +18,15 @@
 
 from typing import Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
 from pyrogram import utils
-from pyrogram.scaffold import Scaffold
 
 
-class GetProfilePhotos(Scaffold):
+class GetProfilePhotos:
     async def get_profile_photos(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         offset: int = 0,
         limit: int = 100
diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py
index dcb7ee4b4c..c0065dd7e0 100644
--- a/pyrogram/methods/users/get_profile_photos_count.py
+++ b/pyrogram/methods/users/get_profile_photos_count.py
@@ -18,12 +18,15 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class GetProfilePhotosCount(Scaffold):
-    async def get_profile_photos_count(self, chat_id: Union[int, str]) -> int:
+class GetProfilePhotosCount:
+    async def get_profile_photos_count(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str]
+    ) -> int:
         """Get the total count of profile pictures for a user.
 
         Parameters:
diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py
index 43ae008423..0e9c961411 100644
--- a/pyrogram/methods/users/get_users.py
+++ b/pyrogram/methods/users/get_users.py
@@ -19,14 +19,14 @@
 import asyncio
 from typing import Iterable, Union, List
 
+import pyrogram
 from pyrogram import raw
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class GetUsers(Scaffold):
+class GetUsers:
     async def get_users(
-        self,
+        self: "pyrogram.Client",
         user_ids: Union[Iterable[Union[int, str]], int, str]
     ) -> Union["types.User", List["types.User"]]:
         """Get information about a user.
diff --git a/pyrogram/methods/users/iter_profile_photos.py b/pyrogram/methods/users/iter_profile_photos.py
index eda77a8889..88c02c3a54 100644
--- a/pyrogram/methods/users/iter_profile_photos.py
+++ b/pyrogram/methods/users/iter_profile_photos.py
@@ -18,13 +18,13 @@
 
 from typing import Union, AsyncGenerator, Optional
 
+import pyrogram
 from pyrogram import types
-from pyrogram.scaffold import Scaffold
 
 
-class IterProfilePhotos(Scaffold):
+class IterProfilePhotos:
     async def iter_profile_photos(
-        self,
+        self: "pyrogram.Client",
         chat_id: Union[int, str],
         offset: int = 0,
         limit: int = 0,
diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py
index 9b1c5c04c5..a68db7cda2 100644
--- a/pyrogram/methods/users/set_profile_photo.py
+++ b/pyrogram/methods/users/set_profile_photo.py
@@ -18,13 +18,13 @@
 
 from typing import Union, BinaryIO
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetProfilePhoto(Scaffold):
+class SetProfilePhoto:
     async def set_profile_photo(
-        self,
+        self: "pyrogram.Client",
         *,
         photo: Union[str, BinaryIO] = None,
         video: Union[str, BinaryIO] = None
diff --git a/pyrogram/methods/users/set_username.py b/pyrogram/methods/users/set_username.py
index 881f2ae685..eeffc25f6c 100644
--- a/pyrogram/methods/users/set_username.py
+++ b/pyrogram/methods/users/set_username.py
@@ -18,13 +18,13 @@
 
 from typing import Optional
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class SetUsername(Scaffold):
+class SetUsername:
     async def set_username(
-        self,
+        self: "pyrogram.Client",
         username: Optional[str]
     ) -> bool:
         """Set your own username.
diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py
index 4218bb1e55..433105acf1 100644
--- a/pyrogram/methods/users/unblock_user.py
+++ b/pyrogram/methods/users/unblock_user.py
@@ -18,13 +18,13 @@
 
 from typing import Union
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UnblockUser(Scaffold):
+class UnblockUser:
     async def unblock_user(
-        self,
+        self: "pyrogram.Client",
         user_id: Union[int, str]
     ) -> bool:
         """Unblock a user.
diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py
index 4dc81204e4..c77c8b4b5b 100644
--- a/pyrogram/methods/users/update_profile.py
+++ b/pyrogram/methods/users/update_profile.py
@@ -16,13 +16,13 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 
-class UpdateProfile(Scaffold):
+class UpdateProfile:
     async def update_profile(
-        self,
+        self: "pyrogram.Client",
         first_name: str = None,
         last_name: str = None,
         bio: str = None
diff --git a/pyrogram/methods/utilities/add_handler.py b/pyrogram/methods/utilities/add_handler.py
index d0ef15ff64..12b41bfe60 100644
--- a/pyrogram/methods/utilities/add_handler.py
+++ b/pyrogram/methods/utilities/add_handler.py
@@ -16,13 +16,17 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram.handlers import DisconnectHandler
 from pyrogram.handlers.handler import Handler
-from pyrogram.scaffold import Scaffold
 
 
-class AddHandler(Scaffold):
-    def add_handler(self, handler: "Handler", group: int = 0):
+class AddHandler:
+    def add_handler(
+        self: "pyrogram.Client",
+        handler: "Handler",
+        group: int = 0
+    ):
         """Register an update handler.
 
         You can register multiple handlers, but at most one handler within a group will be used for a single update.
diff --git a/pyrogram/methods/utilities/export_session_string.py b/pyrogram/methods/utilities/export_session_string.py
index cd1741bdb4..8177c456a9 100644
--- a/pyrogram/methods/utilities/export_session_string.py
+++ b/pyrogram/methods/utilities/export_session_string.py
@@ -16,11 +16,13 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 
 
-class ExportSessionString(Scaffold):
-    async def export_session_string(self):
+class ExportSessionString:
+    async def export_session_string(
+        self: "pyrogram.Client"
+    ):
         """Export the current authorized session as a serialized string.
 
         Session strings are useful for storing in-memory authorized sessions in a portable, serialized string.
diff --git a/pyrogram/methods/utilities/remove_handler.py b/pyrogram/methods/utilities/remove_handler.py
index 12be00b481..fca4a879a9 100644
--- a/pyrogram/methods/utilities/remove_handler.py
+++ b/pyrogram/methods/utilities/remove_handler.py
@@ -16,13 +16,17 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+import pyrogram
 from pyrogram.handlers import DisconnectHandler
 from pyrogram.handlers.handler import Handler
-from pyrogram.scaffold import Scaffold
 
 
-class RemoveHandler(Scaffold):
-    def remove_handler(self, handler: "Handler", group: int = 0):
+class RemoveHandler:
+    def remove_handler(
+        self: "pyrogram.Client",
+        handler: "Handler",
+        group: int = 0
+    ):
         """Remove a previously-registered update handler.
 
         Make sure to provide the right group where the handler was added in. You can use the return value of the
diff --git a/pyrogram/methods/utilities/restart.py b/pyrogram/methods/utilities/restart.py
index e750137fa4..66c246085f 100644
--- a/pyrogram/methods/utilities/restart.py
+++ b/pyrogram/methods/utilities/restart.py
@@ -16,11 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 
 
-class Restart(Scaffold):
-    async def restart(self, block: bool = True):
+class Restart:
+    async def restart(
+        self: "pyrogram.Client",
+        block: bool = True
+    ):
         """Restart the Client.
 
         This method will first call :meth:`~pyrogram.Client.stop` and then :meth:`~pyrogram.Client.start` in a row in
diff --git a/pyrogram/methods/utilities/run.py b/pyrogram/methods/utilities/run.py
index 40decbbd82..6247b936c9 100644
--- a/pyrogram/methods/utilities/run.py
+++ b/pyrogram/methods/utilities/run.py
@@ -19,12 +19,15 @@
 import asyncio
 import inspect
 
+import pyrogram
 from pyrogram.methods.utilities.idle import idle
-from pyrogram.scaffold import Scaffold
 
 
-class Run(Scaffold):
-    def run(self, coroutine=None):
+class Run:
+    def run(
+        self: "pyrogram.Client",
+        coroutine=None
+    ):
         """Start the client, idle the main script and finally stop the client.
 
         This is a convenience method that calls :meth:`~pyrogram.Client.start`, :meth:`~pyrogram.idle` and
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index a8144d3ff5..61ce87a24a 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -18,14 +18,16 @@
 
 import logging
 
+import pyrogram
 from pyrogram import raw
-from pyrogram.scaffold import Scaffold
 
 log = logging.getLogger(__name__)
 
 
-class Start(Scaffold):
-    async def start(self):
+class Start:
+    async def start(
+        self: "pyrogram.Client"
+    ):
         """Start the client.
 
         This method connects the client to Telegram and, in case of new sessions, automatically manages the full
diff --git a/pyrogram/methods/utilities/stop.py b/pyrogram/methods/utilities/stop.py
index 3536caa1e2..92b99fc5f3 100644
--- a/pyrogram/methods/utilities/stop.py
+++ b/pyrogram/methods/utilities/stop.py
@@ -16,11 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from pyrogram.scaffold import Scaffold
+import pyrogram
 
 
-class Stop(Scaffold):
-    async def stop(self, block: bool = True):
+class Stop:
+    async def stop(
+        self: "pyrogram.Client",
+        block: bool = True
+    ):
         """Stop the Client.
 
         This method disconnects the client from Telegram and stops the underlying tasks.
diff --git a/pyrogram/methods/utilities/stop_transmission.py b/pyrogram/methods/utilities/stop_transmission.py
index 70bd58d450..0639eab8f3 100644
--- a/pyrogram/methods/utilities/stop_transmission.py
+++ b/pyrogram/methods/utilities/stop_transmission.py
@@ -17,10 +17,9 @@
 #  along with Pyrogram.  If not, see .
 
 import pyrogram
-from pyrogram.scaffold import Scaffold
 
 
-class StopTransmission(Scaffold):
+class StopTransmission:
     def stop_transmission(self):
         """Stop downloading or uploading a file.
 
diff --git a/pyrogram/scaffold.py b/pyrogram/scaffold.py
deleted file mode 100644
index d87d1522c8..0000000000
--- a/pyrogram/scaffold.py
+++ /dev/null
@@ -1,201 +0,0 @@
-#  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-present Dan 
-#
-#  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 asyncio
-import os
-import platform
-import re
-import sys
-from io import StringIO
-from mimetypes import MimeTypes
-from pathlib import Path
-
-import pyrogram
-from pyrogram import __version__, enums
-from pyrogram.parser import Parser
-from pyrogram.session.internals import MsgId
-from .mime_types import mime_types
-
-
-class Scaffold:
-    APP_VERSION = f"Pyrogram {__version__}"
-    DEVICE_MODEL = f"{platform.python_implementation()} {platform.python_version()}"
-    SYSTEM_VERSION = f"{platform.system()} {platform.release()}"
-
-    LANG_CODE = "en"
-
-    PARENT_DIR = Path(sys.argv[0]).parent
-
-    INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:joinchat/|\+))([\w-]+)$")
-    WORKERS = min(32, os.cpu_count() + 4)
-    WORKDIR = PARENT_DIR
-    CONFIG_FILE = PARENT_DIR / "config.ini"
-
-    mimetypes = MimeTypes()
-    mimetypes.readfp(StringIO(mime_types))
-
-    def __init__(self):
-        try:
-            asyncio.get_event_loop()
-        except RuntimeError:
-            # This happens when creating Client instances inside different threads that don't have an event loop.
-            # Set the main event loop in this thread.
-            asyncio.set_event_loop(pyrogram.main_event_loop)
-
-        self.session_name = None
-        self.api_id = None
-        self.api_hash = None
-        self.app_version = None
-        self.device_model = None
-        self.system_version = None
-        self.lang_code = None
-        self.ipv6 = None
-        self.proxy = None
-        self.test_mode = None
-        self.bot_token = None
-        self.phone_number = None
-        self.phone_code = None
-        self.password = None
-        self.force_sms = None
-        self.workers = None
-        self.workdir = None
-        self.config_file = None
-        self.plugins = None
-        self.parse_mode = None
-        self.no_updates = None
-        self.takeout = None
-        self.sleep_threshold = None
-
-        self.executor = None
-
-        self.storage = None
-
-        self.rnd_id = MsgId
-
-        self.parser = Parser(self)
-        self.parse_mode = enums.ParseMode.DEFAULT
-
-        self.session = None
-
-        self.media_sessions = {}
-        self.media_sessions_lock = asyncio.Lock()
-
-        self.is_connected = None
-        self.is_initialized = None
-
-        self.no_updates = None
-        self.takeout_id = None
-
-        self.dispatcher = None
-
-        self.disconnect_handler = None
-
-        self.loop = None
-
-    async def send(self, *args, **kwargs):
-        pass
-
-    async def resolve_peer(self, *args, **kwargs):
-        pass
-
-    def fetch_peers(self, *args, **kwargs):
-        pass
-
-    def add_handler(self, *args, **kwargs):
-        pass
-
-    async def save_file(self, *args, **kwargs):
-        pass
-
-    async def get_messages(self, *args, **kwargs):
-        pass
-
-    async def get_history(self, *args, **kwargs):
-        pass
-
-    async def get_dialogs(self, *args, **kwargs):
-        pass
-
-    async def get_chat_members(self, *args, **kwargs):
-        pass
-
-    async def get_chat_members_count(self, *args, **kwargs):
-        pass
-
-    async def answer_inline_query(self, *args, **kwargs):
-        pass
-
-    async def get_profile_photos(self, *args, **kwargs):
-        pass
-
-    async def edit_message_text(self, *args, **kwargs):
-        pass
-
-    async def edit_inline_text(self, *args, **kwargs):
-        pass
-
-    async def edit_message_media(self, *args, **kwargs):
-        pass
-
-    async def edit_inline_media(self, *args, **kwargs):
-        pass
-
-    async def edit_message_reply_markup(self, *args, **kwargs):
-        pass
-
-    async def edit_inline_reply_markup(self, *args, **kwargs):
-        pass
-
-    def guess_mime_type(self, *args, **kwargs):
-        pass
-
-    def guess_extension(self, *args, **kwargs):
-        pass
-
-    def load_config(self, *args, **kwargs):
-        pass
-
-    def load_session(self, *args, **kwargs):
-        pass
-
-    def load_plugins(self, *args, **kwargs):
-        pass
-
-    async def handle_download(self, *args, **kwargs):
-        pass
-
-    async def start(self, *args, **kwargs):
-        pass
-
-    async def stop(self, *args, **kwargs):
-        pass
-
-    async def connect(self, *args, **kwargs):
-        pass
-
-    async def authorize(self, *args, **kwargs):
-        pass
-
-    async def disconnect(self, *args, **kwargs):
-        pass
-
-    async def initialize(self, *args, **kwargs):
-        pass
-
-    async def terminate(self, *args, **kwargs):
-        pass
diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py
index 06ab5f944e..a39021000f 100644
--- a/pyrogram/types/inline_mode/inline_query_result_audio.py
+++ b/pyrogram/types/inline_mode/inline_query_result_audio.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import Union, List, Optional
+from typing import List, Optional
 
 import pyrogram
 from pyrogram import raw, types, utils, enums
diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py
index 944d7e6e99..cbed4f0f9d 100644
--- a/pyrogram/types/messages_and_media/__init__.py
+++ b/pyrogram/types/messages_and_media/__init__.py
@@ -28,6 +28,7 @@
 from .photo import Photo
 from .poll import Poll
 from .poll_option import PollOption
+from .reaction import Reaction
 from .sticker import Sticker
 from .stripped_thumbnail import StrippedThumbnail
 from .thumbnail import Thumbnail
@@ -36,7 +37,6 @@
 from .video_note import VideoNote
 from .voice import Voice
 from .webpage import WebPage
-from .reaction import Reaction
 
 __all__ = [
     "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 56ffd691bd..e9f3cab6d2 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -19,7 +19,7 @@
 import logging
 from datetime import datetime
 from functools import partial
-from typing import List, Match, Union, BinaryIO, Optional
+from typing import List, Match, Union, BinaryIO, Optional, Callable
 
 import pyrogram
 from pyrogram import raw, enums
@@ -867,7 +867,7 @@ async def reply_text(
         reply_to_message_id: int = None,
         schedule_date: datetime = None,
         protect_content: bool = None,
-        reply_markup = None
+        reply_markup=None
     ) -> "Message":
         """Bound method *reply_text* of :obj:`~pyrogram.types.Message`.
 
@@ -970,7 +970,7 @@ async def reply_animation(
             "types.ForceReply"
         ] = None,
         reply_to_message_id: int = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_animation* :obj:`~pyrogram.types.Message`.
@@ -1037,7 +1037,7 @@ async def reply_animation(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -1109,7 +1109,7 @@ async def reply_audio(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_audio* of :obj:`~pyrogram.types.Message`.
@@ -1176,7 +1176,7 @@ async def reply_audio(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -1457,7 +1457,7 @@ async def reply_document(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_document* of :obj:`~pyrogram.types.Message`.
@@ -1527,7 +1527,7 @@ async def reply_document(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -1865,7 +1865,7 @@ async def reply_photo(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_photo* of :obj:`~pyrogram.types.Message`.
@@ -1922,7 +1922,7 @@ async def reply_photo(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -2088,7 +2088,7 @@ async def reply_sticker(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_sticker* of :obj:`~pyrogram.types.Message`.
@@ -2130,7 +2130,7 @@ async def reply_sticker(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -2295,7 +2295,7 @@ async def reply_video(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_video* of :obj:`~pyrogram.types.Message`.
@@ -2370,7 +2370,7 @@ async def reply_video(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -2440,7 +2440,7 @@ async def reply_video_note(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_video_note* of :obj:`~pyrogram.types.Message`.
@@ -2494,7 +2494,7 @@ async def reply_video_note(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -2559,7 +2559,7 @@ async def reply_voice(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> "Message":
         """Bound method *reply_voice* of :obj:`~pyrogram.types.Message`.
@@ -2614,7 +2614,7 @@ async def reply_voice(
                 Additional interface options. An object for an inline keyboard, custom reply keyboard,
                 instructions to remove reply keyboard or to force a reply from the user.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
@@ -3321,7 +3321,7 @@ async def download(
         self,
         file_name: str = "",
         block: bool = True,
-        progress: callable = None,
+        progress: Callable = None,
         progress_args: tuple = ()
     ) -> str:
         """Bound method *download* of :obj:`~pyrogram.types.Message`.
@@ -3348,7 +3348,7 @@ async def download(
                 Blocks the code execution until the file has been downloaded.
                 Defaults to True.
 
-            progress (``callable``, *optional*):
+            progress (``Callable``, *optional*):
                 Pass a callback function to view the file transmission progress.
                 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                 detailed description) and will be called back each time a new file chunk has been successfully
diff --git a/pyrogram/types/messages_and_media/video_note.py b/pyrogram/types/messages_and_media/video_note.py
index 450d536db1..3e6b40d0c9 100644
--- a/pyrogram/types/messages_and_media/video_note.py
+++ b/pyrogram/types/messages_and_media/video_note.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 datetime import datetime
 from typing import List
 
 import pyrogram
@@ -23,7 +24,6 @@
 from pyrogram import types
 from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
 from ..object import Object
-from datetime import datetime
 
 
 class VideoNote(Object):
diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py
index 601bcd6e6f..caf18373e1 100644
--- a/pyrogram/types/object.py
+++ b/pyrogram/types/object.py
@@ -24,12 +24,7 @@
 import pyrogram
 
 
-class Meta(type, metaclass=type("", (type,), {"__str__": lambda _: "~hi"})):
-    def __str__(self):
-        return f""
-
-
-class Object(metaclass=Meta):
+class Object:
     def __init__(self, client: "pyrogram.Client" = None):
         self._client = client
 
diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py
index fa539be868..a5292c6418 100644
--- a/pyrogram/types/user_and_chats/chat_event.py
+++ b/pyrogram/types/user_and_chats/chat_event.py
@@ -254,10 +254,10 @@ def __init__(
 
     @staticmethod
     async def _parse(
-            client: "pyrogram.Client",
-            event: "raw.base.ChannelAdminLogEvent",
-            users: List["raw.base.User"],
-            chats: List["raw.base.Chat"]
+        client: "pyrogram.Client",
+        event: "raw.base.ChannelAdminLogEvent",
+        users: List["raw.base.User"],
+        chats: List["raw.base.Chat"]
     ):
         users = {i.id: i for i in users}
         chats = {i.id: i for i in chats}
diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index 06f45b8d34..9b585d7cb5 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -108,8 +108,8 @@ def __init__(
 
     @staticmethod
     def _parse(
-            client: "pyrogram.Client",
-            member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
+        client: "pyrogram.Client",
+        member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
         users: Dict[int, "raw.base.User"],
         chats: Dict[int, "raw.base.Chat"]
     ) -> "ChatMember":
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index 60f6ca9d8a..b3f04e6018 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -297,7 +297,7 @@ async def parse_text_entities(
     text: str,
     parse_mode: enums.ParseMode,
     entities: List["types.MessageEntity"]
-) -> Dict[str, raw.base.MessageEntity]:
+) -> Dict[str, Union[str, List[raw.base.MessageEntity]]]:
     if entities:
         # Inject the client instance because parsing user mentions requires it
         for entity in entities:

From 4f6ce8bec17af1ab76ca7832d3d4167c028ec483 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:06 +0200
Subject: [PATCH 143/539] Add pyproject.toml

---
 pyproject.toml | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 pyproject.toml

diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000000..07de284aa5
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools", "wheel"]
+build-backend = "setuptools.build_meta"
\ No newline at end of file

From 78efb04b404047cdd6a196f891324d5c779a383c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 144/539] Rename Client.send to Client.invoke

---
 pyrogram/client.py                            | 18 +++++------
 pyrogram/methods/advanced/__init__.py         |  6 ++--
 .../methods/advanced/{send.py => invoke.py}   | 18 +++++------
 pyrogram/methods/advanced/resolve_peer.py     |  8 ++---
 pyrogram/methods/advanced/save_file.py        |  2 +-
 .../methods/auth/accept_terms_of_service.py   |  2 +-
 pyrogram/methods/auth/check_password.py       |  4 +--
 pyrogram/methods/auth/get_password_hint.py    |  2 +-
 pyrogram/methods/auth/log_out.py              |  2 +-
 pyrogram/methods/auth/recover_password.py     |  2 +-
 pyrogram/methods/auth/resend_code.py          |  2 +-
 pyrogram/methods/auth/send_code.py            |  2 +-
 pyrogram/methods/auth/send_recovery_code.py   |  2 +-
 pyrogram/methods/auth/sign_in.py              |  2 +-
 pyrogram/methods/auth/sign_in_bot.py          |  2 +-
 pyrogram/methods/auth/sign_up.py              |  2 +-
 pyrogram/methods/auth/terminate.py            |  2 +-
 .../methods/bots/answer_callback_query.py     |  2 +-
 pyrogram/methods/bots/answer_inline_query.py  |  2 +-
 pyrogram/methods/bots/get_game_high_scores.py |  2 +-
 .../methods/bots/get_inline_bot_results.py    |  2 +-
 .../methods/bots/request_callback_answer.py   |  2 +-
 pyrogram/methods/bots/send_game.py            |  2 +-
 .../methods/bots/send_inline_bot_result.py    |  2 +-
 pyrogram/methods/bots/set_bot_commands.py     |  2 +-
 pyrogram/methods/bots/set_game_score.py       |  2 +-
 pyrogram/methods/chats/add_chat_members.py    |  4 +--
 pyrogram/methods/chats/archive_chats.py       |  2 +-
 pyrogram/methods/chats/ban_chat_member.py     |  4 +--
 pyrogram/methods/chats/create_channel.py      |  2 +-
 pyrogram/methods/chats/create_group.py        |  2 +-
 pyrogram/methods/chats/create_supergroup.py   |  2 +-
 pyrogram/methods/chats/delete_channel.py      |  2 +-
 pyrogram/methods/chats/delete_chat_photo.py   |  4 +--
 pyrogram/methods/chats/delete_supergroup.py   |  2 +-
 pyrogram/methods/chats/delete_user_history.py |  2 +-
 pyrogram/methods/chats/get_chat.py            |  8 ++---
 pyrogram/methods/chats/get_chat_event_log.py  |  2 +-
 pyrogram/methods/chats/get_chat_member.py     |  4 +--
 pyrogram/methods/chats/get_chat_members.py    |  4 +--
 .../methods/chats/get_chat_members_count.py   |  4 +--
 .../methods/chats/get_chat_online_count.py    |  2 +-
 pyrogram/methods/chats/get_dialogs.py         |  4 +--
 pyrogram/methods/chats/get_dialogs_count.py   |  4 +--
 pyrogram/methods/chats/get_nearby_chats.py    |  2 +-
 pyrogram/methods/chats/get_send_as_chats.py   |  2 +-
 pyrogram/methods/chats/iter_dialogs.py        |  2 +-
 pyrogram/methods/chats/join_chat.py           |  4 +--
 pyrogram/methods/chats/leave_chat.py          |  6 ++--
 pyrogram/methods/chats/mark_chat_unread.py    |  6 ++--
 pyrogram/methods/chats/pin_chat_message.py    |  2 +-
 pyrogram/methods/chats/promote_chat_member.py |  4 +--
 .../methods/chats/restrict_chat_member.py     |  2 +-
 .../methods/chats/set_administrator_title.py  |  4 +--
 .../methods/chats/set_chat_description.py     |  2 +-
 .../methods/chats/set_chat_permissions.py     |  2 +-
 pyrogram/methods/chats/set_chat_photo.py      |  4 +--
 .../chats/set_chat_protected_content.py       |  6 ++--
 pyrogram/methods/chats/set_chat_title.py      |  4 +--
 pyrogram/methods/chats/set_chat_username.py   |  2 +-
 pyrogram/methods/chats/set_send_as_chat.py    |  2 +-
 pyrogram/methods/chats/set_slow_mode.py       |  2 +-
 pyrogram/methods/chats/unarchive_chats.py     |  2 +-
 pyrogram/methods/chats/unban_chat_member.py   |  2 +-
 .../methods/chats/unpin_all_chat_messages.py  |  2 +-
 pyrogram/methods/chats/unpin_chat_message.py  |  2 +-
 pyrogram/methods/contacts/add_contact.py      |  2 +-
 pyrogram/methods/contacts/delete_contacts.py  |  2 +-
 pyrogram/methods/contacts/get_contacts.py     |  2 +-
 .../methods/contacts/get_contacts_count.py    |  2 +-
 pyrogram/methods/contacts/import_contacts.py  |  2 +-
 .../invite_links/approve_chat_join_request.py |  2 +-
 .../invite_links/create_chat_invite_link.py   |  2 +-
 .../invite_links/decline_chat_join_request.py |  2 +-
 .../delete_chat_admin_invite_links.py         |  2 +-
 .../invite_links/delete_chat_invite_link.py   |  2 +-
 .../invite_links/edit_chat_invite_link.py     |  2 +-
 .../invite_links/export_chat_invite_link.py   |  2 +-
 .../get_chat_admin_invite_links.py            |  2 +-
 .../get_chat_admin_invite_links_count.py      |  2 +-
 .../get_chat_admins_with_invite_links.py      |  2 +-
 .../invite_links/get_chat_invite_link.py      |  2 +-
 .../get_chat_invite_link_members.py           |  2 +-
 .../get_chat_invite_link_members_count.py     |  2 +-
 .../invite_links/revoke_chat_invite_link.py   |  2 +-
 pyrogram/methods/messages/copy_media_group.py |  2 +-
 pyrogram/methods/messages/delete_messages.py  |  4 +--
 .../methods/messages/edit_inline_media.py     |  2 +-
 .../messages/edit_inline_reply_markup.py      |  2 +-
 pyrogram/methods/messages/edit_inline_text.py |  2 +-
 .../methods/messages/edit_message_media.py    | 12 +++----
 .../messages/edit_message_reply_markup.py     |  2 +-
 .../methods/messages/edit_message_text.py     |  2 +-
 pyrogram/methods/messages/forward_messages.py |  2 +-
 .../messages/get_discussion_message.py        |  2 +-
 pyrogram/methods/messages/get_history.py      |  2 +-
 .../methods/messages/get_history_count.py     |  2 +-
 pyrogram/methods/messages/get_messages.py     |  2 +-
 pyrogram/methods/messages/inline_session.py   |  4 +--
 pyrogram/methods/messages/read_history.py     |  2 +-
 pyrogram/methods/messages/retract_vote.py     |  2 +-
 pyrogram/methods/messages/search_global.py    |  2 +-
 .../methods/messages/search_global_count.py   |  2 +-
 pyrogram/methods/messages/search_messages.py  |  2 +-
 .../methods/messages/search_messages_count.py |  2 +-
 pyrogram/methods/messages/send_animation.py   |  4 +--
 pyrogram/methods/messages/send_audio.py       |  2 +-
 .../methods/messages/send_cached_media.py     |  2 +-
 pyrogram/methods/messages/send_chat_action.py |  2 +-
 pyrogram/methods/messages/send_contact.py     |  2 +-
 pyrogram/methods/messages/send_dice.py        |  2 +-
 pyrogram/methods/messages/send_document.py    |  2 +-
 pyrogram/methods/messages/send_location.py    |  2 +-
 pyrogram/methods/messages/send_media_group.py | 26 +++++++--------
 pyrogram/methods/messages/send_message.py     |  2 +-
 pyrogram/methods/messages/send_photo.py       |  2 +-
 pyrogram/methods/messages/send_poll.py        |  2 +-
 pyrogram/methods/messages/send_reaction.py    |  2 +-
 pyrogram/methods/messages/send_sticker.py     |  2 +-
 pyrogram/methods/messages/send_venue.py       |  2 +-
 pyrogram/methods/messages/send_video.py       |  2 +-
 pyrogram/methods/messages/send_video_note.py  |  2 +-
 pyrogram/methods/messages/send_voice.py       |  2 +-
 pyrogram/methods/messages/stop_poll.py        |  2 +-
 pyrogram/methods/messages/vote_poll.py        |  2 +-
 .../methods/password/change_cloud_password.py |  4 +--
 .../methods/password/enable_cloud_password.py |  4 +--
 .../methods/password/remove_cloud_password.py |  4 +--
 pyrogram/methods/users/block_user.py          |  2 +-
 .../methods/users/delete_profile_photos.py    |  2 +-
 pyrogram/methods/users/get_common_chats.py    |  2 +-
 pyrogram/methods/users/get_me.py              |  2 +-
 pyrogram/methods/users/get_profile_photos.py  |  6 ++--
 .../methods/users/get_profile_photos_count.py |  4 +--
 pyrogram/methods/users/get_users.py           |  2 +-
 pyrogram/methods/users/set_profile_photo.py   |  2 +-
 pyrogram/methods/users/set_username.py        |  2 +-
 pyrogram/methods/users/unblock_user.py        |  2 +-
 pyrogram/methods/users/update_profile.py      |  2 +-
 pyrogram/methods/utilities/start.py           |  4 +--
 pyrogram/session/auth.py                      |  8 ++---
 pyrogram/session/session.py                   | 32 +++++++++----------
 pyrogram/types/messages_and_media/message.py  |  2 +-
 pyrogram/types/messages_and_media/sticker.py  |  6 ++--
 144 files changed, 234 insertions(+), 236 deletions(-)
 rename pyrogram/methods/advanced/{send.py => invoke.py} (87%)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index cfef3a8d94..920b723311 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -567,7 +567,7 @@ async def handle_updates(self, updates):
 
                     if not isinstance(message, raw.types.MessageEmpty):
                         try:
-                            diff = await self.send(
+                            diff = await self.invoke(
                                 raw.functions.updates.GetChannelDifference(
                                     channel=await self.resolve_peer(utils.get_channel_id(channel_id)),
                                     filter=raw.types.ChannelMessagesFilter(
@@ -589,7 +589,7 @@ async def handle_updates(self, updates):
 
                 self.dispatcher.updates_queue.put_nowait((update, users, chats))
         elif isinstance(updates, (raw.types.UpdateShortMessage, raw.types.UpdateShortChatMessage)):
-            diff = await self.send(
+            diff = await self.invoke(
                 raw.functions.updates.GetDifference(
                     pts=updates.pts - updates.pts_count,
                     date=updates.date,
@@ -847,14 +847,14 @@ async def get_file(
                     await session.start()
 
                     for _ in range(3):
-                        exported_auth = await self.send(
+                        exported_auth = await self.invoke(
                             raw.functions.auth.ExportAuthorization(
                                 dc_id=dc_id
                             )
                         )
 
                         try:
-                            await session.send(
+                            await session.invoke(
                                 raw.functions.auth.ImportAuthorization(
                                     id=exported_auth.id,
                                     bytes=exported_auth.bytes
@@ -920,7 +920,7 @@ async def get_file(
         file_name = ""
 
         try:
-            r = await session.send(
+            r = await session.invoke(
                 raw.functions.upload.GetFile(
                     location=location,
                     offset=offset,
@@ -958,7 +958,7 @@ async def get_file(
                         if len(chunk) < limit:
                             break
 
-                        r = await session.send(
+                        r = await session.invoke(
                             raw.functions.upload.GetFile(
                                 location=location,
                                 offset=offset,
@@ -986,7 +986,7 @@ async def get_file(
                         file_name = f.name
 
                         while True:
-                            r2 = await cdn_session.send(
+                            r2 = await cdn_session.invoke(
                                 raw.functions.upload.GetCdnFile(
                                     file_token=r.file_token,
                                     offset=offset,
@@ -996,7 +996,7 @@ async def get_file(
 
                             if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded):
                                 try:
-                                    await session.send(
+                                    await session.invoke(
                                         raw.functions.upload.ReuploadCdnFile(
                                             file_token=r.file_token,
                                             request_token=r2.request_token
@@ -1019,7 +1019,7 @@ async def get_file(
                                 )
                             )
 
-                            hashes = await session.send(
+                            hashes = await session.invoke(
                                 raw.functions.upload.GetCdnFileHashes(
                                     file_token=r.file_token,
                                     offset=offset
diff --git a/pyrogram/methods/advanced/__init__.py b/pyrogram/methods/advanced/__init__.py
index a3cf461af7..bf19658a3c 100644
--- a/pyrogram/methods/advanced/__init__.py
+++ b/pyrogram/methods/advanced/__init__.py
@@ -16,14 +16,14 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from .invoke import Invoke
 from .resolve_peer import ResolvePeer
 from .save_file import SaveFile
-from .send import Send
 
 
 class Advanced(
+    Invoke,
     ResolvePeer,
-    SaveFile,
-    Send
+    SaveFile
 ):
     pass
diff --git a/pyrogram/methods/advanced/send.py b/pyrogram/methods/advanced/invoke.py
similarity index 87%
rename from pyrogram/methods/advanced/send.py
rename to pyrogram/methods/advanced/invoke.py
index 6e5551cd97..9ae25d0084 100644
--- a/pyrogram/methods/advanced/send.py
+++ b/pyrogram/methods/advanced/invoke.py
@@ -26,15 +26,15 @@
 log = logging.getLogger(__name__)
 
 
-class Send:
-    async def send(
+class Invoke:
+    async def invoke(
         self: "pyrogram.Client",
-        data: TLObject,
+        query: TLObject,
         retries: int = Session.MAX_RETRIES,
         timeout: float = Session.WAIT_TIMEOUT,
         sleep_threshold: float = None
     ):
-        """Send raw Telegram queries.
+        """Invoke raw Telegram functions.
 
         This method makes it possible to manually call every single Telegram API method in a low-level manner.
         Available functions are listed in the :obj:`functions ` package and may accept compound
@@ -47,7 +47,7 @@ async def send(
             available yet in the Client class as an easy-to-use method).
 
         Parameters:
-            data (``RawFunction``):
+            query (``RawFunction``):
                 The API Schema function filled with proper arguments.
 
             retries (``int``):
@@ -69,13 +69,13 @@ async def send(
             raise ConnectionError("Client has not been started yet")
 
         if self.no_updates:
-            data = raw.functions.InvokeWithoutUpdates(query=data)
+            query = raw.functions.InvokeWithoutUpdates(query=query)
 
         if self.takeout_id:
-            data = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data)
+            query = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=query)
 
-        r = await self.session.send(
-            data, retries, timeout,
+        r = await self.session.invoke(
+            query, retries, timeout,
             (sleep_threshold
              if sleep_threshold is not None
              else self.sleep_threshold)
diff --git a/pyrogram/methods/advanced/resolve_peer.py b/pyrogram/methods/advanced/resolve_peer.py
index db4def9aa2..80fe7975b0 100644
--- a/pyrogram/methods/advanced/resolve_peer.py
+++ b/pyrogram/methods/advanced/resolve_peer.py
@@ -71,7 +71,7 @@ async def resolve_peer(
                     try:
                         return await self.storage.get_peer_by_username(peer_id)
                     except KeyError:
-                        await self.send(
+                        await self.invoke(
                             raw.functions.contacts.ResolveUsername(
                                 username=peer_id
                             )
@@ -88,7 +88,7 @@ async def resolve_peer(
 
             if peer_type == "user":
                 await self.fetch_peers(
-                    await self.send(
+                    await self.invoke(
                         raw.functions.users.GetUsers(
                             id=[
                                 raw.types.InputUser(
@@ -100,13 +100,13 @@ async def resolve_peer(
                     )
                 )
             elif peer_type == "chat":
-                await self.send(
+                await self.invoke(
                     raw.functions.messages.GetChats(
                         id=[-peer_id]
                     )
                 )
             else:
-                await self.send(
+                await self.invoke(
                     raw.functions.channels.GetChannels(
                         id=[
                             raw.types.InputChannel(
diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py
index 9c92651dba..706f28e04f 100644
--- a/pyrogram/methods/advanced/save_file.py
+++ b/pyrogram/methods/advanced/save_file.py
@@ -103,7 +103,7 @@ async def worker(session):
                     return
 
                 try:
-                    await session.send(data)
+                    await session.invoke(data)
                 except Exception as e:
                     log.error(e)
 
diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py
index ea041d6c36..3bc5fbad27 100644
--- a/pyrogram/methods/auth/accept_terms_of_service.py
+++ b/pyrogram/methods/auth/accept_terms_of_service.py
@@ -31,7 +31,7 @@ async def accept_terms_of_service(
             terms_of_service_id (``str``):
                 The terms of service identifier.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.help.AcceptTermsOfService(
                 id=raw.types.DataJSON(
                     data=terms_of_service_id
diff --git a/pyrogram/methods/auth/check_password.py b/pyrogram/methods/auth/check_password.py
index 1f1d142ced..9d8b08abfa 100644
--- a/pyrogram/methods/auth/check_password.py
+++ b/pyrogram/methods/auth/check_password.py
@@ -43,10 +43,10 @@ async def check_password(
         Raises:
             BadRequest: In case the password is invalid.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.auth.CheckPassword(
                 password=compute_password_check(
-                    await self.send(raw.functions.account.GetPassword()),
+                    await self.invoke(raw.functions.account.GetPassword()),
                     password
                 )
             )
diff --git a/pyrogram/methods/auth/get_password_hint.py b/pyrogram/methods/auth/get_password_hint.py
index d900210681..af6557589a 100644
--- a/pyrogram/methods/auth/get_password_hint.py
+++ b/pyrogram/methods/auth/get_password_hint.py
@@ -33,4 +33,4 @@ async def get_password_hint(
         Returns:
             ``str``: On success, the password hint as string is returned.
         """
-        return (await self.send(raw.functions.account.GetPassword())).hint
+        return (await self.invoke(raw.functions.account.GetPassword())).hint
diff --git a/pyrogram/methods/auth/log_out.py b/pyrogram/methods/auth/log_out.py
index 2f8ad019b7..b4a29f8273 100644
--- a/pyrogram/methods/auth/log_out.py
+++ b/pyrogram/methods/auth/log_out.py
@@ -42,7 +42,7 @@ async def log_out(
                 # Log out.
                 app.log_out()
         """
-        await self.send(raw.functions.auth.LogOut())
+        await self.invoke(raw.functions.auth.LogOut())
         await self.stop()
         await self.storage.delete()
 
diff --git a/pyrogram/methods/auth/recover_password.py b/pyrogram/methods/auth/recover_password.py
index 600ac86a0b..9f75a93f79 100644
--- a/pyrogram/methods/auth/recover_password.py
+++ b/pyrogram/methods/auth/recover_password.py
@@ -43,7 +43,7 @@ async def recover_password(
         Raises:
             BadRequest: In case the recovery code is invalid.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.auth.RecoverPassword(
                 code=recovery_code
             )
diff --git a/pyrogram/methods/auth/resend_code.py b/pyrogram/methods/auth/resend_code.py
index d17cc395f8..4210e04d9b 100644
--- a/pyrogram/methods/auth/resend_code.py
+++ b/pyrogram/methods/auth/resend_code.py
@@ -52,7 +52,7 @@ async def resend_code(
         """
         phone_number = phone_number.strip(" +")
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.auth.ResendCode(
                 phone_number=phone_number,
                 phone_code_hash=phone_code_hash
diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py
index 3d42fa6b92..5a4f87ea31 100644
--- a/pyrogram/methods/auth/send_code.py
+++ b/pyrogram/methods/auth/send_code.py
@@ -49,7 +49,7 @@ async def send_code(
 
         while True:
             try:
-                r = await self.send(
+                r = await self.invoke(
                     raw.functions.auth.SendCode(
                         phone_number=phone_number,
                         api_id=self.api_id,
diff --git a/pyrogram/methods/auth/send_recovery_code.py b/pyrogram/methods/auth/send_recovery_code.py
index 40d2b7ddb2..d1f23bf965 100644
--- a/pyrogram/methods/auth/send_recovery_code.py
+++ b/pyrogram/methods/auth/send_recovery_code.py
@@ -36,6 +36,6 @@ async def send_recovery_code(
         Raises:
             BadRequest: In case no recovery email was set up.
         """
-        return (await self.send(
+        return (await self.invoke(
             raw.functions.auth.RequestPasswordRecovery()
         )).email_pattern
diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py
index d8079c95c5..c328c95850 100644
--- a/pyrogram/methods/auth/sign_in.py
+++ b/pyrogram/methods/auth/sign_in.py
@@ -58,7 +58,7 @@ async def sign_in(
         """
         phone_number = phone_number.strip(" +")
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.auth.SignIn(
                 phone_number=phone_number,
                 phone_code_hash=phone_code_hash,
diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py
index db4515a4ef..5f2e68b510 100644
--- a/pyrogram/methods/auth/sign_in_bot.py
+++ b/pyrogram/methods/auth/sign_in_bot.py
@@ -46,7 +46,7 @@ async def sign_in_bot(
         """
         while True:
             try:
-                r = await self.send(
+                r = await self.invoke(
                     raw.functions.auth.ImportBotAuthorization(
                         flags=0,
                         api_id=self.api_id,
diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py
index 4e769ab1b4..6700fee481 100644
--- a/pyrogram/methods/auth/sign_up.py
+++ b/pyrogram/methods/auth/sign_up.py
@@ -56,7 +56,7 @@ async def sign_up(
         """
         phone_number = phone_number.strip(" +")
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.auth.SignUp(
                 phone_number=phone_number,
                 first_name=first_name,
diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py
index d8cca6ba81..548d030cb4 100644
--- a/pyrogram/methods/auth/terminate.py
+++ b/pyrogram/methods/auth/terminate.py
@@ -41,7 +41,7 @@ async def terminate(
             raise ConnectionError("Client is already terminated")
 
         if self.takeout_id:
-            await self.send(raw.functions.account.FinishTakeoutSession())
+            await self.invoke(raw.functions.account.FinishTakeoutSession())
             log.warning(f"Takeout session {self.takeout_id} finished")
 
         await Syncer.remove(self)
diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py
index 73d5ce5569..af2c8f7252 100644
--- a/pyrogram/methods/bots/answer_callback_query.py
+++ b/pyrogram/methods/bots/answer_callback_query.py
@@ -68,7 +68,7 @@ async def answer_callback_query(
                 # Answer with alert
                 app.answer_callback_query(query_id, text=text, show_alert=True)
         """
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.SetBotCallbackAnswer(
                 query_id=int(callback_query_id),
                 cache_time=cache_time,
diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py
index 1751171d53..ebdfab2397 100644
--- a/pyrogram/methods/bots/answer_inline_query.py
+++ b/pyrogram/methods/bots/answer_inline_query.py
@@ -94,7 +94,7 @@ async def answer_inline_query(
                             InputTextMessageContent("Message content"))])
         """
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.SetInlineBotResults(
                 query_id=int(inline_query_id),
                 results=[await r.write(self) for r in results],
diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py
index e4a2ed150c..312cc632b4 100644
--- a/pyrogram/methods/bots/get_game_high_scores.py
+++ b/pyrogram/methods/bots/get_game_high_scores.py
@@ -59,7 +59,7 @@ async def get_game_high_scores(
         """
         # TODO: inline_message_id
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetGameHighScores(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py
index 2c41fec7ec..a71fbad8ec 100644
--- a/pyrogram/methods/bots/get_inline_bot_results.py
+++ b/pyrogram/methods/bots/get_inline_bot_results.py
@@ -70,7 +70,7 @@ async def get_inline_bot_results(
         # TODO: Don't return the raw type
 
         try:
-            return await self.send(
+            return await self.invoke(
                 raw.functions.messages.GetInlineBotResults(
                     bot=await self.resolve_peer(bot),
                     peer=raw.types.InputPeerSelf(),
diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py
index ff6ae0d3ef..908c8ecae6 100644
--- a/pyrogram/methods/bots/request_callback_answer.py
+++ b/pyrogram/methods/bots/request_callback_answer.py
@@ -64,7 +64,7 @@ async def request_callback_answer(
         # Telegram only wants bytes, but we are allowed to pass strings too.
         data = bytes(callback_data, "utf-8") if isinstance(callback_data, str) else callback_data
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.GetBotCallbackAnswer(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id,
diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py
index 7f9e856bb0..c8eee66eff 100644
--- a/pyrogram/methods/bots/send_game.py
+++ b/pyrogram/methods/bots/send_game.py
@@ -71,7 +71,7 @@ async def send_game(
 
                 app.send_game(chat_id, "gamename")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaGame(
diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py
index 299aaaf6f7..00b4204309 100644
--- a/pyrogram/methods/bots/send_inline_bot_result.py
+++ b/pyrogram/methods/bots/send_inline_bot_result.py
@@ -61,7 +61,7 @@ async def send_inline_bot_result(
 
                 app.send_inline_bot_result(chat_id, query_id, result_id)
         """
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.SendInlineBotResult(
                 peer=await self.resolve_peer(chat_id),
                 query_id=query_id,
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index 8c9baa2e6a..6df1a2e443 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -62,7 +62,7 @@ async def set_bot_commands(
                     BotCommand("settings", "Bot settings")])
         """
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.bots.SetBotCommands(
                 commands=[c.write() for c in commands],
                 scope=await scope.write(self),
diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py
index ef644b60db..855e4a2ece 100644
--- a/pyrogram/methods/bots/set_game_score.py
+++ b/pyrogram/methods/bots/set_game_score.py
@@ -75,7 +75,7 @@ async def set_game_score(
                 # Force set new score
                 app.set_game_score(user_id, 25, force=True)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SetGameScore(
                 peer=await self.resolve_peer(chat_id),
                 score=score,
diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py
index cda789aaba..2d053c4e8e 100644
--- a/pyrogram/methods/chats/add_chat_members.py
+++ b/pyrogram/methods/chats/add_chat_members.py
@@ -67,7 +67,7 @@ async def add_chat_members(
 
         if isinstance(peer, raw.types.InputPeerChat):
             for user_id in user_ids:
-                await self.send(
+                await self.invoke(
                     raw.functions.messages.AddChatUser(
                         chat_id=peer.chat_id,
                         user_id=await self.resolve_peer(user_id),
@@ -75,7 +75,7 @@ async def add_chat_members(
                     )
                 )
         else:
-            await self.send(
+            await self.invoke(
                 raw.functions.channels.InviteToChannel(
                     channel=peer,
                     users=[
diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py
index aa5b50d5ec..cba27371cb 100644
--- a/pyrogram/methods/chats/archive_chats.py
+++ b/pyrogram/methods/chats/archive_chats.py
@@ -60,7 +60,7 @@ async def archive_chats(
                 )
             )
 
-        await self.send(
+        await self.invoke(
             raw.functions.folders.EditPeerFolders(
                 folder_peers=folder_peers
             )
diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py
index c01b70462e..d8a207aba8 100644
--- a/pyrogram/methods/chats/ban_chat_member.py
+++ b/pyrogram/methods/chats/ban_chat_member.py
@@ -73,7 +73,7 @@ async def ban_chat_member(
         user_peer = await self.resolve_peer(user_id)
 
         if isinstance(chat_peer, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.EditBanned(
                     channel=chat_peer,
                     participant=user_peer,
@@ -91,7 +91,7 @@ async def ban_chat_member(
                 )
             )
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.DeleteChatUser(
                     chat_id=abs(chat_id),
                     user_id=user_peer
diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py
index 5920d5ff70..1b054b6ed6 100644
--- a/pyrogram/methods/chats/create_channel.py
+++ b/pyrogram/methods/chats/create_channel.py
@@ -43,7 +43,7 @@ async def create_channel(
 
                 app.create_channel("Channel Title", "Channel Description")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.channels.CreateChannel(
                 title=title,
                 about=description,
diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py
index d01a2e683d..78240f9fb0 100644
--- a/pyrogram/methods/chats/create_group.py
+++ b/pyrogram/methods/chats/create_group.py
@@ -55,7 +55,7 @@ async def create_group(
         if not isinstance(users, list):
             users = [users]
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.CreateChat(
                 title=title,
                 users=[await self.resolve_peer(u) for u in users]
diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py
index 348fc72609..eb922c324f 100644
--- a/pyrogram/methods/chats/create_supergroup.py
+++ b/pyrogram/methods/chats/create_supergroup.py
@@ -47,7 +47,7 @@ async def create_supergroup(
 
                 app.create_supergroup("Supergroup Title", "Supergroup Description")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.channels.CreateChannel(
                 title=title,
                 about=description,
diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py
index 246c930af8..210c81f1cd 100644
--- a/pyrogram/methods/chats/delete_channel.py
+++ b/pyrogram/methods/chats/delete_channel.py
@@ -41,7 +41,7 @@ async def delete_channel(
 
                 app.delete_channel(channel_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.channels.DeleteChannel(
                 channel=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py
index 0b4d6488c6..ac485603cd 100644
--- a/pyrogram/methods/chats/delete_chat_photo.py
+++ b/pyrogram/methods/chats/delete_chat_photo.py
@@ -49,14 +49,14 @@ async def delete_chat_photo(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChat):
-            await self.send(
+            await self.invoke(
                 raw.functions.messages.EditChatPhoto(
                     chat_id=peer.chat_id,
                     photo=raw.types.InputChatPhotoEmpty()
                 )
             )
         elif isinstance(peer, raw.types.InputPeerChannel):
-            await self.send(
+            await self.invoke(
                 raw.functions.channels.EditPhoto(
                     channel=peer,
                     photo=raw.types.InputChatPhotoEmpty()
diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py
index 5f6e8168ea..8fb069fff8 100644
--- a/pyrogram/methods/chats/delete_supergroup.py
+++ b/pyrogram/methods/chats/delete_supergroup.py
@@ -41,7 +41,7 @@ async def delete_supergroup(
 
                 app.delete_supergroup(supergroup_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.channels.DeleteChannel(
                 channel=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py
index 867100bb6e..4411ddbd24 100644
--- a/pyrogram/methods/chats/delete_user_history.py
+++ b/pyrogram/methods/chats/delete_user_history.py
@@ -41,7 +41,7 @@ async def delete_user_history(
             ``bool``: True on success, False otherwise.
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.channels.DeleteParticipantHistory(
                 channel=await self.resolve_peer(chat_id),
                 participant=await self.resolve_peer(user_id)
diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py
index 99e5756647..fc19801910 100644
--- a/pyrogram/methods/chats/get_chat.py
+++ b/pyrogram/methods/chats/get_chat.py
@@ -56,7 +56,7 @@ async def get_chat(
         match = self.INVITE_LINK_RE.match(str(chat_id))
 
         if match:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.CheckChatInvite(
                     hash=match.group(1)
                 )
@@ -76,10 +76,10 @@ async def get_chat(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChannel):
-            r = await self.send(raw.functions.channels.GetFullChannel(channel=peer))
+            r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
         elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
-            r = await self.send(raw.functions.users.GetFullUser(id=peer))
+            r = await self.invoke(raw.functions.users.GetFullUser(id=peer))
         else:
-            r = await self.send(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
+            r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
 
         return await types.Chat._parse_full(self, r)
diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py
index db27709094..2325bad99a 100644
--- a/pyrogram/methods/chats/get_chat_event_log.py
+++ b/pyrogram/methods/chats/get_chat_event_log.py
@@ -70,7 +70,7 @@ async def get_chat_event_log(
         limit = min(100, total)
 
         while True:
-            r: raw.base.channels.AdminLogResults = await self.send(
+            r: raw.base.channels.AdminLogResults = await self.invoke(
                 raw.functions.channels.GetAdminLog(
                     channel=await self.resolve_peer(chat_id),
                     q=query,
diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py
index 9717d01953..1b24d2135c 100644
--- a/pyrogram/methods/chats/get_chat_member.py
+++ b/pyrogram/methods/chats/get_chat_member.py
@@ -54,7 +54,7 @@ async def get_chat_member(
         user = await self.resolve_peer(user_id)
 
         if isinstance(chat, raw.types.InputPeerChat):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetFullChat(
                     chat_id=chat.chat_id
                 )
@@ -75,7 +75,7 @@ async def get_chat_member(
             else:
                 raise UserNotParticipant
         elif isinstance(chat, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.GetParticipant(
                     channel=chat,
                     participant=user
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index 7e6b8898fc..a192c3e3ea 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -92,7 +92,7 @@ async def get_chat_members(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChat):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetFullChat(
                     chat_id=peer.chat_id
                 )
@@ -120,7 +120,7 @@ async def get_chat_members(
             else:
                 raise ValueError(f'Invalid filter "{filter}"')
 
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.GetParticipants(
                     channel=peer,
                     filter=filter,
diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py
index a7dae4be05..9c57a11e80 100644
--- a/pyrogram/methods/chats/get_chat_members_count.py
+++ b/pyrogram/methods/chats/get_chat_members_count.py
@@ -48,7 +48,7 @@ async def get_chat_members_count(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChat):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetChats(
                     id=[peer.chat_id]
                 )
@@ -56,7 +56,7 @@ async def get_chat_members_count(
 
             return r.chats[0].participants_count
         elif isinstance(peer, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.GetFullChannel(
                     channel=peer
                 )
diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py
index 3f8e5d6aee..19924542f5 100644
--- a/pyrogram/methods/chats/get_chat_online_count.py
+++ b/pyrogram/methods/chats/get_chat_online_count.py
@@ -42,7 +42,7 @@ async def get_chat_online_count(
                 online = app.get_chat_online_count(chat_id)
                 print(online)
         """
-        return (await self.send(
+        return (await self.invoke(
             raw.functions.messages.GetOnlines(
                 peer=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py
index 7276c80b64..4aaa95ffc4 100644
--- a/pyrogram/methods/chats/get_dialogs.py
+++ b/pyrogram/methods/chats/get_dialogs.py
@@ -67,12 +67,12 @@ async def get_dialogs(
         """
 
         if pinned_only:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetPinnedDialogs(folder_id=0),
                 sleep_threshold=60
             )
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetDialogs(
                     offset_date=utils.datetime_to_timestamp(offset_date),
                     offset_id=0,
diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py
index 3f869909fc..8ca237cff5 100644
--- a/pyrogram/methods/chats/get_dialogs_count.py
+++ b/pyrogram/methods/chats/get_dialogs_count.py
@@ -42,9 +42,9 @@ async def get_dialogs_count(
         """
 
         if pinned_only:
-            return len((await self.send(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs)
+            return len((await self.invoke(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs)
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetDialogs(
                     offset_date=0,
                     offset_id=0,
diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py
index 0dff05aae2..c7c36cc61d 100644
--- a/pyrogram/methods/chats/get_nearby_chats.py
+++ b/pyrogram/methods/chats/get_nearby_chats.py
@@ -49,7 +49,7 @@ async def get_nearby_chats(
                 print(chats)
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.contacts.GetLocated(
                 geo_point=raw.types.InputGeoPoint(
                     lat=latitude,
diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py
index 147da217ce..2db4d5f05a 100644
--- a/pyrogram/methods/chats/get_send_as_chats.py
+++ b/pyrogram/methods/chats/get_send_as_chats.py
@@ -43,7 +43,7 @@ async def get_send_as_chats(
                 chats = app.get_send_as_chats(chat_id)
                 print(chats)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.channels.GetSendAs(
                 peer=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py
index 009bdfa8c2..72a396f758 100644
--- a/pyrogram/methods/chats/iter_dialogs.py
+++ b/pyrogram/methods/chats/iter_dialogs.py
@@ -57,7 +57,7 @@ async def iter_dialogs(
         offset_peer = raw.types.InputPeerEmpty()
 
         while True:
-            r = (await self.send(
+            r = (await self.invoke(
                 raw.functions.messages.GetDialogs(
                     offset_date=offset_date,
                     offset_id=offset_id,
diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py
index c1a850af92..2534442ac6 100644
--- a/pyrogram/methods/chats/join_chat.py
+++ b/pyrogram/methods/chats/join_chat.py
@@ -53,7 +53,7 @@ async def join_chat(
         match = self.INVITE_LINK_RE.match(str(chat_id))
 
         if match:
-            chat = await self.send(
+            chat = await self.invoke(
                 raw.functions.messages.ImportChatInvite(
                     hash=match.group(1)
                 )
@@ -63,7 +63,7 @@ async def join_chat(
             elif isinstance(chat.chats[0], raw.types.Channel):
                 return types.Chat._parse_channel_chat(self, chat.chats[0])
         else:
-            chat = await self.send(
+            chat = await self.invoke(
                 raw.functions.channels.JoinChannel(
                     channel=await self.resolve_peer(chat_id)
                 )
diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py
index 56369e1ce7..7a6eb85dff 100644
--- a/pyrogram/methods/chats/leave_chat.py
+++ b/pyrogram/methods/chats/leave_chat.py
@@ -51,13 +51,13 @@ async def leave_chat(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChannel):
-            return await self.send(
+            return await self.invoke(
                 raw.functions.channels.LeaveChannel(
                     channel=await self.resolve_peer(chat_id)
                 )
             )
         elif isinstance(peer, raw.types.InputPeerChat):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.DeleteChatUser(
                     chat_id=peer.chat_id,
                     user_id=raw.types.InputUserSelf()
@@ -65,7 +65,7 @@ async def leave_chat(
             )
 
             if delete:
-                await self.send(
+                await self.invoke(
                     raw.functions.messages.DeleteHistory(
                         peer=peer,
                         max_id=0
diff --git a/pyrogram/methods/chats/mark_chat_unread.py b/pyrogram/methods/chats/mark_chat_unread.py
index 32251e2a7d..62cb8bee31 100644
--- a/pyrogram/methods/chats/mark_chat_unread.py
+++ b/pyrogram/methods/chats/mark_chat_unread.py
@@ -19,7 +19,7 @@
 from typing import Union
 
 import pyrogram
-from pyrogram.raw import functions
+from pyrogram import raw
 
 
 class MarkChatUnread:
@@ -37,8 +37,8 @@ async def mark_chat_unread(
             ``bool``: On success, True is returned.
         """
 
-        return await self.send(
-            functions.messages.MarkDialogUnread(
+        return await self.invoke(
+            raw.functions.messages.MarkDialogUnread(
                 peer=await self.resolve_peer(chat_id),
                 unread=True
             )
diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py
index 9e34e1aa6c..1f5ac91239 100644
--- a/pyrogram/methods/chats/pin_chat_message.py
+++ b/pyrogram/methods/chats/pin_chat_message.py
@@ -61,7 +61,7 @@ async def pin_chat_message(
                 # Pin without notification
                 app.pin_chat_message(chat_id, message_id, disable_notification=True)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.UpdatePinnedMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py
index 63a844bb2a..b64a17996f 100644
--- a/pyrogram/methods/chats/promote_chat_member.py
+++ b/pyrogram/methods/chats/promote_chat_member.py
@@ -57,7 +57,7 @@ async def promote_chat_member(
         chat_id = await self.resolve_peer(chat_id)
         user_id = await self.resolve_peer(user_id)
 
-        raw_chat_member = (await self.send(
+        raw_chat_member = (await self.invoke(
             raw.functions.channels.GetParticipant(
                 channel=chat_id,
                 participant=user_id
@@ -68,7 +68,7 @@ async def promote_chat_member(
         if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
             rank = raw_chat_member.rank
 
-        await self.send(
+        await self.invoke(
             raw.functions.channels.EditAdmin(
                 channel=chat_id,
                 user_id=user_id,
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index a8ab21730d..52b264e841 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -72,7 +72,7 @@ async def restrict_chat_member(
                 # Chat member can only send text messages
                 app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.channels.EditBanned(
                 channel=await self.resolve_peer(chat_id),
                 participant=await self.resolve_peer(user_id),
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index ed59b342f5..2ea0dccf6c 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -57,7 +57,7 @@ async def set_administrator_title(
         chat_id = await self.resolve_peer(chat_id)
         user_id = await self.resolve_peer(user_id)
 
-        r = (await self.send(
+        r = (await self.invoke(
             raw.functions.channels.GetParticipant(
                 channel=chat_id,
                 participant=user_id
@@ -71,7 +71,7 @@ async def set_administrator_title(
         else:
             raise ValueError("Custom titles can only be applied to owners or administrators of supergroups")
 
-        await self.send(
+        await self.invoke(
             raw.functions.channels.EditAdmin(
                 channel=chat_id,
                 user_id=user_id,
diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py
index 440b405013..4a93530b64 100644
--- a/pyrogram/methods/chats/set_chat_description.py
+++ b/pyrogram/methods/chats/set_chat_description.py
@@ -52,7 +52,7 @@ async def set_chat_description(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, (raw.types.InputPeerChannel, raw.types.InputPeerChat)):
-            await self.send(
+            await self.invoke(
                 raw.functions.messages.EditChatAbout(
                     peer=peer,
                     about=description
diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py
index dfbd5d917d..51d74fee8c 100644
--- a/pyrogram/methods/chats/set_chat_permissions.py
+++ b/pyrogram/methods/chats/set_chat_permissions.py
@@ -62,7 +62,7 @@ async def set_chat_permissions(
                 )
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditChatDefaultBannedRights(
                 peer=await self.resolve_peer(chat_id),
                 banned_rights=raw.types.ChatBannedRights(
diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py
index 1097b2377b..6da4330bcb 100644
--- a/pyrogram/methods/chats/set_chat_photo.py
+++ b/pyrogram/methods/chats/set_chat_photo.py
@@ -100,14 +100,14 @@ async def set_chat_photo(
             )
 
         if isinstance(peer, raw.types.InputPeerChat):
-            await self.send(
+            await self.invoke(
                 raw.functions.messages.EditChatPhoto(
                     chat_id=peer.chat_id,
                     photo=photo,
                 )
             )
         elif isinstance(peer, raw.types.InputPeerChannel):
-            await self.send(
+            await self.invoke(
                 raw.functions.channels.EditPhoto(
                     channel=peer,
                     photo=photo
diff --git a/pyrogram/methods/chats/set_chat_protected_content.py b/pyrogram/methods/chats/set_chat_protected_content.py
index 1372481c99..ee72d7228e 100644
--- a/pyrogram/methods/chats/set_chat_protected_content.py
+++ b/pyrogram/methods/chats/set_chat_protected_content.py
@@ -19,7 +19,7 @@
 from typing import Union
 
 import pyrogram
-from pyrogram.raw import functions
+from pyrogram import raw
 
 
 class SetChatProtectedContent:
@@ -41,8 +41,8 @@ async def set_chat_protected_content(
             ``bool``: On success, True is returned.
         """
 
-        await self.send(
-            functions.messages.ToggleNoForwards(
+        await self.invoke(
+            raw.functions.messages.ToggleNoForwards(
                 peer=await self.resolve_peer(chat_id),
                 enabled=enabled
             )
diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py
index ac30b078fe..edebf17624 100644
--- a/pyrogram/methods/chats/set_chat_title.py
+++ b/pyrogram/methods/chats/set_chat_title.py
@@ -57,14 +57,14 @@ async def set_chat_title(
         peer = await self.resolve_peer(chat_id)
 
         if isinstance(peer, raw.types.InputPeerChat):
-            await self.send(
+            await self.invoke(
                 raw.functions.messages.EditChatTitle(
                     chat_id=peer.chat_id,
                     title=title
                 )
             )
         elif isinstance(peer, raw.types.InputPeerChannel):
-            await self.send(
+            await self.invoke(
                 raw.functions.channels.EditTitle(
                     channel=peer,
                     title=title
diff --git a/pyrogram/methods/chats/set_chat_username.py b/pyrogram/methods/chats/set_chat_username.py
index c63207aa33..c1f6d17ddc 100644
--- a/pyrogram/methods/chats/set_chat_username.py
+++ b/pyrogram/methods/chats/set_chat_username.py
@@ -55,7 +55,7 @@ async def set_chat_username(
 
         if isinstance(peer, raw.types.InputPeerChannel):
             return bool(
-                await self.send(
+                await self.invoke(
                     raw.functions.channels.UpdateUsername(
                         channel=peer,
                         username=username or ""
diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py
index dabb4066f8..bbe210a41e 100644
--- a/pyrogram/methods/chats/set_send_as_chat.py
+++ b/pyrogram/methods/chats/set_send_as_chat.py
@@ -47,7 +47,7 @@ async def set_send_as_chat(
 
                 app.set_send_as_chat(chat_id, send_as_chat_id)
         """
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.SaveDefaultSendAs(
                 peer=await self.resolve_peer(chat_id),
                 send_as=await self.resolve_peer(send_as_chat_id)
diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py
index 3bc00cb21a..e3237ad34f 100644
--- a/pyrogram/methods/chats/set_slow_mode.py
+++ b/pyrogram/methods/chats/set_slow_mode.py
@@ -51,7 +51,7 @@ async def set_slow_mode(
                 app.set_slow_mode(chat_id, None)
         """
 
-        await self.send(
+        await self.invoke(
             raw.functions.channels.ToggleSlowMode(
                 channel=await self.resolve_peer(chat_id),
                 seconds=seconds or 0
diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py
index a6b77d1845..726eb4a07e 100644
--- a/pyrogram/methods/chats/unarchive_chats.py
+++ b/pyrogram/methods/chats/unarchive_chats.py
@@ -60,7 +60,7 @@ async def unarchive_chats(
                 )
             )
 
-        await self.send(
+        await self.invoke(
             raw.functions.folders.EditPeerFolders(
                 folder_peers=folder_peers
             )
diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py
index 9176fe3361..c331e823d4 100644
--- a/pyrogram/methods/chats/unban_chat_member.py
+++ b/pyrogram/methods/chats/unban_chat_member.py
@@ -49,7 +49,7 @@ async def unban_chat_member(
                 # Unban chat member right now
                 app.unban_chat_member(chat_id, user_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.channels.EditBanned(
                 channel=await self.resolve_peer(chat_id),
                 participant=await self.resolve_peer(user_id),
diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py
index bd75c40d6c..93b6eaec90 100644
--- a/pyrogram/methods/chats/unpin_all_chat_messages.py
+++ b/pyrogram/methods/chats/unpin_all_chat_messages.py
@@ -44,7 +44,7 @@ async def unpin_all_chat_messages(
                 # Unpin all chat messages
                 app.unpin_all_chat_messages(chat_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.messages.UnpinAllMessages(
                 peer=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py
index cf3f9e9d5e..6723f5a2a4 100644
--- a/pyrogram/methods/chats/unpin_chat_message.py
+++ b/pyrogram/methods/chats/unpin_chat_message.py
@@ -48,7 +48,7 @@ async def unpin_chat_message(
 
                 app.unpin_chat_message(chat_id, message_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.messages.UpdatePinnedMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py
index 72bdd88acf..433c4c90b6 100644
--- a/pyrogram/methods/contacts/add_contact.py
+++ b/pyrogram/methods/contacts/add_contact.py
@@ -60,7 +60,7 @@ async def add_contact(
                 app.add_contact(12345678, "Foo")
                 app.add_contact("username", "Bar")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.contacts.AddContact(
                 id=await self.resolve_peer(user_id),
                 first_name=first_name,
diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py
index e6ef32583b..03238beb88 100644
--- a/pyrogram/methods/contacts/delete_contacts.py
+++ b/pyrogram/methods/contacts/delete_contacts.py
@@ -50,7 +50,7 @@ async def delete_contacts(
         if not is_user_ids_list:
             user_ids = [user_ids]
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.contacts.DeleteContacts(
                 id=[await self.resolve_peer(i) for i in user_ids]
             )
diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py
index 0b41c3d6cb..ca8888764b 100644
--- a/pyrogram/methods/contacts/get_contacts.py
+++ b/pyrogram/methods/contacts/get_contacts.py
@@ -41,5 +41,5 @@ async def get_contacts(
                 contacts = app.get_contacts()
                 print(contacts)
         """
-        contacts = await self.send(raw.functions.contacts.GetContacts(hash=0))
+        contacts = await self.invoke(raw.functions.contacts.GetContacts(hash=0))
         return types.List(types.User._parse(self, user) for user in contacts.users)
diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py
index b7e5d371c8..d32ae0500f 100644
--- a/pyrogram/methods/contacts/get_contacts_count.py
+++ b/pyrogram/methods/contacts/get_contacts_count.py
@@ -36,4 +36,4 @@ async def get_contacts_count(
                 print(count)
         """
 
-        return len((await self.send(raw.functions.contacts.GetContacts(hash=0))).contacts)
+        return len((await self.invoke(raw.functions.contacts.GetContacts(hash=0))).contacts)
diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py
index 7a6e31420f..de802cff72 100644
--- a/pyrogram/methods/contacts/import_contacts.py
+++ b/pyrogram/methods/contacts/import_contacts.py
@@ -47,7 +47,7 @@ async def import_contacts(
                     InputPhoneContact("+1-456-789-0123", "Bar"),
                     InputPhoneContact("+1-789-012-3456", "Baz")])
         """
-        imported_contacts = await self.send(
+        imported_contacts = await self.invoke(
             raw.functions.contacts.ImportContacts(
                 contacts=contacts
             )
diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py
index a18a1c146a..3cd2248902 100644
--- a/pyrogram/methods/invite_links/approve_chat_join_request.py
+++ b/pyrogram/methods/invite_links/approve_chat_join_request.py
@@ -44,7 +44,7 @@ async def approve_chat_join_request(
         Returns:
             ``bool``: True on success.
         """
-        await self.send(
+        await self.invoke(
             raw.functions.messages.HideChatJoinRequest(
                 peer=await self.resolve_peer(chat_id),
                 user_id=await self.resolve_peer(user_id),
diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py
index 15ca034162..0e3e63a751 100644
--- a/pyrogram/methods/invite_links/create_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/create_chat_invite_link.py
@@ -72,7 +72,7 @@ async def create_chat_invite_link(
                 # Create a new link for up to 7 new users
                 link = app.create_chat_invite_link(chat_id, member_limit=7)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.ExportChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 expire_date=utils.datetime_to_timestamp(expire_date),
diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py
index d7c3d2f2e0..94e3c2fe7f 100644
--- a/pyrogram/methods/invite_links/decline_chat_join_request.py
+++ b/pyrogram/methods/invite_links/decline_chat_join_request.py
@@ -44,7 +44,7 @@ async def decline_chat_join_request(
         Returns:
             ``bool``: True on success.
         """
-        await self.send(
+        await self.invoke(
             raw.functions.messages.HideChatJoinRequest(
                 peer=await self.resolve_peer(chat_id),
                 user_id=await self.resolve_peer(user_id),
diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
index c051717830..8ba6754d0a 100644
--- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py
@@ -44,7 +44,7 @@ async def delete_chat_admin_invite_links(
             ``bool``: On success ``True`` is returned.
         """
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.DeleteRevokedExportedChatInvites(
                 peer=await self.resolve_peer(chat_id),
                 admin_id=await self.resolve_peer(admin_id),
diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py
index 19f4b49b3c..1f38e46cc4 100644
--- a/pyrogram/methods/invite_links/delete_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py
@@ -42,7 +42,7 @@ async def delete_chat_invite_link(
             ``bool``: On success ``True`` is returned.
         """
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.DeleteExportedChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link,
diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py
index 4a6755d6ea..96dcf79ddb 100644
--- a/pyrogram/methods/invite_links/edit_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py
@@ -74,7 +74,7 @@ async def edit_chat_invite_link(
                 # Set no expiration date of a link
                 link = app.edit_chat_invite_link(chat_id, invite_link, expire_date=0)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditExportedChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link,
diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py
index 9734470fea..66fb0227a4 100644
--- a/pyrogram/methods/invite_links/export_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/export_chat_invite_link.py
@@ -53,7 +53,7 @@ async def export_chat_invite_link(
                 # Generate a new primary link
                 link = app.export_chat_invite_link(chat_id)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.ExportChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 legacy_revoke_permanent=True
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
index 0c2660828a..1c79ce273c 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py
@@ -70,7 +70,7 @@ async def get_chat_admin_invite_links(
         offset_link = None
 
         while True:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetExportedChatInvites(
                     peer=await self.resolve_peer(chat_id),
                     admin_id=await self.resolve_peer(admin_id),
diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
index 419c76a776..c26af5063c 100644
--- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
+++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py
@@ -48,7 +48,7 @@ async def get_chat_admin_invite_links_count(
         Returns:
             ``int``: On success, the invite links count is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetExportedChatInvites(
                 peer=await self.resolve_peer(chat_id),
                 admin_id=await self.resolve_peer(admin_id),
diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
index 0f41925a10..61e082bc0e 100644
--- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
+++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py
@@ -40,7 +40,7 @@ async def get_chat_admins_with_invite_links(
             List of :obj:`~pyrogram.types.ChatAdminWithInviteLink`: On success, the list of admins that have exported
             invite links is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetAdminsWithInvites(
                 peer=await self.resolve_peer(chat_id)
             )
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link.py b/pyrogram/methods/invite_links/get_chat_invite_link.py
index 0fe0da8e9e..7447933658 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link.py
@@ -42,7 +42,7 @@ async def get_chat_invite_link(
         Returns:
             :obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetExportedChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members.py b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
index 8269a3465b..28121cccb7 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members.py
@@ -58,7 +58,7 @@ async def get_chat_invite_link_members(
         offset_user = raw.types.InputUserEmpty()
 
         while True:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetChatInviteImporters(
                     peer=await self.resolve_peer(chat_id),
                     link=invite_link,
diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
index c37258fe3c..d542895716 100644
--- a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
+++ b/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py
@@ -41,7 +41,7 @@ async def get_chat_invite_link_members_count(
         Returns:
             ``int``: On success, the joined chat members count is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetChatInviteImporters(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link,
diff --git a/pyrogram/methods/invite_links/revoke_chat_invite_link.py b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
index 64af8e5f73..a334bb8de2 100644
--- a/pyrogram/methods/invite_links/revoke_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/revoke_chat_invite_link.py
@@ -47,7 +47,7 @@ async def revoke_chat_invite_link(
             :obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link object is returned.
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditExportedChatInvite(
                 peer=await self.resolve_peer(chat_id),
                 link=invite_link,
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index 367cf47c57..b204999f3e 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.py
@@ -109,7 +109,7 @@ async def copy_media_group(
                 )
             )
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMultiMedia(
                 peer=await self.resolve_peer(chat_id),
                 multi_media=multi_media,
diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py
index 30438944fb..f8c3e7feed 100644
--- a/pyrogram/methods/messages/delete_messages.py
+++ b/pyrogram/methods/messages/delete_messages.py
@@ -66,14 +66,14 @@ async def delete_messages(
         message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids]
 
         if isinstance(peer, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.DeleteMessages(
                     channel=peer,
                     id=message_ids
                 )
             )
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.DeleteMessages(
                     id=message_ids,
                     revoke=revoke or None
diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py
index 0613bd7368..1bf8d4d249 100644
--- a/pyrogram/methods/messages/edit_inline_media.py
+++ b/pyrogram/methods/messages/edit_inline_media.py
@@ -179,7 +179,7 @@ async def edit_inline_media(
 
         session = await get_session(self, dc_id)
 
-        return await session.send(
+        return await session.invoke(
             raw.functions.messages.EditInlineBotMessage(
                 id=unpacked,
                 media=media,
diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py
index b3760c6751..92c6851e4f 100644
--- a/pyrogram/methods/messages/edit_inline_reply_markup.py
+++ b/pyrogram/methods/messages/edit_inline_reply_markup.py
@@ -58,7 +58,7 @@ async def edit_inline_reply_markup(
 
         session = await get_session(self, dc_id)
 
-        return await session.send(
+        return await session.invoke(
             raw.functions.messages.EditInlineBotMessage(
                 id=unpacked,
                 reply_markup=await reply_markup.write(self) if reply_markup else None,
diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py
index ae4cab3661..9a50d8639b 100644
--- a/pyrogram/methods/messages/edit_inline_text.py
+++ b/pyrogram/methods/messages/edit_inline_text.py
@@ -75,7 +75,7 @@ async def edit_inline_text(
 
         session = await get_session(self, dc_id)
 
-        return await session.send(
+        return await session.invoke(
             raw.functions.messages.EditInlineBotMessage(
                 id=unpacked,
                 no_webpage=disable_web_page_preview or None,
diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py
index 1593bfb6f8..0e3f360c22 100644
--- a/pyrogram/methods/messages/edit_message_media.py
+++ b/pyrogram/methods/messages/edit_message_media.py
@@ -87,7 +87,7 @@ async def edit_message_media(
 
         if isinstance(media, types.InputMediaPhoto):
             if os.path.isfile(media.media):
-                media = await self.send(
+                media = await self.invoke(
                     raw.functions.messages.UploadMedia(
                         peer=await self.resolve_peer(chat_id),
                         media=raw.types.InputMediaUploadedPhoto(
@@ -111,7 +111,7 @@ async def edit_message_media(
                 media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO)
         elif isinstance(media, types.InputMediaVideo):
             if os.path.isfile(media.media):
-                media = await self.send(
+                media = await self.invoke(
                     raw.functions.messages.UploadMedia(
                         peer=await self.resolve_peer(chat_id),
                         media=raw.types.InputMediaUploadedDocument(
@@ -148,7 +148,7 @@ async def edit_message_media(
                 media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO)
         elif isinstance(media, types.InputMediaAudio):
             if os.path.isfile(media.media):
-                media = await self.send(
+                media = await self.invoke(
                     raw.functions.messages.UploadMedia(
                         peer=await self.resolve_peer(chat_id),
                         media=raw.types.InputMediaUploadedDocument(
@@ -184,7 +184,7 @@ async def edit_message_media(
                 media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO)
         elif isinstance(media, types.InputMediaAnimation):
             if os.path.isfile(media.media):
-                media = await self.send(
+                media = await self.invoke(
                     raw.functions.messages.UploadMedia(
                         peer=await self.resolve_peer(chat_id),
                         media=raw.types.InputMediaUploadedDocument(
@@ -222,7 +222,7 @@ async def edit_message_media(
                 media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION)
         elif isinstance(media, types.InputMediaDocument):
             if os.path.isfile(media.media):
-                media = await self.send(
+                media = await self.invoke(
                     raw.functions.messages.UploadMedia(
                         peer=await self.resolve_peer(chat_id),
                         media=raw.types.InputMediaUploadedDocument(
@@ -252,7 +252,7 @@ async def edit_message_media(
             else:
                 media = utils.get_input_media_from_file_id(media.media, FileType.DOCUMENT)
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py
index 91b6fcd3e2..c164afbf77 100644
--- a/pyrogram/methods/messages/edit_message_reply_markup.py
+++ b/pyrogram/methods/messages/edit_message_reply_markup.py
@@ -58,7 +58,7 @@ async def edit_message_reply_markup(
                     InlineKeyboardMarkup([[
                         InlineKeyboardButton("New button", callback_data="new_data")]]))
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index 0f409cfe0a..551beaa143 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -77,7 +77,7 @@ async def edit_message_text(
                     disable_web_page_preview=True)
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index 12ed56aa97..dbc5534e5a 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -79,7 +79,7 @@ async def forward_messages(
         is_iterable = not isinstance(message_ids, int)
         message_ids = list(message_ids) if is_iterable else [message_ids]
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.ForwardMessages(
                 to_peer=await self.resolve_peer(chat_id),
                 from_peer=await self.resolve_peer(from_chat_id),
diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py
index f1de459234..6c72b484de 100644
--- a/pyrogram/methods/messages/get_discussion_message.py
+++ b/pyrogram/methods/messages/get_discussion_message.py
@@ -49,7 +49,7 @@ async def get_discussion_message(
                 # Comment to the post by replying
                 m.reply("comment")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetDiscussionMessage(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
index a67d971e65..ae8e1f37a8 100644
--- a/pyrogram/methods/messages/get_history.py
+++ b/pyrogram/methods/messages/get_history.py
@@ -86,7 +86,7 @@ async def get_history(
 
         messages = await utils.parse_messages(
             self,
-            await self.send(
+            await self.invoke(
                 raw.functions.messages.GetHistory(
                     peer=await self.resolve_peer(chat_id),
                     offset_id=offset_id,
diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_history_count.py
index a76c10b51d..12e068ae84 100644
--- a/pyrogram/methods/messages/get_history_count.py
+++ b/pyrogram/methods/messages/get_history_count.py
@@ -51,7 +51,7 @@ async def get_history_count(
                 app.get_history_count(chat_id)
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.GetHistory(
                 peer=await self.resolve_peer(chat_id),
                 offset_id=0,
diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py
index e9e408b5e2..a6a361af8c 100644
--- a/pyrogram/methods/messages/get_messages.py
+++ b/pyrogram/methods/messages/get_messages.py
@@ -111,7 +111,7 @@ async def get_messages(
         else:
             rpc = raw.functions.messages.GetMessages(id=ids)
 
-        r = await self.send(rpc, sleep_threshold=-1)
+        r = await self.invoke(rpc, sleep_threshold=-1)
 
         messages = await utils.parse_messages(self, r, replies=replies)
 
diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py
index c4ac50aa89..57fa794584 100644
--- a/pyrogram/methods/messages/inline_session.py
+++ b/pyrogram/methods/messages/inline_session.py
@@ -40,14 +40,14 @@ async def get_session(client: "pyrogram.Client", dc_id: int):
         await session.start()
 
         for _ in range(3):
-            exported_auth = await client.send(
+            exported_auth = await client.invoke(
                 raw.functions.auth.ExportAuthorization(
                     dc_id=dc_id
                 )
             )
 
             try:
-                await session.send(
+                await session.invoke(
                     raw.functions.auth.ImportAuthorization(
                         id=exported_auth.id,
                         bytes=exported_auth.bytes
diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_history.py
index 66b8bf50f7..204d9e3114 100644
--- a/pyrogram/methods/messages/read_history.py
+++ b/pyrogram/methods/messages/read_history.py
@@ -66,6 +66,6 @@ async def read_history(
                 max_id=max_id
             )
 
-        await self.send(q)
+        await self.invoke(q)
 
         return True
diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py
index f49807cd7a..8aab69f016 100644
--- a/pyrogram/methods/messages/retract_vote.py
+++ b/pyrogram/methods/messages/retract_vote.py
@@ -48,7 +48,7 @@ async def retract_vote(
 
                 app.retract_vote(chat_id, message_id)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendVote(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id,
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index 3f0d4e9ff3..a6ab555744 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -79,7 +79,7 @@ async def search_global(
         while True:
             messages = await utils.parse_messages(
                 self,
-                await self.send(
+                await self.invoke(
                     raw.functions.messages.SearchGlobal(
                         q=query,
                         filter=filter.value(),
diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py
index c848546ef3..afdad4c188 100644
--- a/pyrogram/methods/messages/search_global_count.py
+++ b/pyrogram/methods/messages/search_global_count.py
@@ -41,7 +41,7 @@ async def search_global_count(
         Returns:
             ``int``: On success, the messages count is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SearchGlobal(
                 q=query,
                 filter=filter.value(),
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index b448a1c204..b40826d9a2 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -32,7 +32,7 @@ async def get_chunk(
     limit: int = 100,
     from_user: Union[int, str] = None
 ) -> List["types.Message"]:
-    r = await client.send(
+    r = await client.invoke(
         raw.functions.messages.Search(
             peer=await client.resolve_peer(chat_id),
             q=query,
diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py
index 85c25d0618..301563e140 100644
--- a/pyrogram/methods/messages/search_messages_count.py
+++ b/pyrogram/methods/messages/search_messages_count.py
@@ -55,7 +55,7 @@ async def search_messages_count(
         Returns:
             ``int``: On success, the messages count is returned.
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.Search(
                 peer=await self.resolve_peer(chat_id),
                 q=query,
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 2e84fe8267..9403b1e49c 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -216,7 +216,7 @@ def progress(current, total):
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
@@ -249,7 +249,7 @@ def progress(current, total):
                                     document.file_id, FileType.ANIMATION
                                 ).id
 
-                                await self.send(
+                                await self.invoke(
                                     raw.functions.messages.SaveGif(
                                         id=document_id,
                                         unsave=True
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 47e914a8b4..e0a98f85d5 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -210,7 +210,7 @@ def progress(current, total):
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 4763e94d46..88a5f30921 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -96,7 +96,7 @@ async def send_cached_media(
                 app.send_cached_media("me", file_id)
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=utils.get_input_media_from_file_id(file_id),
diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py
index 9145653e7a..39f8d85f86 100644
--- a/pyrogram/methods/messages/send_chat_action.py
+++ b/pyrogram/methods/messages/send_chat_action.py
@@ -70,7 +70,7 @@ async def send_chat_action(
         else:
             action = action.value()
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.messages.SetTyping(
                 peer=await self.resolve_peer(chat_id),
                 action=action
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index 6285b502ff..b4683338d5 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.py
@@ -88,7 +88,7 @@ async def send_contact(
 
                 app.send_contact("me", "+1-123-456-7890", "Name")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaContact(
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index c3a6bb42fb..b15cfe2d0b 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -88,7 +88,7 @@ async def send_dice(
                 app.send_dice(chat_id, "🏀")
         """
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaDice(emoticon=emoji),
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 79f6e160ef..5b480cb3ea 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -188,7 +188,7 @@ def progress(current, total):
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py
index 3e9bf37c75..1364543b43 100644
--- a/pyrogram/methods/messages/send_location.py
+++ b/pyrogram/methods/messages/send_location.py
@@ -80,7 +80,7 @@ async def send_location(
 
                 app.send_location("me", 51.500729, -0.124583)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaGeoPoint(
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index ccb6136163..382b2a92a0 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -94,7 +94,7 @@ async def send_media_group(
             if isinstance(i, types.InputMediaPhoto):
                 if isinstance(i.media, str):
                     if os.path.isfile(i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaUploadedPhoto(
@@ -111,7 +111,7 @@ async def send_media_group(
                             )
                         )
                     elif re.match("^https?://", i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaPhotoExternal(
@@ -130,7 +130,7 @@ async def send_media_group(
                     else:
                         media = utils.get_input_media_from_file_id(i.media, FileType.PHOTO)
                 else:
-                    media = await self.send(
+                    media = await self.invoke(
                         raw.functions.messages.UploadMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=raw.types.InputMediaUploadedPhoto(
@@ -149,7 +149,7 @@ async def send_media_group(
             elif isinstance(i, types.InputMediaVideo):
                 if isinstance(i.media, str):
                     if os.path.isfile(i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaUploadedDocument(
@@ -177,7 +177,7 @@ async def send_media_group(
                             )
                         )
                     elif re.match("^https?://", i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaDocumentExternal(
@@ -196,7 +196,7 @@ async def send_media_group(
                     else:
                         media = utils.get_input_media_from_file_id(i.media, FileType.VIDEO)
                 else:
-                    media = await self.send(
+                    media = await self.invoke(
                         raw.functions.messages.UploadMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=raw.types.InputMediaUploadedDocument(
@@ -226,7 +226,7 @@ async def send_media_group(
             elif isinstance(i, types.InputMediaAudio):
                 if isinstance(i.media, str):
                     if os.path.isfile(i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaUploadedDocument(
@@ -253,7 +253,7 @@ async def send_media_group(
                             )
                         )
                     elif re.match("^https?://", i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaDocumentExternal(
@@ -272,7 +272,7 @@ async def send_media_group(
                     else:
                         media = utils.get_input_media_from_file_id(i.media, FileType.AUDIO)
                 else:
-                    media = await self.send(
+                    media = await self.invoke(
                         raw.functions.messages.UploadMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=raw.types.InputMediaUploadedDocument(
@@ -301,7 +301,7 @@ async def send_media_group(
             elif isinstance(i, types.InputMediaDocument):
                 if isinstance(i.media, str):
                     if os.path.isfile(i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaUploadedDocument(
@@ -323,7 +323,7 @@ async def send_media_group(
                             )
                         )
                     elif re.match("^https?://", i.media):
-                        media = await self.send(
+                        media = await self.invoke(
                             raw.functions.messages.UploadMedia(
                                 peer=await self.resolve_peer(chat_id),
                                 media=raw.types.InputMediaDocumentExternal(
@@ -342,7 +342,7 @@ async def send_media_group(
                     else:
                         media = utils.get_input_media_from_file_id(i.media, FileType.DOCUMENT)
                 else:
-                    media = await self.send(
+                    media = await self.invoke(
                         raw.functions.messages.UploadMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=raw.types.InputMediaUploadedDocument(
@@ -376,7 +376,7 @@ async def send_media_group(
                 )
             )
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMultiMedia(
                 peer=await self.resolve_peer(chat_id),
                 multi_media=multi_media,
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 70544178f9..414f744764 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -123,7 +123,7 @@ async def send_message(
 
         message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMessage(
                 peer=await self.resolve_peer(chat_id),
                 no_webpage=disable_web_page_preview or None,
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index 5cacfb39c3..e536d3a000 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -165,7 +165,7 @@ async def send_photo(
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index 10545256eb..0dd877b9e4 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -100,7 +100,7 @@ async def send_poll(
 
                 app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"])
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaPoll(
diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py
index b096934fc2..34c2d92c0a 100644
--- a/pyrogram/methods/messages/send_reaction.py
+++ b/pyrogram/methods/messages/send_reaction.py
@@ -54,7 +54,7 @@ async def send_reaction(
                 # Retract a reaction
                 app.send_reaction(chat_id, message_id)
         """
-        await self.send(
+        await self.invoke(
             raw.functions.messages.SendReaction(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id,
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index 460cfc6304..ca6f47a593 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -147,7 +147,7 @@ async def send_sticker(
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py
index 4dd81f7a3f..7ddb98efdc 100644
--- a/pyrogram/methods/messages/send_venue.py
+++ b/pyrogram/methods/messages/send_venue.py
@@ -99,7 +99,7 @@ async def send_venue(
                     "me", 51.500729, -0.124583,
                     "Elizabeth Tower", "Westminster, London SW1A 0AA, UK")
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),
                 media=raw.types.InputMediaVenue(
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index 9fd8521358..e1c245b1ad 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -222,7 +222,7 @@ def progress(current, total):
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index b4fd8891f5..7412e0eaf6 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -171,7 +171,7 @@ async def send_video_note(
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 5179866e0d..08e1bdc0f1 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -172,7 +172,7 @@ async def send_voice(
 
             while True:
                 try:
-                    r = await self.send(
+                    r = await self.invoke(
                         raw.functions.messages.SendMedia(
                             peer=await self.resolve_peer(chat_id),
                             media=media,
diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py
index 3fdba750d3..e642e1b666 100644
--- a/pyrogram/methods/messages/stop_poll.py
+++ b/pyrogram/methods/messages/stop_poll.py
@@ -56,7 +56,7 @@ async def stop_poll(
         """
         poll = (await self.get_messages(chat_id, message_id)).poll
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.EditMessage(
                 peer=await self.resolve_peer(chat_id),
                 id=message_id,
diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py
index 70a5036574..3fea2e22b9 100644
--- a/pyrogram/methods/messages/vote_poll.py
+++ b/pyrogram/methods/messages/vote_poll.py
@@ -56,7 +56,7 @@ async def vote_poll(
         poll = (await self.get_messages(chat_id, message_id)).poll
         options = [options] if not isinstance(options, list) else options
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.messages.SendVote(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id,
diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py
index a0e8296382..3f7dee0017 100644
--- a/pyrogram/methods/password/change_cloud_password.py
+++ b/pyrogram/methods/password/change_cloud_password.py
@@ -57,7 +57,7 @@ async def change_cloud_password(
                 # Change password and hint
                 app.change_cloud_password("current_password", "new_password", new_hint="hint")
         """
-        r = await self.send(raw.functions.account.GetPassword())
+        r = await self.invoke(raw.functions.account.GetPassword())
 
         if not r.has_password:
             raise ValueError("There is no cloud password to change")
@@ -66,7 +66,7 @@ async def change_cloud_password(
         new_hash = btoi(compute_password_hash(r.new_algo, new_password))
         new_hash = itob(pow(r.new_algo.g, new_hash, btoi(r.new_algo.p)))
 
-        await self.send(
+        await self.invoke(
             raw.functions.account.UpdatePasswordSettings(
                 password=compute_password_check(r, current_password),
                 new_settings=raw.types.account.PasswordInputSettings(
diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py
index 840acfdd49..fd8b3dbfd1 100644
--- a/pyrogram/methods/password/enable_cloud_password.py
+++ b/pyrogram/methods/password/enable_cloud_password.py
@@ -62,7 +62,7 @@ async def enable_cloud_password(
                 # Enable password with hint and email
                 app.enable_cloud_password("password", hint="hint", email="user@email.com")
         """
-        r = await self.send(raw.functions.account.GetPassword())
+        r = await self.invoke(raw.functions.account.GetPassword())
 
         if r.has_password:
             raise ValueError("There is already a cloud password enabled")
@@ -71,7 +71,7 @@ async def enable_cloud_password(
         new_hash = btoi(compute_password_hash(r.new_algo, password))
         new_hash = itob(pow(r.new_algo.g, new_hash, btoi(r.new_algo.p)))
 
-        await self.send(
+        await self.invoke(
             raw.functions.account.UpdatePasswordSettings(
                 password=raw.types.InputCheckPasswordEmpty(),
                 new_settings=raw.types.account.PasswordInputSettings(
diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py
index 1a1c9a0b56..845547d67c 100644
--- a/pyrogram/methods/password/remove_cloud_password.py
+++ b/pyrogram/methods/password/remove_cloud_password.py
@@ -43,12 +43,12 @@ async def remove_cloud_password(
 
                 app.remove_cloud_password("password")
         """
-        r = await self.send(raw.functions.account.GetPassword())
+        r = await self.invoke(raw.functions.account.GetPassword())
 
         if not r.has_password:
             raise ValueError("There is no cloud password to remove")
 
-        await self.send(
+        await self.invoke(
             raw.functions.account.UpdatePasswordSettings(
                 password=compute_password_check(r, password),
                 new_settings=raw.types.account.PasswordInputSettings(
diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py
index b1d96537fb..3298e60190 100644
--- a/pyrogram/methods/users/block_user.py
+++ b/pyrogram/methods/users/block_user.py
@@ -44,7 +44,7 @@ async def block_user(
                 app.block_user(user_id)
         """
         return bool(
-            await self.send(
+            await self.invoke(
                 raw.functions.contacts.Block(
                     id=await self.resolve_peer(user_id)
                 )
diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py
index a1df82eb7a..107f11a6a3 100644
--- a/pyrogram/methods/users/delete_profile_photos.py
+++ b/pyrogram/methods/users/delete_profile_photos.py
@@ -54,7 +54,7 @@ async def delete_profile_photos(
         photo_ids = photo_ids if isinstance(photo_ids, list) else [photo_ids]
         input_photos = [utils.get_input_media_from_file_id(i, FileType.PHOTO).id for i in photo_ids]
 
-        return bool(await self.send(
+        return bool(await self.invoke(
             raw.functions.photos.DeletePhotos(
                 id=input_photos
             )
diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py
index e083e3c981..6c7d5ce786 100644
--- a/pyrogram/methods/users/get_common_chats.py
+++ b/pyrogram/methods/users/get_common_chats.py
@@ -52,7 +52,7 @@ async def get_common_chats(
         peer = await self.resolve_peer(user_id)
 
         if isinstance(peer, raw.types.InputPeerUser):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetCommonChats(
                     user_id=peer,
                     max_id=0,
diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py
index 17ffe3b837..2869f85c8c 100644
--- a/pyrogram/methods/users/get_me.py
+++ b/pyrogram/methods/users/get_me.py
@@ -36,7 +36,7 @@ async def get_me(
                 me = app.get_me()
                 print(me)
         """
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.users.GetFullUser(
                 id=raw.types.InputUserSelf()
             )
diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py
index 62341550dd..ec35aa9eb1 100644
--- a/pyrogram/methods/users/get_profile_photos.py
+++ b/pyrogram/methods/users/get_profile_photos.py
@@ -65,7 +65,7 @@ async def get_profile_photos(
         peer_id = await self.resolve_peer(chat_id)
 
         if isinstance(peer_id, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.channels.GetFullChannel(
                     channel=peer_id
                 )
@@ -75,7 +75,7 @@ async def get_profile_photos(
 
             r = await utils.parse_messages(
                 self,
-                await self.send(
+                await self.invoke(
                     raw.functions.messages.Search(
                         peer=peer_id,
                         q="",
@@ -107,7 +107,7 @@ async def get_profile_photos(
 
             return types.List(photos[offset:limit])
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.photos.GetUserPhotos(
                     user_id=peer_id,
                     offset=offset,
diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py
index c0065dd7e0..41e50f5e8a 100644
--- a/pyrogram/methods/users/get_profile_photos_count.py
+++ b/pyrogram/methods/users/get_profile_photos_count.py
@@ -48,7 +48,7 @@ async def get_profile_photos_count(
         peer_id = await self.resolve_peer(chat_id)
 
         if isinstance(peer_id, raw.types.InputPeerChannel):
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.messages.GetSearchCounters(
                     peer=peer_id,
                     filters=[raw.types.InputMessagesFilterChatPhotos()],
@@ -57,7 +57,7 @@ async def get_profile_photos_count(
 
             return r[0].count
         else:
-            r = await self.send(
+            r = await self.invoke(
                 raw.functions.photos.GetUserPhotos(
                     user_id=peer_id,
                     offset=0,
diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py
index 0e9c961411..6f085c4f51 100644
--- a/pyrogram/methods/users/get_users.py
+++ b/pyrogram/methods/users/get_users.py
@@ -56,7 +56,7 @@ async def get_users(
         user_ids = list(user_ids) if is_iterable else [user_ids]
         user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids])
 
-        r = await self.send(
+        r = await self.invoke(
             raw.functions.users.GetUsers(
                 id=user_ids
             )
diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py
index a68db7cda2..a7d59092b3 100644
--- a/pyrogram/methods/users/set_profile_photo.py
+++ b/pyrogram/methods/users/set_profile_photo.py
@@ -64,7 +64,7 @@ async def set_profile_photo(
         """
 
         return bool(
-            await self.send(
+            await self.invoke(
                 raw.functions.photos.UploadProfilePhoto(
                     file=await self.save_file(photo),
                     video=await self.save_file(video)
diff --git a/pyrogram/methods/users/set_username.py b/pyrogram/methods/users/set_username.py
index eeffc25f6c..68e443f149 100644
--- a/pyrogram/methods/users/set_username.py
+++ b/pyrogram/methods/users/set_username.py
@@ -47,7 +47,7 @@ async def set_username(
         """
 
         return bool(
-            await self.send(
+            await self.invoke(
                 raw.functions.account.UpdateUsername(
                     username=username or ""
                 )
diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py
index 433105acf1..7593065862 100644
--- a/pyrogram/methods/users/unblock_user.py
+++ b/pyrogram/methods/users/unblock_user.py
@@ -44,7 +44,7 @@ async def unblock_user(
                 app.unblock_user(user_id)
         """
         return bool(
-            await self.send(
+            await self.invoke(
                 raw.functions.contacts.Unblock(
                     id=await self.resolve_peer(user_id)
                 )
diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py
index c77c8b4b5b..779aa6cf5c 100644
--- a/pyrogram/methods/users/update_profile.py
+++ b/pyrogram/methods/users/update_profile.py
@@ -60,7 +60,7 @@ async def update_profile(
         """
 
         return bool(
-            await self.send(
+            await self.invoke(
                 raw.functions.account.UpdateProfile(
                     first_name=first_name,
                     last_name=last_name,
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index 61ce87a24a..ab4aef823d 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -58,10 +58,10 @@ async def start(
                 await self.authorize()
 
             if not await self.storage.is_bot() and self.takeout:
-                self.takeout_id = (await self.send(raw.functions.account.InitTakeoutSession())).id
+                self.takeout_id = (await self.invoke(raw.functions.account.InitTakeoutSession())).id
                 log.warning(f"Takeout session {self.takeout_id} initiated")
 
-            await self.send(raw.functions.updates.GetState())
+            await self.invoke(raw.functions.updates.GetState())
         except (Exception, KeyboardInterrupt):
             await self.disconnect()
             raise
diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py
index d4083b2179..7df4fede30 100644
--- a/pyrogram/session/auth.py
+++ b/pyrogram/session/auth.py
@@ -59,7 +59,7 @@ def unpack(b: BytesIO):
         b.seek(20)  # Skip auth_key_id (8), message_id (8) and message_length (4)
         return TLObject.read(b)
 
-    async def send(self, data: TLObject):
+    async def invoke(self, data: TLObject):
         data = self.pack(data)
         await self.connection.send(data)
         response = BytesIO(await self.connection.recv())
@@ -86,7 +86,7 @@ async def create(self):
                 # Step 1; Step 2
                 nonce = int.from_bytes(urandom(16), "little", signed=True)
                 log.debug(f"Send req_pq: {nonce}")
-                res_pq = await self.send(raw.functions.ReqPqMulti(nonce=nonce))
+                res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
                 log.debug(f"Got ResPq: {res_pq.server_nonce}")
                 log.debug(f"Server public key fingerprints: {res_pq.server_public_key_fingerprints}")
 
@@ -130,7 +130,7 @@ async def create(self):
 
                 # Step 5. TODO: Handle "server_DH_params_fail". Code assumes response is ok
                 log.debug("Send req_DH_params")
-                server_dh_params = await self.send(
+                server_dh_params = await self.invoke(
                     raw.functions.ReqDHParams(
                         nonce=nonce,
                         server_nonce=server_nonce,
@@ -190,7 +190,7 @@ async def create(self):
                 encrypted_data = aes.ige256_encrypt(data_with_hash, tmp_aes_key, tmp_aes_iv)
 
                 log.debug("Send set_client_DH_params")
-                set_client_dh_params_answer = await self.send(
+                set_client_dh_params_answer = await self.invoke(
                     raw.functions.SetClientDHParams(
                         nonce=nonce,
                         server_nonce=server_nonce,
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 05d1fd4a3f..3b0edca292 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -106,10 +106,10 @@ async def start(self):
 
                 self.network_task = self.loop.create_task(self.network_worker())
 
-                await self._send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT)
+                await self.send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT)
 
                 if not self.is_cdn:
-                    await self._send(
+                    await self.send(
                         raw.functions.InvokeWithLayer(
                             layer=layer,
                             query=raw.functions.InitConnection(
@@ -240,7 +240,7 @@ async def handle_packet(self, packet):
             log.debug(f"Send {len(self.pending_acks)} acks")
 
             try:
-                await self._send(raw.types.MsgsAck(msg_ids=list(self.pending_acks)), False)
+                await self.send(raw.types.MsgsAck(msg_ids=list(self.pending_acks)), False)
             except (OSError, TimeoutError):
                 pass
             else:
@@ -258,7 +258,7 @@ async def ping_worker(self):
                 break
 
             try:
-                await self._send(
+                await self.send(
                     raw.functions.PingDelayDisconnect(
                         ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10
                     ), False
@@ -287,7 +287,7 @@ async def network_worker(self):
 
         log.info("NetworkTask stopped")
 
-    async def _send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT):
+    async def send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT):
         message = self.msg_factory(data)
         msg_id = message.msg_id
 
@@ -334,13 +334,13 @@ async def _send(self, data: TLObject, wait_response: bool = True, timeout: float
                 raise BadMsgNotification(result.error_code)
             elif isinstance(result, raw.types.BadServerSalt):
                 self.salt = result.new_server_salt
-                return await self._send(data, wait_response, timeout)
+                return await self.send(data, wait_response, timeout)
             else:
                 return result
 
-    async def send(
+    async def invoke(
         self,
-        data: TLObject,
+        query: TLObject,
         retries: int = MAX_RETRIES,
         timeout: float = WAIT_TIMEOUT,
         sleep_threshold: float = SLEEP_THRESHOLD
@@ -350,16 +350,14 @@ async def send(
         except asyncio.TimeoutError:
             pass
 
-        if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)):
-            query = data.query
-        else:
-            query = data
+        if isinstance(query, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)):
+            query = query.query
 
-        query = ".".join(query.QUALNAME.split(".")[1:])
+        query_name = ".".join(query.QUALNAME.split(".")[1:])
 
         while True:
             try:
-                return await self._send(data, timeout=timeout)
+                return await self.send(query, timeout=timeout)
             except FloodWait as e:
                 amount = e.x
 
@@ -367,7 +365,7 @@ async def send(
                     raise
 
                 log.warning(f'[{self.client.session_name}] Waiting for {amount} seconds before continuing '
-                            f'(required by "{query}")')
+                            f'(required by "{query_name}")')
 
                 await asyncio.sleep(amount)
             except (OSError, TimeoutError, InternalServerError, ServiceUnavailable) as e:
@@ -375,8 +373,8 @@ async def send(
                     raise e from None
 
                 (log.warning if retries < 2 else log.info)(
-                    f'[{Session.MAX_RETRIES - retries + 1}] Retrying "{query}" due to {str(e) or repr(e)}')
+                    f'[{Session.MAX_RETRIES - retries + 1}] Retrying "{query_name}" due to {str(e) or repr(e)}')
 
                 await asyncio.sleep(0.5)
 
-                return await self.send(data, retries - 1, timeout)
+                return await self.invoke(query, retries - 1, timeout)
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index e9f3cab6d2..f7965e6a21 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -462,7 +462,7 @@ async def _parse(
         if isinstance(message.from_id, raw.types.PeerUser) and isinstance(message.peer_id, raw.types.PeerUser):
             if from_id not in users or peer_id not in users:
                 try:
-                    r = await client.send(
+                    r = await client.invoke(
                         raw.functions.users.GetUsers(
                             id=[
                                 await client.resolve_peer(from_id),
diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py
index fa6e0be3fb..201b579f17 100644
--- a/pyrogram/types/messages_and_media/sticker.py
+++ b/pyrogram/types/messages_and_media/sticker.py
@@ -112,7 +112,7 @@ def __init__(
     cache = {}
 
     @staticmethod
-    async def _get_sticker_set_name(send, input_sticker_set_id):
+    async def _get_sticker_set_name(invoke, input_sticker_set_id):
         try:
             set_id = input_sticker_set_id[0]
             set_access_hash = input_sticker_set_id[1]
@@ -122,7 +122,7 @@ async def _get_sticker_set_name(send, input_sticker_set_id):
             if name is not None:
                 return name
 
-            name = (await send(
+            name = (await invoke(
                 raw.functions.messages.GetStickerSet(
                     stickerset=raw.types.InputStickerSetID(
                         id=set_id,
@@ -154,7 +154,7 @@ async def _parse(
 
         if isinstance(sticker_set, raw.types.InputStickerSetID):
             input_sticker_set_id = (sticker_set.id, sticker_set.access_hash)
-            set_name = await Sticker._get_sticker_set_name(client.send, input_sticker_set_id)
+            set_name = await Sticker._get_sticker_set_name(client.invoke, input_sticker_set_id)
         else:
             set_name = None
 

From 41f16a17c9e59d159985bfad0e14c0fc3999be17 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 145/539] Fix filters.command not working with multiple running
 bots Closes #864

---
 pyrogram/client.py                  |  3 +++
 pyrogram/filters.py                 | 12 +-----------
 pyrogram/methods/auth/initialize.py |  1 +
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index 920b723311..ac753f8849 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -286,6 +286,9 @@ def __init__(
 
         self.disconnect_handler = None
 
+        # Username used for mentioned bot commands, e.g.: /start@usernamebot
+        self.username = None
+
         self.loop = asyncio.get_event_loop()
 
     def __enter__(self):
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index 2eeef95c59..348e6e7a72 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -745,11 +745,6 @@ async def linked_channel_filter(_, __, m: Message):
 
 
 # region command_filter
-
-# Used by the command filter below
-username = None
-
-
 def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "/", case_sensitive: bool = False):
     """Filter commands, i.e.: text messages starting with "/" or any other custom prefix.
 
@@ -772,12 +767,7 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "
     command_re = re.compile(r"([\"'])(.*?)(?
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 146/539] Fix invited_by being optional

---
 pyrogram/types/user_and_chats/chat_member.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index 9b585d7cb5..cff2ac430d 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -151,7 +151,10 @@ def _parse(
                 user=types.User._parse(client, users[member.user_id]),
                 joined_date=utils.timestamp_to_datetime(member.date),
                 promoted_by=types.User._parse(client, users[member.promoted_by]),
-                invited_by=types.User._parse(client, users[member.inviter_id]),
+                invited_by=(
+                    types.User._parse(client, users[member.inviter_id])
+                    if member.inviter_id else None
+                ),
                 custom_title=member.rank,
                 can_be_edited=member.can_edit,
                 privileges=types.ChatPrivileges._parse(member.admin_rights),

From bf8a334e328d07be14023512c3b32a9073f6980c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 147/539] Revamp get_chat_history related methods

---
 compiler/docs/compiler.py                     |  7 +--
 pyrogram/methods/messages/__init__.py         | 12 ++--
 .../{iter_history.py => get_chat_history.py}  | 61 ++++++++++++-------
 ...ory_count.py => get_chat_history_count.py} |  4 +-
 .../{read_history.py => read_chat_history.py} |  4 +-
 5 files changed, 53 insertions(+), 35 deletions(-)
 rename pyrogram/methods/messages/{iter_history.py => get_chat_history.py} (70%)
 rename pyrogram/methods/messages/{get_history_count.py => get_chat_history_count.py} (97%)
 rename pyrogram/methods/messages/{read_history.py => read_chat_history.py} (97%)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 53ceb91cef..4c632bffad 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -171,10 +171,9 @@ def get_title_list(s: str) -> list:
             delete_messages
             get_messages
             get_media_group
-            get_history
-            get_history_count
-            read_history
-            iter_history
+            get_chat_history
+            get_chat_history_count
+            read_chat_history
             send_poll
             vote_poll
             stop_poll
diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py
index 6b78eeb8ce..18cd65e311 100644
--- a/pyrogram/methods/messages/__init__.py
+++ b/pyrogram/methods/messages/__init__.py
@@ -29,13 +29,13 @@
 from .edit_message_reply_markup import EditMessageReplyMarkup
 from .edit_message_text import EditMessageText
 from .forward_messages import ForwardMessages
+from .get_chat_history import GetChatHistory
+from .get_chat_history_count import GetChatHistoryCount
 from .get_discussion_message import GetDiscussionMessage
 from .get_history import GetHistory
-from .get_history_count import GetHistoryCount
 from .get_media_group import GetMediaGroup
 from .get_messages import GetMessages
-from .iter_history import IterHistory
-from .read_history import ReadHistory
+from .read_chat_history import ReadChatHistory
 from .retract_vote import RetractVote
 from .search_global import SearchGlobal
 from .search_global_count import SearchGlobalCount
@@ -92,10 +92,10 @@ class Messages(
     StopPoll,
     RetractVote,
     DownloadMedia,
-    IterHistory,
+    GetChatHistory,
     SendCachedMedia,
-    GetHistoryCount,
-    ReadHistory,
+    GetChatHistoryCount,
+    ReadChatHistory,
     EditInlineText,
     EditInlineCaption,
     EditInlineMedia,
diff --git a/pyrogram/methods/messages/iter_history.py b/pyrogram/methods/messages/get_chat_history.py
similarity index 70%
rename from pyrogram/methods/messages/iter_history.py
rename to pyrogram/methods/messages/get_chat_history.py
index 4914cd1d41..bc2ed41fa7 100644
--- a/pyrogram/methods/messages/iter_history.py
+++ b/pyrogram/methods/messages/get_chat_history.py
@@ -20,24 +20,47 @@
 from typing import Union, Optional, AsyncGenerator
 
 import pyrogram
-from pyrogram import types
-
-
-class IterHistory:
-    async def iter_history(
+from pyrogram import types, raw, utils
+
+
+async def get_chunk(
+    *,
+    client: "pyrogram.Client",
+    chat_id: Union[int, str],
+    limit: int = 0,
+    offset: int = 0,
+    from_message_id: int = 0,
+    from_date: datetime = datetime.fromtimestamp(0)
+):
+    messages = await client.invoke(
+        raw.functions.messages.GetHistory(
+            peer=await client.resolve_peer(chat_id),
+            offset_id=from_message_id,
+            offset_date=utils.datetime_to_timestamp(from_date),
+            add_offset=offset,
+            limit=limit,
+            max_id=0,
+            min_id=0,
+            hash=0
+        ),
+        sleep_threshold=60
+    )
+
+    return await utils.parse_messages(client, messages, replies=0)
+
+
+class GetChatHistory:
+    async def get_chat_history(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
         limit: int = 0,
         offset: int = 0,
         offset_id: int = 0,
-        offset_date: datetime = datetime.fromtimestamp(0),
-        reverse: bool = False
+        offset_date: datetime = datetime.fromtimestamp(0)
     ) -> Optional[AsyncGenerator["types.Message", None]]:
-        """Iterate through a chat history sequentially.
+        """Get messages from a chat history.
 
-        This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_history` in a loop, thus saving
-        you from the hassle of setting up boilerplate code. It is useful for getting the whole chat history with a
-        single call.
+        The messages are returned in reverse chronological order.
 
         Parameters:
             chat_id (``int`` | ``str``):
@@ -59,37 +82,33 @@ async def iter_history(
             offset_date (:py:obj:`~datetime.datetime`, *optional*):
                 Pass a date as offset to retrieve only older messages starting from that date.
 
-            reverse (``bool``, *optional*):
-                Pass True to retrieve the messages in reversed order (from older to most recent).
-
         Returns:
             ``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.
 
         Example:
             .. code-block:: python
 
-                for message in app.iter_history("pyrogram"):
+                for message in app.get_chat_history(chat_id):
                     print(message.text)
         """
-        offset_id = offset_id or (1 if reverse else 0)
         current = 0
         total = limit or (1 << 31) - 1
         limit = min(100, total)
 
         while True:
-            messages = await self.get_history(
+            messages = await get_chunk(
+                client=self,
                 chat_id=chat_id,
                 limit=limit,
                 offset=offset,
-                offset_id=offset_id,
-                offset_date=offset_date,
-                reverse=reverse
+                from_message_id=offset_id,
+                from_date=offset_date
             )
 
             if not messages:
                 return
 
-            offset_id = messages[-1].id + (1 if reverse else 0)
+            offset_id = messages[-1].id
 
             for message in messages:
                 yield message
diff --git a/pyrogram/methods/messages/get_history_count.py b/pyrogram/methods/messages/get_chat_history_count.py
similarity index 97%
rename from pyrogram/methods/messages/get_history_count.py
rename to pyrogram/methods/messages/get_chat_history_count.py
index 12e068ae84..fbe6bfcad9 100644
--- a/pyrogram/methods/messages/get_history_count.py
+++ b/pyrogram/methods/messages/get_chat_history_count.py
@@ -25,8 +25,8 @@
 log = logging.getLogger(__name__)
 
 
-class GetHistoryCount:
-    async def get_history_count(
+class GetChatHistoryCount:
+    async def get_chat_history_count(
         self: "pyrogram.Client",
         chat_id: Union[int, str]
     ) -> int:
diff --git a/pyrogram/methods/messages/read_history.py b/pyrogram/methods/messages/read_chat_history.py
similarity index 97%
rename from pyrogram/methods/messages/read_history.py
rename to pyrogram/methods/messages/read_chat_history.py
index 204d9e3114..caa228fd28 100644
--- a/pyrogram/methods/messages/read_history.py
+++ b/pyrogram/methods/messages/read_chat_history.py
@@ -22,8 +22,8 @@
 from pyrogram import raw
 
 
-class ReadHistory:
-    async def read_history(
+class ReadChatHistory:
+    async def read_chat_history(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
         max_id: int = 0

From 5f6788ad69da03f45e958794b042f60a71a15444 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 148/539] Improvements to the documentation

---
 compiler/docs/compiler.py                          |  2 +-
 ...-send-raised-exception-oserror-timeouterror.rst | 14 ++++++++------
 docs/source/topics/advanced-usage.rst              |  2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 4c632bffad..78231f7d15 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -310,7 +310,7 @@ def get_title_list(s: str) -> list:
         """,
         advanced="""
         Advanced
-            send
+            invoke
             resolve_peer
             save_file
         """
diff --git a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst
index e6a934d2e9..21ee1a900c 100644
--- a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst
+++ b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst
@@ -1,10 +1,12 @@
 socket.send() raised exception, OSError(), TimeoutError()
 =========================================================
 
-If you get this error chances are you are blocking the event loop for too long.
-In general, it means you are executing thread-blocking code that prevents the event loop from
-running properly. For example:
+If you get this error chances are you are blocking the event loop for too long, most likely due to an improper use of
+non-asynchronous or threaded operations which may lead to blocking code that prevents the event loop from running
+properly.
 
-- You are using ``time.sleep()`` instead of ``asyncio.sleep()``.
-- You are running processing loops that take too much time to complete.
-- You are reading/writing files to disk that take too much time to complete.
\ No newline at end of file
+You can consider the following:
+
+- Use Pyrogram asynchronously in its intended way.
+- Use shorter non-asynchronous processing loops.
+- Use ``asyncio.sleep()`` instead of ``time.sleep()``.
diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst
index 0b0f068323..c84528e4e1 100644
--- a/docs/source/topics/advanced-usage.rst
+++ b/docs/source/topics/advanced-usage.rst
@@ -38,7 +38,7 @@ live in their respective packages (and sub-packages): ``pyrogram.raw.functions``
 as Python classes, meaning you need to create an instance of each every time you need them and fill them in with the
 correct values using named arguments.
 
-Next, to actually invoke the raw function you have to use the :meth:`~pyrogram.Client.send` method provided by the
+Next, to actually invoke the raw function you have to use the :meth:`~pyrogram.Client.invoke` method provided by the
 Client class and pass the function object you created.
 
 Here's some examples:

From d1bdaae81de0f73e8b0c37bed69955a74ba939bd Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 149/539] Add methods related to discussion threads and
 comments

---
 compiler/docs/compiler.py                     |  2 +
 pyrogram/methods/messages/__init__.py         |  6 +-
 .../messages/get_discussion_message.py        |  5 +-
 .../messages/get_discussion_replies.py        | 84 +++++++++++++++++++
 .../messages/get_discussion_replies_count.py  | 60 +++++++++++++
 5 files changed, 154 insertions(+), 3 deletions(-)
 create mode 100644 pyrogram/methods/messages/get_discussion_replies.py
 create mode 100644 pyrogram/methods/messages/get_discussion_replies_count.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 78231f7d15..3357d91157 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -185,6 +185,8 @@ def get_title_list(s: str) -> list:
             search_global_count
             download_media
             get_discussion_message
+            get_discussion_replies
+            get_discussion_replies_count
         """,
         chats="""
         Chats
diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py
index 18cd65e311..62509d9e0b 100644
--- a/pyrogram/methods/messages/__init__.py
+++ b/pyrogram/methods/messages/__init__.py
@@ -32,6 +32,8 @@
 from .get_chat_history import GetChatHistory
 from .get_chat_history_count import GetChatHistoryCount
 from .get_discussion_message import GetDiscussionMessage
+from .get_discussion_replies import GetDiscussionReplies
+from .get_discussion_replies_count import GetDiscussionRepliesCount
 from .get_history import GetHistory
 from .get_media_group import GetMediaGroup
 from .get_messages import GetMessages
@@ -108,6 +110,8 @@ class Messages(
     SearchMessagesCount,
     SearchGlobalCount,
     GetDiscussionMessage,
-    SendReaction
+    SendReaction,
+    GetDiscussionReplies,
+    GetDiscussionRepliesCount
 ):
     pass
diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py
index 6c72b484de..cbcc7bfed2 100644
--- a/pyrogram/methods/messages/get_discussion_message.py
+++ b/pyrogram/methods/messages/get_discussion_message.py
@@ -29,9 +29,10 @@ async def get_discussion_message(
         chat_id: Union[int, str],
         message_id: int,
     ) -> "types.Message":
-        """Get the discussion message from the linked discussion group of a channel post.
+        """Get the first discussion message of a channel post or a discussion thread in a group.
 
-        Reply to the returned message to leave a comment on the linked channel post.
+        Reply to the returned message to leave a comment on the linked channel post or to continue
+        the discussion thread.
 
         Parameters:
             chat_id (``int`` | ``str``):
diff --git a/pyrogram/methods/messages/get_discussion_replies.py b/pyrogram/methods/messages/get_discussion_replies.py
new file mode 100644
index 0000000000..b1279de542
--- /dev/null
+++ b/pyrogram/methods/messages/get_discussion_replies.py
@@ -0,0 +1,84 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Union, Optional, AsyncGenerator
+
+import pyrogram
+from pyrogram import types, raw
+
+
+class GetDiscussionReplies:
+    async def get_discussion_replies(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str],
+        message_id: int,
+        limit: int = 0,
+    ) -> Optional[AsyncGenerator["types.Message", None]]:
+        """Get the message replies of a discussion thread.
+
+        Parameters:
+            chat_id (``int`` | ``str``):
+                Unique identifier (int) or username (str) of the target chat.
+
+            message_id (``int``):
+                Message id.
+
+            limit (``int``, *optional*):
+                Limits the number of messages to be retrieved.
+                By default, no limit is applied and all messages are returned.
+
+        Example:
+            .. code-block:: python
+
+            for m in app.get_discussion_replies(chat_id, message_id):
+                print(m)
+        """
+
+        current = 0
+        total = limit or (1 << 31) - 1
+        limit = min(100, total)
+
+        while True:
+            r = await self.invoke(
+                raw.functions.messages.GetReplies(
+                    peer=await self.resolve_peer(chat_id),
+                    msg_id=message_id,
+                    offset_id=0,
+                    offset_date=0,
+                    add_offset=current,
+                    limit=limit,
+                    max_id=0,
+                    min_id=0,
+                    hash=0
+                )
+            )
+
+            users = {u.id: u for u in r.users}
+            chats = {c.id: c for c in r.chats}
+            messages = r.messages
+
+            if not messages:
+                return
+
+            for message in messages:
+                yield await types.Message._parse(self, message, users, chats, replies=0)
+
+                current += 1
+
+                if current >= total:
+                    return
diff --git a/pyrogram/methods/messages/get_discussion_replies_count.py b/pyrogram/methods/messages/get_discussion_replies_count.py
new file mode 100644
index 0000000000..cb5c1e8ba3
--- /dev/null
+++ b/pyrogram/methods/messages/get_discussion_replies_count.py
@@ -0,0 +1,60 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Union
+
+import pyrogram
+from pyrogram import raw
+
+
+class GetDiscussionRepliesCount:
+    async def get_discussion_replies_count(
+        self: "pyrogram.Client",
+        chat_id: Union[int, str],
+        message_id: int,
+    ) -> int:
+        """Get the total count of replies in a discussion thread.
+
+        Parameters:
+            chat_id (``int`` | ``str``):
+                Unique identifier (int) or username (str) of the target chat.
+
+            message_id (``int``):
+                Message id.
+
+        Example:
+            .. code-block:: python
+
+            count = app.get_discussion_replies_count(chat_id, message_id)
+        """
+
+        r = await self.invoke(
+            raw.functions.messages.GetReplies(
+                peer=await self.resolve_peer(chat_id),
+                msg_id=message_id,
+                offset_id=0,
+                offset_date=0,
+                add_offset=0,
+                limit=1,
+                max_id=0,
+                min_id=0,
+                hash=0
+            )
+        )
+
+        return r.count

From 04eef0909716c489866688af92b16672ab8acf6e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 150/539] Don't fetch reply-to messages in search_messages

---
 pyrogram/methods/messages/search_messages.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index b40826d9a2..da24f31708 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -54,7 +54,7 @@ async def get_chunk(
         sleep_threshold=60
     )
 
-    return await utils.parse_messages(client, r)
+    return await utils.parse_messages(client, r, replies=0)
 
 
 class SearchMessages:

From bbc109d73eb111803af74c31d4dc7124173a07e9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 151/539] Remove unused method

---
 pyrogram/methods/messages/__init__.py    |   2 -
 pyrogram/methods/messages/get_history.py | 107 -----------------------
 2 files changed, 109 deletions(-)
 delete mode 100644 pyrogram/methods/messages/get_history.py

diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py
index 62509d9e0b..0bf34900d0 100644
--- a/pyrogram/methods/messages/__init__.py
+++ b/pyrogram/methods/messages/__init__.py
@@ -34,7 +34,6 @@
 from .get_discussion_message import GetDiscussionMessage
 from .get_discussion_replies import GetDiscussionReplies
 from .get_discussion_replies_count import GetDiscussionRepliesCount
-from .get_history import GetHistory
 from .get_media_group import GetMediaGroup
 from .get_messages import GetMessages
 from .read_chat_history import ReadChatHistory
@@ -72,7 +71,6 @@ class Messages(
     EditMessageMedia,
     EditMessageText,
     ForwardMessages,
-    GetHistory,
     GetMediaGroup,
     GetMessages,
     SendAudio,
diff --git a/pyrogram/methods/messages/get_history.py b/pyrogram/methods/messages/get_history.py
deleted file mode 100644
index ae8e1f37a8..0000000000
--- a/pyrogram/methods/messages/get_history.py
+++ /dev/null
@@ -1,107 +0,0 @@
-#  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-present Dan 
-#
-#  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 logging
-from datetime import datetime
-from typing import Union, List
-
-import pyrogram
-from pyrogram import raw
-from pyrogram import types
-from pyrogram import utils
-
-log = logging.getLogger(__name__)
-
-
-class GetHistory:
-    async def get_history(
-        self: "pyrogram.Client",
-        chat_id: Union[int, str],
-        limit: int = 100,
-        offset: int = 0,
-        offset_id: int = 0,
-        offset_date: datetime = datetime.fromtimestamp(0),
-        reverse: bool = False
-    ) -> List["types.Message"]:
-        """Retrieve a chunk of the history of a chat.
-
-        You can get up to 100 messages at once.
-        For a more convenient way of getting a chat history see :meth:`~pyrogram.Client.iter_history`.
-
-        Parameters:
-            chat_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).
-
-            limit (``int``, *optional*):
-                Limits the number of messages to be retrieved.
-                By default, the first 100 messages are returned.
-
-            offset (``int``, *optional*):
-                Sequential number of the first message to be returned. Defaults to 0 (most recent message).
-                Negative values are also accepted and become useful in case you set offset_id or offset_date.
-
-            offset_id (``int``, *optional*):
-                Pass a message identifier as offset to retrieve only older messages starting from that message.
-
-            offset_date (:py:obj:`~datetime.datetime`, *optional*):
-                Pass a date as offset to retrieve only older messages starting from that date.
-
-            reverse (``bool``, *optional*):
-                Pass True to retrieve the messages in reversed order (from older to most recent).
-
-        Returns:
-            List of :obj:`~pyrogram.types.Message` - On success, a list of the retrieved messages is returned.
-
-        Example:
-            .. code-block:: python
-
-                # Get the last 100 messages of a chat
-                app.get_history(chat_id)
-
-                # Get the last 3 messages of a chat
-                app.get_history(chat_id, limit=3)
-
-                # Get 3 messages after skipping the first 5
-                app.get_history(chat_id, offset=5, limit=3)
-        """
-
-        offset_id = offset_id or (1 if reverse else 0)
-
-        messages = await utils.parse_messages(
-            self,
-            await self.invoke(
-                raw.functions.messages.GetHistory(
-                    peer=await self.resolve_peer(chat_id),
-                    offset_id=offset_id,
-                    offset_date=utils.datetime_to_timestamp(offset_date),
-                    add_offset=offset * (-1 if reverse else 1) - (limit if reverse else 0),
-                    limit=limit,
-                    max_id=0,
-                    min_id=0,
-                    hash=0
-                ),
-                sleep_threshold=60
-            )
-        )
-
-        if reverse:
-            messages.reverse()
-
-        return messages

From 84f0b3a97a63ad5d7284060ebdc4e7650d2192d3 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 152/539] Rename some enums

---
 pyrogram/enums/chat_members_filter.py              | 4 ++--
 pyrogram/enums/messages_filter.py                  | 4 ++--
 pyrogram/methods/messages/search_global.py         | 2 +-
 pyrogram/methods/messages/search_global_count.py   | 2 +-
 pyrogram/methods/messages/search_messages.py       | 4 ++--
 pyrogram/methods/messages/search_messages_count.py | 2 +-
 pyrogram/types/user_and_chats/chat.py              | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/pyrogram/enums/chat_members_filter.py b/pyrogram/enums/chat_members_filter.py
index 089f3d4bb9..bf0e7ef358 100644
--- a/pyrogram/enums/chat_members_filter.py
+++ b/pyrogram/enums/chat_members_filter.py
@@ -23,8 +23,8 @@
 class ChatMembersFilter(AutoName):
     """Chat members filter enumeration used in :meth:`~pyrogram.Client.get_chat_members`"""
 
-    ANY = raw.types.ChannelParticipantsSearch
-    "Any kind of member"
+    SEARCH = raw.types.ChannelParticipantsSearch
+    "Search for members"
 
     BANNED = raw.types.ChannelParticipantsKicked
     "Banned members"
diff --git a/pyrogram/enums/messages_filter.py b/pyrogram/enums/messages_filter.py
index 64d856aa98..b9c84fc939 100644
--- a/pyrogram/enums/messages_filter.py
+++ b/pyrogram/enums/messages_filter.py
@@ -23,8 +23,8 @@
 class MessagesFilter(AutoName):
     """Messages filter enumeration used in used in :meth:`~pyrogram.Client.search_messages` and used in :meth:`~pyrogram.Client.search_global`"""
 
-    ANY = raw.types.InputMessagesFilterEmpty
-    "Any kind of message"
+    EMPTY = raw.types.InputMessagesFilterEmpty
+    "Empty filter (any kind of messages)"
 
     PHOTO = raw.types.InputMessagesFilterPhotos
     "Photo messages"
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index a6ab555744..b53dbf3218 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -28,7 +28,7 @@ class SearchGlobal:
     async def search_global(
         self: "pyrogram.Client",
         query: str = "",
-        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
         limit: int = 0,
     ) -> Optional[AsyncGenerator["types.Message", None]]:
         """Search messages globally from all of your chats.
diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py
index afdad4c188..2e559ded9f 100644
--- a/pyrogram/methods/messages/search_global_count.py
+++ b/pyrogram/methods/messages/search_global_count.py
@@ -24,7 +24,7 @@ class SearchGlobalCount:
     async def search_global_count(
         self: "pyrogram.Client",
         query: str = "",
-        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
     ) -> int:
         """Get the count of messages resulting from a global search.
 
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index da24f31708..0e31871c6c 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -27,7 +27,7 @@ async def get_chunk(
     client,
     chat_id: Union[int, str],
     query: str = "",
-    filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
+    filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
     offset: int = 0,
     limit: int = 100,
     from_user: Union[int, str] = None
@@ -64,7 +64,7 @@ async def search_messages(
         chat_id: Union[int, str],
         query: str = "",
         offset: int = 0,
-        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
         limit: int = 0,
         from_user: Union[int, str] = None
     ) -> Optional[AsyncGenerator["types.Message", None]]:
diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py
index 301563e140..09f778559b 100644
--- a/pyrogram/methods/messages/search_messages_count.py
+++ b/pyrogram/methods/messages/search_messages_count.py
@@ -27,7 +27,7 @@ async def search_messages_count(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
         query: str = "",
-        filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
+        filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
         from_user: Union[int, str] = None
     ) -> int:
         """Get the count of messages resulting from a search inside a chat.
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index 870391a49d..f48f3c0f01 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -843,7 +843,7 @@ async def get_members(
         offset: int = 0,
         limit: int = 200,
         query: str = "",
-        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
+        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.SEARCH
     ) -> List["types.ChatMember"]:
         """Bound method *get_members* of :obj:`~pyrogram.types.Chat`.
 

From 405528c74b2a9a27d20ffd7084df3ca75edc0b66 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 153/539] Revamp get_chat_members related methods

---
 compiler/docs/compiler.py                  |   1 -
 pyrogram/methods/chats/get_chat_members.py | 156 ++++++++++++---------
 2 files changed, 86 insertions(+), 71 deletions(-)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 3357d91157..8c75d711d3 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -209,7 +209,6 @@ def get_title_list(s: str) -> list:
             get_chat_member
             get_chat_members
             get_chat_members_count
-            iter_chat_members
             get_dialogs
             iter_dialogs
             get_dialogs_count
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index a192c3e3ea..c2516a7081 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -25,69 +25,90 @@
 log = logging.getLogger(__name__)
 
 
+async def get_chunk(
+    client: "pyrogram.Client",
+    chat_id: Union[int, str],
+    offset: int,
+    filter: "enums.ChatMembersFilter",
+    limit: int,
+    query: str,
+):
+    is_queryable = filter in [enums.ChatMembersFilter.SEARCH,
+                              enums.ChatMembersFilter.BANNED,
+                              enums.ChatMembersFilter.RESTRICTED]
+
+    filter = filter.value(q=query) if is_queryable else filter.value()
+
+    r = await client.invoke(
+        raw.functions.channels.GetParticipants(
+            channel=await client.resolve_peer(chat_id),
+            filter=filter,
+            offset=offset,
+            limit=limit,
+            hash=0
+        ),
+        sleep_threshold=60
+    )
+
+    members = r.participants
+    users = {u.id: u for u in r.users}
+    chats = {c.id: c for c in r.chats}
+
+    return [types.ChatMember._parse(client, member, users, chats) for member in members]
+
+
 class GetChatMembers:
     async def get_chat_members(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
-        offset: int = 0,
-        limit: int = 200,
         query: str = "",
-        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
+        limit: int = 0,
+        filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.SEARCH
     ) -> List["types.ChatMember"]:
-        """Get a chunk of the members list of a chat.
+        """Get the members list of a chat.
 
-        You can get up to 200 chat members at once.
         A chat can be either a basic group, a supergroup or a channel.
-        You must be admin to retrieve the members list of a channel (also known as "subscribers").
-        For a more convenient way of getting chat members see :meth:`~pyrogram.Client.iter_chat_members`.
+        Requires administrator rights in channels.
 
         Parameters:
             chat_id (``int`` | ``str``):
                 Unique identifier (int) or username (str) of the target chat.
 
-            offset (``int``, *optional*):
-                Sequential number of the first member to be returned.
-                Only applicable to supergroups and channels. Defaults to 0.
-
-            limit (``int``, *optional*):
-                Limits the number of members to be retrieved.
-                Only applicable to supergroups and channels.
-                Defaults to 200.
-
             query (``str``, *optional*):
                 Query string to filter members based on their display names and usernames.
                 Only applicable to supergroups and channels. Defaults to "" (empty string).
-                A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only
+                A query string is applicable only for :obj:`~pyrogram.enums.ChatMembersFilter.SEARCH`,
+                :obj:`~pyrogram.enums.ChatMembersFilter.BANNED` and :obj:`~pyrogram.enums.ChatMembersFilter.RESTRICTED`
+                filters only.
+
+            limit (``int``, *optional*):
+                Limits the number of members to be retrieved.
 
-            filter (``str``, *optional*):
+            filter (:obj:`~pyrogram.enums.ChatMembersFilter`, *optional*):
                 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
-                and channels. It can be any of the followings:
-                *"all"* - all kind of members,
-                *"banned"* - banned members only,
-                *"restricted"* - restricted members only,
-                *"bots"* - bots only,
-                *"recent"* - recent members only,
-                *"administrators"* - chat administrators only.
-                Only applicable to supergroups and channels.
-                Defaults to *"recent"*.
+                and channels.
 
         Returns:
-            List of :obj:`~pyrogram.types.ChatMember`: On success, a list of chat members is returned.
-
-        Raises:
-            ValueError: In case you used an invalid filter or a chat id that belongs to a user.
+            ``Generator``: On success, a generator yielding :obj:`~pyrogram.types.ChatMember` objects is returned.
 
         Example:
             .. code-block:: python
 
-                # Get first 200 recent members
-                app.get_chat_members(chat_id)
+                from pyrogram import enums
+
+                # Get members
+                for member in app.get_chat_members(chat_id):
+                    print(member)
 
-                # Get all administrators
-                app.get_chat_members(chat_id, filter="administrators")
+                # Get administrators
+                administrators = list(app.get_chat_members(
+                    chat_id,
+                    filter=enums.ChatMembersFilter.ADMINISTRATORS))
 
-                # Get all bots
-                app.get_chat_members(chat_id, filter="bots")
+                # Get bots
+                bots = list(app.get_chat_members(
+                    chat_id,
+                    filter=enums.ChatMembersFilter.BOTS))
         """
         peer = await self.resolve_peer(chat_id)
 
@@ -101,40 +122,35 @@ async def get_chat_members(
             members = getattr(r.full_chat.participants, "participants", [])
             users = {i.id: i for i in r.users}
 
-            return types.List(types.ChatMember._parse(self, member, users, {}) for member in members)
-        elif isinstance(peer, raw.types.InputPeerChannel):
-            filter = filter.lower()
-
-            if filter == enums.ChatMembersFilter.ANY:
-                filter = raw.types.ChannelParticipantsSearch(q=query)
-            elif filter == enums.ChatMembersFilter.BANNED:
-                filter = raw.types.ChannelParticipantsKicked(q=query)
-            elif filter == enums.ChatMembersFilter.RESTRICTED:
-                filter = raw.types.ChannelParticipantsBanned(q=query)
-            elif filter == enums.ChatMembersFilter.BOTS:
-                filter = raw.types.ChannelParticipantsBots()
-            elif filter == enums.ChatMembersFilter.RECENT:
-                filter = raw.types.ChannelParticipantsRecent()
-            elif filter == enums.ChatMembersFilter.ADMINISTRATORS:
-                filter = raw.types.ChannelParticipantsAdmins()
-            else:
-                raise ValueError(f'Invalid filter "{filter}"')
+            for member in members:
+                yield types.ChatMember._parse(self, member, users, {})
 
-            r = await self.invoke(
-                raw.functions.channels.GetParticipants(
-                    channel=peer,
-                    filter=filter,
-                    offset=offset,
-                    limit=limit,
-                    hash=0
-                ),
-                sleep_threshold=60
+            return
+
+        current = 0
+        offset = 0
+        total = abs(limit) or (1 << 31) - 1
+        limit = min(200, total)
+
+        while True:
+            members = await get_chunk(
+                client=self,
+                chat_id=chat_id,
+                offset=offset,
+                filter=filter,
+                limit=limit,
+                query=query
             )
 
-            members = r.participants
-            users = {i.id: i for i in r.users}
-            chats = {i.id: i for i in r.chats}
+            if not members:
+                return
+
+            offset += len(members)
+
+            for member in members:
+                yield member
+
+                current += 1
 
-            return types.List(types.ChatMember._parse(self, member, users, chats) for member in members)
-        else:
-            raise ValueError(f'The chat_id "{chat_id}" belongs to a user')
+                if current >= total:
+                    return

From 68f151bad5b8e4b1ebb14a1c8ee39b27306d0722 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 154/539] Merge changes

---
 pyrogram/methods/bots/delete_bot_commands.py |  7 +++----
 pyrogram/methods/bots/get_bot_commands.py    | 11 +++++++----
 pyrogram/methods/bots/set_bot_commands.py    |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/pyrogram/methods/bots/delete_bot_commands.py b/pyrogram/methods/bots/delete_bot_commands.py
index edb82debed..98e6d3960f 100644
--- a/pyrogram/methods/bots/delete_bot_commands.py
+++ b/pyrogram/methods/bots/delete_bot_commands.py
@@ -18,15 +18,14 @@
 
 import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class DeleteBotCommands(Scaffold):
+class DeleteBotCommands:
     async def delete_bot_commands(
         self: "pyrogram.Client",
         scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
         language_code: str = "",
-    ):
+    ) -> bool:
         """Delete the list of the bot's commands for the given scope and user language.
         After deletion, higher level commands will be shown to affected users.
 
@@ -53,7 +52,7 @@ async def delete_bot_commands(
                 app.delete_bot_commands()
         """
 
-        return await self.send(
+        return await self.invoke(
             raw.functions.bots.ResetBotCommands(
                 scope=await scope.write(self),
                 lang_code=language_code,
diff --git a/pyrogram/methods/bots/get_bot_commands.py b/pyrogram/methods/bots/get_bot_commands.py
index c92bd21ea0..fe5be0f3bd 100644
--- a/pyrogram/methods/bots/get_bot_commands.py
+++ b/pyrogram/methods/bots/get_bot_commands.py
@@ -16,17 +16,18 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import List
+
 import pyrogram
 from pyrogram import raw, types
-from pyrogram.scaffold import Scaffold
 
 
-class GetBotCommands(Scaffold):
+class GetBotCommands:
     async def get_bot_commands(
         self: "pyrogram.Client",
         scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
         language_code: str = "",
-    ):
+    ) -> List["types.BotCommand"]:
         """Get the current list of the bot's commands for the given scope and user language.
         Returns Array of BotCommand on success. If commands aren't set, an empty list is returned.
 
@@ -54,9 +55,11 @@ async def get_bot_commands(
                 print(commands)
         """
 
-        return await self.send(
+        r = await self.invoke(
             raw.functions.bots.GetBotCommands(
                 scope=await scope.write(self),
                 lang_code=language_code,
             )
         )
+
+        return types.List(types.BotCommand.read(c) for c in r)
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index 6df1a2e443..b59c0fac78 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -29,7 +29,7 @@ async def set_bot_commands(
         commands: List["types.BotCommand"],
         scope: "types.BotCommandScope" = types.BotCommandScopeDefault(),
         language_code: str = "",
-    ):
+    ) -> bool:
         """Set the list of the bot's commands.
         The commands passed will overwrite any command set previously.
         This method can be used by the own bot only.

From 0e3c2e4412aba73f3fc06860344dc0e4dd95b7f3 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 155/539] Rename RPCError.x to RPCError.value

---
 pyrogram/errors/rpc_error.py                  | 22 +++++++++----------
 pyrogram/methods/auth/send_code.py            |  2 +-
 pyrogram/methods/auth/sign_in_bot.py          |  2 +-
 .../methods/bots/get_inline_bot_results.py    |  2 +-
 pyrogram/methods/messages/send_animation.py   |  2 +-
 pyrogram/methods/messages/send_audio.py       |  2 +-
 pyrogram/methods/messages/send_document.py    |  2 +-
 pyrogram/methods/messages/send_photo.py       |  2 +-
 pyrogram/methods/messages/send_sticker.py     |  2 +-
 pyrogram/methods/messages/send_video.py       |  2 +-
 pyrogram/methods/messages/send_video_note.py  |  2 +-
 pyrogram/methods/messages/send_voice.py       |  2 +-
 pyrogram/session/session.py                   |  2 +-
 13 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/pyrogram/errors/rpc_error.py b/pyrogram/errors/rpc_error.py
index 444447f2bb..63375f199e 100644
--- a/pyrogram/errors/rpc_error.py
+++ b/pyrogram/errors/rpc_error.py
@@ -30,11 +30,11 @@ class RPCError(Exception):
     ID = None
     CODE = None
     NAME = None
-    MESSAGE = "{x}"
+    MESSAGE = "{value}"
 
     def __init__(
         self,
-        x: Union[int, str, raw.types.RpcError] = None,
+        value: Union[int, str, raw.types.RpcError] = None,
         rpc_name: str = None,
         is_unknown: bool = False,
         is_signed: bool = False
@@ -43,18 +43,18 @@ def __init__(
             "-" if is_signed else "",
             self.CODE,
             self.ID or self.NAME,
-            self.MESSAGE.format(x=x),
+            self.MESSAGE.format(value=value),
             f'(caused by "{rpc_name}")' if rpc_name else ""
         ))
 
         try:
-            self.x = int(x)
+            self.value = int(value)
         except (ValueError, TypeError):
-            self.x = x
+            self.value = value
 
         if is_unknown:
             with open("unknown_errors.txt", "a", encoding="utf-8") as f:
-                f.write(f"{datetime.now()}\t{x}\t{rpc_name}\n")
+                f.write(f"{datetime.now()}\t{value}\t{rpc_name}\n")
 
     @staticmethod
     def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
@@ -68,7 +68,7 @@ def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
 
         if error_code not in exceptions:
             raise UnknownError(
-                x=f"[{error_code} {error_message}]",
+                value=f"[{error_code} {error_message}]",
                 rpc_name=rpc_name,
                 is_unknown=True,
                 is_signed=is_signed
@@ -80,18 +80,18 @@ def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
             raise getattr(
                 import_module("pyrogram.errors"),
                 exceptions[error_code]["_"]
-            )(x=f"[{error_code} {error_message}]",
+            )(value=f"[{error_code} {error_message}]",
               rpc_name=rpc_name,
               is_unknown=True,
               is_signed=is_signed)
 
-        x = re.search(r"_(\d+)", error_message)
-        x = x.group(1) if x is not None else x
+        value = re.search(r"_(\d+)", error_message)
+        value = value.group(1) if value is not None else value
 
         raise getattr(
             import_module("pyrogram.errors"),
             exceptions[error_code][error_id]
-        )(x=x,
+        )(value=value,
           rpc_name=rpc_name,
           is_unknown=False,
           is_signed=is_signed)
diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py
index 5a4f87ea31..5f7f70915d 100644
--- a/pyrogram/methods/auth/send_code.py
+++ b/pyrogram/methods/auth/send_code.py
@@ -60,7 +60,7 @@ async def send_code(
             except (PhoneMigrate, NetworkMigrate) as e:
                 await self.session.stop()
 
-                await self.storage.dc_id(e.x)
+                await self.storage.dc_id(e.value)
                 await self.storage.auth_key(
                     await Auth(
                         self, await self.storage.dc_id(),
diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py
index 5f2e68b510..dd322a8e66 100644
--- a/pyrogram/methods/auth/sign_in_bot.py
+++ b/pyrogram/methods/auth/sign_in_bot.py
@@ -57,7 +57,7 @@ async def sign_in_bot(
             except UserMigrate as e:
                 await self.session.stop()
 
-                await self.storage.dc_id(e.x)
+                await self.storage.dc_id(e.value)
                 await self.storage.auth_key(
                     await Auth(
                         self, await self.storage.dc_id(),
diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py
index a71fbad8ec..f145cc8c44 100644
--- a/pyrogram/methods/bots/get_inline_bot_results.py
+++ b/pyrogram/methods/bots/get_inline_bot_results.py
@@ -84,7 +84,7 @@ async def get_inline_bot_results(
             )
         except UnknownError as e:
             # TODO: Add this -503 Timeout error into the Error DB
-            if e.x.error_code == -503 and e.x.error_message == "Timeout":
+            if e.value.error_code == -503 and e.value.error_message == "Timeout":
                 raise TimeoutError("The inline bot didn't answer in time") from None
             else:
                 raise e
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index 9403b1e49c..e45a071462 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -230,7 +230,7 @@ def progress(current, total):
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(animation, file_id=file.id, file_part=e.x)
+                    await self.save_file(animation, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index e0a98f85d5..8c2624a8d8 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -224,7 +224,7 @@ def progress(current, total):
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(audio, file_id=file.id, file_part=e.x)
+                    await self.save_file(audio, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index 5b480cb3ea..c1179cb0e2 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -202,7 +202,7 @@ def progress(current, total):
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(document, file_id=file.id, file_part=e.x)
+                    await self.save_file(document, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index e536d3a000..5391b2f660 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -179,7 +179,7 @@ async def send_photo(
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(photo, file_id=file.id, file_part=e.x)
+                    await self.save_file(photo, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index ca6f47a593..d0b66fb10b 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -161,7 +161,7 @@ async def send_sticker(
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(sticker, file_id=file.id, file_part=e.x)
+                    await self.save_file(sticker, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index e1c245b1ad..49674076bc 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -236,7 +236,7 @@ def progress(current, total):
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(video, file_id=file.id, file_part=e.x)
+                    await self.save_file(video, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index 7412e0eaf6..ce6240d9d5 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -185,7 +185,7 @@ async def send_video_note(
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(video_note, file_id=file.id, file_part=e.x)
+                    await self.save_file(video_note, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 08e1bdc0f1..9bc6456519 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -186,7 +186,7 @@ async def send_voice(
                         )
                     )
                 except FilePartMissing as e:
-                    await self.save_file(voice, file_id=file.id, file_part=e.x)
+                    await self.save_file(voice, file_id=file.id, file_part=e.value)
                 else:
                     for i in r.updates:
                         if isinstance(i, (raw.types.UpdateNewMessage,
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index 3b0edca292..b50bb6d79e 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -359,7 +359,7 @@ async def invoke(
             try:
                 return await self.send(query, timeout=timeout)
             except FloodWait as e:
-                amount = e.x
+                amount = e.value
 
                 if amount > sleep_threshold >= 0:
                     raise

From ecc90caba2749e6f558de3c1badb0209f291f91f Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 156/539] Handle edited messages using a separate handler

---
 docs/source/api/decorators.rst                |   2 +
 docs/source/api/handlers.rst                  |   2 +
 pyrogram/dispatcher.py                        | 110 ++++++++++--------
 pyrogram/filters.py                           |  10 --
 pyrogram/handlers/__init__.py                 |   1 +
 pyrogram/handlers/edited_message_handler.py   |  49 ++++++++
 pyrogram/handlers/message_handler.py          |   4 +-
 pyrogram/methods/decorators/__init__.py       |   2 +
 .../methods/decorators/on_edited_message.py   |  61 ++++++++++
 pyrogram/methods/decorators/on_message.py     |   2 +-
 10 files changed, 184 insertions(+), 59 deletions(-)
 create mode 100644 pyrogram/handlers/edited_message_handler.py
 create mode 100644 pyrogram/methods/decorators/on_edited_message.py

diff --git a/docs/source/api/decorators.rst b/docs/source/api/decorators.rst
index 130f15ceb6..2e7a04f263 100644
--- a/docs/source/api/decorators.rst
+++ b/docs/source/api/decorators.rst
@@ -36,6 +36,7 @@ Index
     :columns: 3
 
     - :meth:`~Client.on_message`
+    - :meth:`~Client.on_edited_message`
     - :meth:`~Client.on_callback_query`
     - :meth:`~Client.on_inline_query`
     - :meth:`~Client.on_chosen_inline_result`
@@ -54,6 +55,7 @@ Details
 
 .. Decorators
 .. autodecorator:: pyrogram.Client.on_message()
+.. autodecorator:: pyrogram.Client.on_edited_message()
 .. autodecorator:: pyrogram.Client.on_callback_query()
 .. autodecorator:: pyrogram.Client.on_inline_query()
 .. autodecorator:: pyrogram.Client.on_chosen_inline_result()
diff --git a/docs/source/api/handlers.rst b/docs/source/api/handlers.rst
index 9694142932..8a8ac71477 100644
--- a/docs/source/api/handlers.rst
+++ b/docs/source/api/handlers.rst
@@ -36,6 +36,7 @@ Index
     :columns: 3
 
     - :class:`MessageHandler`
+    - :class:`EditedMessageHandler`
     - :class:`DeletedMessagesHandler`
     - :class:`CallbackQueryHandler`
     - :class:`InlineQueryHandler`
@@ -53,6 +54,7 @@ Details
 
 .. Handlers
 .. autoclass:: MessageHandler()
+.. autoclass:: EditedMessageHandler()
 .. autoclass:: DeletedMessagesHandler()
 .. autoclass:: CallbackQueryHandler()
 .. autoclass:: InlineQueryHandler()
diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py
index 0c425f4de3..b0ad87f71a 100644
--- a/pyrogram/dispatcher.py
+++ b/pyrogram/dispatcher.py
@@ -24,7 +24,7 @@
 import pyrogram
 from pyrogram import utils
 from pyrogram.handlers import (
-    CallbackQueryHandler, MessageHandler, DeletedMessagesHandler,
+    CallbackQueryHandler, MessageHandler, EditedMessageHandler, DeletedMessagesHandler,
     UserStatusHandler, RawUpdateHandler, InlineQueryHandler, PollHandler,
     ChosenInlineResultHandler, ChatMemberUpdatedHandler, ChatJoinRequestHandler
 )
@@ -42,33 +42,16 @@
 
 
 class Dispatcher:
-    NEW_MESSAGE_UPDATES = (
-        UpdateNewMessage,
-        UpdateNewChannelMessage,
-        UpdateNewScheduledMessage
-    )
-
-    EDIT_MESSAGE_UPDATES = (
-        UpdateEditMessage,
-        UpdateEditChannelMessage,
-    )
-
-    DELETE_MESSAGES_UPDATES = (
-        UpdateDeleteMessages,
-        UpdateDeleteChannelMessages
-    )
-
-    CALLBACK_QUERY_UPDATES = (
-        UpdateBotCallbackQuery,
-        UpdateInlineBotCallbackQuery
-    )
-
-    CHAT_MEMBER_UPDATES = (
-        UpdateChatParticipant,
-        UpdateChannelParticipant
-    )
-
-    MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES
+    NEW_MESSAGE_UPDATES = (UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage)
+    EDIT_MESSAGE_UPDATES = (UpdateEditMessage, UpdateEditChannelMessage)
+    DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages)
+    CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery)
+    CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant)
+    USER_STATUS_UPDATES = (UpdateUserStatus,)
+    BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery,)
+    POLL_UPDATES = (UpdateMessagePoll,)
+    CHOSEN_INLINE_RESULT_UPDATES = (UpdateBotInlineSend,)
+    CHAT_JOIN_REQUEST_UPDATES = (UpdateBotChatInviteRequester,)
 
     def __init__(self, client: "pyrogram.Client"):
         self.client = client
@@ -81,45 +64,80 @@ def __init__(self, client: "pyrogram.Client"):
         self.groups = OrderedDict()
 
         async def message_parser(update, users, chats):
-            return await pyrogram.types.Message._parse(
-                self.client, update.message, users, chats,
-                isinstance(update, UpdateNewScheduledMessage)
-            ), MessageHandler
+            return (
+                await pyrogram.types.Message._parse(self.client, update.message, users, chats,
+                                                    isinstance(update, UpdateNewScheduledMessage)),
+                MessageHandler
+            )
+
+        async def edited_message_parser(update, users, chats):
+            # Edited messages are parsed the same way as new messages, but the handler is different
+            parsed, _ = await message_parser(update, users, chats)
+
+            return (
+                parsed,
+                EditedMessageHandler
+            )
 
         async def deleted_messages_parser(update, users, chats):
-            return utils.parse_deleted_messages(self.client, update), DeletedMessagesHandler
+            return (
+                utils.parse_deleted_messages(self.client, update),
+                DeletedMessagesHandler
+            )
 
         async def callback_query_parser(update, users, chats):
-            return await pyrogram.types.CallbackQuery._parse(self.client, update, users), CallbackQueryHandler
+            return (
+                await pyrogram.types.CallbackQuery._parse(self.client, update, users),
+                CallbackQueryHandler
+            )
 
         async def user_status_parser(update, users, chats):
-            return pyrogram.types.User._parse_user_status(self.client, update), UserStatusHandler
+            return (
+                pyrogram.types.User._parse_user_status(self.client, update),
+                UserStatusHandler
+            )
 
         async def inline_query_parser(update, users, chats):
-            return pyrogram.types.InlineQuery._parse(self.client, update, users), InlineQueryHandler
+            return (
+                pyrogram.types.InlineQuery._parse(self.client, update, users),
+                InlineQueryHandler
+            )
 
         async def poll_parser(update, users, chats):
-            return pyrogram.types.Poll._parse_update(self.client, update), PollHandler
+            return (
+                pyrogram.types.Poll._parse_update(self.client, update),
+                PollHandler
+            )
 
         async def chosen_inline_result_parser(update, users, chats):
-            return pyrogram.types.ChosenInlineResult._parse(self.client, update, users), ChosenInlineResultHandler
+            return (
+                pyrogram.types.ChosenInlineResult._parse(self.client, update, users),
+                ChosenInlineResultHandler
+            )
 
         async def chat_member_updated_parser(update, users, chats):
-            return pyrogram.types.ChatMemberUpdated._parse(self.client, update, users, chats), ChatMemberUpdatedHandler
+            return (
+                pyrogram.types.ChatMemberUpdated._parse(self.client, update, users, chats),
+                ChatMemberUpdatedHandler
+            )
 
         async def chat_join_request_parser(update, users, chats):
-            return pyrogram.types.ChatJoinRequest._parse(self.client, update, users, chats), ChatJoinRequestHandler
+            return (
+                pyrogram.types.ChatJoinRequest._parse(self.client, update, users, chats),
+                ChatJoinRequestHandler
+            )
 
         self.update_parsers = {
-            Dispatcher.MESSAGE_UPDATES: message_parser,
+            Dispatcher.NEW_MESSAGE_UPDATES: message_parser,
+            Dispatcher.EDIT_MESSAGE_UPDATES: edited_message_parser,
             Dispatcher.DELETE_MESSAGES_UPDATES: deleted_messages_parser,
             Dispatcher.CALLBACK_QUERY_UPDATES: callback_query_parser,
-            (UpdateUserStatus,): user_status_parser,
-            (UpdateBotInlineQuery,): inline_query_parser,
-            (UpdateMessagePoll,): poll_parser,
-            (UpdateBotInlineSend,): chosen_inline_result_parser,
+            Dispatcher.USER_STATUS_UPDATES: user_status_parser,
+            Dispatcher.BOT_INLINE_QUERY_UPDATES: inline_query_parser,
+            Dispatcher.POLL_UPDATES: poll_parser,
+            Dispatcher.CHOSEN_INLINE_RESULT_UPDATES: chosen_inline_result_parser,
             Dispatcher.CHAT_MEMBER_UPDATES: chat_member_updated_parser,
-            (UpdateBotChatInviteRequester,): chat_join_request_parser
+            Dispatcher.CHAT_JOIN_REQUEST_UPDATES: chat_join_request_parser
         }
 
         self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}
diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index 348e6e7a72..078ed4fa7e 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -250,16 +250,6 @@ async def caption_filter(_, __, m: Message):
 
 # endregion
 
-# region edited_filter
-async def edited_filter(_, __, m: Message):
-    return bool(m.edit_date)
-
-
-edited = create(edited_filter)
-"""Filter edited messages."""
-
-
-# endregion
 
 # region audio_filter
 async def audio_filter(_, __, m: Message):
diff --git a/pyrogram/handlers/__init__.py b/pyrogram/handlers/__init__.py
index 2b7ef0a201..1c762958a0 100644
--- a/pyrogram/handlers/__init__.py
+++ b/pyrogram/handlers/__init__.py
@@ -22,6 +22,7 @@
 from .chosen_inline_result_handler import ChosenInlineResultHandler
 from .deleted_messages_handler import DeletedMessagesHandler
 from .disconnect_handler import DisconnectHandler
+from .edited_message_handler import EditedMessageHandler
 from .inline_query_handler import InlineQueryHandler
 from .message_handler import MessageHandler
 from .poll_handler import PollHandler
diff --git a/pyrogram/handlers/edited_message_handler.py b/pyrogram/handlers/edited_message_handler.py
new file mode 100644
index 0000000000..78deaf0fa9
--- /dev/null
+++ b/pyrogram/handlers/edited_message_handler.py
@@ -0,0 +1,49 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Callable
+
+from .handler import Handler
+
+
+class EditedMessageHandler(Handler):
+    """The EditedMessage handler class. Used to handle edited messages.
+     It is intended to be used with :meth:`~pyrogram.Client.add_handler`
+
+    For a nicer way to register this handler, have a look at the
+    :meth:`~pyrogram.Client.on_edited_message` decorator.
+
+    Parameters:
+        callback (``Callable``):
+            Pass a function that will be called when a new edited message arrives. It takes *(client, message)*
+            as positional arguments (look at the section below for a detailed description).
+
+        filters (:obj:`Filters`):
+            Pass one or more filters to allow only a subset of messages to be passed
+            in your callback function.
+
+    Other parameters:
+        client (:obj:`~pyrogram.Client`):
+            The Client itself, useful when you want to call other API methods inside the message handler.
+
+        edited_message (:obj:`~pyrogram.types.Message`):
+            The received edited message.
+    """
+
+    def __init__(self, callback: Callable, filters=None):
+        super().__init__(callback, filters)
diff --git a/pyrogram/handlers/message_handler.py b/pyrogram/handlers/message_handler.py
index 63a334fc0d..f5a35b5531 100644
--- a/pyrogram/handlers/message_handler.py
+++ b/pyrogram/handlers/message_handler.py
@@ -22,8 +22,8 @@
 
 
 class MessageHandler(Handler):
-    """The Message handler class. Used to handle text, media and service messages coming from
-    any chat (private, group, channel). It is intended to be used with :meth:`~pyrogram.Client.add_handler`
+    """The Message handler class. Used to handle new messages.
+    It is intended to be used with :meth:`~pyrogram.Client.add_handler`
 
     For a nicer way to register this handler, have a look at the
     :meth:`~pyrogram.Client.on_message` decorator.
diff --git a/pyrogram/methods/decorators/__init__.py b/pyrogram/methods/decorators/__init__.py
index da0ed9ab13..1fc61185c9 100644
--- a/pyrogram/methods/decorators/__init__.py
+++ b/pyrogram/methods/decorators/__init__.py
@@ -22,6 +22,7 @@
 from .on_chosen_inline_result import OnChosenInlineResult
 from .on_deleted_messages import OnDeletedMessages
 from .on_disconnect import OnDisconnect
+from .on_edited_message import OnEditedMessage
 from .on_inline_query import OnInlineQuery
 from .on_message import OnMessage
 from .on_poll import OnPoll
@@ -31,6 +32,7 @@
 
 class Decorators(
     OnMessage,
+    OnEditedMessage,
     OnDeletedMessages,
     OnCallbackQuery,
     OnRawUpdate,
diff --git a/pyrogram/methods/decorators/on_edited_message.py b/pyrogram/methods/decorators/on_edited_message.py
new file mode 100644
index 0000000000..02ebdec3b8
--- /dev/null
+++ b/pyrogram/methods/decorators/on_edited_message.py
@@ -0,0 +1,61 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Callable
+
+import pyrogram
+from pyrogram.filters import Filter
+
+
+class OnEditedMessage:
+    def on_edited_message(
+        self=None,
+        filters=None,
+        group: int = 0
+    ) -> Callable:
+        """Decorator for handling edited messages.
+
+        This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
+        :obj:`~pyrogram.handlers.EditedMessageHandler`.
+
+        Parameters:
+            filters (:obj:`~pyrogram.filters`, *optional*):
+                Pass one or more filters to allow only a subset of messages to be passed
+                in your function.
+
+            group (``int``, *optional*):
+                The group identifier, defaults to 0.
+        """
+
+        def decorator(func: Callable) -> Callable:
+            if isinstance(self, pyrogram.Client):
+                self.add_handler(pyrogram.handlers.EditedMessageHandler(func, filters), group)
+            elif isinstance(self, Filter) or self is None:
+                if not hasattr(func, "handlers"):
+                    func.handlers = []
+
+                func.handlers.append(
+                    (
+                        pyrogram.handlers.MessageHandler(func, self),
+                        group if filters is None else filters
+                    )
+                )
+
+            return func
+
+        return decorator
diff --git a/pyrogram/methods/decorators/on_message.py b/pyrogram/methods/decorators/on_message.py
index e9a3dfdd85..220c12bbcc 100644
--- a/pyrogram/methods/decorators/on_message.py
+++ b/pyrogram/methods/decorators/on_message.py
@@ -28,7 +28,7 @@ def on_message(
         filters=None,
         group: int = 0
     ) -> Callable:
-        """Decorator for handling messages.
+        """Decorator for handling new messages.
 
         This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
         :obj:`~pyrogram.handlers.MessageHandler`.

From b47591e6d232a1c8d3b8dcfb3174dc3aa06ccd81 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 157/539] Turn examples asynchronous

---
 compiler/docs/compiler.py                     |   1 -
 docs/Makefile                                 |   4 +-
 docs/source/start/errors.rst                  |   4 +-
 docs/source/start/examples/bot_keyboards.rst  |  88 ++++---
 .../start/examples/callback_queries.rst       |   6 +-
 .../examples/{echobot.rst => echo_bot.rst}    |   8 +-
 .../start/examples/get_chat_history.rst       |  20 ++
 .../start/examples/get_chat_members.rst       |  15 +-
 docs/source/start/examples/get_dialogs.rst    |  11 +-
 docs/source/start/examples/get_history.rst    |  15 --
 docs/source/start/examples/hello_world.rst    |  11 +-
 docs/source/start/examples/index.rst          |  12 +-
 docs/source/start/examples/inline_queries.rst |   4 +-
 docs/source/start/examples/raw_updates.rst    |   2 +-
 .../source/start/examples/use_inline_bots.rst |  17 +-
 .../{welcomebot.rst => welcome_bot.rst}       |  17 +-
 docs/source/start/invoking.rst                |  30 +--
 docs/source/start/updates.rst                 |  38 +--
 pyrogram/__init__.py                          |   7 -
 pyrogram/client.py                            |  33 ++-
 .../methods/bots/answer_callback_query.py     |   6 +-
 pyrogram/methods/bots/answer_inline_query.py  |   2 +-
 pyrogram/methods/bots/delete_bot_commands.py  |   2 +-
 pyrogram/methods/bots/get_bot_commands.py     |   2 +-
 pyrogram/methods/bots/get_game_high_scores.py |   2 +-
 .../methods/bots/get_inline_bot_results.py    |   2 +-
 .../methods/bots/request_callback_answer.py   |   2 +-
 pyrogram/methods/bots/send_game.py            |   2 +-
 .../methods/bots/send_inline_bot_result.py    |   2 +-
 pyrogram/methods/bots/set_bot_commands.py     |   2 +-
 pyrogram/methods/bots/set_game_score.py       |   4 +-
 pyrogram/methods/chats/__init__.py            |   2 -
 pyrogram/methods/chats/add_chat_members.py    |   6 +-
 pyrogram/methods/chats/archive_chats.py       |   4 +-
 pyrogram/methods/chats/ban_chat_member.py     |   4 +-
 pyrogram/methods/chats/create_channel.py      |   2 +-
 pyrogram/methods/chats/create_group.py        |   2 +-
 pyrogram/methods/chats/create_supergroup.py   |   2 +-
 pyrogram/methods/chats/delete_channel.py      |   2 +-
 pyrogram/methods/chats/delete_chat_photo.py   |   2 +-
 pyrogram/methods/chats/delete_supergroup.py   |   2 +-
 pyrogram/methods/chats/get_chat.py            |   2 +-
 pyrogram/methods/chats/get_chat_event_log.py  |   6 +
 pyrogram/methods/chats/get_chat_member.py     |   2 +-
 pyrogram/methods/chats/get_chat_members.py    |   6 +-
 .../methods/chats/get_chat_members_count.py   |   2 +-
 .../methods/chats/get_chat_online_count.py    |   2 +-
 pyrogram/methods/chats/get_dialogs.py         |   4 +-
 pyrogram/methods/chats/get_dialogs_count.py   |   2 +-
 pyrogram/methods/chats/get_nearby_chats.py    |   2 +-
 pyrogram/methods/chats/get_send_as_chats.py   |   2 +-
 pyrogram/methods/chats/iter_chat_members.py   | 127 ----------
 pyrogram/methods/chats/iter_dialogs.py        |   2 +-
 pyrogram/methods/chats/join_chat.py           |  10 +-
 pyrogram/methods/chats/leave_chat.py          |   4 +-
 pyrogram/methods/chats/pin_chat_message.py    |   4 +-
 pyrogram/methods/chats/promote_chat_member.py |   8 +-
 .../methods/chats/restrict_chat_member.py     |   9 +-
 .../methods/chats/set_administrator_title.py  |   2 +-
 .../methods/chats/set_chat_description.py     |   2 +-
 .../methods/chats/set_chat_permissions.py     |   4 +-
 pyrogram/methods/chats/set_chat_photo.py      |   8 +-
 pyrogram/methods/chats/set_chat_title.py      |   2 +-
 pyrogram/methods/chats/set_chat_username.py   |   2 +-
 pyrogram/methods/chats/set_send_as_chat.py    |   2 +-
 pyrogram/methods/chats/set_slow_mode.py       |   4 +-
 pyrogram/methods/chats/unarchive_chats.py     |   4 +-
 pyrogram/methods/chats/unban_chat_member.py   |   2 +-
 .../methods/chats/unpin_all_chat_messages.py  |   2 +-
 pyrogram/methods/chats/unpin_chat_message.py  |   2 +-
 pyrogram/methods/contacts/add_contact.py      |   7 +-
 pyrogram/methods/contacts/delete_contacts.py  |   4 +-
 pyrogram/methods/contacts/get_contacts.py     |   2 +-
 .../methods/contacts/get_contacts_count.py    |   2 +-
 pyrogram/methods/contacts/import_contacts.py  |   2 +-
 .../invite_links/create_chat_invite_link.py   |   6 +-
 .../invite_links/edit_chat_invite_link.py     |   4 +-
 .../invite_links/export_chat_invite_link.py   |   2 +-
 pyrogram/methods/messages/copy_media_group.py |   9 +-
 pyrogram/methods/messages/copy_message.py     |   2 +-
 pyrogram/methods/messages/delete_messages.py  |   6 +-
 pyrogram/methods/messages/download_media.py   |   8 +-
 .../methods/messages/edit_inline_caption.py   |   2 +-
 .../methods/messages/edit_inline_media.py     |   6 +-
 .../messages/edit_inline_reply_markup.py      |   2 +-
 pyrogram/methods/messages/edit_inline_text.py |   4 +-
 .../methods/messages/edit_message_caption.py  |   2 +-
 .../methods/messages/edit_message_media.py    |   9 +-
 .../messages/edit_message_reply_markup.py     |   2 +-
 .../methods/messages/edit_message_text.py     |   4 +-
 pyrogram/methods/messages/forward_messages.py |   4 +-
 pyrogram/methods/messages/get_chat_history.py |   2 +-
 .../messages/get_chat_history_count.py        |   2 +-
 .../messages/get_discussion_message.py        |   4 +-
 .../messages/get_discussion_replies.py        |   4 +-
 .../messages/get_discussion_replies_count.py  |   2 +-
 pyrogram/methods/messages/get_messages.py     |  10 +-
 .../methods/messages/read_chat_history.py     |   4 +-
 pyrogram/methods/messages/retract_vote.py     |   2 +-
 pyrogram/methods/messages/search_global.py    |   6 +-
 pyrogram/methods/messages/search_messages.py  |   6 +-
 pyrogram/methods/messages/send_animation.py   |  10 +-
 pyrogram/methods/messages/send_audio.py       |  10 +-
 .../methods/messages/send_cached_media.py     |   2 +-
 pyrogram/methods/messages/send_chat_action.py |  12 +-
 pyrogram/methods/messages/send_contact.py     |   2 +-
 pyrogram/methods/messages/send_dice.py        |   6 +-
 pyrogram/methods/messages/send_document.py    |   8 +-
 pyrogram/methods/messages/send_location.py    |   2 +-
 pyrogram/methods/messages/send_media_group.py |   2 +-
 pyrogram/methods/messages/send_message.py     |  16 +-
 pyrogram/methods/messages/send_photo.py       |   8 +-
 pyrogram/methods/messages/send_poll.py        |   2 +-
 pyrogram/methods/messages/send_reaction.py    |   4 +-
 pyrogram/methods/messages/send_sticker.py     |   4 +-
 pyrogram/methods/messages/send_venue.py       |   4 +-
 pyrogram/methods/messages/send_video.py       |  10 +-
 pyrogram/methods/messages/send_video_note.py  |   4 +-
 pyrogram/methods/messages/send_voice.py       |   6 +-
 pyrogram/methods/messages/stop_poll.py        |   2 +-
 pyrogram/methods/messages/vote_poll.py        |   2 +-
 .../methods/password/change_cloud_password.py |   4 +-
 .../methods/password/enable_cloud_password.py |   6 +-
 .../methods/password/remove_cloud_password.py |   2 +-
 pyrogram/methods/users/block_user.py          |   2 +-
 .../methods/users/delete_profile_photos.py    |   6 +-
 pyrogram/methods/users/get_common_chats.py    |   2 +-
 pyrogram/methods/users/get_me.py              |   2 +-
 pyrogram/methods/users/get_profile_photos.py  |   6 +-
 .../methods/users/get_profile_photos_count.py |   2 +-
 pyrogram/methods/users/get_users.py           |   4 +-
 pyrogram/methods/users/iter_profile_photos.py |   4 +-
 pyrogram/methods/users/set_profile_photo.py   |   4 +-
 pyrogram/methods/users/set_username.py        |   2 +-
 pyrogram/methods/users/unblock_user.py        |   2 +-
 pyrogram/methods/users/update_profile.py      |   6 +-
 pyrogram/methods/utilities/add_handler.py     |   4 +-
 .../utilities/export_session_string.py        |   7 +-
 pyrogram/methods/utilities/idle.py            |  32 +--
 pyrogram/methods/utilities/remove_handler.py  |   4 +-
 pyrogram/methods/utilities/restart.py         |  14 +-
 pyrogram/methods/utilities/run.py             |  29 ++-
 pyrogram/methods/utilities/start.py           |  12 +-
 pyrogram/methods/utilities/stop.py            |  10 +-
 .../methods/utilities/stop_transmission.py    |  16 +-
 .../bots_and_keyboards/callback_query.py      |   4 +-
 pyrogram/types/inline_mode/inline_query.py    |   4 +-
 pyrogram/types/messages_and_media/message.py  | 157 ++++++------
 pyrogram/types/user_and_chats/chat.py         | 234 ++++--------------
 .../types/user_and_chats/chat_join_request.py |   8 +-
 pyrogram/types/user_and_chats/user.py         |  12 +-
 151 files changed, 619 insertions(+), 858 deletions(-)
 rename docs/source/start/examples/{echobot.rst => echo_bot.rst} (82%)
 create mode 100644 docs/source/start/examples/get_chat_history.rst
 delete mode 100644 docs/source/start/examples/get_history.rst
 rename docs/source/start/examples/{welcomebot.rst => welcome_bot.rst} (73%)
 delete mode 100644 pyrogram/methods/chats/iter_chat_members.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 8c75d711d3..91bbad3810 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -534,7 +534,6 @@ def get_title_list(s: str) -> list:
             Chat.promote_member
             Chat.get_member
             Chat.get_members
-            Chat.iter_members
             Chat.add_members
             Chat.join
             Chat.leave
diff --git a/docs/Makefile b/docs/Makefile
index ceb7494c14..8eacc12a4d 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -20,4 +20,6 @@ help:
 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
 
 lhtml: # live html
-	sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2) -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
+	sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2) \
+	    --watch ../pyrogram \
+	    -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
diff --git a/docs/source/start/errors.rst b/docs/source/start/errors.rst
index 5f59deef6c..0188107413 100644
--- a/docs/source/start/errors.rst
+++ b/docs/source/start/errors.rst
@@ -89,7 +89,7 @@ Errors with Values
 
 Exception objects may also contain some informative values. For example, ``FloodWait`` holds the amount of seconds you
 have to wait before you can try again, some other errors contain the DC number on which the request must be repeated on.
-The value is stored in the ``x`` attribute of the exception object:
+The value is stored in the ``value`` attribute of the exception object:
 
 .. code-block:: python
 
@@ -100,5 +100,5 @@ The value is stored in the ``x`` attribute of the exception object:
         try:
             ...  # Your code
         except FloodWait as e:
-            await asyncio.sleep(e.x)  # Wait "x" seconds before continuing
+            await asyncio.sleep(e.value)  # Wait N seconds before continuing
     ...
\ No newline at end of file
diff --git a/docs/source/start/examples/bot_keyboards.rst b/docs/source/start/examples/bot_keyboards.rst
index a3a549f4df..b774a80e7e 100644
--- a/docs/source/start/examples/bot_keyboards.rst
+++ b/docs/source/start/examples/bot_keyboards.rst
@@ -12,51 +12,57 @@ like send_audio(), send_document(), send_location(), etc...
 .. code-block:: python
 
     from pyrogram import Client
-    from pyrogram.types import ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
+    from pyrogram.types import (ReplyKeyboardMarkup, InlineKeyboardMarkup,
+                                InlineKeyboardButton)
 
     # Create a client using your bot token
     app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
 
-    with app:
-        app.send_message(
-            "me",  # Edit this
-            "This is a ReplyKeyboardMarkup example",
-            reply_markup=ReplyKeyboardMarkup(
-                [
-                    ["A", "B", "C", "D"],  # First row
-                    ["E", "F", "G"],  # Second row
-                    ["H", "I"],  # Third row
-                    ["J"]  # Fourth row
-                ],
-                resize_keyboard=True  # Make the keyboard smaller
-            )
-        )
-
-        app.send_message(
-            "me",  # Edit this
-            "This is a InlineKeyboardMarkup example",
-            reply_markup=InlineKeyboardMarkup(
-                [
-                    [  # First row
-                        InlineKeyboardButton(  # Generates a callback query when pressed
-                            "Button",
-                            callback_data="data"
-                        ),
-                        InlineKeyboardButton(  # Opens a web URL
-                            "URL",
-                            url="https://docs.pyrogram.org"
-                        ),
+
+    async def main():
+        async with app:
+            await app.send_message(
+                "me",  # Edit this
+                "This is a ReplyKeyboardMarkup example",
+                reply_markup=ReplyKeyboardMarkup(
+                    [
+                        ["A", "B", "C", "D"],  # First row
+                        ["E", "F", "G"],  # Second row
+                        ["H", "I"],  # Third row
+                        ["J"]  # Fourth row
                     ],
-                    [  # Second row
-                        InlineKeyboardButton(  # Opens the inline interface
-                            "Choose chat",
-                            switch_inline_query="pyrogram"
-                        ),
-                        InlineKeyboardButton(  # Opens the inline interface in the current chat
-                            "Inline here",
-                            switch_inline_query_current_chat="pyrogram"
-                        )
+                    resize_keyboard=True  # Make the keyboard smaller
+                )
+            )
+
+            await app.send_message(
+                "me",  # Edit this
+                "This is a InlineKeyboardMarkup example",
+                reply_markup=InlineKeyboardMarkup(
+                    [
+                        [  # First row
+                            InlineKeyboardButton(  # Generates a callback query when pressed
+                                "Button",
+                                callback_data="data"
+                            ),
+                            InlineKeyboardButton(  # Opens a web URL
+                                "URL",
+                                url="https://docs.pyrogram.org"
+                            ),
+                        ],
+                        [  # Second row
+                            InlineKeyboardButton(  # Opens the inline interface
+                                "Choose chat",
+                                switch_inline_query="pyrogram"
+                            ),
+                            InlineKeyboardButton(  # Opens the inline interface in the current chat
+                                "Inline here",
+                                switch_inline_query_current_chat="pyrogram"
+                            )
+                        ]
                     ]
-                ]
+                )
             )
-        )
+
+
+    app.run(main())
\ No newline at end of file
diff --git a/docs/source/start/examples/callback_queries.rst b/docs/source/start/examples/callback_queries.rst
index 73273058a1..64da57b39a 100644
--- a/docs/source/start/examples/callback_queries.rst
+++ b/docs/source/start/examples/callback_queries.rst
@@ -12,8 +12,10 @@ It uses the @on_callback_query decorator to register a CallbackQueryHandler.
 
 
     @app.on_callback_query()
-    def answer(client, callback_query):
-        callback_query.answer(f"Button contains: '{callback_query.data}'", show_alert=True)
+    async def answer(client, callback_query):
+        await callback_query.answer(
+            f"Button contains: '{callback_query.data}'",
+            show_alert=True)
 
 
     app.run()  # Automatically start() and idle()
\ No newline at end of file
diff --git a/docs/source/start/examples/echobot.rst b/docs/source/start/examples/echo_bot.rst
similarity index 82%
rename from docs/source/start/examples/echobot.rst
rename to docs/source/start/examples/echo_bot.rst
index 2ff578e97d..de8288b5e4 100644
--- a/docs/source/start/examples/echobot.rst
+++ b/docs/source/start/examples/echo_bot.rst
@@ -1,5 +1,5 @@
-echobot
-=======
+echo_bot
+========
 
 This simple echo bot replies to every private text message.
 
@@ -14,8 +14,8 @@ It uses the ``@on_message`` decorator to register a ``MessageHandler`` and appli
 
 
     @app.on_message(filters.text & filters.private)
-    def echo(client, message):
-        message.reply(message.text)
+    async def echo(client, message):
+        await message.reply(message.text)
 
 
     app.run()  # Automatically start() and idle()
\ No newline at end of file
diff --git a/docs/source/start/examples/get_chat_history.rst b/docs/source/start/examples/get_chat_history.rst
new file mode 100644
index 0000000000..59939948b3
--- /dev/null
+++ b/docs/source/start/examples/get_chat_history.rst
@@ -0,0 +1,20 @@
+get_history
+===========
+
+This example shows how to get the full message history of a chat, starting from the latest message.
+
+.. code-block:: python
+
+    from pyrogram import Client
+
+    app = Client("my_account")
+
+
+    async def main():
+        async with app:
+            # "me" refers to your own chat (Saved Messages)
+            async for message in app.get_chat_history("me"):
+                print(message)
+
+
+    app.run(main())
\ No newline at end of file
diff --git a/docs/source/start/examples/get_chat_members.rst b/docs/source/start/examples/get_chat_members.rst
index 8d47797604..26636ca344 100644
--- a/docs/source/start/examples/get_chat_members.rst
+++ b/docs/source/start/examples/get_chat_members.rst
@@ -7,9 +7,16 @@ This example shows how to get all the members of a chat.
 
     from pyrogram import Client
 
+    # Target channel/supergroup
+    TARGET = -100123456789
+
     app = Client("my_account")
-    target = "pyrogramchat"  # Target channel/supergroup
 
-    with app:
-        for member in app.iter_chat_members(target):
-            print(member.user.first_name)
\ No newline at end of file
+
+    async def main():
+        async with app:
+            async for member in app.get_chat_members(TARGET):
+                print(member)
+
+
+    app.run(main())
\ No newline at end of file
diff --git a/docs/source/start/examples/get_dialogs.rst b/docs/source/start/examples/get_dialogs.rst
index b1a4806427..e5b1060966 100644
--- a/docs/source/start/examples/get_dialogs.rst
+++ b/docs/source/start/examples/get_dialogs.rst
@@ -9,6 +9,11 @@ This example shows how to get the full dialogs list (as user).
 
     app = Client("my_account")
 
-    with app:
-        for dialog in app.iter_dialogs():
-            print(dialog.chat.title or dialog.chat.first_name)
\ No newline at end of file
+
+    async def main():
+        async with app:
+            async for dialog in app.get_dialogs():
+                print(dialog.chat.title or dialog.chat.first_name)
+
+
+    app.run(main())
\ No newline at end of file
diff --git a/docs/source/start/examples/get_history.rst b/docs/source/start/examples/get_history.rst
deleted file mode 100644
index 01433d91fe..0000000000
--- a/docs/source/start/examples/get_history.rst
+++ /dev/null
@@ -1,15 +0,0 @@
-get_history
-===========
-
-This example shows how to get the full message history of a chat, starting from the latest message.
-
-.. code-block:: python
-
-    from pyrogram import Client
-
-    app = Client("my_account")
-    target = "me"  # "me" refers to your own chat (Saved Messages)
-
-    with app:
-        for message in app.iter_history(target):
-            print(message.text)
\ No newline at end of file
diff --git a/docs/source/start/examples/hello_world.rst b/docs/source/start/examples/hello_world.rst
index 997659e237..2902241e8c 100644
--- a/docs/source/start/examples/hello_world.rst
+++ b/docs/source/start/examples/hello_world.rst
@@ -10,6 +10,11 @@ This example demonstrates a basic API usage
     # Create a new Client instance
     app = Client("my_account")
 
-    with app:
-        # Send a message, Markdown is enabled by default
-        app.send_message("me", "Hi there! I'm using **Pyrogram**")
+
+    async def main():
+        async with app:
+            # Send a message, Markdown is enabled by default
+            await app.send_message("me", "Hi there! I'm using **Pyrogram**")
+
+
+    app.run(main())
diff --git a/docs/source/start/examples/index.rst b/docs/source/start/examples/index.rst
index 7d8a69a41d..d47b60e80d 100644
--- a/docs/source/start/examples/index.rst
+++ b/docs/source/start/examples/index.rst
@@ -17,9 +17,9 @@ to give you a basic idea.
     :align: center
 
     :doc:`hello_world`, "Demonstration of basic API usage"
-    :doc:`echobot`, "Echo every private text message"
-    :doc:`welcomebot`, "The Welcome Bot in @PyrogramChat"
-    :doc:`get_history`, "Get the full message history of a chat"
+    :doc:`echo_bot`, "Echo every private text message"
+    :doc:`welcome_bot`, "The Welcome Bot in @PyrogramChat"
+    :doc:`get_chat_history`, "Get the full message history of a chat"
     :doc:`get_chat_members`, "Get all the members of a chat"
     :doc:`get_dialogs`, "Get all of your dialog chats"
     :doc:`callback_queries`, "Handle callback queries (as bot) coming from inline button presses"
@@ -34,9 +34,9 @@ For more advanced examples, see https://snippets.pyrogram.org.
     :hidden:
 
     hello_world
-    echobot
-    welcomebot
-    get_history
+    echo_bot
+    welcome_bot
+    get_chat_history
     get_chat_members
     get_dialogs
     callback_queries
diff --git a/docs/source/start/examples/inline_queries.rst b/docs/source/start/examples/inline_queries.rst
index 09d226ef6b..b78c6e1cb8 100644
--- a/docs/source/start/examples/inline_queries.rst
+++ b/docs/source/start/examples/inline_queries.rst
@@ -16,8 +16,8 @@ It uses the @on_inline_query decorator to register an InlineQueryHandler.
 
 
     @app.on_inline_query()
-    def answer(client, inline_query):
-        inline_query.answer(
+    async def answer(client, inline_query):
+        await inline_query.answer(
             results=[
                 InlineQueryResultArticle(
                     title="Installation",
diff --git a/docs/source/start/examples/raw_updates.rst b/docs/source/start/examples/raw_updates.rst
index 6086a9686c..463a45a80b 100644
--- a/docs/source/start/examples/raw_updates.rst
+++ b/docs/source/start/examples/raw_updates.rst
@@ -11,7 +11,7 @@ This example shows how to handle raw updates.
 
 
     @app.on_raw_update()
-    def raw(client, update, users, chats):
+    async def raw(client, update, users, chats):
         print(update)
 
 
diff --git a/docs/source/start/examples/use_inline_bots.rst b/docs/source/start/examples/use_inline_bots.rst
index 63e4698506..8a2a72acc4 100644
--- a/docs/source/start/examples/use_inline_bots.rst
+++ b/docs/source/start/examples/use_inline_bots.rst
@@ -10,9 +10,16 @@ This example shows how to query an inline bot (as user).
     # Create a new Client
     app = Client("my_account")
 
-    with app:
-        # Get bot results for "hello" from the inline bot @vid
-        bot_results = app.get_inline_bot_results("vid", "hello")
 
-        # Send the first result (bot_results.results[0]) to your own chat (Saved Messages)
-        app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id)
\ No newline at end of file
+    async def main():
+        async with app:
+            # Get bot results for "hello" from the inline bot @vid
+            bot_results = await app.get_inline_bot_results("vid", "hello")
+
+            # Send the first result to your own chat (Saved Messages)
+            await app.send_inline_bot_result(
+                "me", bot_results.query_id,
+                bot_results.results[0].id)
+
+
+    app.run(main())
\ No newline at end of file
diff --git a/docs/source/start/examples/welcomebot.rst b/docs/source/start/examples/welcome_bot.rst
similarity index 73%
rename from docs/source/start/examples/welcomebot.rst
rename to docs/source/start/examples/welcome_bot.rst
index a742059007..4e30ea7f0a 100644
--- a/docs/source/start/examples/welcomebot.rst
+++ b/docs/source/start/examples/welcome_bot.rst
@@ -1,5 +1,5 @@
-welcomebot
-==========
+welcome_bot
+===========
 
 This example uses the ``emoji`` module to easily add emoji in your text messages and ``filters``
 to make it only work for specific messages in a specific chat.
@@ -8,24 +8,23 @@ to make it only work for specific messages in a specific chat.
 
     from pyrogram import Client, emoji, filters
 
-    TARGET = -100123456789  # Target chat. Can also be a list of multiple chat ids/usernames
-    MENTION = "[{}](tg://user?id={})"  # User mention markup
-    MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.org/)'s group chat {}!"  # Welcome message
+    # Target chat. Can also be a list of multiple chat ids/usernames
+    TARGET = -100123456789
+    # Welcome message template
+    MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.org/)'s group chat {}!"
 
     app = Client("my_account")
 
 
     # Filter in only new_chat_members updates generated in TARGET chat
     @app.on_message(filters.chat(TARGET) & filters.new_chat_members)
-    def welcome(client, message):
+    async def welcome(client, message):
         # Build the new members list (with mentions) by using their first_name
         new_members = [u.mention for u in message.new_chat_members]
-
         # Build the welcome message by using an emoji and the list we built above
         text = MESSAGE.format(emoji.SPARKLES, ", ".join(new_members))
-
         # Send the welcome message, without the web page preview
-        message.reply_text(text, disable_web_page_preview=True)
+        await message.reply_text(text, disable_web_page_preview=True)
 
 
     app.run()  # Automatically start() and idle()
\ No newline at end of file
diff --git a/docs/source/start/invoking.rst b/docs/source/start/invoking.rst
index de1e321ed1..ab91e7306b 100644
--- a/docs/source/start/invoking.rst
+++ b/docs/source/start/invoking.rst
@@ -1,5 +1,5 @@
-Calling Methods
-===============
+Invoking Methods
+================
 
 At this point, we have successfully :doc:`installed Pyrogram <../intro/install>` and :doc:`authorized ` our
 account; we are now aiming towards the core of the framework.
@@ -14,7 +14,7 @@ account; we are now aiming towards the core of the framework.
 Basic Usage
 -----------
 
-Making API method calls with Pyrogram is very simple. Here's a basic example we are going to examine step by step:
+Making API calls with Pyrogram is very simple. Here's a basic example we are going to examine step by step:
 
 .. code-block:: python
 
@@ -43,7 +43,7 @@ Step-by-step
 
         app = Client("my_account")
 
-#.  Async methods can't be executed at the top level, because they must be inside an async context.
+#.  Async methods must be invoked within an async context.
     Here we define an async function and put our code inside. Also notice the ``await`` keyword in front of the method
     call; this is required for all asynchronous methods.
 
@@ -101,24 +101,4 @@ be instantiated inside the main function.
         async with app:
             await app.send_message("me", "Hi!")
 
-    asyncio.run(main())
-
-Synchronous Calls
-------------------
-
-Pyrogram is an asynchronous framework, but it also provides a convenience way for calling methods without the need
-of async/await keywords and the extra boilerplate. In case you want Pyrogram to run synchronously, simply  use the
-synchronous context manager:
-
-.. code-block:: python
-
-    from pyrogram import Client
-
-    app = Client("my_account")
-
-    with app:
-        app.send_message("me", "Hi!")
-
-As you can see, the non-async example becomes less cluttered. Use Pyrogram in this non-asynchronous way only when you
-want to write something without the boilerplate or in case you want to combine Pyrogram with other libraries that are
-not async.
\ No newline at end of file
+    asyncio.run(main())
\ No newline at end of file
diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst
index dee5a11589..0cdf76507f 100644
--- a/docs/source/start/updates.rst
+++ b/docs/source/start/updates.rst
@@ -1,8 +1,8 @@
 Handling Updates
 ================
 
-Calling :doc:`API methods ` sequentially is one way to use Pyrogram, but how to react when, for example, a
-new message arrives? This page deals with updates and how to handle such events in Pyrogram.
+:doc:`Invoking API methods ` sequentially is one way to use Pyrogram. This page deals with Telegram updates
+and how to handle new incoming messages or other events in Pyrogram.
 
 .. contents:: Contents
     :backlinks: none
@@ -14,7 +14,7 @@ new message arrives? This page deals with updates and how to handle such events
 Defining Updates
 ----------------
 
-As hinted already, updates are simply events that happen in your Telegram account (incoming messages, new members join,
+As hinted already, updates are events that happen in your Telegram account (incoming messages, new members join,
 bot button presses, etc.), which are meant to notify you about a new specific state that has changed. These updates are
 handled by registering one or more callback functions in your app using :doc:`Handlers <../api/handlers>`.
 
@@ -52,25 +52,6 @@ In the last line we see again the :meth:`~pyrogram.Client.run` method, this time
 Its purpose here is simply to automatically :meth:`~pyrogram.Client.start`, keep the Client online so that it can listen
 for updates and :meth:`~pyrogram.Client.stop` it once you hit ``CTRL+C``.
 
-Synchronous handlers
-^^^^^^^^^^^^^^^^^^^^^
-
-You can also have synchronous handlers; you only need to define the callback function without using ``async def`` and
-call API methods by not placing ``await`` in front of them:
-
-.. code-block:: python
-
-    @app.on_message()
-    def my_handler(client, message):
-        message.forward("me")
-
-.. note::
-
-    You can mix ``def`` and ``async def`` handlers as much as you like, Pyrogram will still work concurrently and
-    efficiently regardless of what you choose. However, it is recommended to use Pyrogram in its native, asynchronous
-    form at all times, unless you want to write something without the boilerplate or in case you want to combine
-    Pyrogram with other libraries that are not async.
-
 Using add_handler()
 ^^^^^^^^^^^^^^^^^^^
 
@@ -91,16 +72,3 @@ function and registers it in your Client. It is useful in case you want to progr
     app.add_handler(my_handler)
 
     app.run()
-
-The same about synchronous handlers applies for :meth:`~pyrogram.Client.add_handler`:
-
-.. code-block:: python
-
-    def my_function(client, message):
-        message.forward("me")
-
-.. note::
-
-    From now on, you'll see examples using synchronous code (i.e.: without ``async`` and ``await``, unless when actually
-    relevant). This is done to keep snippets concise and more readable. Once you get the idea behind a feature, you can
-    easily turn examples asynchronous later on.
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 5e5ea69c39..bcef9c1d98 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -35,15 +35,8 @@ class ContinuePropagation(StopAsyncIteration):
     pass
 
 
-import asyncio
-
 from . import raw, types, filters, handlers, emoji, enums
 from .client import Client
 from .sync import idle
 
-# Save the main thread loop for future references
-main_event_loop = asyncio.get_event_loop()
-
-CRYPTO_EXECUTOR_SIZE_THRESHOLD = 512
-
 crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker")
diff --git a/pyrogram/client.py b/pyrogram/client.py
index ac753f8849..525ecf4a51 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -452,29 +452,26 @@ def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]):
         Example:
             .. code-block:: python
 
-                from pyrogram import Client, enums
+                from pyrogram import enums
 
-                app = Client("my_account")
+                # Default combined mode: Markdown + HTML
+                await app.send_message("me", "1. **markdown** and html")
 
-                with app:
-                    # Default combined mode: Markdown + HTML
-                    app.send_message("me", "1. **markdown** and html")
+                # Force Markdown-only, HTML is disabled
+                app.set_parse_mode(enums.ParseMode.MARKDOWN)
+                await app.send_message("me", "2. **markdown** and html")
 
-                    # Force Markdown-only, HTML is disabled
-                    app.set_parse_mode(enums.ParseMode.MARKDOWN)
-                    app.send_message("me", "2. **markdown** and html")
+                # Force HTML-only, Markdown is disabled
+                app.set_parse_mode(enums.ParseMode.HTML)
+                await app.send_message("me", "3. **markdown** and html")
 
-                    # Force HTML-only, Markdown is disabled
-                    app.set_parse_mode(enums.ParseMode.HTML)
-                    app.send_message("me", "3. **markdown** and html")
+                # Disable the parser completely
+                app.set_parse_mode(enums.ParseMode.DISABLED)
+                await app.send_message("me", "4. **markdown** and html")
 
-                    # Disable the parser completely
-                    app.set_parse_mode(enums.ParseMode.DISABLED)
-                    app.send_message("me", "4. **markdown** and html")
-
-                    # Bring back the default combined mode
-                    app.set_parse_mode(enums.ParseMode.DEFAULT)
-                    app.send_message("me", "5. **markdown** and html")
+                # Bring back the default combined mode
+                app.set_parse_mode(enums.ParseMode.DEFAULT)
+                await app.send_message("me", "5. **markdown** and html")
         """
 
         self.parse_mode = parse_mode
diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py
index af2c8f7252..95d479314a 100644
--- a/pyrogram/methods/bots/answer_callback_query.py
+++ b/pyrogram/methods/bots/answer_callback_query.py
@@ -60,13 +60,13 @@ async def answer_callback_query(
             .. code-block:: python
 
                 # Answer only (remove the spinning circles)
-                app.answer_callback_query(query_id)
+                await app.answer_callback_query(query_id)
 
                 # Answer without alert
-                app.answer_callback_query(query_id, text=text)
+                await app.answer_callback_query(query_id, text=text)
 
                 # Answer with alert
-                app.answer_callback_query(query_id, text=text, show_alert=True)
+                await app.answer_callback_query(query_id, text=text, show_alert=True)
         """
         return await self.invoke(
             raw.functions.messages.SetBotCallbackAnswer(
diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py
index ebdfab2397..e9acd9375d 100644
--- a/pyrogram/methods/bots/answer_inline_query.py
+++ b/pyrogram/methods/bots/answer_inline_query.py
@@ -86,7 +86,7 @@ async def answer_inline_query(
 
                 from pyrogram.types import InlineQueryResultArticle, InputTextMessageContent
 
-                app.answer_inline_query(
+                await app.answer_inline_query(
                     inline_query_id,
                     results=[
                         InlineQueryResultArticle(
diff --git a/pyrogram/methods/bots/delete_bot_commands.py b/pyrogram/methods/bots/delete_bot_commands.py
index 98e6d3960f..2e638aed7f 100644
--- a/pyrogram/methods/bots/delete_bot_commands.py
+++ b/pyrogram/methods/bots/delete_bot_commands.py
@@ -49,7 +49,7 @@ async def delete_bot_commands(
             .. code-block:: python
 
                 # Delete commands
-                app.delete_bot_commands()
+                await app.delete_bot_commands()
         """
 
         return await self.invoke(
diff --git a/pyrogram/methods/bots/get_bot_commands.py b/pyrogram/methods/bots/get_bot_commands.py
index fe5be0f3bd..f62b63754a 100644
--- a/pyrogram/methods/bots/get_bot_commands.py
+++ b/pyrogram/methods/bots/get_bot_commands.py
@@ -51,7 +51,7 @@ async def get_bot_commands(
             .. code-block:: python
 
                 # Get commands
-                commands = app.get_bot_commands()
+                commands = await app.get_bot_commands()
                 print(commands)
         """
 
diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py
index 312cc632b4..555e9af5e3 100644
--- a/pyrogram/methods/bots/get_game_high_scores.py
+++ b/pyrogram/methods/bots/get_game_high_scores.py
@@ -54,7 +54,7 @@ async def get_game_high_scores(
         Example:
             .. code-block:: python
 
-                scores = app.get_game_high_scores(user_id, chat_id, message_id)
+                scores = await app.get_game_high_scores(user_id, chat_id, message_id)
                 print(scores)
         """
         # TODO: inline_message_id
diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py
index f145cc8c44..3ef1d4dea0 100644
--- a/pyrogram/methods/bots/get_inline_bot_results.py
+++ b/pyrogram/methods/bots/get_inline_bot_results.py
@@ -64,7 +64,7 @@ async def get_inline_bot_results(
         Example:
             .. code-block:: python
 
-                results = app.get_inline_bot_results("pyrogrambot")
+                results = await app.get_inline_bot_results("pyrogrambot")
                 print(results)
         """
         # TODO: Don't return the raw type
diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py
index 908c8ecae6..9c0626a56e 100644
--- a/pyrogram/methods/bots/request_callback_answer.py
+++ b/pyrogram/methods/bots/request_callback_answer.py
@@ -58,7 +58,7 @@ async def request_callback_answer(
         Example:
             .. code-block:: python
 
-                app.request_callback_answer(chat_id, message_id, "callback_data")
+                await app.request_callback_answer(chat_id, message_id, "callback_data")
         """
 
         # Telegram only wants bytes, but we are allowed to pass strings too.
diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py
index c8eee66eff..e4181166f7 100644
--- a/pyrogram/methods/bots/send_game.py
+++ b/pyrogram/methods/bots/send_game.py
@@ -69,7 +69,7 @@ async def send_game(
         Example:
             .. code-block:: python
 
-                app.send_game(chat_id, "gamename")
+                await app.send_game(chat_id, "gamename")
         """
         r = await self.invoke(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py
index 00b4204309..ebe5ca8d24 100644
--- a/pyrogram/methods/bots/send_inline_bot_result.py
+++ b/pyrogram/methods/bots/send_inline_bot_result.py
@@ -59,7 +59,7 @@ async def send_inline_bot_result(
         Example:
             .. code-block:: python
 
-                app.send_inline_bot_result(chat_id, query_id, result_id)
+                await app.send_inline_bot_result(chat_id, query_id, result_id)
         """
         return await self.invoke(
             raw.functions.messages.SendInlineBotResult(
diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py
index b59c0fac78..7dfbf10979 100644
--- a/pyrogram/methods/bots/set_bot_commands.py
+++ b/pyrogram/methods/bots/set_bot_commands.py
@@ -57,7 +57,7 @@ async def set_bot_commands(
                 from pyrogram.types import BotCommand
 
                 # Set new commands
-                app.set_bot_commands([
+                await app.set_bot_commands([
                     BotCommand("start", "Start the bot"),
                     BotCommand("settings", "Bot settings")])
         """
diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py
index 855e4a2ece..f9008e4435 100644
--- a/pyrogram/methods/bots/set_game_score.py
+++ b/pyrogram/methods/bots/set_game_score.py
@@ -70,10 +70,10 @@ async def set_game_score(
             .. code-block:: python
 
                 # Set new score
-                app.set_game_score(user_id, 1000)
+                await app.set_game_score(user_id, 1000)
 
                 # Force set new score
-                app.set_game_score(user_id, 25, force=True)
+                await app.set_game_score(user_id, 25, force=True)
         """
         r = await self.invoke(
             raw.functions.messages.SetGameScore(
diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py
index 6eedbd32e6..1b744a0569 100644
--- a/pyrogram/methods/chats/__init__.py
+++ b/pyrogram/methods/chats/__init__.py
@@ -36,7 +36,6 @@
 from .get_dialogs_count import GetDialogsCount
 from .get_nearby_chats import GetNearbyChats
 from .get_send_as_chats import GetSendAsChats
-from .iter_chat_members import IterChatMembers
 from .iter_dialogs import IterDialogs
 from .join_chat import JoinChat
 from .leave_chat import LeaveChat
@@ -78,7 +77,6 @@ class Chats(
     GetDialogs,
     GetChatMembersCount,
     IterDialogs,
-    IterChatMembers,
     SetChatUsername,
     SetChatPermissions,
     GetDialogsCount,
diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py
index 2d053c4e8e..2bf145f907 100644
--- a/pyrogram/methods/chats/add_chat_members.py
+++ b/pyrogram/methods/chats/add_chat_members.py
@@ -52,13 +52,13 @@ async def add_chat_members(
             .. code-block:: python
 
                 # Add one member to a group or channel
-                app.add_chat_members(chat_id, user_id)
+                await app.add_chat_members(chat_id, user_id)
 
                 # Add multiple members to a group or channel
-                app.add_chat_members(chat_id, [user_id1, user_id2, user_id3])
+                await app.add_chat_members(chat_id, [user_id1, user_id2, user_id3])
 
                 # Change forward_limit (for basic groups only)
-                app.add_chat_members(chat_id, user_id, forward_limit=25)
+                await app.add_chat_members(chat_id, user_id, forward_limit=25)
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py
index cba27371cb..40544e0fdc 100644
--- a/pyrogram/methods/chats/archive_chats.py
+++ b/pyrogram/methods/chats/archive_chats.py
@@ -41,10 +41,10 @@ async def archive_chats(
             .. code-block:: python
 
                 # Archive chat
-                app.archive_chats(chat_id)
+                await app.archive_chats(chat_id)
 
                 # Archive multiple chats at once
-                app.archive_chats([chat_id1, chat_id2, chat_id3])
+                await app.archive_chats([chat_id1, chat_id2, chat_id3])
         """
 
         if not isinstance(chat_ids, list):
diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py
index d8a207aba8..8e1bca1eda 100644
--- a/pyrogram/methods/chats/ban_chat_member.py
+++ b/pyrogram/methods/chats/ban_chat_member.py
@@ -64,10 +64,10 @@ async def ban_chat_member(
                 from datetime import datetime, timedelta
 
                 # Ban chat member forever
-                app.ban_chat_member(chat_id, user_id)
+                await app.ban_chat_member(chat_id, user_id)
 
                 # Ban chat member and automatically unban after 24h
-                app.ban_chat_member(chat_id, user_id, datetime.now() + timedelta(days=1))
+                await app.ban_chat_member(chat_id, user_id, datetime.now() + timedelta(days=1))
         """
         chat_peer = await self.resolve_peer(chat_id)
         user_peer = await self.resolve_peer(user_id)
diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py
index 1b054b6ed6..2a1497789d 100644
--- a/pyrogram/methods/chats/create_channel.py
+++ b/pyrogram/methods/chats/create_channel.py
@@ -41,7 +41,7 @@ async def create_channel(
         Example:
             .. code-block:: python
 
-                app.create_channel("Channel Title", "Channel Description")
+                await app.create_channel("Channel Title", "Channel Description")
         """
         r = await self.invoke(
             raw.functions.channels.CreateChannel(
diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py
index 78240f9fb0..a2ffa8de66 100644
--- a/pyrogram/methods/chats/create_group.py
+++ b/pyrogram/methods/chats/create_group.py
@@ -50,7 +50,7 @@ async def create_group(
         Example:
             .. code-block:: python
 
-                app.create_group("Group Title", user_id)
+                await app.create_group("Group Title", user_id)
         """
         if not isinstance(users, list):
             users = [users]
diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py
index eb922c324f..04da148a90 100644
--- a/pyrogram/methods/chats/create_supergroup.py
+++ b/pyrogram/methods/chats/create_supergroup.py
@@ -45,7 +45,7 @@ async def create_supergroup(
         Example:
             .. code-block:: python
 
-                app.create_supergroup("Supergroup Title", "Supergroup Description")
+                await app.create_supergroup("Supergroup Title", "Supergroup Description")
         """
         r = await self.invoke(
             raw.functions.channels.CreateChannel(
diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py
index 210c81f1cd..7aad47d033 100644
--- a/pyrogram/methods/chats/delete_channel.py
+++ b/pyrogram/methods/chats/delete_channel.py
@@ -39,7 +39,7 @@ async def delete_channel(
         Example:
             .. code-block:: python
 
-                app.delete_channel(channel_id)
+                await app.delete_channel(channel_id)
         """
         await self.invoke(
             raw.functions.channels.DeleteChannel(
diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py
index ac485603cd..058b7fdb29 100644
--- a/pyrogram/methods/chats/delete_chat_photo.py
+++ b/pyrogram/methods/chats/delete_chat_photo.py
@@ -44,7 +44,7 @@ async def delete_chat_photo(
         Example:
             .. code-block:: python
 
-                app.delete_chat_photo(chat_id)
+                await app.delete_chat_photo(chat_id)
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py
index 8fb069fff8..39d5a07d91 100644
--- a/pyrogram/methods/chats/delete_supergroup.py
+++ b/pyrogram/methods/chats/delete_supergroup.py
@@ -39,7 +39,7 @@ async def delete_supergroup(
         Example:
             .. code-block:: python
 
-                app.delete_supergroup(supergroup_id)
+                await app.delete_supergroup(supergroup_id)
         """
         await self.invoke(
             raw.functions.channels.DeleteChannel(
diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py
index fc19801910..d3246447a7 100644
--- a/pyrogram/methods/chats/get_chat.py
+++ b/pyrogram/methods/chats/get_chat.py
@@ -50,7 +50,7 @@ async def get_chat(
         Example:
             .. code-block:: python
 
-                chat = app.get_chat("pyrogram")
+                chat = await app.get_chat("pyrogram")
                 print(chat)
         """
         match = self.INVITE_LINK_RE.match(str(chat_id))
diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py
index 2325bad99a..622fe0bc0f 100644
--- a/pyrogram/methods/chats/get_chat_event_log.py
+++ b/pyrogram/methods/chats/get_chat_event_log.py
@@ -64,6 +64,12 @@ async def get_chat_event_log(
 
         Yields:
             :obj:`~pyrogram.types.ChatEvent` objects.
+
+        Example:
+            .. code-block:: python
+
+                async for event in app.get_chat_event_log(chat_id):
+                    print(event)
         """
         current = 0
         total = abs(limit) or (1 << 31)
diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py
index 1b24d2135c..526cf744ca 100644
--- a/pyrogram/methods/chats/get_chat_member.py
+++ b/pyrogram/methods/chats/get_chat_member.py
@@ -47,7 +47,7 @@ async def get_chat_member(
         Example:
             .. code-block:: python
 
-                member = app.get_chat_member(chat_id, "me")
+                member = await app.get_chat_member(chat_id, "me")
                 print(member)
         """
         chat = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py
index c2516a7081..065e262c7b 100644
--- a/pyrogram/methods/chats/get_chat_members.py
+++ b/pyrogram/methods/chats/get_chat_members.py
@@ -97,16 +97,16 @@ async def get_chat_members(
                 from pyrogram import enums
 
                 # Get members
-                for member in app.get_chat_members(chat_id):
+                async for member in app.get_chat_members(chat_id):
                     print(member)
 
                 # Get administrators
-                administrators = list(app.get_chat_members(
+                administrators = list(await app.get_chat_members(
                     chat_id,
                     filter=enums.ChatMembersFilter.ADMINISTRATORS))
 
                 # Get bots
-                bots = list(app.get_chat_members(
+                bots = list(await app.get_chat_members(
                     chat_id,
                     filter=enums.ChatMembersFilter.BOTS))
         """
diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py
index 9c57a11e80..e2f7fa8b92 100644
--- a/pyrogram/methods/chats/get_chat_members_count.py
+++ b/pyrogram/methods/chats/get_chat_members_count.py
@@ -42,7 +42,7 @@ async def get_chat_members_count(
         Example:
             .. code-block:: python
 
-                count = app.get_chat_members_count(chat_id)
+                count = await app.get_chat_members_count(chat_id)
                 print(count)
         """
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py
index 19924542f5..45c60d978b 100644
--- a/pyrogram/methods/chats/get_chat_online_count.py
+++ b/pyrogram/methods/chats/get_chat_online_count.py
@@ -39,7 +39,7 @@ async def get_chat_online_count(
         Example:
             .. code-block:: python
 
-                online = app.get_chat_online_count(chat_id)
+                online = await app.get_chat_online_count(chat_id)
                 print(online)
         """
         return (await self.invoke(
diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py
index 4aaa95ffc4..f888c3ef4c 100644
--- a/pyrogram/methods/chats/get_dialogs.py
+++ b/pyrogram/methods/chats/get_dialogs.py
@@ -60,10 +60,10 @@ async def get_dialogs(
             .. code-block:: python
 
                 # Get first 100 dialogs
-                app.get_dialogs()
+                await app.get_dialogs()
 
                 # Get pinned dialogs
-                app.get_dialogs(pinned_only=True)
+                await app.get_dialogs(pinned_only=True)
         """
 
         if pinned_only:
diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py
index 8ca237cff5..3d96732cf1 100644
--- a/pyrogram/methods/chats/get_dialogs_count.py
+++ b/pyrogram/methods/chats/get_dialogs_count.py
@@ -37,7 +37,7 @@ async def get_dialogs_count(
         Example:
             .. code-block:: python
 
-                count = app.get_dialogs_count()
+                count = await app.get_dialogs_count()
                 print(count)
         """
 
diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py
index c7c36cc61d..2ebd930644 100644
--- a/pyrogram/methods/chats/get_nearby_chats.py
+++ b/pyrogram/methods/chats/get_nearby_chats.py
@@ -45,7 +45,7 @@ async def get_nearby_chats(
         Example:
             .. code-block:: python
 
-                chats = app.get_nearby_chats(51.500729, -0.124583)
+                chats = await app.get_nearby_chats(latitude, longitude)
                 print(chats)
         """
 
diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py
index 2db4d5f05a..2ad3b8b561 100644
--- a/pyrogram/methods/chats/get_send_as_chats.py
+++ b/pyrogram/methods/chats/get_send_as_chats.py
@@ -40,7 +40,7 @@ async def get_send_as_chats(
         Example:
             .. code-block:: python
 
-                chats = app.get_send_as_chats(chat_id)
+                chats = await app.get_send_as_chats(chat_id)
                 print(chats)
         """
         r = await self.invoke(
diff --git a/pyrogram/methods/chats/iter_chat_members.py b/pyrogram/methods/chats/iter_chat_members.py
deleted file mode 100644
index f3ccf06c81..0000000000
--- a/pyrogram/methods/chats/iter_chat_members.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-present Dan 
-#
-#  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 typing import Union, AsyncGenerator, Optional
-
-import pyrogram
-from pyrogram import raw
-from pyrogram import types
-
-
-class Filters:
-    ALL = "all"
-    BANNED = "banned"
-    RESTRICTED = "restricted"
-    BOTS = "bots"
-    RECENT = "recent"
-    ADMINISTRATORS = "administrators"
-
-
-class IterChatMembers:
-    async def iter_chat_members(
-        self: "pyrogram.Client",
-        chat_id: Union[int, str],
-        limit: int = 0,
-        query: str = "",
-        filter: str = Filters.RECENT
-    ) -> Optional[AsyncGenerator["types.ChatMember", None]]:
-        """Iterate through the members of a chat sequentially.
-
-        This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_chat_members` in a loop,
-        thus saving you from the hassle of setting up boilerplate code. It is useful for getting the whole members list
-        of a chat with a single call.
-
-        Parameters:
-            chat_id (``int`` | ``str``):
-                Unique identifier (int) or username (str) of the target chat.
-
-            limit (``int``, *optional*):
-                Limits the number of members to be retrieved.
-
-            query (``str``, *optional*):
-                Query string to filter members based on their display names and usernames.
-                Defaults to "" (empty string).
-                A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
-
-            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 the followings:
-                *"all"* - all kind of members,
-                *"banned"* - banned members only,
-                *"restricted"* - restricted members only,
-                *"bots"* - bots only,
-                *"recent"* - recent members only,
-                *"administrators"* - chat administrators only.
-                Defaults to *"recent"*.
-
-        Returns:
-            ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects.
-
-        Example:
-            .. code-block:: python
-
-                # Iterate though all chat members
-                for member in app.iter_chat_members(chat_id):
-                    print(member.user.first_name)
-
-                # Iterate though all administrators
-                for member in app.iter_chat_members(chat_id, filter="administrators"):
-                    print(member.user.first_name)
-
-                # Iterate though all bots
-                for member in app.iter_chat_members(chat_id, filter="bots"):
-                    print(member.user.first_name)
-        """
-        current = 0
-        yielded = set()
-        total = limit or (1 << 31) - 1
-        limit = min(200, total)
-        resolved_chat_id = await self.resolve_peer(chat_id)
-        offset = 0
-
-        while True:
-            chat_members = await self.get_chat_members(
-                chat_id=chat_id,
-                offset=offset,
-                limit=limit,
-                query=query,
-                filter=filter
-            )
-
-            if not chat_members:
-                break
-
-            if isinstance(resolved_chat_id, raw.types.InputPeerChat):
-                total = len(chat_members)
-
-            offset += len(chat_members)
-
-            for chat_member in chat_members:
-                peer_id = chat_member.user.id if chat_member.user else chat_member.chat.id
-
-                if peer_id in yielded:
-                    continue
-
-                yield chat_member
-
-                yielded.add(peer_id)
-
-                current += 1
-
-                if current >= total:
-                    return
diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py
index 72a396f758..d0f037bea0 100644
--- a/pyrogram/methods/chats/iter_dialogs.py
+++ b/pyrogram/methods/chats/iter_dialogs.py
@@ -45,7 +45,7 @@ async def iter_dialogs(
             .. code-block:: python
 
                 # Iterate through all dialogs
-                for dialog in app.iter_dialogs():
+                async for dialog in app.iter_dialogs():
                     print(dialog.chat.first_name or dialog.chat.title)
         """
         current = 0
diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py
index 2534442ac6..07d7b2a7e2 100644
--- a/pyrogram/methods/chats/join_chat.py
+++ b/pyrogram/methods/chats/join_chat.py
@@ -41,14 +41,14 @@ async def join_chat(
         Example:
             .. code-block:: python
 
-                # Join chat via username
-                app.join_chat("pyrogram")
-
                 # Join chat via invite link
-                app.join_chat("https://t.me/joinchat/AAAAAE0QmSW3IUmm3UFR7A")
+                await app.join_chat("https://t.me/+AbCdEf0123456789")
+
+                # Join chat via username
+                await app.join_chat("pyrogram")
 
                 # Join a linked chat
-                app.join_chat(app.get_chat("pyrogram").linked_chat.id)
+                await app.join_chat(app.get_chat("pyrogram").linked_chat.id)
         """
         match = self.INVITE_LINK_RE.match(str(chat_id))
 
diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py
index 7a6eb85dff..942173f469 100644
--- a/pyrogram/methods/chats/leave_chat.py
+++ b/pyrogram/methods/chats/leave_chat.py
@@ -43,10 +43,10 @@ async def leave_chat(
             .. code-block:: python
 
                 # Leave chat or channel
-                app.leave_chat(chat_id)
+                await app.leave_chat(chat_id)
 
                 # Leave basic chat and also delete the dialog
-                app.leave_chat(chat_id, delete=True)
+                await app.leave_chat(chat_id, delete=True)
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py
index 1f5ac91239..0eaa152513 100644
--- a/pyrogram/methods/chats/pin_chat_message.py
+++ b/pyrogram/methods/chats/pin_chat_message.py
@@ -56,10 +56,10 @@ async def pin_chat_message(
             .. code-block:: python
 
                 # Pin with notification
-                app.pin_chat_message(chat_id, message_id)
+                await app.pin_chat_message(chat_id, message_id)
 
                 # Pin without notification
-                app.pin_chat_message(chat_id, message_id, disable_notification=True)
+                await app.pin_chat_message(chat_id, message_id, disable_notification=True)
         """
         r = await self.invoke(
             raw.functions.messages.UpdatePinnedMessage(
diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py
index b64a17996f..e6f2171e2e 100644
--- a/pyrogram/methods/chats/promote_chat_member.py
+++ b/pyrogram/methods/chats/promote_chat_member.py
@@ -27,7 +27,7 @@ async def promote_chat_member(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
         user_id: Union[int, str],
-        privileges: "types.ChatPrivileges" = types.ChatPrivileges(),
+        privileges: "types.ChatPrivileges" = None,
     ) -> bool:
         """Promote or demote a user in a supergroup or a channel.
 
@@ -52,11 +52,15 @@ async def promote_chat_member(
             .. code-block:: python
 
                 # Promote chat member to admin
-                app.promote_chat_member(chat_id, user_id)
+                await app.promote_chat_member(chat_id, user_id)
         """
         chat_id = await self.resolve_peer(chat_id)
         user_id = await self.resolve_peer(user_id)
 
+        # See Chat.promote_member for the reason of this (instead of setting types.ChatPrivileges() as default arg).
+        if privileges is None:
+            privileges = types.ChatPrivileges()
+
         raw_chat_member = (await self.invoke(
             raw.functions.channels.GetParticipant(
                 channel=chat_id,
diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py
index 52b264e841..4ebb5f1877 100644
--- a/pyrogram/methods/chats/restrict_chat_member.py
+++ b/pyrogram/methods/chats/restrict_chat_member.py
@@ -60,17 +60,18 @@ async def restrict_chat_member(
             .. code-block:: python
 
                 from datetime import datetime, timedelta
-
                 from pyrogram.types import ChatPermissions
 
                 # Completely restrict chat member (mute) forever
-                app.restrict_chat_member(chat_id, user_id, ChatPermissions())
+                await app.restrict_chat_member(chat_id, user_id, ChatPermissions())
 
                 # Chat member muted for 24h
-                app.restrict_chat_member(chat_id, user_id, ChatPermissions(), datetime.now() + timedelta(days=1))
+                await app.restrict_chat_member(chat_id, user_id, ChatPermissions(),
+                    datetime.now() + timedelta(days=1))
 
                 # Chat member can only send text messages
-                app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
+                await app.restrict_chat_member(chat_id, user_id,
+                    ChatPermissions(can_send_messages=True))
         """
         r = await self.invoke(
             raw.functions.channels.EditBanned(
diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py
index 2ea0dccf6c..15f9dea5ef 100644
--- a/pyrogram/methods/chats/set_administrator_title.py
+++ b/pyrogram/methods/chats/set_administrator_title.py
@@ -52,7 +52,7 @@ async def set_administrator_title(
         Example:
             .. code-block:: python
 
-                app.set_administrator_title(chat_id, user_id, "Admin Title")
+                await app.set_administrator_title(chat_id, user_id, "Admin Title")
         """
         chat_id = await self.resolve_peer(chat_id)
         user_id = await self.resolve_peer(user_id)
diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py
index 4a93530b64..3eee92cae2 100644
--- a/pyrogram/methods/chats/set_chat_description.py
+++ b/pyrogram/methods/chats/set_chat_description.py
@@ -47,7 +47,7 @@ async def set_chat_description(
         Example:
             .. code-block:: python
 
-                app.set_chat_description(chat_id, "New Description")
+                await app.set_chat_description(chat_id, "New Description")
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py
index 51d74fee8c..d1280ea725 100644
--- a/pyrogram/methods/chats/set_chat_permissions.py
+++ b/pyrogram/methods/chats/set_chat_permissions.py
@@ -50,10 +50,10 @@ async def set_chat_permissions(
                 from pyrogram.types import ChatPermissions
 
                 # Completely restrict chat
-                app.set_chat_permissions(chat_id, ChatPermissions())
+                await app.set_chat_permissions(chat_id, ChatPermissions())
 
                 # Chat members can only send text messages and media messages
-                app.set_chat_permissions(
+                await app.set_chat_permissions(
                     chat_id,
                     ChatPermissions(
                         can_send_messages=True,
diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py
index 6da4330bcb..dd44bb872c 100644
--- a/pyrogram/methods/chats/set_chat_photo.py
+++ b/pyrogram/methods/chats/set_chat_photo.py
@@ -68,17 +68,17 @@ async def set_chat_photo(
             .. code-block:: python
 
                 # Set chat photo using a local file
-                app.set_chat_photo(chat_id, photo="photo.jpg")
+                await app.set_chat_photo(chat_id, photo="photo.jpg")
 
                 # Set chat photo using an exiting Photo file_id
-                app.set_chat_photo(chat_id, photo=photo.file_id)
+                await app.set_chat_photo(chat_id, photo=photo.file_id)
 
 
                 # Set chat video using a local file
-                app.set_chat_photo(chat_id, video="video.mp4")
+                await app.set_chat_photo(chat_id, video="video.mp4")
 
                 # Set chat photo using an exiting Video file_id
-                app.set_chat_photo(chat_id, video=video.file_id)
+                await app.set_chat_photo(chat_id, video=video.file_id)
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py
index edebf17624..e2c270e6d2 100644
--- a/pyrogram/methods/chats/set_chat_title.py
+++ b/pyrogram/methods/chats/set_chat_title.py
@@ -52,7 +52,7 @@ async def set_chat_title(
         Example:
             .. code-block:: python
 
-                app.set_chat_title(chat_id, "New Title")
+                await app.set_chat_title(chat_id, "New Title")
         """
         peer = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/chats/set_chat_username.py b/pyrogram/methods/chats/set_chat_username.py
index c1f6d17ddc..2d4bc08a88 100644
--- a/pyrogram/methods/chats/set_chat_username.py
+++ b/pyrogram/methods/chats/set_chat_username.py
@@ -48,7 +48,7 @@ async def set_chat_username(
         Example:
             .. code-block:: python
 
-                app.set_chat_username(chat_id, "new_username")
+                await app.set_chat_username(chat_id, "new_username")
         """
 
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py
index bbe210a41e..4cb50aed0c 100644
--- a/pyrogram/methods/chats/set_send_as_chat.py
+++ b/pyrogram/methods/chats/set_send_as_chat.py
@@ -45,7 +45,7 @@ async def set_send_as_chat(
         Example:
             .. code-block:: python
 
-                app.set_send_as_chat(chat_id, send_as_chat_id)
+                await app.set_send_as_chat(chat_id, send_as_chat_id)
         """
         return await self.invoke(
             raw.functions.messages.SaveDefaultSendAs(
diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py
index e3237ad34f..ca68c87f46 100644
--- a/pyrogram/methods/chats/set_slow_mode.py
+++ b/pyrogram/methods/chats/set_slow_mode.py
@@ -45,10 +45,10 @@ async def set_slow_mode(
             .. code-block:: python
 
                 # Set slow mode to 60 seconds
-                app.set_slow_mode(chat_id, 60)
+                await app.set_slow_mode(chat_id, 60)
 
                 # Disable slow mode
-                app.set_slow_mode(chat_id, None)
+                await app.set_slow_mode(chat_id, None)
         """
 
         await self.invoke(
diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py
index 726eb4a07e..c518fe912c 100644
--- a/pyrogram/methods/chats/unarchive_chats.py
+++ b/pyrogram/methods/chats/unarchive_chats.py
@@ -41,10 +41,10 @@ async def unarchive_chats(
             .. code-block:: python
 
                 # Unarchive chat
-                app.unarchive_chats(chat_id)
+                await app.unarchive_chats(chat_id)
 
                 # Unarchive multiple chats at once
-                app.unarchive_chats([chat_id1, chat_id2, chat_id3])
+                await app.unarchive_chats([chat_id1, chat_id2, chat_id3])
         """
 
         if not isinstance(chat_ids, list):
diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py
index c331e823d4..46c2241e72 100644
--- a/pyrogram/methods/chats/unban_chat_member.py
+++ b/pyrogram/methods/chats/unban_chat_member.py
@@ -47,7 +47,7 @@ async def unban_chat_member(
             .. code-block:: python
 
                 # Unban chat member right now
-                app.unban_chat_member(chat_id, user_id)
+                await app.unban_chat_member(chat_id, user_id)
         """
         await self.invoke(
             raw.functions.channels.EditBanned(
diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py
index 93b6eaec90..866ca7c0b7 100644
--- a/pyrogram/methods/chats/unpin_all_chat_messages.py
+++ b/pyrogram/methods/chats/unpin_all_chat_messages.py
@@ -42,7 +42,7 @@ async def unpin_all_chat_messages(
             .. code-block:: python
 
                 # Unpin all chat messages
-                app.unpin_all_chat_messages(chat_id)
+                await app.unpin_all_chat_messages(chat_id)
         """
         await self.invoke(
             raw.functions.messages.UnpinAllMessages(
diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py
index 6723f5a2a4..5b3768c096 100644
--- a/pyrogram/methods/chats/unpin_chat_message.py
+++ b/pyrogram/methods/chats/unpin_chat_message.py
@@ -46,7 +46,7 @@ async def unpin_chat_message(
         Example:
             .. code-block:: python
 
-                app.unpin_chat_message(chat_id, message_id)
+                await app.unpin_chat_message(chat_id, message_id)
         """
         await self.invoke(
             raw.functions.messages.UpdatePinnedMessage(
diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py
index 433c4c90b6..ae7566b2fd 100644
--- a/pyrogram/methods/contacts/add_contact.py
+++ b/pyrogram/methods/contacts/add_contact.py
@@ -57,8 +57,11 @@ async def add_contact(
         Example:
             .. code-block:: python
 
-                app.add_contact(12345678, "Foo")
-                app.add_contact("username", "Bar")
+                # Add contact by id
+                await app.add_contact(12345678, "Foo")
+
+                # Add contact by username
+                await app.add_contact("username", "Bar")
         """
         r = await self.invoke(
             raw.functions.contacts.AddContact(
diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py
index 03238beb88..31d2bcbec0 100644
--- a/pyrogram/methods/contacts/delete_contacts.py
+++ b/pyrogram/methods/contacts/delete_contacts.py
@@ -42,8 +42,8 @@ async def delete_contacts(
         Example:
             .. code-block:: python
 
-                app.delete_contacts(user_id)
-                app.delete_contacts([user_id1, user_id2, user_id3])
+                await app.delete_contacts(user_id)
+                await app.delete_contacts([user_id1, user_id2, user_id3])
         """
         is_user_ids_list = isinstance(user_ids, list)
 
diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py
index ca8888764b..110d93a321 100644
--- a/pyrogram/methods/contacts/get_contacts.py
+++ b/pyrogram/methods/contacts/get_contacts.py
@@ -38,7 +38,7 @@ async def get_contacts(
         Example:
             .. code-block:: python
 
-                contacts = app.get_contacts()
+                contacts = await app.get_contacts()
                 print(contacts)
         """
         contacts = await self.invoke(raw.functions.contacts.GetContacts(hash=0))
diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py
index d32ae0500f..a709b6769f 100644
--- a/pyrogram/methods/contacts/get_contacts_count.py
+++ b/pyrogram/methods/contacts/get_contacts_count.py
@@ -32,7 +32,7 @@ async def get_contacts_count(
         Example:
             .. code-block:: python
 
-                count = app.get_contacts_count()
+                count = await app.get_contacts_count()
                 print(count)
         """
 
diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py
index de802cff72..11df315be8 100644
--- a/pyrogram/methods/contacts/import_contacts.py
+++ b/pyrogram/methods/contacts/import_contacts.py
@@ -42,7 +42,7 @@ async def import_contacts(
 
                 from pyrogram.types import InputPhoneContact
 
-                app.import_contacts([
+                await app.import_contacts([
                     InputPhoneContact("+1-123-456-7890", "Foo"),
                     InputPhoneContact("+1-456-789-0123", "Bar"),
                     InputPhoneContact("+1-789-012-3456", "Baz")])
diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py
index 0e3e63a751..703d3d1434 100644
--- a/pyrogram/methods/invite_links/create_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/create_chat_invite_link.py
@@ -67,10 +67,10 @@ async def create_chat_invite_link(
             .. code-block:: python
 
                 # Create a new link without limits
-                link = app.create_chat_invite_link(chat_id)
+                link = await app.create_chat_invite_link(chat_id)
 
-                # Create a new link for up to 7 new users
-                link = app.create_chat_invite_link(chat_id, member_limit=7)
+                # Create a new link for up to 3 new users
+                link = await app.create_chat_invite_link(chat_id, member_limit=3)
         """
         r = await self.invoke(
             raw.functions.messages.ExportChatInvite(
diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py
index 96dcf79ddb..29f658ec8a 100644
--- a/pyrogram/methods/invite_links/edit_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py
@@ -69,10 +69,10 @@ async def edit_chat_invite_link(
             .. code-block:: python
 
                 # Edit the member limit of a link
-                link = app.edit_chat_invite_link(chat_id, invite_link, member_limit=9)
+                link = await app.edit_chat_invite_link(chat_id, invite_link, member_limit=5)
 
                 # Set no expiration date of a link
-                link = app.edit_chat_invite_link(chat_id, invite_link, expire_date=0)
+                link = await app.edit_chat_invite_link(chat_id, invite_link, expire_date=0)
         """
         r = await self.invoke(
             raw.functions.messages.EditExportedChatInvite(
diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py
index 66fb0227a4..ae40391fe0 100644
--- a/pyrogram/methods/invite_links/export_chat_invite_link.py
+++ b/pyrogram/methods/invite_links/export_chat_invite_link.py
@@ -51,7 +51,7 @@ async def export_chat_invite_link(
             .. code-block:: python
 
                 # Generate a new primary link
-                link = app.export_chat_invite_link(chat_id)
+                link = await app.export_chat_invite_link(chat_id)
         """
         r = await self.invoke(
             raw.functions.messages.ExportChatInvite(
diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py
index b204999f3e..de47465d27 100644
--- a/pyrogram/methods/messages/copy_media_group.py
+++ b/pyrogram/methods/messages/copy_media_group.py
@@ -76,9 +76,12 @@ async def copy_media_group(
             .. code-block:: python
 
                 # Copy a media group
-                app.copy_media_group("me", source_chat, message_id)
-                app.copy_media_group("me", source_chat, message_id, captions="single caption")
-                app.copy_media_group("me", source_chat, message_id, captions=["caption 1", None, ""])
+                await app.copy_media_group(to_chat, from_chat, 123)
+
+                await app.copy_media_group(to_chat, from_chat, 123, captions="single caption")
+                
+                await app.copy_media_group(to_chat, from_chat, 123,
+                    captions=["caption 1", None, ""])
         """
 
         media_group = await self.get_media_group(from_chat_id, message_id)
diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index 94c11d4b50..b114a9e0af 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -101,7 +101,7 @@ async def copy_message(
             .. code-block:: python
 
                 # Copy a message
-                app.copy_message("me", "pyrogram", 20)
+                await app.copy_message(to_chat, from_chat, 123)
 
         """
         message: types.Message = await self.get_messages(from_chat_id, message_id)
diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py
index f8c3e7feed..b25c0ad4d5 100644
--- a/pyrogram/methods/messages/delete_messages.py
+++ b/pyrogram/methods/messages/delete_messages.py
@@ -54,13 +54,13 @@ async def delete_messages(
             .. code-block:: python
 
                 # Delete one message
-                app.delete_messages(chat_id, message_id)
+                await app.delete_messages(chat_id, message_id)
 
                 # Delete multiple messages at once
-                app.delete_messages(chat_id, list_of_message_ids)
+                await app.delete_messages(chat_id, list_of_message_ids)
 
                 # Delete messages only on your side (without revoking)
-                app.delete_messages(chat_id, message_id, revoke=False)
+                await app.delete_messages(chat_id, message_id, revoke=False)
         """
         peer = await self.resolve_peer(chat_id)
         message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids]
diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py
index d75ba281a0..8b587d2fae 100644
--- a/pyrogram/methods/messages/download_media.py
+++ b/pyrogram/methods/messages/download_media.py
@@ -89,16 +89,16 @@ async def download_media(
             .. code-block:: python
 
                 # Download from Message
-                app.download_media(message)
+                await app.download_media(message)
 
                 # Download from file id
-                app.download_media(message.photo.file_id)
+                await app.download_media(message.photo.file_id)
 
                 # Keep track of the progress while downloading
-                def progress(current, total):
+                async def progress(current, total):
                     print(f"{current * 100 / total:.1f}%")
 
-                app.download_media(message, progress=progress)
+                await app.download_media(message, progress=progress)
         """
         available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note",
                            "new_chat_photo")
diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py
index 3068098ed9..0996d34e68 100644
--- a/pyrogram/methods/messages/edit_inline_caption.py
+++ b/pyrogram/methods/messages/edit_inline_caption.py
@@ -53,7 +53,7 @@ async def edit_inline_caption(
             .. code-block:: python
 
                 # Bots only
-                app.edit_inline_caption(inline_message_id, "new media caption")
+                await app.edit_inline_caption(inline_message_id, "new media caption")
         """
         return await self.edit_inline_text(
             inline_message_id=inline_message_id,
diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py
index 1bf8d4d249..59a18aa7b1 100644
--- a/pyrogram/methods/messages/edit_inline_media.py
+++ b/pyrogram/methods/messages/edit_inline_media.py
@@ -61,13 +61,13 @@ async def edit_inline_media(
                 # Bots only
 
                 # Replace the current media with a local photo
-                app.edit_inline_media(inline_message_id, InputMediaPhoto("new_photo.jpg"))
+                await app.edit_inline_media(inline_message_id, InputMediaPhoto("new_photo.jpg"))
 
                 # Replace the current media with a local video
-                app.edit_inline_media(inline_message_id, InputMediaVideo("new_video.mp4"))
+                await app.edit_inline_media(inline_message_id, InputMediaVideo("new_video.mp4"))
 
                 # Replace the current media with a local audio
-                app.edit_inline_media(inline_message_id, InputMediaAudio("new_audio.mp3"))
+                await app.edit_inline_media(inline_message_id, InputMediaAudio("new_audio.mp3"))
         """
         caption = media.caption
         parse_mode = media.parse_mode
diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py
index 92c6851e4f..4e06e447f7 100644
--- a/pyrogram/methods/messages/edit_inline_reply_markup.py
+++ b/pyrogram/methods/messages/edit_inline_reply_markup.py
@@ -47,7 +47,7 @@ async def edit_inline_reply_markup(
                 from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
 
                 # Bots only
-                app.edit_inline_reply_markup(
+                await app.edit_inline_reply_markup(
                     inline_message_id,
                     InlineKeyboardMarkup([[
                         InlineKeyboardButton("New button", callback_data="new_data")]]))
diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py
index 9a50d8639b..9caee55aaf 100644
--- a/pyrogram/methods/messages/edit_inline_text.py
+++ b/pyrogram/methods/messages/edit_inline_text.py
@@ -62,10 +62,10 @@ async def edit_inline_text(
                 # Bots only
 
                 # Simple edit text
-                app.edit_inline_text(inline_message_id, "new text")
+                await app.edit_inline_text(inline_message_id, "new text")
 
                 # Take the same text message, remove the web page preview only
-                app.edit_inline_text(
+                await app.edit_inline_text(
                     inline_message_id, message.text,
                     disable_web_page_preview=True)
         """
diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py
index fc92b02f1f..d3b311db6e 100644
--- a/pyrogram/methods/messages/edit_message_caption.py
+++ b/pyrogram/methods/messages/edit_message_caption.py
@@ -62,7 +62,7 @@ async def edit_message_caption(
         Example:
             .. code-block:: python
 
-                app.edit_message_caption(chat_id, message_id, "new media caption")
+                await app.edit_message_caption(chat_id, message_id, "new media caption")
         """
         return await self.edit_message_text(
             chat_id=chat_id,
diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py
index 0e3f360c22..3dce81edb9 100644
--- a/pyrogram/methods/messages/edit_message_media.py
+++ b/pyrogram/methods/messages/edit_message_media.py
@@ -69,13 +69,16 @@ async def edit_message_media(
                 from pyrogram.types import InputMediaPhoto, InputMediaVideo, InputMediaAudio
 
                 # Replace the current media with a local photo
-                app.edit_message_media(chat_id, message_id, InputMediaPhoto("new_photo.jpg"))
+                await app.edit_message_media(chat_id, message_id,
+                    InputMediaPhoto("new_photo.jpg"))
 
                 # Replace the current media with a local video
-                app.edit_message_media(chat_id, message_id, InputMediaVideo("new_video.mp4"))
+                await app.edit_message_media(chat_id, message_id,
+                    InputMediaVideo("new_video.mp4"))
 
                 # Replace the current media with a local audio
-                app.edit_message_media(chat_id, message_id, InputMediaAudio("new_audio.mp3"))
+                await app.edit_message_media(chat_id, message_id,
+                    InputMediaAudio("new_audio.mp3"))
         """
         caption = media.caption
         parse_mode = media.parse_mode
diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py
index c164afbf77..088e646ddb 100644
--- a/pyrogram/methods/messages/edit_message_reply_markup.py
+++ b/pyrogram/methods/messages/edit_message_reply_markup.py
@@ -53,7 +53,7 @@ async def edit_message_reply_markup(
                 from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
 
                 # Bots only
-                app.edit_message_reply_markup(
+                await app.edit_message_reply_markup(
                     chat_id, message_id,
                     InlineKeyboardMarkup([[
                         InlineKeyboardButton("New button", callback_data="new_data")]]))
diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py
index 551beaa143..94852de582 100644
--- a/pyrogram/methods/messages/edit_message_text.py
+++ b/pyrogram/methods/messages/edit_message_text.py
@@ -69,10 +69,10 @@ async def edit_message_text(
             .. code-block:: python
 
                 # Simple edit text
-                app.edit_message_text(chat_id, message_id, "new text")
+                await app.edit_message_text(chat_id, message_id, "new text")
 
                 # Take the same text message, remove the web page preview only
-                app.edit_message_text(
+                await app.edit_message_text(
                     chat_id, message_id, message.text,
                     disable_web_page_preview=True)
         """
diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py
index dbc5534e5a..6ee8492294 100644
--- a/pyrogram/methods/messages/forward_messages.py
+++ b/pyrogram/methods/messages/forward_messages.py
@@ -70,10 +70,10 @@ async def forward_messages(
             .. code-block:: python
 
                 # Forward a single message
-                app.forward_messages("me", "pyrogram", 20)
+                await app.forward_messages(to_chat, from_chat, 123)
 
                 # Forward multiple messages at once
-                app.forward_messages("me", "pyrogram", [3, 20, 27])
+                await app.forward_messages(to_chat, from_chat, [1, 2, 3])
         """
 
         is_iterable = not isinstance(message_ids, int)
diff --git a/pyrogram/methods/messages/get_chat_history.py b/pyrogram/methods/messages/get_chat_history.py
index bc2ed41fa7..f21a081f19 100644
--- a/pyrogram/methods/messages/get_chat_history.py
+++ b/pyrogram/methods/messages/get_chat_history.py
@@ -88,7 +88,7 @@ async def get_chat_history(
         Example:
             .. code-block:: python
 
-                for message in app.get_chat_history(chat_id):
+                async for message in app.get_chat_history(chat_id):
                     print(message.text)
         """
         current = 0
diff --git a/pyrogram/methods/messages/get_chat_history_count.py b/pyrogram/methods/messages/get_chat_history_count.py
index fbe6bfcad9..46f61eb056 100644
--- a/pyrogram/methods/messages/get_chat_history_count.py
+++ b/pyrogram/methods/messages/get_chat_history_count.py
@@ -48,7 +48,7 @@ async def get_chat_history_count(
         Example:
             .. code-block:: python
 
-                app.get_history_count(chat_id)
+                await app.get_history_count(chat_id)
         """
 
         r = await self.invoke(
diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py
index cbcc7bfed2..93510e211e 100644
--- a/pyrogram/methods/messages/get_discussion_message.py
+++ b/pyrogram/methods/messages/get_discussion_message.py
@@ -45,10 +45,10 @@ async def get_discussion_message(
             .. code-block:: python
 
                 # Get the discussion message
-                m = app.get_discussion_message(channel_id, message_id)
+                m = await app.get_discussion_message(channel_id, message_id)
 
                 # Comment to the post by replying
-                m.reply("comment")
+                await m.reply("comment")
         """
         r = await self.invoke(
             raw.functions.messages.GetDiscussionMessage(
diff --git a/pyrogram/methods/messages/get_discussion_replies.py b/pyrogram/methods/messages/get_discussion_replies.py
index b1279de542..467cca8d2b 100644
--- a/pyrogram/methods/messages/get_discussion_replies.py
+++ b/pyrogram/methods/messages/get_discussion_replies.py
@@ -45,8 +45,8 @@ async def get_discussion_replies(
         Example:
             .. code-block:: python
 
-            for m in app.get_discussion_replies(chat_id, message_id):
-                print(m)
+                async for message in app.get_discussion_replies(chat_id, message_id):
+                    print(message)
         """
 
         current = 0
diff --git a/pyrogram/methods/messages/get_discussion_replies_count.py b/pyrogram/methods/messages/get_discussion_replies_count.py
index cb5c1e8ba3..260be802eb 100644
--- a/pyrogram/methods/messages/get_discussion_replies_count.py
+++ b/pyrogram/methods/messages/get_discussion_replies_count.py
@@ -40,7 +40,7 @@ async def get_discussion_replies_count(
         Example:
             .. code-block:: python
 
-            count = app.get_discussion_replies_count(chat_id, message_id)
+                count = await app.get_discussion_replies_count(chat_id, message_id)
         """
 
         r = await self.invoke(
diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py
index a6a361af8c..8db24dd955 100644
--- a/pyrogram/methods/messages/get_messages.py
+++ b/pyrogram/methods/messages/get_messages.py
@@ -71,19 +71,19 @@ async def get_messages(
             .. code-block:: python
 
                 # Get one message
-                app.get_messages(chat_id, 12345)
+                await app.get_messages(chat_id, 12345)
 
                 # Get more than one message (list of messages)
-                app.get_messages(chat_id, [12345, 12346])
+                await app.get_messages(chat_id, [12345, 12346])
 
                 # Get message by ignoring any replied-to message
-                app.get_messages(chat_id, message_id, replies=0)
+                await app.get_messages(chat_id, message_id, replies=0)
 
                 # Get message with all chained replied-to messages
-                app.get_messages(chat_id, message_id, replies=-1)
+                await app.get_messages(chat_id, message_id, replies=-1)
 
                 # Get the replied-to message of a message
-                app.get_messages(chat_id, reply_to_message_ids=message_id)
+                await app.get_messages(chat_id, reply_to_message_ids=message_id)
 
         Raises:
             ValueError: In case of invalid arguments.
diff --git a/pyrogram/methods/messages/read_chat_history.py b/pyrogram/methods/messages/read_chat_history.py
index caa228fd28..8a58fa264c 100644
--- a/pyrogram/methods/messages/read_chat_history.py
+++ b/pyrogram/methods/messages/read_chat_history.py
@@ -47,10 +47,10 @@ async def read_chat_history(
             .. code-block:: python
 
                 # Mark the whole chat as read
-                app.read_history(chat_id)
+                await app.read_history(chat_id)
 
                 # Mark messages as read only up to the given message id
-                app.read_history(chat_id, 123456)
+                await app.read_history(chat_id, 12345)
         """
 
         peer = await self.resolve_peer(chat_id)
diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py
index 8aab69f016..8420a4a318 100644
--- a/pyrogram/methods/messages/retract_vote.py
+++ b/pyrogram/methods/messages/retract_vote.py
@@ -46,7 +46,7 @@ async def retract_vote(
         Example:
             .. code-block:: python
 
-                app.retract_vote(chat_id, message_id)
+                await app.retract_vote(chat_id, message_id)
         """
         r = await self.invoke(
             raw.functions.messages.SendVote(
diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py
index b53dbf3218..1a65702e01 100644
--- a/pyrogram/methods/messages/search_global.py
+++ b/pyrogram/methods/messages/search_global.py
@@ -59,12 +59,14 @@ async def search_global(
         Example:
             .. code-block:: python
 
+                from pyrogram import enums
+
                 # Search for "pyrogram". Get the first 50 results
-                for message in app.search_global("pyrogram", limit=50):
+                async for message in app.search_global("pyrogram", limit=50):
                     print(message.text)
 
                 # Search for recent photos from Global. Get the first 20 results
-                for message in app.search_global(filter="photo", limit=20):
+                async for message in app.search_global(filter=enums.MessagesFilter.PHOTO, limit=20):
                     print(message.photo)
         """
         current = 0
diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py
index 0e31871c6c..1f9fa3c76e 100644
--- a/pyrogram/methods/messages/search_messages.py
+++ b/pyrogram/methods/messages/search_messages.py
@@ -108,15 +108,15 @@ async def search_messages(
                 from pyrogram import enums
 
                 # Search for text messages in chat. Get the last 120 results
-                for message in app.search_messages(chat_id, query="hello", limit=120):
+                async for message in app.search_messages(chat_id, query="hello", limit=120):
                     print(message.text)
 
                 # Search for pinned messages in chat
-                for message in app.search_messages(chat_id, filter=enums.MessagesFilter.PINNED):
+                async for message in app.search_messages(chat_id, filter=enums.MessagesFilter.PINNED):
                     print(message.text)
 
                 # Search for messages containing "hello" sent by yourself in chat
-                for message in app.search_messages(chat, "hello", from_user="me"):
+                async for message in app.search_messages(chat, "hello", from_user="me"):
                     print(message.text)
         """
 
diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py
index e45a071462..efa9cb1671 100644
--- a/pyrogram/methods/messages/send_animation.py
+++ b/pyrogram/methods/messages/send_animation.py
@@ -153,19 +153,19 @@ async def send_animation(
             .. code-block:: python
 
                 # Send animation by uploading from local file
-                app.send_animation("me", "animation.gif")
+                await app.send_animation("me", "animation.gif")
 
                 # Add caption to the animation
-                app.send_animation("me", "animation.gif", caption="animation caption")
+                await app.send_animation("me", "animation.gif", caption="animation caption")
 
                 # Unsave the animation once is sent
-                app.send_animation("me", "animation.gif", unsave=True)
+                await app.send_animation("me", "animation.gif", unsave=True)
 
                 # Keep track of the progress while uploading
-                def progress(current, total):
+                async def progress(current, total):
                     print(f"{current * 100 / total:.1f}%")
 
-                app.send_animation("me", "animation.gif", progress=progress)
+                await app.send_animation("me", "animation.gif", progress=progress)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py
index 8c2624a8d8..f4552832fe 100644
--- a/pyrogram/methods/messages/send_audio.py
+++ b/pyrogram/methods/messages/send_audio.py
@@ -149,21 +149,21 @@ async def send_audio(
             .. code-block:: python
 
                 # Send audio file by uploading from file
-                app.send_audio("me", "audio.mp3")
+                await app.send_audio("me", "audio.mp3")
 
                 # Add caption to the audio
-                app.send_audio("me", "audio.mp3", caption="audio caption")
+                await app.send_audio("me", "audio.mp3", caption="audio caption")
 
                 # Set audio metadata
-                app.send_audio(
+                await app.send_audio(
                     "me", "audio.mp3",
                     title="Title", performer="Performer", duration=234)
 
                 # Keep track of the progress while uploading
-                def progress(current, total):
+                async def progress(current, total):
                     print(f"{current * 100 / total:.1f}%")
 
-                app.send_audio("me", "audio.mp3", progress=progress)
+                await app.send_audio("me", "audio.mp3", progress=progress)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py
index 88a5f30921..f0e04d7232 100644
--- a/pyrogram/methods/messages/send_cached_media.py
+++ b/pyrogram/methods/messages/send_cached_media.py
@@ -93,7 +93,7 @@ async def send_cached_media(
         Example:
             .. code-block:: python
 
-                app.send_cached_media("me", file_id)
+                await app.send_cached_media("me", file_id)
         """
 
         r = await self.invoke(
diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py
index 39f8d85f86..15b5ac0853 100644
--- a/pyrogram/methods/messages/send_chat_action.py
+++ b/pyrogram/methods/messages/send_chat_action.py
@@ -19,14 +19,14 @@
 from typing import Union
 
 import pyrogram
-from pyrogram import raw
+from pyrogram import raw, enums
 
 
 class SendChatAction:
     async def send_chat_action(
         self: "pyrogram.Client",
         chat_id: Union[int, str],
-        action: "pyrogram.enums.ChatAction"
+        action: "enums.ChatAction"
     ) -> bool:
         """Tell the other party that something is happening on your side.
 
@@ -51,16 +51,16 @@ async def send_chat_action(
                 from pyrogram import enums
 
                 # Send "typing" chat action
-                app.send_chat_action(chat_id, enums.ChatAction.TYPING)
+                await app.send_chat_action(chat_id, enums.ChatAction.TYPING)
 
                 # Send "upload_video" chat action
-                app.send_chat_action(chat_id, enums.ChatAction.UPLOAD_VIDEO)
+                await app.send_chat_action(chat_id, enums.ChatAction.UPLOAD_VIDEO)
 
                 # Send "playing" chat action
-                app.send_chat_action(chat_id, enums.ChatAction.PLAYING)
+                await app.send_chat_action(chat_id, enums.ChatAction.PLAYING)
 
                 # Cancel any current chat action
-                app.send_chat_action(chat_id, enums.ChatAction.CANCEL)
+                await app.send_chat_action(chat_id, enums.ChatAction.CANCEL)
         """
 
         action_name = action.name.lower()
diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py
index b4683338d5..cedcd0b25b 100644
--- a/pyrogram/methods/messages/send_contact.py
+++ b/pyrogram/methods/messages/send_contact.py
@@ -86,7 +86,7 @@ async def send_contact(
         Example:
             .. code-block:: python
 
-                app.send_contact("me", "+1-123-456-7890", "Name")
+                await app.send_contact("me", "+1-123-456-7890", "Name")
         """
         r = await self.invoke(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py
index b15cfe2d0b..942f681ff0 100644
--- a/pyrogram/methods/messages/send_dice.py
+++ b/pyrogram/methods/messages/send_dice.py
@@ -79,13 +79,13 @@ async def send_dice(
             .. code-block:: python
 
                 # Send a dice
-                app.send_dice(chat_id)
+                await app.send_dice(chat_id)
 
                 # Send a dart
-                app.send_dice(chat_id, "🎯")
+                await app.send_dice(chat_id, "🎯")
 
                 # Send a basketball
-                app.send_dice(chat_id, "🏀")
+                await app.send_dice(chat_id, "🏀")
         """
 
         r = await self.invoke(
diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py
index c1179cb0e2..99c90fbb25 100644
--- a/pyrogram/methods/messages/send_document.py
+++ b/pyrogram/methods/messages/send_document.py
@@ -141,16 +141,16 @@ async def send_document(
             .. code-block:: python
 
                 # Send document by uploading from local file
-                app.send_document("me", "document.zip")
+                await app.send_document("me", "document.zip")
 
                 # Add caption to the document file
-                app.send_document("me", "document.zip", caption="document caption")
+                await app.send_document("me", "document.zip", caption="document caption")
 
                 # Keep track of the progress while uploading
-                def progress(current, total):
+                async def progress(current, total):
                     print(f"{current * 100 / total:.1f}%")
 
-                app.send_document("me", "document.zip", progress=progress)
+                await app.send_document("me", "document.zip", progress=progress)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py
index 1364543b43..fe7d1ed16d 100644
--- a/pyrogram/methods/messages/send_location.py
+++ b/pyrogram/methods/messages/send_location.py
@@ -78,7 +78,7 @@ async def send_location(
         Example:
             .. code-block:: python
 
-                app.send_location("me", 51.500729, -0.124583)
+                app.send_location("me", latitude, longitude)
         """
         r = await self.invoke(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py
index 382b2a92a0..43eb9d7c2b 100644
--- a/pyrogram/methods/messages/send_media_group.py
+++ b/pyrogram/methods/messages/send_media_group.py
@@ -79,7 +79,7 @@ async def send_media_group(
 
                 from pyrogram.types import InputMediaPhoto, InputMediaVideo
 
-                app.send_media_group(
+                await app.send_media_group(
                     "me",
                     [
                         InputMediaPhoto("photo1.jpg"),
diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 414f744764..0a7ab6d102 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -88,31 +88,29 @@ async def send_message(
             .. code-block:: python
 
                 # Simple example
-                app.send_message("me", "Message sent with **Pyrogram**!")
+                await app.send_message("me", "Message sent with **Pyrogram**!")
 
                 # Disable web page previews
-                app.send_message("me", "https://docs.pyrogram.org", disable_web_page_preview=True)
+                await app.send_message("me", "https://docs.pyrogram.org",
+                    disable_web_page_preview=True)
 
                 # Reply to a message using its id
-                app.send_message("me", "this is a reply", reply_to_message_id=12345)
+                await app.send_message("me", "this is a reply", reply_to_message_id=123)
 
-                # Force HTML-only styles for this request only
-                app.send_message("me", "**not bold**, italic", parse_mode="html")
+            .. code-block:: python
 
-                ##
                 # For bots only, send messages with keyboards attached
-                ##
 
                 from pyrogram.types import (
                     ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton)
 
                 # Send a normal keyboard
-                app.send_message(
+                await app.send_message(
                     chat_id, "Look at that button!",
                     reply_markup=ReplyKeyboardMarkup([["Nice!"]]))
 
                 # Send an inline keyboard
-                app.send_message(
+                await app.send_message(
                     chat_id, "These are inline buttons",
                     reply_markup=InlineKeyboardMarkup(
                         [
diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py
index 5391b2f660..85d6fe4b7c 100644
--- a/pyrogram/methods/messages/send_photo.py
+++ b/pyrogram/methods/messages/send_photo.py
@@ -128,16 +128,16 @@ async def send_photo(
             .. code-block:: python
 
                 # Send photo by uploading from local file
-                app.send_photo("me", "photo.jpg")
+                await app.send_photo("me", "photo.jpg")
 
                 # Send photo by uploading from URL
-                app.send_photo("me", "https://i.imgur.com/BQBTP7d.png")
+                await app.send_photo("me", "https://example.com/example.jpg)
 
                 # Add caption to a photo
-                app.send_photo("me", "photo.jpg", caption="Holidays!")
+                await app.send_photo("me", "photo.jpg", caption="Caption")
 
                 # Send self-destructing photo
-                app.send_photo("me", "photo.jpg", ttl_seconds=10)
+                await app.send_photo("me", "photo.jpg", ttl_seconds=10)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index 0dd877b9e4..1305d2d680 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -98,7 +98,7 @@ async def send_poll(
         Example:
             .. code-block:: python
 
-                app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"])
+                await app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"])
         """
         r = await self.invoke(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py
index 34c2d92c0a..7f597cb626 100644
--- a/pyrogram/methods/messages/send_reaction.py
+++ b/pyrogram/methods/messages/send_reaction.py
@@ -49,10 +49,10 @@ async def send_reaction(
             .. code-block:: python
 
                 # Send a reaction
-                app.send_reaction(chat_id, message_id, "🔥")
+                await app.send_reaction(chat_id, message_id, "🔥")
 
                 # Retract a reaction
-                app.send_reaction(chat_id, message_id)
+                await app.send_reaction(chat_id, message_id)
         """
         await self.invoke(
             raw.functions.messages.SendReaction(
diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py
index d0b66fb10b..2fc4565cb5 100644
--- a/pyrogram/methods/messages/send_sticker.py
+++ b/pyrogram/methods/messages/send_sticker.py
@@ -111,10 +111,10 @@ async def send_sticker(
             .. code-block:: python
 
                 # Send sticker by uploading from local file
-                app.send_sticker("me", "sticker.webp")
+                await app.send_sticker("me", "sticker.webp")
 
                 # Send sticker using file_id
-                app.send_sticker("me", file_id)
+                await app.send_sticker("me", file_id)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py
index 7ddb98efdc..e8cc760b30 100644
--- a/pyrogram/methods/messages/send_venue.py
+++ b/pyrogram/methods/messages/send_venue.py
@@ -96,8 +96,8 @@ async def send_venue(
             .. code-block:: python
 
                 app.send_venue(
-                    "me", 51.500729, -0.124583,
-                    "Elizabeth Tower", "Westminster, London SW1A 0AA, UK")
+                    "me", latitude, longitude,
+                    "Venue title", "Venue address")
         """
         r = await self.invoke(
             raw.functions.messages.SendMedia(
diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py
index 49674076bc..299f1b477c 100644
--- a/pyrogram/methods/messages/send_video.py
+++ b/pyrogram/methods/messages/send_video.py
@@ -158,19 +158,19 @@ async def send_video(
             .. code-block:: python
 
                 # Send video by uploading from local file
-                app.send_video("me", "video.mp4")
+                await app.send_video("me", "video.mp4")
 
                 # Add caption to the video
-                app.send_video("me", "video.mp4", caption="video caption")
+                await app.send_video("me", "video.mp4", caption="video caption")
 
                 # Send self-destructing video
-                app.send_video("me", "video.mp4", ttl_seconds=10)
+                await app.send_video("me", "video.mp4", ttl_seconds=10)
 
                 # Keep track of the progress while uploading
-                def progress(current, total):
+                async def progress(current, total):
                     print(f"{current * 100 / total:.1f}%")
 
-                app.send_video("me", "video.mp4", progress=progress)
+                await app.send_video("me", "video.mp4", progress=progress)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py
index ce6240d9d5..bf33cdb724 100644
--- a/pyrogram/methods/messages/send_video_note.py
+++ b/pyrogram/methods/messages/send_video_note.py
@@ -125,10 +125,10 @@ async def send_video_note(
             .. code-block:: python
 
                 # Send video note by uploading from local file
-                app.send_video_note("me", "video_note.mp4")
+                await app.send_video_note("me", "video_note.mp4")
 
                 # Set video note length
-                app.send_video_note("me", "video_note.mp4", length=25)
+                await app.send_video_note("me", "video_note.mp4", length=25)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py
index 9bc6456519..5947ecc23d 100644
--- a/pyrogram/methods/messages/send_voice.py
+++ b/pyrogram/methods/messages/send_voice.py
@@ -127,13 +127,13 @@ async def send_voice(
             .. code-block:: python
 
                 # Send voice note by uploading from local file
-                app.send_voice("me", "voice.ogg")
+                await app.send_voice("me", "voice.ogg")
 
                 # Add caption to the voice note
-                app.send_voice("me", "voice.ogg", caption="voice caption")
+                await app.send_voice("me", "voice.ogg", caption="voice caption")
 
                 # Set voice note duration
-                app.send_voice("me", "voice.ogg", duration=20)
+                await app.send_voice("me", "voice.ogg", duration=20)
         """
         file = None
 
diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py
index e642e1b666..6104403f5c 100644
--- a/pyrogram/methods/messages/stop_poll.py
+++ b/pyrogram/methods/messages/stop_poll.py
@@ -52,7 +52,7 @@ async def stop_poll(
         Example:
             .. code-block:: python
 
-                app.stop_poll(chat_id, message_id)
+                await app.stop_poll(chat_id, message_id)
         """
         poll = (await self.get_messages(chat_id, message_id)).poll
 
diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py
index 3fea2e22b9..72a912deae 100644
--- a/pyrogram/methods/messages/vote_poll.py
+++ b/pyrogram/methods/messages/vote_poll.py
@@ -50,7 +50,7 @@ async def vote_poll(
         Example:
             .. code-block:: python
 
-                app.vote_poll(chat_id, message_id, 6)
+                await app.vote_poll(chat_id, message_id, 6)
         """
 
         poll = (await self.get_messages(chat_id, message_id)).poll
diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py
index 3f7dee0017..c5e8bd27c7 100644
--- a/pyrogram/methods/password/change_cloud_password.py
+++ b/pyrogram/methods/password/change_cloud_password.py
@@ -52,10 +52,10 @@ async def change_cloud_password(
             .. code-block:: python
 
                 # Change password only
-                app.change_cloud_password("current_password", "new_password")
+                await app.change_cloud_password("current_password", "new_password")
 
                 # Change password and hint
-                app.change_cloud_password("current_password", "new_password", new_hint="hint")
+                await app.change_cloud_password("current_password", "new_password", new_hint="hint")
         """
         r = await self.invoke(raw.functions.account.GetPassword())
 
diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py
index fd8b3dbfd1..a6533dbf70 100644
--- a/pyrogram/methods/password/enable_cloud_password.py
+++ b/pyrogram/methods/password/enable_cloud_password.py
@@ -54,13 +54,13 @@ async def enable_cloud_password(
             .. code-block:: python
 
                 # Enable password without hint and email
-                app.enable_cloud_password("password")
+                await app.enable_cloud_password("password")
 
                 # Enable password with hint and without email
-                app.enable_cloud_password("password", hint="hint")
+                await app.enable_cloud_password("password", hint="hint")
 
                 # Enable password with hint and email
-                app.enable_cloud_password("password", hint="hint", email="user@email.com")
+                await app.enable_cloud_password("password", hint="hint", email="user@email.com")
         """
         r = await self.invoke(raw.functions.account.GetPassword())
 
diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py
index 845547d67c..dab37d8635 100644
--- a/pyrogram/methods/password/remove_cloud_password.py
+++ b/pyrogram/methods/password/remove_cloud_password.py
@@ -41,7 +41,7 @@ async def remove_cloud_password(
         Example:
             .. code-block:: python
 
-                app.remove_cloud_password("password")
+                await app.remove_cloud_password("password")
         """
         r = await self.invoke(raw.functions.account.GetPassword())
 
diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py
index 3298e60190..f14479558e 100644
--- a/pyrogram/methods/users/block_user.py
+++ b/pyrogram/methods/users/block_user.py
@@ -41,7 +41,7 @@ async def block_user(
         Example:
             .. code-block:: python
 
-                app.block_user(user_id)
+                await app.block_user(user_id)
         """
         return bool(
             await self.invoke(
diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py
index 107f11a6a3..e7205661eb 100644
--- a/pyrogram/methods/users/delete_profile_photos.py
+++ b/pyrogram/methods/users/delete_profile_photos.py
@@ -43,13 +43,13 @@ async def delete_profile_photos(
             .. code-block:: python
 
                 # Get the photos to be deleted
-                photos = app.get_profile_photos("me")
+                photos = await app.get_profile_photos("me")
 
                 # Delete one photo
-                app.delete_profile_photos(photos[0].file_id)
+                await app.delete_profile_photos(photos[0].file_id)
 
                 # Delete the rest of the photos
-                app.delete_profile_photos([p.file_id for p in photos[1:]])
+                await app.delete_profile_photos([p.file_id for p in photos[1:]])
         """
         photo_ids = photo_ids if isinstance(photo_ids, list) else [photo_ids]
         input_photos = [utils.get_input_media_from_file_id(i, FileType.PHOTO).id for i in photo_ids]
diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py
index 6c7d5ce786..7269a81ed7 100644
--- a/pyrogram/methods/users/get_common_chats.py
+++ b/pyrogram/methods/users/get_common_chats.py
@@ -45,7 +45,7 @@ async def get_common_chats(
         Example:
             .. code-block:: python
 
-                common = app.get_common_chats(user_id)
+                common = await app.get_common_chats(user_id)
                 print(common)
         """
 
diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py
index 2869f85c8c..610a11af53 100644
--- a/pyrogram/methods/users/get_me.py
+++ b/pyrogram/methods/users/get_me.py
@@ -33,7 +33,7 @@ async def get_me(
         Example:
             .. code-block:: python
 
-                me = app.get_me()
+                me = await app.get_me()
                 print(me)
         """
         r = await self.invoke(
diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_profile_photos.py
index ec35aa9eb1..ba20c89ce1 100644
--- a/pyrogram/methods/users/get_profile_photos.py
+++ b/pyrogram/methods/users/get_profile_photos.py
@@ -54,13 +54,13 @@ async def get_profile_photos(
             .. code-block:: python
 
                 # Get the first 100 profile photos of a user
-                app.get_profile_photos("me")
+                await app.get_profile_photos("me")
 
                 # Get only the first profile photo of a user
-                app.get_profile_photos("me", limit=1)
+                await app.get_profile_photos("me", limit=1)
 
                 # Get 3 profile photos of a user, skip the first 5
-                app.get_profile_photos("me", limit=3, offset=5)
+                await app.get_profile_photos("me", limit=3, offset=5)
         """
         peer_id = await self.resolve_peer(chat_id)
 
diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_profile_photos_count.py
index 41e50f5e8a..4c0fe5d5f0 100644
--- a/pyrogram/methods/users/get_profile_photos_count.py
+++ b/pyrogram/methods/users/get_profile_photos_count.py
@@ -41,7 +41,7 @@ async def get_profile_photos_count(
         Example:
             .. code-block:: python
 
-                count = app.get_profile_photos_count("me")
+                count = await app.get_profile_photos_count("me")
                 print(count)
         """
 
diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py
index 6f085c4f51..caef79663f 100644
--- a/pyrogram/methods/users/get_users.py
+++ b/pyrogram/methods/users/get_users.py
@@ -47,10 +47,10 @@ async def get_users(
             .. code-block:: python
 
                 # Get information about one user
-                app.get_users("me")
+                await app.get_users("me")
 
                 # Get information about multiple users at once
-                app.get_users([user1, user2, user3])
+                await app.get_users([user_id1, user_id2, user_id3])
         """
         is_iterable = not isinstance(user_ids, (int, str))
         user_ids = list(user_ids) if is_iterable else [user_ids]
diff --git a/pyrogram/methods/users/iter_profile_photos.py b/pyrogram/methods/users/iter_profile_photos.py
index 88c02c3a54..6665bc9bda 100644
--- a/pyrogram/methods/users/iter_profile_photos.py
+++ b/pyrogram/methods/users/iter_profile_photos.py
@@ -54,8 +54,8 @@ async def iter_profile_photos(
         Example:
             .. code-block:: python
 
-                for photo in app.iter_profile_photos("me"):
-                    print(photo.file_id)
+                async for photo in app.iter_profile_photos("me"):
+                    print(photo)
         """
         current = 0
         total = limit or (1 << 31)
diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py
index a7d59092b3..86aaf31f6d 100644
--- a/pyrogram/methods/users/set_profile_photo.py
+++ b/pyrogram/methods/users/set_profile_photo.py
@@ -57,10 +57,10 @@ async def set_profile_photo(
             .. code-block:: python
 
                 # Set a new profile photo
-                app.set_profile_photo(photo="new_photo.jpg")
+                await app.set_profile_photo(photo="new_photo.jpg")
 
                 # Set a new profile video
-                app.set_profile_photo(video="new_video.mp4")
+                await app.set_profile_photo(video="new_video.mp4")
         """
 
         return bool(
diff --git a/pyrogram/methods/users/set_username.py b/pyrogram/methods/users/set_username.py
index 68e443f149..6f070bc5f2 100644
--- a/pyrogram/methods/users/set_username.py
+++ b/pyrogram/methods/users/set_username.py
@@ -43,7 +43,7 @@ async def set_username(
         Example:
             .. code-block:: python
 
-                app.set_username("new_username")
+                await app.set_username("new_username")
         """
 
         return bool(
diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py
index 7593065862..4809aa6ba6 100644
--- a/pyrogram/methods/users/unblock_user.py
+++ b/pyrogram/methods/users/unblock_user.py
@@ -41,7 +41,7 @@ async def unblock_user(
         Example:
             .. code-block:: python
 
-                app.unblock_user(user_id)
+                await app.unblock_user(user_id)
         """
         return bool(
             await self.invoke(
diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py
index 779aa6cf5c..31f12508f5 100644
--- a/pyrogram/methods/users/update_profile.py
+++ b/pyrogram/methods/users/update_profile.py
@@ -50,13 +50,13 @@ async def update_profile(
             .. code-block:: python
 
                 # Update your first name only
-                app.update_profile(first_name="Pyrogram")
+                await app.update_profile(first_name="Pyrogram")
 
                 # Update first name and bio
-                app.update_profile(first_name="Pyrogram", bio="https://docs.pyrogram.org/")
+                await app.update_profile(first_name="Pyrogram", bio="https://docs.pyrogram.org/")
 
                 # Remove the last name
-                app.update_profile(last_name="")
+                await app.update_profile(last_name="")
         """
 
         return bool(
diff --git a/pyrogram/methods/utilities/add_handler.py b/pyrogram/methods/utilities/add_handler.py
index 12b41bfe60..136647d981 100644
--- a/pyrogram/methods/utilities/add_handler.py
+++ b/pyrogram/methods/utilities/add_handler.py
@@ -50,12 +50,12 @@ def add_handler(
                 from pyrogram import Client
                 from pyrogram.handlers import MessageHandler
 
-                def dump(client, message):
+                async def hello(client, message):
                     print(message)
 
                 app = Client("my_account")
 
-                app.add_handler(MessageHandler(dump))
+                app.add_handler(MessageHandler(hello))
 
                 app.run()
         """
diff --git a/pyrogram/methods/utilities/export_session_string.py b/pyrogram/methods/utilities/export_session_string.py
index 8177c456a9..6529484d9b 100644
--- a/pyrogram/methods/utilities/export_session_string.py
+++ b/pyrogram/methods/utilities/export_session_string.py
@@ -35,11 +35,6 @@ async def export_session_string(
         Example:
             .. code-block:: python
 
-                from pyrogram import Client
-
-                app = Client("my_account")
-
-                with app:
-                    print(app.export_session_string())
+                s = await app.export_session_string()
         """
         return await self.storage.export_session_string()
diff --git a/pyrogram/methods/utilities/idle.py b/pyrogram/methods/utilities/idle.py
index c708d6f1fb..bcd685e08d 100644
--- a/pyrogram/methods/utilities/idle.py
+++ b/pyrogram/methods/utilities/idle.py
@@ -41,33 +41,35 @@ async def idle():
     It is useful for event-driven application only, that are, applications which react upon incoming Telegram
     updates through handlers, rather than executing a set of methods sequentially.
 
-    The way Pyrogram works, it will keep your handlers in a pool of worker threads, which are executed concurrently
-    outside the main thread; calling idle() will ensure the client(s) will be kept alive by not letting the main
-    script to end, until you decide to quit.
-
     Once a signal is received (e.g.: from CTRL+C) the function will terminate and your main script will continue.
     Don't forget to call :meth:`~pyrogram.Client.stop` for each running client before the script ends.
 
     Example:
         .. code-block:: python
 
+            import asyncio
             from pyrogram import Client, idle
 
-            app1 = Client("account1")
-            app2 = Client("account2")
-            app3 = Client("account3")
 
-            ...  # Set handlers up
+            async def main():
+                apps = [
+                    Client("account1"),
+                    Client("account2"),
+                    Client("account3")
+                ]
+
+                ...  # Set up handlers
+
+                for app in apps:
+                    await app.start()
+
+                await idle()
 
-            app1.start()
-            app2.start()
-            app3.start()
+                for app in apps:
+                    await app.stop()
 
-            idle()
 
-            app1.stop()
-            app2.stop()
-            app3.stop()
+            asyncio.run(main())
     """
     global is_idling
 
diff --git a/pyrogram/methods/utilities/remove_handler.py b/pyrogram/methods/utilities/remove_handler.py
index fca4a879a9..9f1c974e69 100644
--- a/pyrogram/methods/utilities/remove_handler.py
+++ b/pyrogram/methods/utilities/remove_handler.py
@@ -45,12 +45,12 @@ def remove_handler(
                 from pyrogram import Client
                 from pyrogram.handlers import MessageHandler
 
-                def dump(client, message):
+                async def hello(client, message):
                     print(message)
 
                 app = Client("my_account")
 
-                handler = app.add_handler(MessageHandler(dump))
+                handler = app.add_handler(MessageHandler(hello))
 
                 # Starred expression to unpack (handler, group)
                 app.remove_handler(*handler)
diff --git a/pyrogram/methods/utilities/restart.py b/pyrogram/methods/utilities/restart.py
index 66c246085f..44fd6745ef 100644
--- a/pyrogram/methods/utilities/restart.py
+++ b/pyrogram/methods/utilities/restart.py
@@ -32,7 +32,7 @@ async def restart(
         Parameters:
             block (``bool``, *optional*):
                 Blocks the code execution until the client has been restarted. It is useful with ``block=False`` in case
-                you want to restart the own client *within* an handler in order not to cause a deadlock.
+                you want to restart the own client within an handler in order not to cause a deadlock.
                 Defaults to True.
 
         Returns:
@@ -47,15 +47,17 @@ async def restart(
                 from pyrogram import Client
 
                 app = Client("my_account")
-                app.start()
 
-                ...  # Call API methods
 
-                app.restart()
+                async def main():
+                    await app.start()
+                    ...  # Invoke API methods
+                    await app.restart()
+                    ...  # Invoke other API methods
+                    await app.stop()
 
-                ...  # Call other API methods
 
-                app.stop()
+                app.run(main())
         """
 
         async def do_it():
diff --git a/pyrogram/methods/utilities/run.py b/pyrogram/methods/utilities/run.py
index 6247b936c9..e3890355a9 100644
--- a/pyrogram/methods/utilities/run.py
+++ b/pyrogram/methods/utilities/run.py
@@ -30,8 +30,17 @@ def run(
     ):
         """Start the client, idle the main script and finally stop the client.
 
-        This is a convenience method that calls :meth:`~pyrogram.Client.start`, :meth:`~pyrogram.idle` and
-        :meth:`~pyrogram.Client.stop` in sequence. It makes running a single client less verbose.
+        When calling this method without any argument it acts as a convenience method that calls
+        :meth:`~pyrogram.Client.start`, :meth:`~pyrogram.idle` and :meth:`~pyrogram.Client.stop` in sequence.
+        It makes running a single client less verbose.
+
+        In case a coroutine is passed as argument, runs the coroutine until it's completed and doesn't do any client
+        operation. This is almost the same as :py:obj:`asyncio.run` except for the fact that Pyrogram's ``run`` uses the
+        current event loop instead of a new one.
+
+        Parameters:
+            coroutine (``Coroutine``, *optional*):
+                Pass a coroutine to run it until it completes.
 
         Raises:
             ConnectionError: In case you try to run an already started client.
@@ -42,10 +51,22 @@ def run(
                 from pyrogram import Client
 
                 app = Client("my_account")
-
                 ...  # Set handlers up
-
                 app.run()
+
+            .. code-block:: python
+
+                from pyrogram import Client
+
+                app = Client("my_account")
+
+
+                async def main():
+                    async with app:
+                        print(await app.get_me())
+
+
+                app.run(main())
         """
         loop = asyncio.get_event_loop()
         run = loop.run_until_complete
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index ab4aef823d..bf5468fbe6 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -30,7 +30,7 @@ async def start(
     ):
         """Start the client.
 
-        This method connects the client to Telegram and, in case of new sessions, automatically manages the full
+        This method connects the client to Telegram and, in case of new sessions, automatically manages the
         authorization process using an interactive prompt.
 
         Returns:
@@ -45,11 +45,15 @@ async def start(
                 from pyrogram import Client
 
                 app = Client("my_account")
-                app.start()
 
-                ...  # Call API methods
 
-                app.stop()
+                async def main():
+                    await app.start()
+                    ...  # Invoke API methods
+                    await app.stop()
+
+
+                app.run(main())
         """
         is_authorized = await self.connect()
 
diff --git a/pyrogram/methods/utilities/stop.py b/pyrogram/methods/utilities/stop.py
index 92b99fc5f3..1b28add046 100644
--- a/pyrogram/methods/utilities/stop.py
+++ b/pyrogram/methods/utilities/stop.py
@@ -46,11 +46,15 @@ async def stop(
                 from pyrogram import Client
 
                 app = Client("my_account")
-                app.start()
 
-                ...  # Call API methods
 
-                app.stop()
+                async def main():
+                    await app.start()
+                    ...  # Invoke API methods
+                    await app.stop()
+
+
+                app.run(main())
         """
 
         async def do_it():
diff --git a/pyrogram/methods/utilities/stop_transmission.py b/pyrogram/methods/utilities/stop_transmission.py
index 0639eab8f3..da64569523 100644
--- a/pyrogram/methods/utilities/stop_transmission.py
+++ b/pyrogram/methods/utilities/stop_transmission.py
@@ -29,17 +29,15 @@ def stop_transmission(self):
         Example:
             .. code-block:: python
 
-                from pyrogram import Client
-
-                app = Client("my_account")
-
-                # Example to stop transmission once the upload progress reaches 50%
-                # Useless in practice, but shows how to stop on command
-                def progress(current, total, client):
+                # Stop transmission once the upload progress reaches 50%
+                async def progress(current, total, client):
                     if (current * 100 / total) > 50:
                         client.stop_transmission()
 
-                with app:
-                    app.send_document("me", "file.zip", progress=progress, progress_args=(app,))
+                async with app:
+                    await app.send_document(
+                        "me", "file.zip",
+                        progress=progress,
+                        progress_args=(app,))
         """
         raise pyrogram.StopTransmission
diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py
index 436b6076ea..8c96d6cc61 100644
--- a/pyrogram/types/bots_and_keyboards/callback_query.py
+++ b/pyrogram/types/bots_and_keyboards/callback_query.py
@@ -131,7 +131,7 @@ async def answer(self, text: str = None, show_alert: bool = None, url: str = Non
 
         .. code-block:: python
 
-            client.answer_callback_query(
+            await client.answer_callback_query(
                 callback_query.id,
                 text="Hello",
                 show_alert=True
@@ -140,7 +140,7 @@ async def answer(self, text: str = None, show_alert: bool = None, url: str = Non
         Example:
             .. code-block:: python
 
-                callback_query.answer("Hello", show_alert=True)
+                await callback_query.answer("Hello", show_alert=True)
 
         Parameters:
             text (``str``, *optional*):
diff --git a/pyrogram/types/inline_mode/inline_query.py b/pyrogram/types/inline_mode/inline_query.py
index 6f671059d0..a5f0422e72 100644
--- a/pyrogram/types/inline_mode/inline_query.py
+++ b/pyrogram/types/inline_mode/inline_query.py
@@ -122,7 +122,7 @@ async def answer(
 
         .. code-block:: python
 
-            client.answer_inline_query(
+            await client.answer_inline_query(
                 inline_query.id,
                 results=[...]
             )
@@ -130,7 +130,7 @@ async def answer(
         Example:
             .. code-block:: python
 
-                inline_query.answer([...])
+                await inline_query.answer([...])
 
         Parameters:
             results (List of :obj:`~pyrogram.types.InlineQueryResult`):
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index f7965e6a21..0c639e359c 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -834,7 +834,7 @@ async def get_media_group(self) -> List["types.Message"]:
         
         .. code-block:: python
 
-            client.get_media_group(
+            await client.get_media_group(
                 chat_id=message.chat.id,
                 message_id=message.id
             )
@@ -842,7 +842,7 @@ async def get_media_group(self) -> List["types.Message"]:
         Example:
             .. code-block:: python
 
-                message.get_media_group()
+                await message.get_media_group()
                 
         Returns:
             List of :obj:`~pyrogram.types.Message`: On success, a list of messages of the media group is returned.
@@ -877,7 +877,7 @@ async def reply_text(
 
         .. code-block:: python
 
-            client.send_message(
+            await client.send_message(
                 chat_id=message.chat.id,
                 text="hello",
                 reply_to_message_id=message.id
@@ -886,7 +886,7 @@ async def reply_text(
         Example:
             .. code-block:: python
 
-                message.reply_text("hello", quote=True)
+                await message.reply_text("hello", quote=True)
 
         Parameters:
             text (``str``):
@@ -979,7 +979,7 @@ async def reply_animation(
 
         .. code-block:: python
 
-            client.send_animation(
+            await client.send_animation(
                 chat_id=message.chat.id,
                 animation=animation
             )
@@ -987,7 +987,7 @@ async def reply_animation(
         Example:
             .. code-block:: python
 
-                message.reply_animation(animation)
+                await message.reply_animation(animation)
 
         Parameters:
             animation (``str``):
@@ -1118,7 +1118,7 @@ async def reply_audio(
 
         .. code-block:: python
 
-            client.send_audio(
+            await client.send_audio(
                 chat_id=message.chat.id,
                 audio=audio
             )
@@ -1126,7 +1126,7 @@ async def reply_audio(
         Example:
             .. code-block:: python
 
-                message.reply_audio(audio)
+                await message.reply_audio(audio)
 
         Parameters:
             audio (``str``):
@@ -1251,7 +1251,7 @@ async def reply_cached_media(
 
         .. code-block:: python
 
-            client.send_cached_media(
+            await client.send_cached_media(
                 chat_id=message.chat.id,
                 file_id=file_id
             )
@@ -1259,7 +1259,7 @@ async def reply_cached_media(
         Example:
             .. code-block:: python
 
-                message.reply_cached_media(file_id)
+                await message.reply_cached_media(file_id)
 
         Parameters:
             file_id (``str``):
@@ -1315,31 +1315,30 @@ async def reply_cached_media(
             reply_markup=reply_markup
         )
 
-    async def reply_chat_action(self, action: str) -> bool:
+    async def reply_chat_action(self, action: "enums.ChatAction") -> bool:
         """Bound method *reply_chat_action* of :obj:`~pyrogram.types.Message`.
 
         Use as a shortcut for:
 
         .. code-block:: python
 
-            client.send_chat_action(
+            from pyrogram import enums
+
+            await client.send_chat_action(
                 chat_id=message.chat.id,
-                action="typing"
+                action=enums.ChatAction.TYPING
             )
 
         Example:
             .. code-block:: python
 
-                message.reply_chat_action("typing")
+                from pyrogram import enums
+
+                await message.reply_chat_action(enums.ChatAction.TYPING)
 
         Parameters:
-            action (``str``):
-                Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
-                text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
-                *"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
-                *"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
-                *"choose_contact"* for contacts, *"playing"* for games or *"cancel"* to cancel any chat action currently
-                displayed.
+            action (:obj:`~pyrogram.enums.ChatAction`):
+                Type of action to broadcast.
 
         Returns:
             ``bool``: On success, True is returned.
@@ -1375,7 +1374,7 @@ async def reply_contact(
 
         .. code-block:: python
 
-            client.send_contact(
+            await client.send_contact(
                 chat_id=message.chat.id,
                 phone_number=phone_number,
                 first_name=first_name
@@ -1384,7 +1383,7 @@ async def reply_contact(
         Example:
             .. code-block:: python
 
-                message.reply_contact("+1-123-456-7890", "Name")
+                await message.reply_contact("+1-123-456-7890", "Name")
 
         Parameters:
             phone_number (``str``):
@@ -1466,7 +1465,7 @@ async def reply_document(
 
         .. code-block:: python
 
-            client.send_document(
+            await client.send_document(
                 chat_id=message.chat.id,
                 document=document
             )
@@ -1474,7 +1473,7 @@ async def reply_document(
         Example:
             .. code-block:: python
 
-                message.reply_document(document)
+                await message.reply_document(document)
 
         Parameters:
             document (``str``):
@@ -1599,7 +1598,7 @@ async def reply_game(
 
         .. code-block:: python
 
-            client.send_game(
+            await client.send_game(
                 chat_id=message.chat.id,
                 game_short_name="lumberjack"
             )
@@ -1607,7 +1606,7 @@ async def reply_game(
         Example:
             .. code-block:: python
 
-                message.reply_game("lumberjack")
+                await message.reply_game("lumberjack")
 
         Parameters:
             game_short_name (``str``):
@@ -1663,7 +1662,7 @@ async def reply_inline_bot_result(
 
         .. code-block:: python
 
-            client.send_inline_bot_result(
+            await client.send_inline_bot_result(
                 chat_id=message.chat.id,
                 query_id=query_id,
                 result_id=result_id
@@ -1672,7 +1671,7 @@ async def reply_inline_bot_result(
         Example:
             .. code-block:: python
 
-                message.reply_inline_bot_result(query_id, result_id)
+                await message.reply_inline_bot_result(query_id, result_id)
 
         Parameters:
             query_id (``int``):
@@ -1733,16 +1732,16 @@ async def reply_location(
 
         .. code-block:: python
 
-            client.send_location(
+            await client.send_location(
                 chat_id=message.chat.id,
-                latitude=41.890251,
-                longitude=12.492373
+                latitude=latitude,
+                longitude=longitude
             )
 
         Example:
             .. code-block:: python
 
-                message.reply_location(41.890251, 12.492373)
+                await message.reply_location(latitude, longitude)
 
         Parameters:
             latitude (``float``):
@@ -1801,7 +1800,7 @@ async def reply_media_group(
 
         .. code-block:: python
 
-            client.send_media_group(
+            await client.send_media_group(
                 chat_id=message.chat.id,
                 media=list_of_media
             )
@@ -1809,7 +1808,7 @@ async def reply_media_group(
         Example:
             .. code-block:: python
 
-                message.reply_media_group(list_of_media)
+                await message.reply_media_group(list_of_media)
 
         Parameters:
             media (``list``):
@@ -1874,7 +1873,7 @@ async def reply_photo(
 
         .. code-block:: python
 
-            client.send_photo(
+            await client.send_photo(
                 chat_id=message.chat.id,
                 photo=photo
             )
@@ -1882,7 +1881,7 @@ async def reply_photo(
         Example:
             .. code-block:: python
 
-                message.reply_photo(photo)
+                await message.reply_photo(photo)
 
         Parameters:
             photo (``str``):
@@ -1997,16 +1996,16 @@ async def reply_poll(
 
         .. code-block:: python
 
-            client.send_poll(
+            await client.send_poll(
                 chat_id=message.chat.id,
-                question="Is Pyrogram the best?",
-                options=["Yes", "Yes"]
+                question="This is a poll",
+                options=["A", "B", "C]
             )
 
         Example:
             .. code-block:: python
 
-                message.reply_poll("Is Pyrogram the best?", ["Yes", "Yes"])
+                await message.reply_poll("This is a poll", ["A", "B", "C"])
 
         Parameters:
             question (``str``):
@@ -2097,7 +2096,7 @@ async def reply_sticker(
 
         .. code-block:: python
 
-            client.send_sticker(
+            await client.send_sticker(
                 chat_id=message.chat.id,
                 sticker=sticker
             )
@@ -2105,7 +2104,7 @@ async def reply_sticker(
         Example:
             .. code-block:: python
 
-                message.reply_sticker(sticker)
+                await message.reply_sticker(sticker)
 
         Parameters:
             sticker (``str``):
@@ -2200,18 +2199,18 @@ async def reply_venue(
 
         .. code-block:: python
 
-            client.send_venue(
+            await client.send_venue(
                 chat_id=message.chat.id,
-                latitude=41.890251,
-                longitude=12.492373,
-                title="Coliseum",
-                address="Piazza del Colosseo, 1, 00184 Roma RM"
+                latitude=latitude,
+                longitude=longitude,
+                title="Venue title",
+                address="Venue address"
             )
 
         Example:
             .. code-block:: python
 
-                message.reply_venue(41.890251, 12.492373, "Coliseum", "Piazza del Colosseo, 1, 00184 Roma RM")
+                await message.reply_venue(latitude, longitude, "Venue title", "Venue address")
 
         Parameters:
             latitude (``float``):
@@ -2304,7 +2303,7 @@ async def reply_video(
 
         .. code-block:: python
 
-            client.send_video(
+            await client.send_video(
                 chat_id=message.chat.id,
                 video=video
             )
@@ -2312,7 +2311,7 @@ async def reply_video(
         Example:
             .. code-block:: python
 
-                message.reply_video(video)
+                await message.reply_video(video)
 
         Parameters:
             video (``str``):
@@ -2449,7 +2448,7 @@ async def reply_video_note(
 
         .. code-block:: python
 
-            client.send_video_note(
+            await client.send_video_note(
                 chat_id=message.chat.id,
                 video_note=video_note
             )
@@ -2457,7 +2456,7 @@ async def reply_video_note(
         Example:
             .. code-block:: python
 
-                message.reply_video_note(video_note)
+                await message.reply_video_note(video_note)
 
         Parameters:
             video_note (``str``):
@@ -2568,7 +2567,7 @@ async def reply_voice(
 
         .. code-block:: python
 
-            client.send_voice(
+            await client.send_voice(
                 chat_id=message.chat.id,
                 voice=voice
             )
@@ -2576,7 +2575,7 @@ async def reply_voice(
         Example:
             .. code-block:: python
 
-                message.reply_voice(voice)
+                await message.reply_voice(voice)
 
         Parameters:
             voice (``str``):
@@ -2680,7 +2679,7 @@ async def edit_text(
 
         .. code-block:: python
 
-            client.edit_message_text(
+            await client.edit_message_text(
                 chat_id=message.chat.id,
                 message_id=message.id,
                 text="hello"
@@ -2689,7 +2688,7 @@ async def edit_text(
         Example:
             .. code-block:: python
 
-                message.edit_text("hello")
+                await message.edit_text("hello")
 
         Parameters:
             text (``str``):
@@ -2739,7 +2738,7 @@ async def edit_caption(
 
         .. code-block:: python
 
-            client.edit_message_caption(
+            await client.edit_message_caption(
                 chat_id=message.chat.id,
                 message_id=message.id,
                 caption="hello"
@@ -2748,7 +2747,7 @@ async def edit_caption(
         Example:
             .. code-block:: python
 
-                message.edit_caption("hello")
+                await message.edit_caption("hello")
 
         Parameters:
             caption (``str``):
@@ -2790,7 +2789,7 @@ async def edit_media(
 
         .. code-block:: python
 
-            client.edit_message_media(
+            await client.edit_message_media(
                 chat_id=message.chat.id,
                 message_id=message.id,
                 media=media
@@ -2799,7 +2798,7 @@ async def edit_media(
         Example:
             .. code-block:: python
 
-                message.edit_media(media)
+                await message.edit_media(media)
 
         Parameters:
             media (:obj:`~pyrogram.types.InputMedia`):
@@ -2828,7 +2827,7 @@ async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = N
 
         .. code-block:: python
 
-            client.edit_message_reply_markup(
+            await client.edit_message_reply_markup(
                 chat_id=message.chat.id,
                 message_id=message.id,
                 reply_markup=inline_reply_markup
@@ -2837,7 +2836,7 @@ async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = N
         Example:
             .. code-block:: python
 
-                message.edit_reply_markup(inline_reply_markup)
+                await message.edit_reply_markup(inline_reply_markup)
 
         Parameters:
             reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`):
@@ -2868,7 +2867,7 @@ async def forward(
 
         .. code-block:: python
 
-            client.forward_messages(
+            await client.forward_messages(
                 chat_id=chat_id,
                 from_chat_id=message.chat.id,
                 message_ids=message.id
@@ -2877,7 +2876,7 @@ async def forward(
         Example:
             .. code-block:: python
 
-                message.forward(chat_id)
+                await message.forward(chat_id)
 
         Parameters:
             chat_id (``int`` | ``str``):
@@ -2929,7 +2928,7 @@ async def copy(
 
         .. code-block:: python
 
-            client.copy_message(
+            await client.copy_message(
                 chat_id=chat_id,
                 from_chat_id=message.chat.id,
                 message_id=message.id
@@ -2938,7 +2937,7 @@ async def copy(
         Example:
             .. code-block:: python
 
-                message.copy(chat_id)
+                await message.copy(chat_id)
 
         Parameters:
             chat_id (``int`` | ``str``):
@@ -3100,7 +3099,7 @@ async def delete(self, revoke: bool = True):
 
         .. code-block:: python
 
-            client.delete_messages(
+            await client.delete_messages(
                 chat_id=chat_id,
                 message_ids=message.id
             )
@@ -3108,7 +3107,7 @@ async def delete(self, revoke: bool = True):
         Example:
             .. code-block:: python
 
-                message.delete()
+                await message.delete()
 
         Parameters:
             revoke (``bool``, *optional*):
@@ -3138,7 +3137,7 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None,
 
         .. code-block:: python
 
-            client.request_callback_answer(
+            await client.request_callback_answer(
                 chat_id=message.chat.id,
                 message_id=message.id,
                 callback_data=message.reply_markup[i][j].callback_data
@@ -3148,7 +3147,7 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None,
 
         .. code-block:: python
 
-            client.send_message(
+            await client.send_message(
                 chat_id=message.chat.id,
                 text=message.reply_markup[i][j].text
             )
@@ -3257,7 +3256,7 @@ async def react(self, emoji: str = "") -> bool:
 
         .. code-block:: python
 
-            client.send_reaction(
+            await client.send_reaction(
                 chat_id=chat_id,
                 message_id=message.message_id,
                 emoji="🔥"
@@ -3266,7 +3265,7 @@ async def react(self, emoji: str = "") -> bool:
         Example:
             .. code-block:: python
 
-                message.react(emoji="🔥")
+                await message.react(emoji="🔥")
 
         Parameters:
             emoji (``str``, *optional*):
@@ -3330,12 +3329,12 @@ async def download(
 
         .. code-block:: python
 
-            client.download_media(message)
+            await lient.download_media(message)
 
         Example:
             .. code-block:: python
 
-                message.download()
+                await message.download()
 
         Parameters:
             file_name (``str``, *optional*):
@@ -3430,7 +3429,7 @@ async def pin(self, disable_notification: bool = False, both_sides: bool = False
 
         .. code-block:: python
 
-            client.pin_chat_message(
+            await client.pin_chat_message(
                 chat_id=message.chat.id,
                 message_id=message_id
             )
@@ -3438,7 +3437,7 @@ async def pin(self, disable_notification: bool = False, both_sides: bool = False
         Example:
             .. code-block:: python
 
-                message.pin()
+                await message.pin()
 
         Parameters:
             disable_notification (``bool``):
@@ -3469,7 +3468,7 @@ async def unpin(self) -> bool:
 
         .. code-block:: python
 
-            client.unpin_chat_message(
+            await client.unpin_chat_message(
                 chat_id=message.chat.id,
                 message_id=message_id
             )
@@ -3477,7 +3476,7 @@ async def unpin(self) -> bool:
         Example:
             .. code-block:: python
 
-                message.unpin()
+                await message.unpin()
 
         Returns:
             True on success.
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index f48f3c0f01..e36107bf61 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -17,7 +17,7 @@
 #  along with Pyrogram.  If not, see .
 
 from datetime import datetime
-from typing import Union, List, Generator, Optional
+from typing import Union, List
 
 import pyrogram
 from pyrogram import raw, enums
@@ -365,12 +365,12 @@ async def archive(self):
 
         .. code-block:: python
 
-            client.archive_chats(-100123456789)
+            await client.archive_chats(-100123456789)
 
         Example:
             .. code-block:: python
 
-                chat.archive()
+                await chat.archive()
 
         Returns:
             True on success.
@@ -388,12 +388,12 @@ async def unarchive(self):
 
         .. code-block:: python
 
-            client.unarchive_chats(-100123456789)
+            await client.unarchive_chats(-100123456789)
 
         Example:
             .. code-block:: python
 
-                chat.unarchive()
+                await chat.unarchive()
 
         Returns:
             True on success.
@@ -412,7 +412,7 @@ async def set_title(self, title: str) -> bool:
 
         .. code-block:: python
 
-            client.set_chat_title(
+            await client.set_chat_title(
                 chat_id=chat_id,
                 title=title
             )
@@ -420,7 +420,7 @@ async def set_title(self, title: str) -> bool:
         Example:
             .. code-block:: python
 
-                chat.set_title("Lounge")
+                await chat.set_title("Lounge")
 
         Note:
             In regular groups (non-supergroups), this method will only work if the "All Members Are Admins"
@@ -450,7 +450,7 @@ async def set_description(self, description: str) -> bool:
 
         .. code-block:: python
 
-            client.set_chat_description(
+            await client.set_chat_description(
                 chat_id=chat_id,
                 description=description
             )
@@ -458,7 +458,7 @@ async def set_description(self, description: str) -> bool:
         Example:
             .. code-block:: python
 
-                chat.set_chat_description("Don't spam!")
+                await chat.set_chat_description("Don't spam!")
 
         Parameters:
             description (``str``):
@@ -484,7 +484,7 @@ async def set_photo(self, photo: str) -> bool:
 
         .. code-block:: python
 
-            client.set_chat_photo(
+            await client.set_chat_photo(
                 chat_id=chat_id,
                 photo=photo
             )
@@ -492,7 +492,7 @@ async def set_photo(self, photo: str) -> bool:
         Example:
             .. code-block:: python
 
-                chat.set_photo("photo.png")
+                await chat.set_photo("photo.png")
 
         Parameters:
             photo (``str``):
@@ -522,7 +522,7 @@ async def ban_member(
 
         .. code-block:: python
 
-            client.ban_chat_member(
+            await client.ban_chat_member(
                 chat_id=chat_id,
                 user_id=user_id
             )
@@ -530,7 +530,7 @@ async def ban_member(
         Example:
             .. code-block:: python
 
-                chat.ban_member(123456789)
+                await chat.ban_member(123456789)
 
         Note:
             In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" setting is
@@ -571,7 +571,7 @@ async def unban_member(
 
         .. code-block:: python
 
-            client.unban_chat_member(
+            await client.unban_chat_member(
                 chat_id=chat_id,
                 user_id=user_id
             )
@@ -579,7 +579,7 @@ async def unban_member(
         Example:
             .. code-block:: python
 
-                chat.unban_member(123456789)
+                await chat.unban_member(123456789)
 
         Parameters:
             user_id (``int`` | ``str``):
@@ -610,7 +610,7 @@ async def restrict_member(
 
         .. code-block:: python
 
-            client.restrict_chat_member(
+            await client.restrict_chat_member(
                 chat_id=chat_id,
                 user_id=user_id,
                 permissions=ChatPermissions()
@@ -619,7 +619,7 @@ async def restrict_member(
         Example:
             .. code-block:: python
 
-                chat.restrict_member(user_id, ChatPermissions())
+                await chat.restrict_member(user_id, ChatPermissions())
 
         Parameters:
             user_id (``int`` | ``str``):
@@ -648,19 +648,12 @@ async def restrict_member(
             until_date=until_date,
         )
 
+    # Set None as privileges default due to issues with partially initialized module, because at the time Chat
+    # is being initialized, ChatPrivileges would be required here, but was not initialized yet.
     async def promote_member(
         self,
         user_id: Union[int, str],
-        can_manage_chat: bool = True,
-        can_change_info: bool = True,
-        can_post_messages: bool = False,
-        can_edit_messages: bool = False,
-        can_delete_messages: bool = True,
-        can_restrict_members: bool = True,
-        can_invite_users: bool = True,
-        can_pin_messages: bool = False,
-        can_promote_members: bool = False,
-        can_manage_voice_chats: bool = False
+        privileges: "types.ChatPrivileges" = None
     ) -> bool:
         """Bound method *promote_member* of :obj:`~pyrogram.types.Chat`.
 
@@ -668,7 +661,7 @@ async def promote_member(
 
         .. code-block:: python
 
-            client.promote_chat_member(
+            await client.promote_chat_member(
                 chat_id=chat_id,
                 user_id=user_id
             )
@@ -677,46 +670,15 @@ async def promote_member(
 
             .. code-block:: python
 
-                chat.promote_member(123456789)
+                await chat.promote_member(123456789)
 
         Parameters:
             user_id (``int`` | ``str``):
                 Unique identifier (int) or username (str) of the target user.
                 For a contact that exists in your Telegram address book you can use his phone number (str).
 
-            can_manage_chat (``bool``, *optional*):
-                Pass True, if the administrator can access the chat event log, chat statistics, message statistics
-                in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode.
-                Implied by any other administrator privilege.
-
-            can_change_info (``bool``, *optional*):
-                Pass True, if the administrator can change chat title, photo and other settings.
-
-            can_post_messages (``bool``, *optional*):
-                Pass True, if the administrator can create channel posts, channels only.
-
-            can_edit_messages (``bool``, *optional*):
-                Pass True, if the administrator can edit messages of other users and can pin messages, channels only.
-
-            can_delete_messages (``bool``, *optional*):
-                Pass True, if the administrator can delete messages of other users.
-
-            can_restrict_members (``bool``, *optional*):
-                Pass True, if the administrator can restrict, ban or unban chat members.
-
-            can_invite_users (``bool``, *optional*):
-                Pass True, if the administrator can invite new users to the chat.
-
-            can_pin_messages (``bool``, *optional*):
-                Pass True, if the administrator can pin messages, supergroups only.
-
-            can_promote_members (``bool``, *optional*):
-                Pass True, if the administrator can add new administrators with a subset of his own privileges or
-                demote administrators that he has promoted, directly or indirectly (promoted by administrators that
-                were appointed by him).
-
-            can_manage_voice_chats (``bool``, *optional*):
-                Pass True, if the administration can manage voice chats (also called group calls).
+            privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
+                New user privileges.
 
         Returns:
             ``bool``: True on success.
@@ -728,16 +690,7 @@ async def promote_member(
         return await self._client.promote_chat_member(
             chat_id=self.id,
             user_id=user_id,
-            can_manage_chat=can_manage_chat,
-            can_change_info=can_change_info,
-            can_post_messages=can_post_messages,
-            can_edit_messages=can_edit_messages,
-            can_delete_messages=can_delete_messages,
-            can_restrict_members=can_restrict_members,
-            can_invite_users=can_invite_users,
-            can_pin_messages=can_pin_messages,
-            can_promote_members=can_promote_members,
-            can_manage_voice_chats=can_manage_voice_chats
+            privileges=privileges
         )
 
     async def join(self):
@@ -747,12 +700,12 @@ async def join(self):
 
         .. code-block:: python
 
-            client.join_chat(123456789)
+            await client.join_chat(123456789)
 
         Example:
             .. code-block:: python
 
-                chat.join()
+                await chat.join()
 
         Note:
             This only works for public groups, channels that have set a username or linked chats.
@@ -773,12 +726,12 @@ async def leave(self):
 
         .. code-block:: python
 
-            client.leave_chat(123456789)
+            await client.leave_chat(123456789)
 
         Example:
             .. code-block:: python
 
-                chat.leave()
+                await chat.leave()
 
         Raises:
             RPCError: In case of a Telegram RPC error.
@@ -819,7 +772,7 @@ async def get_member(
 
         .. code-block:: python
 
-            client.get_chat_member(
+            await client.get_chat_member(
                 chat_id=chat_id,
                 user_id=user_id
             )
@@ -827,7 +780,7 @@ async def get_member(
         Example:
             .. code-block:: python
 
-                chat.get_member(user_id)
+                await chat.get_member(user_id)
 
         Returns:
             :obj:`~pyrogram.types.ChatMember`: On success, a chat member is returned.
@@ -840,9 +793,8 @@ async def get_member(
 
     async def get_members(
         self,
-        offset: int = 0,
-        limit: int = 200,
         query: str = "",
+        limit: int = 0,
         filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.SEARCH
     ) -> List["types.ChatMember"]:
         """Bound method *get_members* of :obj:`~pyrogram.types.Chat`.
@@ -851,120 +803,38 @@ async def get_members(
 
         .. code-block:: python
 
-            client.get_chat_members(chat_id)
-
-
-        Parameters:
-            offset (``int``, *optional*):
-                Sequential number of the first member to be returned.
-                Only applicable to supergroups and channels. Defaults to 0 [1]_.
-
-            limit (``int``, *optional*):
-                Limits the number of members to be retrieved.
-                Only applicable to supergroups and channels.
-                Defaults to 200, which is also the maximum server limit allowed per method call.
-
-            query (``str``, *optional*):
-                Query string to filter members based on their display names and usernames.
-                Only applicable to supergroups and channels. 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 the followings:
-                *"all"* - all kind of members,
-                *"banned"* - banned members only,
-                *"restricted"* - restricted members only,
-                *"bots"* - bots only,
-                *"recent"* - recent members only,
-                *"administrators"* - chat administrators only.
-                Only applicable to supergroups and channels.
-                Defaults to *"recent"*.
-
-        .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
-            on channels.
-
-        .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
+            async for member in client.get_chat_members(chat_id):
+                print(member)
 
         Example:
             .. code-block:: python
 
-                # Get first 200 recent members
-                chat.get_members()
-
-                # Get all administrators
-                chat.get_members(filter="administrators")
-
-                # Get all bots
-                chat.get_members(filter="bots")
-
-        Returns:
-            List of :obj:`~pyrogram.types.ChatMember`: On success, a list of chat members is returned.
-        """
-
-        return await self._client.get_chat_members(
-            self.id,
-            offset=offset,
-            limit=limit,
-            query=query,
-            filter=filter
-        )
-
-    def iter_members(
-        self,
-        limit: int = 0,
-        query: str = "",
-        filter: str = "all"
-    ) -> Optional[Generator["types.ChatMember", None, None]]:
-        """Bound method *iter_members* of :obj:`~pyrogram.types.Chat`.
-
-        Use as a shortcut for:
-
-        .. code-block:: python
+                async for member in chat.get_members():
+                    print(member)
 
         Parameters:
-            limit (``int``, *optional*):
-                Limits the number of members to be retrieved.
-                Only applicable to supergroups and channels.
-                Defaults to 200, which is also the maximum server limit allowed per method call [1]_.
-
             query (``str``, *optional*):
                 Query string to filter members based on their display names and usernames.
-                Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
+                Only applicable to supergroups and channels. Defaults to "" (empty string).
+                A query string is applicable only for :obj:`~pyrogram.enums.ChatMembersFilter.SEARCH`,
+                :obj:`~pyrogram.enums.ChatMembersFilter.BANNED` and :obj:`~pyrogram.enums.ChatMembersFilter.RESTRICTED`
+                filters only.
+
+            limit (``int``, *optional*):
+                Limits the number of members to be retrieved.
 
             filter (:obj:`~pyrogram.enums.ChatMembersFilter`, *optional*):
                 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
                 and channels.
 
-        .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
-            on channels.
-
-        .. [2] A query string is applicable only for *"all"*, *"banned"* and *"restricted"* filters only.
-
-        Example:
-            .. code-block:: python
-
-                from pyrogram import enums
-
-                # Get first 200 recent members
-                for member in chat.get_members():
-                    print(member.user.first_name)
-
-                # Get all administrators
-                for member in chat.iter_members(filter=enums.ChatMembersFilter.ADMINISTRATORS):
-                    print(member.user.first_name)
-
-                # Get first 3 bots
-                for member in chat.iter_members(filter=enums.ChatMembersFilter.BOTS, limit=3):
-                    print(member.user.first_name)
-
         Returns:
-            ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects.
+            ``Generator``: On success, a generator yielding :obj:`~pyrogram.types.ChatMember` objects is returned.
         """
 
-        return self._client.iter_chat_members(
+        return self._client.get_chat_members(
             self.id,
-            limit=limit,
             query=query,
+            limit=limit,
             filter=filter
         )
 
@@ -979,12 +849,12 @@ async def add_members(
 
         .. code-block:: python
 
-            client.add_chat_members(chat_id, user_id)
+            await client.add_chat_members(chat_id, user_id)
 
         Example:
             .. code-block:: python
 
-                chat.add_members(user_id)
+                await chat.add_members(user_id)
 
         Returns:
             ``bool``: On success, True is returned.
@@ -1003,12 +873,12 @@ async def mark_unread(self, ) -> bool:
 
         .. code-block:: python
 
-            client.mark_unread(chat_id)
+            await client.mark_unread(chat_id)
 
         Example:
             .. code-block:: python
 
-                chat.mark_unread()
+                await chat.mark_unread()
 
         Returns:
             ``bool``: On success, True is returned.
@@ -1023,7 +893,7 @@ async def set_protected_content(self, enabled: bool) -> bool:
 
         .. code-block:: python
 
-            client.set_chat_protected_content(chat_id, enabled)
+            await client.set_chat_protected_content(chat_id, enabled)
 
         Parameters:
             enabled (``bool``):
@@ -1032,7 +902,7 @@ async def set_protected_content(self, enabled: bool) -> bool:
         Example:
             .. code-block:: python
 
-                chat.set_protected_content(enabled)
+                await chat.set_protected_content(enabled)
 
         Returns:
             ``bool``: On success, True is returned.
diff --git a/pyrogram/types/user_and_chats/chat_join_request.py b/pyrogram/types/user_and_chats/chat_join_request.py
index ee9da3ef2c..b810640b76 100644
--- a/pyrogram/types/user_and_chats/chat_join_request.py
+++ b/pyrogram/types/user_and_chats/chat_join_request.py
@@ -89,7 +89,7 @@ async def approve(self) -> bool:
         
         .. code-block:: python
 
-            client.approve_chat_join_request(
+            await client.approve_chat_join_request(
                 chat_id=request.chat.id,
                 user_id=request.from_user.id
             )
@@ -97,7 +97,7 @@ async def approve(self) -> bool:
         Example:
             .. code-block:: python
 
-                request.approve()
+                await request.approve()
                 
         Returns:
             ``bool``: True on success.
@@ -117,7 +117,7 @@ async def decline(self) -> bool:
         
         .. code-block:: python
 
-            client.decline_chat_join_request(
+            await client.decline_chat_join_request(
                 chat_id=request.chat.id,
                 user_id=request.from_user.id
             )
@@ -125,7 +125,7 @@ async def decline(self) -> bool:
         Example:
             .. code-block:: python
 
-                request.decline()
+                await request.decline()
                 
         Returns:
             ``bool``: True on success.
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index 2ec09fb583..ff32e97336 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -274,12 +274,12 @@ async def archive(self):
 
         .. code-block:: python
 
-            client.archive_chats(123456789)
+            await client.archive_chats(123456789)
 
         Example:
             .. code-block:: python
 
-                user.archive()
+               await user.archive()
 
         Returns:
             True on success.
@@ -297,12 +297,12 @@ async def unarchive(self):
 
         .. code-block:: python
 
-            client.unarchive_chats(123456789)
+            await client.unarchive_chats(123456789)
 
         Example:
             .. code-block:: python
 
-                user.unarchive()
+                await user.unarchive()
 
         Returns:
             True on success.
@@ -320,12 +320,12 @@ def block(self):
 
         .. code-block:: python
 
-            client.block_user(123456789)
+            await client.block_user(123456789)
 
         Example:
             .. code-block:: python
 
-                user.block()
+                await user.block()
 
         Returns:
             True on success.

From 1e66ac26367c3e7de998ada050c4f0a8f0791bd0 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 158/539] Small documentation fix

---
 pyrogram/types/user_and_chats/chat_member.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py
index cff2ac430d..4459a8d1c0 100644
--- a/pyrogram/types/user_and_chats/chat_member.py
+++ b/pyrogram/types/user_and_chats/chat_member.py
@@ -38,7 +38,7 @@ class ChatMember(Object):
             Information about the chat (useful in case of banned channel senders).
 
         joined_date (:py:obj:`~datetime.datetime`, *optional*):
-            Date when the user joined..
+            Date when the user joined.
             Not available for the owner.
 
         custom_title (``str``, *optional*):

From b8f39725c50d4ec1625268882e0bf5e1900a5383 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 159/539] Remove outdated FAQ

---
 docs/source/faq/index.rst                     |  2 --
 ...-event-handler-triggered-twice-or-more.rst | 28 -------------------
 2 files changed, 30 deletions(-)
 delete mode 100644 docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst

diff --git a/docs/source/faq/index.rst b/docs/source/faq/index.rst
index 0b16534943..e5bef2be0f 100644
--- a/docs/source/faq/index.rst
+++ b/docs/source/faq/index.rst
@@ -17,7 +17,6 @@ This FAQ page provides answers to common questions about Pyrogram and, to some e
 - :doc:`code-hangs-when-calling-stop-restart-add-remove-handler`
 - :doc:`unicodeencodeerror-codec-cant-encode`
 - :doc:`uploading-with-urls-gives-error-webpage-curl-failed`
-- :doc:`why-is-the-event-handler-triggered-twice-or-more`
 - :doc:`sqlite3-operationalerror-database-is-locked`
 - :doc:`sqlite3-interfaceerror-error-binding-parameter`
 - :doc:`socket-send-raised-exception-oserror-timeouterror`
@@ -39,7 +38,6 @@ This FAQ page provides answers to common questions about Pyrogram and, to some e
     code-hangs-when-calling-stop-restart-add-remove-handler
     unicodeencodeerror-codec-cant-encode
     uploading-with-urls-gives-error-webpage-curl-failed
-    why-is-the-event-handler-triggered-twice-or-more
     sqlite3-operationalerror-database-is-locked
     sqlite3-interfaceerror-error-binding-parameter
     socket-send-raised-exception-oserror-timeouterror
diff --git a/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst b/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst
deleted file mode 100644
index ada12f1de3..0000000000
--- a/docs/source/faq/why-is-the-event-handler-triggered-twice-or-more.rst
+++ /dev/null
@@ -1,28 +0,0 @@
-Why is the event handler called twice or more?
-==============================================
-
-The event handler is being called twice or more because one or more message edit events have arrived.
-By default, Pyrogram listens to both new and edit message events inside ``on_message`` handlers. To prevent edit events
-from calling the handler, use the "not edited" filter ``~filters.edited``.
-
-For example:
-
-.. code-block:: python
-
-    ...
-
-    @app.on_message(... & ~filters.edited)
-    async def handler(client, message):
-        ...
-
-Or, avoid handling any edited message altogether this way:
-
-.. code-block:: python
-
-    ...
-
-    @app.on_message(filters.edited)
-    async def edited(client, message):
-        pass
-
-    ...  # other handlers
\ No newline at end of file

From 124bcb4db7e126935e5c24630070b0a39bcaa0d5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 160/539] Remove API key requirement for existing sessions

---
 compiler/errors/source/303_SEE_OTHER.tsv      |  10 +-
 compiler/errors/source/400_BAD_REQUEST.tsv    |  10 +-
 compiler/errors/source/420_FLOOD.tsv          |  10 +-
 .../source/500_INTERNAL_SERVER_ERROR.tsv      |   4 +-
 .../errors/source/503_SERVICE_UNAVAILABLE.tsv |   4 +-
 docs/source/api/enums/NextCodeType.rst        |   8 +
 docs/source/api/enums/index.rst               |   2 +
 docs/source/index.rst                         |   3 +-
 docs/source/intro/quickstart.rst              |   2 +
 docs/source/intro/setup.rst                   |  60 ------
 docs/source/start/auth.rst                    |  35 +++-
 docs/source/start/invoking.rst                |   6 +
 docs/source/start/setup.rst                   |  40 ++++
 docs/source/start/updates.rst                 |   4 +
 docs/source/topics/config-file.rst            |  97 ---------
 docs/source/topics/proxy.rst                  |  56 ++---
 docs/source/topics/use-filters.rst            |   4 +-
 pyrogram/client.py                            | 197 ++++++------------
 pyrogram/connection/transport/tcp/tcp.py      |  11 +-
 pyrogram/enums/__init__.py                    |   1 +
 pyrogram/enums/next_code_type.py              |  36 ++++
 pyrogram/enums/sent_code_type.py              |   2 +-
 pyrogram/methods/auth/connect.py              |   1 -
 pyrogram/session/session.py                   |   2 +-
 pyrogram/storage/file_storage.py              |  61 +-----
 pyrogram/storage/sqlite_storage.py            |  10 +-
 pyrogram/storage/storage.py                   |   3 +
 pyrogram/types/authorization/sent_code.py     |   6 +-
 28 files changed, 250 insertions(+), 435 deletions(-)
 create mode 100644 docs/source/api/enums/NextCodeType.rst
 delete mode 100644 docs/source/intro/setup.rst
 create mode 100644 docs/source/start/setup.rst
 delete mode 100644 docs/source/topics/config-file.rst
 create mode 100644 pyrogram/enums/next_code_type.py

diff --git a/compiler/errors/source/303_SEE_OTHER.tsv b/compiler/errors/source/303_SEE_OTHER.tsv
index 62c1409df2..301660cefe 100644
--- a/compiler/errors/source/303_SEE_OTHER.tsv
+++ b/compiler/errors/source/303_SEE_OTHER.tsv
@@ -1,6 +1,6 @@
 id	message
-FILE_MIGRATE_X	The file to be accessed is currently stored in DC{x}
-NETWORK_MIGRATE_X	The source IP address is associated with DC{x} (for registration)
-PHONE_MIGRATE_X	The phone number a user is trying to use for authorization is associated with DC{x}
-STATS_MIGRATE_X	The statistics of the group/channel are stored in DC{x}
-USER_MIGRATE_X	The user whose identity is being used to execute queries is associated with DC{x} (for registration)
\ No newline at end of file
+FILE_MIGRATE_X	The file to be accessed is currently stored in DC{value}
+NETWORK_MIGRATE_X	The source IP address is associated with DC{value} (for registration)
+PHONE_MIGRATE_X	The phone number a user is trying to use for authorization is associated with DC{value}
+STATS_MIGRATE_X	The statistics of the group/channel are stored in DC{value}
+USER_MIGRATE_X	The user whose identity is being used to execute queries is associated with DC{value} (for registration)
\ No newline at end of file
diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv
index e5c74e010c..f3b42fb397 100644
--- a/compiler/errors/source/400_BAD_REQUEST.tsv
+++ b/compiler/errors/source/400_BAD_REQUEST.tsv
@@ -89,7 +89,7 @@ DOCUMENT_INVALID	The document is invalid
 EMAIL_HASH_EXPIRED	The email hash expired and cannot be used to verify it
 EMAIL_INVALID	The email provided is invalid
 EMAIL_UNCONFIRMED	Email unconfirmed
-EMAIL_UNCONFIRMED_X	The provided email isn't confirmed, {x} is the length of the verification code that was just sent to the email
+EMAIL_UNCONFIRMED_X	The provided email isn't confirmed, {value} is the length of the verification code that was just sent to the email
 EMAIL_VERIFY_EXPIRED	The verification email has expired
 EMOTICON_EMPTY	The emoticon parameter is empty
 EMOTICON_INVALID	The emoticon parameter is invalid
@@ -108,7 +108,7 @@ EXTERNAL_URL_INVALID	The external media URL is invalid
 FIELD_NAME_EMPTY	The field with the name FIELD_NAME is missing
 FIELD_NAME_INVALID	The field with the name FIELD_NAME is invalid
 FILE_ID_INVALID	The file id is invalid
-FILE_MIGRATE_X	The file is in Data Center No. {x}
+FILE_MIGRATE_X	The file is in Data Center No. {value}
 FILE_PARTS_INVALID	Invalid number of parts. The value is not between 1 and 4000
 FILE_PART_EMPTY	The file part sent is empty
 FILE_PART_INVALID	The file part number is invalid. The value is not between 0 and 3999
@@ -116,7 +116,7 @@ FILE_PART_LENGTH_INVALID	The length of a file part is invalid
 FILE_PART_SIZE_CHANGED	The part size is different from the size of one of the previous parts in the same file
 FILE_PART_SIZE_INVALID	512 KB cannot be evenly divided by part_size
 FILE_PART_TOO_BIG	The size limit (512 KB) for the content of the file part has been exceeded
-FILE_PART_X_MISSING	Part {x} of the file is missing from storage
+FILE_PART_X_MISSING	Part {value} of the file is missing from storage
 FILE_REFERENCE_EMPTY	The file id contains an empty file reference, you must obtain a valid one by fetching the message from the origin context
 FILE_REFERENCE_EXPIRED	The file id contains an expired file reference, you must obtain a valid one by fetching the message from the origin context
 FILE_REFERENCE_INVALID	The file id contains an invalid file reference, you must obtain a valid one by fetching the message from the origin context
@@ -198,7 +198,7 @@ PASSWORD_HASH_INVALID	The two-step verification password is invalid
 PASSWORD_MISSING	The account is missing the two-step verification password
 PASSWORD_RECOVERY_NA	The password recovery e-mail is not available
 PASSWORD_REQUIRED	The two-step verification password is required for this method
-PASSWORD_TOO_FRESH_X	The two-step verification password was added recently and you are required to wait {x} seconds
+PASSWORD_TOO_FRESH_X	The two-step verification password was added recently and you are required to wait {value} seconds
 PAYMENT_PROVIDER_INVALID	The payment provider was not recognised or its token was invalid
 PEER_FLOOD	The method can't be used because your account is currently limited
 PEER_ID_INVALID	The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it
@@ -349,4 +349,4 @@ WEBDOCUMENT_URL_EMPTY	The web document URL is empty
 WEBDOCUMENT_URL_INVALID	The web document URL is invalid
 WEBPAGE_CURL_FAILED	Telegram server could not fetch the provided URL
 WEBPAGE_MEDIA_EMPTY	The URL doesn't contain any valid media
-YOU_BLOCKED_USER	You blocked this user
+YOU_BLOCKED_USER	You blocked this user
\ No newline at end of file
diff --git a/compiler/errors/source/420_FLOOD.tsv b/compiler/errors/source/420_FLOOD.tsv
index 9afa1fa067..575cc2f5b5 100644
--- a/compiler/errors/source/420_FLOOD.tsv
+++ b/compiler/errors/source/420_FLOOD.tsv
@@ -1,6 +1,6 @@
 id	message
-2FA_CONFIRM_WAIT_X	A wait of {x} seconds is required because this account is active and protected by a 2FA password
-FLOOD_TEST_PHONE_WAIT_X	A wait of {x} seconds is required in the test servers
-FLOOD_WAIT_X	A wait of {x} seconds is required
-SLOWMODE_WAIT_X	A wait of {x} seconds is required to send messages in this chat.
-TAKEOUT_INIT_DELAY_X	You have to confirm the data export request using one of your mobile devices or wait {x} seconds
\ No newline at end of file
+2FA_CONFIRM_WAIT_X	A wait of {value} seconds is required because this account is active and protected by a 2FA password
+FLOOD_TEST_PHONE_WAIT_X	A wait of {value} seconds is required in the test servers
+FLOOD_WAIT_X	A wait of {value} seconds is required
+SLOWMODE_WAIT_X	A wait of {value} seconds is required to send messages in this chat.
+TAKEOUT_INIT_DELAY_X	You have to confirm the data export request using one of your mobile devices or wait {value} seconds
\ No newline at end of file
diff --git a/compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv b/compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv
index 9982fc662f..abfc57a39d 100644
--- a/compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv
+++ b/compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv
@@ -13,8 +13,8 @@ GROUPCALL_ADD_PARTICIPANTS_FAILED	Failure while adding voice chat member due to
 GROUPED_ID_OCCUPY_FAILED	Telegram is having internal problems. Please try again later
 HISTORY_GET_FAILED	The chat history couldn't be retrieved due to Telegram having internal problems. Please try again later
 IMAGE_ENGINE_DOWN	Image engine down due to Telegram having internal problems. Please try again later
-INTERDC_X_CALL_ERROR	An error occurred while Telegram was intercommunicating with DC{x}. Please try again later
-INTERDC_X_CALL_RICH_ERROR	A rich error occurred while Telegram was intercommunicating with DC{x}. Please try again later
+INTERDC_X_CALL_ERROR	An error occurred while Telegram was intercommunicating with DC{value}. Please try again later
+INTERDC_X_CALL_RICH_ERROR	A rich error occurred while Telegram was intercommunicating with DC{value}. Please try again later
 MEMBER_FETCH_FAILED	Telegram is having internal problems. Please try again later
 MEMBER_NO_LOCATION	Couldn't find the member's location due to Telegram having internal problems. Please try again later
 MEMBER_OCCUPY_PRIMARY_LOC_FAILED	Telegram is having internal problems. Please try again later
diff --git a/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv b/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
index eaa426a814..c28edb0aeb 100644
--- a/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
+++ b/compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
@@ -1,3 +1,3 @@
 id	message
-Timeout	Telegram is having internal problems. Please try again later.
-ApiCallError	Telegram is having internal problems. Please try again later.
\ No newline at end of file
+ApiCallError	Telegram is having internal problems. Please try again later.
+Timeout	Telegram is having internal problems. Please try again later.
\ No newline at end of file
diff --git a/docs/source/api/enums/NextCodeType.rst b/docs/source/api/enums/NextCodeType.rst
new file mode 100644
index 0000000000..46164e47d6
--- /dev/null
+++ b/docs/source/api/enums/NextCodeType.rst
@@ -0,0 +1,8 @@
+NextCodeType
+============
+
+.. autoclass:: pyrogram.enums.NextCodeType()
+    :members:
+
+.. raw:: html
+    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst
index 7dfa1f3c24..574b4dd7ce 100644
--- a/docs/source/api/enums/index.rst
+++ b/docs/source/api/enums/index.rst
@@ -25,6 +25,7 @@ to apply only a valid value among the expected ones.
     ParseMode
     PollType
     SentCodeType
+    NextCodeType
     UserStatus
 
 .. toctree::
@@ -42,4 +43,5 @@ to apply only a valid value among the expected ones.
     ParseMode
     PollType
     SentCodeType
+    NextCodeType
     UserStatus
\ No newline at end of file
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 910d031f1f..89a8ae890a 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -111,12 +111,12 @@ Meta
 
     intro/quickstart
     intro/install
-    intro/setup
 
 .. toctree::
     :hidden:
     :caption: Getting Started
 
+    start/setup
     start/auth
     start/invoking
     start/updates
@@ -144,7 +144,6 @@ Meta
     topics/use-filters
     topics/create-filters
     topics/more-on-updates
-    topics/config-file
     topics/smart-plugins
     topics/client-settings
     topics/tgcrypto
diff --git a/docs/source/intro/quickstart.rst b/docs/source/intro/quickstart.rst
index 0981d14794..72f2dd86b4 100644
--- a/docs/source/intro/quickstart.rst
+++ b/docs/source/intro/quickstart.rst
@@ -26,10 +26,12 @@ Get Pyrogram Real Fast
         api_id = 12345
         api_hash = "0123456789abcdef0123456789abcdef"
 
+
         async def main():
             async with Client("my_account", api_id, api_hash) as app:
                 await app.send_message("me", "Greetings from **Pyrogram**!")
 
+
         asyncio.run(main())
 
 4. Replace *api_id* and *api_hash* values with your own.
diff --git a/docs/source/intro/setup.rst b/docs/source/intro/setup.rst
deleted file mode 100644
index 8bffcd86b4..0000000000
--- a/docs/source/intro/setup.rst
+++ /dev/null
@@ -1,60 +0,0 @@
-Project Setup
-=============
-
-We have just :doc:`installed Pyrogram `. In this page we'll discuss what you need to do in order to set up a
-project with the framework.
-
-.. contents:: Contents
-    :backlinks: none
-    :depth: 1
-    :local:
-
------
-
-API Keys
---------
-
-The very first step requires you to obtain a valid Telegram API key (API id/hash pair):
-
-#. Visit https://my.telegram.org/apps and log in with your Telegram Account.
-#. Fill out the form with your details and register a new Telegram application.
-#. Done. The API key consists of two parts: **api_id** and **api_hash**. Keep it secret.
-
-.. note::
-
-    The API key defines a token for a Telegram *application* you are going to build.
-    This means that you are able to authorize multiple users or bots with a single API key.
-
-Configuration
--------------
-
-Having the API key from the previous step in handy, we can now begin to configure a Pyrogram project.
-There are two ways to do so, and you can choose what fits better for you:
-
--   First option: create a new ``config.ini`` file next to your main script, copy-paste the following and
-    replace the *api_id* and *api_hash* values with your own. This method allows you to keep your credentials out of
-    your code without having to deal with how to load them.
-
-    .. code-block:: ini
-
-        [pyrogram]
-        api_id = 12345
-        api_hash = 0123456789abcdef0123456789abcdef
-
--   Alternatively, you can pass your API key to Pyrogram by simply using the *api_id* and *api_hash* parameters of the
-    Client class. This way you can have full control on how to store and load your credentials:
-
-    .. code-block:: python
-
-        from pyrogram import Client
-
-        app = Client(
-            "my_account",
-            api_id=12345,
-            api_hash="0123456789abcdef0123456789abcdef"
-        )
-
-.. note::
-
-    To keep code snippets clean and concise, from now on it is assumed you are making use of the ``config.ini`` file,
-    thus, the *api_id* and *api_hash* parameters usage won't be shown anymore.
diff --git a/docs/source/start/auth.rst b/docs/source/start/auth.rst
index 0e61e59d11..39a4face94 100644
--- a/docs/source/start/auth.rst
+++ b/docs/source/start/auth.rst
@@ -1,7 +1,7 @@
 Authorization
 =============
 
-Once a :doc:`project is set up <../intro/setup>`, you will still have to follow a few steps before you can actually use Pyrogram to make
+Once a :doc:`project is set up `, you will still have to follow a few steps before you can actually use Pyrogram to make
 API calls. This section provides all the information you need in order to authorize yourself as user or bot.
 
 .. contents:: Contents
@@ -23,7 +23,11 @@ the :meth:`~pyrogram.Client.run` method:
 
     from pyrogram import Client
 
-    app = Client("my_account")
+    api_id = 12345
+    api_hash = "0123456789abcdef0123456789abcdef"
+
+    app = Client("my_account", api_id=api_id, api_hash=api_hash)
+
     app.run()
 
 This starts an interactive shell asking you to input your **phone number**, including your `Country Code`_ (the plus
@@ -38,8 +42,8 @@ authorized or via SMS:
     Logged in successfully
 
 After successfully authorizing yourself, a new file called ``my_account.session`` will be created allowing Pyrogram to
-execute API calls with your identity. This file is personal and 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.
+execute API calls with your identity. This file is personal and will be loaded again when you restart your app.
+You can now remove the api_id and api_hash values from the code as they are not needed anymore.
 
 .. note::
 
@@ -51,7 +55,7 @@ Bot Authorization
 
 Bots are a special kind of users that are authorized via their tokens (instead of phone numbers), which are created by
 the `Bot Father`_. Bot tokens replace the users' phone numbers only — you still need to
-:doc:`configure a Telegram API key <../intro/setup>` with Pyrogram, even when using bots.
+:doc:`configure a Telegram API key <../start/setup>` with Pyrogram, even when using bots.
 
 The authorization process is automatically managed. All you need to do is choose a ``session_name`` (can be anything,
 usually your bot username) and pass your bot token using the ``bot_token`` parameter. The session file will be named
@@ -61,12 +65,29 @@ after the session name, which will be ``my_bot.session`` for the example below.
 
     from pyrogram import Client
 
+    api_id = 12345
+    api_hash = "0123456789abcdef0123456789abcdef"
+    bot_token = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
+
     app = Client(
         "my_bot",
-        bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
+        api_id=api_id, api_hash=api_hash,
+        bot_token=bot_token
     )
 
     app.run()
 
 .. _Country Code: https://en.wikipedia.org/wiki/List_of_country_calling_codes
-.. _Bot Father: https://t.me/botfather
\ No newline at end of file
+.. _Bot Father: https://t.me/botfather
+
+.. note::
+
+    The API key (api_id and api_hash) and the bot_token is not needed anymore after a successful authorization.
+    This means you can now simply use:
+
+    .. code-block:: python
+
+        from pyrogram import Client
+
+        app = Client("my_account")
+        app.run()
\ No newline at end of file
diff --git a/docs/source/start/invoking.rst b/docs/source/start/invoking.rst
index ab91e7306b..415ef848b4 100644
--- a/docs/source/start/invoking.rst
+++ b/docs/source/start/invoking.rst
@@ -22,10 +22,12 @@ Making API calls with Pyrogram is very simple. Here's a basic example we are goi
 
     app = Client("my_account")
 
+
     async def main():
         async with app:
             await app.send_message("me", "Hi!")
 
+
     app.run(main())
 
 Step-by-step
@@ -76,11 +78,13 @@ Below there's the same example as above, but without the use of the context mana
 
     app = Client("my_account")
 
+
     async def main():
         await app.start()
         await app.send_message("me", "Hi!")
         await app.stop()
 
+
     app.run(main())
 
 Using asyncio.run()
@@ -95,10 +99,12 @@ be instantiated inside the main function.
     import asyncio
     from pyrogram import Client
 
+
     async def main():
         app = Client("my_account")
 
         async with app:
             await app.send_message("me", "Hi!")
 
+
     asyncio.run(main())
\ No newline at end of file
diff --git a/docs/source/start/setup.rst b/docs/source/start/setup.rst
new file mode 100644
index 0000000000..b8fd6effd7
--- /dev/null
+++ b/docs/source/start/setup.rst
@@ -0,0 +1,40 @@
+Project Setup
+=============
+
+We have just :doc:`installed Pyrogram <../intro/install>`. In this page we'll discuss what you need to do in order to set up a
+project with the framework.
+
+.. contents:: Contents
+    :backlinks: none
+    :depth: 1
+    :local:
+
+-----
+
+API Key
+-------
+
+The first step requires you to obtain a valid Telegram API key (api_id and api_hash pair):
+
+#. Visit https://my.telegram.org/apps and log in with your Telegram account.
+#. Fill out the form with your details and register a new Telegram application.
+#. Done. The API key consists of two parts: **api_id** and **api_hash**. Keep it secret.
+
+.. note::
+
+    The API key defines a token for a Telegram *application* you are going to build.
+    This means that you are able to authorize multiple users or bots with a single API key.
+
+Configuration
+-------------
+
+Having the API key from the previous step in handy, we can now begin to configure a Pyrogram project: pass your API key to Pyrogram by using the *api_id* and *api_hash* parameters of the Client class:
+
+.. code-block:: python
+
+    from pyrogram import Client
+
+    api_id = 12345
+    api_hash = "0123456789abcdef0123456789abcdef"
+
+    app = Client("my_account", api_id=api_id, api_hash=api_hash)
\ No newline at end of file
diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst
index 0cdf76507f..450f0d853c 100644
--- a/docs/source/start/updates.rst
+++ b/docs/source/start/updates.rst
@@ -39,10 +39,12 @@ The most elegant way to register a message handler is by using the :meth:`~pyrog
 
     app = Client("my_account")
 
+
     @app.on_message()
     async def my_handler(client, message):
         await message.forward("me")
 
+
     app.run()
 
 The defined function ``my_handler``, which accepts the two arguments *(client, message)*, will be the function that gets
@@ -63,9 +65,11 @@ function and registers it in your Client. It is useful in case you want to progr
     from pyrogram import Client
     from pyrogram.handlers import MessageHandler
 
+
     async def my_function(client, message):
         await message.forward("me")
 
+
     app = Client("my_account")
 
     my_handler = MessageHandler(my_function)
diff --git a/docs/source/topics/config-file.rst b/docs/source/topics/config-file.rst
deleted file mode 100644
index 1657625acd..0000000000
--- a/docs/source/topics/config-file.rst
+++ /dev/null
@@ -1,97 +0,0 @@
-Configuration File
-==================
-
-As already mentioned in previous pages, Pyrogram can be configured by the use of an INI file.
-This page explains how this file is structured, how to use it and why.
-
-.. contents:: Contents
-    :backlinks: none
-    :depth: 1
-    :local:
-
------
-
-Introduction
-------------
-
-The idea behind using a configuration file is to help keeping your code free of private settings information such as
-the API Key and Proxy, without having you to deal with how to load such settings. The configuration file, usually
-referred as ``config.ini`` file, is automatically loaded from the root of your working directory; all you need to do is
-fill in the necessary parts.
-
-.. note::
-
-    The configuration file is optional, but recommended. If, for any reason, you prefer not to use it, there's always an
-    alternative way to configure Pyrogram via Client's parameters. Doing so, you can have full control on how to store
-    and load your settings.
-
-    Settings specified via Client's parameter have higher priority and will override any setting stored in the
-    configuration file.
-
-
-The config.ini File
--------------------
-
-By default, Pyrogram will look for a file named ``config.ini`` placed at the root of your working directory, that is,
-the same folder of your running script. You can change the name or location of your configuration file by specifying it
-in your Client's parameter *config_file*.
-
--   Replace the default *config.ini* file with *my_configuration.ini*:
-
-    .. code-block:: python
-
-        from pyrogram import Client
-
-        app = Client("my_account", config_file="my_configuration.ini")
-
-
-Configuration Sections
-----------------------
-
-These are all the sections Pyrogram uses in its configuration file:
-
-Pyrogram
-^^^^^^^^
-
-The ``[pyrogram]`` section contains your Telegram API credentials: *api_id* and *api_hash*.
-
-.. code-block:: ini
-
-    [pyrogram]
-    api_id = 12345
-    api_hash = 0123456789abcdef0123456789abcdef
-
-`More info about API Key. <../intro/setup#api-keys>`_
-
-Proxy
-^^^^^
-
-The ``[proxy]`` section contains settings about your SOCKS5 proxy.
-
-.. code-block:: ini
-
-    [proxy]
-    enabled = True
-    hostname = 11.22.33.44
-    port = 1080
-    username = 
-    password = 
-
-`More info about SOCKS5 Proxy. `_
-
-Plugins
-^^^^^^^
-
-The ``[plugins]`` section contains settings about Smart Plugins.
-
-.. code-block:: ini
-
-    [plugins]
-    root = plugins
-    include =
-        module
-        folder.module
-    exclude =
-        module fn2
-
-`More info about Smart Plugins. `_
diff --git a/docs/source/topics/proxy.rst b/docs/source/topics/proxy.rst
index 7d7e2c88db..74e054bc26 100644
--- a/docs/source/topics/proxy.rst
+++ b/docs/source/topics/proxy.rst
@@ -1,8 +1,8 @@
-SOCKS5 Proxy
-============
+Proxy Settings
+==============
 
 Pyrogram supports proxies with and without authentication. This feature allows Pyrogram to exchange data with Telegram
-through an intermediate SOCKS5 proxy server.
+through an intermediate SOCKS 4/5 or HTTP (CONNECT) proxy server.
 
 .. contents:: Contents
     :backlinks: none
@@ -14,44 +14,22 @@ through an intermediate SOCKS5 proxy server.
 Usage
 -----
 
--  To use Pyrogram with a proxy, simply append the following to your ``config.ini`` file and replace the values
-   with your own settings:
+To use Pyrogram with a proxy, use the *proxy* parameter in the Client class. If your proxy doesn't require authorization
+you can omit ``username`` and ``password``.
 
-   .. code-block:: ini
+.. code-block:: python
 
-       [proxy]
-       enabled = True
-       hostname = 11.22.33.44
-       port = 1080
-       username = 
-       password = 
+   from pyrogram import Client
 
-   To enable or disable the proxy without deleting your settings from the config file,
-   change the ``enabled`` value as follows:
-
-      -   ``1``, ``yes``, ``True`` or ``on``: Enables the proxy
-      -   ``0``, ``no``, ``False`` or ``off``: Disables the proxy
-
--  Alternatively, you can setup your proxy without the need of the ``config.ini`` file by using the *proxy* parameter
-   in the Client class:
-
-   .. code-block:: python
-
-       from pyrogram import Client
-
-       app = Client(
-           session_name="example",
-           proxy=dict(
-               hostname="11.22.33.44",
-               port=1080,
-               username="",
-               password=""
-           )
+   app = Client(
+       "my_account",
+       proxy=dict(
+           scheme="socks5",  # "socks4", "socks5" and "http" are supported
+           hostname="11.22.33.44",
+           port=1234,
+           username="",
+           password=""
        )
+   )
 
-       app.start()
-
-       ...
-
-.. note:: If your proxy doesn't require authorization you can omit ``username`` and ``password`` by either leaving the
-   values blank/empty or completely delete the lines.
\ No newline at end of file
+   app.run()
diff --git a/docs/source/topics/use-filters.rst b/docs/source/topics/use-filters.rst
index eda6d7addc..62e94d27c8 100644
--- a/docs/source/topics/use-filters.rst
+++ b/docs/source/topics/use-filters.rst
@@ -57,11 +57,11 @@ operators ``~``, ``&`` and ``|``:
 
 Here are some examples:
 
--   Message is a **text** message **and** is **not edited**.
+-   Message is a **text** message **or** a **photo**.
 
     .. code-block:: python
 
-        @app.on_message(filters.text & ~filters.edited)
+        @app.on_message(filters.text | filters.photo)
         def my_handler(client, message):
             print(message)
 
diff --git a/pyrogram/client.py b/pyrogram/client.py
index 525ecf4a51..19ee051082 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -27,7 +27,6 @@
 import sys
 import tempfile
 from concurrent.futures.thread import ThreadPoolExecutor
-from configparser import ConfigParser
 from hashlib import sha256
 from importlib import import_module
 from io import StringIO
@@ -76,38 +75,37 @@ class Client(Methods):
             pass here as argument.
 
         api_id (``int`` | ``str``, *optional*):
-            The *api_id* part of your Telegram API Key, as integer. E.g.: "12345".
-            This is an alternative way to pass it if you don't want to use the *config.ini* file.
+            The *api_id* part of your Telegram API key, as integer.
+            E.g.: 12345.
 
         api_hash (``str``, *optional*):
-            The *api_hash* part of your Telegram API Key, as string. E.g.: "0123456789abcdef0123456789abcdef".
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
+            The *api_hash* part of your Telegram API key, as string.
+            E.g.: "0123456789abcdef0123456789abcdef".
 
         app_version (``str``, *optional*):
-            Application version. Defaults to "Pyrogram |version|".
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
+            Application version.
+            Defaults to "Pyrogram x.y.z".
 
         device_model (``str``, *optional*):
-            Device model. Defaults to *platform.python_implementation() + " " + platform.python_version()*.
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
+            Device model.
+            Defaults to *platform.python_implementation() + " " + platform.python_version()*.
 
         system_version (``str``, *optional*):
-            Operating System version. Defaults to *platform.system() + " " + platform.release()*.
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
+            Operating System version.
+            Defaults to *platform.system() + " " + platform.release()*.
 
         lang_code (``str``, *optional*):
-            Code of the language used on the client, in ISO 639-1 standard. Defaults to "en".
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
+            Code of the language used on the client, in ISO 639-1 standard.
+            Defaults to "en".
 
         ipv6 (``bool``, *optional*):
             Pass True to connect to Telegram using IPv6.
             Defaults to False (IPv4).
 
         proxy (``dict``, *optional*):
-            Your SOCKS5 Proxy settings as dict,
-            e.g.: *dict(hostname="11.22.33.44", port=1080, username="user", password="pass")*.
+            The Proxy settings as dict.
+            E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*.
             The *username* and *password* can be omitted if your proxy doesn't require authorization.
-            This is an alternative way to setup a proxy if you don't want to use the *config.ini* file.
 
         test_mode (``bool``, *optional*):
             Enable or disable login to the test servers.
@@ -117,7 +115,6 @@ class Client(Methods):
         bot_token (``str``, *optional*):
             Pass your Bot API token to create a bot session, e.g.: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
             Only applicable for new sessions.
-            This is an alternative way to set it if you don't want to use the *config.ini* file.
 
         phone_number (``str``, *optional*):
             Pass your phone number as string (with your Country Code prefix included) to avoid entering it manually.
@@ -131,11 +128,6 @@ class Client(Methods):
             Pass your Two-Step Verification password as string (if you have one) to avoid entering it manually.
             Only applicable for new sessions.
 
-        force_sms (``bool``, *optional*):
-            Pass True to force Telegram sending the authorization code via SMS.
-            Only applicable for new sessions.
-            Defaults to False.
-
         workers (``int``, *optional*):
             Number of maximum concurrent workers for handling incoming updates.
             Defaults to ``min(32, os.cpu_count() + 4)``.
@@ -145,13 +137,8 @@ class Client(Methods):
             will store your session files.
             Defaults to the parent directory of the main script.
 
-        config_file (``str``, *optional*):
-            Path of the configuration file.
-            Defaults to ./config.ini
-
         plugins (``dict``, *optional*):
             Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*.
-            This is an alternative way to setup plugins if you don't want to use the *config.ini* file.
 
         parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
             The parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
@@ -194,7 +181,6 @@ class Client(Methods):
     INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:joinchat/|\+))([\w-]+)$")
     WORKERS = min(32, (os.cpu_count() or 0) + 4)  # os.cpu_count() can be None
     WORKDIR = PARENT_DIR
-    CONFIG_FILE = PARENT_DIR / "config.ini"
 
     mimetypes = MimeTypes()
     mimetypes.readfp(StringIO(mime_types))
@@ -204,10 +190,10 @@ def __init__(
         session_name: Union[str, Storage],
         api_id: int = None,
         api_hash: str = None,
-        app_version: str = None,
-        device_model: str = None,
-        system_version: str = None,
-        lang_code: str = None,
+        app_version: str = APP_VERSION,
+        device_model: str = DEVICE_MODEL,
+        system_version: str = SYSTEM_VERSION,
+        lang_code: str = LANG_CODE,
         ipv6: bool = False,
         proxy: dict = None,
         test_mode: bool = False,
@@ -215,10 +201,8 @@ def __init__(
         phone_number: str = None,
         phone_code: str = None,
         password: str = None,
-        force_sms: bool = False,
         workers: int = WORKERS,
         workdir: str = WORKDIR,
-        config_file: str = CONFIG_FILE,
         plugins: dict = None,
         parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
         no_updates: bool = None,
@@ -236,17 +220,14 @@ def __init__(
         self.system_version = system_version
         self.lang_code = lang_code
         self.ipv6 = ipv6
-        # TODO: Make code consistent, use underscore for private/protected fields
-        self._proxy = proxy
+        self.proxy = proxy
         self.test_mode = test_mode
         self.bot_token = bot_token
         self.phone_number = phone_number
         self.phone_code = phone_code
         self.password = password
-        self.force_sms = force_sms
         self.workers = workers
         self.workdir = Path(workdir)
-        self.config_file = Path(config_file)
         self.plugins = plugins
         self.parse_mode = parse_mode
         self.no_updates = no_updates
@@ -295,29 +276,19 @@ def __enter__(self):
         return self.start()
 
     def __exit__(self, *args):
-        self.stop()
+        try:
+            self.stop()
+        except ConnectionError:
+            pass
 
     async def __aenter__(self):
         return await self.start()
 
     async def __aexit__(self, *args):
-        await self.stop()
-
-    @property
-    def proxy(self):
-        return self._proxy
-
-    @proxy.setter
-    def proxy(self, value):
-        if value is None:
-            self._proxy = None
-            return
-
-        if self._proxy is None:
-            self._proxy = {}
-
-        self._proxy["enabled"] = bool(value.get("enabled", True))
-        self._proxy.update(value)
+        try:
+            await self.stop()
+        except ConnectionError:
+            pass
 
     async def authorize(self) -> User:
         if self.bot_token:
@@ -355,17 +326,14 @@ async def authorize(self) -> User:
             else:
                 break
 
-        if self.force_sms:
-            sent_code = await self.resend_code(self.phone_number, sent_code.phone_code_hash)
+        sent_code_descriptions = {
+            enums.SentCodeType.APP: "Telegram app",
+            enums.SentCodeType.SMS: "SMS",
+            enums.SentCodeType.CALL: "phone call",
+            enums.SentCodeType.FLASH_CALL: "phone flash call"
+        }
 
-        print("The confirmation code has been sent via {}".format(
-            {
-                "app": "Telegram app",
-                "sms": "SMS",
-                "call": "phone call",
-                "flash_call": "phone flash call"
-            }[sent_code.type]
-        ))
+        print(f"The confirmation code has been sent via {sent_code_descriptions[sent_code.type]}")
 
         while True:
             if not self.phone_code:
@@ -615,79 +583,6 @@ async def handle_updates(self, updates):
         elif isinstance(updates, raw.types.UpdatesTooLong):
             log.info(updates)
 
-    def load_config(self):
-        parser = ConfigParser()
-        parser.read(str(self.config_file))
-
-        if self.bot_token:
-            pass
-        else:
-            self.bot_token = parser.get("pyrogram", "bot_token", fallback=None)
-
-        if self.api_id and self.api_hash:
-            pass
-        else:
-            if parser.has_section("pyrogram"):
-                self.api_id = parser.getint("pyrogram", "api_id")
-                self.api_hash = parser.get("pyrogram", "api_hash")
-            else:
-                raise AttributeError("No API Key found. More info: https://docs.pyrogram.org/intro/setup")
-
-        for option in ["app_version", "device_model", "system_version", "lang_code"]:
-            if getattr(self, option):
-                pass
-            else:
-                if parser.has_section("pyrogram"):
-                    setattr(self, option, parser.get(
-                        "pyrogram",
-                        option,
-                        fallback=getattr(Client, option.upper())
-                    ))
-                else:
-                    setattr(self, option, getattr(Client, option.upper()))
-
-        if self._proxy:
-            self._proxy["enabled"] = bool(self._proxy.get("enabled", True))
-        else:
-            self._proxy = {}
-
-            if parser.has_section("proxy"):
-                self._proxy["enabled"] = parser.getboolean("proxy", "enabled", fallback=True)
-                self._proxy["hostname"] = parser.get("proxy", "hostname")
-                self._proxy["port"] = parser.getint("proxy", "port")
-                self._proxy["username"] = parser.get("proxy", "username", fallback=None) or None
-                self._proxy["password"] = parser.get("proxy", "password", fallback=None) or None
-
-        if self.plugins:
-            self.plugins = {
-                "enabled": bool(self.plugins.get("enabled", True)),
-                "root": self.plugins.get("root", None),
-                "include": self.plugins.get("include", []),
-                "exclude": self.plugins.get("exclude", [])
-            }
-        else:
-            try:
-                section = parser["plugins"]
-
-                self.plugins = {
-                    "enabled": section.getboolean("enabled", True),
-                    "root": section.get("root", None),
-                    "include": section.get("include", []),
-                    "exclude": section.get("exclude", [])
-                }
-
-                include = self.plugins["include"]
-                exclude = self.plugins["exclude"]
-
-                if include:
-                    self.plugins["include"] = include.strip().split("\n")
-
-                if exclude:
-                    self.plugins["exclude"] = exclude.strip().split("\n")
-
-            except KeyError:
-                self.plugins = None
-
     async def load_session(self):
         await self.storage.open()
 
@@ -699,6 +594,12 @@ async def load_session(self):
         ])
 
         if session_empty:
+            if not self.api_id or not self.api_hash:
+                raise AttributeError("The API key is required for new authorizations. "
+                                     "More info: https://docs.pyrogram.org/start/auth")
+
+            await self.storage.api_id(self.api_id)
+
             await self.storage.dc_id(2)
             await self.storage.date(0)
 
@@ -711,6 +612,24 @@ async def load_session(self):
             )
             await self.storage.user_id(None)
             await self.storage.is_bot(None)
+        else:
+            # Needed for migration from storage v2 to v3
+            if not await self.storage.api_id():
+                while True:
+                    try:
+                        value = int(await ainput("Enter the api_id part of the API key: "))
+
+                        if value <= 0:
+                            print("Invalid value")
+                            continue
+
+                        confirm = (await ainput(f'Is "{value}" correct? (y/N): ')).lower()
+
+                        if confirm == "y":
+                            await self.storage.api_id(value)
+                            break
+                    except Exception as e:
+                        print(e)
 
     def load_plugins(self):
         if self.plugins:
diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py
index 0b858c0265..5cd67937e5 100644
--- a/pyrogram/connection/transport/tcp/tcp.py
+++ b/pyrogram/connection/transport/tcp/tcp.py
@@ -47,9 +47,8 @@ def __init__(self, ipv6: bool, proxy: dict):
         self.lock = asyncio.Lock()
         self.loop = asyncio.get_event_loop()
 
-        if proxy.get("enabled", False):
-            hostname = proxy.get("hostname", None)
-            port = proxy.get("port", None)
+        if proxy:
+            hostname = proxy.get("hostname")
 
             try:
                 ip_address = ipaddress.ip_address(hostname)
@@ -62,14 +61,14 @@ def __init__(self, ipv6: bool, proxy: dict):
                     self.socket = socks.socksocket(socket.AF_INET)
 
             self.socket.set_proxy(
-                proxy_type=socks.SOCKS5,
+                proxy_type=getattr(socks, proxy.get("scheme").upper()),
                 addr=hostname,
-                port=port,
+                port=proxy.get("port", None),
                 username=proxy.get("username", None),
                 password=proxy.get("password", None)
             )
 
-            log.info(f"Using proxy {hostname}:{port}")
+            log.info(f"Using proxy {hostname}")
         else:
             self.socket = socks.socksocket(
                 socket.AF_INET6 if ipv6
diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py
index 50c85f608e..7d553918a8 100644
--- a/pyrogram/enums/__init__.py
+++ b/pyrogram/enums/__init__.py
@@ -25,6 +25,7 @@
 from .message_media import MessageMedia
 from .message_service import MessageService
 from .messages_filter import MessagesFilter
+from .next_code_type import NextCodeType
 from .parse_mode import ParseMode
 from .poll_type import PollType
 from .sent_code_type import SentCodeType
diff --git a/pyrogram/enums/next_code_type.py b/pyrogram/enums/next_code_type.py
new file mode 100644
index 0000000000..eadaf191a1
--- /dev/null
+++ b/pyrogram/enums/next_code_type.py
@@ -0,0 +1,36 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from .auto_name import AutoName
+
+
+class NextCodeType(AutoName):
+    """Next code type enumeration used in :obj:`~pyrogram.types.SentCode`."""
+
+    CALL = raw.types.auth.CodeTypeCall
+    "The code will be sent via a phone call. A synthesized voice will tell the user which verification code to input."
+
+    FLASH_CALL = raw.types.auth.CodeTypeFlashCall
+    "The code will be sent via a flash phone call, that will be closed immediately."
+
+    MISSED_CALL = raw.types.auth.CodeTypeMissedCall
+    "Missed call."
+
+    SMS = raw.types.auth.CodeTypeSms
+    "The code was sent via SMS."
diff --git a/pyrogram/enums/sent_code_type.py b/pyrogram/enums/sent_code_type.py
index 73ae724cf2..bee9de3fcb 100644
--- a/pyrogram/enums/sent_code_type.py
+++ b/pyrogram/enums/sent_code_type.py
@@ -33,7 +33,7 @@ class SentCodeType(AutoName):
     "The code will be sent via a flash phone call, that will be closed immediately."
 
     MISSED_CALL = raw.types.auth.SentCodeTypeMissedCall
-    "Missed call"
+    "Missed call."
 
     SMS = raw.types.auth.SentCodeTypeSms
     "The code was sent via SMS."
diff --git a/pyrogram/methods/auth/connect.py b/pyrogram/methods/auth/connect.py
index 191a0e9376..612e064bb4 100644
--- a/pyrogram/methods/auth/connect.py
+++ b/pyrogram/methods/auth/connect.py
@@ -37,7 +37,6 @@ async def connect(
         if self.is_connected:
             raise ConnectionError("Client is already connected")
 
-        self.load_config()
         await self.load_session()
 
         self.session = Session(
diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py
index b50bb6d79e..ff643859a7 100644
--- a/pyrogram/session/session.py
+++ b/pyrogram/session/session.py
@@ -113,7 +113,7 @@ async def start(self):
                         raw.functions.InvokeWithLayer(
                             layer=layer,
                             query=raw.functions.InitConnection(
-                                api_id=self.client.api_id,
+                                api_id=await self.client.storage.api_id(),
                                 app_version=self.client.app_version,
                                 device_model=self.client.device_model,
                                 system_version=self.client.system_version,
diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py
index 8ba8910cea..986787cd95 100644
--- a/pyrogram/storage/file_storage.py
+++ b/pyrogram/storage/file_storage.py
@@ -16,8 +16,6 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-import base64
-import json
 import logging
 import os
 import sqlite3
@@ -36,37 +34,6 @@ def __init__(self, name: str, workdir: Path):
 
         self.database = workdir / (self.name + self.FILE_EXTENSION)
 
-    def migrate_from_json(self, session_json: dict):
-        self.open()
-
-        self.dc_id(session_json["dc_id"])
-        self.test_mode(session_json["test_mode"])
-        self.auth_key(base64.b64decode("".join(session_json["auth_key"])))
-        self.user_id(session_json["user_id"])
-        self.date(session_json.get("date", 0))
-        self.is_bot(session_json.get("is_bot", False))
-
-        peers_by_id = session_json.get("peers_by_id", {})
-        peers_by_phone = session_json.get("peers_by_phone", {})
-
-        peers = {}
-
-        for k, v in peers_by_id.items():
-            if v is None:
-                type_ = "group"
-            elif k.startswith("-100"):
-                type_ = "channel"
-            else:
-                type_ = "user"
-
-            peers[int(k)] = [int(k), int(v) if v is not None else None, type_, None, None]
-
-        for k, v in peers_by_phone.items():
-            peers[v][4] = k
-
-        # noinspection PyTypeChecker
-        self.update_peers(peers.values())
-
     def update(self):
         version = self.version()
 
@@ -76,34 +43,18 @@ def update(self):
 
             version += 1
 
+        if version == 2:
+            with self.lock, self.conn:
+                self.conn.execute("ALTER TABLE sessions ADD api_id INTEGER")
+
+            version += 1
+
         self.version(version)
 
     async def open(self):
         path = self.database
         file_exists = path.is_file()
 
-        if file_exists:
-            try:
-                with open(str(path), encoding="utf-8") as f:
-                    session_json = json.load(f)
-            except ValueError:
-                pass
-            else:
-                log.warning("JSON session storage detected! Converting it into an SQLite session storage...")
-
-                path.rename(path.name + ".OLD")
-
-                log.warning(f'The old session file has been renamed to "{path.name}.OLD"')
-
-                self.migrate_from_json(session_json)
-
-                log.warning("Done! The session has been successfully converted from JSON to SQLite storage")
-
-                return
-
-        if Path(path.name + ".OLD").is_file():
-            log.warning(f'Old session file detected: "{path.name}.OLD". You can remove this file now')
-
         self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False)
 
         if not file_exists:
diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py
index 106896f601..f7fbb55bec 100644
--- a/pyrogram/storage/sqlite_storage.py
+++ b/pyrogram/storage/sqlite_storage.py
@@ -31,6 +31,7 @@
 CREATE TABLE sessions
 (
     dc_id     INTEGER PRIMARY KEY,
+    api_id    INTEGER,
     test_mode INTEGER,
     auth_key  BLOB,
     date      INTEGER NOT NULL,
@@ -90,7 +91,7 @@ def get_input_peer(peer_id: int, access_hash: int, peer_type: str):
 
 
 class SQLiteStorage(Storage):
-    VERSION = 2
+    VERSION = 3
     USERNAME_TTL = 8 * 60 * 60
 
     def __init__(self, name: str):
@@ -109,8 +110,8 @@ def create(self):
             )
 
             self.conn.execute(
-                "INSERT INTO sessions VALUES (?, ?, ?, ?, ?, ?)",
-                (2, None, None, 0, None, None)
+                "INSERT INTO sessions VALUES (?, ?, ?, ?, ?, ?, ?)",
+                (2, None, None, None, 0, None, None)
             )
 
     async def open(self):
@@ -195,6 +196,9 @@ def _accessor(self, value: Any = object):
     async def dc_id(self, value: int = object):
         return self._accessor(value)
 
+    async def api_id(self, value: int = object):
+        return self._accessor(value)
+
     async def test_mode(self, value: bool = object):
         return self._accessor(value)
 
diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py
index 578dee1755..8daaae7e88 100644
--- a/pyrogram/storage/storage.py
+++ b/pyrogram/storage/storage.py
@@ -59,6 +59,9 @@ async def get_peer_by_phone_number(self, phone_number: str):
     async def dc_id(self, value: int = object):
         raise NotImplementedError
 
+    async def api_id(self, value: int = object):
+        raise NotImplementedError
+
     async def test_mode(self, value: bool = object):
         raise NotImplementedError
 
diff --git a/pyrogram/types/authorization/sent_code.py b/pyrogram/types/authorization/sent_code.py
index b0ac9eebc6..2b29bb3af4 100644
--- a/pyrogram/types/authorization/sent_code.py
+++ b/pyrogram/types/authorization/sent_code.py
@@ -31,7 +31,7 @@ class SentCode(Object):
             Confirmation code identifier useful for the next authorization steps (either
             :meth:`~pyrogram.Client.sign_in` or :meth:`~pyrogram.Client.sign_up`).
 
-        next_type (:obj:`~pyrogram.enums.SentCodeType`, *optional*):
+        next_type (:obj:`~pyrogram.enums.NextCodeType`, *optional*):
             Type of the next code to be sent with :meth:`~pyrogram.Client.resend_code`.
 
         timeout (``int``, *optional*):
@@ -42,7 +42,7 @@ def __init__(
         self, *,
         type: "enums.SentCodeType",
         phone_code_hash: str,
-        next_type: "enums.SentCodeType" = None,
+        next_type: "enums.NextCodeType" = None,
         timeout: int = None
     ):
         super().__init__()
@@ -57,6 +57,6 @@ def _parse(sent_code: raw.types.auth.SentCode) -> "SentCode":
         return SentCode(
             type=enums.SentCodeType(type(sent_code.type)),
             phone_code_hash=sent_code.phone_code_hash,
-            next_type=enums.SentCodeType(type(sent_code.next_type)) if sent_code.next_type else None,
+            next_type=enums.NextCodeType(type(sent_code.next_type)) if sent_code.next_type else None,
             timeout=sent_code.timeout
         )

From 6fa4cdff150b1997e7f539bad497eca73cabe7ab Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 161/539] Fix user mentions for deleted accounts

---
 pyrogram/types/user_and_chats/user.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index ff32e97336..666c72675d 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -195,7 +195,11 @@ def __init__(
 
     @property
     def mention(self):
-        return Link(f"tg://user?id={self.id}", self.first_name, self._client.parse_mode)
+        return Link(
+            f"tg://user?id={self.id}",
+            self.first_name or "Deleted Account",
+            self._client.parse_mode
+        )
 
     @staticmethod
     def _parse(client, user: "raw.base.User") -> Optional["User"]:

From 9be3818486d9c2226984e9bb86807a396219d7a0 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 162/539] Add new function compose

---
 compiler/docs/compiler.py             |  2 +-
 compiler/docs/template/methods.rst    |  7 ++-
 pyrogram/__init__.py                  |  2 +-
 pyrogram/methods/utilities/compose.py | 62 +++++++++++++++++++++++++++
 pyrogram/methods/utilities/run.py     |  2 +
 pyrogram/sync.py                      |  7 ++-
 6 files changed, 76 insertions(+), 6 deletions(-)
 create mode 100644 pyrogram/methods/utilities/compose.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 91bbad3810..cce4f76945 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -339,7 +339,7 @@ def get_title_list(s: str) -> list:
                     f2.write(title + "\n" + "=" * len(title) + "\n\n")
                     f2.write(".. automethod:: pyrogram.Client.{}()".format(method))
 
-            functions = ["idle"]
+            functions = ["idle", "compose"]
 
             for func in functions:
                 with open(root + "/{}.rst".format(func), "w") as f2:
diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst
index 794e657e4c..1620350de8 100644
--- a/compiler/docs/template/methods.rst
+++ b/compiler/docs/template/methods.rst
@@ -1,8 +1,9 @@
 Available Methods
 =================
 
-This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance.
-Some other utility functions can instead be found in the main package directly.
+This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance,
+except for :meth:`~pyrogram.idle()` and :meth:`~pyrogram.compose()`, which are special functions that can be found in
+the main package directly.
 
 .. code-block:: python
 
@@ -40,11 +41,13 @@ Utilities
     :nosignatures:
 
     idle
+    compose
 
 .. toctree::
     :hidden:
 
     idle
+    compose
 
 .. currentmodule:: pyrogram.Client
 
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index bcef9c1d98..1b8202ce62 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -37,6 +37,6 @@ class ContinuePropagation(StopAsyncIteration):
 
 from . import raw, types, filters, handlers, emoji, enums
 from .client import Client
-from .sync import idle
+from .sync import idle, compose
 
 crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker")
diff --git a/pyrogram/methods/utilities/compose.py b/pyrogram/methods/utilities/compose.py
new file mode 100644
index 0000000000..c8bdf76956
--- /dev/null
+++ b/pyrogram/methods/utilities/compose.py
@@ -0,0 +1,62 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import List
+
+import pyrogram
+from .idle import idle
+
+
+async def compose(clients: List["pyrogram.Client"]):
+    """Run multiple clients at once.
+
+    This method can be used to run multiple clients at once and can be found directly in the ``pyrogram`` package.
+
+    If you want to run a single client, you can use Client's bound method :meth:`~pyrogram.Client.run`.
+
+    Parameters:
+        clients (List of :obj:`~pyrogram.Client`):
+            A list of client objects to run.
+
+    Example:
+        .. code-block:: python
+
+            import asyncio
+            from pyrogram import Client, compose
+
+
+            async def main():
+                app1 = Client("account1")
+                app2 = Client("account2")
+                app3 = Client("account3")
+
+                ...
+
+                await compose([app1, app2, app3])
+
+
+            asyncio.run(main())
+
+    """
+    for c in clients:
+        await c.start()
+
+    await idle()
+
+    for c in clients:
+        await c.stop()
diff --git a/pyrogram/methods/utilities/run.py b/pyrogram/methods/utilities/run.py
index e3890355a9..ec1bece320 100644
--- a/pyrogram/methods/utilities/run.py
+++ b/pyrogram/methods/utilities/run.py
@@ -38,6 +38,8 @@ def run(
         operation. This is almost the same as :py:obj:`asyncio.run` except for the fact that Pyrogram's ``run`` uses the
         current event loop instead of a new one.
 
+        If you want to run multiple clients at once, see :meth:`pyrogram.compose`.
+
         Parameters:
             coroutine (``Coroutine``, *optional*):
                 Pass a coroutine to run it until it completes.
diff --git a/pyrogram/sync.py b/pyrogram/sync.py
index 41c23e3b80..94c82a3dd6 100644
--- a/pyrogram/sync.py
+++ b/pyrogram/sync.py
@@ -23,7 +23,7 @@
 
 from pyrogram import types
 from pyrogram.methods import Methods
-from pyrogram.methods.utilities import idle as idle_module
+from pyrogram.methods.utilities import idle as idle_module, compose as compose_module
 
 
 def async_to_sync(obj, name):
@@ -105,6 +105,9 @@ def wrap(source):
     if inspect.isclass(cls):
         wrap(cls)
 
-# Special case for idle, because it's not inside Methods
+# Special case for idle and compose, because they are not inside Methods
 async_to_sync(idle_module, "idle")
 idle = getattr(idle_module, "idle")
+
+async_to_sync(compose_module, "compose")
+compose = getattr(compose_module, "compose")

From 7fa091719c74a5a70a193287edb32db374612363 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 163/539] Add documentation page about synchronous usage

---
 docs/source/index.rst              | 12 +++--
 docs/source/topics/synchronous.rst | 73 ++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 4 deletions(-)
 create mode 100644 docs/source/topics/synchronous.rst

diff --git a/docs/source/index.rst b/docs/source/index.rst
index 89a8ae890a..c3f5d35252 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -69,8 +69,11 @@ How the Documentation is Organized
 ----------------------------------
 
 Contents are organized into sections composed of self-contained topics which can be all accessed from the sidebar, or by
-following them in order using the :guilabel:`Next` button at the end of each page. Here below you can, instead, find a
-list of the most relevant pages for a quick access.
+following them in order using the :guilabel:`Next` button at the end of each page.
+You can also switch to Dark or Light theme or leave on Auto (follows system preferences) by using the dedicated button
+in the top left corner.
+
+Here below you can, instead, find a list of the most relevant pages for a quick access.
 
 First Steps
 ^^^^^^^^^^^
@@ -144,11 +147,12 @@ Meta
     topics/use-filters
     topics/create-filters
     topics/more-on-updates
-    topics/smart-plugins
     topics/client-settings
+    topics/synchronous
+    topics/text-formatting
     topics/tgcrypto
+    topics/smart-plugins
     topics/storage-engines
-    topics/text-formatting
     topics/serializing
     topics/proxy
     topics/scheduling
diff --git a/docs/source/topics/synchronous.rst b/docs/source/topics/synchronous.rst
new file mode 100644
index 0000000000..e082f18c48
--- /dev/null
+++ b/docs/source/topics/synchronous.rst
@@ -0,0 +1,73 @@
+Synchronous Usage
+=================
+
+Pyrogram is an asynchronous framework and as such it is subject to the asynchronous rules. It can, however, run in
+synchronous mode (also known as non-asynchronous or sync/non-async for short). This mode exists mainly as a convenience
+way for invoking methods without the need of ``async``/``await`` keywords and the extra boilerplate, but **it's not the
+intended way to use the framework**.
+
+You can use Pyrogram in this synchronous mode when you want to write something short and contained without the
+async boilerplate or in case you want to combine Pyrogram with other libraries that are not async.
+
+.. warning::
+
+    You have to be very careful when using the framework in its synchronous, non-native form, especially when combined
+    with other non-async libraries because thread blocking operations that clog the asynchronous event loop underneath
+    will make the program run erratically.
+
+.. contents:: Contents
+    :backlinks: none
+    :depth: 1
+    :local:
+
+-----
+
+Synchronous Invocations
+-----------------------
+
+The following is a standard example of running asynchronous functions with Python's asyncio.
+Pyrogram is being used inside the main function with its asynchronous interface.
+
+.. code-block:: python
+
+    import asyncio
+    from pyrogram import Client
+
+
+    async def main():
+        app = Client("my_account")
+
+        async with app:
+            await app.send_message("me", "Hi!")
+
+
+    asyncio.run(main())
+
+To run Pyrogram synchronously, use the non-async context manager as shown in the following example.
+As you can see, the non-async example becomes less cluttered.
+
+.. code-block:: python
+
+    from pyrogram import Client
+
+    app = Client("my_account")
+
+    with app:
+        app.send_message("me", "Hi!")
+
+Synchronous handlers
+--------------------
+
+You can also have synchronous handlers; you only need to define the callback function without using ``async def`` and
+invoke API methods by not placing ``await`` in front of them. Mixing ``def`` and ``async def`` handlers together is also
+possible.
+
+.. code-block:: python
+
+    @app.on_message()
+    async def handler1(client, message):
+        await message.forward("me")
+
+    @app.on_edited_message()
+    def handler2(client, message):
+        message.forward("me")

From d14665ad960ae9ee68981a029253c53c3669e770 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:56:07 +0200
Subject: [PATCH 164/539] Fix text-formatting.rst examples

---
 docs/source/topics/text-formatting.rst | 36 ++++++++++++++------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst
index df3589a948..8ad2b4db61 100644
--- a/docs/source/topics/text-formatting.rst
+++ b/docs/source/topics/text-formatting.rst
@@ -44,14 +44,10 @@ list of the basic styles currently supported by Pyrogram.
       fixed-width
         code block
 
-.. note::
-
-    User text mentions are only guaranteed to work if you have already met the user (in groups or private chats).
-
 Markdown Style
 --------------
 
-To strictly use this mode, pass "markdown" to the *parse_mode* parameter when using
+To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the *parse_mode* parameter when using
 :meth:`~pyrogram.Client.send_message`. Use the following syntax in your message:
 
 .. code-block:: text
@@ -82,6 +78,8 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us
 
 .. code-block:: python
 
+    from pyrogram import enums
+
     app.send_message(
         "me",
         (
@@ -97,14 +95,14 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us
             "    print(i)"
             "```"
         ),
-        parse_mode="markdown"
+        parse_mode=enums.ParseMode.MARKDOWN
     )
 
 HTML Style
 ----------
 
-To strictly use this mode, pass "html" to the *parse_mode* parameter when using :meth:`~pyrogram.Client.send_message`.
-The following tags are currently supported:
+To strictly use this mode, pass :obj:`~pyrogram.enums.HTML` to the *parse_mode* parameter when using
+:meth:`~pyrogram.Client.send_message`. The following tags are currently supported:
 
 .. code-block:: text
 
@@ -134,6 +132,8 @@ The following tags are currently supported:
 
 .. code-block:: python
 
+    from pyrogram import enums
+
     app.send_message(
         "me",
         (
@@ -149,7 +149,7 @@ The following tags are currently supported:
             "    print(i)"
             "
" ), - parse_mode="html" + parse_mode=enums.ParseMode.HTML ) .. note:: @@ -186,12 +186,14 @@ Result: **bold**, *italic* If you don't like this behaviour you can always choose to only enable either Markdown or HTML in strict mode by passing -"markdown" or "html" as argument to the *parse_mode* parameter. +:obj:`~pyrogram.enums.MARKDOWN` or :obj:`~pyrogram.enums.HTML` as argument to the *parse_mode* parameter. + +.. code-block:: python -.. code-block:: + from pyrogram import enums - app.send_message("me", "**bold**, italic", parse_mode="markdown") - app.send_message("me", "**bold**, italic", parse_mode="html") + app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.MARKDOWN) + app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.HTML) Result: @@ -199,12 +201,14 @@ Result: \*\*bold**, *italic* -In case you want to completely turn off the style parser, simply pass ``None`` to *parse_mode*. The text will be sent -as-is. +In case you want to completely turn off the style parser, simply pass :obj:`~pyrogram.enums.DISABLED` to *parse_mode*. +The text will be sent as-is. .. code-block:: python - app.send_message("me", "**bold**, italic", parse_mode=None) + from pyrogram import enums + + app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.DISABLED) Result: From 8af17c3ed5ed9ff760152eae059813cb120e1698 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 165/539] Documentation improvements --- README.md | 2 +- compiler/docs/compiler.py | 3 +++ compiler/docs/template/toctree.txt | 2 ++ docs/Makefile | 3 +-- docs/source/conf.py | 10 +++++----- docs/source/index.rst | 17 +++-------------- docs/source/topics/serializing.rst | 4 +--- 7 files changed, 16 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 455908676c..764526769f 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ If you'd like to support Pyrogram, you can consider: - **Ready**: Install Pyrogram with pip and start building your applications right away. - **Easy**: Makes the Telegram API simple and intuitive, while still allowing advanced usages. - **Elegant**: Low-level details are abstracted and re-presented in a more convenient way. -- **Fast**: Boosted up by [TgCrypto](https://github.com/pyrogram/tgcrypto), a high-performance crypto library written in pure C. +- **Fast**: Boosted up by [TgCrypto](https://github.com/pyrogram/tgcrypto), a high-performance cryptography library written in C. - **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. - **Async**: Fully asynchronous (also usable synchronously if wanted, for convenience). - **Powerful**: Full access to Telegram's API to execute any official client action and more. diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index cce4f76945..dd857fc31f 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -21,6 +21,8 @@ import re import shutil +import pyrogram + HOME = "compiler/docs" DESTINATION = "docs/source/telegram" PYROGRAM_API_DEST = "docs/source/api" @@ -112,6 +114,7 @@ def build(path, level=0): toctree.format( title=k.title(), title_markup="=" * len(k), + layer=pyrogram.raw.all.layer, module=module, entities="\n ".join(entities) ) diff --git a/compiler/docs/template/toctree.txt b/compiler/docs/template/toctree.txt index 717276c40e..cc2ca9ac22 100644 --- a/compiler/docs/template/toctree.txt +++ b/compiler/docs/template/toctree.txt @@ -1,6 +1,8 @@ {title} {title_markup} +Layer {layer} + .. module:: {module} .. toctree:: diff --git a/docs/Makefile b/docs/Makefile index 8eacc12a4d..c94d48ccac 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -21,5 +21,4 @@ help: lhtml: # live html sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \ - --watch ../pyrogram \ - -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) + --watch ../pyrogram -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) diff --git a/docs/source/conf.py b/docs/source/conf.py index cb273c070f..3071cdc17b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -49,7 +49,7 @@ source_suffix = ".rst" autodoc_member_order = "bysource" -templates_path = ["_resources/templates"] +templates_path = ["../resources/templates"] html_copy_source = False napoleon_use_rtype = False @@ -63,7 +63,7 @@ html_title = "Pyrogram Documentation" html_theme = "sphinx_rtd_theme" -html_static_path = ["_resources/static"] +html_static_path = ["../resources/static"] html_show_sourcelink = True html_show_copyright = False html_theme_options = { @@ -75,11 +75,11 @@ "style_external_links": True } -html_logo = "_resources/static/img/pyrogram.png" -html_favicon = "_resources/static/img/favicon.ico" +html_logo = "../resources/static/img/pyrogram.png" +html_favicon = "../resources/static/img/favicon.ico" latex_engine = "xelatex" -latex_logo = "_resources/static/img/pyrogram.png" +latex_logo = "../resources/static/img/pyrogram.png" latex_elements = { "pointsize": "12pt", diff --git a/docs/source/index.rst b/docs/source/index.rst index c3f5d35252..93605f064c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -14,8 +14,8 @@ Welcome to Pyrogram Telegram MTProto API Framework for Python
- - Development + + Website @@ -54,17 +54,6 @@ If you'd like to support Pyrogram, you can consider: - `Become a LiberaPay patron `_. - `Become an OpenCollective backer `_. -Key Features ------------- - -- **Ready**: Install Pyrogram with pip and start building your applications right away. -- **Easy**: Makes the Telegram API simple and intuitive, while still allowing advanced usages. -- **Elegant**: Low-level details are abstracted and re-presented in a more convenient way. -- **Fast**: Boosted up by :doc:`TgCrypto `, a high-performance crypto library written in pure C. -- **Type-hinted**: Types and methods are all type-hinted, enabling excellent editor support. -- **Async**: Fully asynchronous (also usable synchronously if wanted, for convenience). -- **Powerful**: Full access to Telegram's API to execute any official client action and more. - How the Documentation is Organized ---------------------------------- @@ -172,7 +161,7 @@ Meta .. toctree:: :hidden: - :caption: Telegram API + :caption: Telegram Raw API telegram/functions/index telegram/types/index diff --git a/docs/source/topics/serializing.rst b/docs/source/topics/serializing.rst index e12e3f0511..6a8082b147 100644 --- a/docs/source/topics/serializing.rst +++ b/docs/source/topics/serializing.rst @@ -15,9 +15,7 @@ humans and another more compact for machines that is able to recover the origina For Humans - str(obj) --------------------- -If you want a nicely formatted, human readable JSON representation of any object in the API -- namely, any object from -:doc:`Pyrogram types <../api/types/index>`, :doc:`raw functions <../telegram/functions/index>` and -:doc:`raw types <../telegram/types/index>` -- you can use ``str(obj)``. +If you want a nicely formatted, human readable JSON representation of any object in the API you can use ``str(obj)``. .. code-block:: python From 296b866234ad0eb0ebccbc5d8e68958877302321 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 166/539] Improve performance by adding a message cache --- pyrogram/client.py | 21 +++++++++++++++ .../bots_and_keyboards/callback_query.py | 10 +++++-- pyrogram/types/messages_and_media/message.py | 26 +++++++++++++------ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 19ee051082..79168a93b4 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -270,6 +270,8 @@ def __init__( # Username used for mentioned bot commands, e.g.: /start@usernamebot self.username = None + self.message_cache = Cache(10000) + self.loop = asyncio.get_event_loop() def __enter__(self): @@ -989,3 +991,22 @@ def guess_mime_type(self, filename: str) -> Optional[str]: def guess_extension(self, mime_type: str) -> Optional[str]: return self.mimetypes.guess_extension(mime_type) + + +class Cache: + def __init__(self, capacity: int): + self.capacity = capacity + self.store = {} + + def __getitem__(self, key): + return self.store.get(key, None) + + def __setitem__(self, key, value): + if key in self.store: + del self.store[key] + + self.store[key] = value + + if len(self.store) > self.capacity: + for _ in range(self.capacity // 2 + 1): + del self.store[next(iter(self.store))] diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py index 8c96d6cc61..dc4741b264 100644 --- a/pyrogram/types/bots_and_keyboards/callback_query.py +++ b/pyrogram/types/bots_and_keyboards/callback_query.py @@ -89,12 +89,18 @@ def __init__( self.matches = matches @staticmethod - async def _parse(client, callback_query, users) -> "CallbackQuery": + async def _parse(client: "pyrogram.Client", callback_query, users) -> "CallbackQuery": message = None inline_message_id = None if isinstance(callback_query, raw.types.UpdateBotCallbackQuery): - message = await client.get_messages(utils.get_peer_id(callback_query.peer), callback_query.msg_id) + chat_id = utils.get_peer_id(callback_query.peer) + message_id = callback_query.msg_id + + message = client.message_cache[(chat_id, message_id)] + + if not message: + message = await client.get_messages(chat_id, message_id) elif isinstance(callback_query, raw.types.UpdateInlineBotCallbackQuery): inline_message_id = b64encode( pack( diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 0c639e359c..ec5eed51dd 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -445,7 +445,7 @@ def __init__( @staticmethod async def _parse( - client, + client: "pyrogram.Client", message: raw.base.Message, users: dict, chats: dict, @@ -592,6 +592,8 @@ async def _parse( except MessageIdsEmpty: pass + client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message + return parsed_message if isinstance(message, raw.types.Message): @@ -802,18 +804,26 @@ async def _parse( ) if message.reply_to: + parsed_message.reply_to_message_id = message.reply_to.reply_to_msg_id + parsed_message.reply_to_top_message_id = message.reply_to.reply_to_top_id + if replies: try: - parsed_message.reply_to_message = await client.get_messages( - parsed_message.chat.id, - reply_to_message_ids=message.id, - replies=replies - 1 - ) + key = (parsed_message.chat.id, parsed_message.reply_to_message_id) + reply_to_message = client.message_cache[key] + + if not reply_to_message: + reply_to_message = await client.get_messages( + parsed_message.chat.id, + reply_to_message_ids=message.id, + replies=replies - 1 + ) + + parsed_message.reply_to_message = reply_to_message except MessageIdsEmpty: pass - parsed_message.reply_to_message_id = message.reply_to.reply_to_msg_id - parsed_message.reply_to_top_message_id = message.reply_to.reply_to_top_id + client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message return parsed_message From bd11767e887601f20f69378fc02da73eb3fc50f5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 167/539] Use a shorter __license__ string --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 1b8202ce62..e4c8bcf356 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . __version__ = "1.4.16" -__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" +__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " from concurrent.futures.thread import ThreadPoolExecutor From a34ee4b444af8a870f8c21147c374d7394ebddb9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 168/539] Update index.rst --- docs/source/index.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index 93605f064c..b7c5241f15 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -18,6 +18,10 @@ Welcome to Pyrogram Website • + + Development + + • Releases From 5c0806a8a94079809c54899170fd4c3bfb652325 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 169/539] Add __repr__ to enumerations --- pyrogram/enums/auto_name.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/enums/auto_name.py b/pyrogram/enums/auto_name.py index b1d10d1077..b43fa74180 100644 --- a/pyrogram/enums/auto_name.py +++ b/pyrogram/enums/auto_name.py @@ -22,3 +22,6 @@ class AutoName(Enum): def _generate_next_value_(self, *args): return self.lower() + + def __repr__(self): + return f"pyrogram.enums.{self}" From 6eadb75086d12d30e795fc6a2e2ec8a96d38ed4c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 170/539] Recursively bind when using Object.bind() --- pyrogram/types/object.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py index caf18373e1..8b6a5b99bf 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -29,7 +29,7 @@ def __init__(self, client: "pyrogram.Client" = None): self._client = client def bind(self, client: "pyrogram.Client"): - """Bind a Client instance to this Pyrogram Object + """Recursively bind a Client instance to this and to all nested Pyrogram objects. Parameters: client (:obj:`~pyrogram.types.Client`): @@ -38,6 +38,12 @@ def bind(self, client: "pyrogram.Client"): """ self._client = client + for i in self.__dict__: + o = getattr(self, i) + + if isinstance(o, Object): + o.bind(client) + @staticmethod def default(obj: "Object"): if isinstance(obj, bytes): From 4cb9dec35dc3722f893f3b8443ef988a617db4d5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 171/539] Remove remaining iter_* methods --- compiler/docs/compiler.py | 6 +- pyrogram/methods/chats/__init__.py | 2 - pyrogram/methods/chats/get_dialogs.py | 109 +++++++++--------- pyrogram/methods/chats/iter_dialogs.py | 106 ----------------- pyrogram/methods/users/__init__.py | 10 +- ...t_profile_photos.py => get_chat_photos.py} | 82 +++++++------ ...otos_count.py => get_chat_photos_count.py} | 8 +- pyrogram/methods/users/iter_profile_photos.py | 82 ------------- 8 files changed, 110 insertions(+), 295 deletions(-) delete mode 100644 pyrogram/methods/chats/iter_dialogs.py rename pyrogram/methods/users/{get_profile_photos.py => get_chat_photos.py} (64%) rename pyrogram/methods/users/{get_profile_photos_count.py => get_chat_photos_count.py} (92%) delete mode 100644 pyrogram/methods/users/iter_profile_photos.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index dd857fc31f..9d1b743460 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -213,7 +213,6 @@ def get_title_list(s: str) -> list: get_chat_members get_chat_members_count get_dialogs - iter_dialogs get_dialogs_count set_chat_username get_nearby_chats @@ -238,9 +237,8 @@ def get_title_list(s: str) -> list: Users get_me get_users - get_profile_photos - get_profile_photos_count - iter_profile_photos + get_chat_photos + get_chat_photos_count set_profile_photo delete_profile_photos set_username diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 1b744a0569..a2bdde08a4 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -36,7 +36,6 @@ from .get_dialogs_count import GetDialogsCount from .get_nearby_chats import GetNearbyChats from .get_send_as_chats import GetSendAsChats -from .iter_dialogs import IterDialogs from .join_chat import JoinChat from .leave_chat import LeaveChat from .mark_chat_unread import MarkChatUnread @@ -76,7 +75,6 @@ class Chats( UnpinChatMessage, GetDialogs, GetChatMembersCount, - IterDialogs, SetChatUsername, SetChatPermissions, GetDialogsCount, diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py index f888c3ef4c..2869a6a1ed 100644 --- a/pyrogram/methods/chats/get_dialogs.py +++ b/pyrogram/methods/chats/get_dialogs.py @@ -16,92 +16,87 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import logging -from datetime import datetime -from typing import List +from typing import AsyncGenerator, Optional import pyrogram -from pyrogram import raw -from pyrogram import types -from pyrogram import utils - -log = logging.getLogger(__name__) +from pyrogram import types, raw, utils class GetDialogs: async def get_dialogs( self: "pyrogram.Client", - offset_date: datetime = datetime.fromtimestamp(0), - limit: int = 100, - pinned_only: bool = False - ) -> List["types.Dialog"]: - """Get a chunk of the user's dialogs. - - You can get up to 100 dialogs at once. - For a more convenient way of getting a user's dialogs see :meth:`~pyrogram.Client.iter_dialogs`. + limit: int = 0 + ) -> Optional[AsyncGenerator["types.Dialog", None]]: + """Get a user's dialogs sequentially. Parameters: - offset_date (:py:obj:`~datetime.datetime`): - The offset date taken from the top message of a :obj:`~pyrogram.types.Dialog`. - Defaults to epoch. Valid for non-pinned dialogs only. - - limit (``str``, *optional*): + limit (``int``, *optional*): Limits the number of dialogs to be retrieved. - Defaults to 100. Valid for non-pinned dialogs only. - - pinned_only (``bool``, *optional*): - Pass True if you want to get only pinned dialogs. - Defaults to False. + By default, no limit is applied and all dialogs are returned. Returns: - List of :obj:`~pyrogram.types.Dialog`: On success, a list of dialogs is returned. + ``Generator``: A generator yielding :obj:`~pyrogram.types.Dialog` objects. Example: .. code-block:: python - # Get first 100 dialogs - await app.get_dialogs() - - # Get pinned dialogs - await app.get_dialogs(pinned_only=True) + # Iterate through all dialogs + async for dialog in app.get_dialogs(): + print(dialog.chat.first_name or dialog.chat.title) """ + current = 0 + total = limit or (1 << 31) - 1 + limit = min(100, total) - if pinned_only: - r = await self.invoke( - raw.functions.messages.GetPinnedDialogs(folder_id=0), - sleep_threshold=60 - ) - else: + offset_date = 0 + offset_id = 0 + offset_peer = raw.types.InputPeerEmpty() + + while True: r = await self.invoke( raw.functions.messages.GetDialogs( - offset_date=utils.datetime_to_timestamp(offset_date), - offset_id=0, - offset_peer=raw.types.InputPeerEmpty(), + offset_date=offset_date, + offset_id=offset_id, + offset_peer=offset_peer, limit=limit, - hash=0, - exclude_pinned=True + hash=0 ), sleep_threshold=60 ) - users = {i.id: i for i in r.users} - chats = {i.id: i for i in r.chats} + 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, raw.types.MessageEmpty): + continue + + chat_id = utils.get_peer_id(message.peer_id) + messages[chat_id] = await types.Message._parse(self, message, users, chats) + + dialogs = [] + + for dialog in r.dialogs: + if not isinstance(dialog, raw.types.Dialog): + continue - messages = {} + dialogs.append(types.Dialog._parse(self, dialog, messages, users, chats)) - for message in r.messages: - if isinstance(message, raw.types.MessageEmpty): - continue + if not dialogs: + return - chat_id = utils.get_peer_id(message.peer_id) - messages[chat_id] = await types.Message._parse(self, message, users, chats) + last = dialogs[-1] - parsed_dialogs = [] + offset_id = last.top_message.id + offset_date = utils.datetime_to_timestamp(last.top_message.date) + offset_peer = await self.resolve_peer(last.chat.id) - for dialog in r.dialogs: - if not isinstance(dialog, raw.types.Dialog): - continue + for dialog in dialogs: + yield dialog - parsed_dialogs.append(types.Dialog._parse(self, dialog, messages, users, chats)) + current += 1 - return types.List(parsed_dialogs) + if current >= total: + return diff --git a/pyrogram/methods/chats/iter_dialogs.py b/pyrogram/methods/chats/iter_dialogs.py deleted file mode 100644 index d0f037bea0..0000000000 --- a/pyrogram/methods/chats/iter_dialogs.py +++ /dev/null @@ -1,106 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# -# 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 typing import AsyncGenerator, Optional - -import pyrogram -from pyrogram import types, raw, utils - - -class IterDialogs: - async def iter_dialogs( - self: "pyrogram.Client", - limit: int = 0 - ) -> Optional[AsyncGenerator["types.Dialog", None]]: - """Iterate through a user's dialogs sequentially. - - This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_dialogs` in a loop, - thus saving you from the hassle of setting up boilerplate code. It is useful for getting the whole dialogs list - with a single call. - - Parameters: - limit (``int``, *optional*): - Limits the number of dialogs to be retrieved. - By default, no limit is applied and all dialogs are returned. - - Returns: - ``Generator``: A generator yielding :obj:`~pyrogram.types.Dialog` objects. - - Example: - .. code-block:: python - - # Iterate through all dialogs - async for dialog in app.iter_dialogs(): - print(dialog.chat.first_name or dialog.chat.title) - """ - current = 0 - total = limit or (1 << 31) - 1 - limit = min(100, total) - - offset_date = 0 - offset_id = 0 - offset_peer = raw.types.InputPeerEmpty() - - while True: - r = (await self.invoke( - raw.functions.messages.GetDialogs( - offset_date=offset_date, - offset_id=offset_id, - offset_peer=offset_peer, - limit=limit, - hash=0 - ), - sleep_threshold=60 - )) - - 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, raw.types.MessageEmpty): - continue - - chat_id = utils.get_peer_id(message.peer_id) - messages[chat_id] = await types.Message._parse(self, message, users, chats) - - dialogs = [] - - for dialog in r.dialogs: - if not isinstance(dialog, raw.types.Dialog): - continue - - dialogs.append(types.Dialog._parse(self, dialog, messages, users, chats)) - - if not dialogs: - return - - last = dialogs[-1] - - offset_id = last.top_message.id - offset_date = last.top_message.date - offset_peer = await self.resolve_peer(last.chat.id) - - for dialog in dialogs: - yield dialog - - current += 1 - - if current >= total: - return diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py index 6cd81bc363..2ed719e8fc 100644 --- a/pyrogram/methods/users/__init__.py +++ b/pyrogram/methods/users/__init__.py @@ -18,12 +18,11 @@ from .block_user import BlockUser from .delete_profile_photos import DeleteProfilePhotos +from .get_chat_photos import GetChatPhotos +from .get_chat_photos_count import GetChatPhotosCount from .get_common_chats import GetCommonChats from .get_me import GetMe -from .get_profile_photos import GetProfilePhotos -from .get_profile_photos_count import GetProfilePhotosCount from .get_users import GetUsers -from .iter_profile_photos import IterProfilePhotos from .set_profile_photo import SetProfilePhoto from .set_username import SetUsername from .unblock_user import UnblockUser @@ -33,14 +32,13 @@ class Users( BlockUser, GetCommonChats, - GetProfilePhotos, + GetChatPhotos, SetProfilePhoto, DeleteProfilePhotos, GetUsers, GetMe, SetUsername, - GetProfilePhotosCount, - IterProfilePhotos, + GetChatPhotosCount, UnblockUser, UpdateProfile, ): diff --git a/pyrogram/methods/users/get_profile_photos.py b/pyrogram/methods/users/get_chat_photos.py similarity index 64% rename from pyrogram/methods/users/get_profile_photos.py rename to pyrogram/methods/users/get_chat_photos.py index ba20c89ce1..d3bc1f1feb 100644 --- a/pyrogram/methods/users/get_profile_photos.py +++ b/pyrogram/methods/users/get_chat_photos.py @@ -16,22 +16,19 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union, List +from typing import Union, AsyncGenerator, Optional import pyrogram -from pyrogram import raw -from pyrogram import types -from pyrogram import utils +from pyrogram import types, raw, utils -class GetProfilePhotos: - async def get_profile_photos( +class GetChatPhotos: + async def get_chat_photos( self: "pyrogram.Client", chat_id: Union[int, str], - offset: int = 0, - limit: int = 100 - ) -> List["types.Photo"]: - """Get a list of profile pictures for a user or a chat. + limit: int = 0, + ) -> Optional[AsyncGenerator["types.Photo", None]]: + """Get a chat or a user profile photos sequentially. Parameters: chat_id (``int`` | ``str``): @@ -39,28 +36,18 @@ async def get_profile_photos( For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - offset (``int``, *optional*): - Sequential number of the first photo to be returned. - By default, all photos are returned. - limit (``int``, *optional*): - Limits the number of photos to be retrieved. - Values between 1—100 are accepted. Defaults to 100. + Limits the number of profile photos to be retrieved. + By default, no limit is applied and all profile photos are returned. Returns: - List of :obj:`~pyrogram.types.Photo`: On success, a list of profile photos is returned. + ``Generator``: A generator yielding :obj:`~pyrogram.types.Photo` objects. Example: .. code-block:: python - # Get the first 100 profile photos of a user - await app.get_profile_photos("me") - - # Get only the first profile photo of a user - await app.get_profile_photos("me", limit=1) - - # Get 3 profile photos of a user, skip the first 5 - await app.get_profile_photos("me", limit=3, offset=5) + async for photo in app.get_chat_photos("me"): + print(photo) """ peer_id = await self.resolve_peer(chat_id) @@ -105,15 +92,42 @@ async def get_profile_photos( else: photos = [] - return types.List(photos[offset:limit]) + current = 0 + + for photo in photos: + yield photo + + current += 1 + + if current >= limit: + return else: - r = await self.invoke( - raw.functions.photos.GetUserPhotos( - user_id=peer_id, - offset=offset, - max_id=0, - limit=limit + current = 0 + total = limit or (1 << 31) + limit = min(100, total) + offset = 0 + + while True: + r = await self.invoke( + raw.functions.photos.GetUserPhotos( + user_id=peer_id, + offset=offset, + max_id=0, + limit=limit + ) ) - ) - return types.List(types.Photo._parse(self, photo) for photo in r.photos) + photos = [types.Photo._parse(self, photo) for photo in r.photos] + + if not photos: + return + + offset += len(photos) + + for photo in photos: + yield photo + + current += 1 + + if current >= total: + return diff --git a/pyrogram/methods/users/get_profile_photos_count.py b/pyrogram/methods/users/get_chat_photos_count.py similarity index 92% rename from pyrogram/methods/users/get_profile_photos_count.py rename to pyrogram/methods/users/get_chat_photos_count.py index 4c0fe5d5f0..eca186a820 100644 --- a/pyrogram/methods/users/get_profile_photos_count.py +++ b/pyrogram/methods/users/get_chat_photos_count.py @@ -22,12 +22,12 @@ from pyrogram import raw -class GetProfilePhotosCount: - async def get_profile_photos_count( +class GetChatPhotosCount: + async def get_chat_photos_count( self: "pyrogram.Client", chat_id: Union[int, str] ) -> int: - """Get the total count of profile pictures for a user. + """Get the total count of photos for a chat. Parameters: chat_id (``int`` | ``str``): @@ -41,7 +41,7 @@ async def get_profile_photos_count( Example: .. code-block:: python - count = await app.get_profile_photos_count("me") + count = await app.get_chat_photos_count("me") print(count) """ diff --git a/pyrogram/methods/users/iter_profile_photos.py b/pyrogram/methods/users/iter_profile_photos.py deleted file mode 100644 index 6665bc9bda..0000000000 --- a/pyrogram/methods/users/iter_profile_photos.py +++ /dev/null @@ -1,82 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# -# 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 typing import Union, AsyncGenerator, Optional - -import pyrogram -from pyrogram import types - - -class IterProfilePhotos: - async def iter_profile_photos( - self: "pyrogram.Client", - chat_id: Union[int, str], - offset: int = 0, - limit: int = 0, - ) -> Optional[AsyncGenerator["types.Photo", None]]: - """Iterate through a chat or a user profile photos sequentially. - - This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_profile_photos` in a - loop, thus saving you from the hassle of setting up boilerplate code. It is useful for getting all the profile - photos with a single call. - - Parameters: - chat_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). - - limit (``int``, *optional*): - Limits the number of profile photos to be retrieved. - By default, no limit is applied and all profile photos are returned. - - offset (``int``, *optional*): - Sequential number of the first profile photo to be returned. - - Returns: - ``Generator``: A generator yielding :obj:`~pyrogram.types.Photo` objects. - - Example: - .. code-block:: python - - async for photo in app.iter_profile_photos("me"): - print(photo) - """ - current = 0 - total = limit or (1 << 31) - limit = min(100, total) - - while True: - photos = await self.get_profile_photos( - chat_id=chat_id, - offset=offset, - limit=limit - ) - - if not photos: - return - - offset += len(photos) - - for photo in photos: - yield photo - - current += 1 - - if current >= total: - return From 0d054fa9bc820c85c345a0b9016d1cc23a2e334e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 172/539] Update index.rst --- 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 b7c5241f15..5ee12b7ec2 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -15,7 +15,7 @@ Welcome to Pyrogram
- Website + Homepage From 01ca652f8c814c68b50d824685a37c9ce665f627 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 173/539] Add support for in-memory downloads --- pyrogram/client.py | 242 +++++++++---------- pyrogram/methods/messages/download_media.py | 37 ++- pyrogram/types/messages_and_media/message.py | 7 + 3 files changed, 152 insertions(+), 134 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 79168a93b4..f727658de2 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -29,10 +29,10 @@ from concurrent.futures.thread import ThreadPoolExecutor from hashlib import sha256 from importlib import import_module -from io import StringIO +from io import StringIO, BytesIO from mimetypes import MimeTypes from pathlib import Path -from typing import Union, List, Optional, Callable +from typing import Union, List, Optional, Callable, BinaryIO import pyrogram from pyrogram import __version__, __license__ @@ -482,34 +482,6 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra return is_min - async def handle_download(self, packet): - temp_file_path = "" - final_file_path = "" - - try: - file_id, directory, file_name, file_size, progress, progress_args = packet - - temp_file_path = await self.get_file( - file_id=file_id, - file_size=file_size, - progress=progress, - progress_args=progress_args - ) - - if temp_file_path: - final_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) - os.makedirs(directory, exist_ok=True) - shutil.move(temp_file_path, final_file_path) - except Exception as e: - log.error(e, exc_info=True) - - try: - os.remove(temp_file_path) - except OSError: - pass - else: - return final_file_path or None - async def handle_updates(self, updates): if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): is_min = (await self.fetch_peers(updates.users)) or (await self.fetch_peers(updates.chats)) @@ -747,13 +719,41 @@ def load_plugins(self): else: log.warning(f'[{self.session_name}] No plugin loaded from "{root}"') + async def handle_download(self, packet): + file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet + + file = await self.get_file( + file_id=file_id, + file_size=file_size, + in_memory=in_memory, + progress=progress, + progress_args=progress_args + ) + + if file and not in_memory: + file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + os.makedirs(directory, exist_ok=True) + shutil.move(file.name, file_path) + + try: + file.close() + except FileNotFoundError: + pass + + return file_path + + if file and in_memory: + file.name = file_name + return file + async def get_file( self, file_id: FileId, file_size: int, + in_memory: bool, progress: Callable, progress_args: tuple = () - ) -> str: + ) -> Optional[BinaryIO]: dc_id = file_id.dc_id async with self.media_sessions_lock: @@ -838,7 +838,8 @@ async def get_file( limit = 1024 * 1024 offset = 0 - file_name = "" + + file = BytesIO() if in_memory else tempfile.NamedTemporaryFile("wb") try: r = await session.invoke( @@ -851,43 +852,40 @@ async def get_file( ) if isinstance(r, raw.types.upload.File): - with tempfile.NamedTemporaryFile("wb", delete=False) as f: - file_name = f.name - - while True: - chunk = r.bytes - - f.write(chunk) + while True: + chunk = r.bytes - offset += limit + file.write(chunk) - if progress: - func = functools.partial( - progress, - min(offset, file_size) - if file_size != 0 - else offset, - file_size, - *progress_args - ) - - if inspect.iscoroutinefunction(progress): - await func() - else: - await self.loop.run_in_executor(self.executor, func) + offset += limit - if len(chunk) < limit: - break - - r = await session.invoke( - raw.functions.upload.GetFile( - location=location, - offset=offset, - limit=limit - ), - sleep_threshold=30 + if progress: + func = functools.partial( + progress, + min(offset, file_size) + if file_size != 0 + else offset, + file_size, + *progress_args ) + if inspect.iscoroutinefunction(progress): + await func() + else: + await self.loop.run_in_executor(self.executor, func) + + if len(chunk) < limit: + break + + r = await session.invoke( + raw.functions.upload.GetFile( + location=location, + offset=offset, + limit=limit + ), + sleep_threshold=30 + ) + elif isinstance(r, raw.types.upload.FileCdnRedirect): async with self.media_sessions_lock: cdn_session = self.media_sessions.get(r.dc_id, None) @@ -903,88 +901,82 @@ async def get_file( self.media_sessions[r.dc_id] = cdn_session try: - with tempfile.NamedTemporaryFile("wb", delete=False) as f: - file_name = f.name - - while True: - r2 = await cdn_session.invoke( - raw.functions.upload.GetCdnFile( - file_token=r.file_token, - offset=offset, - limit=limit - ) + while True: + r2 = await cdn_session.invoke( + raw.functions.upload.GetCdnFile( + file_token=r.file_token, + offset=offset, + limit=limit ) + ) - if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded): - try: - await session.invoke( - raw.functions.upload.ReuploadCdnFile( - file_token=r.file_token, - request_token=r2.request_token - ) + if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded): + try: + await session.invoke( + raw.functions.upload.ReuploadCdnFile( + file_token=r.file_token, + request_token=r2.request_token ) - except VolumeLocNotFound: - break - else: - continue - - chunk = r2.bytes - - # https://core.telegram.org/cdn#decrypting-files - decrypted_chunk = aes.ctr256_decrypt( - chunk, - r.encryption_key, - bytearray( - r.encryption_iv[:-4] - + (offset // 16).to_bytes(4, "big") ) + except VolumeLocNotFound: + break + else: + continue + + chunk = r2.bytes + + # https://core.telegram.org/cdn#decrypting-files + decrypted_chunk = aes.ctr256_decrypt( + chunk, + r.encryption_key, + bytearray( + r.encryption_iv[:-4] + + (offset // 16).to_bytes(4, "big") ) + ) - hashes = await session.invoke( - raw.functions.upload.GetCdnFileHashes( - file_token=r.file_token, - offset=offset - ) + hashes = await session.invoke( + raw.functions.upload.GetCdnFileHashes( + file_token=r.file_token, + offset=offset ) + ) - # https://core.telegram.org/cdn#verifying-files - for i, h in enumerate(hashes): - cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] - CDNFileHashMismatch.check(h.hash == sha256(cdn_chunk).digest()) + # https://core.telegram.org/cdn#verifying-files + for i, h in enumerate(hashes): + cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] + CDNFileHashMismatch.check(h.hash == sha256(cdn_chunk).digest()) - f.write(decrypted_chunk) + file.write(decrypted_chunk) - offset += limit + offset += limit - if progress: - func = functools.partial( - progress, - min(offset, file_size) if file_size != 0 else offset, - file_size, - *progress_args - ) + if progress: + func = functools.partial( + progress, + min(offset, file_size) if file_size != 0 else offset, + file_size, + *progress_args + ) - if inspect.iscoroutinefunction(progress): - await func() - else: - await self.loop.run_in_executor(self.executor, func) + if inspect.iscoroutinefunction(progress): + await func() + else: + await self.loop.run_in_executor(self.executor, func) - if len(chunk) < limit: - break + if len(chunk) < limit: + break except Exception as e: raise e except Exception as e: if not isinstance(e, pyrogram.StopTransmission): log.error(e, exc_info=True) - try: - os.remove(file_name) - except OSError: - pass + file.close() - return "" + return None else: - return file_name + return file def guess_mime_type(self, filename: str) -> Optional[str]: return self.mimetypes.guess_type(filename)[0] diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py index 8b587d2fae..d46bd50391 100644 --- a/pyrogram/methods/messages/download_media.py +++ b/pyrogram/methods/messages/download_media.py @@ -18,9 +18,8 @@ import asyncio import os -import time from datetime import datetime -from typing import Union, Optional, Callable +from typing import Union, Optional, Callable, BinaryIO import pyrogram from pyrogram import types @@ -34,10 +33,11 @@ async def download_media( self: "pyrogram.Client", message: Union["types.Message", str], file_name: str = DEFAULT_DOWNLOAD_DIR, + in_memory: bool = False, block: bool = True, progress: Callable = None, progress_args: tuple = () - ) -> Optional[str]: + ) -> Optional[Union[str, BinaryIO]]: """Download the media from a message. Parameters: @@ -51,6 +51,11 @@ async def download_media( 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. + in_memory (``bool``, *optional*): + Pass True to download the media in-memory. + A binary file-like object with its attribute ".name" set will be returned. + Defaults to False. + block (``bool``, *optional*): Blocks the code execution until the file has been downloaded. Defaults to True. @@ -78,14 +83,17 @@ async def download_media( You can either keep ``*args`` or add every single extra argument in your function signature. Returns: - ``str`` | ``None``: On success, the absolute path of the downloaded file is returned, otherwise, in case - the download failed or was deliberately stopped with :meth:`~pyrogram.Client.stop_transmission`, None is - returned. + ``str`` | ``None`` | ``BinaryIO``: On success, the absolute path of the downloaded file is returned, + otherwise, in case the download failed or was deliberately stopped with + :meth:`~pyrogram.Client.stop_transmission`, None is returned. + Otherwise, in case ``in_memory=True``, a binary file-like object with its attribute ".name" set is returned. Raises: ValueError: if the message doesn't contain any downloadable media Example: + Download media to file + .. code-block:: python # Download from Message @@ -99,6 +107,15 @@ async def progress(current, total): print(f"{current * 100 / total:.1f}%") await app.download_media(message, progress=progress) + + Download media in-memory + + .. code-block:: python + + file = await app.download_media(message, in_memory=True) + + file_name = file.name + file_bytes = bytes(file.getbuffer()) """ available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note", "new_chat_photo") @@ -125,7 +142,7 @@ async def progress(current, total): media_file_name = getattr(media, "file_name", "") file_size = getattr(media, "file_size", 0) mime_type = getattr(media, "mime_type", "") - date = getattr(media, "date", 0) + date = getattr(media, "date", None) directory, file_name = os.path.split(file_name) file_name = file_name or media_file_name or "" @@ -153,12 +170,14 @@ async def progress(current, total): file_name = "{}_{}_{}{}".format( FileType(file_id_obj.file_type).name.lower(), - datetime.fromtimestamp(date or time.time()).strftime("%Y-%m-%d_%H-%M-%S"), + (date or datetime.now()).strftime("%Y-%m-%d_%H-%M-%S"), self.rnd_id(), extension ) - downloader = self.handle_download((file_id_obj, directory, file_name, file_size, progress, progress_args)) + downloader = self.handle_download( + (file_id_obj, directory, file_name, in_memory, file_size, progress, progress_args) + ) if block: return await downloader diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index ec5eed51dd..b7b26805c4 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3329,6 +3329,7 @@ async def retract_vote( async def download( self, file_name: str = "", + in_memory: bool = False, block: bool = True, progress: Callable = None, progress_args: tuple = () @@ -3353,6 +3354,11 @@ async def download( 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. + in_memory (``bool``, *optional*): + Pass True to download the media in-memory. + A binary file-like object with its attribute ".name" set will be returned. + Defaults to False. + block (``bool``, *optional*): Blocks the code execution until the file has been downloaded. Defaults to True. @@ -3389,6 +3395,7 @@ async def download( return await self._client.download_media( message=self, file_name=file_name, + in_memory=in_memory, block=block, progress=progress, progress_args=progress_args, From b2c4d26ce66807901b7c08bfe2b74e587f8eb0a1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 174/539] Fix Message.download() docstrings --- pyrogram/types/messages_and_media/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index b7b26805c4..3a72fe33eb 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3340,7 +3340,7 @@ async def download( .. code-block:: python - await lient.download_media(message) + await client.download_media(message) Example: .. code-block:: python From 3e33ef0c0d6df837b445e2d35bbdfda79599ac40 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 175/539] Add support for media streams with the method stream_media --- compiler/docs/compiler.py | 1 + pyrogram/client.py | 72 ++++++++---------- pyrogram/methods/messages/__init__.py | 4 +- pyrogram/methods/messages/stream_media.py | 93 +++++++++++++++++++++++ 4 files changed, 130 insertions(+), 40 deletions(-) create mode 100644 pyrogram/methods/messages/stream_media.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 9d1b743460..b5382438cb 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -187,6 +187,7 @@ def get_title_list(s: str) -> list: search_global search_global_count download_media + stream_media get_discussion_message get_discussion_replies get_discussion_replies_count diff --git a/pyrogram/client.py b/pyrogram/client.py index f727658de2..18e5253b1c 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -32,7 +32,7 @@ from io import StringIO, BytesIO from mimetypes import MimeTypes from pathlib import Path -from typing import Union, List, Optional, Callable, BinaryIO +from typing import Union, List, Optional, Callable, AsyncGenerator import pyrogram from pyrogram import __version__, __license__ @@ -722,13 +722,10 @@ def load_plugins(self): async def handle_download(self, packet): file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet - file = await self.get_file( - file_id=file_id, - file_size=file_size, - in_memory=in_memory, - progress=progress, - progress_args=progress_args - ) + file = BytesIO() if in_memory else tempfile.NamedTemporaryFile("wb", delete=False) + + async for chunk in self.get_file(file_id, file_size, 0, 0, progress, progress_args): + file.write(chunk) if file and not in_memory: file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) @@ -749,11 +746,12 @@ async def handle_download(self, packet): async def get_file( self, file_id: FileId, - file_size: int, - in_memory: bool, - progress: Callable, + file_size: int = 0, + limit: int = 0, + offset: int = 0, + progress: Callable = None, progress_args: tuple = () - ) -> Optional[BinaryIO]: + ) -> Optional[AsyncGenerator[bytes, None]]: dc_id = file_id.dc_id async with self.media_sessions_lock: @@ -836,17 +834,17 @@ async def get_file( thumb_size=file_id.thumbnail_size ) - limit = 1024 * 1024 - offset = 0 - - file = BytesIO() if in_memory else tempfile.NamedTemporaryFile("wb") + current = 0 + total = abs(limit) or (1 << 31) - 1 + chunk_size = 1024 * 1024 + offset_bytes = abs(offset) * chunk_size try: r = await session.invoke( raw.functions.upload.GetFile( location=location, - offset=offset, - limit=limit + offset=offset_bytes, + limit=chunk_size ), sleep_threshold=30 ) @@ -855,16 +853,17 @@ async def get_file( while True: chunk = r.bytes - file.write(chunk) + yield chunk - offset += limit + current += 1 + offset_bytes += chunk_size if progress: func = functools.partial( progress, - min(offset, file_size) + min(offset_bytes, file_size) if file_size != 0 - else offset, + else offset_bytes, file_size, *progress_args ) @@ -874,14 +873,14 @@ async def get_file( else: await self.loop.run_in_executor(self.executor, func) - if len(chunk) < limit: + if len(chunk) < chunk_size or current >= total: break r = await session.invoke( raw.functions.upload.GetFile( location=location, - offset=offset, - limit=limit + offset=offset_bytes, + limit=chunk_size ), sleep_threshold=30 ) @@ -905,8 +904,8 @@ async def get_file( r2 = await cdn_session.invoke( raw.functions.upload.GetCdnFile( file_token=r.file_token, - offset=offset, - limit=limit + offset=offset_bytes, + limit=chunk_size ) ) @@ -931,14 +930,14 @@ async def get_file( r.encryption_key, bytearray( r.encryption_iv[:-4] - + (offset // 16).to_bytes(4, "big") + + (offset_bytes // 16).to_bytes(4, "big") ) ) hashes = await session.invoke( raw.functions.upload.GetCdnFileHashes( file_token=r.file_token, - offset=offset + offset=offset_bytes ) ) @@ -947,14 +946,15 @@ async def get_file( cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] CDNFileHashMismatch.check(h.hash == sha256(cdn_chunk).digest()) - file.write(decrypted_chunk) + yield decrypted_chunk - offset += limit + current += 1 + offset_bytes += chunk_size if progress: func = functools.partial( progress, - min(offset, file_size) if file_size != 0 else offset, + min(offset_bytes, file_size) if file_size != 0 else offset_bytes, file_size, *progress_args ) @@ -964,7 +964,7 @@ async def get_file( else: await self.loop.run_in_executor(self.executor, func) - if len(chunk) < limit: + if len(chunk) < chunk_size or current >= total: break except Exception as e: raise e @@ -972,12 +972,6 @@ async def get_file( if not isinstance(e, pyrogram.StopTransmission): log.error(e, exc_info=True) - file.close() - - return None - else: - return file - def guess_mime_type(self, filename: str) -> Optional[str]: return self.mimetypes.guess_type(filename)[0] diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index 0bf34900d0..dafce11e4f 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -61,6 +61,7 @@ from .send_video_note import SendVideoNote from .send_voice import SendVoice from .stop_poll import StopPoll +from .stream_media import StreamMedia from .vote_poll import VotePoll @@ -110,6 +111,7 @@ class Messages( GetDiscussionMessage, SendReaction, GetDiscussionReplies, - GetDiscussionRepliesCount + GetDiscussionRepliesCount, + StreamMedia ): pass diff --git a/pyrogram/methods/messages/stream_media.py b/pyrogram/methods/messages/stream_media.py new file mode 100644 index 0000000000..0daaa55667 --- /dev/null +++ b/pyrogram/methods/messages/stream_media.py @@ -0,0 +1,93 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union, Optional, BinaryIO + +import pyrogram +from pyrogram import types +from pyrogram.file_id import FileId + + +class StreamMedia: + async def stream_media( + self: "pyrogram.Client", + message: Union["types.Message", str], + limit: int = 0, + offset: int = 0 + ) -> Optional[Union[str, BinaryIO]]: + """Stream the media from a message chunk by chunk. + + The chunk size is 1 MiB (1024 * 1024 bytes). + + Parameters: + message (:obj:`~pyrogram.types.Message` | ``str``): + Pass a Message containing the media, the media itself (message.audio, message.video, ...) or a file id + as string. + + limit (``int``, *optional*): + Limit the amount of chunks to stream. + Defaults to 0 (stream the whole media). + + offset (``int``, *optional*): + How many chunks to skip before starting to stream. + Defaults to 0 (start from the beginning). + + Returns: + ``Generator``: A generator yielding bytes chunk by chunk + + Example: + .. code-block:: python + + # Stream the whole media + async for chunk in app.stream_media(message): + print(len(chunk)) + + # Stream the first 3 chunks only + async for chunk in app.stream_media(message, limit=3): + print(len(chunk)) + + # Stream the last 3 chunks only + import math + chunks = math.ceil(message.document.file_size / 1024 / 1024) + async for chunk in app.stream_media(message, offset=chunks - 3): + print(len(chunk)) + """ + available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note", + "new_chat_photo") + + if isinstance(message, types.Message): + for kind in available_media: + media = getattr(message, kind, None) + + if media is not None: + break + else: + raise ValueError("This message doesn't contain any downloadable media") + else: + media = message + + if isinstance(media, str): + file_id_str = media + else: + file_id_str = media.file_id + + file_id_obj = FileId.decode(file_id_str) + file_size = getattr(media, "file_size", 0) + + async for chunk in self.get_file(file_id_obj, file_size, limit, offset): + yield chunk From 394a9adc03941f41d4edaa7ba70133f393bd98ed Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 176/539] Fix type hints --- pyrogram/methods/chats/get_chat_members.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index 065e262c7b..65688a3d71 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . import logging -from typing import Union, List +from typing import Union, Optional, AsyncGenerator import pyrogram from pyrogram import raw, types, enums @@ -64,7 +64,7 @@ async def get_chat_members( query: str = "", limit: int = 0, filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.SEARCH - ) -> List["types.ChatMember"]: + ) -> Optional[AsyncGenerator["types.ChatMember", None]]: """Get the members list of a chat. A chat can be either a basic group, a supergroup or a channel. From 70d5f22e0deb524839588bcf7b2b7d800ecf25be Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 177/539] Some fixes to the documentation --- docs/Makefile | 2 +- docs/source/intro/quickstart.rst | 2 +- docs/source/start/auth.rst | 4 +- docs/source/start/errors.rst | 5 +- docs/source/start/updates.rst | 2 +- docs/source/topics/advanced-usage.rst | 14 ++-- docs/source/topics/client-settings.rst | 16 +---- docs/source/topics/create-filters.rst | 52 ++------------- docs/source/topics/debugging.rst | 2 +- docs/source/topics/more-on-updates.rst | 38 +++++------ docs/source/topics/serializing.rst | 8 +-- docs/source/topics/smart-plugins.rst | 88 +++++--------------------- docs/source/topics/test-servers.rst | 4 +- docs/source/topics/text-formatting.rst | 12 ++-- docs/source/topics/use-filters.rst | 18 +++--- 15 files changed, 75 insertions(+), 192 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index c94d48ccac..066560f8f7 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -21,4 +21,4 @@ help: lhtml: # live html sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \ - --watch ../pyrogram -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) + --watch ../pyrogram --watch resources -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) diff --git a/docs/source/intro/quickstart.rst b/docs/source/intro/quickstart.rst index 72f2dd86b4..cccbfbc76b 100644 --- a/docs/source/intro/quickstart.rst +++ b/docs/source/intro/quickstart.rst @@ -50,7 +50,7 @@ Enjoy the API That was just a quick overview. In the next few pages of the introduction, we'll take a much more in-depth look of what we have just done above. -If you are feeling eager to continue you can take a shortcut to :doc:`Calling Methods <../start/invoking>` and come back +If you are feeling eager to continue you can take a shortcut to :doc:`Invoking Methods <../start/invoking>` and come back later to learn some more details. .. _community: https://t.me/Pyrogram diff --git a/docs/source/start/auth.rst b/docs/source/start/auth.rst index 39a4face94..08c1875ac6 100644 --- a/docs/source/start/auth.rst +++ b/docs/source/start/auth.rst @@ -82,8 +82,8 @@ after the session name, which will be ``my_bot.session`` for the example below. .. note:: - The API key (api_id and api_hash) and the bot_token is not needed anymore after a successful authorization. - This means you can now simply use: + The API key (api_id and api_hash) and the bot_token are not required anymore after a successful authorization. + This means you can now simply use the following: .. code-block:: python diff --git a/docs/source/start/errors.rst b/docs/source/start/errors.rst index 0188107413..402fea8b7c 100644 --- a/docs/source/start/errors.rst +++ b/docs/source/start/errors.rst @@ -25,7 +25,7 @@ This error is raised every time a method call against Telegram's API was unsucce from pyrogram.errors import RPCError -.. note:: +.. warning:: Avoid catching this error everywhere, especially when no feedback is given (i.e. by logging/printing the full error traceback), because it makes it impossible to understand what went wrong. @@ -81,9 +81,6 @@ In case Pyrogram does not know anything about a specific error yet, it raises a for example, an unknown error with error code ``400``, will be raised as a ``BadRequest``. This way you can catch the whole category of errors and be sure to also handle these unknown errors. -In case a whole class of errors is unknown (that is, an error code that is unknown), Pyrogram will raise a special -``520 UnknownError`` exception. - Errors with Values ------------------ diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst index 450f0d853c..685128c21c 100644 --- a/docs/source/start/updates.rst +++ b/docs/source/start/updates.rst @@ -14,7 +14,7 @@ and how to handle new incoming messages or other events in Pyrogram. Defining Updates ---------------- -As hinted already, updates are events that happen in your Telegram account (incoming messages, new members join, +Updates are events that happen in your Telegram account (incoming messages, new members join, bot button presses, etc.), which are meant to notify you about a new specific state that has changed. These updates are handled by registering one or more callback functions in your app using :doc:`Handlers <../api/handlers>`. diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst index c84528e4e1..86eb67c4db 100644 --- a/docs/source/topics/advanced-usage.rst +++ b/docs/source/topics/advanced-usage.rst @@ -50,8 +50,8 @@ Here's some examples: from pyrogram import Client from pyrogram.raw import functions - with Client("my_account") as app: - app.send( + async with Client("my_account") as app: + await app.send( functions.account.UpdateProfile( first_name="First Name", last_name="Last Name", about="New bio text" @@ -65,12 +65,12 @@ Here's some examples: from pyrogram import Client from pyrogram.raw import functions, types - with Client("my_account") as app: + async with Client("my_account") as app: # Set online status - app.send(functions.account.UpdateStatus(offline=False)) + await app.send(functions.account.UpdateStatus(offline=False)) # Set offline status - app.send(functions.account.UpdateStatus(offline=True)) + await app.send(functions.account.UpdateStatus(offline=True)) - Get chat info: @@ -79,8 +79,8 @@ Here's some examples: from pyrogram import Client from pyrogram.raw import functions, types - with Client("my_account") as app: - r = app.send( + async with Client("my_account") as app: + r = await app.send( functions.channels.GetFullChannel( channel=app.resolve_peer("username") ) diff --git a/docs/source/topics/client-settings.rst b/docs/source/topics/client-settings.rst index 1b93d99d7b..02dce71375 100644 --- a/docs/source/topics/client-settings.rst +++ b/docs/source/topics/client-settings.rst @@ -18,16 +18,7 @@ settings. By default you will see something like the following: Set Custom Values ----------------- -To set custom values, you can either make use of the ``config.ini`` file, this way: - -.. code-block:: ini - - [pyrogram] - app_version = 1.2.3 - device_model = PC - system_version = Linux - -Or, pass the arguments directly in the Client's constructor. +To set custom values, you can pass the arguments directly in the Client's constructor. .. code-block:: python @@ -47,11 +38,6 @@ English). With the following code we make Telegram know we want it to speak in Italian (it): -.. code-block:: ini - - [pyrogram] - lang_code = it - .. code-block:: python app = Client( diff --git a/docs/source/topics/create-filters.rst b/docs/source/topics/create-filters.rst index ae7bd5ecf7..f8c05af620 100644 --- a/docs/source/topics/create-filters.rst +++ b/docs/source/topics/create-filters.rst @@ -25,7 +25,7 @@ button: from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton - app.send_message( + await app.send_message( "username", # Change this to your username or id "Pyrogram custom filter test", reply_markup=InlineKeyboardMarkup( @@ -48,40 +48,20 @@ queries containing "pyrogram" as data: from pyrogram import filters - static_data_filter = filters.create(lambda _, __, query: query.data == "pyrogram") - -The first two arguments of the callback function are unused here and because of this we named them using underscores. - -The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example. The same -can be achieved with a normal function, but we don't really need it as it makes sense only inside the filter's scope: - -.. code-block:: python - - from pyrogram import filters - - def func(_, __, query): + async def func(_, __, query): return query.data == "pyrogram" static_data_filter = filters.create(func) -Asynchronous filters are also possible. Sadly, Python itself doesn't have an ``async lambda``, so we are left with -using a named function: - -.. code-block:: python - - from pyrogram import filters - - async def func(_, __, query): - return query.data == "pyrogram" - static_data_filter = filters.create(func) +The first two arguments of the callback function are unused here and because of this we named them using underscores. Finally, the filter usage remains the same: .. code-block:: python @app.on_callback_query(static_data_filter) - def pyrogram_data(_, query): + async def pyrogram_data(_, query): query.answer("it works!") Filters with Arguments @@ -94,18 +74,6 @@ via named arguments. This is how a dynamic custom filter looks like: -.. code-block:: python - - from pyrogram import filters - - def dynamic_data_filter(data): - return filters.create( - lambda flt, _, query: flt.data == query.data, - data=data # "data" kwarg is accessed with "flt.data" above - ) - -And its asynchronous variant: - .. code-block:: python from pyrogram import filters @@ -122,7 +90,7 @@ And finally its usage: .. code-block:: python @app.on_callback_query(dynamic_data_filter("pyrogram")) - def pyrogram_data(_, query): + async def pyrogram_data(_, query): query.answer("it works!") @@ -133,16 +101,6 @@ The missing piece we haven't covered yet is the second argument of a filter call argument. This is a reference to the :obj:`~pyrogram.Client` instance that is running the filter and it is useful in case you would like to make some API calls before deciding whether the filter should allow the update or not: -.. code-block:: python - - def func(_, client, query): - # r = client.some_api_method() - # check response "r" and decide to return True or False - ... - -Asynchronous filters making API calls work fine as well. Just remember that you need to put ``async`` in front of -function definitions and ``await`` in front of method calls: - .. code-block:: python async def func(_, client, query): diff --git a/docs/source/topics/debugging.rst b/docs/source/topics/debugging.rst index 6e6e6d5ed8..1c0ac069f9 100644 --- a/docs/source/topics/debugging.rst +++ b/docs/source/topics/debugging.rst @@ -27,7 +27,7 @@ Consider the following code: .. code-block:: python - me = app.get_users("me") + me = await app.get_users("me") print(me) # User This will show a JSON representation of the object returned by :meth:`~pyrogram.Client.get_users`, which is a diff --git a/docs/source/topics/more-on-updates.rst b/docs/source/topics/more-on-updates.rst index 81a46f3be4..18c1a68af3 100644 --- a/docs/source/topics/more-on-updates.rst +++ b/docs/source/topics/more-on-updates.rst @@ -26,12 +26,12 @@ For example, take these two handlers: .. code-block:: python @app.on_message(filters.text | filters.sticker) - def text_or_sticker(client, message): + async def text_or_sticker(client, message): print("Text or Sticker") @app.on_message(filters.text) - def just_text(client, message): + async def just_text(client, message): print("Just Text") Here, ``just_text`` is never executed because ``text_or_sticker``, which has been registered first, already handles @@ -40,7 +40,7 @@ texts (``filters.text`` is shared and conflicting). To enable it, register the h .. code-block:: python @app.on_message(filters.text, group=1) - def just_text(client, message): + async def just_text(client, message): print("Just Text") Or, if you want ``just_text`` to be executed *before* ``text_or_sticker`` (note ``-1``, which is less than ``0``): @@ -48,7 +48,7 @@ Or, if you want ``just_text`` to be executed *before* ``text_or_sticker`` (note .. code-block:: python @app.on_message(filters.text, group=-1) - def just_text(client, message): + async def just_text(client, message): print("Just Text") With :meth:`~pyrogram.Client.add_handler` (without decorators) the same can be achieved with: @@ -68,17 +68,17 @@ continue to propagate the same update to the next groups until all the handlers .. code-block:: python @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(0) @app.on_message(filters.private, group=1) - def _(client, message): + async def _(client, message): raise Exception("Unhandled exception!") # Simulate an unhandled exception @app.on_message(filters.private, group=2) - def _(client, message): + async def _(client, message): print(2) All these handlers will handle the same kind of messages, that are, messages sent or received in private chats. @@ -110,18 +110,18 @@ Example with ``stop_propagation()``: .. code-block:: python @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(0) @app.on_message(filters.private, group=1) - def _(client, message): + async def _(client, message): print(1) message.stop_propagation() @app.on_message(filters.private, group=2) - def _(client, message): + async def _(client, message): print(2) Example with ``raise StopPropagation``: @@ -131,18 +131,18 @@ Example with ``raise StopPropagation``: from pyrogram import StopPropagation @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(0) @app.on_message(filters.private, group=1) - def _(client, message): + async ef _(client, message): print(1) raise StopPropagation @app.on_message(filters.private, group=2) - def _(client, message): + async def _(client, message): print(2) Each handler is registered in a different group, but the handler in group number 2 will never be executed because the @@ -178,19 +178,19 @@ Example with ``continue_propagation()``: .. code-block:: python @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(0) message.continue_propagation() @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(1) message.continue_propagation() @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(2) Example with ``raise ContinuePropagation``: @@ -200,19 +200,19 @@ Example with ``raise ContinuePropagation``: from pyrogram import ContinuePropagation @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(0) raise ContinuePropagation @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(1) raise ContinuePropagation @app.on_message(filters.private) - def _(client, message): + async def _(client, message): print(2) Three handlers are registered in the same group, and all of them will be executed because the propagation was continued diff --git a/docs/source/topics/serializing.rst b/docs/source/topics/serializing.rst index 6a8082b147..3dc644f880 100644 --- a/docs/source/topics/serializing.rst +++ b/docs/source/topics/serializing.rst @@ -21,8 +21,8 @@ If you want a nicely formatted, human readable JSON representation of any object ... - with app: - r = app.get_chat("me") + async with app: + r = await app.get_chat("me") print(str(r)) .. tip:: @@ -44,8 +44,8 @@ as the process requires the package to be in scope. ... - with app: - r = app.get_chat("me") + async with app: + r = await app.get_chat("me") print(repr(r)) print(eval(repr(r)) == r) # True diff --git a/docs/source/topics/smart-plugins.rst b/docs/source/topics/smart-plugins.rst index a94e3212fe..c378c9d81f 100644 --- a/docs/source/topics/smart-plugins.rst +++ b/docs/source/topics/smart-plugins.rst @@ -33,7 +33,6 @@ after importing your modules, like this: .. code-block:: text myproject/ - config.ini handlers.py main.py @@ -41,12 +40,12 @@ after importing your modules, like this: .. code-block:: python - def echo(client, message): - message.reply(message.text) + async def echo(client, message): + await message.reply(message.text) - def echo_reversed(client, message): - message.reply(message.text[::-1]) + async def echo_reversed(client, message): + await message.reply(message.text[::-1]) - ``main.py`` @@ -84,7 +83,7 @@ Setting up your Pyrogram project to accommodate Smart Plugins is pretty straight #. Create a new folder to store all the plugins (e.g.: "plugins", "handlers", ...). #. Put your python files full of plugins inside. Organize them as you wish. -#. Enable plugins in your Client or via the *config.ini* file. +#. Enable plugins in your Client. .. note:: @@ -95,7 +94,6 @@ Setting up your Pyrogram project to accommodate Smart Plugins is pretty straight myproject/ plugins/ handlers.py - config.ini main.py - ``plugins/handlers.py`` @@ -106,31 +104,16 @@ Setting up your Pyrogram project to accommodate Smart Plugins is pretty straight @Client.on_message(filters.text & filters.private) - def echo(client, message): - message.reply(message.text) + async def echo(client, message): + await message.reply(message.text) @Client.on_message(filters.text & filters.private, group=1) - def echo_reversed(client, message): - message.reply(message.text[::-1]) - -- ``config.ini`` - - .. code-block:: ini - - [plugins] - root = plugins + async def echo_reversed(client, message): + await message.reply(message.text[::-1]) - ``main.py`` - .. code-block:: python - - from pyrogram import Client - - Client("my_account").run() - - Alternatively, without using the *config.ini* file: - .. code-block:: python from pyrogram import Client @@ -144,9 +127,9 @@ The first important thing to note is the new ``plugins`` folder. You can put *an each file can contain *any decorated function* (handlers) with one limitation: within a single module (file) you must use different names for each decorated function. -The second thing is telling Pyrogram where to look for your plugins: you can either use the *config.ini* file or -the Client parameter "plugins"; the *root* value must match the name of your plugins root folder. Your Pyrogram Client -instance will **automatically** scan the folder upon starting to search for valid handlers and register them for you. +The second thing is telling Pyrogram where to look for your plugins: you can use the Client parameter "plugins"; +the *root* value must match the name of your plugins root folder. Your Pyrogram Client instance will **automatically** +scan the folder upon starting to search for valid handlers and register them for you. Then you'll notice you can now use decorators. That's right, you can apply the usual decorators to your callback functions in a static way, i.e. **without having the Client instance around**: simply use ``@Client`` (Client class) @@ -166,7 +149,7 @@ found inside each module will be, instead, loaded in the order they are defined, This default loading behaviour is usually enough, but sometimes you want to have more control on what to include (or exclude) and in which exact order to load plugins. The way to do this is to make use of ``include`` and ``exclude`` -directives, either in the *config.ini* file or in the dictionary passed as Client argument. Here's how they work: +directives in the dictionary passed as Client argument. Here's how they work: - If both ``include`` and ``exclude`` are omitted, all plugins are loaded as described above. - If ``include`` is given, only the specified plugins will be loaded, in the order they are passed. @@ -208,15 +191,6 @@ also organized in subfolders: - Load every handler from every module, namely *plugins0.py*, *plugins1.py* and *plugins2.py* in alphabetical order (files) and definition order (handlers inside files): - Using *config.ini* file: - - .. code-block:: ini - - [plugins] - root = plugins - - Using *Client*'s parameter: - .. code-block:: python plugins = dict(root="plugins") @@ -225,18 +199,6 @@ also organized in subfolders: - Load only handlers defined inside *plugins2.py* and *plugins0.py*, in this order: - Using *config.ini* file: - - .. code-block:: ini - - [plugins] - root = plugins - include = - subfolder2.plugins2 - plugins0 - - Using *Client*'s parameter: - .. code-block:: python plugins = dict( @@ -251,16 +213,6 @@ also organized in subfolders: - Load everything except the handlers inside *plugins2.py*: - Using *config.ini* file: - - .. code-block:: ini - - [plugins] - root = plugins - exclude = subfolder2.plugins2 - - Using *Client*'s parameter: - .. code-block:: python plugins = dict( @@ -272,16 +224,6 @@ also organized in subfolders: - Load only *fn3*, *fn1* and *fn2* (in this order) from *plugins1.py*: - Using *config.ini* file: - - .. code-block:: ini - - [plugins] - root = plugins - include = subfolder1.plugins1 fn3 fn1 fn2 - - Using *Client*'s parameter: - .. code-block:: python plugins = dict( @@ -306,8 +248,8 @@ updates) will be modified in such a way that a special ``handlers`` attribute po .. code-block:: python @Client.on_message(filters.text & filters.private) - def echo(client, message): - message.reply(message.text) + async def echo(client, message): + await message.reply(message.text) print(echo) print(echo.handlers) diff --git a/docs/source/topics/test-servers.rst b/docs/source/topics/test-servers.rst index cba5e709f0..1ccfe286c8 100644 --- a/docs/source/topics/test-servers.rst +++ b/docs/source/topics/test-servers.rst @@ -9,8 +9,8 @@ Telegram's test servers without hassle. All you need to do is start a new sessio from pyrogram import Client - with Client("my_account_test", test_mode=True) as app: - print(app.get_me()) + async with Client("my_account_test", test_mode=True) as app: + print(await app.get_me()) .. note:: diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index 8ad2b4db61..4e11fb7410 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -80,7 +80,7 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the from pyrogram import enums - app.send_message( + await app.send_message( "me", ( "**bold**, " @@ -134,7 +134,7 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.HTML` to the *parse_mode* from pyrogram import enums - app.send_message( + await app.send_message( "me", ( "bold, " @@ -179,7 +179,7 @@ This means you can combine together both syntaxes in the same text: .. code-block:: python - app.send_message("me", "**bold**, italic") + await app.send_message("me", "**bold**, italic") Result: @@ -192,8 +192,8 @@ If you don't like this behaviour you can always choose to only enable either Mar from pyrogram import enums - app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.MARKDOWN) - app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.HTML) + await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.MARKDOWN) + await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.HTML) Result: @@ -208,7 +208,7 @@ The text will be sent as-is. from pyrogram import enums - app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.DISABLED) + await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.DISABLED) Result: diff --git a/docs/source/topics/use-filters.rst b/docs/source/topics/use-filters.rst index 62e94d27c8..ab7296af85 100644 --- a/docs/source/topics/use-filters.rst +++ b/docs/source/topics/use-filters.rst @@ -28,7 +28,7 @@ Let's start right away with a simple example: @app.on_message(filters.sticker) - def my_handler(client, message): + async def my_handler(client, message): print(message) - or, without decorators. Here filters are passed as the second argument of the handler constructor; the first is the @@ -40,7 +40,7 @@ Let's start right away with a simple example: from pyrogram.handlers import MessageHandler - def my_handler(client, message): + async def my_handler(client, message): print(message) @@ -62,7 +62,7 @@ Here are some examples: .. code-block:: python @app.on_message(filters.text | filters.photo) - def my_handler(client, message): + async def my_handler(client, message): print(message) - Message is a **sticker** **and** is coming from a **channel or** a **private** chat. @@ -70,7 +70,7 @@ Here are some examples: .. code-block:: python @app.on_message(filters.sticker & (filters.channel | filters.private)) - def my_handler(client, message): + async def my_handler(client, message): print(message) Advanced Filters @@ -84,7 +84,7 @@ can also accept arguments: .. code-block:: python @app.on_message(filters.command(["start", "help"])) - def my_handler(client, message): + async def my_handler(client, message): print(message) - Message is a **text** message or a media **caption** matching the given **regex** pattern. @@ -92,7 +92,7 @@ can also accept arguments: .. code-block:: python @app.on_message(filters.regex("pyrogram")) - def my_handler(client, message): + async def my_handler(client, message): print(message) More handlers using different filters can also live together. @@ -100,15 +100,15 @@ More handlers using different filters can also live together. .. code-block:: python @app.on_message(filters.command("start")) - def start_command(client, message): + async def start_command(client, message): print("This is the /start command") @app.on_message(filters.command("help")) - def help_command(client, message): + async def help_command(client, message): print("This is the /help command") @app.on_message(filters.chat("PyrogramChat")) - def from_pyrogramchat(client, message): + async def from_pyrogramchat(client, message): print("New message in @PyrogramChat") From e3419f0f3d0b22af2f7a7b00ae77bd1db77a3b92 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 178/539] Add InlineQueryResultContact and InlineQueryResultDocument --- pyrogram/types/inline_mode/__init__.py | 5 +- .../types/inline_mode/inline_query_result.py | 6 +- .../inline_query_result_contact.py | 114 ++++++++++++++ .../inline_query_result_document.py | 145 ++++++++++++++++++ 4 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_contact.py create mode 100644 pyrogram/types/inline_mode/inline_query_result_document.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index c1f5b87f87..25a568f539 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -24,8 +24,11 @@ from .inline_query_result_audio import InlineQueryResultAudio from .inline_query_result_photo import InlineQueryResultPhoto from .inline_query_result_video import InlineQueryResultVideo +from .inline_query_result_contact import InlineQueryResultContact +from .inline_query_result_document import InlineQueryResultDocument __all__ = [ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", - "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult" + "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", + "InlineQueryResultContact", "InlineQueryResultDocument" ] diff --git a/pyrogram/types/inline_mode/inline_query_result.py b/pyrogram/types/inline_mode/inline_query_result.py index 48d633c141..4ea2f7be64 100644 --- a/pyrogram/types/inline_mode/inline_query_result.py +++ b/pyrogram/types/inline_mode/inline_query_result.py @@ -49,8 +49,12 @@ class InlineQueryResult(Object): Pyrogram currently supports results of the following types: - :obj:`~pyrogram.types.InlineQueryResultArticle` - - :obj:`~pyrogram.types.InlineQueryResultPhoto` + - :obj:`~pyrogram.types.InlineQueryResultAudio` - :obj:`~pyrogram.types.InlineQueryResultAnimation` + - :obj:`~pyrogram.types.InlineQueryResultContact` + - :obj:`~pyrogram.types.InlineQueryResultDocument` + - :obj:`~pyrogram.types.InlineQueryResultPhoto` + - :obj:`~pyrogram.types.InlineQueryResultVideo` """ def __init__( diff --git a/pyrogram/types/inline_mode/inline_query_result_contact.py b/pyrogram/types/inline_mode/inline_query_result_contact.py new file mode 100644 index 0000000000..d55a624450 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_contact.py @@ -0,0 +1,114 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw, types +from .inline_query_result import InlineQueryResult + + +class InlineQueryResultContact(InlineQueryResult): + """Contact with a phone number + + By default, this contact will be sent by the user. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the + contact. + + Parameters: + phone_number (``str``): + Contact's phone number. + + first_name (``str``): + Contact's first name. + + last_name (``str``, *optional*): + Contact's last name. + + vcard (``str``, *optional*): + Additional data about the contact in the form of a `vCard `_. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*): + Content of the message to be sent instead of the contact. + + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumb_width (``int``, *optional*): + Thumbnail width. + + thumb_height (``int``, *optional*): + Thumbnail height. + """ + + def __init__( + self, + phone_number: str, + first_name: str, + last_name: str = "", + vcard: str = "", + id: str = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 + ): + super().__init__("contact", id, input_message_content, reply_markup) + + self.phone_number = phone_number + self.first_name = first_name + self.last_name = last_name + self.vcard = vcard + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height + + async def write(self, client: "pyrogram.Client"): + return raw.types.InputBotInlineResult( + id=self.id, + type=self.type, + title=self.first_name, + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaContact( + phone_number=self.phone_number, + first_name=self.first_name, + last_name=self.last_name, + vcard=self.vcard, + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + ) + ), + thumb=raw.types.InputWebDocument( + url=self.thumb_url, + size=0, + mime_type="image/jpg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumb_width, + h=self.thumb_height + ) + ] + ) if self.thumb_url else None + ) diff --git a/pyrogram/types/inline_mode/inline_query_result_document.py b/pyrogram/types/inline_mode/inline_query_result_document.py new file mode 100644 index 0000000000..eac7901b14 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_document.py @@ -0,0 +1,145 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult + + +class InlineQueryResultDocument(InlineQueryResult): + """Link to a file. + + By default, this file will be sent by the user with an optional caption. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the file. + + Parameters: + document_url (``str``): + A valid URL for the file. + + title (``str``): + Title for the result. + + mime_type (``str``, *optional*): + Mime type of the content of the file, either “application/pdf” or “application/zip”. + Defaults to "application/zip". + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + caption (``str``, *optional*): + Caption of the video to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + description (``str``, *optional*): + Short description of the result. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the file. + + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumb_width (``int``, *optional*): + Thumbnail width. + + thumb_height (``int``, *optional*): + Thumbnail height. + """ + + def __init__( + self, + document_url: str, + title: str, + mime_type: str = "application/zip", + id: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + description: str = "", + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 + ): + super().__init__("file", id, input_message_content, reply_markup) + + self.document_url = document_url + self.title = title + self.mime_type = mime_type + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.description = description + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height + + async def write(self, client: "pyrogram.Client"): + document = raw.types.InputWebDocument( + url=self.document_url, + size=0, + mime_type=self.mime_type, + attributes=[] + ) + + thumb = raw.types.InputWebDocument( + url=self.thumb_url, + size=0, + mime_type="image/jpeg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumb_width, + h=self.thumb_height + ) + ] + ) if self.thumb_url else None + + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + return raw.types.InputBotInlineResult( + id=self.id, + type=self.type, + title=self.title, + description=self.description, + thumb=thumb, + content=document, + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From ade31f8989649053c87c8cfb78d00f7f53850edb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 179/539] Update the session string format --- pyrogram/client.py | 67 ++++++++++++++++-------------- pyrogram/storage/memory_storage.py | 33 +++++++++++---- pyrogram/storage/storage.py | 31 +++++++------- 3 files changed, 78 insertions(+), 53 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 18e5253b1c..6b2ac9a1f2 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -49,7 +49,7 @@ from pyrogram.handlers.handler import Handler from pyrogram.methods import Methods from pyrogram.session import Auth, Session -from pyrogram.storage import Storage, FileStorage, MemoryStorage +from pyrogram.storage import FileStorage, MemoryStorage from pyrogram.types import User, TermsOfService from pyrogram.utils import ainput from .dispatcher import Dispatcher @@ -65,14 +65,8 @@ class Client(Methods): """Pyrogram Client, the main means for interacting with Telegram. Parameters: - session_name (``str``): - Pass a string of your choice to give a name to the client session, e.g.: "*my_account*". This name will be - used to save a file on disk that stores details needed to reconnect without asking again for credentials. - Alternatively, if you don't want a file to be saved on disk, pass the special name ``":memory:"`` to start - an in-memory session that will be discarded as soon as you stop the Client. In order to reconnect again - using a memory storage without having to login again, you can use - :meth:`~pyrogram.Client.export_session_string` before stopping the client to get a session string you can - pass here as argument. + name (``str``): + Pass a string of your choice to give a name to the client, e.g.: "my_account". api_id (``int`` | ``str``, *optional*): The *api_id* part of your Telegram API key, as integer. @@ -116,6 +110,17 @@ class Client(Methods): Pass your Bot API token to create a bot session, e.g.: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" Only applicable for new sessions. + session_string (``str``, *optional*): + Pass a session string to load the session in-memory. + Implies ``in_memory=True``. + + in_memory (``bool``, *optional*): + Pass True to start an in-memory session that will be discarded as soon as the client stops. + In order to reconnect again using an in-memory session without having to login again, you can use + :meth:`~pyrogram.Client.export_session_string` before stopping the client to get a session string you can + pass to the ``session_string`` parameter. + Defaults to False. + phone_number (``str``, *optional*): Pass your phone number as string (with your Country Code prefix included) to avoid entering it manually. Only applicable for new sessions. @@ -187,7 +192,7 @@ class Client(Methods): def __init__( self, - session_name: Union[str, Storage], + name: str, api_id: int = None, api_hash: str = None, app_version: str = APP_VERSION, @@ -198,6 +203,8 @@ def __init__( proxy: dict = None, test_mode: bool = False, bot_token: str = None, + session_string: str = None, + in_memory: bool = None, phone_number: str = None, phone_code: str = None, password: str = None, @@ -212,7 +219,7 @@ def __init__( ): super().__init__() - self.session_name = session_name + self.name = name self.api_id = api_id self.api_hash = api_hash self.app_version = app_version @@ -223,6 +230,8 @@ def __init__( self.proxy = proxy self.test_mode = test_mode self.bot_token = bot_token + self.session_string = session_string + self.in_memory = in_memory self.phone_number = phone_number self.phone_code = phone_code self.password = password @@ -237,16 +246,12 @@ def __init__( self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler") - if isinstance(session_name, str): - if session_name == ":memory:" or len(session_name) >= MemoryStorage.SESSION_STRING_SIZE: - session_name = re.sub(r"[\n\s]+", "", session_name) - self.storage = MemoryStorage(session_name) - else: - self.storage = FileStorage(session_name, self.workdir) - elif isinstance(session_name, Storage): - self.storage = session_name + if self.session_string: + self.storage = MemoryStorage(self.name, self.session_string) + elif self.in_memory: + self.storage = MemoryStorage(self.name) else: - raise ValueError("Unknown storage engine") + self.storage = FileStorage(self.name, self.workdir) self.dispatcher = Dispatcher(self) @@ -638,7 +643,7 @@ def load_plugins(self): self.add_handler(handler, group) log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format( - self.session_name, type(handler).__name__, name, group, module_path)) + self.name, type(handler).__name__, name, group, module_path)) count += 1 except Exception: @@ -651,11 +656,11 @@ def load_plugins(self): try: module = import_module(module_path) except ImportError: - log.warning(f'[{self.session_name}] [LOAD] Ignoring non-existent module "{module_path}"') + log.warning(f'[{self.name}] [LOAD] Ignoring non-existent module "{module_path}"') continue if "__path__" in dir(module): - log.warning(f'[{self.session_name}] [LOAD] Ignoring namespace "{module_path}"') + log.warning(f'[{self.name}] [LOAD] Ignoring namespace "{module_path}"') continue if handlers is None: @@ -670,13 +675,13 @@ def load_plugins(self): self.add_handler(handler, group) log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format( - self.session_name, type(handler).__name__, name, group, module_path)) + self.name, type(handler).__name__, name, group, module_path)) count += 1 except Exception: if warn_non_existent_functions: log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format( - self.session_name, name, module_path)) + self.name, name, module_path)) if exclude: for path, handlers in exclude: @@ -686,11 +691,11 @@ def load_plugins(self): try: module = import_module(module_path) except ImportError: - log.warning(f'[{self.session_name}] [UNLOAD] Ignoring non-existent module "{module_path}"') + log.warning(f'[{self.name}] [UNLOAD] Ignoring non-existent module "{module_path}"') continue if "__path__" in dir(module): - log.warning(f'[{self.session_name}] [UNLOAD] Ignoring namespace "{module_path}"') + log.warning(f'[{self.name}] [UNLOAD] Ignoring namespace "{module_path}"') continue if handlers is None: @@ -705,19 +710,19 @@ def load_plugins(self): self.remove_handler(handler, group) log.info('[{}] [UNLOAD] {}("{}") from group {} in "{}"'.format( - self.session_name, type(handler).__name__, name, group, module_path)) + self.name, type(handler).__name__, name, group, module_path)) count -= 1 except Exception: if warn_non_existent_functions: log.warning('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"'.format( - self.session_name, name, module_path)) + self.name, name, module_path)) if count > 0: log.info('[{}] Successfully loaded {} plugin{} from "{}"'.format( - self.session_name, count, "s" if count > 1 else "", root)) + self.name, count, "s" if count > 1 else "", root)) else: - log.warning(f'[{self.session_name}] No plugin loaded from "{root}"') + log.warning(f'[{self.name}] No plugin loaded from "{root}"') async def handle_download(self, packet): file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet diff --git a/pyrogram/storage/memory_storage.py b/pyrogram/storage/memory_storage.py index 1035356dc9..2c01f4474d 100644 --- a/pyrogram/storage/memory_storage.py +++ b/pyrogram/storage/memory_storage.py @@ -27,23 +27,42 @@ class MemoryStorage(SQLiteStorage): - def __init__(self, name: str): + def __init__(self, name: str, session_string: str = None): super().__init__(name) + self.session_string = session_string + async def open(self): self.conn = sqlite3.connect(":memory:", check_same_thread=False) self.create() - if self.name != ":memory:": - dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack( - (self.SESSION_STRING_FORMAT if len(self.name) == MemoryStorage.SESSION_STRING_SIZE else - self.SESSION_STRING_FORMAT_64), - base64.urlsafe_b64decode( - self.name + "=" * (-len(self.name) % 4) + if self.session_string: + # Old format + if len(self.session_string) in [self.SESSION_STRING_SIZE, self.SESSION_STRING_SIZE_64]: + dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack( + (self.OLD_SESSION_STRING_FORMAT + if len(self.session_string) == self.SESSION_STRING_SIZE else + self.OLD_SESSION_STRING_FORMAT_64), + base64.urlsafe_b64decode(self.session_string + "=" * (-len(self.session_string) % 4)) ) + + await self.dc_id(dc_id) + await self.test_mode(test_mode) + await self.auth_key(auth_key) + await self.user_id(user_id) + await self.is_bot(is_bot) + await self.date(0) + + log.warning("You are using an old session string format. Use export_session_string to update") + return + + dc_id, api_id, test_mode, auth_key, user_id, is_bot = struct.unpack( + self.SESSION_STRING_FORMAT, + base64.urlsafe_b64decode(self.session_string + "=" * (-len(self.session_string) % 4)) ) await self.dc_id(dc_id) + await self.api_id(api_id) await self.test_mode(test_mode) await self.auth_key(auth_key) await self.user_id(user_id) diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py index 8daaae7e88..de397718fc 100644 --- a/pyrogram/storage/storage.py +++ b/pyrogram/storage/storage.py @@ -17,18 +17,19 @@ # along with Pyrogram. If not, see . import base64 +import lzma import struct from typing import List, Tuple -from pyrogram import utils - class Storage: - SESSION_STRING_FORMAT = ">B?256sI?" - SESSION_STRING_FORMAT_64 = ">B?256sQ?" + OLD_SESSION_STRING_FORMAT = ">B?256sI?" + OLD_SESSION_STRING_FORMAT_64 = ">B?256sQ?" SESSION_STRING_SIZE = 351 SESSION_STRING_SIZE_64 = 356 + SESSION_STRING_FORMAT = ">BI?256sQ?" + def __init__(self, name: str): self.name = name @@ -78,14 +79,14 @@ async def is_bot(self, value: bool = object): raise NotImplementedError async def export_session_string(self): - user_id = await self.user_id() - return base64.urlsafe_b64encode( - struct.pack( - self.SESSION_STRING_FORMAT if user_id < utils.MAX_USER_ID_OLD else self.SESSION_STRING_FORMAT_64, - await self.dc_id(), - await self.test_mode(), - await self.auth_key(), - user_id, - await self.is_bot() - ) - ).decode().rstrip("=") + packed = struct.pack( + self.SESSION_STRING_FORMAT, + await self.dc_id(), + await self.api_id(), + await self.test_mode(), + await self.auth_key(), + await self.user_id(), + await self.is_bot() + ) + + return base64.urlsafe_b64encode(packed).decode().rstrip("=") From ef78900fdb19a93fe11b36db34ca8e307bdba336 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 180/539] Fixes to the documentation --- docs/source/start/auth.rst | 4 ++-- docs/source/topics/storage-engines.rst | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/source/start/auth.rst b/docs/source/start/auth.rst index 08c1875ac6..ba28ac69b7 100644 --- a/docs/source/start/auth.rst +++ b/docs/source/start/auth.rst @@ -16,7 +16,7 @@ User Authorization In order to use the API, Telegram requires that users be authorized via their phone numbers. Pyrogram automatically manages this process, all you need to do is create an instance of the -:class:`~pyrogram.Client` class by passing to it a ``session_name`` of your choice (e.g.: "my_account") and call +:class:`~pyrogram.Client` class by passing to it a ``name`` of your choice (e.g.: "my_account") and call the :meth:`~pyrogram.Client.run` method: .. code-block:: python @@ -57,7 +57,7 @@ Bots are a special kind of users that are authorized via their tokens (instead o the `Bot Father`_. Bot tokens replace the users' phone numbers only — you still need to :doc:`configure a Telegram API key <../start/setup>` with Pyrogram, even when using bots. -The authorization process is automatically managed. All you need to do is choose a ``session_name`` (can be anything, +The authorization process is automatically managed. All you need to do is choose a ``name`` (can be anything, usually your bot username) and pass your bot token using the ``bot_token`` parameter. The session file will be named after the session name, which will be ``my_bot.session`` for the example below. diff --git a/docs/source/topics/storage-engines.rst b/docs/source/topics/storage-engines.rst index 8d693647d6..c83e7a5b7c 100644 --- a/docs/source/topics/storage-engines.rst +++ b/docs/source/topics/storage-engines.rst @@ -31,15 +31,15 @@ This is the most common storage engine. It is implemented by using **SQLite**, w The database will be saved to disk as a single portable file and is designed to efficiently store and retrieve data whenever they are needed. -To use this type of engine, simply pass any name of your choice to the ``session_name`` parameter of the +To use this type of engine, simply pass any name of your choice to the ``name`` parameter of the :obj:`~pyrogram.Client` constructor, as usual: .. code-block:: python from pyrogram import Client - with Client("my_account") as app: - print(app.get_me()) + async with Client("my_account") as app: + print(await app.get_me()) Once you successfully log in (either with a user or a bot identity), a session file will be created and saved to disk as ``my_account.session``. Any subsequent client restart will make Pyrogram search for a file named that way and the @@ -48,15 +48,15 @@ session database will be automatically loaded. Memory Storage ^^^^^^^^^^^^^^ -In case you don't want to have any session file saved to disk, you can use an in-memory storage by passing the special -session name "**:memory:**" to the ``session_name`` parameter of the :obj:`~pyrogram.Client` constructor: +In case you don't want to have any session file saved to disk, you can use an in-memory storage by passing True to the +``in_memory`` parameter of the :obj:`~pyrogram.Client` constructor: .. code-block:: python from pyrogram import Client - with Client(":memory:") as app: - print(app.get_me()) + async with Client("my_account", in_memory=True) as app: + print(await app.get_me()) This storage engine is still backed by SQLite, but the database exists purely in memory. This means that, once you stop a client, the entire database is discarded and the session details used for logging in again will be lost forever. @@ -71,8 +71,8 @@ In case you want to use an in-memory storage, but also want to keep access to th from pyrogram import Client - with Client(":memory:") as app: - print(app.export_session_string()) + async with Client("my_account", in_memory=True) as app: + print(await app.export_session_string()) ...and save the resulting string. You can use this string as session name the next time you want to login using the same session; the storage used will still be in-memory: @@ -83,8 +83,8 @@ using the same session; the storage used will still be in-memory: session_string = "...ZnUIFD8jsjXTb8g_vpxx48k1zkov9sapD-tzjz-S4WZv70M..." - with Client(session_string) as app: - print(app.get_me()) + async with Client("my_account", session_string=session_string) as app: + print(await app.get_me()) Session strings are useful when you want to run authorized Pyrogram clients on platforms where their ephemeral filesystems makes it harder for a file-based storage engine to properly work as intended. From 74f970e8637abfc81d3539237a6ebdb266079830 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 181/539] Add more docstrings to stream_media --- pyrogram/methods/messages/stream_media.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/methods/messages/stream_media.py b/pyrogram/methods/messages/stream_media.py index 0daaa55667..ea41b7bc37 100644 --- a/pyrogram/methods/messages/stream_media.py +++ b/pyrogram/methods/messages/stream_media.py @@ -32,7 +32,8 @@ async def stream_media( ) -> Optional[Union[str, BinaryIO]]: """Stream the media from a message chunk by chunk. - The chunk size is 1 MiB (1024 * 1024 bytes). + You can use this method to partially download a file into memory or to selectively download chunks of file. + The chunk maximum size is 1 MiB (1024 * 1024 bytes). Parameters: message (:obj:`~pyrogram.types.Message` | ``str``): From f6f6141b19c15c30cc2f83d5decab44f67b5818a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 182/539] Add approve/decline_all_chat_join_requests --- .../approve_all_chat_join_requests.py | 53 +++++++++++++++++++ .../decline_all_chat_join_requests.py | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 pyrogram/methods/invite_links/approve_all_chat_join_requests.py create mode 100644 pyrogram/methods/invite_links/decline_all_chat_join_requests.py diff --git a/pyrogram/methods/invite_links/approve_all_chat_join_requests.py b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py new file mode 100644 index 0000000000..ec2fc1bc6c --- /dev/null +++ b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py @@ -0,0 +1,53 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union + +import pyrogram +from pyrogram import raw + + +class ApproveAllChatJoinRequests: + async def approve_all_chat_join_requests( + self: "pyrogram.Client", + chat_id: Union[int, str], + invite_link: str = None + ) -> bool: + """Approve all pending join requests in a chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). + + invite_link (``str``, *optional*): + Pass an invite link to approve only its join requests. + By default, all join requests are approved. + + Returns: + ``bool``: True on success. + """ + await self.invoke( + raw.functions.messages.HideAllChatJoinRequests( + peer=await self.resolve_peer(chat_id), + approved=True, + link=invite_link + ) + ) + + return True diff --git a/pyrogram/methods/invite_links/decline_all_chat_join_requests.py b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py new file mode 100644 index 0000000000..620e26245e --- /dev/null +++ b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py @@ -0,0 +1,53 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union + +import pyrogram +from pyrogram import raw + + +class DeclineAllChatJoinRequests: + async def decline_all_chat_join_requests( + self: "pyrogram.Client", + chat_id: Union[int, str], + invite_link: str = None + ) -> bool: + """Decline all pending join requests in a chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). + + invite_link (``str``, *optional*): + Pass an invite link to decline only its join requests. + By default, all join requests are declined. + + Returns: + ``bool``: True on success. + """ + await self.invoke( + raw.functions.messages.HideAllChatJoinRequests( + peer=await self.resolve_peer(chat_id), + approved=False, + link=invite_link + ) + ) + + return True From d48cef9a26d178d29161fc8e4e5a77fefda42fb4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 183/539] Add ChatJoiner and get_chat_join_requests Rename get_chat_invite_link_{members -> joiners} Rename get_chat_invite_link_{members -> joiners}_count --- compiler/docs/compiler.py | 8 +- pyrogram/methods/invite_links/__init__.py | 16 ++-- ...ers.py => get_chat_invite_link_joiners.py} | 18 ++-- ... => get_chat_invite_link_joiners_count.py} | 4 +- .../invite_links/get_chat_join_requests.py | 86 +++++++++++++++++++ pyrogram/types/user_and_chats/__init__.py | 4 +- pyrogram/types/user_and_chats/chat_joiner.py | 82 ++++++++++++++++++ 7 files changed, 196 insertions(+), 22 deletions(-) rename pyrogram/methods/invite_links/{get_chat_invite_link_members.py => get_chat_invite_link_joiners.py} (85%) rename pyrogram/methods/invite_links/{get_chat_invite_link_members_count.py => get_chat_invite_link_joiners_count.py} (95%) create mode 100644 pyrogram/methods/invite_links/get_chat_join_requests.py create mode 100644 pyrogram/types/user_and_chats/chat_joiner.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index b5382438cb..01acf6322c 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -256,14 +256,17 @@ def get_title_list(s: str) -> list: edit_chat_invite_link revoke_chat_invite_link delete_chat_invite_link - get_chat_invite_link_members - get_chat_invite_link_members_count + get_chat_invite_link_joiners + get_chat_invite_link_joiners_count get_chat_admin_invite_links get_chat_admin_invite_links_count get_chat_admins_with_invite_links + get_chat_join_requests delete_chat_admin_invite_links approve_chat_join_request + approve_all_chat_join_requests decline_chat_join_request + decline_all_chat_join_requests """, contacts=""" Contacts @@ -370,6 +373,7 @@ def get_title_list(s: str) -> list: ChatEventFilter ChatMemberUpdated ChatJoinRequest + ChatJoiner Dialog Restriction """, diff --git a/pyrogram/methods/invite_links/__init__.py b/pyrogram/methods/invite_links/__init__.py index c2183d9b55..67c1d14958 100644 --- a/pyrogram/methods/invite_links/__init__.py +++ b/pyrogram/methods/invite_links/__init__.py @@ -17,8 +17,10 @@ # along with Pyrogram. If not, see . +from .approve_all_chat_join_requests import ApproveAllChatJoinRequests from .approve_chat_join_request import ApproveChatJoinRequest from .create_chat_invite_link import CreateChatInviteLink +from .decline_all_chat_join_requests import DeclineAllChatJoinRequests from .decline_chat_join_request import DeclineChatJoinRequest from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks from .delete_chat_invite_link import DeleteChatInviteLink @@ -28,8 +30,9 @@ from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks from .get_chat_invite_link import GetChatInviteLink -from .get_chat_invite_link_members import GetChatInviteLinkMembers -from .get_chat_invite_link_members_count import GetChatInviteLinkMembersCount +from .get_chat_invite_link_joiners import GetChatInviteLinkJoiners +from .get_chat_invite_link_joiners_count import GetChatInviteLinkJoinersCount +from .get_chat_join_requests import GetChatJoinRequests from .revoke_chat_invite_link import RevokeChatInviteLink @@ -38,8 +41,8 @@ class InviteLinks( DeleteChatInviteLink, EditChatInviteLink, CreateChatInviteLink, - GetChatInviteLinkMembers, - GetChatInviteLinkMembersCount, + GetChatInviteLinkJoiners, + GetChatInviteLinkJoinersCount, GetChatAdminInviteLinks, ExportChatInviteLink, DeleteChatAdminInviteLinks, @@ -47,6 +50,9 @@ class InviteLinks( GetChatAdminsWithInviteLinks, GetChatInviteLink, ApproveChatJoinRequest, - DeclineChatJoinRequest + DeclineChatJoinRequest, + ApproveAllChatJoinRequests, + DeclineAllChatJoinRequests, + GetChatJoinRequests ): pass diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py similarity index 85% rename from pyrogram/methods/invite_links/get_chat_invite_link_members.py rename to pyrogram/methods/invite_links/get_chat_invite_link_joiners.py index 28121cccb7..cfd6873433 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_members.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py @@ -23,13 +23,13 @@ from pyrogram import types -class GetChatInviteLinkMembers: - async def get_chat_invite_link_members( +class GetChatInviteLinkJoiners: + async def get_chat_invite_link_joiners( self: "pyrogram.Client", chat_id: Union[int, str], invite_link: str, limit: int = 0 - ) -> Optional[AsyncGenerator["types.ChatMember", None]]: + ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: """Get the members who joined the chat with the invite link. Parameters: @@ -45,10 +45,10 @@ async def get_chat_invite_link_members( By default, no limit is applied and all invite links are returned. Returns: - ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects. + ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects. Yields: - :obj:`~pyrogram.types.ChatMember` objects. + :obj:`~pyrogram.types.ChatJoiner` objects. """ current = 0 total = abs(limit) or (1 << 31) - 1 @@ -77,13 +77,7 @@ async def get_chat_invite_link_members( offset_user = await self.resolve_peer(r.importers[-1].user_id) for i in r.importers: - user = types.User._parse(self, users[i.user_id]) - - yield types.ChatMember( - user=user, - status="member", - joined_date=i.date - ) + yield types.ChatJoiner._parse(self, i, users) current += 1 diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py similarity index 95% rename from pyrogram/methods/invite_links/get_chat_invite_link_members_count.py rename to pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py index d542895716..084fbae570 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_members_count.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py @@ -22,8 +22,8 @@ from pyrogram import raw -class GetChatInviteLinkMembersCount: - async def get_chat_invite_link_members_count( +class GetChatInviteLinkJoinersCount: + async def get_chat_invite_link_joiners_count( self: "pyrogram.Client", chat_id: Union[int, str], invite_link: str diff --git a/pyrogram/methods/invite_links/get_chat_join_requests.py b/pyrogram/methods/invite_links/get_chat_join_requests.py new file mode 100644 index 0000000000..9a9bc38793 --- /dev/null +++ b/pyrogram/methods/invite_links/get_chat_join_requests.py @@ -0,0 +1,86 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union, Optional, AsyncGenerator + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class GetChatJoinRequests: + async def get_chat_join_requests( + self: "pyrogram.Client", + chat_id: Union[int, str], + limit: int = 0, + query: str = "" + ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: + """Get the pending join requests of a chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). + + limit (``int``, *optional*): + Limits the number of invite links to be retrieved. + By default, no limit is applied and all invite links are returned. + + query (``str``, *optional*): + Query to search for a user. + + Returns: + ``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects. + + Yields: + :obj:`~pyrogram.types.ChatJoiner` objects. + """ + current = 0 + total = abs(limit) or (1 << 31) - 1 + limit = min(100, total) + + offset_date = 0 + offset_user = raw.types.InputUserEmpty() + + while True: + r = await self.invoke( + raw.functions.messages.GetChatInviteImporters( + peer=await self.resolve_peer(chat_id), + limit=limit, + offset_date=offset_date, + offset_user=offset_user, + requested=True, + q=query + ) + ) + + if not r.importers: + break + + users = {i.id: i for i in r.users} + + offset_date = r.importers[-1].date + offset_user = await self.resolve_peer(r.importers[-1].user_id) + + for i in r.importers: + yield types.ChatJoiner._parse(self, i, users) + + current += 1 + + if current >= total: + return diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 15ddf8c9e3..bf5082792d 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -22,6 +22,7 @@ from .chat_event_filter import ChatEventFilter from .chat_invite_link import ChatInviteLink from .chat_join_request import ChatJoinRequest +from .chat_joiner import ChatJoiner from .chat_member import ChatMember from .chat_member_updated import ChatMemberUpdated from .chat_permissions import ChatPermissions @@ -57,5 +58,6 @@ "ChatMemberUpdated", "VoiceChatScheduled", "ChatJoinRequest", - "ChatPrivileges" + "ChatPrivileges", + "ChatJoiner" ] diff --git a/pyrogram/types/user_and_chats/chat_joiner.py b/pyrogram/types/user_and_chats/chat_joiner.py new file mode 100644 index 0000000000..024f88ea26 --- /dev/null +++ b/pyrogram/types/user_and_chats/chat_joiner.py @@ -0,0 +1,82 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 datetime import datetime +from typing import Dict + +import pyrogram +from pyrogram import raw, types, utils +from ..object import Object + + +class ChatJoiner(Object): + """Contains information about a joiner member of a chat. + + Parameters: + user (:obj:`~pyrogram.types.User`): + Information about the user. + + date (:py:obj:`~datetime.datetime`): + Date when the user joined. + + bio (``str``, *optional*): + Bio of the user. + + pending (``bool``, *optional*): + True in case the chat joiner has a pending request. + + approved_by (:obj:`~pyrogram.types.User`, *optional*): + Administrator who approved this chat joiner. + """ + + def __init__( + self, + *, + client: "pyrogram.Client", + user: "types.User", + date: datetime = None, + bio: str = None, + pending: bool = None, + approved_by: "types.User" = None, + ): + super().__init__(client) + + self.user = user + self.date = date + self.bio = bio + self.pending = pending + self.approved_by = approved_by + + @staticmethod + def _parse( + client: "pyrogram.Client", + joiner: "raw.base.ChatInviteImporter", + users: Dict[int, "raw.base.User"], + ) -> "ChatJoiner": + return ChatJoiner( + user=types.User._parse(client, users[joiner.user_id]), + date=utils.timestamp_to_datetime(joiner.date), + pending=joiner.requested, + bio=joiner.about, + approved_by=( + types.User._parse(client, users[joiner.approved_by]) + if joiner.approved_by + else None + ), + client=client + ) From 39694a29497aee87d6ee91155e9b7570b7849aa9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 184/539] Add speedups.rst --- docs/source/index.rst | 2 +- docs/source/topics/speedups.rst | 65 +++++++++++++++++++++++++++++++++ docs/source/topics/tgcrypto.rst | 29 --------------- pyrogram/crypto/aes.py | 2 +- 4 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 docs/source/topics/speedups.rst delete mode 100644 docs/source/topics/tgcrypto.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 5ee12b7ec2..885f79dd8e 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -143,7 +143,7 @@ Meta topics/client-settings topics/synchronous topics/text-formatting - topics/tgcrypto + topics/speedups topics/smart-plugins topics/storage-engines topics/serializing diff --git a/docs/source/topics/speedups.rst b/docs/source/topics/speedups.rst new file mode 100644 index 0000000000..6340e1ad4f --- /dev/null +++ b/docs/source/topics/speedups.rst @@ -0,0 +1,65 @@ +Speedups +======== + +Pyrogram's speed can be boosted up by using TgCrypto and uvloop. + +.. contents:: Contents + :backlinks: none + :depth: 1 + :local: + +----- + +TgCrypto +-------- + +TgCrypto_ is a high-performance, easy-to-install cryptography library specifically written in C for Pyrogram as a Python +extension. It is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram +requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC. + +Installation +^^^^^^^^^^^^ + +.. code-block:: bash + + $ pip3 install -U tgcrypto + +Usage +^^^^^ + +Pyrogram will automatically make use of TgCrypto when detected, all you need to do is to install it. + +uvloop +------ + +uvloop_ is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses +libuv under the hood. It makes asyncio 2-4x faster. + +Installation +^^^^^^^^^^^^ + +.. code-block:: bash + + $ pip3 install -U uvloop + +Usage +^^^^^ + +Call ``uvloop.install()`` before calling ``asyncio.run()`` or ``app.run()`` + +.. code-block:: python + + import asyncio + import uvloop + + async def main(): + app = Client("my_account") + + async with app: + print(await app.get_me()) + + uvloop.install() + asyncio.run(main()) + +.. _TgCrypto: https://github.com/pyrogram/tgcrypto +.. _uvloop: https://github.com/MagicStack/uvloop diff --git a/docs/source/topics/tgcrypto.rst b/docs/source/topics/tgcrypto.rst deleted file mode 100644 index f6ca211d3e..0000000000 --- a/docs/source/topics/tgcrypto.rst +++ /dev/null @@ -1,29 +0,0 @@ -Fast Crypto -=========== - -Pyrogram's speed can be boosted up by TgCrypto_, a high-performance, easy-to-install cryptography library specifically -written in C for Pyrogram as a Python extension. - -TgCrypto is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram -requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC. - -Installation ------------- - -.. code-block:: bash - - $ pip3 install -U tgcrypto - -.. note:: When TgCrypto is not detected in your system, Pyrogram will automatically fall back to a slower Python-only - implementation and will show you a warning. - -The reason about being an optional package is that TgCrypto requires extra system tools in order to be compiled. -The errors you receive when trying to install TgCrypto are system dependent, but also descriptive enough to understand -what you should do next: - -- **Windows**: Install `Visual C++ 2015 Build Tools `_. -- **macOS**: A pop-up will automatically ask you to install the command line developer tools. -- **Linux**: Install a proper C compiler (``gcc``, ``clang``) and the Python header files (``python3-dev``). -- **Termux**: Install ``clang`` package. - -.. _TgCrypto: https://github.com/pyrogram/tgcrypto \ No newline at end of file diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index 532cd5e8d0..bb937128df 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -54,7 +54,7 @@ def xor(a: bytes, b: bytes) -> bytes: log.warning( "TgCrypto is missing! " "Pyrogram will work the same, but at a much slower speed. " - "More info: https://docs.pyrogram.org/topics/tgcrypto" + "More info: https://docs.pyrogram.org/topics/speedups" ) From ed5fab6952de19ab79ebbfb3171b57f6d075eba4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 185/539] Update proxy example --- docs/source/topics/proxy.rst | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/source/topics/proxy.rst b/docs/source/topics/proxy.rst index 74e054bc26..286743493d 100644 --- a/docs/source/topics/proxy.rst +++ b/docs/source/topics/proxy.rst @@ -19,17 +19,16 @@ you can omit ``username`` and ``password``. .. code-block:: python - from pyrogram import Client - - app = Client( - "my_account", - proxy=dict( - scheme="socks5", # "socks4", "socks5" and "http" are supported - hostname="11.22.33.44", - port=1234, - username="", - password="" - ) - ) + from pyrogram import Client + + proxy = { + "scheme": "socks5", # "socks4", "socks5" and "http" are supported + "hostname": "11.22.33.44", + "port": 1234, + "username": "username", + "password": "password" + } + + app = Client("my_account", proxy=proxy) app.run() From 4e1b54288b49afc0f01792c775efb7f4539b1f5d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 186/539] Fix Client.name usage --- 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 ff643859a7..ff195b96ec 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -364,7 +364,7 @@ async def invoke( if amount > sleep_threshold >= 0: raise - log.warning(f'[{self.client.session_name}] Waiting for {amount} seconds before continuing ' + log.warning(f'[{self.client.name}] Waiting for {amount} seconds before continuing ' f'(required by "{query_name}")') await asyncio.sleep(amount) From f6b8d78672093a02f2f408573a3532a71fa6033c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 187/539] Fix documentation link --- docs/source/intro/install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/intro/install.rst b/docs/source/intro/install.rst index 67a6b9432d..c45c384489 100644 --- a/docs/source/intro/install.rst +++ b/docs/source/intro/install.rst @@ -20,7 +20,7 @@ Install Pyrogram $ pip3 install -U pyrogram -- or, with :doc:`TgCrypto <../topics/tgcrypto>` as extra requirement (recommended): +- or, with :doc:`TgCrypto <../topics/speedups>` as extra requirement (recommended): .. code-block:: text From 6b0dca09dec5205c0a3eafdab07cee7a0980c56e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 188/539] Add WebAppInfo and field web_app to (Inline)KeyboardButton. --- compiler/docs/compiler.py | 1 + pyrogram/types/bots_and_keyboards/__init__.py | 2 + .../inline_keyboard_button.py | 22 +++++++++++ .../bots_and_keyboards/keyboard_button.py | 22 ++++++++++- .../types/bots_and_keyboards/web_app_info.py | 37 +++++++++++++++++++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 pyrogram/types/bots_and_keyboards/web_app_info.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 01acf6322c..9b9d2322da 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -416,6 +416,7 @@ def get_title_list(s: str) -> list: CallbackQuery GameHighScore CallbackGame + WebAppInfo """, bot_commands=""" Bot commands diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 37e6dfe831..44fd589452 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -35,6 +35,7 @@ from .login_url import LoginUrl from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove +from .web_app_info import WebAppInfo __all__ = [ "CallbackGame", @@ -56,4 +57,5 @@ "BotCommandScopeChatAdministrators", "BotCommandScopeChatMember", "BotCommandScopeDefault", + "WebAppInfo" ] diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py index de6a04207c..a1d8a7adc8 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py @@ -39,6 +39,12 @@ class InlineKeyboardButton(Object): url (``str``, *optional*): HTTP url to be opened when button is pressed. + web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*): + Description of the `Web App `_ that will be launched when the user + presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the + method :meth:`~pyrogram.Client.answer_web_app_query`. Available only in private chats between a user and the + bot. + login_url (:obj:`~pyrogram.types.LoginUrl`, *optional*): An HTTP URL used to automatically authorize the user. Can be used as a replacement for the `Telegram Login Widget `_. @@ -70,6 +76,7 @@ def __init__( text: str, callback_data: Union[str, bytes] = None, url: str = None, + web_app: "types.WebAppInfo" = None, login_url: "types.LoginUrl" = None, user_id: int = None, switch_inline_query: str = None, @@ -81,6 +88,7 @@ def __init__( self.text = str(text) self.callback_data = callback_data self.url = url + self.web_app = web_app self.login_url = login_url self.user_id = user_id self.switch_inline_query = switch_inline_query @@ -139,6 +147,14 @@ def read(b: "raw.base.KeyboardButton"): callback_game=types.CallbackGame() ) + if isinstance(b, raw.types.KeyboardButtonWebView): + return InlineKeyboardButton( + text=b.text, + web_app=types.WebAppInfo( + url=b.url + ) + ) + async def write(self, client: "pyrogram.Client"): if self.callback_data is not None: # Telegram only wants bytes, but we are allowed to pass strings too, for convenience. @@ -184,3 +200,9 @@ async def write(self, client: "pyrogram.Client"): return raw.types.KeyboardButtonGame( text=self.text ) + + if self.web_app is not None: + return raw.types.KeyboardButtonWebView( + text=self.text, + url=self.web_app.url + ) diff --git a/pyrogram/types/bots_and_keyboards/keyboard_button.py b/pyrogram/types/bots_and_keyboards/keyboard_button.py index 626df749c0..5c8d4b733c 100644 --- a/pyrogram/types/bots_and_keyboards/keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/keyboard_button.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram import raw +from pyrogram import raw, types from ..object import Object @@ -37,19 +37,27 @@ class KeyboardButton(Object): request_location (``bool``, *optional*): If True, the user's current location will be sent when the button is pressed. Available in private chats only. + + web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*): + If specified, the described `Web App `_ will be launched when the + button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private + chats only. + """ def __init__( self, text: str, request_contact: bool = None, - request_location: bool = None + request_location: bool = None, + web_app: "types.WebAppInfo" = None ): super().__init__() self.text = str(text) self.request_contact = request_contact self.request_location = request_location + self.web_app = web_app @staticmethod def read(b): @@ -68,10 +76,20 @@ def read(b): request_location=True ) + if isinstance(b, raw.types.KeyboardButtonSimpleWebView): + return KeyboardButton( + text=b.text, + web_app=types.WebAppInfo( + url=b.url + ) + ) + def write(self): if self.request_contact: return raw.types.KeyboardButtonRequestPhone(text=self.text) elif self.request_location: return raw.types.KeyboardButtonRequestGeoLocation(text=self.text) + elif self.web_app: + return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url) else: return raw.types.KeyboardButton(text=self.text) diff --git a/pyrogram/types/bots_and_keyboards/web_app_info.py b/pyrogram/types/bots_and_keyboards/web_app_info.py new file mode 100644 index 0000000000..1dbb0a781c --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/web_app_info.py @@ -0,0 +1,37 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 ..object import Object + + +class WebAppInfo(Object): + """Contains information about a `Web App `_. + + Parameters: + url (``str``): + An HTTPS URL of a Web App to be opened with additional data as specified in + `Initializing Web Apps `_. + """ + + def __init__( + self, *, + url: str, + ): + super().__init__() + + self.url = url From a3c7f5e991744858b122ef7209b5fb825d1a7c86 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 189/539] Rename voice_* related fields to video_* --- pyrogram/enums/chat_event_action.py | 2 +- pyrogram/enums/message_service.py | 16 +++--- pyrogram/filters.py | 26 ++++----- pyrogram/types/messages_and_media/message.py | 56 +++++++++---------- pyrogram/types/user_and_chats/__init__.py | 16 +++--- ...oice_chat_ended.py => video_chat_ended.py} | 6 +- ...vited.py => video_chat_members_invited.py} | 6 +- ...t_scheduled.py => video_chat_scheduled.py} | 6 +- ..._chat_started.py => video_chat_started.py} | 2 +- 9 files changed, 68 insertions(+), 68 deletions(-) rename pyrogram/types/user_and_chats/{voice_chat_ended.py => video_chat_ended.py} (92%) rename pyrogram/types/user_and_chats/{voice_chat_members_invited.py => video_chat_members_invited.py} (92%) rename pyrogram/types/user_and_chats/{voice_chat_scheduled.py => video_chat_scheduled.py} (91%) rename pyrogram/types/user_and_chats/{voice_chat_started.py => video_chat_started.py} (96%) diff --git a/pyrogram/enums/chat_event_action.py b/pyrogram/enums/chat_event_action.py index 9b73de913c..7a5954720f 100644 --- a/pyrogram/enums/chat_event_action.py +++ b/pyrogram/enums/chat_event_action.py @@ -96,7 +96,7 @@ class ChatEventAction(AutoName): # MEMBER_VOLUME_CHANGED = auto() "" - # VOICE_CHAT_STARTED = auto() + # VIDEO_CHAT_STARTED = auto() "" POLL_STOPPED = auto() diff --git a/pyrogram/enums/message_service.py b/pyrogram/enums/message_service.py index b38e471793..7b23c730c2 100644 --- a/pyrogram/enums/message_service.py +++ b/pyrogram/enums/message_service.py @@ -57,14 +57,14 @@ class MessageService(AutoName): GAME_HIGH_SCORE = auto() "Game high score" - VOICE_CHAT_STARTED = auto() - "Voice chat started" + VIDEO_CHAT_STARTED = auto() + "Video chat started" - VOICE_CHAT_ENDED = auto() - "Voice chat ended" + VIDEO_CHAT_ENDED = auto() + "Video chat ended" - VOICE_CHAT_SCHEDULED = auto() - "Voice chat scheduled" + VIDEO_CHAT_SCHEDULED = auto() + "Video chat scheduled" - VOICE_CHAT_MEMBERS_INVITED = auto() - "Voice chat members invited" + VIDEO_CHAT_MEMBERS_INVITED = auto() + "Video chat members invited" diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 078ed4fa7e..013adee4e2 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -636,34 +636,34 @@ async def via_bot_filter(_, __, m: Message): # endregion -# region voice_chat_started_filter -async def voice_chat_started_filter(_, __, m: Message): - return bool(m.voice_chat_started) +# region video_chat_started_filter +async def video_chat_started_filter(_, __, m: Message): + return bool(m.video_chat_started) -voice_chat_started = create(voice_chat_started_filter) +video_chat_started = create(video_chat_started_filter) """Filter messages for started voice chats""" # endregion -# region voice_chat_ended_filter -async def voice_chat_ended_filter(_, __, m: Message): - return bool(m.voice_chat_ended) +# region video_chat_ended_filter +async def video_chat_ended_filter(_, __, m: Message): + return bool(m.video_chat_ended) -voice_chat_ended = create(voice_chat_ended_filter) +video_chat_ended = create(video_chat_ended_filter) """Filter messages for ended voice chats""" # endregion -# region voice_chat_members_invited_filter -async def voice_chat_members_invited_filter(_, __, m: Message): - return bool(m.voice_chat_members_invited) +# region video_chat_members_invited_filter +async def video_chat_members_invited_filter(_, __, m: Message): + return bool(m.video_chat_members_invited) -voice_chat_members_invited = create(voice_chat_members_invited_filter) +video_chat_members_invited = create(video_chat_members_invited_filter) """Filter messages for voice chat invited members""" @@ -680,7 +680,7 @@ async def service_filter(_, __, m: Message): A service message contains any of the following fields set: *left_chat_member*, *new_chat_title*, *new_chat_photo*, *delete_chat_photo*, *group_chat_created*, *supergroup_chat_created*, *channel_chat_created*, *migrate_to_chat_id*, *migrate_from_chat_id*, *pinned_message*, *game_score*, -*voice_chat_started*, *voice_chat_ended*, *voice_chat_members_invited*. +*video_chat_started*, *video_chat_ended*, *video_chat_members_invited*. """ diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 3a72fe33eb..7a5341fdd8 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -273,16 +273,16 @@ class Message(Object, Update): E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"]. Only applicable when using :obj:`~pyrogram.filters.command`. - voice_chat_scheduled (:obj:`~pyrogram.types.VoiceChatScheduled`, *optional*): + video_chat_scheduled (:obj:`~pyrogram.types.VideoChatScheduled`, *optional*): Service message: voice chat scheduled. - voice_chat_started (:obj:`~pyrogram.types.VoiceChatStarted`, *optional*): + video_chat_started (:obj:`~pyrogram.types.VideoChatStarted`, *optional*): Service message: the voice chat started. - voice_chat_ended (:obj:`~pyrogram.types.VoiceChatEnded`, *optional*): + video_chat_ended (:obj:`~pyrogram.types.VideoChatEnded`, *optional*): Service message: the voice chat has ended. - voice_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*): + video_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*): Service message: new members were invited to the voice chat. reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): @@ -362,10 +362,10 @@ def __init__( outgoing: bool = None, matches: List[Match] = None, command: List[str] = None, - voice_chat_scheduled: "types.VoiceChatScheduled" = None, - voice_chat_started: "types.VoiceChatStarted" = None, - voice_chat_ended: "types.VoiceChatEnded" = None, - voice_chat_members_invited: "types.VoiceChatMembersInvited" = None, + video_chat_scheduled: "types.VideoChatScheduled" = None, + video_chat_started: "types.VideoChatStarted" = None, + video_chat_ended: "types.VideoChatEnded" = None, + video_chat_members_invited: "types.VideoChatMembersInvited" = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -437,10 +437,10 @@ def __init__( self.matches = matches self.command = command self.reply_markup = reply_markup - self.voice_chat_scheduled = voice_chat_scheduled - self.voice_chat_started = voice_chat_started - self.voice_chat_ended = voice_chat_ended - self.voice_chat_members_invited = voice_chat_members_invited + self.video_chat_scheduled = video_chat_scheduled + self.video_chat_started = video_chat_started + self.video_chat_ended = video_chat_ended + self.video_chat_members_invited = video_chat_members_invited self.reactions = reactions @staticmethod @@ -487,10 +487,10 @@ async def _parse( group_chat_created = None channel_chat_created = None new_chat_photo = None - voice_chat_scheduled = None - voice_chat_started = None - voice_chat_ended = None - voice_chat_members_invited = None + video_chat_scheduled = None + video_chat_started = None + video_chat_ended = None + video_chat_members_invited = None service_type = None @@ -525,18 +525,18 @@ async def _parse( new_chat_photo = types.Photo._parse(client, action.photo) service_type = enums.MessageService.NEW_CHAT_PHOTO elif isinstance(action, raw.types.MessageActionGroupCallScheduled): - voice_chat_scheduled = types.VoiceChatScheduled._parse(action) - service_type = enums.MessageService.VOICE_CHAT_SCHEDULED + video_chat_scheduled = types.VideoChatScheduled._parse(action) + service_type = enums.MessageService.VIDEO_CHAT_SCHEDULED elif isinstance(action, raw.types.MessageActionGroupCall): if action.duration: - voice_chat_ended = types.VoiceChatEnded._parse(action) - service_type = enums.MessageService.VOICE_CHAT_ENDED + video_chat_ended = types.VideoChatEnded._parse(action) + service_type = enums.MessageService.VIDEO_CHAT_ENDED else: - voice_chat_started = types.VoiceChatStarted() - service_type = enums.MessageService.VOICE_CHAT_STARTED + video_chat_started = types.VideoChatStarted() + service_type = enums.MessageService.VIDEO_CHAT_STARTED elif isinstance(action, raw.types.MessageActionInviteToGroupCall): - voice_chat_members_invited = types.VoiceChatMembersInvited._parse(client, action, users) - service_type = enums.MessageService.VOICE_CHAT_MEMBERS_INVITED + video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users) + service_type = enums.MessageService.VIDEO_CHAT_MEMBERS_INVITED from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None @@ -557,10 +557,10 @@ async def _parse( migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None, group_chat_created=group_chat_created, channel_chat_created=channel_chat_created, - voice_chat_scheduled=voice_chat_scheduled, - voice_chat_started=voice_chat_started, - voice_chat_ended=voice_chat_ended, - voice_chat_members_invited=voice_chat_members_invited, + video_chat_scheduled=video_chat_scheduled, + video_chat_started=video_chat_started, + video_chat_ended=video_chat_ended, + video_chat_members_invited=video_chat_members_invited, client=client # TODO: supergroup_chat_created ) diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index bf5082792d..a9b633599f 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -33,10 +33,10 @@ from .invite_link_importer import InviteLinkImporter from .restriction import Restriction from .user import User -from .voice_chat_ended import VoiceChatEnded -from .voice_chat_members_invited import VoiceChatMembersInvited -from .voice_chat_scheduled import VoiceChatScheduled -from .voice_chat_started import VoiceChatStarted +from .video_chat_ended import VideoChatEnded +from .video_chat_members_invited import VideoChatMembersInvited +from .video_chat_scheduled import VideoChatScheduled +from .video_chat_started import VideoChatStarted __all__ = [ "Chat", @@ -52,11 +52,11 @@ "ChatInviteLink", "InviteLinkImporter", "ChatAdminWithInviteLinks", - "VoiceChatStarted", - "VoiceChatEnded", - "VoiceChatMembersInvited", + "VideoChatStarted", + "VideoChatEnded", + "VideoChatMembersInvited", "ChatMemberUpdated", - "VoiceChatScheduled", + "VideoChatScheduled", "ChatJoinRequest", "ChatPrivileges", "ChatJoiner" diff --git a/pyrogram/types/user_and_chats/voice_chat_ended.py b/pyrogram/types/user_and_chats/video_chat_ended.py similarity index 92% rename from pyrogram/types/user_and_chats/voice_chat_ended.py rename to pyrogram/types/user_and_chats/video_chat_ended.py index b6b05feaf3..8c9fac6a0a 100644 --- a/pyrogram/types/user_and_chats/voice_chat_ended.py +++ b/pyrogram/types/user_and_chats/video_chat_ended.py @@ -20,7 +20,7 @@ from ..object import Object -class VoiceChatEnded(Object): +class VideoChatEnded(Object): """A service message about a voice chat ended in the chat. Parameters: @@ -37,5 +37,5 @@ def __init__( self.duration = duration @staticmethod - def _parse(action: "raw.types.MessageActionGroupCall") -> "VoiceChatEnded": - return VoiceChatEnded(duration=action.duration) + def _parse(action: "raw.types.MessageActionGroupCall") -> "VideoChatEnded": + return VideoChatEnded(duration=action.duration) diff --git a/pyrogram/types/user_and_chats/voice_chat_members_invited.py b/pyrogram/types/user_and_chats/video_chat_members_invited.py similarity index 92% rename from pyrogram/types/user_and_chats/voice_chat_members_invited.py rename to pyrogram/types/user_and_chats/video_chat_members_invited.py index 0fd4249ba5..9f2e3d1ef4 100644 --- a/pyrogram/types/user_and_chats/voice_chat_members_invited.py +++ b/pyrogram/types/user_and_chats/video_chat_members_invited.py @@ -22,7 +22,7 @@ from ..object import Object -class VoiceChatMembersInvited(Object): +class VideoChatMembersInvited(Object): """A service message about new members invited to a voice chat. @@ -44,7 +44,7 @@ def _parse( client, action: "raw.types.MessageActionInviteToGroupCall", users: Dict[int, "raw.types.User"] - ) -> "VoiceChatMembersInvited": + ) -> "VideoChatMembersInvited": users = [types.User._parse(client, users[i]) for i in action.users] - return VoiceChatMembersInvited(users=users) + return VideoChatMembersInvited(users=users) diff --git a/pyrogram/types/user_and_chats/voice_chat_scheduled.py b/pyrogram/types/user_and_chats/video_chat_scheduled.py similarity index 91% rename from pyrogram/types/user_and_chats/voice_chat_scheduled.py rename to pyrogram/types/user_and_chats/video_chat_scheduled.py index 0bb00bc509..5bdd592515 100644 --- a/pyrogram/types/user_and_chats/voice_chat_scheduled.py +++ b/pyrogram/types/user_and_chats/video_chat_scheduled.py @@ -22,7 +22,7 @@ from ..object import Object -class VoiceChatScheduled(Object): +class VideoChatScheduled(Object): """A service message about a voice chat scheduled in the chat. Parameters: @@ -39,5 +39,5 @@ def __init__( self.start_date = start_date @staticmethod - def _parse(action: "raw.types.MessageActionGroupCallScheduled") -> "VoiceChatScheduled": - return VoiceChatScheduled(start_date=utils.timestamp_to_datetime(action.schedule_date)) + def _parse(action: "raw.types.MessageActionGroupCallScheduled") -> "VideoChatScheduled": + return VideoChatScheduled(start_date=utils.timestamp_to_datetime(action.schedule_date)) diff --git a/pyrogram/types/user_and_chats/voice_chat_started.py b/pyrogram/types/user_and_chats/video_chat_started.py similarity index 96% rename from pyrogram/types/user_and_chats/voice_chat_started.py rename to pyrogram/types/user_and_chats/video_chat_started.py index e260e784fb..ff48b39cd6 100644 --- a/pyrogram/types/user_and_chats/voice_chat_started.py +++ b/pyrogram/types/user_and_chats/video_chat_started.py @@ -19,7 +19,7 @@ from ..object import Object -class VoiceChatStarted(Object): +class VideoChatStarted(Object): """A service message about a voice chat started in the chat. Currently holds no information. From c54be38696201a7253c1ee21bbe188adb01ac978 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 190/539] Rename can_manage_voice_chats to can_manage_video_chats --- pyrogram/methods/chats/promote_chat_member.py | 2 +- pyrogram/types/user_and_chats/chat_privileges.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py index e6f2171e2e..f8a2779b3b 100644 --- a/pyrogram/methods/chats/promote_chat_member.py +++ b/pyrogram/methods/chats/promote_chat_member.py @@ -86,7 +86,7 @@ async def promote_chat_member( invite_users=privileges.can_invite_users, pin_messages=privileges.can_pin_messages, add_admins=privileges.can_promote_members, - manage_call=privileges.can_manage_voice_chats, + manage_call=privileges.can_manage_video_chats, other=privileges.can_manage_chat ), rank=rank or "" diff --git a/pyrogram/types/user_and_chats/chat_privileges.py b/pyrogram/types/user_and_chats/chat_privileges.py index 403bb9572b..8a420da5b7 100644 --- a/pyrogram/types/user_and_chats/chat_privileges.py +++ b/pyrogram/types/user_and_chats/chat_privileges.py @@ -32,7 +32,7 @@ class ChatPrivileges(Object): can_delete_messages (``bool``, *optional*): True, if the administrator can delete messages of other users. - can_manage_voice_chats (``bool``, *optional*): + can_manage_video_chats (``bool``, *optional*): Groups and supergroups only. True, if the administrator can manage voice chats (also called group calls). @@ -71,7 +71,7 @@ def __init__( *, can_manage_chat: bool = True, can_delete_messages: bool = False, - can_manage_voice_chats: bool = False, # Groups and supergroups only + can_manage_video_chats: bool = False, # Groups and supergroups only can_restrict_members: bool = False, can_promote_members: bool = False, can_change_info: bool = False, @@ -85,7 +85,7 @@ def __init__( self.can_manage_chat: bool = can_manage_chat self.can_delete_messages: bool = can_delete_messages - self.can_manage_voice_chats: bool = can_manage_voice_chats + self.can_manage_video_chats: bool = can_manage_video_chats self.can_restrict_members: bool = can_restrict_members self.can_promote_members: bool = can_promote_members self.can_change_info: bool = can_change_info @@ -100,7 +100,7 @@ def _parse(admin_rights: "raw.base.ChatAdminRights") -> "ChatPrivileges": return ChatPrivileges( can_manage_chat=admin_rights.other, can_delete_messages=admin_rights.delete_messages, - can_manage_voice_chats=admin_rights.manage_call, + can_manage_video_chats=admin_rights.manage_call, can_restrict_members=admin_rights.ban_users, can_promote_members=admin_rights.add_admins, can_change_info=admin_rights.change_info, From 7654dc82e84b3347872c0479e2d60529f9a23776 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 191/539] Add methods {get,set}_bot_default_privileges.py --- compiler/docs/compiler.py | 2 + pyrogram/methods/bots/__init__.py | 6 +- .../bots/get_bot_default_privileges.py | 57 +++++++++++++ .../bots/set_bot_default_privileges.py | 79 +++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/bots/get_bot_default_privileges.py create mode 100644 pyrogram/methods/bots/set_bot_default_privileges.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 9b9d2322da..c5f8dea5fe 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -295,6 +295,8 @@ def get_title_list(s: str) -> list: set_bot_commands get_bot_commands delete_bot_commands + set_bot_default_privileges + get_bot_default_privileges """, authorization=""" Authorization diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index 54854b8e3d..7ff79e8403 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -20,12 +20,14 @@ from .answer_inline_query import AnswerInlineQuery from .delete_bot_commands import DeleteBotCommands from .get_bot_commands import GetBotCommands +from .get_bot_default_privileges import GetBotDefaultPrivileges from .get_game_high_scores import GetGameHighScores from .get_inline_bot_results import GetInlineBotResults from .request_callback_answer import RequestCallbackAnswer from .send_game import SendGame from .send_inline_bot_result import SendInlineBotResult from .set_bot_commands import SetBotCommands +from .set_bot_default_privileges import SetBotDefaultPrivileges from .set_game_score import SetGameScore @@ -40,6 +42,8 @@ class Bots( GetGameHighScores, SetBotCommands, GetBotCommands, - DeleteBotCommands + DeleteBotCommands, + SetBotDefaultPrivileges, + GetBotDefaultPrivileges ): pass diff --git a/pyrogram/methods/bots/get_bot_default_privileges.py b/pyrogram/methods/bots/get_bot_default_privileges.py new file mode 100644 index 0000000000..e1f70fa1e8 --- /dev/null +++ b/pyrogram/methods/bots/get_bot_default_privileges.py @@ -0,0 +1,57 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class GetBotDefaultPrivileges: + async def get_bot_default_privileges( + self: "pyrogram.Client", + for_channels: bool = None + ) -> Optional["types.ChatPrivileges"]: + """Get the current default privileges of the bot. + + Parameters: + for_channels (``bool``, *optional*): + Pass True to get default privileges of the bot in channels. Otherwise, default privileges of the bot + for groups and supergroups will be returned. + + Returns: + ``bool``: On success, True is returned. + + Example: + .. code-block:: python + + privileges = await app.get_bot_default_privileges() + """ + + bot_info = await self.invoke( + raw.functions.users.GetFullUser( + id=raw.types.InputUserSelf() + ) + ) + + field = "bot_broadcast_admin_rights" if for_channels else "bot_group_admin_rights" + + admin_rights = getattr(bot_info.full_user, field) + + return types.ChatPrivileges._parse(admin_rights) if admin_rights else None diff --git a/pyrogram/methods/bots/set_bot_default_privileges.py b/pyrogram/methods/bots/set_bot_default_privileges.py new file mode 100644 index 0000000000..52e480266b --- /dev/null +++ b/pyrogram/methods/bots/set_bot_default_privileges.py @@ -0,0 +1,79 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from pyrogram import types + + +class SetBotDefaultPrivileges: + async def set_bot_default_privileges( + self: "pyrogram.Client", + privileges: "types.ChatPrivileges" = None, + for_channels: bool = None + ) -> bool: + """Change the default privileges requested by the bot when it's added as an administrator to groups or channels. + + These privileges will be suggested to users, but they are are free to modify the list before adding the bot. + + Parameters: + privileges (:obj:`~pyrogram.types.ChatPrivileges`): + New default privileges. None to clear. + Defaults to None. + + for_channels (``bool``, *optional*): + Pass True to change the default privileges of the bot in channels. Otherwise, the default privileges of + the bot for groups and supergroups will be changed. + + Returns: + ``bool``: On success, True is returned. + + Example: + .. code-block:: python + + from pyrogram.types import ChatPrivileges + + await app.set_bot_default_privileges( + ChatPrivileges( + can_delete_messages=True, + can_restrict_members=True + ) + ) + """ + + function = ( + raw.functions.bots.SetBotBroadcastDefaultAdminRights + if for_channels + else raw.functions.bots.SetBotGroupDefaultAdminRights + ) + + admin_rights = raw.types.ChatAdminRights( + change_info=privileges.can_change_info, + post_messages=privileges.can_post_messages, + edit_messages=privileges.can_edit_messages, + delete_messages=privileges.can_delete_messages, + ban_users=privileges.can_restrict_members, + invite_users=privileges.can_invite_users, + pin_messages=privileges.can_pin_messages, + add_admins=privileges.can_promote_members, + anonymous=privileges.is_anonymous, + manage_call=privileges.can_manage_video_chats, + other=privileges.can_manage_chat + ) if privileges else raw.types.ChatAdminRights() + + return await self.invoke(function(admin_rights=admin_rights)) From 76546b0a1354d34f26192bc1f4320d3bf311db3c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 192/539] Add MenuButton related classes --- compiler/docs/compiler.py | 4 ++ pyrogram/types/bots_and_keyboards/__init__.py | 10 +++- .../types/bots_and_keyboards/menu_button.py | 44 ++++++++++++++++ .../menu_button_commands.py | 32 ++++++++++++ .../bots_and_keyboards/menu_button_default.py | 32 ++++++++++++ .../bots_and_keyboards/menu_button_web_app.py | 51 +++++++++++++++++++ 6 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/bots_and_keyboards/menu_button.py create mode 100644 pyrogram/types/bots_and_keyboards/menu_button_commands.py create mode 100644 pyrogram/types/bots_and_keyboards/menu_button_default.py create mode 100644 pyrogram/types/bots_and_keyboards/menu_button_web_app.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c5f8dea5fe..e9007b7bdd 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -419,6 +419,10 @@ def get_title_list(s: str) -> list: GameHighScore CallbackGame WebAppInfo + MenuButton + MenuButtonCommands + MenuButtonWebApp + MenuButtonDefault """, bot_commands=""" Bot commands diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 44fd589452..58f98ced31 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -33,6 +33,10 @@ from .inline_keyboard_markup import InlineKeyboardMarkup from .keyboard_button import KeyboardButton from .login_url import LoginUrl +from .menu_button import MenuButton +from .menu_button_commands import MenuButtonCommands +from .menu_button_default import MenuButtonDefault +from .menu_button_web_app import MenuButtonWebApp from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove from .web_app_info import WebAppInfo @@ -57,5 +61,9 @@ "BotCommandScopeChatAdministrators", "BotCommandScopeChatMember", "BotCommandScopeDefault", - "WebAppInfo" + "WebAppInfo", + "MenuButton", + "MenuButtonCommands", + "MenuButtonWebApp", + "MenuButtonDefault" ] diff --git a/pyrogram/types/bots_and_keyboards/menu_button.py b/pyrogram/types/bots_and_keyboards/menu_button.py new file mode 100644 index 0000000000..e61e7baa29 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button.py @@ -0,0 +1,44 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from ..object import Object + + +class MenuButton(Object): + """Describes the bot's menu button in a private chat. + + It should be one of: + + - :obj:`~pyrogram.types.MenuButtonCommands` + - :obj:`~pyrogram.types.MenuButtonWebApp` + - :obj:`~pyrogram.types.MenuButtonDefault` + + If a menu button other than :obj:`~pyrogram.types.MenuButtonDefault` is set for a private chat, then it is applied + in the chat. Otherwise the default menu button is applied. By default, the menu button opens the list of bot + commands. + """ + + def __init__(self, type: str): + super().__init__() + + self.type = type + + async def write(self, client: "pyrogram.Client") -> "raw.base.BotMenuButton": + raise NotImplementedError diff --git a/pyrogram/types/bots_and_keyboards/menu_button_commands.py b/pyrogram/types/bots_and_keyboards/menu_button_commands.py new file mode 100644 index 0000000000..b2ef77c9de --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_commands.py @@ -0,0 +1,32 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from .menu_button import MenuButton + + +class MenuButtonCommands(MenuButton): + """A menu button, which opens the bot's list of commands. + """ + + def __init__(self): + super().__init__("commands") + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonCommands": + return raw.types.BotMenuButtonCommands() diff --git a/pyrogram/types/bots_and_keyboards/menu_button_default.py b/pyrogram/types/bots_and_keyboards/menu_button_default.py new file mode 100644 index 0000000000..a00e67633e --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_default.py @@ -0,0 +1,32 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from .menu_button import MenuButton + + +class MenuButtonDefault(MenuButton): + """Describes that no specific value for the menu button was set. + """ + + def __init__(self): + super().__init__("default") + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonDefault": + return raw.types.BotMenuButtonDefault() diff --git a/pyrogram/types/bots_and_keyboards/menu_button_web_app.py b/pyrogram/types/bots_and_keyboards/menu_button_web_app.py new file mode 100644 index 0000000000..109088bbcf --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_web_app.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw, types +from .menu_button import MenuButton + + +class MenuButtonWebApp(MenuButton): + """A menu button, which launches a `Web App `_. + + Parameters: + text (``str``): + Text on the button + + web_app (:obj:`~pyrogram.types.WebAppInfo`): + Description of the Web App that will be launched when the user presses the button. + The Web App will be able to send an arbitrary message on behalf of the user using the method + :meth:`~pyrogram.Client.answer_web_app_query`. + """ + + def __init__( + self, + text: str, + web_app: "types.WebAppInfo" + ): + super().__init__("web_app") + + self.text = text + self.web_app = web_app + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButton": + return raw.types.BotMenuButton( + text=self.text, + url=self.web_app.url + ) From 173888f7c92f1e4afb90d41b9615d5ef3c520efa Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 193/539] Fix renamed classes in the documentation --- compiler/docs/compiler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index e9007b7bdd..68be1e0777 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -401,10 +401,10 @@ def get_title_list(s: str) -> list: PollOption Dice Reaction - VoiceChatScheduled - VoiceChatStarted - VoiceChatEnded - VoiceChatMembersInvited + VideoChatScheduled + VideoChatStarted + VideoChatEnded + VideoChatMembersInvited """, bot_keyboards=""" Bot keyboards From fd0044c2ecb75b5ac7d84cbdbb22cbf69726bc80 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 194/539] Add {get,set}_chat_menu_button --- compiler/docs/compiler.py | 2 + pyrogram/methods/bots/__init__.py | 6 +- pyrogram/methods/bots/get_chat_menu_button.py | 63 +++++++++++++++++++ pyrogram/methods/bots/set_chat_menu_button.py | 53 ++++++++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/bots/get_chat_menu_button.py create mode 100644 pyrogram/methods/bots/set_chat_menu_button.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 68be1e0777..be5c14bba4 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -297,6 +297,8 @@ def get_title_list(s: str) -> list: delete_bot_commands set_bot_default_privileges get_bot_default_privileges + set_chat_menu_button + get_chat_menu_button """, authorization=""" Authorization diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index 7ff79e8403..de1abe1c2e 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -21,6 +21,7 @@ from .delete_bot_commands import DeleteBotCommands from .get_bot_commands import GetBotCommands from .get_bot_default_privileges import GetBotDefaultPrivileges +from .get_chat_menu_button import GetChatMenuButton from .get_game_high_scores import GetGameHighScores from .get_inline_bot_results import GetInlineBotResults from .request_callback_answer import RequestCallbackAnswer @@ -28,6 +29,7 @@ from .send_inline_bot_result import SendInlineBotResult from .set_bot_commands import SetBotCommands from .set_bot_default_privileges import SetBotDefaultPrivileges +from .set_chat_menu_button import SetChatMenuButton from .set_game_score import SetGameScore @@ -44,6 +46,8 @@ class Bots( GetBotCommands, DeleteBotCommands, SetBotDefaultPrivileges, - GetBotDefaultPrivileges + GetBotDefaultPrivileges, + SetChatMenuButton, + GetChatMenuButton ): pass diff --git a/pyrogram/methods/bots/get_chat_menu_button.py b/pyrogram/methods/bots/get_chat_menu_button.py new file mode 100644 index 0000000000..ec1c7ed238 --- /dev/null +++ b/pyrogram/methods/bots/get_chat_menu_button.py @@ -0,0 +1,63 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class GetChatMenuButton: + async def get_chat_menu_button( + self: "pyrogram.Client", + chat_id: Union[int, str] = None, + ) -> "types.MenuButton": + """Get the current value of the bot's menu button in a private chat, or the default menu button. + + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + If not specified, default bot's menu button will be returned. + """ + + if chat_id: + r = await self.invoke( + raw.functions.bots.GetBotMenuButton( + user_id=await self.resolve_peer(chat_id), + ) + ) + else: + r = (await self.invoke( + raw.functions.users.GetFullUser( + id=raw.types.InputUserSelf() + ) + )).full_user.bot_info.menu_button + + if isinstance(r, raw.types.BotMenuButtonCommands): + return types.MenuButtonCommands() + + if isinstance(r, raw.types.BotMenuButtonDefault): + return types.MenuButtonDefault() + + if isinstance(r, raw.types.BotMenuButton): + return types.MenuButtonWebApp( + text=r.text, + web_app=types.WebAppInfo( + url=r.url + ) + ) diff --git a/pyrogram/methods/bots/set_chat_menu_button.py b/pyrogram/methods/bots/set_chat_menu_button.py new file mode 100644 index 0000000000..1305c495c4 --- /dev/null +++ b/pyrogram/methods/bots/set_chat_menu_button.py @@ -0,0 +1,53 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Union + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class SetChatMenuButton: + async def set_chat_menu_button( + self: "pyrogram.Client", + chat_id: Union[int, str] = None, + menu_button: "types.MenuButton" = None + ) -> bool: + """Change the bot's menu button in a private chat, or the default menu button. + + chat_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the target chat. + If not specified, default bot's menu button will be changed. + + menu_button (:obj:`~pyrogram.types.MenuButton`, *optional*): + The new bot's menu button. + Defaults to :obj:`~pyrogram.types.MenuButtonDefault`. + """ + + await self.invoke( + raw.functions.bots.SetBotMenuButton( + user_id=await self.resolve_peer(chat_id or "me"), + button=( + (await menu_button.write(self)) if menu_button + else (await types.MenuButtonDefault().write(self)) + ) + ) + ) + + return True From b7b7e8ec696e5562945e6f337d05341005210c20 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 195/539] Use GitHub buttons with dark theme support --- docs/source/support.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/source/support.rst b/docs/source/support.rst index 32dfdb6b71..8efa4bc19f 100644 --- a/docs/source/support.rst +++ b/docs/source/support.rst @@ -7,14 +7,16 @@ Support Pyrogram
Fork + href="https://github.com/pyrogram/pyrogram" + data-color-scheme="no-preference: light; light: light; dark: dark;" + data-icon="octicon-star" data-size="large" data-show-count="true" + aria-label="Star pyrogram/pyrogram on GitHub">Star Star + href="https://github.com/pyrogram/pyrogram/fork" + data-color-scheme="no-preference: light; light: light; dark: dark;" + data-icon="octicon-repo-forked" data-size="large" + data-show-count="true" aria-label="Fork pyrogram/pyrogram on GitHub">Fork

@@ -34,10 +36,9 @@ GitHub Sponsor - Sponsor + data-color-scheme="no-preference: light; light: light; dark: dark;" + data-icon="octicon-heart" data-size="large" + aria-label="Sponsor @delivrance on GitHub">Sponsor ----- From ccadabca4a6a6e6ba2da12d88b51573da855fac7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 196/539] Update documentation --- docs/source/index.rst | 4 ++-- docs/source/topics/speedups.rst | 25 ++++++++++++++++++++++++- docs/source/topics/synchronous.rst | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 885f79dd8e..d4699d5430 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -141,9 +141,9 @@ Meta topics/create-filters topics/more-on-updates topics/client-settings - topics/synchronous - topics/text-formatting topics/speedups + topics/text-formatting + topics/synchronous topics/smart-plugins topics/storage-engines topics/serializing diff --git a/docs/source/topics/speedups.rst b/docs/source/topics/speedups.rst index 6340e1ad4f..821b26f4df 100644 --- a/docs/source/topics/speedups.rst +++ b/docs/source/topics/speedups.rst @@ -45,21 +45,44 @@ Installation Usage ^^^^^ -Call ``uvloop.install()`` before calling ``asyncio.run()`` or ``app.run()`` +Call ``uvloop.install()`` before calling ``asyncio.run()`` or ``app.run()``. .. code-block:: python import asyncio import uvloop + from pyrogram import Client + + async def main(): app = Client("my_account") async with app: print(await app.get_me()) + uvloop.install() asyncio.run(main()) +The ``uvloop.install()`` call also needs to be placed before creating a Client instance. + +.. code-block:: python + + import uvloop + from pyrogram import Client + + uvloop.install() + + app = Client("my_account") + + + @app.on_message() + async def hello(client, message): + print(await client.get_me()) + + + app.run() + .. _TgCrypto: https://github.com/pyrogram/tgcrypto .. _uvloop: https://github.com/MagicStack/uvloop diff --git a/docs/source/topics/synchronous.rst b/docs/source/topics/synchronous.rst index e082f18c48..a6e12383d1 100644 --- a/docs/source/topics/synchronous.rst +++ b/docs/source/topics/synchronous.rst @@ -71,3 +71,18 @@ possible. @app.on_edited_message() def handler2(client, message): message.forward("me") + +uvloop usage +------------ + +When using Pyrogram in its synchronous mode combined with uvloop, you need to call ``uvloop.install()`` before importing +Pyrogram. + +.. code-block:: python + + import uvloop + uvloop.install() + + from pyrogram import Client + + ... \ No newline at end of file From 59ccc4de8880ce540849d4a18ae5334b80392b6b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 197/539] Documentation fixes --- pyrogram/filters.py | 4 ++-- pyrogram/methods/bots/get_chat_menu_button.py | 7 ++++--- pyrogram/methods/bots/set_chat_menu_button.py | 15 ++++++++------- .../types/user_and_chats/chat_event_filter.py | 10 +++++----- pyrogram/types/user_and_chats/chat_privileges.py | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 013adee4e2..76bff856ff 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -642,7 +642,7 @@ async def video_chat_started_filter(_, __, m: Message): video_chat_started = create(video_chat_started_filter) -"""Filter messages for started voice chats""" +"""Filter messages for started video chats""" # endregion @@ -653,7 +653,7 @@ async def video_chat_ended_filter(_, __, m: Message): video_chat_ended = create(video_chat_ended_filter) -"""Filter messages for ended voice chats""" +"""Filter messages for ended video chats""" # endregion diff --git a/pyrogram/methods/bots/get_chat_menu_button.py b/pyrogram/methods/bots/get_chat_menu_button.py index ec1c7ed238..8fb61b0173 100644 --- a/pyrogram/methods/bots/get_chat_menu_button.py +++ b/pyrogram/methods/bots/get_chat_menu_button.py @@ -30,9 +30,10 @@ async def get_chat_menu_button( ) -> "types.MenuButton": """Get the current value of the bot's menu button in a private chat, or the default menu button. - chat_id (``int`` | ``str``): - Unique identifier (int) or username (str) of the target chat. - If not specified, default bot's menu button will be returned. + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + If not specified, default bot's menu button will be returned. """ if chat_id: diff --git a/pyrogram/methods/bots/set_chat_menu_button.py b/pyrogram/methods/bots/set_chat_menu_button.py index 1305c495c4..87e26c036c 100644 --- a/pyrogram/methods/bots/set_chat_menu_button.py +++ b/pyrogram/methods/bots/set_chat_menu_button.py @@ -31,13 +31,14 @@ async def set_chat_menu_button( ) -> bool: """Change the bot's menu button in a private chat, or the default menu button. - chat_id (``int`` | ``str``, *optional*): - Unique identifier (int) or username (str) of the target chat. - If not specified, default bot's menu button will be changed. - - menu_button (:obj:`~pyrogram.types.MenuButton`, *optional*): - The new bot's menu button. - Defaults to :obj:`~pyrogram.types.MenuButtonDefault`. + Parameters: + chat_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the target chat. + If not specified, default bot's menu button will be changed. + + menu_button (:obj:`~pyrogram.types.MenuButton`, *optional*): + The new bot's menu button. + Defaults to :obj:`~pyrogram.types.MenuButtonDefault`. """ await self.invoke( diff --git a/pyrogram/types/user_and_chats/chat_event_filter.py b/pyrogram/types/user_and_chats/chat_event_filter.py index 7edc3a07eb..92298ea3be 100644 --- a/pyrogram/types/user_and_chats/chat_event_filter.py +++ b/pyrogram/types/user_and_chats/chat_event_filter.py @@ -66,8 +66,8 @@ class ChatEventFilter(Object): True, if members leaving events should be returned. Defaults to False. - voice_chats (``bool``, *optional*): - True, if voice chats events should be returned. + video_chats (``bool``, *optional*): + True, if video chats events should be returned. Defaults to False. """ @@ -83,7 +83,7 @@ def __init__( edited_messages: bool = False, pinned_messages: bool = False, leaving_members: bool = False, - voice_chats: bool = False + video_chats: bool = False ): super().__init__() @@ -97,7 +97,7 @@ def __init__( self.edited_messages = edited_messages self.pinned_messages = pinned_messages self.leaving_members = leaving_members - self.voice_chats = voice_chats + self.video_chats = video_chats def write(self) -> "raw.base.ChannelAdminLogEventsFilter": join = False @@ -152,7 +152,7 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter": if self.leaving_members: leave = True - if self.voice_chats: + if self.video_chats: group_call = True return raw.types.ChannelAdminLogEventsFilter( diff --git a/pyrogram/types/user_and_chats/chat_privileges.py b/pyrogram/types/user_and_chats/chat_privileges.py index 8a420da5b7..09bb341dfc 100644 --- a/pyrogram/types/user_and_chats/chat_privileges.py +++ b/pyrogram/types/user_and_chats/chat_privileges.py @@ -34,7 +34,7 @@ class ChatPrivileges(Object): can_manage_video_chats (``bool``, *optional*): Groups and supergroups only. - True, if the administrator can manage voice chats (also called group calls). + True, if the administrator can manage video chats (also called group calls). can_restrict_members (``bool``, *optional*): True, if the administrator can restrict, ban or unban chat members. From 515531774ba72de3dc9c47fedf52e5e1b56eed7b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 198/539] Small documentation fix --- 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 d4699d5430..d96223cb13 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -75,7 +75,7 @@ First Steps :columns: 1 - :doc:`Quick Start `: Overview to get you started quickly. - - :doc:`Calling Methods `: How to call Pyrogram's methods. + - :doc:`Invoking Methods `: How to call Pyrogram's methods. - :doc:`Handling Updates `: How to handle Telegram updates. - :doc:`Error Handling `: How to handle API errors correctly. From b645a75b93201cd1fd203b99145a0fcc73ffc534 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 199/539] Allow negative offsets in stream_media --- pyrogram/methods/messages/stream_media.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/messages/stream_media.py b/pyrogram/methods/messages/stream_media.py index ea41b7bc37..91ffefd7ee 100644 --- a/pyrogram/methods/messages/stream_media.py +++ b/pyrogram/methods/messages/stream_media.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 math from typing import Union, Optional, BinaryIO import pyrogram @@ -62,10 +63,12 @@ async def stream_media( async for chunk in app.stream_media(message, limit=3): print(len(chunk)) - # Stream the last 3 chunks only - import math - chunks = math.ceil(message.document.file_size / 1024 / 1024) - async for chunk in app.stream_media(message, offset=chunks - 3): + # Stream the rest of the media by skipping the first 3 chunks + async for chunk in app.stream_media(message, offset=3): + print(len(chunk)) + + # Stream the last 3 chunks only (negative offset) + async for chunk in app.stream_media(message, offset=-3): print(len(chunk)) """ available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note", @@ -90,5 +93,12 @@ async def stream_media( file_id_obj = FileId.decode(file_id_str) file_size = getattr(media, "file_size", 0) + if offset < 0: + if file_size == 0: + raise ValueError("Negative offsets are not supported for file ids, pass a Message object instead") + + chunks = math.ceil(file_size / 1024 / 1024) + offset += chunks + async for chunk in self.get_file(file_id_obj, file_size, limit, offset): yield chunk From c44643faadbd8c13f4e70903079f705d3bd2784a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 200/539] Add the class WebAppData --- compiler/docs/compiler.py | 1 + pyrogram/enums/message_service.py | 3 ++ pyrogram/types/messages_and_media/__init__.py | 3 +- pyrogram/types/messages_and_media/message.py | 10 ++++ .../types/messages_and_media/web_app_data.py | 51 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/messages_and_media/web_app_data.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index be5c14bba4..a626649d04 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -407,6 +407,7 @@ def get_title_list(s: str) -> list: VideoChatStarted VideoChatEnded VideoChatMembersInvited + WebAppData """, bot_keyboards=""" Bot keyboards diff --git a/pyrogram/enums/message_service.py b/pyrogram/enums/message_service.py index 7b23c730c2..636e6db575 100644 --- a/pyrogram/enums/message_service.py +++ b/pyrogram/enums/message_service.py @@ -68,3 +68,6 @@ class MessageService(AutoName): VIDEO_CHAT_MEMBERS_INVITED = auto() "Video chat members invited" + + WEB_APP_DATA = auto() + "Web app data" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index cbed4f0f9d..e5ade1ea7f 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -37,9 +37,10 @@ from .video_note import VideoNote from .voice import Voice from .webpage import WebPage +from .web_app_data import WebAppData __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", - "Reaction" + "Reaction", "WebAppData" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 7a5341fdd8..526839c951 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -285,6 +285,9 @@ class Message(Object, Update): video_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*): Service message: new members were invited to the voice chat. + web_app_data (:obj:`~pyrogram.types.WebAppData`, *optional*): + Service message: web app data sent to the bot. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -366,6 +369,7 @@ def __init__( video_chat_started: "types.VideoChatStarted" = None, video_chat_ended: "types.VideoChatEnded" = None, video_chat_members_invited: "types.VideoChatMembersInvited" = None, + web_app_data: "types.WebAppData" = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -441,6 +445,7 @@ def __init__( self.video_chat_started = video_chat_started self.video_chat_ended = video_chat_ended self.video_chat_members_invited = video_chat_members_invited + self.web_app_data = web_app_data self.reactions = reactions @staticmethod @@ -491,6 +496,7 @@ async def _parse( video_chat_started = None video_chat_ended = None video_chat_members_invited = None + web_app_data = None service_type = None @@ -537,6 +543,9 @@ async def _parse( elif isinstance(action, raw.types.MessageActionInviteToGroupCall): video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users) service_type = enums.MessageService.VIDEO_CHAT_MEMBERS_INVITED + elif isinstance(action, raw.types.MessageActionWebViewDataSentMe): + web_app_data = types.WebAppData._parse(action) + service_type = enums.MessageService.WEB_APP_DATA from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None @@ -561,6 +570,7 @@ async def _parse( video_chat_started=video_chat_started, video_chat_ended=video_chat_ended, video_chat_members_invited=video_chat_members_invited, + web_app_data=web_app_data, client=client # TODO: supergroup_chat_created ) diff --git a/pyrogram/types/messages_and_media/web_app_data.py b/pyrogram/types/messages_and_media/web_app_data.py new file mode 100644 index 0000000000..b9a471fd89 --- /dev/null +++ b/pyrogram/types/messages_and_media/web_app_data.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from ..object import Object + + +class WebAppData(Object): + """Contains data sent from a `Web App `_ to the bot. + + Parameters: + data (``str``): + The data. + + button_text (``str``): + Text of the *web_app* keyboard button, from which the Web App was opened. + + """ + + def __init__( + self, + *, + data: str, + button_text: str, + ): + super().__init__() + + self.data = data + self.button_text = button_text + + @staticmethod + def _parse(action: "raw.types.MessageActionWebViewDataSentMe"): + return WebAppData( + data=action.data, + button_text=action.text + ) From 663594876d3d5f30087270489ca5c9c50308d20a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 201/539] Rename webpage.py to web_page.py --- pyrogram/types/messages_and_media/__init__.py | 2 +- pyrogram/types/messages_and_media/{webpage.py => web_page.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pyrogram/types/messages_and_media/{webpage.py => web_page.py} (100%) diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index e5ade1ea7f..3a18b2a5bf 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -36,8 +36,8 @@ from .video import Video from .video_note import VideoNote from .voice import Voice -from .webpage import WebPage from .web_app_data import WebAppData +from .web_page import WebPage __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", diff --git a/pyrogram/types/messages_and_media/webpage.py b/pyrogram/types/messages_and_media/web_page.py similarity index 100% rename from pyrogram/types/messages_and_media/webpage.py rename to pyrogram/types/messages_and_media/web_page.py From 4e6c1690d26eb493475f8c75de93eb536ffc4640 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 202/539] Add pack_inline_message_id util function --- pyrogram/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index b3f04e6018..c855ae62e0 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -146,6 +146,26 @@ def parse_deleted_messages(client, update) -> List["types.Message"]: return types.List(parsed_messages) +def pack_inline_message_id(msg_id: "raw.base.InputBotInlineMessageID"): + if isinstance(msg_id, raw.types.InputBotInlineMessageID): + inline_message_id_packed = struct.pack( + " Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 203/539] Use pack_inline_message_id util function in CallbackQuery --- pyrogram/types/bots_and_keyboards/callback_query.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py index dc4741b264..efdd14ca4d 100644 --- a/pyrogram/types/bots_and_keyboards/callback_query.py +++ b/pyrogram/types/bots_and_keyboards/callback_query.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from base64 import b64encode -from struct import pack from typing import Union, List, Match, Optional import pyrogram @@ -102,15 +100,7 @@ async def _parse(client: "pyrogram.Client", callback_query, users) -> "CallbackQ if not message: message = await client.get_messages(chat_id, message_id) elif isinstance(callback_query, raw.types.UpdateInlineBotCallbackQuery): - inline_message_id = b64encode( - pack( - " +# +# 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 import raw, utils +from ..object import Object + + +class SentWebAppMessage(Object): + """Contains information about an inline message sent by a `Web App `_ on behalf of a user. + + Parameters: + inline_message_id (``str``): + Identifier of the sent inline message. + Available only if there is an inline keyboard attached to the message. + """ + + def __init__( + self, *, + inline_message_id: str, + ): + super().__init__() + + self.inline_message_id = inline_message_id + + @staticmethod + def _parse(obj: "raw.types.WebViewMessageSent"): + return SentWebAppMessage(inline_message_id=utils.pack_inline_message_id(obj.msg_id)) From 43f9b57567edffc1c86d41c269570abf2ed6ebcf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 205/539] Add the method answer_web_app_query --- compiler/docs/compiler.py | 1 + pyrogram/methods/bots/__init__.py | 4 +- pyrogram/methods/bots/answer_web_app_query.py | 51 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/bots/answer_web_app_query.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index e1667a8519..3948df6933 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -299,6 +299,7 @@ def get_title_list(s: str) -> list: get_bot_default_privileges set_chat_menu_button get_chat_menu_button + answer_web_app_query """, authorization=""" Authorization diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index de1abe1c2e..da52fcfb00 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -18,6 +18,7 @@ from .answer_callback_query import AnswerCallbackQuery from .answer_inline_query import AnswerInlineQuery +from .answer_web_app_query import AnswerWebAppQuery from .delete_bot_commands import DeleteBotCommands from .get_bot_commands import GetBotCommands from .get_bot_default_privileges import GetBotDefaultPrivileges @@ -48,6 +49,7 @@ class Bots( SetBotDefaultPrivileges, GetBotDefaultPrivileges, SetChatMenuButton, - GetChatMenuButton + GetChatMenuButton, + AnswerWebAppQuery ): pass diff --git a/pyrogram/methods/bots/answer_web_app_query.py b/pyrogram/methods/bots/answer_web_app_query.py new file mode 100644 index 0000000000..f887e28098 --- /dev/null +++ b/pyrogram/methods/bots/answer_web_app_query.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw +from pyrogram import types + + +class AnswerWebAppQuery: + async def answer_web_app_query( + self: "pyrogram.Client", + web_app_query_id: str, + result: "types.InlineQueryResult" + ) -> "types.SentWebAppMessage": + """Set the result of an interaction with a `Web App `_ and send a + corresponding message on behalf of the user to the chat from which the query originated. + + Parameters: + web_app_query_id (``str``): + Unique identifier for the answered query. + + result (:obj:`~pyrogram.types.InlineQueryResult`): + A list of results for the inline query. + + Returns: + :obj:`~pyrogram.types.SentWebAppMessage`: On success the sent web app message is returned. + """ + + r = await self.invoke( + raw.functions.messages.SendWebViewResultMessage( + bot_query_id=web_app_query_id, + result=await result.write(self) + ) + ) + + return types.SentWebAppMessage._parse(r) From 6087c2a9748d5216be217e1a6ed0ea967793ef87 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 206/539] Add missing entry in __init__.py --- pyrogram/types/bots_and_keyboards/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 58f98ced31..6f05a3b486 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -39,6 +39,7 @@ from .menu_button_web_app import MenuButtonWebApp from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove +from .sent_web_app_message import SentWebAppMessage from .web_app_info import WebAppInfo __all__ = [ @@ -65,5 +66,6 @@ "MenuButton", "MenuButtonCommands", "MenuButtonWebApp", - "MenuButtonDefault" + "MenuButtonDefault", + "SentWebAppMessage" ] From 2ad53ec00ba9fea4a2873ef4ea85b33138264447 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 207/539] Update unpack_inline_message_id --- pyrogram/utils.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index c855ae62e0..18230ed4f5 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -166,15 +166,27 @@ def pack_inline_message_id(msg_id: "raw.base.InputBotInlineMessageID"): return base64.urlsafe_b64encode(inline_message_id_packed).decode().rstrip("=") -def unpack_inline_message_id(inline_message_id: str) -> "raw.types.InputBotInlineMessageID": - r = inline_message_id + "=" * (-len(inline_message_id) % 4) - r = struct.unpack(" "raw.base.InputBotInlineMessageID": + padded = inline_message_id + "=" * (-len(inline_message_id) % 4) + decoded = base64.urlsafe_b64decode(padded) + + if len(decoded) == 20: + unpacked = struct.unpack(" Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 208/539] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 66ede5066d..160c0fda64 100644 --- a/setup.py +++ b/setup.py @@ -140,12 +140,12 @@ def run(self): download_url="https://github.com/pyrogram/pyrogram/releases/latest", author="Dan", author_email="dan@pyrogram.org", - license="LGPLv3+", + license="LGPLv3", classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", - "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", + "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", From 1ebc7041464302ec2bf37cd701ffc712c27982f2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 209/539] Documentation cleanup --- compiler/docs/compiler.py | 3 --- compiler/docs/template/toctree.txt | 2 -- compiler/errors/compiler.py | 2 -- 3 files changed, 7 deletions(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 3948df6933..a03d2ee316 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -21,8 +21,6 @@ import re import shutil -import pyrogram - HOME = "compiler/docs" DESTINATION = "docs/source/telegram" PYROGRAM_API_DEST = "docs/source/api" @@ -114,7 +112,6 @@ def build(path, level=0): toctree.format( title=k.title(), title_markup="=" * len(k), - layer=pyrogram.raw.all.layer, module=module, entities="\n ".join(entities) ) diff --git a/compiler/docs/template/toctree.txt b/compiler/docs/template/toctree.txt index cc2ca9ac22..717276c40e 100644 --- a/compiler/docs/template/toctree.txt +++ b/compiler/docs/template/toctree.txt @@ -1,8 +1,6 @@ {title} {title_markup} -Layer {layer} - .. module:: {module} .. toctree:: diff --git a/compiler/errors/compiler.py b/compiler/errors/compiler.py index d2c1010456..0c4ef399b6 100644 --- a/compiler/errors/compiler.py +++ b/compiler/errors/compiler.py @@ -133,8 +133,6 @@ def start(): with open("{}/all.py".format(DEST), "w", encoding="utf-8") as f: f.write(re.sub("{count}", str(count), content)) - print("Compiling Errors: [100%]") - if "__main__" == __name__: HOME = "." From 109c9d4a0af2961377a7ff44b71ac18426f7076b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 210/539] Migrate setup.py commands to a Makefile --- Makefile | 53 ++++++++++++++++++++++ dev-requirements.txt | 3 +- docs/Makefile | 24 ---------- docs/make.bat | 36 --------------- docs/requirements.txt | 4 +- setup.py | 103 ++---------------------------------------- 6 files changed, 59 insertions(+), 164 deletions(-) create mode 100644 Makefile delete mode 100644 docs/Makefile delete mode 100644 docs/make.bat diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..0d19832945 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +VENV := venv +PYTHON := $(VENV)/bin/python + +RM := rm -rf + +.PHONY: venv build docs + +venv: + $(RM) $(VENV) + python3 -m venv $(VENV) + $(PYTHON) -m pip install -U pip wheel setuptools + $(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt -r docs/requirements.txt + @echo "Created venv with $$($(PYTHON) --version)" + +clean-build: + $(RM) *.egg-info build dist + +clean-docs: + $(RM) docs/build + $(RM) docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram + +clean-api: + $(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types + +clean: + make clean-build + make clean-docs + make clean-api + +api: + cd compiler/api && ../../$(PYTHON) compiler.py + cd compiler/errors && ../../$(PYTHON) compiler.py + +docs-live: + make clean-docs + cd compiler/docs && ../../$(PYTHON) compiler.py + $(RM) docs/source/telegram + $(VENV)/bin/sphinx-autobuild \ + --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \ + --watch pyrogram --watch docs/resources \ + -b html "docs/source" "docs/build/html" -j auto + +docs: + make clean-docs + cd compiler/docs && ../../$(PYTHON) compiler.py + $(VENV)/bin/sphinx-build \ + -b html "docs/source" "docs/build/html" -j auto + +build: + make clean-build + make clean-api + $(PYTHON) setup.py sdist + $(PYTHON) setup.py bdist_wheel \ No newline at end of file diff --git a/dev-requirements.txt b/dev-requirements.txt index 17f8c0348c..d8968085b3 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,4 +2,5 @@ pytest pytest-asyncio -pytest-cov \ No newline at end of file +pytest-cov +twine \ No newline at end of file diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 066560f8f7..0000000000 --- a/docs/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -j $(shell nproc --all) -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) - -lhtml: # live html - sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \ - --watch ../pyrogram --watch resources -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index fea543e258..0000000000 --- a/docs/make.bat +++ /dev/null @@ -1,36 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=source -set BUILDDIR=build -set SPHINXPROJ=Pyrogram - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd diff --git a/docs/requirements.txt b/docs/requirements.txt index f83e673d74..7283c8ba69 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,4 @@ sphinx sphinx_rtd_theme==1.0.0 sphinx_copybutton -pypandoc -requests -sphinx-autobuild +sphinx-autobuild \ No newline at end of file diff --git a/setup.py b/setup.py index 160c0fda64..d1bd9c90dd 100644 --- a/setup.py +++ b/setup.py @@ -16,15 +16,12 @@ # 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 -from setuptools import setup, find_packages, Command +from setuptools import setup, find_packages from compiler.api import compiler as api_compiler -from compiler.docs import compiler as docs_compiler from compiler.errors import compiler as errors_compiler with open("requirements.txt", encoding="utf-8") as r: @@ -36,96 +33,6 @@ with open("README.md", encoding="utf-8") as f: readme = f.read() - -class Clean(Command): - DIST = ["./build", "./dist", "./Pyrogram.egg-info"] - API = [ - "pyrogram/errors/exceptions", "pyrogram/raw/functions", "pyrogram/raw/types", "pyrogram/raw/base", - "pyrogram/raw/all.py" - ] - DOCS = [ - "docs/source/telegram", "docs/build", "docs/source/api/methods", "docs/source/api/types", - "docs/source/api/bound-methods" - ] - - 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 - - def finalize_options(self): - pass - - def run(self): - 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 or not paths: - 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: - print("skipping {}".format(path)) - 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: - errors_compiler.start() - api_compiler.start() - - if self.docs: - docs_compiler.start() - - if len(argv) > 1 and argv[1] in ["bdist_wheel", "install", "develop"]: api_compiler.start() errors_compiler.start() @@ -172,14 +79,10 @@ def run(self): "Documentation": "https://docs.pyrogram.org", }, python_requires="~=3.6", - package_data = { + package_data={ "pyrogram": ["py.typed"], }, packages=find_packages(exclude=["compiler*", "tests*"]), zip_safe=False, - install_requires=requires, - cmdclass={ - "clean": Clean, - "generate": Generate - } + install_requires=requires ) From 077687b85d4ff5759f16668aa996c6bf940dca43 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 211/539] Add missing fields to InlineQueryResultArticle --- .../inline_query_result_article.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/pyrogram/types/inline_mode/inline_query_result_article.py b/pyrogram/types/inline_mode/inline_query_result_article.py index 73260dd9cc..096273f15b 100644 --- a/pyrogram/types/inline_mode/inline_query_result_article.py +++ b/pyrogram/types/inline_mode/inline_query_result_article.py @@ -43,11 +43,17 @@ class InlineQueryResultArticle(InlineQueryResult): description (``str``, *optional*): Short description of the result. - thumb_url (``str``, *optional*): - URL of the thumbnail for the result. - reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): Inline keyboard attached to the message. + + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumb_width (``int``, *optional*): + Thumbnail width. + + thumb_height (``int``, *optional*): + Thumbnail height """ def __init__( @@ -55,10 +61,12 @@ def __init__( title: str, input_message_content: "types.InputMessageContent", id: str = None, - reply_markup: "types.InlineKeyboardMarkup" = None, url: str = None, description: str = None, - thumb_url: str = None + reply_markup: "types.InlineKeyboardMarkup" = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 ): super().__init__("article", id, input_message_content, reply_markup) @@ -66,6 +74,8 @@ def __init__( self.url = url self.description = description self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height async def write(self, client: "pyrogram.Client"): return raw.types.InputBotInlineResult( @@ -79,6 +89,11 @@ async def write(self, client: "pyrogram.Client"): url=self.thumb_url, size=0, mime_type="image/jpeg", - attributes=[] + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumb_width, + h=self.thumb_height + ) + ] ) if self.thumb_url else None ) From 5108b78ef5823e76ca96edcf1c30fa0c1ab08bc6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 212/539] Add missing fields to InlineQueryResultPhoto --- .../inline_mode/inline_query_result_photo.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py index 110b604661..9e03548954 100644 --- a/pyrogram/types/inline_mode/inline_query_result_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_photo.py @@ -39,6 +39,12 @@ class InlineQueryResultPhoto(InlineQueryResult): URL of the thumbnail for the photo. Defaults to the value passed in *photo_url*. + photo_width (``int``, *optional*): + Width of the photo. + + photo_height (``int``, *optional*): + Height of the photo + id (``str``, *optional*): Unique identifier for this result, 1-64 bytes. Defaults to a randomly generated UUID4. @@ -70,6 +76,8 @@ def __init__( self, photo_url: str, thumb_url: str = None, + photo_width: int = 0, + photo_height: int = 0, id: str = None, title: str = None, description: str = None, @@ -83,6 +91,8 @@ def __init__( self.photo_url = photo_url self.thumb_url = thumb_url + self.photo_width = photo_width + self.photo_height = photo_height self.title = title self.description = description self.caption = caption @@ -96,7 +106,12 @@ async def write(self, client: "pyrogram.Client"): url=self.photo_url, size=0, mime_type="image/jpeg", - attributes=[] + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.photo_width, + h=self.photo_height + ) + ] ) if self.thumb_url is None: From 4367dbc46551a4ec256bef89a8d35ae4f744b7a2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 213/539] Add missing fields to InlineQueryResultAnimation --- .../inline_query_result_animation.py | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py index 4a170a1834..71d1edf40a 100644 --- a/pyrogram/types/inline_mode/inline_query_result_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_animation.py @@ -35,10 +35,23 @@ class InlineQueryResultAnimation(InlineQueryResult): A valid URL for the animated GIF file. File size must not exceed 1 MB. + animation_width (``int``, *optional*) + Width of the animation. + + animation_height (``int``, *optional*) + Height of the animation. + + animation_duration (``int``, *optional*) + Duration of the animation in seconds. + thumb_url (``str``, *optional*): URL of the static thumbnail for the result (jpeg or gif) Defaults to the value passed in *animation_url*. + thumb_mime_type (``str``, *optional*) + MIME type of the thumbnail, must be one of "image/jpeg", "image/gif", or "video/mp4". + Defaults to "image/jpeg". + id (``str``, *optional*): Unique identifier for this result, 1-64 bytes. Defaults to a randomly generated UUID4. @@ -46,11 +59,8 @@ class InlineQueryResultAnimation(InlineQueryResult): title (``str``, *optional*): Title for the result. - description (``str``, *optional*): - Short description of the result. - caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the animation to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -69,7 +79,11 @@ class InlineQueryResultAnimation(InlineQueryResult): def __init__( self, animation_url: str, + animation_width: int = 0, + animation_height: int = 0, + animation_duration: int = 0, thumb_url: str = None, + thumb_mime_type: str = "image/jpeg", id: str = None, title: str = None, description: str = None, @@ -82,7 +96,11 @@ def __init__( super().__init__("gif", id, input_message_content, reply_markup) self.animation_url = animation_url + self.animation_width = animation_width + self.animation_height = animation_height + self.animation_duration = animation_duration self.thumb_url = thumb_url + self.thumb_mime_type = thumb_mime_type self.title = title self.description = description self.caption = caption @@ -96,7 +114,13 @@ async def write(self, client: "pyrogram.Client"): url=self.animation_url, size=0, mime_type="image/gif", - attributes=[] + attributes=[ + raw.types.DocumentAttributeVideo( + w=self.animation_width, + h=self.animation_height, + duration=self.animation_duration + ) + ] ) if self.thumb_url is None: @@ -105,7 +129,7 @@ async def write(self, client: "pyrogram.Client"): thumb = raw.types.InputWebDocument( url=self.thumb_url, size=0, - mime_type="image/gif", + mime_type=self.thumb_mime_type, attributes=[] ) @@ -117,7 +141,6 @@ async def write(self, client: "pyrogram.Client"): id=self.id, type=self.type, title=self.title, - description=self.description, thumb=thumb, content=animation, send_message=( From 9c28ccdf60311d9709a3dfc8fa506b98faec0858 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 214/539] Add InlineQueryResultVoice --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_mode/inline_query_result_voice.py | 114 ++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_voice.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 25a568f539..daff01174f 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -26,9 +26,10 @@ from .inline_query_result_video import InlineQueryResultVideo from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument +from .inline_query_result_voice import InlineQueryResultVoice __all__ = [ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", - "InlineQueryResultContact", "InlineQueryResultDocument" + "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_voice.py b/pyrogram/types/inline_mode/inline_query_result_voice.py new file mode 100644 index 0000000000..31b422f8d3 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_voice.py @@ -0,0 +1,114 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import List, Optional + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult + + +class InlineQueryResultVoice(InlineQueryResult): + """Link to a voice recording in an .OGG container encoded with OPUS. + + By default, this voice recording will be sent by the user. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the + voice message. + + Parameters: + voice_url (``str``): + A valid URL for the voice recording. + + title (``str``): + Title for the result. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + voice_duration (``int``, *optional*): + Recording duration in seconds. + + caption (``str``, *optional*): + Caption of the audio to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*): + Content of the message to be sent instead of the audio. + """ + + def __init__( + self, + voice_url: str, + title: str, + id: str = None, + voice_duration: int = 0, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("voice", id, input_message_content, reply_markup) + + self.voice_url = voice_url + self.title = title + self.voice_duration = voice_duration + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + + async def write(self, client: "pyrogram.Client"): + audio = raw.types.InputWebDocument( + url=self.voice_url, + size=0, + mime_type="audio/mpeg", + attributes=[raw.types.DocumentAttributeAudio( + duration=self.voice_duration, + title=self.title, + )] + ) + + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + return raw.types.InputBotInlineResult( + id=self.id, + type=self.type, + title=self.title, + content=audio, + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From 13e26ca64a4dee11801027f85ef2a4a7f6066211 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 215/539] Add InlineQueryResultLocation --- pyrogram/types/inline_mode/__init__.py | 7 +- .../inline_query_result_location.py | 122 ++++++++++++++++++ 2 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_location.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index daff01174f..0d84dcd31f 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -22,14 +22,15 @@ from .inline_query_result_animation import InlineQueryResultAnimation from .inline_query_result_article import InlineQueryResultArticle from .inline_query_result_audio import InlineQueryResultAudio -from .inline_query_result_photo import InlineQueryResultPhoto -from .inline_query_result_video import InlineQueryResultVideo from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument +from .inline_query_result_location import InlineQueryResultLocation +from .inline_query_result_photo import InlineQueryResultPhoto +from .inline_query_result_video import InlineQueryResultVideo from .inline_query_result_voice import InlineQueryResultVoice __all__ = [ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", - "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice" + "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_location.py b/pyrogram/types/inline_mode/inline_query_result_location.py new file mode 100644 index 0000000000..236f39a624 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_location.py @@ -0,0 +1,122 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw, types +from .inline_query_result import InlineQueryResult + + +class InlineQueryResultLocation(InlineQueryResult): + """A location on a map. + + By default, the location will be sent by the user. Alternatively, you can use *input_message_content* to send a + message with the specified content instead of the location. + + Parameters: + title (``str``): + Title for the result. + + latitude (``float``): + Location latitude in degrees. + + longitude (``float``): + Location longitude in degrees. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + horizontal_accuracy (``float``, *optional*) + The radius of uncertainty for the location, measured in meters; 0-1500. + + live_period (``int``, *optional*): + Period in seconds for which the location can be updated, should be between 60 and 86400. + + heading (``int``, *optional*): + For live locations, a direction in which the user is moving, in degrees. + Must be between 1 and 360 if specified. + + proximity_alert_radius (``int``, *optional*): + For live locations, a maximum distance for proximity alerts about approaching another chat member, + in meters. Must be between 1 and 100000 if specified. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the file. + + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumb_width (``int``, *optional*): + Thumbnail width. + + thumb_height (``int``, *optional*): + Thumbnail height. + """ + + def __init__( + self, + title: str, + latitude: float, + longitude: float, + horizontal_accuracy: float = None, + live_period: int = None, + heading: int = None, + proximity_alert_radius: int = None, + id: str = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 + ): + super().__init__("location", id, input_message_content, reply_markup) + + self.title = title + self.latitude = latitude + self.longitude = longitude + self.horizontal_accuracy = horizontal_accuracy + self.live_period = live_period + self.heading = heading + self.proximity_alert_radius = proximity_alert_radius + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height + + async def write(self, client: "pyrogram.Client"): + return raw.types.InputBotInlineResult( + id=self.id, + type=self.type, + title=self.title, + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaGeo( + geo_point=raw.types.InputGeoPoint( + lat=self.latitude, + long=self.longitude + ), + heading=self.heading, + period=self.live_period, + proximity_notification_radius=self.proximity_alert_radius, + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None + ) + ) + ) From d209074e44a325795f5d78babc8728c0fd912ace Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 216/539] Add InlineQueryResultVenue --- pyrogram/types/inline_mode/__init__.py | 4 +- .../inline_mode/inline_query_result_venue.py | 131 ++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_venue.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 0d84dcd31f..8646b8e47e 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -26,11 +26,13 @@ from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation from .inline_query_result_photo import InlineQueryResultPhoto +from .inline_query_result_venue import InlineQueryResultVenue from .inline_query_result_video import InlineQueryResultVideo from .inline_query_result_voice import InlineQueryResultVoice __all__ = [ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", - "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation" + "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", + "InlineQueryResultVenue" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_venue.py b/pyrogram/types/inline_mode/inline_query_result_venue.py new file mode 100644 index 0000000000..b3b513a55d --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_venue.py @@ -0,0 +1,131 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw, types +from .inline_query_result import InlineQueryResult + + +class InlineQueryResultVenue(InlineQueryResult): + """A venue. + + By default, the venue will be sent by the user. Alternatively, you can use *input_message_content* to send a message + with the specified content instead of the venue. + + Parameters: + title (``str``): + Title for the result. + + address (``str``): + Address of the venue. + + latitude (``float``): + Location latitude in degrees. + + longitude (``float``): + Location longitude in degrees. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + foursquare_id (``str``, *optional*): + Foursquare identifier of the venue if known. + + foursquare_type (``str``, *optional*): + Foursquare type of the venue, if known. + + google_place_id (``str``, *optional*): + Google Places identifier of the venue. + + google_place_type (``str``, *optional*): + Google Places type of the venue. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the file. + + thumb_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumb_width (``int``, *optional*): + Thumbnail width. + + thumb_height (``int``, *optional*): + Thumbnail height. + """ + + def __init__( + self, + title: str, + address: str, + latitude: float, + longitude: float, + id: str = None, + foursquare_id: str = None, + foursquare_type: str = None, + google_place_id: str = None, + google_place_type: str = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, + thumb_width: int = 0, + thumb_height: int = 0 + ): + super().__init__("venue", id, input_message_content, reply_markup) + + self.title = title + self.address = address + self.latitude = latitude + self.longitude = longitude + self.foursquare_id = foursquare_id + self.foursquare_type = foursquare_type + self.google_place_id = google_place_id + self.google_place_type = google_place_type + self.thumb_url = thumb_url + self.thumb_width = thumb_width + self.thumb_height = thumb_height + + async def write(self, client: "pyrogram.Client"): + return raw.types.InputBotInlineResult( + id=self.id, + type=self.type, + title=self.title, + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaVenue( + geo_point=raw.types.InputGeoPoint( + lat=self.latitude, + long=self.longitude + ), + title=self.title, + address=self.address, + provider=( + "foursquare" if self.foursquare_id or self.foursquare_type + else "google" if self.google_place_id or self.google_place_type + else "" + ), + venue_id=self.foursquare_id or self.google_place_id or "", + venue_type=self.foursquare_type or self.google_place_type or "", + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None + ) + ) + ) From c0dc882f2c38ea08fa4c1eb6382e37ad7c27a9ee Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 217/539] Add InlineQueryResultCachedPhoto --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_query_result_cached_photo.py | 111 ++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_photo.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 8646b8e47e..c6f5192f09 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -22,6 +22,7 @@ from .inline_query_result_animation import InlineQueryResultAnimation from .inline_query_result_article import InlineQueryResultArticle from .inline_query_result_audio import InlineQueryResultAudio +from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation @@ -34,5 +35,5 @@ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", - "InlineQueryResultVenue" + "InlineQueryResultVenue", "InlineQueryResultCachedPhoto" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py new file mode 100644 index 0000000000..843acab7c7 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py @@ -0,0 +1,111 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedPhoto(InlineQueryResult): + """A link to a photo stored on the Telegram servers. + + By default, this photo will be sent by the user with an optional caption. Alternatively, you can use + *input_message_content* to send a message with the specified content instead of the photo. + + Parameters: + photo_file_id (``str``): + A valid file identifier of the photo. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + title (``str``, *optional*): + Title for the result. + + description (``str``, *optional*): + Short description of the result. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + photo_file_id: str, + id: str = None, + title: str = None, + description: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("photo", id, input_message_content, reply_markup) + + self.photo_file_id = photo_file_id + self.title = title + self.description = description + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.photo_file_id) + + return raw.types.InputBotInlineResultPhoto( + id=self.id, + type=self.type, + photo=raw.types.InputPhoto( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From d87810ceb03403351cc6b30a5226c11a3fce0f6b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 218/539] Fix docstring indentation --- pyrogram/types/inline_mode/inline_query_result_cached_photo.py | 2 +- pyrogram/types/inline_mode/inline_query_result_photo.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py index 843acab7c7..2e01d344ec 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py @@ -52,7 +52,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): You can combine both syntaxes together. caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): - List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): An InlineKeyboardMarkup object. diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py index 9e03548954..d75ccac2a5 100644 --- a/pyrogram/types/inline_mode/inline_query_result_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_photo.py @@ -63,7 +63,7 @@ class InlineQueryResultPhoto(InlineQueryResult): You can combine both syntaxes together. caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): - List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): An InlineKeyboardMarkup object. From 0b0af2da5b30f4044d102e21114eb26ab28edb54 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 219/539] Add InlineQueryResultCachedAnimation --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_query_result_cached_animation.py | 108 ++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_animation.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index c6f5192f09..0bf60051ea 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -22,6 +22,7 @@ from .inline_query_result_animation import InlineQueryResultAnimation from .inline_query_result_article import InlineQueryResultArticle from .inline_query_result_audio import InlineQueryResultAudio +from .inline_query_result_cached_animation import InlineQueryResultCachedAnimation from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument @@ -35,5 +36,5 @@ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", - "InlineQueryResultVenue", "InlineQueryResultCachedPhoto" + "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_animation.py b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py new file mode 100644 index 0000000000..63e58ca027 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py @@ -0,0 +1,108 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedAnimation(InlineQueryResult): + """A link to an animation file stored on the Telegram servers. + + By default, this animation file will be sent by the user with an optional caption. + Alternatively, you can use *input_message_content* to send a message with specified content instead of the + animation. + + Parameters: + animation_file_id (``str``): + A valid file identifier for the animation file. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + title (``str``, *optional*): + Title for the result. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + animation_file_id: str, + id: str = None, + title: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("gif", id, input_message_content, reply_markup) + + self.animation_file_id = animation_file_id + self.title = title + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.animation_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + title=self.title, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From a9cadf302207575fc41e1d4c5254b30a83c7e20b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 220/539] Add InlineQueryResultCachedSticker --- pyrogram/types/inline_mode/__init__.py | 4 +- .../inline_query_result_cached_sticker.py | 78 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_sticker.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 0bf60051ea..7ed21c169b 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -24,6 +24,7 @@ from .inline_query_result_audio import InlineQueryResultAudio from .inline_query_result_cached_animation import InlineQueryResultCachedAnimation from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto +from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation @@ -36,5 +37,6 @@ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", - "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation" + "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation", + "InlineQueryResultCachedSticker" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py b/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py new file mode 100644 index 0000000000..06d012fbe6 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py @@ -0,0 +1,78 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 import raw, types +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedSticker(InlineQueryResult): + """A link to a sticker stored on the Telegram servers + + By default, this sticker will be sent by the user. Alternatively, you can use *input_message_content* to send a + message with the specified content instead of the sticker. + + Parameters: + sticker_file_id (``str``): + A valid file identifier of the sticker. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + sticker_file_id: str, + id: str = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("sticker", id, input_message_content, reply_markup) + + self.sticker_file_id = sticker_file_id + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + file_id = FileId.decode(self.sticker_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message="", + ) + ) + ) From 65a213b2227613ecfdc78ca89a2fac9bc0e3b3e7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 221/539] Add InlineQueryResultCachedDocument --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_query_result_cached_document.py | 112 ++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_document.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 7ed21c169b..ac98fb66e3 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -23,6 +23,7 @@ from .inline_query_result_article import InlineQueryResultArticle from .inline_query_result_audio import InlineQueryResultAudio from .inline_query_result_cached_animation import InlineQueryResultCachedAnimation +from .inline_query_result_cached_document import InlineQueryResultCachedDocument from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker from .inline_query_result_contact import InlineQueryResultContact @@ -38,5 +39,5 @@ "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation", - "InlineQueryResultCachedSticker" + "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_document.py b/pyrogram/types/inline_mode/inline_query_result_cached_document.py new file mode 100644 index 0000000000..5a50c18e4a --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_document.py @@ -0,0 +1,112 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedDocument(InlineQueryResult): + """A link to a file stored on the Telegram servers. + + By default, this file will be sent by the user with an optional caption. Alternatively, you can use + *input_message_content* to send a message with the specified content instead of the file. + + Parameters: + document_file_id (``str``): + A valid file identifier for the file. + + title (``str``): + Title for the result. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + description (``str``, *optional*): + Short description of the result. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + document_file_id: str, + title: str, + id: str = None, + description: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("file", id, input_message_content, reply_markup) + + self.document_file_id = document_file_id + self.title = title + self.description = description + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.document_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + title=self.title, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From c4948eac27e6e58ba8a7ba9befb79fa69ef6c7eb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 222/539] Add InlineQueryResultCachedVideo --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_query_result_cached_video.py | 114 ++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_video.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index ac98fb66e3..b8db4d68f8 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -26,6 +26,7 @@ from .inline_query_result_cached_document import InlineQueryResultCachedDocument from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker +from .inline_query_result_cached_video import InlineQueryResultCachedVideo from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation @@ -39,5 +40,5 @@ "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation", - "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument" + "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_video.py b/pyrogram/types/inline_mode/inline_query_result_cached_video.py new file mode 100644 index 0000000000..00ea32ecdb --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_video.py @@ -0,0 +1,114 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedVideo(InlineQueryResult): + """A link to a video file stored on the Telegram servers. + + By default, this video file will be sent by the user with an optional caption. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the + video. + + Parameters: + video_file_id (``str``): + A valid file identifier for the video file. + + title (``str``): + Title for the result. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + description (``str``, *optional*): + Short description of the result. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + video_file_id: str, + title: str, + id: str = None, + description: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("video", id, input_message_content, reply_markup) + + self.video_file_id = video_file_id + self.title = title + self.description = description + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.video_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + title=self.title, + description=self.description, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From b2643e91975ad940eabdd8ba4b02e66c16ddd9c4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 223/539] Use "description" in InlineQueryResultCachedDocument --- .../types/inline_mode/inline_query_result_cached_document.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_document.py b/pyrogram/types/inline_mode/inline_query_result_cached_document.py index 5a50c18e4a..2ab190e7ff 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_document.py @@ -95,6 +95,7 @@ async def write(self, client: "pyrogram.Client"): id=self.id, type=self.type, title=self.title, + description=self.description, document=raw.types.InputDocument( id=file_id.media_id, access_hash=file_id.access_hash, From 8e8972d5acfe39c0bc8222de0abc74cf7464cdad Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 224/539] Add InlineQueryResultCachedVoice --- pyrogram/types/inline_mode/__init__.py | 4 +- .../inline_query_result_cached_voice.py | 108 ++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_voice.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index b8db4d68f8..20e6f10c2b 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -27,6 +27,7 @@ from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker from .inline_query_result_cached_video import InlineQueryResultCachedVideo +from .inline_query_result_cached_voice import InlineQueryResultCachedVoice from .inline_query_result_contact import InlineQueryResultContact from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation @@ -40,5 +41,6 @@ "InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult", "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation", - "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo" + "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo", + "InlineQueryResultCachedVoice" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_voice.py b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py new file mode 100644 index 0000000000..cc2bd76855 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py @@ -0,0 +1,108 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedVoice(InlineQueryResult): + """A link to a voice message stored on the Telegram servers. + + By default, this voice message will be sent by the user. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the voice + message. + + Parameters: + voice_file_id (``str``): + A valid file identifier for the voice message. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + title (``str``, *optional*): + Title for the result. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + voice_file_id: str, + id: str = None, + title: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("voice", id, input_message_content, reply_markup) + + self.voice_file_id = voice_file_id + self.title = title + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.voice_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + title=self.title, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From 703ec1676c4732465f02d53c873b74b8ebea38b5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 225/539] Add InlineQueryResultCachedAudio --- pyrogram/types/inline_mode/__init__.py | 3 +- .../inline_query_result_cached_audio.py | 101 ++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/inline_mode/inline_query_result_cached_audio.py diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 20e6f10c2b..f7323abf95 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -35,6 +35,7 @@ from .inline_query_result_venue import InlineQueryResultVenue from .inline_query_result_video import InlineQueryResultVideo from .inline_query_result_voice import InlineQueryResultVoice +from .inline_query_result_cached_audio import InlineQueryResultCachedAudio __all__ = [ "InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto", @@ -42,5 +43,5 @@ "InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation", "InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation", "InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo", - "InlineQueryResultCachedVoice" + "InlineQueryResultCachedVoice", "InlineQueryResultCachedAudio" ] diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_audio.py b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py new file mode 100644 index 0000000000..9535f63343 --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py @@ -0,0 +1,101 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import Optional, List + +import pyrogram +from pyrogram import raw, types, utils, enums +from .inline_query_result import InlineQueryResult +from ...file_id import FileId + + +class InlineQueryResultCachedAudio(InlineQueryResult): + """A link to an MP3 audio file stored on the Telegram servers + + By default, this audio file will be sent by the user. Alternatively, you can use *input_message_content* to send a + message with the specified content instead of the audio. + + Parameters: + audio_file_id (``str``): + A valid file identifier for the audio file. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + caption (``str``, *optional*): + Caption of the photo to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): + Content of the message to be sent instead of the photo. + """ + + def __init__( + self, + audio_file_id: str, + id: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None, + input_message_content: "types.InputMessageContent" = None + ): + super().__init__("audio", id, input_message_content, reply_markup) + + self.audio_file_id = audio_file_id + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + async def write(self, client: "pyrogram.Client"): + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + + file_id = FileId.decode(self.audio_file_id) + + return raw.types.InputBotInlineResultDocument( + id=self.id, + type=self.type, + document=raw.types.InputDocument( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + ), + send_message=( + await self.input_message_content.write(client, self.reply_markup) + if self.input_message_content + else raw.types.InputBotInlineMessageMediaAuto( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + message=message, + entities=entities + ) + ) + ) From c2333c05758a6338c255597478030ddf50bd1795 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 226/539] Add inline query results to the documentation --- compiler/docs/compiler.py | 16 ++++++++-- .../types/inline_mode/inline_query_result.py | 30 ++++++------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index a03d2ee316..6c2276b778 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -452,11 +452,23 @@ def get_title_list(s: str) -> list: Inline Mode InlineQuery InlineQueryResult + InlineQueryResultCachedAudio + InlineQueryResultCachedDocument + InlineQueryResultCachedAnimation + InlineQueryResultCachedPhoto + InlineQueryResultCachedSticker + InlineQueryResultCachedVideo + InlineQueryResultCachedVoice InlineQueryResultArticle - InlineQueryResultPhoto - InlineQueryResultAnimation InlineQueryResultAudio + InlineQueryResultContact + InlineQueryResultDocument + InlineQueryResultAnimation + InlineQueryResultLocation + InlineQueryResultPhoto + InlineQueryResultVenue InlineQueryResultVideo + InlineQueryResultVoice ChosenInlineResult """, input_message_content=""" diff --git a/pyrogram/types/inline_mode/inline_query_result.py b/pyrogram/types/inline_mode/inline_query_result.py index 4ea2f7be64..8548e023c7 100644 --- a/pyrogram/types/inline_mode/inline_query_result.py +++ b/pyrogram/types/inline_mode/inline_query_result.py @@ -22,39 +22,27 @@ from pyrogram import types from ..object import Object -"""- :obj:`~pyrogram.types.InlineQueryResultCachedAudio` + +class InlineQueryResult(Object): + """One result of an inline query. + + - :obj:`~pyrogram.types.InlineQueryResultCachedAudio` - :obj:`~pyrogram.types.InlineQueryResultCachedDocument` - - :obj:`~pyrogram.types.InlineQueryResultCachedGif` - - :obj:`~pyrogram.types.InlineQueryResultCachedMpeg4Gif` + - :obj:`~pyrogram.types.InlineQueryResultCachedAnimation` - :obj:`~pyrogram.types.InlineQueryResultCachedPhoto` - :obj:`~pyrogram.types.InlineQueryResultCachedSticker` - :obj:`~pyrogram.types.InlineQueryResultCachedVideo` - :obj:`~pyrogram.types.InlineQueryResultCachedVoice` + - :obj:`~pyrogram.types.InlineQueryResultArticle` - :obj:`~pyrogram.types.InlineQueryResultAudio` - :obj:`~pyrogram.types.InlineQueryResultContact` - - :obj:`~pyrogram.types.InlineQueryResultGame` - :obj:`~pyrogram.types.InlineQueryResultDocument` - - :obj:`~pyrogram.types.InlineQueryResultGif` + - :obj:`~pyrogram.types.InlineQueryResultAnimation` - :obj:`~pyrogram.types.InlineQueryResultLocation` - - :obj:`~pyrogram.types.InlineQueryResultMpeg4Gif` - :obj:`~pyrogram.types.InlineQueryResultPhoto` - :obj:`~pyrogram.types.InlineQueryResultVenue` - :obj:`~pyrogram.types.InlineQueryResultVideo` - - :obj:`~pyrogram.types.InlineQueryResultVoice`""" - - -class InlineQueryResult(Object): - """One result of an inline query. - - Pyrogram currently supports results of the following types: - - - :obj:`~pyrogram.types.InlineQueryResultArticle` - - :obj:`~pyrogram.types.InlineQueryResultAudio` - - :obj:`~pyrogram.types.InlineQueryResultAnimation` - - :obj:`~pyrogram.types.InlineQueryResultContact` - - :obj:`~pyrogram.types.InlineQueryResultDocument` - - :obj:`~pyrogram.types.InlineQueryResultPhoto` - - :obj:`~pyrogram.types.InlineQueryResultVideo` + - :obj:`~pyrogram.types.InlineQueryResultVoice` """ def __init__( From 20c6b959d5cd316bf3a030e26046e2f3f5e660d8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 227/539] Update Object.bind docstring --- pyrogram/types/object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py index 8b6a5b99bf..9e2c684b3e 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -29,7 +29,7 @@ def __init__(self, client: "pyrogram.Client" = None): self._client = client def bind(self, client: "pyrogram.Client"): - """Recursively bind a Client instance to this and to all nested Pyrogram objects. + """Bind a Client instance to this and to all nested Pyrogram objects. Parameters: client (:obj:`~pyrogram.types.Client`): From 57a489747062e571eb33f95e8df5660f6cf274f8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 228/539] Skip attributes with leading underscore in Object.__eq__ --- pyrogram/types/object.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py index 9e2c684b3e..28bee9a7fc 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -88,6 +88,9 @@ def __repr__(self) -> str: def __eq__(self, other: "Object") -> bool: for attr in self.__dict__: try: + if attr.startswith("_"): + continue + if getattr(self, attr) != getattr(other, attr): return False except AttributeError: From 1ae719c2529d28cf7efb29782c873882c64f759c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 229/539] Rework send_poll: add missing parameters --- pyrogram/methods/messages/send_poll.py | 77 ++++++++++--- pyrogram/types/messages_and_media/message.py | 111 +++++++++++++------ 2 files changed, 137 insertions(+), 51 deletions(-) diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py index 1305d2d680..3f6f35d240 100644 --- a/pyrogram/methods/messages/send_poll.py +++ b/pyrogram/methods/messages/send_poll.py @@ -31,13 +31,19 @@ async def send_poll( question: str, options: List[str], is_anonymous: bool = True, - allows_multiple_answers: bool = None, type: "enums.PollType" = enums.PollType.REGULAR, + allows_multiple_answers: bool = None, correct_option_id: int = None, + explanation: str = None, + explanation_parse_mode: "enums.ParseMode" = None, + explanation_entities: List["types.MessageEntity"] = None, + open_period: int = None, + close_date: datetime = None, + is_closed: bool = None, disable_notification: bool = None, + protect_content: bool = None, reply_to_message_id: int = None, schedule_date: datetime = None, - protect_content: bool = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -69,25 +75,49 @@ async def send_poll( allows_multiple_answers (``bool``, *optional*): True, if the poll allows multiple answers, ignored for polls in quiz mode. - Defaults to False + Defaults to False. correct_option_id (``int``, *optional*): - 0-based identifier of the correct answer option (the index of the correct option) - Required for polls in quiz mode. + 0-based identifier of the correct answer option, required for polls in quiz mode. + + explanation (``str``, *optional*): + Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style + poll, 0-200 characters with at most 2 line feeds after entities parsing. + + explanation_parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + explanation_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the poll explanation, which can be specified instead of + *parse_mode*. + + open_period (``int``, *optional*): + Amount of time in seconds the poll will be active after creation, 5-600. + Can't be used together with *close_date*. + + close_date (:py:obj:`~datetime.datetime`, *optional*): + Point in time when the poll will be automatically closed. + Must be at least 5 and no more than 600 seconds in the future. + Can't be used together with *open_period*. + + is_closed (``bool``, *optional*): + Pass True, if the poll needs to be immediately closed. + This can be useful for poll preview. disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. schedule_date (:py:obj:`~datetime.datetime`, *optional*): Date when the message will be automatically sent. - protect_content (``bool``, *optional*): - Protects the contents of the sent message from forwarding and saving. - reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -100,25 +130,40 @@ async def send_poll( await app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"]) """ + + message, entities = (await utils.parse_text_entities( + self, explanation, explanation_parse_mode, explanation_entities + )).values() + + # For some reason passing None or [] as solution_entities will lead to INPUT_CONSTRUCTOR_INVALID_00 + # Add a dummy message entity with no length as workaround + solution = message or None + solution_entities = entities or ([raw.types.MessageEntityBold(offset=0, length=0)] if solution else None) + r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPoll( poll=raw.types.Poll( - id=0, + id=self.rnd_id(), question=question, answers=[ - raw.types.PollAnswer(text=o, option=bytes([i])) - for i, o in enumerate(options) + raw.types.PollAnswer(text=text, option=bytes([i])) + for i, text in enumerate(options) ], - multiple_choice=allows_multiple_answers or None, - public_voters=not is_anonymous or None, - quiz=type == enums.PollType.QUIZ or None + closed=is_closed, + public_voters=not is_anonymous, + multiple_choice=allows_multiple_answers, + quiz=type == enums.PollType.QUIZ or False, + close_period=open_period, + close_date=utils.datetime_to_timestamp(close_date) ), - correct_answers=None if correct_option_id is None else [bytes([correct_option_id])] + correct_answers=[bytes([correct_option_id])] if correct_option_id is not None else None, + solution=solution, + solution_entities=solution_entities ), message="", - silent=disable_notification or None, + silent=disable_notification, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=utils.datetime_to_timestamp(schedule_date), diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 526839c951..78817f4992 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -951,7 +951,7 @@ async def reply_text( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1088,7 +1088,7 @@ async def reply_animation( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1227,7 +1227,7 @@ async def reply_audio( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1319,7 +1319,7 @@ async def reply_cached_media( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1441,7 +1441,7 @@ async def reply_contact( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1577,7 +1577,7 @@ async def reply_document( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1655,7 +1655,7 @@ async def reply_game( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1719,7 +1719,7 @@ async def reply_inline_bot_result( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1793,7 +1793,7 @@ async def reply_location( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1856,7 +1856,7 @@ async def reply_media_group( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1972,7 +1972,7 @@ async def reply_photo( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -1995,12 +1995,19 @@ async def reply_poll( self, question: str, options: List[str], - quote: bool = None, is_anonymous: bool = True, + type: "enums.PollType" = enums.PollType.REGULAR, allows_multiple_answers: bool = None, - type: str = "regular", correct_option_id: int = None, + explanation: str = None, + explanation_parse_mode: "enums.ParseMode" = None, + explanation_entities: List["types.MessageEntity"] = None, + open_period: int = None, + close_date: datetime = None, + is_closed: bool = None, + quote: bool = None, disable_notification: bool = None, + protect_content: bool = None, reply_to_message_id: int = None, schedule_date: datetime = None, reply_markup: Union[ @@ -2029,39 +2036,66 @@ async def reply_poll( Parameters: question (``str``): - The poll question, as string. + Poll question, 1-255 characters. options (List of ``str``): - The poll options, as list of strings (2 to 10 options are allowed). + List of answer options, 2-10 strings 1-100 characters each. - quote (``bool``, *optional*): - If ``True``, the message will be sent as a reply to this message. - If *reply_to_message_id* is passed, this parameter will be ignored. - Defaults to ``True`` in group chats and ``False`` in private chats. - is_anonymous (``bool``, *optional*): True, if the poll needs to be anonymous. Defaults to True. - type (``str``, *optional*): - Poll type, "quiz" or "regular". - Defaults to "regular" + type (:obj`~pyrogram.enums.PollType`, *optional*): + Poll type, :obj:`~pyrogram.enums.PollType.QUIZ` or :obj:`~pyrogram.enums.PollType.REGULAR`. + Defaults to :obj:`~pyrogram.enums.PollType.REGULAR`. allows_multiple_answers (``bool``, *optional*): True, if the poll allows multiple answers, ignored for polls in quiz mode. - Defaults to False - + Defaults to False. + correct_option_id (``int``, *optional*): - 0-based identifier of the correct answer option (the index of the correct option) - Required for polls in quiz mode. + 0-based identifier of the correct answer option, required for polls in quiz mode. + + explanation (``str``, *optional*): + Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style + poll, 0-200 characters with at most 2 line feeds after entities parsing. + + explanation_parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + explanation_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the poll explanation, which can be specified instead of + *parse_mode*. + + open_period (``int``, *optional*): + Amount of time in seconds the poll will be active after creation, 5-600. + Can't be used together with *close_date*. + + close_date (:py:obj:`~datetime.datetime`, *optional*): + Point in time when the poll will be automatically closed. + Must be at least 5 and no more than 600 seconds in the future. + Can't be used together with *open_period*. + + is_closed (``bool``, *optional*): + Pass True, if the poll needs to be immediately closed. + This can be useful for poll preview. + + quote (``bool``, *optional*): + If ``True``, the message will be sent as a reply to this message. + If *reply_to_message_id* is passed, this parameter will be ignored. + Defaults to ``True`` in group chats and ``False`` in private chats. disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. + protect_content (``bool``, *optional*): + Protects the contents of the sent message from forwarding and saving. + reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. - + schedule_date (:py:obj:`~datetime.datetime`, *optional*): Date when the message will be automatically sent. @@ -2076,7 +2110,7 @@ async def reply_poll( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -2086,10 +2120,17 @@ async def reply_poll( question=question, options=options, is_anonymous=is_anonymous, - allows_multiple_answers=allows_multiple_answers, type=type, + allows_multiple_answers=allows_multiple_answers, correct_option_id=correct_option_id, + explanation=explanation, + explanation_parse_mode=explanation_parse_mode, + explanation_entities=explanation_entities, + open_period=open_period, + close_date=close_date, + is_closed=is_closed, disable_notification=disable_notification, + protect_content=protect_content, reply_to_message_id=reply_to_message_id, schedule_date=schedule_date, reply_markup=reply_markup @@ -2180,7 +2221,7 @@ async def reply_sticker( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -2275,7 +2316,7 @@ async def reply_venue( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -2420,7 +2461,7 @@ async def reply_video( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -2544,7 +2585,7 @@ async def reply_video_note( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id @@ -2664,7 +2705,7 @@ async def reply_voice( RPCError: In case of a Telegram RPC error. """ if quote is None: - quote = self.chat.type != "private" + quote = self.chat.type != enums.ChatType.PRIVATE if reply_to_message_id is None and quote: reply_to_message_id = self.id From 264a206a139ab6fdaf166df9eb36c0cdfabb4faf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 230/539] Rename enum MessageMedia to MessageMediaType --- docs/source/api/enums/MessageMedia.rst | 8 ----- docs/source/api/enums/MessageMediaType.rst | 8 +++++ docs/source/api/enums/index.rst | 4 +-- pyrogram/enums/__init__.py | 2 +- ...message_media.py => message_media_type.py} | 4 +-- pyrogram/types/messages_and_media/message.py | 32 +++++++++---------- 6 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 docs/source/api/enums/MessageMedia.rst create mode 100644 docs/source/api/enums/MessageMediaType.rst rename pyrogram/enums/{message_media.py => message_media_type.py} (92%) diff --git a/docs/source/api/enums/MessageMedia.rst b/docs/source/api/enums/MessageMedia.rst deleted file mode 100644 index f42693f0c1..0000000000 --- a/docs/source/api/enums/MessageMedia.rst +++ /dev/null @@ -1,8 +0,0 @@ -MessageMedia -============ - -.. autoclass:: pyrogram.enums.MessageMedia() - :members: - -.. raw:: html - :file: ./cleanup.html \ No newline at end of file diff --git a/docs/source/api/enums/MessageMediaType.rst b/docs/source/api/enums/MessageMediaType.rst new file mode 100644 index 0000000000..04e439d20e --- /dev/null +++ b/docs/source/api/enums/MessageMediaType.rst @@ -0,0 +1,8 @@ +MessageMediaType +================ + +.. autoclass:: pyrogram.enums.MessageMediaType() + :members: + +.. raw:: html + :file: ./cleanup.html \ No newline at end of file diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst index 574b4dd7ce..12b1fac180 100644 --- a/docs/source/api/enums/index.rst +++ b/docs/source/api/enums/index.rst @@ -19,7 +19,7 @@ to apply only a valid value among the expected ones. ChatMembersFilter ChatType MessageEntityType - MessageMedia + MessageMediaType MessageService MessagesFilter ParseMode @@ -37,7 +37,7 @@ to apply only a valid value among the expected ones. ChatMembersFilter ChatType MessageEntityType - MessageMedia + MessageMediaType MessageService MessagesFilter ParseMode diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index 7d553918a8..acdc5233a1 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -22,7 +22,7 @@ from .chat_members_filter import ChatMembersFilter from .chat_type import ChatType from .message_entity_type import MessageEntityType -from .message_media import MessageMedia +from .message_media_type import MessageMediaType from .message_service import MessageService from .messages_filter import MessagesFilter from .next_code_type import NextCodeType diff --git a/pyrogram/enums/message_media.py b/pyrogram/enums/message_media_type.py similarity index 92% rename from pyrogram/enums/message_media.py rename to pyrogram/enums/message_media_type.py index b7dfd03bc6..5887811405 100644 --- a/pyrogram/enums/message_media.py +++ b/pyrogram/enums/message_media_type.py @@ -21,8 +21,8 @@ from .auto_name import AutoName -class MessageMedia(AutoName): - """Message media enumeration used in :obj:`~pyrogram.types.Message`.""" +class MessageMediaType(AutoName): + """Message media type enumeration used in :obj:`~pyrogram.types.Message`.""" AUDIO = auto() "Audio media" diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 78817f4992..9f0cf8a388 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -118,7 +118,7 @@ class Message(Object, Update): This field will contain the enumeration type of the service message. You can use ``service = getattr(message, message.service.value)`` to access the service message. - media (:obj:`~pyrogram.enums.MessageMedia`, *optional*): + media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*): The message is a media message. This field will contain the enumeration type of the media message. You can use ``media = getattr(message, message.media.value)`` to access the media message. @@ -657,19 +657,19 @@ async def _parse( if media: if isinstance(media, raw.types.MessageMediaPhoto): photo = types.Photo._parse(client, media.photo, media.ttl_seconds) - media_type = enums.MessageMedia.PHOTO + media_type = enums.MessageMediaType.PHOTO elif isinstance(media, raw.types.MessageMediaGeo): location = types.Location._parse(client, media.geo) - media_type = enums.MessageMedia.LOCATION + media_type = enums.MessageMediaType.LOCATION elif isinstance(media, raw.types.MessageMediaContact): contact = types.Contact._parse(client, media) - media_type = enums.MessageMedia.CONTACT + media_type = enums.MessageMediaType.CONTACT elif isinstance(media, raw.types.MessageMediaVenue): venue = types.Venue._parse(client, media) - media_type = enums.MessageMedia.VENUE + media_type = enums.MessageMediaType.VENUE elif isinstance(media, raw.types.MessageMediaGame): game = types.Game._parse(client, message) - media_type = enums.MessageMedia.GAME + media_type = enums.MessageMediaType.GAME elif isinstance(media, raw.types.MessageMediaDocument): doc = media.document @@ -687,14 +687,14 @@ async def _parse( if audio_attributes.voice: voice = types.Voice._parse(client, doc, audio_attributes) - media_type = enums.MessageMedia.VOICE + media_type = enums.MessageMediaType.VOICE else: audio = types.Audio._parse(client, doc, audio_attributes, file_name) - media_type = enums.MessageMedia.AUDIO + media_type = enums.MessageMediaType.AUDIO elif raw.types.DocumentAttributeAnimated in attributes: video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None) animation = types.Animation._parse(client, doc, video_attributes, file_name) - media_type = enums.MessageMedia.ANIMATION + media_type = enums.MessageMediaType.ANIMATION elif raw.types.DocumentAttributeSticker in attributes: sticker = await types.Sticker._parse( client, doc, @@ -702,31 +702,31 @@ async def _parse( attributes[raw.types.DocumentAttributeSticker], file_name ) - media_type = enums.MessageMedia.STICKER + media_type = enums.MessageMediaType.STICKER elif raw.types.DocumentAttributeVideo in attributes: video_attributes = attributes[raw.types.DocumentAttributeVideo] if video_attributes.round_message: video_note = types.VideoNote._parse(client, doc, video_attributes) - media_type = enums.MessageMedia.VIDEO_NOTE + media_type = enums.MessageMediaType.VIDEO_NOTE else: video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds) - media_type = enums.MessageMedia.VIDEO + media_type = enums.MessageMediaType.VIDEO else: document = types.Document._parse(client, doc, file_name) - media_type = enums.MessageMedia.DOCUMENT + media_type = enums.MessageMediaType.DOCUMENT elif isinstance(media, raw.types.MessageMediaWebPage): if isinstance(media.webpage, raw.types.WebPage): web_page = types.WebPage._parse(client, media.webpage) - media_type = enums.MessageMedia.WEB_PAGE + media_type = enums.MessageMediaType.WEB_PAGE else: media = None elif isinstance(media, raw.types.MessageMediaPoll): poll = types.Poll._parse(client, media) - media_type = enums.MessageMedia.POLL + media_type = enums.MessageMediaType.POLL elif isinstance(media, raw.types.MessageMediaDice): dice = types.Dice._parse(client, media) - media_type = enums.MessageMedia.DICE + media_type = enums.MessageMediaType.DICE else: media = None From be37e3b46c5a917695476684503a2779469dc235 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 231/539] Rename enum MessageService to MessageServiceType --- docs/source/api/enums/MessageService.rst | 8 ---- docs/source/api/enums/MessageServiceType.rst | 8 ++++ docs/source/api/enums/index.rst | 4 +- pyrogram/enums/__init__.py | 2 +- ...age_service.py => message_service_type.py} | 4 +- pyrogram/types/messages_and_media/message.py | 40 +++++++++---------- 6 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 docs/source/api/enums/MessageService.rst create mode 100644 docs/source/api/enums/MessageServiceType.rst rename pyrogram/enums/{message_service.py => message_service_type.py} (93%) diff --git a/docs/source/api/enums/MessageService.rst b/docs/source/api/enums/MessageService.rst deleted file mode 100644 index 7b7ee4e212..0000000000 --- a/docs/source/api/enums/MessageService.rst +++ /dev/null @@ -1,8 +0,0 @@ -MessageService -============== - -.. autoclass:: pyrogram.enums.MessageService() - :members: - -.. raw:: html - :file: ./cleanup.html \ No newline at end of file diff --git a/docs/source/api/enums/MessageServiceType.rst b/docs/source/api/enums/MessageServiceType.rst new file mode 100644 index 0000000000..2de56818d8 --- /dev/null +++ b/docs/source/api/enums/MessageServiceType.rst @@ -0,0 +1,8 @@ +MessageServiceType +================== + +.. autoclass:: pyrogram.enums.MessageServiceType() + :members: + +.. raw:: html + :file: ./cleanup.html \ No newline at end of file diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst index 12b1fac180..bd9f8b1da7 100644 --- a/docs/source/api/enums/index.rst +++ b/docs/source/api/enums/index.rst @@ -20,7 +20,7 @@ to apply only a valid value among the expected ones. ChatType MessageEntityType MessageMediaType - MessageService + MessageServiceType MessagesFilter ParseMode PollType @@ -38,7 +38,7 @@ to apply only a valid value among the expected ones. ChatType MessageEntityType MessageMediaType - MessageService + MessageServiceType MessagesFilter ParseMode PollType diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index acdc5233a1..f847b3cf57 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -23,7 +23,7 @@ from .chat_type import ChatType from .message_entity_type import MessageEntityType from .message_media_type import MessageMediaType -from .message_service import MessageService +from .message_service_type import MessageServiceType from .messages_filter import MessagesFilter from .next_code_type import NextCodeType from .parse_mode import ParseMode diff --git a/pyrogram/enums/message_service.py b/pyrogram/enums/message_service_type.py similarity index 93% rename from pyrogram/enums/message_service.py rename to pyrogram/enums/message_service_type.py index 636e6db575..8a60e29e6e 100644 --- a/pyrogram/enums/message_service.py +++ b/pyrogram/enums/message_service_type.py @@ -21,8 +21,8 @@ from .auto_name import AutoName -class MessageService(AutoName): - """Message service enumeration used in :obj:`~pyrogram.types.Message`.""" +class MessageServiceType(AutoName): + """Message service type enumeration used in :obj:`~pyrogram.types.Message`.""" NEW_CHAT_MEMBERS = auto() "New members join" diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 9f0cf8a388..68f92c3cdc 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -113,7 +113,7 @@ class Message(Object, Update): The message is empty. A message can be empty in case it was deleted or you tried to retrieve a message that doesn't exist yet. - service (:obj:`~pyrogram.enums.MessageService`, *optional*): + service (:obj:`~pyrogram.enums.MessageServiceType`, *optional*): The message is a service message. This field will contain the enumeration type of the service message. You can use ``service = getattr(message, message.service.value)`` to access the service message. @@ -321,10 +321,10 @@ def __init__( reply_to_message: "Message" = None, mentioned: bool = None, empty: bool = None, - service: "enums.MessageService" = None, + service: "enums.MessageServiceType" = None, scheduled: bool = None, from_scheduled: bool = None, - media: str = None, + media: "enums.MessageMediaType" = None, edit_date: datetime = None, media_group_id: str = None, author_signature: str = None, @@ -502,50 +502,50 @@ async def _parse( if isinstance(action, raw.types.MessageActionChatAddUser): new_chat_members = [types.User._parse(client, users[i]) for i in action.users] - service_type = enums.MessageService.NEW_CHAT_MEMBERS + service_type = enums.MessageServiceType.NEW_CHAT_MEMBERS elif isinstance(action, raw.types.MessageActionChatJoinedByLink): new_chat_members = [types.User._parse(client, users[utils.get_raw_peer_id(message.from_id)])] - service_type = enums.MessageService.NEW_CHAT_MEMBERS + service_type = enums.MessageServiceType.NEW_CHAT_MEMBERS elif isinstance(action, raw.types.MessageActionChatDeleteUser): left_chat_member = types.User._parse(client, users[action.user_id]) - service_type = enums.MessageService.LEFT_CHAT_MEMBERS + service_type = enums.MessageServiceType.LEFT_CHAT_MEMBERS elif isinstance(action, raw.types.MessageActionChatEditTitle): new_chat_title = action.title - service_type = enums.MessageService.NEW_CHAT_TITLE + service_type = enums.MessageServiceType.NEW_CHAT_TITLE elif isinstance(action, raw.types.MessageActionChatDeletePhoto): delete_chat_photo = True - service_type = enums.MessageService.DELETE_CHAT_PHOTO + service_type = enums.MessageServiceType.DELETE_CHAT_PHOTO elif isinstance(action, raw.types.MessageActionChatMigrateTo): migrate_to_chat_id = action.channel_id - service_type = enums.MessageService.MIGRATE_TO_CHAT_ID + service_type = enums.MessageServiceType.MIGRATE_TO_CHAT_ID elif isinstance(action, raw.types.MessageActionChannelMigrateFrom): migrate_from_chat_id = action.chat_id - service_type = enums.MessageService.MIGRATE_FROM_CHAT_ID + service_type = enums.MessageServiceType.MIGRATE_FROM_CHAT_ID elif isinstance(action, raw.types.MessageActionChatCreate): group_chat_created = True - service_type = enums.MessageService.GROUP_CHAT_CREATED + service_type = enums.MessageServiceType.GROUP_CHAT_CREATED elif isinstance(action, raw.types.MessageActionChannelCreate): channel_chat_created = True - service_type = enums.MessageService.CHANNEL_CHAT_CREATED + service_type = enums.MessageServiceType.CHANNEL_CHAT_CREATED elif isinstance(action, raw.types.MessageActionChatEditPhoto): new_chat_photo = types.Photo._parse(client, action.photo) - service_type = enums.MessageService.NEW_CHAT_PHOTO + service_type = enums.MessageServiceType.NEW_CHAT_PHOTO elif isinstance(action, raw.types.MessageActionGroupCallScheduled): video_chat_scheduled = types.VideoChatScheduled._parse(action) - service_type = enums.MessageService.VIDEO_CHAT_SCHEDULED + service_type = enums.MessageServiceType.VIDEO_CHAT_SCHEDULED elif isinstance(action, raw.types.MessageActionGroupCall): if action.duration: video_chat_ended = types.VideoChatEnded._parse(action) - service_type = enums.MessageService.VIDEO_CHAT_ENDED + service_type = enums.MessageServiceType.VIDEO_CHAT_ENDED else: video_chat_started = types.VideoChatStarted() - service_type = enums.MessageService.VIDEO_CHAT_STARTED + service_type = enums.MessageServiceType.VIDEO_CHAT_STARTED elif isinstance(action, raw.types.MessageActionInviteToGroupCall): video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users) - service_type = enums.MessageService.VIDEO_CHAT_MEMBERS_INVITED + service_type = enums.MessageServiceType.VIDEO_CHAT_MEMBERS_INVITED elif isinstance(action, raw.types.MessageActionWebViewDataSentMe): web_app_data = types.WebAppData._parse(action) - service_type = enums.MessageService.WEB_APP_DATA + service_type = enums.MessageServiceType.WEB_APP_DATA from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None @@ -583,7 +583,7 @@ async def _parse( replies=0 ) - parsed_message.service = enums.MessageService.PINNED_MESSAGE + parsed_message.service = enums.MessageServiceType.PINNED_MESSAGE except MessageIdsEmpty: pass @@ -598,7 +598,7 @@ async def _parse( replies=0 ) - parsed_message.service = enums.MessageService.GAME_HIGH_SCORE + parsed_message.service = enums.MessageServiceType.GAME_HIGH_SCORE except MessageIdsEmpty: pass From 61e737b2e831734c8f17c0687d2998fe5825335b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 232/539] Update minimum required Python version to 3.7 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index d1bd9c90dd..2cb7d7f677 100644 --- a/setup.py +++ b/setup.py @@ -56,11 +56,11 @@ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", @@ -78,7 +78,7 @@ "Source": "https://github.com/pyrogram/pyrogram", "Documentation": "https://docs.pyrogram.org", }, - python_requires="~=3.6", + python_requires="~=3.7", package_data={ "pyrogram": ["py.typed"], }, From 822e09ae13ab54eddd3bc675c8eee2c10ab8e3e8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 233/539] Update Client's docstrings --- pyrogram/client.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 6b2ac9a1f2..4cf0740f60 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -146,15 +146,14 @@ class Client(Methods): Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): - The parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"* - to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser - completely. + Set the global parse mode of the client. By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. no_updates (``bool``, *optional*): - Pass True to completely disable incoming updates for the current session. - When updates are disabled your client can't receive any new message. + Pass True to disable incoming updates. + When updates are disabled the client can't receive messages or other updates. Useful for batch programs that don't need to deal with updates. - Defaults to False (updates enabled and always received). + Defaults to False (updates enabled and received). takeout (``bool``, *optional*): Pass True to let the client use a takeout session instead of a normal one, implies *no_updates=True*. From e80ffd275c3403aef213d0f6f2f189be16812684 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 234/539] Documentation fixes --- docs/source/intro/quickstart.rst | 2 +- docs/source/topics/storage-engines.rst | 4 ++-- docs/source/topics/synchronous.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/intro/quickstart.rst b/docs/source/intro/quickstart.rst index cccbfbc76b..29c355e7c7 100644 --- a/docs/source/intro/quickstart.rst +++ b/docs/source/intro/quickstart.rst @@ -50,7 +50,7 @@ Enjoy the API That was just a quick overview. In the next few pages of the introduction, we'll take a much more in-depth look of what we have just done above. -If you are feeling eager to continue you can take a shortcut to :doc:`Invoking Methods <../start/invoking>` and come back +If you are feeling eager to continue you can take a shortcut to :doc:`../start/invoking` and come back later to learn some more details. .. _community: https://t.me/Pyrogram diff --git a/docs/source/topics/storage-engines.rst b/docs/source/topics/storage-engines.rst index c83e7a5b7c..34147917ee 100644 --- a/docs/source/topics/storage-engines.rst +++ b/docs/source/topics/storage-engines.rst @@ -74,8 +74,8 @@ In case you want to use an in-memory storage, but also want to keep access to th async with Client("my_account", in_memory=True) as app: print(await app.export_session_string()) -...and save the resulting string. You can use this string as session name the next time you want to login -using the same session; the storage used will still be in-memory: +...and save the resulting string. You can use this string by passing it as Client argument the next time you want to +login using the same session; the storage used will still be in-memory: .. code-block:: python diff --git a/docs/source/topics/synchronous.rst b/docs/source/topics/synchronous.rst index a6e12383d1..0a677b0e50 100644 --- a/docs/source/topics/synchronous.rst +++ b/docs/source/topics/synchronous.rst @@ -1,7 +1,7 @@ Synchronous Usage ================= -Pyrogram is an asynchronous framework and as such it is subject to the asynchronous rules. It can, however, run in +Pyrogram is an asynchronous framework and as such is subject to the asynchronous rules. It can, however, run in synchronous mode (also known as non-asynchronous or sync/non-async for short). This mode exists mainly as a convenience way for invoking methods without the need of ``async``/``await`` keywords and the extra boilerplate, but **it's not the intended way to use the framework**. From 0dc112ea8cb0a978e39a390308cdfc9654c36a6d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH 235/539] Update Pyrogram to v2.0.0 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e4c8bcf356..761c790a38 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "1.4.16" +__version__ = "2.0.0" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From c799703965a54f8e64e6677edafd543ba728f92e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:11:54 +0200 Subject: [PATCH 236/539] Fix plugins loading --- pyrogram/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 4cf0740f60..74897e5f08 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -614,7 +614,7 @@ def load_plugins(self): plugins = self.plugins.copy() for option in ["include", "exclude"]: - if plugins[option]: + if plugins.get(option, []): plugins[option] = [ (i.split()[0], i.split()[1:] or None) for i in self.plugins[option] @@ -622,10 +622,10 @@ def load_plugins(self): else: return - if plugins.get("enabled", False): + if plugins.get("enabled", True): root = plugins["root"] - include = plugins["include"] - exclude = plugins["exclude"] + include = plugins.get("include", []) + exclude = plugins.get("exclude", []) count = 0 From e188da7afcfd4f7c6f63b0d0404f89cb467fb18e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:12:17 +0200 Subject: [PATCH 237/539] Update Pyrogram to v2.0.1 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 761c790a38..9ae1f3c7d4 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.0" +__version__ = "2.0.1" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ba34bf84f98a665305b6ece47dfdd0e45b2bd429 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:23:07 +0200 Subject: [PATCH 238/539] Show an error message for invalid parse modes --- pyrogram/parser/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py index 35a15d0c68..16701b39ee 100644 --- a/pyrogram/parser/parser.py +++ b/pyrogram/parser/parser.py @@ -51,6 +51,8 @@ async def parse(self, text: str, mode: Optional[enums.ParseMode] = None): if mode == enums.ParseMode.DISABLED: return {"message": text, "entities": []} + raise ValueError(f'Invalid parse mode "{mode}"') + @staticmethod def unparse(text: str, entities: list, is_html: bool): if is_html: From e43bfd276a861117c9de4032dbdf8b8f9c289300 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 14:30:00 +0200 Subject: [PATCH 239/539] Update Pyrogram to v2.0.2 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 9ae1f3c7d4..aa6646cd0a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.1" +__version__ = "2.0.2" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 1b9dac8ad3da7d92ddb93fa786057a333485735f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 14:50:00 +0200 Subject: [PATCH 240/539] Fix GitHub actions --- .github/workflows/python.yml | 9 +++++---- tests/filters/__init__.py | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 89ed8532ce..9d25f33f7b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -8,8 +8,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] + os: [ubuntu-latest, macos-latest] + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 @@ -26,8 +26,9 @@ jobs: - name: Generate API run: | - python setup.py generate --api + make venv + make api - name: Run tests run: | - tox + tox \ No newline at end of file diff --git a/tests/filters/__init__.py b/tests/filters/__init__.py index e93649f521..ebc674c470 100644 --- a/tests/filters/__init__.py +++ b/tests/filters/__init__.py @@ -17,9 +17,11 @@ # along with Pyrogram. If not, see . class Client: - @staticmethod - async def get_me(): - return User("username") + def __init__(self): + self.username = "username" + + async def get_me(self): + return User(self.username) class User: From 6437d2862eed2ecde54b388b96f21c9b2ca2cb2c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 16:38:30 +0200 Subject: [PATCH 241/539] Revert "Add pyproject.toml" This reverts commit 4f6ce8bec17af1ab76ca7832d3d4167c028ec483. --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 07de284aa5..0000000000 --- a/pyproject.toml +++ /dev/null @@ -1,3 +0,0 @@ -[build-system] -requires = ["setuptools", "wheel"] -build-backend = "setuptools.build_meta" \ No newline at end of file From 3c08d02c200d90dd82c993bbff901fc438b114f8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 16:40:55 +0200 Subject: [PATCH 242/539] Update Pyrogram to v2.0.3 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index aa6646cd0a..aeb9129dc9 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.2" +__version__ = "2.0.3" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 240659f6163e653a69671ced9805d15a5e1ed521 Mon Sep 17 00:00:00 2001 From: lordcodes <83734728+LORD-ME-CODE@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:06:45 +0300 Subject: [PATCH 243/539] Close the downloaded file before moving it (#964) * download media on windows fix mmmmmmmm * Style fixes Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/client.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 74897e5f08..40fe1cfeb3 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -734,13 +734,9 @@ async def handle_download(self, packet): if file and not in_memory: file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) os.makedirs(directory, exist_ok=True) + file.close() shutil.move(file.name, file_path) - try: - file.close() - except FileNotFoundError: - pass - return file_path if file and in_memory: From aecdd492eb855d012842d6da8c89e25fcf323ff7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:07:26 +0200 Subject: [PATCH 244/539] Update Pyrogram to v2.0.4 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index aeb9129dc9..4bc6369a07 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.3" +__version__ = "2.0.4" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 88527567989fabc54f8fed8e5d266ec3ba20c834 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:13:18 +0200 Subject: [PATCH 245/539] Fix zero-datetime not working in some systems --- pyrogram/methods/chats/ban_chat_member.py | 2 +- pyrogram/methods/chats/restrict_chat_member.py | 2 +- pyrogram/methods/invite_links/edit_chat_invite_link.py | 2 +- pyrogram/methods/messages/get_chat_history.py | 4 ++-- pyrogram/types/user_and_chats/chat.py | 4 ++-- pyrogram/utils.py | 6 +++++- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py index 8e1bca1eda..16a1308247 100644 --- a/pyrogram/methods/chats/ban_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -29,7 +29,7 @@ async def ban_chat_member( self: "pyrogram.Client", chat_id: Union[int, str], user_id: Union[int, str], - until_date: datetime = datetime.fromtimestamp(0) + until_date: datetime = utils.zero_datetime() ) -> Union["types.Message", bool]: """Ban a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py index 4ebb5f1877..717ba60bd2 100644 --- a/pyrogram/methods/chats/restrict_chat_member.py +++ b/pyrogram/methods/chats/restrict_chat_member.py @@ -30,7 +30,7 @@ async def restrict_chat_member( chat_id: Union[int, str], user_id: Union[int, str], permissions: "types.ChatPermissions", - until_date: datetime = datetime.fromtimestamp(0) + until_date: datetime = utils.zero_datetime() ) -> "types.Chat": """Restrict a user in a supergroup. diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py index 29f658ec8a..9951684787 100644 --- a/pyrogram/methods/invite_links/edit_chat_invite_link.py +++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py @@ -51,7 +51,7 @@ async def edit_chat_invite_link( expire_date (:py:obj:`~datetime.datetime`, *optional*): Point in time when the link will expire. - Defaults to None (no change), pass ``datetime.fromtimestamp(0)`` to set no expiration date. + Defaults to None (no change), pass None to set no expiration date. member_limit (``int``, *optional*): Maximum number of users that can be members of the chat simultaneously after joining the chat via this diff --git a/pyrogram/methods/messages/get_chat_history.py b/pyrogram/methods/messages/get_chat_history.py index f21a081f19..a7fcc491e9 100644 --- a/pyrogram/methods/messages/get_chat_history.py +++ b/pyrogram/methods/messages/get_chat_history.py @@ -30,7 +30,7 @@ async def get_chunk( limit: int = 0, offset: int = 0, from_message_id: int = 0, - from_date: datetime = datetime.fromtimestamp(0) + from_date: datetime = utils.zero_datetime() ): messages = await client.invoke( raw.functions.messages.GetHistory( @@ -56,7 +56,7 @@ async def get_chat_history( limit: int = 0, offset: int = 0, offset_id: int = 0, - offset_date: datetime = datetime.fromtimestamp(0) + offset_date: datetime = utils.zero_datetime() ) -> Optional[AsyncGenerator["types.Message", None]]: """Get messages from a chat history. diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index e36107bf61..7e4442a132 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -514,7 +514,7 @@ async def set_photo(self, photo: str) -> bool: async def ban_member( self, user_id: Union[int, str], - until_date: datetime = datetime.fromtimestamp(0) + until_date: datetime = utils.zero_datetime() ) -> Union["types.Message", bool]: """Bound method *ban_member* of :obj:`~pyrogram.types.Chat`. @@ -602,7 +602,7 @@ async def restrict_member( self, user_id: Union[int, str], permissions: "types.ChatPermissions", - until_date: datetime = datetime.fromtimestamp(0), + until_date: datetime = utils.zero_datetime(), ) -> "types.Chat": """Bound method *unban_member* of :obj:`~pyrogram.types.Chat`. diff --git a/pyrogram/utils.py b/pyrogram/utils.py index 18230ed4f5..b9f3fdd84b 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -23,7 +23,7 @@ import os import struct from concurrent.futures.thread import ThreadPoolExecutor -from datetime import datetime +from datetime import datetime, timezone from getpass import getpass from typing import Union, List, Dict, Optional @@ -345,6 +345,10 @@ async def parse_text_entities( } +def zero_datetime() -> datetime: + return datetime.fromtimestamp(0, timezone.utc) + + def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]: return datetime.fromtimestamp(ts) if ts else None From f9d42320a7e14d66603181a661f7026dad071a77 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:13:45 +0200 Subject: [PATCH 246/539] Update Pyrogram to v2.0.5 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 4bc6369a07..8c3a4f5a03 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.4" +__version__ = "2.0.5" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 27c9338970b00e6106ea011835f65a6190c6f754 Mon Sep 17 00:00:00 2001 From: Alisson Lauffer Date: Sun, 24 Apr 2022 13:36:47 -0300 Subject: [PATCH 247/539] Fix Message.react() (#965) --- pyrogram/types/messages_and_media/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 68f92c3cdc..ab5e202f2a 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3319,7 +3319,7 @@ async def react(self, emoji: str = "") -> bool: await client.send_reaction( chat_id=chat_id, - message_id=message.message_id, + message_id=message.id, emoji="🔥" ) @@ -3342,7 +3342,7 @@ async def react(self, emoji: str = "") -> bool: return await self._client.send_reaction( chat_id=self.chat.id, - message_id=self.message_id, + message_id=self.id, emoji=emoji ) From 5239392480356a28ff4acf53ee57d4f83e7d8147 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:37:13 +0200 Subject: [PATCH 248/539] Update Pyrogram to v2.0.6 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 8c3a4f5a03..2876b5020b 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.5" +__version__ = "2.0.6" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 228b45b17915d75c5545cf0b5916dc8d0284f602 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 21:19:36 +0200 Subject: [PATCH 249/539] Update docstrings --- pyrogram/client.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 40fe1cfeb3..b0c493d5c9 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -66,14 +66,14 @@ class Client(Methods): Parameters: name (``str``): - Pass a string of your choice to give a name to the client, e.g.: "my_account". + A name for the client, e.g.: "my_account". api_id (``int`` | ``str``, *optional*): - The *api_id* part of your Telegram API key, as integer. - E.g.: 12345. + The *api_id* part of the Telegram API key, as integer or string. + E.g.: 12345 or "12345". api_hash (``str``, *optional*): - The *api_hash* part of your Telegram API key, as string. + The *api_hash* part of the Telegram API key, as string. E.g.: "0123456789abcdef0123456789abcdef". app_version (``str``, *optional*): @@ -99,7 +99,7 @@ class Client(Methods): proxy (``dict``, *optional*): The Proxy settings as dict. E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*. - The *username* and *password* can be omitted if your proxy doesn't require authorization. + The *username* and *password* can be omitted if the proxy doesn't require authorization. test_mode (``bool``, *optional*): Enable or disable login to the test servers. @@ -107,7 +107,7 @@ class Client(Methods): Defaults to False. bot_token (``str``, *optional*): - Pass your Bot API token to create a bot session, e.g.: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" + Pass the Bot API token to create a bot session, e.g.: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" Only applicable for new sessions. session_string (``str``, *optional*): @@ -122,7 +122,7 @@ class Client(Methods): Defaults to False. phone_number (``str``, *optional*): - Pass your phone number as string (with your Country Code prefix included) to avoid entering it manually. + Pass the phone number as string (with the Country Code prefix included) to avoid entering it manually. Only applicable for new sessions. phone_code (``str``, *optional*): @@ -130,7 +130,7 @@ class Client(Methods): Only applicable for new sessions. password (``str``, *optional*): - Pass your Two-Step Verification password as string (if you have one) to avoid entering it manually. + Pass the Two-Step Verification password as string (if required) to avoid entering it manually. Only applicable for new sessions. workers (``int``, *optional*): @@ -138,12 +138,12 @@ class Client(Methods): Defaults to ``min(32, os.cpu_count() + 4)``. workdir (``str``, *optional*): - Define a custom working directory. The working directory is the location in your filesystem where Pyrogram - will store your session files. + Define a custom working directory. + The working directory is the location in the filesystem where Pyrogram will store the session files. Defaults to the parent directory of the main script. plugins (``dict``, *optional*): - Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*. + Smart Plugins settings as dict, e.g.: *dict(root="plugins")*. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): Set the global parse mode of the client. By default, texts are parsed using both Markdown and HTML styles. @@ -157,7 +157,7 @@ class Client(Methods): takeout (``bool``, *optional*): Pass True to let the client use a takeout session instead of a normal one, implies *no_updates=True*. - Useful for exporting your Telegram data. Methods invoked inside a takeout session (such as get_history, + Useful for exporting Telegram data. Methods invoked inside a takeout session (such as get_chat_history, download_media, ...) are less prone to throw FloodWait exceptions. Only available for users, bots will ignore this parameter. Defaults to False (normal session). From 6e3dbbde5a8f2d90096e5e4890b66901ebd6f6e3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 21:20:13 +0200 Subject: [PATCH 250/539] Allow passing the api_id as string --- pyrogram/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index b0c493d5c9..2bc1dbfd21 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -192,7 +192,7 @@ class Client(Methods): def __init__( self, name: str, - api_id: int = None, + api_id: Union[int, str] = None, api_hash: str = None, app_version: str = APP_VERSION, device_model: str = DEVICE_MODEL, @@ -219,7 +219,7 @@ def __init__( super().__init__() self.name = name - self.api_id = api_id + self.api_id = int(api_id) if api_id else None self.api_hash = api_hash self.app_version = app_version self.device_model = device_model From a93e21831f79941e59ec59a21f6c49bddd442385 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 21:20:35 +0200 Subject: [PATCH 251/539] Update Pyrogram to v2.0.7 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2876b5020b..b0b5cf9ece 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.6" +__version__ = "2.0.7" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 8a2416665b5c6d9b5ce20ccfb117726d29ac7e00 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 08:30:26 +0200 Subject: [PATCH 252/539] Fix HTML and Markdown unparsing --- pyrogram/parser/html.py | 21 +++++++++++++-------- pyrogram/parser/markdown.py | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index c5f3c1e12d..8a7063e58a 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -24,6 +24,7 @@ import pyrogram from pyrogram import raw +from pyrogram.enums import MessageEntityType from pyrogram.errors import PeerIdInvalid from . import utils @@ -155,17 +156,21 @@ def unparse(text: str, entities: list): start = entity.offset end = start + entity.length - if entity_type in ("bold", "italic", "underline", "strikethrough"): - start_tag = f"<{entity_type[0]}>" - end_tag = f"" - elif entity_type in ("code", "pre", "blockquote", "spoiler"): - start_tag = f"<{entity_type}>" - end_tag = f"" - elif entity_type == "text_link": + if entity_type in (MessageEntityType.BOLD, MessageEntityType.ITALIC, MessageEntityType.UNDERLINE, + MessageEntityType.STRIKETHROUGH): + name = entity_type.name[0].lower() + start_tag = f"<{name}>" + end_tag = f"" + elif entity_type in (MessageEntityType.CODE, MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE, + MessageEntityType.SPOILER): + name = entity_type.name.lower() + start_tag = f"<{name}>" + end_tag = f"" + elif entity_type == MessageEntityType.TEXT_LINK: url = entity.url start_tag = f'' end_tag = "" - elif entity_type == "text_mention": + elif entity_type == MessageEntityType.TEXT_MENTION: user = entity.user start_tag = f'' end_tag = "" diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index 8b24d06302..364793406a 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -21,6 +21,7 @@ from typing import Optional import pyrogram +from pyrogram.enums import MessageEntityType from . import utils from .html import HTML @@ -119,25 +120,25 @@ def unparse(text: str, entities: list): start = entity.offset end = start + entity.length - if entity_type == "bold": + if entity_type == MessageEntityType.BOLD: start_tag = end_tag = BOLD_DELIM - elif entity_type == "italic": + elif entity_type == MessageEntityType.ITALIC: start_tag = end_tag = ITALIC_DELIM - elif entity_type == "underline": + elif entity_type == MessageEntityType.UNDERLINE: start_tag = end_tag = UNDERLINE_DELIM - elif entity_type == "strikethrough": + elif entity_type == MessageEntityType.STRIKETHROUGH: start_tag = end_tag = STRIKE_DELIM - elif entity_type == "code": + elif entity_type == MessageEntityType.CODE: start_tag = end_tag = CODE_DELIM - elif entity_type in ("pre", "blockquote"): + elif entity_type in (MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE): start_tag = end_tag = PRE_DELIM - elif entity_type == "spoiler": + elif entity_type == MessageEntityType.SPOILER: start_tag = end_tag = SPOILER_DELIM - elif entity_type == "text_link": + elif entity_type == MessageEntityType.TEXT_LINK: url = entity.url start_tag = "[" end_tag = f"]({url})" - elif entity_type == "text_mention": + elif entity_type == MessageEntityType.TEXT_MENTION: user = entity.user start_tag = "[" end_tag = f"](tg://user?id={user.id})" From 7bedf30d308d7a871b2ab43fd0a6aab12cf9f294 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 08:30:56 +0200 Subject: [PATCH 253/539] Update Pyrogram to v2.0.8 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index b0b5cf9ece..33eb712cf8 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.7" +__version__ = "2.0.8" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From b309caccd7fe722567f635f8c7b1abffe71608f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Mon, 25 Apr 2022 20:20:15 +0530 Subject: [PATCH 254/539] Make timestamp_to_datetime timezone aware (#966) * timezone aware object * Update utils.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index b9f3fdd84b..ce19e3bd5f 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -350,7 +350,7 @@ def zero_datetime() -> datetime: def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]: - return datetime.fromtimestamp(ts) if ts else None + return datetime.fromtimestamp(ts, timezone.utc) if ts else None def datetime_to_timestamp(dt: Optional[datetime]) -> Optional[int]: From 5f47c8c4990317352ab89f80af60909b8928b17a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 16:52:04 +0200 Subject: [PATCH 255/539] Fix some examples --- pyrogram/methods/chats/get_chat_members.py | 12 ++++++------ pyrogram/methods/messages/read_chat_history.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index 65688a3d71..3e11872cb1 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -101,14 +101,14 @@ async def get_chat_members( print(member) # Get administrators - administrators = list(await app.get_chat_members( - chat_id, - filter=enums.ChatMembersFilter.ADMINISTRATORS)) + administrators = [] + async for m in app.get_chat_members(chat_id, filter=enums.ChatMembersFilter.ADMINISTRATORS): + administrators.append(m) # Get bots - bots = list(await app.get_chat_members( - chat_id, - filter=enums.ChatMembersFilter.BOTS)) + bots = [] + async for m in app.get_chat_members(chat_id, filter=enums.ChatMembersFilter.BOTS): + bots.append(m) """ peer = await self.resolve_peer(chat_id) diff --git a/pyrogram/methods/messages/read_chat_history.py b/pyrogram/methods/messages/read_chat_history.py index 8a58fa264c..b3cc3bfc4c 100644 --- a/pyrogram/methods/messages/read_chat_history.py +++ b/pyrogram/methods/messages/read_chat_history.py @@ -47,10 +47,10 @@ async def read_chat_history( .. code-block:: python # Mark the whole chat as read - await app.read_history(chat_id) + await app.read_chat_history(chat_id) # Mark messages as read only up to the given message id - await app.read_history(chat_id, 12345) + await app.read_chat_history(chat_id, 12345) """ peer = await self.resolve_peer(chat_id) From 318996f81120148e0136132daff98e00c9aeb7aa Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 16:52:56 +0200 Subject: [PATCH 256/539] Update Pyrogram to v2.0.9 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 33eb712cf8..c7de8533f7 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.8" +__version__ = "2.0.9" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From c71d36ea49f43cd30a4d67f6c46f5da996a823d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 17:19:38 +0200 Subject: [PATCH 257/539] Fix Chat.get_members() --- pyrogram/types/user_and_chats/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 7e4442a132..b726d96e84 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from datetime import datetime -from typing import Union, List +from typing import Union, List, Optional, AsyncGenerator import pyrogram from pyrogram import raw, enums @@ -791,12 +791,12 @@ async def get_member( user_id=user_id ) - async def get_members( + def get_members( self, query: str = "", limit: int = 0, filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.SEARCH - ) -> List["types.ChatMember"]: + ) -> Optional[AsyncGenerator["types.ChatMember", None]]: """Bound method *get_members* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: From 43e08d4143049d6bc4189c3387af1ee5b2347442 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 17:20:05 +0200 Subject: [PATCH 258/539] Update Pyrogram to v2.0.10 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c7de8533f7..38b64a4822 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.9" +__version__ = "2.0.10" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 7992549386f138092a97329150c577b065663cb6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 17:27:36 +0200 Subject: [PATCH 259/539] Fix on_edited_message not being correctly registered in plugins --- pyrogram/methods/decorators/on_edited_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/methods/decorators/on_edited_message.py b/pyrogram/methods/decorators/on_edited_message.py index 02ebdec3b8..a8c86bb6d2 100644 --- a/pyrogram/methods/decorators/on_edited_message.py +++ b/pyrogram/methods/decorators/on_edited_message.py @@ -51,7 +51,7 @@ def decorator(func: Callable) -> Callable: func.handlers.append( ( - pyrogram.handlers.MessageHandler(func, self), + pyrogram.handlers.EditedMessageHandler(func, self), group if filters is None else filters ) ) From 1c0ddc9a8f59b5bbd5bd68b964e8d12a0161431e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 17:27:54 +0200 Subject: [PATCH 260/539] Update Pyrogram to v2.0.11 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 38b64a4822..e5eee02b93 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.10" +__version__ = "2.0.11" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 9deec03b873ac103bad9d53c3b79a56587ba84c4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:40:39 +0200 Subject: [PATCH 261/539] Revert "Make timestamp_to_datetime timezone aware (#966)" This reverts commit b309caccd7fe722567f635f8c7b1abffe71608f3. --- pyrogram/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index ce19e3bd5f..b9f3fdd84b 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -350,7 +350,7 @@ def zero_datetime() -> datetime: def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]: - return datetime.fromtimestamp(ts, timezone.utc) if ts else None + return datetime.fromtimestamp(ts) if ts else None def datetime_to_timestamp(dt: Optional[datetime]) -> Optional[int]: From bee5136598ee518f39184944be669852faf3c87f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:41:06 +0200 Subject: [PATCH 262/539] Update Pyrogram to v2.0.12 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e5eee02b93..8c264744c9 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.11" +__version__ = "2.0.12" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 23b03c6b1944bf29d73b720eee12bba370926154 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:02:19 +0200 Subject: [PATCH 263/539] Fix parsing of text mentions --- pyrogram/types/messages_and_media/message_entity.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index dbd6a98264..8a880a1fad 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -71,12 +71,21 @@ def __init__( @staticmethod def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["MessageEntity"]: + # Special case for InputMessageEntityMentionName -> MessageEntityType.TEXT_MENTION + # This happens in case of UpdateShortSentMessage inside send_message() where entities are parsed from the input + if isinstance(entity, raw.types.InputMessageEntityMentionName): + entity_type = enums.MessageEntityType.TEXT_MENTION + user_id = entity.user_id.user_id + else: + entity_type = enums.MessageEntityType(entity.__class__) + user_id = getattr(entity, "user_id", None) + return MessageEntity( - type=enums.MessageEntityType(entity.__class__), + type=entity_type, offset=entity.offset, length=entity.length, url=getattr(entity, "url", None), - user=types.User._parse(client, users.get(getattr(entity, "user_id", None), None)), + user=types.User._parse(client, users.get(user_id, None)), language=getattr(entity, "language", None), client=client ) From a21dd9f1313ae1b28b7bcafaac53a34fd6a6cdfe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:02:44 +0200 Subject: [PATCH 264/539] Update Pyrogram to v2.0.13 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 8c264744c9..cb25265ed0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.12" +__version__ = "2.0.13" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 2f82e753d681596233e7cab653a7c592a00b4a0b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Apr 2022 09:04:20 +0200 Subject: [PATCH 265/539] Keep namespaces in constructors names --- compiler/docs/compiler.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 6c2276b778..a1cc115eae 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -65,13 +65,19 @@ def build(path, level=0): if level: full_path = base + "/" + full_path + namespace = path.split("/")[-1] + if namespace in ["base", "types", "functions"]: + namespace = "" + + full_name = f"{(namespace + '.') if namespace else ''}{name}" + os.makedirs(os.path.dirname(DESTINATION + "/" + full_path), exist_ok=True) with open(DESTINATION + "/" + full_path, "w", encoding="utf-8") as f: f.write( page_template.format( - title=name, - title_markup="=" * len(name), + title=full_name, + title_markup="=" * len(full_name), full_class_path="pyrogram.raw.{}".format( ".".join(full_path.split("/")[:-1]) + "." + name ) @@ -90,7 +96,7 @@ def build(path, level=0): entities = [] for i in v: - entities.append(snek(i).replace("_", "-")) + entities.append(f'{i} <{snek(i).replace("_", "-")}>') if k != base: inner_path = base + "/" + k + "/index" + ".rst" From 4b6f29bb7605798259229959c4ee9bc94a920aeb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Apr 2022 09:10:48 +0200 Subject: [PATCH 266/539] Update examples --- docs/source/topics/advanced-usage.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst index 86eb67c4db..df99042d1b 100644 --- a/docs/source/topics/advanced-usage.rst +++ b/docs/source/topics/advanced-usage.rst @@ -51,7 +51,7 @@ Here's some examples: from pyrogram.raw import functions async with Client("my_account") as app: - await app.send( + await app.invoke( functions.account.UpdateProfile( first_name="First Name", last_name="Last Name", about="New bio text" @@ -67,10 +67,10 @@ Here's some examples: async with Client("my_account") as app: # Set online status - await app.send(functions.account.UpdateStatus(offline=False)) + await app.invoke(functions.account.UpdateStatus(offline=False)) # Set offline status - await app.send(functions.account.UpdateStatus(offline=True)) + await app.invoke(functions.account.UpdateStatus(offline=True)) - Get chat info: @@ -80,7 +80,7 @@ Here's some examples: from pyrogram.raw import functions, types async with Client("my_account") as app: - r = await app.send( + r = await app.invoke( functions.channels.GetFullChannel( channel=app.resolve_peer("username") ) From 045fe0bf210e997ea9820a761797c0ff4067f184 Mon Sep 17 00:00:00 2001 From: Hitalo <40531911+HitaloSama@users.noreply.github.com> Date: Wed, 27 Apr 2022 04:13:47 -0300 Subject: [PATCH 267/539] Remove wrong Client.parse_mode assignment (#973) --- pyrogram/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 2bc1dbfd21..5904747a91 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -257,7 +257,6 @@ def __init__( self.rnd_id = MsgId self.parser = Parser(self) - self.parse_mode = enums.ParseMode.DEFAULT self.session = None From 32b3452e76f81147a959ac00cff547c39184cb39 Mon Sep 17 00:00:00 2001 From: Stark Programmer <88478059+StarkBotsIndustries@users.noreply.github.com> Date: Wed, 27 Apr 2022 12:47:14 +0530 Subject: [PATCH 268/539] Fix self-destruct media if file_id and ttl_seconds are passed (#971) --- pyrogram/methods/messages/send_photo.py | 2 +- pyrogram/methods/messages/send_video.py | 2 +- pyrogram/utils.py | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 85d6fe4b7c..836ce1b1d4 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -155,7 +155,7 @@ async def send_photo( ttl_seconds=ttl_seconds ) else: - media = utils.get_input_media_from_file_id(photo, FileType.PHOTO) + media = utils.get_input_media_from_file_id(photo, FileType.PHOTO, ttl_seconds=ttl_seconds) else: file = await self.save_file(photo, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedPhoto( diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index 299f1b477c..669b42ec05 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -200,7 +200,7 @@ async def progress(current, total): ttl_seconds=ttl_seconds ) else: - media = utils.get_input_media_from_file_id(video, FileType.VIDEO) + media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=ttl_seconds) else: thumb = await self.save_file(thumb) file = await self.save_file(video, progress=progress, progress_args=progress_args) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index b9f3fdd84b..d5862d1a67 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -42,7 +42,8 @@ async def ainput(prompt: str = "", *, hide: bool = False): def get_input_media_from_file_id( file_id: str, - expected_file_type: FileType = None + expected_file_type: FileType = None, + ttl_seconds: int = None ) -> Union["raw.types.InputMediaPhoto", "raw.types.InputMediaDocument"]: try: decoded = FileId.decode(file_id) @@ -64,7 +65,8 @@ def get_input_media_from_file_id( id=decoded.media_id, access_hash=decoded.access_hash, file_reference=decoded.file_reference - ) + ), + ttl_seconds=ttl_seconds ) if file_type in DOCUMENT_TYPES: @@ -73,7 +75,8 @@ def get_input_media_from_file_id( id=decoded.media_id, access_hash=decoded.access_hash, file_reference=decoded.file_reference - ) + ), + ttl_seconds=ttl_seconds ) raise ValueError(f"Unknown file id: {file_id}") From 295060d190e98245ee16d68f887ba2aed1cf9cbf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Apr 2022 09:56:48 +0200 Subject: [PATCH 269/539] Remove "0x" prefix from IDs in the documentation --- 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 5736c68d49..7cbce6f396 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -378,7 +378,7 @@ def start(format: bool = False): else: docstring += f"Telegram API method.\n\n" - docstring += f" Details:\n - Layer: ``{layer}``\n - ID: ``{c.id}``\n\n" + docstring += f" Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n" if docstring_args: docstring += " Parameters:\n " + "\n ".join(docstring_args) From 5a7675597f843183d47e26d12a636fa0664580a2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:42:44 +0200 Subject: [PATCH 270/539] Update Pyrogram to v2.0.14 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index cb25265ed0..9580260818 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.13" +__version__ = "2.0.14" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ebb7bb2958392711760a945d2add815490469e94 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Apr 2022 21:37:05 +0200 Subject: [PATCH 271/539] Fix enumeration docstring --- pyrogram/enums/messages_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/enums/messages_filter.py b/pyrogram/enums/messages_filter.py index b9c84fc939..67bfac63ee 100644 --- a/pyrogram/enums/messages_filter.py +++ b/pyrogram/enums/messages_filter.py @@ -21,7 +21,7 @@ class MessagesFilter(AutoName): - """Messages filter enumeration used in used in :meth:`~pyrogram.Client.search_messages` and used in :meth:`~pyrogram.Client.search_global`""" + """Messages filter enumeration used in :meth:`~pyrogram.Client.search_messages` and :meth:`~pyrogram.Client.search_global`""" EMPTY = raw.types.InputMessagesFilterEmpty "Empty filter (any kind of messages)" From a762cbc23787f3c745e920d1a890a486ea05ee34 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 29 Apr 2022 11:02:58 +0200 Subject: [PATCH 272/539] Remove unused import --- pyrogram/storage/storage.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py index de397718fc..0689b6826c 100644 --- a/pyrogram/storage/storage.py +++ b/pyrogram/storage/storage.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import base64 -import lzma import struct from typing import List, Tuple From bbe90fc6d376f7b6be4ed35f677828296b5c7e07 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 29 Apr 2022 11:03:28 +0200 Subject: [PATCH 273/539] Update Pyrogram to v2.0.15 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 9580260818..19fdc0cf9a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.14" +__version__ = "2.0.15" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 795ffc027af6ffdc58b63eeb3fa8bd592349a2d9 Mon Sep 17 00:00:00 2001 From: Evgen Fil Date: Fri, 29 Apr 2022 15:40:19 +0500 Subject: [PATCH 274/539] Allow non-interactive migration from storage v2 to v3 (#979) --- pyrogram/client.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 5904747a91..c12de07508 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -592,21 +592,24 @@ async def load_session(self): else: # Needed for migration from storage v2 to v3 if not await self.storage.api_id(): - while True: - try: - value = int(await ainput("Enter the api_id part of the API key: ")) + if self.api_id: + await self.storage.api_id(self.api_id) + else: + while True: + try: + value = int(await ainput("Enter the api_id part of the API key: ")) - if value <= 0: - print("Invalid value") - continue + if value <= 0: + print("Invalid value") + continue - confirm = (await ainput(f'Is "{value}" correct? (y/N): ')).lower() + confirm = (await ainput(f'Is "{value}" correct? (y/N): ')).lower() - if confirm == "y": - await self.storage.api_id(value) - break - except Exception as e: - print(e) + if confirm == "y": + await self.storage.api_id(value) + break + except Exception as e: + print(e) def load_plugins(self): if self.plugins: From 97b6c32c7ff707fd2721338581e7dad5072f745e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:41:06 +0200 Subject: [PATCH 275/539] Update Pyrogram to v2.0.16 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 19fdc0cf9a..164d8c60df 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.15" +__version__ = "2.0.16" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 956e5c1a4f6a7657b325bf873be4666aad1ee25f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 May 2022 09:04:25 +0200 Subject: [PATCH 276/539] Clean up on download's stop_transmission and return None --- pyrogram/__init__.py | 2 +- pyrogram/client.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 164d8c60df..7dccf1046a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ from concurrent.futures.thread import ThreadPoolExecutor -class StopTransmission(StopAsyncIteration): +class StopTransmission(Exception): pass diff --git a/pyrogram/client.py b/pyrogram/client.py index c12de07508..c1d04046b2 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -727,23 +727,27 @@ def load_plugins(self): async def handle_download(self, packet): file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet - file = BytesIO() if in_memory else tempfile.NamedTemporaryFile("wb", delete=False) - async for chunk in self.get_file(file_id, file_size, 0, 0, progress, progress_args): - file.write(chunk) - - if file and not in_memory: - file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) - os.makedirs(directory, exist_ok=True) - file.close() - shutil.move(file.name, file_path) - - return file_path - - if file and in_memory: - file.name = file_name - return file + try: + async for chunk in self.get_file(file_id, file_size, 0, 0, progress, progress_args): + file.write(chunk) + except pyrogram.StopTransmission: + if not in_memory: + file.close() + os.remove(file.name) + + return None + else: + if in_memory: + file.name = file_name + return file + else: + file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + os.makedirs(directory, exist_ok=True) + file.close() + shutil.move(file.name, file_path) + return file_path async def get_file( self, @@ -970,9 +974,10 @@ async def get_file( break except Exception as e: raise e + except pyrogram.StopTransmission: + raise except Exception as e: - if not isinstance(e, pyrogram.StopTransmission): - log.error(e, exc_info=True) + log.error(e, exc_info=True) def guess_mime_type(self, filename: str) -> Optional[str]: return self.mimetypes.guess_type(filename)[0] From ec43196df78592ddec6bd85db70315e250857146 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 May 2022 09:05:05 +0200 Subject: [PATCH 277/539] Update Pyrogram to v2.0.17 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 7dccf1046a..ff0c79d077 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.16" +__version__ = "2.0.17" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 97a4ddea270325b17f7ce37f0c65ac9edda99acf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 6 May 2022 21:57:33 +0200 Subject: [PATCH 278/539] Update error messages --- compiler/errors/source/400_BAD_REQUEST.tsv | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index f3b42fb397..990d875ea8 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -4,7 +4,7 @@ ACCESS_TOKEN_EXPIRED The bot token has expired ACCESS_TOKEN_INVALID The bot access token is invalid ADMINS_TOO_MUCH The chat has too many administrators ADMIN_RANK_EMOJI_NOT_ALLOWED Emoji are not allowed in custom administrator titles -ADMIN_RANK_INVALID The custom administrator title is invalid or is longer than 16 characters +ADMIN_RANK_INVALID The custom administrator title is invalid or too long ALBUM_PHOTOS_TOO_MANY Too many photos were included in the album API_ID_INVALID The api_id/api_hash combination is invalid API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side because it was published somewhere @@ -35,7 +35,7 @@ BOT_SCORE_NOT_MODIFIED The bot score was not modified BROADCAST_ID_INVALID The channel is invalid BROADCAST_PUBLIC_VOTERS_FORBIDDEN Polls with public voters cannot be sent in channels BROADCAST_REQUIRED The request can only be used with a channel -BUTTON_DATA_INVALID The button callback data contains invalid data or exceeds 64 bytes +BUTTON_DATA_INVALID The button callback data is invalid or too large BUTTON_TYPE_INVALID The type of one of the buttons you provided is invalid BUTTON_URL_INVALID The button url is invalid CALL_ALREADY_ACCEPTED The call is already accepted @@ -49,7 +49,7 @@ CHANNEL_ADD_INVALID Internal error. CHANNEL_BANNED The channel is banned CHANNEL_INVALID The channel parameter is invalid CHANNEL_PRIVATE The channel/supergroup is not accessible -CHANNEL_TOO_LARGE The channel is too large to be deleted; this error is issued when trying to delete channels with more than 1000 members (subject to change) +CHANNEL_TOO_LARGE The channel is too large CHAT_ABOUT_NOT_MODIFIED The chat about text was not modified because you tried to edit it using the same content CHAT_ABOUT_TOO_LONG The chat about text is too long CHAT_ADMIN_REQUIRED The method requires chat admin privileges @@ -109,13 +109,13 @@ FIELD_NAME_EMPTY The field with the name FIELD_NAME is missing FIELD_NAME_INVALID The field with the name FIELD_NAME is invalid FILE_ID_INVALID The file id is invalid FILE_MIGRATE_X The file is in Data Center No. {value} -FILE_PARTS_INVALID Invalid number of parts. The value is not between 1 and 4000 +FILE_PARTS_INVALID Invalid number of parts. FILE_PART_EMPTY The file part sent is empty -FILE_PART_INVALID The file part number is invalid. The value is not between 0 and 3999 +FILE_PART_INVALID The file part number is invalid. FILE_PART_LENGTH_INVALID The length of a file part is invalid FILE_PART_SIZE_CHANGED The part size is different from the size of one of the previous parts in the same file -FILE_PART_SIZE_INVALID 512 KB cannot be evenly divided by part_size -FILE_PART_TOO_BIG The size limit (512 KB) for the content of the file part has been exceeded +FILE_PART_SIZE_INVALID The file part size is invalid +FILE_PART_TOO_BIG The size limit for the content of the file part has been exceeded FILE_PART_X_MISSING Part {value} of the file is missing from storage FILE_REFERENCE_EMPTY The file id contains an empty file reference, you must obtain a valid one by fetching the message from the origin context FILE_REFERENCE_EXPIRED The file id contains an expired file reference, you must obtain a valid one by fetching the message from the origin context @@ -162,7 +162,7 @@ LOCATION_INVALID The file location is invalid MAX_ID_INVALID The max_id parameter is invalid MAX_QTS_INVALID The provided QTS is invalid MD5_CHECKSUM_INVALID The file's checksum did not match the md5_checksum parameter -MEDIA_CAPTION_TOO_LONG The media caption is longer than 1024 characters +MEDIA_CAPTION_TOO_LONG The media caption is too long MEDIA_EMPTY The media you tried to send is invalid MEDIA_INVALID The media is invalid MEDIA_NEW_INVALID The new media to edit the message with is invalid @@ -176,7 +176,7 @@ MESSAGE_IDS_EMPTY The requested message doesn't exist or you provided no message MESSAGE_ID_INVALID The message id is invalid MESSAGE_NOT_MODIFIED The message was not modified because you tried to edit it using the same content MESSAGE_POLL_CLOSED You can't interact with a closed poll -MESSAGE_TOO_LONG The message text is over 4096 characters +MESSAGE_TOO_LONG The message text is too long METHOD_INVALID The API method is invalid and cannot be used MSG_ID_INVALID The message ID used in the peer was invalid MSG_WAIT_FAILED A waiting call returned an error @@ -225,7 +225,7 @@ PHOTO_FILE_MISSING Profile photo file missing PHOTO_ID_INVALID The photo id is invalid PHOTO_INVALID The photo is invalid PHOTO_INVALID_DIMENSIONS The photo dimensions are invalid -PHOTO_SAVE_FILE_INVALID The photo you tried to send cannot be saved by Telegram. A reason may be that it exceeds 10 MB. Try resizing it locally +PHOTO_SAVE_FILE_INVALID The photo you tried to send cannot be saved by Telegram PHOTO_THUMB_URL_EMPTY The photo thumb URL is empty PHOTO_THUMB_URL_INVALID The photo thumb URL is invalid PINNED_DIALOGS_TOO_MUCH Too many pinned dialogs @@ -268,9 +268,9 @@ SCHEDULE_BOT_NOT_ALLOWED Bots are not allowed to schedule messages SCHEDULE_DATE_INVALID Invalid schedule date provided SCHEDULE_DATE_TOO_LATE The date you tried to schedule is too far in the future (more than one year) SCHEDULE_STATUS_PRIVATE You cannot schedule a message until the person comes online if their privacy does not show this information -SCHEDULE_TOO_MUCH You cannot schedule more than 100 messages in this chat +SCHEDULE_TOO_MUCH You tried to schedule too many messages in this chat SEARCH_QUERY_EMPTY The search query is empty -SECONDS_INVALID The seconds interval is invalid, for slow mode try with 0 (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h) +SECONDS_INVALID The seconds interval is invalid SEND_MESSAGE_MEDIA_INVALID The message media is invalid SEND_MESSAGE_TYPE_INVALID The message type is invalid SESSION_TOO_FRESH_X You can't do this action because the current session was logged-in recently From ce49fc38a05c193144a02c43cffa880f30ed7c70 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 6 May 2022 22:00:20 +0200 Subject: [PATCH 279/539] Fix promote_chat_member when adding bots as admins --- pyrogram/methods/chats/promote_chat_member.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py index f8a2779b3b..46ffe44681 100644 --- a/pyrogram/methods/chats/promote_chat_member.py +++ b/pyrogram/methods/chats/promote_chat_member.py @@ -19,7 +19,7 @@ from typing import Union import pyrogram -from pyrogram import raw, types +from pyrogram import raw, types, errors class PromoteChatMember: @@ -61,12 +61,15 @@ async def promote_chat_member( if privileges is None: privileges = types.ChatPrivileges() - raw_chat_member = (await self.invoke( - raw.functions.channels.GetParticipant( - channel=chat_id, - participant=user_id - ) - )).participant + try: + raw_chat_member = (await self.invoke( + raw.functions.channels.GetParticipant( + channel=chat_id, + participant=user_id + ) + )).participant + except errors.RPCError: + raw_chat_member = None rank = None if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin): From a320a9e7ffbe15f41325bca6aef45f18b93d4557 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 6 May 2022 22:00:41 +0200 Subject: [PATCH 280/539] Update Pyrogram to v2.0.18 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index ff0c79d077..599f5ec41b 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.17" +__version__ = "2.0.18" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From f1e4a0ce74ae7ad5bbdd71def5e3f746e72e7249 Mon Sep 17 00:00:00 2001 From: leonardotty <81367045+leonardotty@users.noreply.github.com> Date: Fri, 6 May 2022 22:06:11 +0200 Subject: [PATCH 281/539] Update maximum caption length (#989) Co-authored-by: leonardotty Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/methods/messages/copy_media_group.py | 2 +- pyrogram/methods/messages/copy_message.py | 2 +- pyrogram/methods/messages/send_animation.py | 2 +- pyrogram/methods/messages/send_audio.py | 2 +- pyrogram/methods/messages/send_cached_media.py | 2 +- pyrogram/methods/messages/send_document.py | 2 +- pyrogram/methods/messages/send_photo.py | 2 +- pyrogram/methods/messages/send_video.py | 2 +- pyrogram/methods/messages/send_voice.py | 2 +- .../inline_query_result_animation.py | 2 +- .../inline_mode/inline_query_result_audio.py | 2 +- .../inline_query_result_cached_animation.py | 2 +- .../inline_query_result_cached_audio.py | 2 +- .../inline_query_result_cached_document.py | 2 +- .../inline_query_result_cached_photo.py | 2 +- .../inline_query_result_cached_video.py | 2 +- .../inline_query_result_cached_voice.py | 2 +- .../inline_query_result_document.py | 2 +- .../inline_mode/inline_query_result_photo.py | 2 +- .../inline_mode/inline_query_result_video.py | 2 +- .../inline_mode/inline_query_result_voice.py | 2 +- .../types/input_media/input_media_animation.py | 2 +- .../types/input_media/input_media_audio.py | 2 +- .../types/input_media/input_media_document.py | 2 +- .../types/input_media/input_media_photo.py | 2 +- .../types/input_media/input_media_video.py | 2 +- pyrogram/types/messages_and_media/message.py | 18 +++++++++--------- 27 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index de47465d27..981a4ec2cd 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -51,7 +51,7 @@ async def copy_media_group( Message identifier in the chat specified in *from_chat_id*. captions (``str`` | List of ``str`` , *optional*): - New caption for media, 0-1024 characters after entities parsing for each media. + New caption for media, 0-4096 characters after entities parsing for each media. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py index b114a9e0af..c94145e6ec 100644 --- a/pyrogram/methods/messages/copy_message.py +++ b/pyrogram/methods/messages/copy_message.py @@ -66,7 +66,7 @@ async def copy_message( Message identifier in the chat specified in *from_chat_id*. caption (``string``, *optional*): - New caption for media, 0-1024 characters after entities parsing. + New caption for media, 0-4096 characters after entities parsing. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index efa9cb1671..74b892133f 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -73,7 +73,7 @@ async def send_animation( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Animation caption, 0-1024 characters. + Animation caption, 0-4096 characters. unsave (``bool``, *optional*): By default, the server will save into your own collection any new animation you send. diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index f4552832fe..e0e2493b77 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -74,7 +74,7 @@ async def send_audio( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Audio caption, 0-1024 characters. + Audio caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py index f0e04d7232..85040885d1 100644 --- a/pyrogram/methods/messages/send_cached_media.py +++ b/pyrogram/methods/messages/send_cached_media.py @@ -61,7 +61,7 @@ async def send_cached_media( Pass a file_id as string to send a media that exists on the Telegram servers. caption (``str``, *optional*): - Media caption, 0-1024 characters. + Media caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py index 99c90fbb25..9c96a03b89 100644 --- a/pyrogram/methods/messages/send_document.py +++ b/pyrogram/methods/messages/send_document.py @@ -76,7 +76,7 @@ async def send_document( Thumbnails can't be reused and can be only uploaded as a new file. caption (``str``, *optional*): - Document caption, 0-1024 characters. + Document caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 836ce1b1d4..3cd32ef26c 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -67,7 +67,7 @@ async def send_photo( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Photo caption, 0-1024 characters. + Photo caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index 669b42ec05..de4150f003 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -74,7 +74,7 @@ async def send_video( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Video caption, 0-1024 characters. + Video caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index 5947ecc23d..e12a0992de 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -68,7 +68,7 @@ async def send_voice( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Voice message caption, 0-1024 characters. + Voice message caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py index 71d1edf40a..4a70b02c0d 100644 --- a/pyrogram/types/inline_mode/inline_query_result_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_animation.py @@ -60,7 +60,7 @@ class InlineQueryResultAnimation(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the animation to be sent, 0-1024 characters. + Caption of the animation to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py index a39021000f..685b53d46e 100644 --- a/pyrogram/types/inline_mode/inline_query_result_audio.py +++ b/pyrogram/types/inline_mode/inline_query_result_audio.py @@ -48,7 +48,7 @@ class InlineQueryResultAudio(InlineQueryResult): Audio duration in seconds. caption (``str``, *optional*): - Caption of the audio to be sent, 0-1024 characters. + Caption of the audio to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_animation.py b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py index 63e58ca027..9233fb704f 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py @@ -43,7 +43,7 @@ class InlineQueryResultCachedAnimation(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_audio.py b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py index 9535f63343..e31cde8684 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_audio.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py @@ -39,7 +39,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult): Defaults to a randomly generated UUID4. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_document.py b/pyrogram/types/inline_mode/inline_query_result_cached_document.py index 2ab190e7ff..acd7c9dc53 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_document.py @@ -45,7 +45,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py index 2e01d344ec..142085ac37 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py @@ -45,7 +45,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_video.py b/pyrogram/types/inline_mode/inline_query_result_cached_video.py index 00ea32ecdb..999386357a 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_video.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_video.py @@ -46,7 +46,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_voice.py b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py index cc2bd76855..8ca7de4690 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_voice.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py @@ -43,7 +43,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_document.py b/pyrogram/types/inline_mode/inline_query_result_document.py index eac7901b14..517c7523b5 100644 --- a/pyrogram/types/inline_mode/inline_query_result_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_document.py @@ -45,7 +45,7 @@ class InlineQueryResultDocument(InlineQueryResult): Defaults to a randomly generated UUID4. caption (``str``, *optional*): - Caption of the video to be sent, 0-1024 characters. + Caption of the video to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py index d75ccac2a5..434b57b363 100644 --- a/pyrogram/types/inline_mode/inline_query_result_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_photo.py @@ -56,7 +56,7 @@ class InlineQueryResultPhoto(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_video.py b/pyrogram/types/inline_mode/inline_query_result_video.py index 5f71111f4f..82a9368105 100644 --- a/pyrogram/types/inline_mode/inline_query_result_video.py +++ b/pyrogram/types/inline_mode/inline_query_result_video.py @@ -61,7 +61,7 @@ class InlineQueryResultVideo(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the video to be sent, 0-1024 characters. + Caption of the video to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_voice.py b/pyrogram/types/inline_mode/inline_query_result_voice.py index 31b422f8d3..7a8d18ed71 100644 --- a/pyrogram/types/inline_mode/inline_query_result_voice.py +++ b/pyrogram/types/inline_mode/inline_query_result_voice.py @@ -45,7 +45,7 @@ class InlineQueryResultVoice(InlineQueryResult): Recording duration in seconds. caption (``str``, *optional*): - Caption of the audio to be sent, 0-1024 characters. + Caption of the audio to be sent, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py index 04aa940edc..39cfb5b45d 100644 --- a/pyrogram/types/input_media/input_media_animation.py +++ b/pyrogram/types/input_media/input_media_animation.py @@ -41,7 +41,7 @@ class InputMediaAnimation(InputMedia): 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-1024 characters. + Caption of the animation to be sent, 0-4096 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py index b4bb7575be..6ab4fe0ef3 100644 --- a/pyrogram/types/input_media/input_media_audio.py +++ b/pyrogram/types/input_media/input_media_audio.py @@ -43,7 +43,7 @@ class InputMediaAudio(InputMedia): 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-1024 characters. + Caption of the audio to be sent, 0-4096 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py index 91dfc7d673..3e5a0f5788 100644 --- a/pyrogram/types/input_media/input_media_document.py +++ b/pyrogram/types/input_media/input_media_document.py @@ -41,7 +41,7 @@ class InputMediaDocument(InputMedia): 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-1024 characters. + Caption of the document to be sent, 0-4096 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_photo.py b/pyrogram/types/input_media/input_media_photo.py index ce8b41a218..178ee3d420 100644 --- a/pyrogram/types/input_media/input_media_photo.py +++ b/pyrogram/types/input_media/input_media_photo.py @@ -36,7 +36,7 @@ class InputMediaPhoto(InputMedia): pass an HTTP URL as a string for Telegram to get a photo from the Internet. caption (``str``, *optional*): - Caption of the photo to be sent, 0-1024 characters. + Caption of the photo to be sent, 0-4096 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py index bad4e3ef3a..130129ab60 100644 --- a/pyrogram/types/input_media/input_media_video.py +++ b/pyrogram/types/input_media/input_media_video.py @@ -42,7 +42,7 @@ class InputMediaVideo(InputMedia): 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-1024 characters. + Caption of the video to be sent, 0-4096 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index ab5e202f2a..1ffdeafdb3 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -177,7 +177,7 @@ class Message(Object, Update): Message is a video note, information about the video message. caption (``str``, *optional*): - Caption for the audio, document, photo, video or voice, 0-1024 characters. + Caption for the audio, document, photo, video or voice, 0-4096 characters. If the message contains caption entities (bold, italic, ...) you can access *caption.markdown* or *caption.html* to get the marked up caption text. In case there is no caption entity, the fields will contain the same text as *caption*. @@ -1022,7 +1022,7 @@ async def reply_animation( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Animation caption, 0-1024 characters. + Animation caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1161,7 +1161,7 @@ async def reply_audio( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Audio caption, 0-1024 characters. + Audio caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1292,7 +1292,7 @@ async def reply_cached_media( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``bool``, *optional*): - Media caption, 0-1024 characters. + Media caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1514,7 +1514,7 @@ async def reply_document( Thumbnails can't be reused and can be only uploaded as a new file. caption (``str``, *optional*): - Document caption, 0-1024 characters. + Document caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1916,7 +1916,7 @@ async def reply_photo( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Photo caption, 0-1024 characters. + Photo caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -2387,7 +2387,7 @@ async def reply_video( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Video caption, 0-1024 characters. + Video caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -2651,7 +2651,7 @@ async def reply_voice( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Voice message caption, 0-1024 characters. + Voice message caption, 0-4096 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -3007,7 +3007,7 @@ async def copy( For a contact that exists in your Telegram address book you can use his phone number (str). caption (``string``, *optional*): - New caption for media, 0-1024 characters after entities parsing. + New caption for media, 0-4096 characters after entities parsing. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. From 0bc340081fefcaead193a046a804af8eca683787 Mon Sep 17 00:00:00 2001 From: Moshe <62907797+moshe-coh@users.noreply.github.com> Date: Fri, 6 May 2022 23:08:23 +0300 Subject: [PATCH 282/539] Fix wrong enum usage (#988) --- pyrogram/types/user_and_chats/chat_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py index a5292c6418..88ff42f343 100644 --- a/pyrogram/types/user_and_chats/chat_event.py +++ b/pyrogram/types/user_and_chats/chat_event.py @@ -369,7 +369,7 @@ async def _parse( elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleAdmin): old_administrator_privileges = types.ChatMember._parse(client, action.prev_participant, users, chats) new_administrator_privileges = types.ChatMember._parse(client, action.new_participant, users, chats) - action = enums.ChatEventAction.ADMIN_RIGHTS_CHANGED + action = enums.ChatEventAction.ADMINISTRATOR_PRIVILEGES_CHANGED elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleBan): old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users, chats) From e708f8dabfd39e37c4d4e820a67abb654c38b03e Mon Sep 17 00:00:00 2001 From: Stark Programmer <88478059+StarkBotsIndustries@users.noreply.github.com> Date: Sat, 7 May 2022 01:38:52 +0530 Subject: [PATCH 283/539] Add missing parameters to Chat.set_photo (#980) --- pyrogram/methods/chats/set_chat_photo.py | 4 +-- pyrogram/types/user_and_chats/chat.py | 41 ++++++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py index dd44bb872c..615eca253e 100644 --- a/pyrogram/methods/chats/set_chat_photo.py +++ b/pyrogram/methods/chats/set_chat_photo.py @@ -70,14 +70,14 @@ async def set_chat_photo( # Set chat photo using a local file await app.set_chat_photo(chat_id, photo="photo.jpg") - # Set chat photo using an exiting Photo file_id + # Set chat photo using an existing Photo file_id await app.set_chat_photo(chat_id, photo=photo.file_id) # Set chat video using a local file await app.set_chat_photo(chat_id, video="video.mp4") - # Set chat photo using an exiting Video file_id + # Set chat photo using an existing Video file_id await app.set_chat_photo(chat_id, video=video.file_id) """ peer = await self.resolve_peer(chat_id) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index b726d96e84..dc345bbc63 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from datetime import datetime -from typing import Union, List, Optional, AsyncGenerator +from typing import Union, List, Optional, AsyncGenerator, BinaryIO import pyrogram from pyrogram import raw, enums @@ -477,7 +477,13 @@ async def set_description(self, description: str) -> bool: description=description ) - async def set_photo(self, photo: str) -> bool: + async def set_photo( + self, + *, + photo: Union[str, BinaryIO] = None, + video: Union[str, BinaryIO] = None, + video_start_ts: float = None, + ) -> bool: """Bound method *set_photo* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: @@ -492,11 +498,32 @@ async def set_photo(self, photo: str) -> bool: Example: .. code-block:: python - await chat.set_photo("photo.png") + # Set chat photo using a local file + await chat.set_photo(photo="photo.jpg") + + # Set chat photo using an existing Photo file_id + await chat.set_photo(photo=photo.file_id) + + + # Set chat video using a local file + await chat.set_photo(video="video.mp4") + + # Set chat photo using an existing Video file_id + await chat.set_photo(video=video.file_id) Parameters: - photo (``str``): - New chat photo. You can pass a :obj:`~pyrogram.types.Photo` id or a file path to upload a new photo. + photo (``str`` | ``BinaryIO``, *optional*): + New chat photo. You can pass a :obj:`~pyrogram.types.Photo` file_id, a file path to upload a new photo + from your local machine or a binary file-like object with its attribute + ".name" set for in-memory uploads. + + video (``str`` | ``BinaryIO``, *optional*): + New chat video. You can pass a :obj:`~pyrogram.types.Video` file_id, a file path to upload a new video + from your local machine or a binary file-like object with its attribute + ".name" set for in-memory uploads. + + video_start_ts (``float``, *optional*): + The timestamp in seconds of the video frame to use as photo profile preview. Returns: ``bool``: True on success. @@ -508,7 +535,9 @@ async def set_photo(self, photo: str) -> bool: return await self._client.set_chat_photo( chat_id=self.id, - photo=photo + photo=photo, + video=video, + video_start_ts=video_start_ts ) async def ban_member( From 4916b02d3e39c6202e824a83430c1327bbc52133 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 6 May 2022 22:09:31 +0200 Subject: [PATCH 284/539] Update Pyrogram to v2.0.19 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 599f5ec41b..0be47e5f44 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.18" +__version__ = "2.0.19" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 6cf849c3eacd58d7befd3b357952121d5c80b7ba Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 7 May 2022 12:01:14 +0200 Subject: [PATCH 285/539] Revert "Update maximum caption length (#989)" This reverts commit f1e4a0ce74ae7ad5bbdd71def5e3f746e72e7249. --- pyrogram/methods/messages/copy_media_group.py | 2 +- pyrogram/methods/messages/copy_message.py | 2 +- pyrogram/methods/messages/send_animation.py | 2 +- pyrogram/methods/messages/send_audio.py | 2 +- pyrogram/methods/messages/send_cached_media.py | 2 +- pyrogram/methods/messages/send_document.py | 2 +- pyrogram/methods/messages/send_photo.py | 2 +- pyrogram/methods/messages/send_video.py | 2 +- pyrogram/methods/messages/send_voice.py | 2 +- .../inline_query_result_animation.py | 2 +- .../inline_mode/inline_query_result_audio.py | 2 +- .../inline_query_result_cached_animation.py | 2 +- .../inline_query_result_cached_audio.py | 2 +- .../inline_query_result_cached_document.py | 2 +- .../inline_query_result_cached_photo.py | 2 +- .../inline_query_result_cached_video.py | 2 +- .../inline_query_result_cached_voice.py | 2 +- .../inline_query_result_document.py | 2 +- .../inline_mode/inline_query_result_photo.py | 2 +- .../inline_mode/inline_query_result_video.py | 2 +- .../inline_mode/inline_query_result_voice.py | 2 +- .../types/input_media/input_media_animation.py | 2 +- .../types/input_media/input_media_audio.py | 2 +- .../types/input_media/input_media_document.py | 2 +- .../types/input_media/input_media_photo.py | 2 +- .../types/input_media/input_media_video.py | 2 +- pyrogram/types/messages_and_media/message.py | 18 +++++++++--------- 27 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index 981a4ec2cd..de47465d27 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -51,7 +51,7 @@ async def copy_media_group( Message identifier in the chat specified in *from_chat_id*. captions (``str`` | List of ``str`` , *optional*): - New caption for media, 0-4096 characters after entities parsing for each media. + New caption for media, 0-1024 characters after entities parsing for each media. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py index c94145e6ec..b114a9e0af 100644 --- a/pyrogram/methods/messages/copy_message.py +++ b/pyrogram/methods/messages/copy_message.py @@ -66,7 +66,7 @@ async def copy_message( Message identifier in the chat specified in *from_chat_id*. caption (``string``, *optional*): - New caption for media, 0-4096 characters after entities parsing. + New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index 74b892133f..efa9cb1671 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -73,7 +73,7 @@ async def send_animation( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Animation caption, 0-4096 characters. + Animation caption, 0-1024 characters. unsave (``bool``, *optional*): By default, the server will save into your own collection any new animation you send. diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index e0e2493b77..f4552832fe 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -74,7 +74,7 @@ async def send_audio( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Audio caption, 0-4096 characters. + Audio caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py index 85040885d1..f0e04d7232 100644 --- a/pyrogram/methods/messages/send_cached_media.py +++ b/pyrogram/methods/messages/send_cached_media.py @@ -61,7 +61,7 @@ async def send_cached_media( Pass a file_id as string to send a media that exists on the Telegram servers. caption (``str``, *optional*): - Media caption, 0-4096 characters. + Media caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py index 9c96a03b89..99c90fbb25 100644 --- a/pyrogram/methods/messages/send_document.py +++ b/pyrogram/methods/messages/send_document.py @@ -76,7 +76,7 @@ async def send_document( Thumbnails can't be reused and can be only uploaded as a new file. caption (``str``, *optional*): - Document caption, 0-4096 characters. + Document caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 3cd32ef26c..836ce1b1d4 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -67,7 +67,7 @@ async def send_photo( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Photo caption, 0-4096 characters. + Photo caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index de4150f003..669b42ec05 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -74,7 +74,7 @@ async def send_video( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Video caption, 0-4096 characters. + Video caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index e12a0992de..5947ecc23d 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -68,7 +68,7 @@ async def send_voice( pass a binary file-like object with its attribute ".name" set for in-memory uploads. caption (``str``, *optional*): - Voice message caption, 0-4096 characters. + Voice message caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py index 4a70b02c0d..71d1edf40a 100644 --- a/pyrogram/types/inline_mode/inline_query_result_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_animation.py @@ -60,7 +60,7 @@ class InlineQueryResultAnimation(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the animation to be sent, 0-4096 characters. + Caption of the animation to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py index 685b53d46e..a39021000f 100644 --- a/pyrogram/types/inline_mode/inline_query_result_audio.py +++ b/pyrogram/types/inline_mode/inline_query_result_audio.py @@ -48,7 +48,7 @@ class InlineQueryResultAudio(InlineQueryResult): Audio duration in seconds. caption (``str``, *optional*): - Caption of the audio to be sent, 0-4096 characters. + Caption of the audio to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_animation.py b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py index 9233fb704f..63e58ca027 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_animation.py @@ -43,7 +43,7 @@ class InlineQueryResultCachedAnimation(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_audio.py b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py index e31cde8684..9535f63343 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_audio.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_audio.py @@ -39,7 +39,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult): Defaults to a randomly generated UUID4. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_document.py b/pyrogram/types/inline_mode/inline_query_result_cached_document.py index acd7c9dc53..2ab190e7ff 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_document.py @@ -45,7 +45,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py index 142085ac37..2e01d344ec 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_photo.py @@ -45,7 +45,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_video.py b/pyrogram/types/inline_mode/inline_query_result_cached_video.py index 999386357a..00ea32ecdb 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_video.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_video.py @@ -46,7 +46,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_voice.py b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py index 8ca7de4690..cc2bd76855 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_voice.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_voice.py @@ -43,7 +43,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult): Title for the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_document.py b/pyrogram/types/inline_mode/inline_query_result_document.py index 517c7523b5..eac7901b14 100644 --- a/pyrogram/types/inline_mode/inline_query_result_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_document.py @@ -45,7 +45,7 @@ class InlineQueryResultDocument(InlineQueryResult): Defaults to a randomly generated UUID4. caption (``str``, *optional*): - Caption of the video to be sent, 0-4096 characters. + Caption of the video to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py index 434b57b363..d75ccac2a5 100644 --- a/pyrogram/types/inline_mode/inline_query_result_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_photo.py @@ -56,7 +56,7 @@ class InlineQueryResultPhoto(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_video.py b/pyrogram/types/inline_mode/inline_query_result_video.py index 82a9368105..5f71111f4f 100644 --- a/pyrogram/types/inline_mode/inline_query_result_video.py +++ b/pyrogram/types/inline_mode/inline_query_result_video.py @@ -61,7 +61,7 @@ class InlineQueryResultVideo(InlineQueryResult): Short description of the result. caption (``str``, *optional*): - Caption of the video to be sent, 0-4096 characters. + Caption of the video to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/inline_mode/inline_query_result_voice.py b/pyrogram/types/inline_mode/inline_query_result_voice.py index 7a8d18ed71..31b422f8d3 100644 --- a/pyrogram/types/inline_mode/inline_query_result_voice.py +++ b/pyrogram/types/inline_mode/inline_query_result_voice.py @@ -45,7 +45,7 @@ class InlineQueryResultVoice(InlineQueryResult): Recording duration in seconds. caption (``str``, *optional*): - Caption of the audio to be sent, 0-4096 characters. + Caption of the audio to be sent, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py index 39cfb5b45d..04aa940edc 100644 --- a/pyrogram/types/input_media/input_media_animation.py +++ b/pyrogram/types/input_media/input_media_animation.py @@ -41,7 +41,7 @@ class InputMediaAnimation(InputMedia): 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-4096 characters. + Caption of the animation to be sent, 0-1024 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py index 6ab4fe0ef3..b4bb7575be 100644 --- a/pyrogram/types/input_media/input_media_audio.py +++ b/pyrogram/types/input_media/input_media_audio.py @@ -43,7 +43,7 @@ class InputMediaAudio(InputMedia): 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-4096 characters. + Caption of the audio to be sent, 0-1024 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py index 3e5a0f5788..91dfc7d673 100644 --- a/pyrogram/types/input_media/input_media_document.py +++ b/pyrogram/types/input_media/input_media_document.py @@ -41,7 +41,7 @@ class InputMediaDocument(InputMedia): 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-4096 characters. + Caption of the document to be sent, 0-1024 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_photo.py b/pyrogram/types/input_media/input_media_photo.py index 178ee3d420..ce8b41a218 100644 --- a/pyrogram/types/input_media/input_media_photo.py +++ b/pyrogram/types/input_media/input_media_photo.py @@ -36,7 +36,7 @@ class InputMediaPhoto(InputMedia): pass an HTTP URL as a string for Telegram to get a photo from the Internet. caption (``str``, *optional*): - Caption of the photo to be sent, 0-4096 characters. + Caption of the photo to be sent, 0-1024 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py index 130129ab60..bad4e3ef3a 100644 --- a/pyrogram/types/input_media/input_media_video.py +++ b/pyrogram/types/input_media/input_media_video.py @@ -42,7 +42,7 @@ class InputMediaVideo(InputMedia): 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-4096 characters. + Caption of the video to be sent, 0-1024 characters. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 1ffdeafdb3..ab5e202f2a 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -177,7 +177,7 @@ class Message(Object, Update): Message is a video note, information about the video message. caption (``str``, *optional*): - Caption for the audio, document, photo, video or voice, 0-4096 characters. + Caption for the audio, document, photo, video or voice, 0-1024 characters. If the message contains caption entities (bold, italic, ...) you can access *caption.markdown* or *caption.html* to get the marked up caption text. In case there is no caption entity, the fields will contain the same text as *caption*. @@ -1022,7 +1022,7 @@ async def reply_animation( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Animation caption, 0-4096 characters. + Animation caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1161,7 +1161,7 @@ async def reply_audio( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Audio caption, 0-4096 characters. + Audio caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1292,7 +1292,7 @@ async def reply_cached_media( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``bool``, *optional*): - Media caption, 0-4096 characters. + Media caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1514,7 +1514,7 @@ async def reply_document( Thumbnails can't be reused and can be only uploaded as a new file. caption (``str``, *optional*): - Document caption, 0-4096 characters. + Document caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -1916,7 +1916,7 @@ async def reply_photo( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Photo caption, 0-4096 characters. + Photo caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -2387,7 +2387,7 @@ async def reply_video( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Video caption, 0-4096 characters. + Video caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -2651,7 +2651,7 @@ async def reply_voice( Defaults to ``True`` in group chats and ``False`` in private chats. caption (``str``, *optional*): - Voice message caption, 0-4096 characters. + Voice message caption, 0-1024 characters. parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): By default, texts are parsed using both Markdown and HTML styles. @@ -3007,7 +3007,7 @@ async def copy( For a contact that exists in your Telegram address book you can use his phone number (str). caption (``string``, *optional*): - New caption for media, 0-4096 characters after entities parsing. + New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept. Pass "" (empty string) to remove the caption. From 6fdf9a60f69800af00b676c8eb68b925bdf12f93 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 7 May 2022 12:04:22 +0200 Subject: [PATCH 286/539] Update example --- docs/source/faq/how-to-avoid-flood-waits.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/faq/how-to-avoid-flood-waits.rst b/docs/source/faq/how-to-avoid-flood-waits.rst index 0736e576f2..4d2994d1f4 100644 --- a/docs/source/faq/how-to-avoid-flood-waits.rst +++ b/docs/source/faq/how-to-avoid-flood-waits.rst @@ -16,7 +16,7 @@ The following shows how to catch the exception in your code and wait the require try: ... # Your code except FloodWait as e: - await asyncio.sleep(e.x) # Wait "x" seconds before continuing + await asyncio.sleep(e.value) # Wait "value" seconds before continuing ... From 8961da7a2ce0a68900d606d2fb23a3590502353a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 13 May 2022 11:56:42 +0200 Subject: [PATCH 287/539] Update API schema to Layer 142 --- compiler/api/source/main_api.tl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index cb4bf0ac1c..e28f715e64 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -103,7 +103,7 @@ userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#29562865 id:long = Chat; chat#41cbf256 flags:# creator:flags.0?true left:flags.2?true deactivated:flags.5?true call_active:flags.23?true call_not_empty:flags.24?true noforwards:flags.25?true id:long title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat; chatForbidden#6592a1a7 id:long title:string = Chat; -channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; +channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat; chatFull#d18ee226 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?Vector = ChatFull; @@ -392,9 +392,9 @@ photos.photo#20212ca8 photo:Photo users:Vector = photos.Photo; upload.file#96a18d5 type:storage.FileType mtime:int bytes:bytes = upload.File; upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes file_hashes:Vector = upload.File; -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; +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 this_port_only:flags.5?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; -config#330b4067 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 pfs_enabled:flags.13?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 pinned_infolder_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 base_lang_pack_version:flags.2?int = Config; +config#330b4067 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 pfs_enabled:flags.13?true force_try_ipv6:flags.14?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 pinned_infolder_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 base_lang_pack_version:flags.2?int = Config; nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc; @@ -852,7 +852,7 @@ phoneCallAccepted#3660c311 flags:# video:flags.6?true id:long access_hash:long d phoneCall#967f7c67 flags:# p2p_allowed:flags.5?true video:flags.6?true id:long access_hash:long date:int admin_id:long participant_id:long g_a_or_b:bytes key_fingerprint:long protocol:PhoneCallProtocol connections:Vector start_date:int = PhoneCall; phoneCallDiscarded#50ca4de1 flags:# need_rating:flags.2?true need_debug:flags.3?true video:flags.6?true id:long reason:flags.0?PhoneCallDiscardReason duration:flags.1?int = PhoneCall; -phoneConnection#9d4c17c0 id:long ip:string ipv6:string port:int peer_tag:bytes = PhoneConnection; +phoneConnection#9cc123c7 flags:# tcp:flags.0?true id:long ip:string ipv6:string port:int peer_tag:bytes = PhoneConnection; phoneConnectionWebrtc#635fe375 flags:# turn:flags.0?true stun:flags.1?true id:long ip:string ipv6:string port:int username:string password:string = PhoneConnection; phoneCallProtocol#fc878fc8 flags:# udp_p2p:flags.0?true udp_reflector:flags.1?true min_layer:int max_layer:int library_versions:Vector = PhoneCallProtocol; @@ -1205,7 +1205,7 @@ messages.messageViews#b6c4f543 views:Vector chats:Vector use messages.discussionMessage#a6341782 flags:# messages:Vector max_id:flags.0?int read_inbox_max_id:flags.1?int read_outbox_max_id:flags.2?int unread_count:int chats:Vector users:Vector = messages.DiscussionMessage; -messageReplyHeader#a6d57763 flags:# reply_to_msg_id:int reply_to_peer_id:flags.0?Peer reply_to_top_id:flags.1?int = MessageReplyHeader; +messageReplyHeader#a6d57763 flags:# reply_to_scheduled:flags.2?true reply_to_msg_id:int reply_to_peer_id:flags.0?Peer reply_to_top_id:flags.1?int = MessageReplyHeader; messageReplies#83d60fc2 flags:# comments:flags.0?true replies:int replies_pts:int recent_repliers:flags.1?Vector channel_id:flags.0?long max_id:flags.2?int read_max_id:flags.3?int = MessageReplies; @@ -1273,7 +1273,7 @@ account.resetPasswordFailedWait#e3779861 retry_date:int = account.ResetPasswordR account.resetPasswordRequestedWait#e9effc7d until_date:int = account.ResetPasswordResult; account.resetPasswordOk#e926d63e = account.ResetPasswordResult; -sponsoredMessage#3a836df8 flags:# random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage; +sponsoredMessage#3a836df8 flags:# recommended:flags.5?true random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage; messages.sponsoredMessages#65a4c7d5 messages:Vector chats:Vector users:Vector = messages.SponsoredMessages; @@ -1785,6 +1785,7 @@ phone.joinGroupCallPresentation#cbea6bc4 call:InputGroupCall params:DataJSON = U phone.leaveGroupCallPresentation#1c50d144 call:InputGroupCall = Updates; phone.getGroupCallStreamChannels#1ab21940 call:InputGroupCall = phone.GroupCallStreamChannels; phone.getGroupCallStreamRtmpUrl#deb3abbf peer:InputPeer revoke:Bool = phone.GroupCallStreamRtmpUrl; +phone.saveCallLog#41248786 peer:InputPhoneCall file:InputFile = Bool; langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference; langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector; @@ -1801,4 +1802,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 140 +// LAYER 142 \ No newline at end of file From 6e1425ada3790b3ade70bacf21d968582d3882bf Mon Sep 17 00:00:00 2001 From: DevOps117 <55235206+devops117@users.noreply.github.com> Date: Sat, 14 May 2022 12:28:30 +0530 Subject: [PATCH 288/539] Drop support for iterators where they are not needed (#969) * delete_messages: Drop support for generators Since we used a list there anyway, this approach will lead to more localized errors and can reduce function overhead. Signed-off-by: devops117 <55235206+devops117@users.noreply.github.com> * delete_messages: Return pts_count:int An example usecase would be for a normal bot which uses range based on message ids instead of keeping a track of messages and using the DeletedMessagesHandler. Signed-off-by: devops117 <55235206+devops117@users.noreply.github.com> * Drop support for Iterators and update docstrings and some cleanups. Signed-off-by: devops117 <55235206+devops117@users.noreply.github.com> * Update get_users.py * Update get_messages.py * Update delete_messages.py * Update forward_messages.py * Update get_messages.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/methods/contacts/delete_contacts.py | 9 +++---- pyrogram/methods/messages/delete_messages.py | 21 ++++++++------- pyrogram/methods/messages/forward_messages.py | 17 ++++++------ pyrogram/methods/messages/get_messages.py | 27 ++++++++++--------- pyrogram/methods/users/get_common_chats.py | 4 +-- pyrogram/methods/users/get_users.py | 20 +++++++------- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py index 31d2bcbec0..448e849a22 100644 --- a/pyrogram/methods/contacts/delete_contacts.py +++ b/pyrogram/methods/contacts/delete_contacts.py @@ -45,9 +45,9 @@ async def delete_contacts( await app.delete_contacts(user_id) await app.delete_contacts([user_id1, user_id2, user_id3]) """ - is_user_ids_list = isinstance(user_ids, list) + is_list = isinstance(user_ids, list) - if not is_user_ids_list: + if not is_list: user_ids = [user_ids] r = await self.invoke( @@ -61,7 +61,4 @@ async def delete_contacts( users = types.List([types.User._parse(self, i) for i in r.users]) - if is_user_ids_list: - return users - else: - return users[0] + return users if is_list else users[0] diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py index b25c0ad4d5..a07b36ddcf 100644 --- a/pyrogram/methods/messages/delete_messages.py +++ b/pyrogram/methods/messages/delete_messages.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union, Iterable +from typing import Union, List import pyrogram from pyrogram import raw @@ -26,9 +26,9 @@ class DeleteMessages: async def delete_messages( self: "pyrogram.Client", chat_id: Union[int, str], - message_ids: Union[int, Iterable[int]], + message_ids: Union[int, List[int]], revoke: bool = True - ) -> bool: + ) -> int: """Delete messages, including service messages. Parameters: @@ -37,9 +37,8 @@ async def delete_messages( 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). - message_ids (``int`` | ``Iterable[int]``): + message_ids (``int`` | List of ``int``): A list of Message identifiers to delete (integers) or a single message id. - Iterators and Generators are also accepted. revoke (``bool``, *optional*): Deletes messages on both parts. @@ -48,7 +47,7 @@ async def delete_messages( Defaults to True. Returns: - ``bool``: True on success, False otherwise. + ``int``: Amount of affected messages Example: .. code-block:: python @@ -63,7 +62,9 @@ async def delete_messages( await app.delete_messages(chat_id, message_id, revoke=False) """ peer = await self.resolve_peer(chat_id) - message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] + # Follow type annotation of the raw function "DeleteMessage". + if not isinstance(message_ids, list): + message_ids = [message_ids] if isinstance(peer, raw.types.InputPeerChannel): r = await self.invoke( @@ -76,10 +77,10 @@ async def delete_messages( r = await self.invoke( raw.functions.messages.DeleteMessages( id=message_ids, - revoke=revoke or None + revoke=revoke or None # Follow the type annotation. ) ) - # Deleting messages you don't have right onto, won't raise any error. + # Deleting messages you don't have right onto won't raise any error. # Check for pts_count, which is 0 in case deletes fail. - return bool(r.pts_count) + return r.pts_count diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py index 6ee8492294..2e2882532b 100644 --- a/pyrogram/methods/messages/forward_messages.py +++ b/pyrogram/methods/messages/forward_messages.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from datetime import datetime -from typing import Union, Iterable, List +from typing import Union, List import pyrogram from pyrogram import raw, utils @@ -29,7 +29,7 @@ async def forward_messages( self: "pyrogram.Client", chat_id: Union[int, str], from_chat_id: Union[int, str], - message_ids: Union[int, Iterable[int]], + message_ids: Union[int, List[int]], disable_notification: bool = None, schedule_date: datetime = None, protect_content: bool = None @@ -49,7 +49,6 @@ async def forward_messages( message_ids (``int`` | List of ``int``): A list of Message identifiers in the chat specified in *from_chat_id* or a single message id. - Iterators and Generators are also accepted. disable_notification (``bool``, *optional*): Sends the message silently. @@ -62,9 +61,8 @@ async def forward_messages( Protects the contents of the sent message from forwarding and saving. Returns: - :obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was an - integer, the single forwarded message is returned, otherwise, in case *message_ids* was an iterable, - the returned value will be a list of messages, even if such iterable contained just a single element. + :obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was not + a list, a single message is returned, otherwise a list of messages is returned. Example: .. code-block:: python @@ -76,8 +74,9 @@ async def forward_messages( await app.forward_messages(to_chat, from_chat, [1, 2, 3]) """ - is_iterable = not isinstance(message_ids, int) - message_ids = list(message_ids) if is_iterable else [message_ids] + is_list = isinstance(message_ids, list) + if not is_list: + message_ids = [message_ids] r = await self.invoke( raw.functions.messages.ForwardMessages( @@ -107,4 +106,4 @@ async def forward_messages( ) ) - return types.List(forwarded_messages) if is_iterable else forwarded_messages[0] + return types.List(forwarded_messages) if is_list else forwarded_messages[0] diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index 8db24dd955..ce38b2322f 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . import logging -from typing import Union, Iterable, List +from typing import Union, List import pyrogram from pyrogram import raw @@ -34,8 +34,8 @@ class GetMessages: async def get_messages( self: "pyrogram.Client", chat_id: Union[int, str], - message_ids: Union[int, Iterable[int]] = None, - reply_to_message_ids: Union[int, Iterable[int]] = None, + message_ids: Union[int, List[int]] = None, + reply_to_message_ids: Union[int, List[int]] = None, replies: int = 1 ) -> Union["types.Message", List["types.Message"]]: """Get one or more messages from a chat by using message identifiers. @@ -48,13 +48,13 @@ async def get_messages( 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). - message_ids (``iterable``, *optional*): + message_ids (``int`` | List of ``int``, *optional*): Pass a single message identifier or a list of message ids (as integers) to get the content of the - message themselves. Iterators and Generators are also accepted. + message themselves. - reply_to_message_ids (``iterable``, *optional*): + reply_to_message_ids (``int`` | List of ``int``, *optional*): Pass a single message identifier or a list of message ids (as integers) to get the content of - the previous message you replied to using this message. Iterators and Generators are also accepted. + the previous message you replied to using this message. If *message_ids* is set, this argument will be ignored. replies (``int``, *optional*): @@ -63,9 +63,8 @@ async def get_messages( Defaults to 1. Returns: - :obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was an - integer, the single requested message is returned, otherwise, in case *message_ids* was an iterable, the - returned value will be a list of messages, even if such iterable contained just a single element. + :obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was not + a list, a single message is returned, otherwise a list of messages is returned. Example: .. code-block:: python @@ -99,8 +98,10 @@ async def get_messages( peer = await self.resolve_peer(chat_id) - is_iterable = not isinstance(ids, int) - ids = list(ids) if is_iterable else [ids] + is_list = isinstance(ids, list) + if not is_list: + ids = [ids] + ids = [ids_type(id=i) for i in ids] if replies < 0: @@ -115,4 +116,4 @@ async def get_messages( messages = await utils.parse_messages(self, r, replies=replies) - return messages if is_iterable else messages[0] if messages else None + return messages if is_list else messages[0] diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py index 7269a81ed7..a45bda6f4c 100644 --- a/pyrogram/methods/users/get_common_chats.py +++ b/pyrogram/methods/users/get_common_chats.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union +from typing import Union, List import pyrogram from pyrogram import raw @@ -27,7 +27,7 @@ class GetCommonChats: async def get_common_chats( self: "pyrogram.Client", user_id: Union[int, str] - ) -> list: + ) -> List["types.Chat"]: """Get the common chats you have with a user. Parameters: diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py index caef79663f..c3f93d98fd 100644 --- a/pyrogram/methods/users/get_users.py +++ b/pyrogram/methods/users/get_users.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . import asyncio -from typing import Iterable, Union, List +from typing import Union, List import pyrogram from pyrogram import raw @@ -27,21 +27,19 @@ class GetUsers: async def get_users( self: "pyrogram.Client", - user_ids: Union[Iterable[Union[int, str]], int, str] + user_ids: Union[int, str, List[Union[int, str]]] ) -> Union["types.User", List["types.User"]]: """Get information about a user. You can retrieve up to 200 users at once. Parameters: - user_ids (``iterable``): + user_ids (``int`` | ``str`` | List of ``int`` or ``str``): A list of User identifiers (id or username) or a single user id/username. For a contact that exists in your Telegram address book you can use his phone number (str). - Iterators and Generators are also accepted. Returns: - :obj:`~pyrogram.types.User` | List of :obj:`~pyrogram.types.User`: In case *user_ids* was an integer or - string the single requested user is returned, otherwise, in case *user_ids* was an iterable a list of users - is returned, even if the iterable contained one item only. + :obj:`~pyrogram.types.User` | List of :obj:`~pyrogram.types.User`: In case *user_ids* was not a list, + a single user is returned, otherwise a list of users is returned. Example: .. code-block:: python @@ -52,8 +50,10 @@ async def get_users( # Get information about multiple users at once await app.get_users([user_id1, user_id2, user_id3]) """ - is_iterable = not isinstance(user_ids, (int, str)) - user_ids = list(user_ids) if is_iterable else [user_ids] + is_list = isinstance(user_ids, list) + if not is_list: + user_ids = [user_ids] + user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids]) r = await self.invoke( @@ -67,4 +67,4 @@ async def get_users( for i in r: users.append(types.User._parse(self, i)) - return users if is_iterable else users[0] + return users if is_list else users[0] From 9c441ff16dbc536c36c34ab496c256d164b57164 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 11:22:06 +0200 Subject: [PATCH 289/539] Update Pyrogram to v2.0.20 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 0be47e5f44..c9c190745e 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.19" +__version__ = "2.0.20" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 7c3c0565b4a0ae26ce80b6c42033d34fa60309ea Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 17:29:11 +0200 Subject: [PATCH 290/539] Fix wrapped function invocations --- 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 ff195b96ec..2e90184a2c 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -351,9 +351,11 @@ async def invoke( pass if isinstance(query, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): - query = query.query + inner_query = query.query + else: + inner_query = query - query_name = ".".join(query.QUALNAME.split(".")[1:]) + query_name = ".".join(inner_query.QUALNAME.split(".")[1:]) while True: try: From 050a7304bac775fe6d6a2d13ced60a17d267e615 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 17:29:55 +0200 Subject: [PATCH 291/539] Update Pyrogram to v2.0.21 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c9c190745e..d1f66bf124 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.20" +__version__ = "2.0.21" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From d984ae24d5d878276c23fc44ae94005d1b504af3 Mon Sep 17 00:00:00 2001 From: leonardotty <81367045+leonardotty@users.noreply.github.com> Date: Sat, 14 May 2022 19:28:44 +0200 Subject: [PATCH 292/539] Add missing parameter to send_reaction (#993) --- pyrogram/methods/messages/send_reaction.py | 10 ++++++++-- pyrogram/types/messages_and_media/message.py | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py index 7f597cb626..1ede4ead79 100644 --- a/pyrogram/methods/messages/send_reaction.py +++ b/pyrogram/methods/messages/send_reaction.py @@ -27,7 +27,8 @@ async def send_reaction( self: "pyrogram.Client", chat_id: Union[int, str], message_id: int, - emoji: str = "" + emoji: str = "", + big: bool = False ) -> bool: """Send a reaction to a message. @@ -41,6 +42,10 @@ async def send_reaction( emoji (``str``, *optional*): Reaction emoji. Pass "" as emoji (default) to retract the reaction. + + big (``bool``, *optional*): + Pass True to show a bigger and longer reaction. + Defaults to False. Returns: ``bool``: On success, True is returned. @@ -58,7 +63,8 @@ async def send_reaction( raw.functions.messages.SendReaction( peer=await self.resolve_peer(chat_id), msg_id=message_id, - reaction=emoji + reaction=emoji, + big=big ) ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index ab5e202f2a..f742970210 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3310,7 +3310,7 @@ async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None, else: await self.reply(button, quote=quote) - async def react(self, emoji: str = "") -> bool: + async def react(self, emoji: str = "", big: bool = False) -> bool: """Bound method *react* of :obj:`~pyrogram.types.Message`. Use as a shortcut for: @@ -3332,6 +3332,10 @@ async def react(self, emoji: str = "") -> bool: emoji (``str``, *optional*): Reaction emoji. Pass "" as emoji (default) to retract the reaction. + + big (``bool``, *optional*): + Pass True to show a bigger and longer reaction. + Defaults to False. Returns: ``bool``: On success, True is returned. @@ -3343,7 +3347,8 @@ async def react(self, emoji: str = "") -> bool: return await self._client.send_reaction( chat_id=self.chat.id, message_id=self.id, - emoji=emoji + emoji=emoji, + big=big ) async def retract_vote( From 15bfaed254916aa7a85f77412ae2a85bee1ec6d1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 19:29:52 +0200 Subject: [PATCH 293/539] Update Pyrogram to v2.0.22 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index d1f66bf124..86b973b059 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.21" +__version__ = "2.0.22" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ff90baffb3cc90cac971ff35f9cd46a1175abb3d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 21:12:37 +0200 Subject: [PATCH 294/539] Fix get_messages and usages --- pyrogram/methods/messages/get_messages.py | 2 +- pyrogram/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index ce38b2322f..f44b3b2f4c 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -116,4 +116,4 @@ async def get_messages( messages = await utils.parse_messages(self, r, replies=replies) - return messages if is_list else messages[0] + return messages if is_list else messages[0] if messages else None diff --git a/pyrogram/utils.py b/pyrogram/utils.py index d5862d1a67..bd000d949c 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -113,7 +113,7 @@ async def parse_messages(client, messages: "raw.types.messages.Messages", replie reply_messages = await client.get_messages( chat_id, - reply_to_message_ids=messages_with_replies.keys(), + reply_to_message_ids=list(messages_with_replies.keys()), replies=replies - 1 ) From 427738d02ab04d5c98002f16b33cfba135d2d24b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 May 2022 21:12:54 +0200 Subject: [PATCH 295/539] Update Pyrogram to v2.0.23 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 86b973b059..2d00a75960 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.22" +__version__ = "2.0.23" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 5681ccefe1de84047fa57bbb418afc60f7c9df2e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 May 2022 14:24:59 +0200 Subject: [PATCH 296/539] Add back the ability to pass iterators to some methods --- pyrogram/methods/messages/delete_messages.py | 16 +++++--------- pyrogram/methods/messages/forward_messages.py | 15 ++++++------- pyrogram/methods/messages/get_messages.py | 22 +++++++++---------- pyrogram/methods/users/get_users.py | 13 +++++------ pyrogram/utils.py | 2 +- 5 files changed, 30 insertions(+), 38 deletions(-) diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py index a07b36ddcf..523ecd544c 100644 --- a/pyrogram/methods/messages/delete_messages.py +++ b/pyrogram/methods/messages/delete_messages.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union, List +from typing import Union, Iterable import pyrogram from pyrogram import raw @@ -26,7 +26,7 @@ class DeleteMessages: async def delete_messages( self: "pyrogram.Client", chat_id: Union[int, str], - message_ids: Union[int, List[int]], + message_ids: Union[int, Iterable[int]], revoke: bool = True ) -> int: """Delete messages, including service messages. @@ -37,8 +37,8 @@ async def delete_messages( 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). - message_ids (``int`` | List of ``int``): - A list of Message identifiers to delete (integers) or a single message id. + message_ids (``int`` | Iterable of ``int``): + An iterable of message identifiers to delete (integers) or a single message id. revoke (``bool``, *optional*): Deletes messages on both parts. @@ -62,9 +62,7 @@ async def delete_messages( await app.delete_messages(chat_id, message_id, revoke=False) """ peer = await self.resolve_peer(chat_id) - # Follow type annotation of the raw function "DeleteMessage". - if not isinstance(message_ids, list): - message_ids = [message_ids] + message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] if isinstance(peer, raw.types.InputPeerChannel): r = await self.invoke( @@ -77,10 +75,8 @@ async def delete_messages( r = await self.invoke( raw.functions.messages.DeleteMessages( id=message_ids, - revoke=revoke or None # Follow the type annotation. + revoke=revoke ) ) - # Deleting messages you don't have right onto won't raise any error. - # Check for pts_count, which is 0 in case deletes fail. return r.pts_count diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py index 2e2882532b..be7b2ab5ef 100644 --- a/pyrogram/methods/messages/forward_messages.py +++ b/pyrogram/methods/messages/forward_messages.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from datetime import datetime -from typing import Union, List +from typing import Union, List, Iterable import pyrogram from pyrogram import raw, utils @@ -29,7 +29,7 @@ async def forward_messages( self: "pyrogram.Client", chat_id: Union[int, str], from_chat_id: Union[int, str], - message_ids: Union[int, List[int]], + message_ids: Union[int, Iterable[int]], disable_notification: bool = None, schedule_date: datetime = None, protect_content: bool = None @@ -47,8 +47,8 @@ async def forward_messages( 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). - message_ids (``int`` | List of ``int``): - A list of Message identifiers in the chat specified in *from_chat_id* or a single message id. + message_ids (``int`` | Iterable of ``int``): + An iterable of message identifiers in the chat specified in *from_chat_id* or a single message id. disable_notification (``bool``, *optional*): Sends the message silently. @@ -74,9 +74,8 @@ async def forward_messages( await app.forward_messages(to_chat, from_chat, [1, 2, 3]) """ - is_list = isinstance(message_ids, list) - if not is_list: - message_ids = [message_ids] + is_iterable = not isinstance(message_ids, int) + message_ids = list(message_ids) if is_iterable else [message_ids] r = await self.invoke( raw.functions.messages.ForwardMessages( @@ -106,4 +105,4 @@ async def forward_messages( ) ) - return types.List(forwarded_messages) if is_list else forwarded_messages[0] + return types.List(forwarded_messages) if is_iterable else forwarded_messages[0] diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index f44b3b2f4c..17d80e58a6 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . import logging -from typing import Union, List +from typing import Union, List, Iterable import pyrogram from pyrogram import raw @@ -34,8 +34,8 @@ class GetMessages: async def get_messages( self: "pyrogram.Client", chat_id: Union[int, str], - message_ids: Union[int, List[int]] = None, - reply_to_message_ids: Union[int, List[int]] = None, + message_ids: Union[int, Iterable[int]] = None, + reply_to_message_ids: Union[int, Iterable[int]] = None, replies: int = 1 ) -> Union["types.Message", List["types.Message"]]: """Get one or more messages from a chat by using message identifiers. @@ -48,12 +48,12 @@ async def get_messages( 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). - message_ids (``int`` | List of ``int``, *optional*): - Pass a single message identifier or a list of message ids (as integers) to get the content of the + message_ids (``int`` | Iterable of ``int``, *optional*): + Pass a single message identifier or an iterable of message ids (as integers) to get the content of the message themselves. - reply_to_message_ids (``int`` | List of ``int``, *optional*): - Pass a single message identifier or a list of message ids (as integers) to get the content of + reply_to_message_ids (``int`` | Iterable of ``int``, *optional*): + Pass a single message identifier or an iterable of message ids (as integers) to get the content of the previous message you replied to using this message. If *message_ids* is set, this argument will be ignored. @@ -98,10 +98,8 @@ async def get_messages( peer = await self.resolve_peer(chat_id) - is_list = isinstance(ids, list) - if not is_list: - ids = [ids] - + is_iterable = not isinstance(ids, int) + ids = list(ids) if is_iterable else [ids] ids = [ids_type(id=i) for i in ids] if replies < 0: @@ -116,4 +114,4 @@ async def get_messages( messages = await utils.parse_messages(self, r, replies=replies) - return messages if is_list else messages[0] if messages else None + return messages if is_iterable else messages[0] if messages else None diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py index c3f93d98fd..384dded0af 100644 --- a/pyrogram/methods/users/get_users.py +++ b/pyrogram/methods/users/get_users.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . import asyncio -from typing import Union, List +from typing import Union, List, Iterable import pyrogram from pyrogram import raw @@ -27,13 +27,13 @@ class GetUsers: async def get_users( self: "pyrogram.Client", - user_ids: Union[int, str, List[Union[int, str]]] + user_ids: Union[int, str, Iterable[Union[int, str]]] ) -> Union["types.User", List["types.User"]]: """Get information about a user. You can retrieve up to 200 users at once. Parameters: - user_ids (``int`` | ``str`` | List of ``int`` or ``str``): + user_ids (``int`` | ``str`` | Iterable of ``int`` or ``str``): A list of User identifiers (id or username) or a single user id/username. For a contact that exists in your Telegram address book you can use his phone number (str). @@ -50,10 +50,9 @@ async def get_users( # Get information about multiple users at once await app.get_users([user_id1, user_id2, user_id3]) """ - is_list = isinstance(user_ids, list) - if not is_list: - user_ids = [user_ids] + is_iterable = not isinstance(user_ids, (int, str)) + user_ids = list(user_ids) if is_iterable else [user_ids] user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids]) r = await self.invoke( @@ -67,4 +66,4 @@ async def get_users( for i in r: users.append(types.User._parse(self, i)) - return users if is_list else users[0] + return users if is_iterable else users[0] diff --git a/pyrogram/utils.py b/pyrogram/utils.py index bd000d949c..d5862d1a67 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -113,7 +113,7 @@ async def parse_messages(client, messages: "raw.types.messages.Messages", replie reply_messages = await client.get_messages( chat_id, - reply_to_message_ids=list(messages_with_replies.keys()), + reply_to_message_ids=messages_with_replies.keys(), replies=replies - 1 ) From f6283757e14fce1d2edd19dd8bd29b7b73e6b3de Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 May 2022 14:26:12 +0200 Subject: [PATCH 297/539] Add sequential parameter to compose() --- pyrogram/methods/utilities/compose.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pyrogram/methods/utilities/compose.py b/pyrogram/methods/utilities/compose.py index c8bdf76956..cfc5ca3e61 100644 --- a/pyrogram/methods/utilities/compose.py +++ b/pyrogram/methods/utilities/compose.py @@ -16,13 +16,17 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import asyncio from typing import List import pyrogram from .idle import idle -async def compose(clients: List["pyrogram.Client"]): +async def compose( + clients: List["pyrogram.Client"], + sequential: bool = False +): """Run multiple clients at once. This method can be used to run multiple clients at once and can be found directly in the ``pyrogram`` package. @@ -33,6 +37,10 @@ async def compose(clients: List["pyrogram.Client"]): clients (List of :obj:`~pyrogram.Client`): A list of client objects to run. + sequential (``bool``, *optional*): + Pass True to run clients sequentially. + Defaults to False (run clients concurrently) + Example: .. code-block:: python @@ -53,10 +61,16 @@ async def main(): asyncio.run(main()) """ - for c in clients: - await c.start() + if sequential: + for c in clients: + await c.start() + else: + await asyncio.gather(*[c.start() for c in clients]) await idle() - for c in clients: - await c.stop() + if sequential: + for c in clients: + await c.stop() + else: + await asyncio.gather(*[c.stop() for c in clients]) From 644dd55393c49e34cb894cb68ab24e4ff5ac6551 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 15 May 2022 14:26:58 +0200 Subject: [PATCH 298/539] Update Pyrogram to v2.0.24 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2d00a75960..c96c574c64 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.23" +__version__ = "2.0.24" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 6974d97fb4112a8662c9f311ba4cc281c1e27aa9 Mon Sep 17 00:00:00 2001 From: Gaung Ramadhan Date: Wed, 25 May 2022 15:56:55 +0700 Subject: [PATCH 299/539] Fix type hint of User.status (#998) --- pyrogram/types/user_and_chats/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py index 666c72675d..8860784d8d 100644 --- a/pyrogram/types/user_and_chats/user.py +++ b/pyrogram/types/user_and_chats/user.py @@ -158,7 +158,7 @@ def __init__( is_support: bool = None, first_name: str = None, last_name: str = None, - status: str = None, + status: "enums.UserStatus" = None, last_online_date: datetime = None, next_offline_date: datetime = None, username: str = None, From f7c678855d051e69974d50318bdcb30526ccdfcf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 25 May 2022 10:58:32 +0200 Subject: [PATCH 300/539] Update Pyrogram to v2.0.25 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c96c574c64..a435d23820 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.24" +__version__ = "2.0.25" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From c5958fc0c43190b0bf6fd72188373e97ab02ce25 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 May 2022 11:30:20 +0200 Subject: [PATCH 301/539] Fix offset_date not being an integer timestamp Closes #1003 --- pyrogram/methods/messages/search_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py index 1a65702e01..5e54a965c8 100644 --- a/pyrogram/methods/messages/search_global.py +++ b/pyrogram/methods/messages/search_global.py @@ -102,7 +102,7 @@ async def search_global( last = messages[-1] - offset_date = last.date + offset_date = utils.datetime_to_timestamp(last.date) offset_peer = await self.resolve_peer(last.chat.id) offset_id = last.id From ba3104fd53e1397ec626511ec96aa7da725c8e0b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 May 2022 11:30:41 +0200 Subject: [PATCH 302/539] Update Pyrogram to v2.0.26 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a435d23820..c376cbb376 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.25" +__version__ = "2.0.26" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From edf5e9863f7a20c3be2c02ef83d5d14b39ef617d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:46:22 +0200 Subject: [PATCH 303/539] Update FAQ --- .../socket-send-raised-exception-oserror-timeouterror.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst index 21ee1a900c..4d9aa89de9 100644 --- a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst +++ b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst @@ -1,9 +1,10 @@ socket.send() raised exception, OSError(), TimeoutError() ========================================================= -If you get this error chances are you are blocking the event loop for too long, most likely due to an improper use of -non-asynchronous or threaded operations which may lead to blocking code that prevents the event loop from running -properly. +If you get this error chances are you or Telegram ended up with a slow or inconsistent network connection, which +triggers internal timeouts due to data not being sent/received in time. Another reason could be because you are blocking +the event loop for too long, most likely due to an improper use of non-asynchronous or threaded operations which may +lead to blocking code that prevents the event loop from running properly. You can consider the following: From a1bdcd672ea9331fef4bcee49a50052cf8b11fee Mon Sep 17 00:00:00 2001 From: Prashant Sengar <45726744+prashantsengar@users.noreply.github.com> Date: Mon, 6 Jun 2022 22:17:15 +0530 Subject: [PATCH 304/539] Fix type of "has_protected_content" (#994) `has_protected_content` attribute of Message class was assigned the wrong type in the docstring (str), corrected it to `bool` --- pyrogram/types/messages_and_media/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index f742970210..56e4d7feec 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -133,7 +133,7 @@ class Message(Object, Update): Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. - has_protected_content (``str``, *optional*): + has_protected_content (``bool``, *optional*): True, if the message can't be forwarded. text (``str``, *optional*): From 37e0015463216a212b6417248a89c9133052ad07 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:47:51 +0200 Subject: [PATCH 305/539] Update Pyrogram to v2.0.27 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c376cbb376..6e562ce075 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.26" +__version__ = "2.0.27" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 7f9e841ccd44246ad855ad4855a6431a5823c554 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 14 Jun 2022 16:55:19 +0200 Subject: [PATCH 306/539] Update API schema to Layer 143 --- compiler/api/source/main_api.tl | 81 ++++++++++++++++++--------- pyrogram/types/user_and_chats/user.py | 6 ++ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index e28f715e64..3f44fe0fbe 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -88,7 +88,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType; storage.fileWebp#1081464c = storage.FileType; userEmpty#d3bc4b7a id:long = User; -user#3ff6ecb0 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; +user#3ff6ecb0 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; userProfilePhoto#82d1f706 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto; @@ -128,7 +128,7 @@ messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; messageMediaContact#70322949 phone_number:string first_name:string last_name:string vcard:string user_id:long = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; -messageMediaDocument#9cb070d7 flags:# document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; +messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia; messageMediaGame#fdb19008 game:Game = MessageMedia; @@ -151,8 +151,8 @@ messageActionChannelMigrateFrom#ea3948e9 title:string chat_id:long = MessageActi messageActionPinMessage#94bd38ed = MessageAction; messageActionHistoryClear#9fbab604 = MessageAction; messageActionGameScore#92a72876 game_id:long score:int = MessageAction; -messageActionPaymentSentMe#8f31b327 flags:# currency:string total_amount:long payload:bytes info:flags.0?PaymentRequestedInfo shipping_option_id:flags.1?string charge:PaymentCharge = MessageAction; -messageActionPaymentSent#40699cd0 currency:string total_amount:long = MessageAction; +messageActionPaymentSentMe#8f31b327 flags:# recurring_init:flags.2?true recurring_used:flags.3?true currency:string total_amount:long payload:bytes info:flags.0?PaymentRequestedInfo shipping_option_id:flags.1?string charge:PaymentCharge = MessageAction; +messageActionPaymentSent#96163f56 flags:# recurring_init:flags.2?true recurring_used:flags.3?true currency:string total_amount:long invoice_slug:flags.0?string = MessageAction; messageActionPhoneCall#80e11a7f flags:# video:flags.2?true call_id:long reason:flags.0?PhoneCallDiscardReason duration:flags.1?int = MessageAction; messageActionScreenshotTaken#4792929b = MessageAction; messageActionCustomAction#fae69f56 message:string = MessageAction; @@ -368,6 +368,7 @@ updateAttachMenuBots#17b7a20b = Update; updateWebViewResultSent#1592b79d query_id:long = Update; updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update; updateSavedRingtones#74d8be99 = Update; +updateTranscribedAudio#84cd5a flags:# pending:flags.0?true peer:Peer msg_id:int transcription_id:long text:string = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -412,7 +413,7 @@ encryptedChatDiscarded#1e1c7c45 flags:# history_deleted:flags.0?true id:int = En inputEncryptedChat#f141b5e1 chat_id:int access_hash:long = InputEncryptedChat; encryptedFileEmpty#c21f497e = EncryptedFile; -encryptedFile#4a70994c id:long access_hash:long size:int dc_id:int key_fingerprint:int = EncryptedFile; +encryptedFile#a8008cd8 id:long access_hash:long size:long dc_id:int key_fingerprint:int = EncryptedFile; inputEncryptedFileEmpty#1837c364 = InputEncryptedFile; inputEncryptedFileUploaded#64bd0306 id:long parts:int md5_checksum:string key_fingerprint:int = InputEncryptedFile; @@ -432,7 +433,7 @@ inputDocumentEmpty#72f0eaae = InputDocument; inputDocument#1abfb575 id:long access_hash:long file_reference:bytes = InputDocument; documentEmpty#36f8c871 id:long = Document; -document#1e87342b flags:# id:long access_hash:long file_reference:bytes date:int mime_type:string size:int thumbs:flags.0?Vector video_thumbs:flags.1?Vector dc_id:int attributes:Vector = Document; +document#8fd4c4d8 flags:# id:long access_hash:long file_reference:bytes date:int mime_type:string size:long thumbs:flags.0?Vector video_thumbs:flags.1?Vector dc_id:int attributes:Vector = Document; help.support#17c6b5f6 phone_number:string user:User = help.Support; @@ -540,6 +541,7 @@ auth.passwordRecovery#137948a5 email_pattern:string = auth.PasswordRecovery; receivedNotifyMessage#a384b779 id:int flags:int = ReceivedNotifyMessage; chatInviteExported#ab4a819 flags:# revoked:flags.0?true permanent:flags.5?true request_needed:flags.6?true link:string admin_id:long date:int start_date:flags.4?int expire_date:flags.1?int usage_limit:flags.2?int usage:flags.3?int requested:flags.7?int title:flags.8?string = ExportedChatInvite; +chatInvitePublicJoinRequests#ed107ab7 = ExportedChatInvite; chatInviteAlready#5a686d7c chat:Chat = ChatInvite; chatInvite#300c44c1 flags:# channel:flags.0?true broadcast:flags.1?true public:flags.2?true megagroup:flags.3?true request_needed:flags.6?true title:string about:flags.5?string photo:Photo participants_count:int participants:flags.4?Vector = ChatInvite; @@ -559,7 +561,7 @@ messages.stickerSetNotModified#d3f924eb = messages.StickerSet; botCommand#c27ac8c7 command:string description:string = BotCommand; -botInfo#e4169b5d user_id:long description:string commands:Vector menu_button:BotMenuButton = BotInfo; +botInfo#8f300b57 flags:# user_id:flags.0?long description:flags.1?string description_photo:flags.4?Photo description_document:flags.5?Document commands:flags.2?Vector menu_button:flags.3?BotMenuButton = BotInfo; keyboardButton#a2fa4880 text:string = KeyboardButton; keyboardButtonUrl#258aff05 text:string url:string = KeyboardButton; @@ -801,7 +803,7 @@ dataJSON#7d748d04 data:string = DataJSON; labeledPrice#cb296bf8 label:string amount:long = LabeledPrice; -invoice#cd886e0 flags:# test:flags.0?true name_requested:flags.1?true phone_requested:flags.2?true email_requested:flags.3?true shipping_address_requested:flags.4?true flexible:flags.5?true phone_to_provider:flags.6?true email_to_provider:flags.7?true currency:string prices:Vector max_tip_amount:flags.8?long suggested_tip_amounts:flags.8?Vector = Invoice; +invoice#3e85a91b flags:# test:flags.0?true name_requested:flags.1?true phone_requested:flags.2?true email_requested:flags.3?true shipping_address_requested:flags.4?true flexible:flags.5?true phone_to_provider:flags.6?true email_to_provider:flags.7?true recurring:flags.9?true currency:string prices:Vector max_tip_amount:flags.8?long suggested_tip_amounts:flags.8?Vector recurring_terms_url:flags.9?string = Invoice; paymentCharge#ea02c27e id:string provider_charge_id:string = PaymentCharge; @@ -821,7 +823,7 @@ inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile; -payments.paymentForm#1694761b flags:# can_save_credentials:flags.2?true password_missing:flags.3?true form_id:long bot_id:long invoice:Invoice provider_id:long url:string native_provider:flags.4?string native_params:flags.4?DataJSON saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?PaymentSavedCredentials users:Vector = payments.PaymentForm; +payments.paymentForm#b0133b37 flags:# can_save_credentials:flags.2?true password_missing:flags.3?true form_id:long bot_id:long title:string description:string photo:flags.5?WebDocument invoice:Invoice provider_id:long url:string native_provider:flags.4?string native_params:flags.4?DataJSON saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?PaymentSavedCredentials users:Vector = payments.PaymentForm; payments.validatedRequestedInfo#d1451883 flags:# id:flags.0?string shipping_options:flags.1?Vector = payments.ValidatedRequestedInfo; @@ -950,7 +952,7 @@ dialogPeerFolder#514519e2 folder_id:int = DialogPeer; messages.foundStickerSetsNotModified#d54b65d = messages.FoundStickerSets; messages.foundStickerSets#8af09dd2 hash:long sets:Vector = messages.FoundStickerSets; -fileHash#6242c773 offset:int limit:int hash:bytes = FileHash; +fileHash#f39b035c offset:long limit:int hash:bytes = FileHash; inputClientProxy#75588b3f address:string port:int = InputClientProxy; @@ -961,7 +963,7 @@ inputSecureFileUploaded#3334b0f0 id:long parts:int md5_checksum:string file_hash inputSecureFile#5367e5be id:long access_hash:long = InputSecureFile; secureFileEmpty#64199744 = SecureFile; -secureFile#e0277a62 id:long access_hash:long size:int dc_id:int date:int file_hash:bytes secret:bytes = SecureFile; +secureFile#7d09c27e id:long access_hash:long size:long dc_id:int date:int file_hash:bytes secret:bytes = SecureFile; secureData#8aeabec3 data:bytes data_hash:bytes secret:bytes = SecureData; @@ -1088,7 +1090,7 @@ codeSettings#8a6469c2 flags:# allow_flashcall:flags.0?true current_number:flags. wallPaperSettings#1dc1bca4 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int = WallPaperSettings; -autoDownloadSettings#e04232f3 flags:# disabled:flags.0?true video_preload_large:flags.1?true audio_preload_next:flags.2?true phonecalls_less_data:flags.3?true photo_size_max:int video_size_max:int file_size_max:int video_upload_maxbitrate:int = AutoDownloadSettings; +autoDownloadSettings#8efab953 flags:# disabled:flags.0?true video_preload_large:flags.1?true audio_preload_next:flags.2?true phonecalls_less_data:flags.3?true photo_size_max:int video_size_max:long file_size_max:long video_upload_maxbitrate:int = AutoDownloadSettings; account.autoDownloadSettings#63cacf26 low:AutoDownloadSettings medium:AutoDownloadSettings high:AutoDownloadSettings = account.AutoDownloadSettings; @@ -1160,6 +1162,7 @@ bankCardOpenUrl#f568028a url:string name:string = BankCardOpenUrl; payments.bankCardData#3e24e573 title:string open_urls:Vector = payments.BankCardData; dialogFilter#7438f7e8 flags:# contacts:flags.0?true non_contacts:flags.1?true groups:flags.2?true broadcasts:flags.3?true bots:flags.4?true exclude_muted:flags.11?true exclude_read:flags.12?true exclude_archived:flags.13?true id:int title:string emoticon:flags.25?string pinned_peers:Vector include_peers:Vector exclude_peers:Vector = DialogFilter; +dialogFilterDefault#363293ae = DialogFilter; dialogFilterSuggested#77744d4a filter:DialogFilter description:string = DialogFilterSuggested; @@ -1299,7 +1302,7 @@ messageReactions#4f2b9479 flags:# min:flags.0?true can_see_list:flags.2?true res messages.messageReactionsList#31bd492d flags:# count:int reactions:Vector chats:Vector users:Vector next_offset:flags.0?string = messages.MessageReactionsList; -availableReaction#c077ec01 flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction; +availableReaction#c077ec01 flags:# inactive:flags.0?true premium:flags.2?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction; messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions; messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions; @@ -1319,7 +1322,7 @@ attachMenuBotIconColor#4576f3f0 name:string color:int = AttachMenuBotIconColor; attachMenuBotIcon#b2a7386b flags:# name:string icon:Document colors:flags.0?Vector = AttachMenuBotIcon; -attachMenuBot#e93cb772 flags:# inactive:flags.0?true bot_id:long short_name:string icons:Vector = AttachMenuBot; +attachMenuBot#c8aa2cd2 flags:# inactive:flags.0?true has_settings:flags.1?true bot_id:long short_name:string peer_types:Vector icons:Vector = AttachMenuBot; attachMenuBotsNotModified#f1d88a5c = AttachMenuBots; attachMenuBots#3c4301c0 hash:long bots:Vector users:Vector = AttachMenuBots; @@ -1347,6 +1350,21 @@ notificationSoundRingtone#ff6c8049 id:long = NotificationSound; account.savedRingtone#b7263f6d = account.SavedRingtone; account.savedRingtoneConverted#1f307eb7 document:Document = account.SavedRingtone; +attachMenuPeerTypeSameBotPM#7d6be90e = AttachMenuPeerType; +attachMenuPeerTypeBotPM#c32bfa1a = AttachMenuPeerType; +attachMenuPeerTypePM#f146d31f = AttachMenuPeerType; +attachMenuPeerTypeChat#509113f = AttachMenuPeerType; +attachMenuPeerTypeBroadcast#7bfbdefc = AttachMenuPeerType; + +inputInvoiceMessage#c5b56859 peer:InputPeer msg_id:int = InputInvoice; +inputInvoiceSlug#c326caef slug:string = InputInvoice; + +payments.exportedInvoice#aed0cbd9 url:string = payments.ExportedInvoice; + +messages.transcribedAudio#93752c52 flags:# pending:flags.0?true transcription_id:long text:string = messages.TranscribedAudio; + +help.premiumPromo#8a4f3c29 status_text:string status_entities:Vector video_sections:Vector videos:Vector currency:string monthly_amount:long users:Vector = help.PremiumPromo; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1417,7 +1435,7 @@ account.sendVerifyPhoneCode#a5a356f9 phone_number:string settings:CodeSettings = 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.initTakeoutSession#8ef3eab0 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?long = account.Takeout; account.finishTakeoutSession#1d2652ee flags:# success:flags.0?true = Bool; account.confirmPasswordEmail#8fdf1920 code:string = Bool; account.resendPasswordEmail#7a7f2a15 = Bool; @@ -1529,7 +1547,7 @@ messages.editChatAdmin#a85bd1c2 chat_id:long user_id:InputUser is_admin:Bool = B messages.migrateChat#a2875319 chat_id:long = Updates; messages.searchGlobal#4bc6589a flags:# folder_id:flags.0?int q:string filter:MessagesFilter min_date:int max_date:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; messages.reorderStickerSets#78337739 flags:# masks:flags.0?true order:Vector = Bool; -messages.getDocumentByHash#338e2464 sha256:bytes size:int mime_type:string = Document; +messages.getDocumentByHash#b1f2061f sha256:bytes size:long mime_type:string = Document; messages.getSavedGifs#5cf09635 hash:long = messages.SavedGifs; messages.saveGif#327a30cb id:InputDocument unsave:Bool = Bool; messages.getInlineBotResults#514e999d flags:# bot:InputUser peer:InputPeer geo_point:flags.0?InputGeoPoint query:string offset:string = messages.BotResults; @@ -1642,11 +1660,13 @@ messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = mes messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots; messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot; messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool; -messages.requestWebView#fa04dff flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int = WebViewResult; -messages.prolongWebView#d22ad148 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int = Bool; +messages.requestWebView#91b15831 flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = WebViewResult; +messages.prolongWebView#ea5fbcce flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = Bool; messages.requestSimpleWebView#6abb2f73 flags:# bot:InputUser url:string theme_params:flags.0?DataJSON = SimpleWebViewResult; messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent; messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates; +messages.transcribeAudio#269e9a49 peer:InputPeer msg_id:int = messages.TranscribedAudio; +messages.rateTranscribedAudio#7f1d072f peer:InputPeer msg_id:int transcription_id:long good:Bool = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1658,13 +1678,13 @@ photos.deletePhotos#87cf7f2f id:Vector = Vector; photos.getUserPhotos#91cd32a8 user_id:InputUser offset:int max_id:long limit:int = photos.Photos; upload.saveFilePart#b304a621 file_id:long file_part:int bytes:bytes = Bool; -upload.getFile#b15a9afc flags:# precise:flags.0?true cdn_supported:flags.1?true location:InputFileLocation offset:int limit:int = upload.File; +upload.getFile#be5335be flags:# precise:flags.0?true cdn_supported:flags.1?true location:InputFileLocation offset:long limit:int = upload.File; upload.saveBigFilePart#de7b673d file_id:long file_part:int file_total_parts:int bytes:bytes = Bool; upload.getWebFile#24e6818d location:InputWebFileLocation offset:int limit:int = upload.WebFile; -upload.getCdnFile#2000bcc3 file_token:bytes offset:int limit:int = upload.CdnFile; +upload.getCdnFile#395f69da file_token:bytes offset:long limit:int = upload.CdnFile; upload.reuploadCdnFile#9b2754a8 file_token:bytes request_token:bytes = Vector; -upload.getCdnFileHashes#4da54231 file_token:bytes offset:int = Vector; -upload.getFileHashes#c7025931 location:InputFileLocation offset:int = Vector; +upload.getCdnFileHashes#91dc3f31 file_token:bytes offset:long = Vector; +upload.getFileHashes#9156982a location:InputFileLocation offset:long = Vector; help.getConfig#c4f9186b = Config; help.getNearestDc#1fb33026 = NearestDc; @@ -1688,6 +1708,7 @@ help.getPromoData#c0977421 = help.PromoData; help.hidePromoData#1e251c95 peer:InputPeer = Bool; help.dismissSuggestion#f50dbaa1 peer:InputPeer suggestion:string = Bool; help.getCountriesList#735787a8 lang_code:string hash:int = help.CountriesList; +help.getPremiumPromo#b81b93d4 = help.PremiumPromo; channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool; channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector = messages.AffectedMessages; @@ -1728,6 +1749,8 @@ channels.viewSponsoredMessage#beaedb94 channel:InputChannel random_id:bytes = Bo channels.getSponsoredMessages#ec210fbf channel:InputChannel = messages.SponsoredMessages; channels.getSendAs#dc770ee peer:InputPeer = channels.SendAsPeers; channels.deleteParticipantHistory#367544db channel:InputChannel participant:InputPeer = messages.AffectedHistory; +channels.toggleJoinToSend#e4cb9580 channel:InputChannel enabled:Bool = Updates; +channels.toggleJoinRequest#4c2985b6 channel:InputChannel enabled:Bool = Updates; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1739,13 +1762,19 @@ bots.getBotMenuButton#9c60eb28 user_id:InputUser = BotMenuButton; bots.setBotBroadcastDefaultAdminRights#788464e1 admin_rights:ChatAdminRights = Bool; bots.setBotGroupDefaultAdminRights#925ec9ea admin_rights:ChatAdminRights = Bool; -payments.getPaymentForm#8a333c8d flags:# peer:InputPeer msg_id:int theme_params:flags.0?DataJSON = payments.PaymentForm; +payments.getPaymentForm#37148dbb flags:# invoice:InputInvoice theme_params:flags.0?DataJSON = payments.PaymentForm; payments.getPaymentReceipt#2478d1cc peer:InputPeer msg_id:int = payments.PaymentReceipt; -payments.validateRequestedInfo#db103170 flags:# save:flags.0?true peer:InputPeer msg_id:int info:PaymentRequestedInfo = payments.ValidatedRequestedInfo; -payments.sendPaymentForm#30c3bc9d flags:# form_id:long peer:InputPeer msg_id:int requested_info_id:flags.0?string shipping_option_id:flags.1?string credentials:InputPaymentCredentials tip_amount:flags.2?long = payments.PaymentResult; +payments.validateRequestedInfo#b6c8f12b flags:# save:flags.0?true invoice:InputInvoice info:PaymentRequestedInfo = payments.ValidatedRequestedInfo; +payments.sendPaymentForm#2d03522f flags:# form_id:long invoice:InputInvoice requested_info_id:flags.0?string shipping_option_id:flags.1?string credentials:InputPaymentCredentials tip_amount:flags.2?long = payments.PaymentResult; payments.getSavedInfo#227d824b = payments.SavedInfo; payments.clearSavedInfo#d83d70c1 flags:# credentials:flags.0?true info:flags.1?true = Bool; payments.getBankCardData#2e79d779 number:string = payments.BankCardData; +payments.exportInvoice#f91b065 invoice_media:InputMedia = payments.ExportedInvoice; +payments.assignAppStoreTransaction#fec13c6 flags:# restore:flags.0?true transaction_id:string receipt:bytes = Updates; +payments.assignPlayMarketTransaction#4faa4aed purchase_token:string = Updates; +payments.restorePlayMarketReceipt#d164e36a receipt:bytes = Updates; +payments.canPurchasePremium#aa6a90c8 = Bool; +payments.requestRecurringPayment#146e958d user_id:InputUser recurring_init_charge:string invoice_media:InputMedia = Updates; stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet; stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet; @@ -1802,4 +1831,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 142 \ No newline at end of file +// LAYER 143 \ No newline at end of file diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py index 8860784d8d..4df3b17e76 100644 --- a/pyrogram/types/user_and_chats/user.py +++ b/pyrogram/types/user_and_chats/user.py @@ -97,6 +97,9 @@ class User(Object, Update): is_support (``bool``, *optional*): True, if this user is part of the Telegram support team. + is_premium (``bool``, *optional*): + True, if this user is a premium user. + first_name (``str``, *optional*): User's or bot's first name. @@ -156,6 +159,7 @@ def __init__( is_scam: bool = None, is_fake: bool = None, is_support: bool = None, + is_premium: bool = None, first_name: str = None, last_name: str = None, status: "enums.UserStatus" = None, @@ -181,6 +185,7 @@ def __init__( self.is_scam = is_scam self.is_fake = is_fake self.is_support = is_support + self.is_premium = is_premium self.first_name = first_name self.last_name = last_name self.status = status @@ -218,6 +223,7 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]: is_scam=user.scam, is_fake=user.fake, is_support=user.support, + is_premium=user.premium, first_name=user.first_name, last_name=user.last_name, **User._parse_status(user.status, user.bot), From b59dcd16152d51467041cc68f9d4fdcfe37174c0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:32:10 +0200 Subject: [PATCH 307/539] Do not trigger a reconnection when skipping invalid packets --- pyrogram/session/session.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 2e90184a2c..a6537bb9a4 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -189,7 +189,6 @@ async def handle_packet(self, packet): self.stored_msg_ids ) except SecurityCheckMismatch: - self.connection.close() return messages = ( From d61a2ce8a9e6dcb337410b3d3f955e29820fe74e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:40:30 +0200 Subject: [PATCH 308/539] Remove syncer.py --- pyrogram/methods/auth/initialize.py | 2 - pyrogram/methods/auth/terminate.py | 3 +- pyrogram/syncer.py | 88 ----------------------------- 3 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 pyrogram/syncer.py diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index cb8fd0cc74..48bd6f10ff 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.py @@ -19,7 +19,6 @@ import logging import pyrogram -from pyrogram.syncer import Syncer log = logging.getLogger(__name__) @@ -46,7 +45,6 @@ async def initialize( self.load_plugins() await self.dispatcher.start() - await Syncer.add(self) self.username = (await self.get_me()).username self.is_initialized = True diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 548d030cb4..707c25e90e 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -20,7 +20,6 @@ import pyrogram from pyrogram import raw -from pyrogram.syncer import Syncer log = logging.getLogger(__name__) @@ -44,7 +43,7 @@ async def terminate( await self.invoke(raw.functions.account.FinishTakeoutSession()) log.warning(f"Takeout session {self.takeout_id} finished") - await Syncer.remove(self) + await self.storage.save() await self.dispatcher.stop() for media_session in self.media_sessions.values(): diff --git a/pyrogram/syncer.py b/pyrogram/syncer.py deleted file mode 100644 index 3ff1bfc9fd..0000000000 --- a/pyrogram/syncer.py +++ /dev/null @@ -1,88 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# -# 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 asyncio -import logging -import time - -log = logging.getLogger(__name__) - - -class Syncer: - INTERVAL = 20 - - clients = {} - event = None - lock = None - - @classmethod - async def add(cls, client): - if cls.event is None: - cls.event = asyncio.Event() - - if cls.lock is None: - cls.lock = asyncio.Lock() - - async with cls.lock: - await cls.sync(client) - - cls.clients[id(client)] = client - - if len(cls.clients) == 1: - cls.start() - - @classmethod - async def remove(cls, client): - async with cls.lock: - await cls.sync(client) - - del cls.clients[id(client)] - - if len(cls.clients) == 0: - cls.stop() - - @classmethod - def start(cls): - cls.event.clear() - asyncio.get_event_loop().create_task(cls.worker()) - - @classmethod - def stop(cls): - cls.event.set() - - @classmethod - async def worker(cls): - while True: - try: - await asyncio.wait_for(cls.event.wait(), cls.INTERVAL) - except asyncio.TimeoutError: - async with cls.lock: - for client in cls.clients.values(): - await cls.sync(client) - else: - break - - @classmethod - async def sync(cls, client): - try: - start = time.time() - await client.storage.save() - except Exception as e: - log.critical(e, exc_info=True) - else: - log.debug(f'Synced "{client.storage.name}" in {(time.time() - start) * 1000:.6} ms') From b35810dc9f1332d37a33847fd8846d12394c2db0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:48:03 +0200 Subject: [PATCH 309/539] Update compose example --- pyrogram/methods/utilities/compose.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/utilities/compose.py b/pyrogram/methods/utilities/compose.py index cfc5ca3e61..e05773b8e1 100644 --- a/pyrogram/methods/utilities/compose.py +++ b/pyrogram/methods/utilities/compose.py @@ -49,13 +49,15 @@ async def compose( async def main(): - app1 = Client("account1") - app2 = Client("account2") - app3 = Client("account3") + apps = [ + Client("account1"), + Client("account2"), + Client("account3") + ] ... - await compose([app1, app2, app3]) + await compose(apps) asyncio.run(main()) From 0a50520fc94ef53a55f6d36714102f934f891b37 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:51:16 +0200 Subject: [PATCH 310/539] Improve idle() implementation --- pyrogram/methods/utilities/idle.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pyrogram/methods/utilities/idle.py b/pyrogram/methods/utilities/idle.py index bcd685e08d..00db22a2e4 100644 --- a/pyrogram/methods/utilities/idle.py +++ b/pyrogram/methods/utilities/idle.py @@ -23,8 +23,6 @@ log = logging.getLogger(__name__) -is_idling = False - # Signal number to name signals = { k: v for v, k in signal.__dict__.items() @@ -71,18 +69,19 @@ async def main(): asyncio.run(main()) """ - global is_idling + task = None def signal_handler(signum, __): - global is_idling - logging.info(f"Stop signal received ({signals[signum]}). Exiting...") - is_idling = False + task.cancel() for s in (SIGINT, SIGTERM, SIGABRT): signal_fn(s, signal_handler) - is_idling = True + while True: + task = asyncio.create_task(asyncio.sleep(600)) - while is_idling: - await asyncio.sleep(1) + try: + await task + except asyncio.CancelledError: + break From 6a766faf2fa784c2db786bd57676e1c2ee982166 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:53:27 +0200 Subject: [PATCH 311/539] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 764526769f..6b904e2987 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@
Telegram MTProto API Framework for Python
+ + Homepage + + • Documentation From d71db29a8c6f579719f6a0895be43782a5619803 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 10:28:49 +0200 Subject: [PATCH 312/539] Store the "me" user object --- pyrogram/client.py | 3 +-- pyrogram/filters.py | 2 +- pyrogram/methods/auth/initialize.py | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index c1d04046b2..d30a5e9a80 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -270,8 +270,7 @@ def __init__( self.disconnect_handler = None - # Username used for mentioned bot commands, e.g.: /start@usernamebot - self.username = None + self.me: Optional[User] = None self.message_cache = Cache(10000) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 76bff856ff..f31b385ed4 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -757,7 +757,7 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = " command_re = re.compile(r"([\"'])(.*?)(? Date: Mon, 20 Jun 2022 10:32:17 +0200 Subject: [PATCH 313/539] Improve upload file size checks --- pyrogram/methods/advanced/save_file.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index 706f28e04f..6a43deac6f 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -125,8 +125,10 @@ async def worker(session): if file_size == 0: raise ValueError("File size equals to 0 B") - if file_size > 2000 * 1024 * 1024: - raise ValueError("Telegram doesn't support uploading files bigger than 2000 MiB") + file_size_limit_mib = 4000 if self.me.is_premium else 2000 + + if file_size > file_size_limit_mib * 1024 * 1024: + raise ValueError(f"Can't upload files bigger than {file_size_limit_mib} MiB") file_total_parts = int(math.ceil(file_size / part_size)) is_big = file_size > 10 * 1024 * 1024 From 34ffc4991ae1c3ce17ae39bbdedf722269644f3b Mon Sep 17 00:00:00 2001 From: noreph <60476630+noreph@users.noreply.github.com> Date: Mon, 20 Jun 2022 17:41:10 +0800 Subject: [PATCH 314/539] Fix example typo (#1020) --- pyrogram/methods/messages/send_photo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 836ce1b1d4..6add68cd6c 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -131,7 +131,7 @@ async def send_photo( await app.send_photo("me", "photo.jpg") # Send photo by uploading from URL - await app.send_photo("me", "https://example.com/example.jpg) + await app.send_photo("me", "https://example.com/example.jpg") # Add caption to a photo await app.send_photo("me", "photo.jpg", caption="Caption") From b904a4f3e28b7ba95a605f2c64c09c73a416712e Mon Sep 17 00:00:00 2001 From: "Mr. Developer" <77911154+MrBotDeveloper@users.noreply.github.com> Date: Mon, 20 Jun 2022 15:12:11 +0530 Subject: [PATCH 315/539] Fix FAQ example (#1007) --- docs/source/faq/how-to-avoid-flood-waits.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/faq/how-to-avoid-flood-waits.rst b/docs/source/faq/how-to-avoid-flood-waits.rst index 4d2994d1f4..06d1cdc2a9 100644 --- a/docs/source/faq/how-to-avoid-flood-waits.rst +++ b/docs/source/faq/how-to-avoid-flood-waits.rst @@ -9,7 +9,7 @@ The following shows how to catch the exception in your code and wait the require .. code-block:: python - import time + import asyncio from pyrogram.errors import FloodWait ... @@ -20,4 +20,4 @@ The following shows how to catch the exception in your code and wait the require ... -More info about error handling can be found :doc:`here <../start/errors>`. \ No newline at end of file +More info about error handling can be found :doc:`here <../start/errors>`. From eb4ff1427be795407e1138192a764286099658f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Mon, 20 Jun 2022 15:12:37 +0530 Subject: [PATCH 316/539] Fix delete_profile_photos example (#990) --- pyrogram/methods/users/delete_profile_photos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py index e7205661eb..2e7615444f 100644 --- a/pyrogram/methods/users/delete_profile_photos.py +++ b/pyrogram/methods/users/delete_profile_photos.py @@ -43,7 +43,7 @@ async def delete_profile_photos( .. code-block:: python # Get the photos to be deleted - photos = await app.get_profile_photos("me") + photos = list(await app.get_chat_photos("me")) # Delete one photo await app.delete_profile_photos(photos[0].file_id) From 4b10ec8e87956bf220eaf0dc180adf1b14d51392 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:43:40 +0200 Subject: [PATCH 317/539] Pickle datetime objects into timestamps (#1016) * Pickle datetime objects into timestamps * Rename variable * Add length check --- pyrogram/types/object.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py index 28bee9a7fc..3253c8ecff 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -98,7 +98,24 @@ def __eq__(self, other: "Object") -> bool: return True + def __setstate__(self, state): + for attr in state: + obj = state[attr] + + # Maybe a better alternative would be https://docs.python.org/3/library/inspect.html#inspect.signature + if isinstance(obj, tuple) and len(obj) == 2 and obj[0] == "dt": + state[attr] = datetime.fromtimestamp(obj[1]) + + self.__dict__ = state + def __getstate__(self): - new_dict = self.__dict__.copy() - new_dict.pop("_client", None) - return new_dict + state = self.__dict__.copy() + state.pop("_client", None) + + for attr in state: + obj = state[attr] + + if isinstance(obj, datetime): + state[attr] = ("dt", obj.timestamp()) + + return state From 81baf853b514539b367f007428991db655dca3d5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:44:41 +0200 Subject: [PATCH 318/539] Update Pyrogram to v2.0.28 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 6e562ce075..ca5dd4e9cd 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.27" +__version__ = "2.0.28" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 212ea5739095fbb00553818e812727999aeabeff Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:49:17 +0200 Subject: [PATCH 319/539] Fix tests --- tests/filters/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/filters/__init__.py b/tests/filters/__init__.py index ebc674c470..6711b51b4c 100644 --- a/tests/filters/__init__.py +++ b/tests/filters/__init__.py @@ -18,10 +18,10 @@ class Client: def __init__(self): - self.username = "username" + self.me = User("username") async def get_me(self): - return User(self.username) + return self.me class User: From 78e1d29b3744a12beef7bca69dc8776d4e28e91f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:49:43 +0200 Subject: [PATCH 320/539] Update Pyrogram to v2.0.29 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index ca5dd4e9cd..3be904d46a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.28" +__version__ = "2.0.29" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 0e0642ebfdb70281f62b7aef61bbd998be2efe30 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Jun 2022 12:12:08 +0200 Subject: [PATCH 321/539] Add [403 PREMIUM_ACCOUNT_REQUIRED] error Closes #1024 --- compiler/errors/source/403_FORBIDDEN.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/errors/source/403_FORBIDDEN.tsv b/compiler/errors/source/403_FORBIDDEN.tsv index ff6955f1f1..69777cd249 100644 --- a/compiler/errors/source/403_FORBIDDEN.tsv +++ b/compiler/errors/source/403_FORBIDDEN.tsv @@ -24,4 +24,5 @@ USER_INVALID The provided user is invalid USER_IS_BLOCKED The user is blocked USER_NOT_MUTUAL_CONTACT The provided user is not a mutual contact USER_PRIVACY_RESTRICTED The user's privacy settings is preventing you to perform this action -USER_RESTRICTED You are limited/restricted. You can't perform this action \ No newline at end of file +USER_RESTRICTED You are limited/restricted. You can't perform this action +PREMIUM_ACCOUNT_REQUIRED This action requires a premium account \ No newline at end of file From 3aaf35792f2cfa2f2adbf84992ee5411af65c52d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Jun 2022 12:16:14 +0200 Subject: [PATCH 322/539] Update Pyrogram to v2.0.30 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 3be904d46a..146c3ce879 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.29" +__version__ = "2.0.30" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 4398cbb561ac92af18c61378d3bebcb6fb2ae73a Mon Sep 17 00:00:00 2001 From: Davide Galilei <43778739+DavideGalilei@users.noreply.github.com> Date: Thu, 14 Jul 2022 20:21:34 +0200 Subject: [PATCH 323/539] Improve edit_inline_media (#1036) --- .../methods/messages/edit_inline_media.py | 48 +++++++++++++++---- pyrogram/methods/messages/inline_session.py | 4 +- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 59a18aa7b1..cec4a3e1d3 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -18,16 +18,20 @@ import os import re +import asyncio import pyrogram from pyrogram import raw from pyrogram import types from pyrogram import utils +from pyrogram.errors import RPCError, MediaEmpty from pyrogram.file_id import FileType from .inline_session import get_session class EditInlineMedia: + MAX_RETRIES = 3 + async def edit_inline_media( self: "pyrogram.Client", inline_message_id: str, @@ -147,7 +151,8 @@ async def edit_inline_media( file_name=os.path.basename(media.media) ), raw.types.DocumentAttributeAnimated() - ] + ], + nosound_video=True ) elif re.match("^https?://", media.media): media = raw.types.InputMediaDocumentExternal( @@ -165,7 +170,8 @@ async def edit_inline_media( raw.types.DocumentAttributeFilename( file_name=os.path.basename(media.media) ) - ] + ], + force_file=True ) elif re.match("^https?://", media.media): media = raw.types.InputMediaDocumentExternal( @@ -179,12 +185,34 @@ async def edit_inline_media( session = await get_session(self, dc_id) - return await session.invoke( - raw.functions.messages.EditInlineBotMessage( - id=unpacked, - media=media, - reply_markup=await reply_markup.write(self) if reply_markup else None, - **await self.parser.parse(caption, parse_mode) - ), - sleep_threshold=self.sleep_threshold + actual_media = await self.invoke( + raw.functions.messages.UploadMedia( + peer=raw.types.InputPeerSelf(), + media=media + ) ) + + for i in range(self.MAX_RETRIES): + try: + return await session.invoke( + raw.functions.messages.EditInlineBotMessage( + id=unpacked, + media=raw.types.InputMediaDocument( + id=raw.types.InputDocument( + id=actual_media.document.id, + access_hash=actual_media.document.access_hash, + file_reference=actual_media.document.file_reference + ) + ), + reply_markup=await reply_markup.write(self) if reply_markup else None, + **await self.parser.parse(caption, parse_mode) + ), + sleep_threshold=self.sleep_threshold + ) + except RPCError as e: + if i == self.MAX_RETRIES - 1: + raise + + if isinstance(e, MediaEmpty): + # Must wait due to a server race condition + await asyncio.sleep(1) diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py index 57fa794584..a514f5a68c 100644 --- a/pyrogram/methods/messages/inline_session.py +++ b/pyrogram/methods/messages/inline_session.py @@ -33,8 +33,8 @@ async def get_session(client: "pyrogram.Client", dc_id: int): session = client.media_sessions[dc_id] = Session( client, dc_id, - await Auth(client, dc_id, False).create(), - False, is_media=True + await Auth(client, dc_id, await client.storage.test_mode()).create(), + await client.storage.test_mode(), is_media=True ) await session.start() From 11d6a4a833c4e9f925507d255d5306d94e466094 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 14 Jul 2022 20:22:48 +0200 Subject: [PATCH 324/539] Update Pyrogram to v2.0.31 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 146c3ce879..a9390e6418 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.30" +__version__ = "2.0.31" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 70e73d3ca8953bf1dad9bfc5c29f604b343007e0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 14 Jul 2022 21:01:07 +0200 Subject: [PATCH 325/539] Add ENTITY_BOUNDS_INVALID error description --- compiler/errors/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 990d875ea8..726f5f829a 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -349,4 +349,5 @@ WEBDOCUMENT_URL_EMPTY The web document URL is empty WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media -YOU_BLOCKED_USER You blocked this user \ No newline at end of file +YOU_BLOCKED_USER You blocked this user +ENTITY_BOUNDS_INVALID The message entity bounds are invalid \ No newline at end of file From d1e8b3bf1e87e65bf5724cbae709e8dadac02183 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 14 Jul 2022 21:01:30 +0200 Subject: [PATCH 326/539] Update Pyrogram to v2.0.32 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a9390e6418..8cc2b9e0bd 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.31" +__version__ = "2.0.32" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 298d361092aee2c410bb1086d65483151fae2de7 Mon Sep 17 00:00:00 2001 From: Mahesh <44301650+Mahesh0253@users.noreply.github.com> Date: Sat, 16 Jul 2022 22:55:26 +0530 Subject: [PATCH 327/539] Store "me" user object before starting dispatcher (#1042) --- pyrogram/methods/auth/initialize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index 3e69204430..26c9d0bf8c 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.py @@ -44,8 +44,8 @@ async def initialize( self.load_plugins() - await self.dispatcher.start() - self.me = await self.get_me() + await self.dispatcher.start() + self.is_initialized = True From d9c8e0450b0913e3949ab5938bb5d91dc6af7c63 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 16 Jul 2022 19:25:57 +0200 Subject: [PATCH 328/539] Update Pyrogram to v2.0.33 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 8cc2b9e0bd..673b89fb36 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.32" +__version__ = "2.0.33" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ed748952b5d7acb33ed64e3d63de895419144cdb Mon Sep 17 00:00:00 2001 From: Harsh <65716674+Harsh-br0@users.noreply.github.com> Date: Fri, 22 Jul 2022 20:45:18 +0530 Subject: [PATCH 329/539] Filter out empty entities internally (#1041) * Filter out empty entities internally I guess it's fine to handle empty entities internally to avoid ENTITY_BOUNDS_INVALID , so the client won't send the empty entities * revert utils and apply changes to parser/html.py * Update utils.py * Update utils.py * Update utils.py * Update html.py * Update utils.py * Update utils.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/parser/html.py | 19 +++++++++++++++---- pyrogram/utils.py | 23 +++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 8a7063e58a..d9a8d36876 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -140,6 +140,9 @@ async def parse(self, text: str): entities.append(entity) + # Remove zero-length entities + entities = list(filter(lambda x: x.length > 0, entities)) + return { "message": utils.remove_surrogates(parser.text), "entities": sorted(entities, key=lambda e: e.offset) @@ -156,13 +159,21 @@ def unparse(text: str, entities: list): start = entity.offset end = start + entity.length - if entity_type in (MessageEntityType.BOLD, MessageEntityType.ITALIC, MessageEntityType.UNDERLINE, - MessageEntityType.STRIKETHROUGH): + if entity_type in ( + MessageEntityType.BOLD, + MessageEntityType.ITALIC, + MessageEntityType.UNDERLINE, + MessageEntityType.STRIKETHROUGH, + ): name = entity_type.name[0].lower() start_tag = f"<{name}>" end_tag = f"" - elif entity_type in (MessageEntityType.CODE, MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE, - MessageEntityType.SPOILER): + elif entity_type in ( + MessageEntityType.CODE, + MessageEntityType.PRE, + MessageEntityType.BLOCKQUOTE, + MessageEntityType.SPOILER, + ): name = entity_type.name.lower() start_tag = f"<{name}>" end_tag = f"" diff --git a/pyrogram/utils.py b/pyrogram/utils.py index d5862d1a67..b6a8d6bfb6 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -48,8 +48,10 @@ def get_input_media_from_file_id( try: decoded = FileId.decode(file_id) except Exception: - raise ValueError(f'Failed to decode "{file_id}". The value does not represent an existing local file, ' - f'HTTP URL, or valid file id.') + raise ValueError( + f'Failed to decode "{file_id}". The value does not represent an existing local file, ' + f"HTTP URL, or valid file id." + ) file_type = decoded.file_type @@ -82,7 +84,11 @@ def get_input_media_from_file_id( raise ValueError(f"Unknown file id: {file_id}") -async def parse_messages(client, messages: "raw.types.messages.Messages", replies: int = 1) -> List["types.Message"]: +async def parse_messages( + client, + messages: "raw.types.messages.Messages", + replies: int = 1 +) -> List["types.Message"]: users = {i.id: i for i in messages.users} chats = {i.id: i for i in messages.chats} @@ -260,8 +266,10 @@ def xor(a: bytes, b: bytes) -> bytes: return bytes(i ^ j for i, j in zip(a, b)) -def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow, - password: str) -> bytes: +def compute_password_hash( + algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow, + password: str +) -> bytes: hash1 = sha256(algo.salt1 + password.encode() + algo.salt1) hash2 = sha256(algo.salt2 + hash1 + algo.salt2) hash3 = hashlib.pbkdf2_hmac("sha512", hash2, algo.salt1, 100000) @@ -270,7 +278,10 @@ def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACS # noinspection PyPep8Naming -def compute_password_check(r: raw.types.account.Password, password: str) -> raw.types.InputCheckPasswordSRP: +def compute_password_check( + r: raw.types.account.Password, + password: str +) -> raw.types.InputCheckPasswordSRP: algo = r.current_algo p_bytes = algo.p From 6f7ec0de03a2b497d3a5c844c1c9e1ec40896483 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jul 2022 17:16:13 +0200 Subject: [PATCH 330/539] Update Pyrogram to v2.0.34 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 673b89fb36..35373be398 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.33" +__version__ = "2.0.34" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 673660242422fb4b852e84dd028af6a2a50002cb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jul 2022 22:52:21 +0200 Subject: [PATCH 331/539] Handle socket.connect() blocking-ness --- pyrogram/connection/transport/tcp/tcp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 5cd67937e5..c0efb625ab 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -21,6 +21,7 @@ import logging import socket import time +from concurrent.futures import ThreadPoolExecutor try: import socks @@ -78,7 +79,11 @@ def __init__(self, ipv6: bool, proxy: dict): self.socket.settimeout(TCP.TIMEOUT) async def connect(self, address: tuple): - self.socket.connect(address) + # The socket used by the whole logic is blocking and thus it blocks when connecting. + # Offload the task to a thread executor to avoid blocking the main event loop. + with ThreadPoolExecutor(1) as executor: + await self.loop.run_in_executor(executor, self.socket.connect, address) + self.reader, self.writer = await asyncio.open_connection(sock=self.socket) def close(self): From de3127720ecce9ece8da99f32c9dfd8ce55793cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jul 2022 22:52:47 +0200 Subject: [PATCH 332/539] Update Pyrogram to v2.0.35 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 35373be398..95fa60c7ba 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.34" +__version__ = "2.0.35" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 0505ff0d5e22ae13239a9737053933476d712214 Mon Sep 17 00:00:00 2001 From: AsmSafone <77989182+AsmSafone@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:56:21 +0600 Subject: [PATCH 333/539] Add some sticker-related errors (#1055) * Add STICKERS_TOO_MUCH, STICKERSET_NOT_MODIFIED, STICKER_VIDEO_NOWEBM error description * Update 400_BAD_REQUEST.tsv Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/errors/source/400_BAD_REQUEST.tsv | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 726f5f829a..877c967b37 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -285,7 +285,9 @@ START_PARAM_EMPTY The start parameter is empty START_PARAM_INVALID The start parameter is invalid START_PARAM_TOO_LONG The start parameter is too long STICKERSET_INVALID The requested sticker set is invalid +STICKERSET_NOT_MODIFIED The sticker set is not modified STICKERS_EMPTY The sticker provided is empty +STICKERS_TOO_MUCH Too many stickers in the set STICKER_DOCUMENT_INVALID The sticker document is invalid STICKER_EMOJI_INVALID The sticker emoji is invalid STICKER_FILE_INVALID The sticker file is invalid @@ -294,6 +296,7 @@ STICKER_INVALID The provided sticker is invalid STICKER_PNG_DIMENSIONS The sticker png dimensions are invalid STICKER_PNG_NOPNG Stickers must be png files but the provided image was not a png STICKER_TGS_NOTGS A tgs sticker file was expected, but something else was provided +STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided STICKER_THUMB_PNG_NOPNG A png sticker thumbnail file was expected, but something else was provided TAKEOUT_INVALID The takeout id is invalid TAKEOUT_REQUIRED The method must be invoked inside a takeout session @@ -350,4 +353,4 @@ WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media YOU_BLOCKED_USER You blocked this user -ENTITY_BOUNDS_INVALID The message entity bounds are invalid \ No newline at end of file +ENTITY_BOUNDS_INVALID The message entity bounds are invalid From 8da085198442a879103e813b035672c2ab827c52 Mon Sep 17 00:00:00 2001 From: dogghi <75123663+doggyhaha@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:58:36 +0200 Subject: [PATCH 334/539] Add support for BytesIO in InputMedia objects (#1047) fix docstrings and fix "TypeError: stat: path should be string, bytes, os.PathLike or integer, not BytesIO" when passing a BytesIO object to an InputMedia subclass --- pyrogram/methods/messages/edit_inline_media.py | 11 ++++++----- pyrogram/methods/messages/edit_message_media.py | 11 ++++++----- pyrogram/types/input_media/input_media.py | 4 ++-- pyrogram/types/input_media/input_media_animation.py | 2 +- pyrogram/types/input_media/input_media_audio.py | 2 +- pyrogram/types/input_media/input_media_document.py | 2 +- pyrogram/types/input_media/input_media_video.py | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index cec4a3e1d3..4126c802fb 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -19,6 +19,7 @@ import os import re import asyncio +import io import pyrogram from pyrogram import raw @@ -77,7 +78,7 @@ async def edit_inline_media( parse_mode = media.parse_mode if isinstance(media, types.InputMediaPhoto): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = raw.types.InputMediaUploadedPhoto( file=await self.save_file(media.media) ) @@ -88,7 +89,7 @@ async def edit_inline_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) elif isinstance(media, types.InputMediaVideo): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "video/mp4", thumb=await self.save_file(media.thumb), @@ -112,7 +113,7 @@ async def edit_inline_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) elif isinstance(media, types.InputMediaAudio): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "audio/mpeg", thumb=await self.save_file(media.thumb), @@ -135,7 +136,7 @@ async def edit_inline_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO) elif isinstance(media, types.InputMediaAnimation): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "video/mp4", thumb=await self.save_file(media.thumb), @@ -161,7 +162,7 @@ async def edit_inline_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) elif isinstance(media, types.InputMediaDocument): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "application/zip", thumb=await self.save_file(media.thumb), diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index 3dce81edb9..a3840f2374 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -18,6 +18,7 @@ import os import re +import io from typing import Union import pyrogram @@ -89,7 +90,7 @@ async def edit_message_media( message, entities = (await self.parser.parse(caption, parse_mode)).values() if isinstance(media, types.InputMediaPhoto): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), @@ -113,7 +114,7 @@ async def edit_message_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) elif isinstance(media, types.InputMediaVideo): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), @@ -150,7 +151,7 @@ async def edit_message_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) elif isinstance(media, types.InputMediaAudio): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), @@ -186,7 +187,7 @@ async def edit_message_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO) elif isinstance(media, types.InputMediaAnimation): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), @@ -224,7 +225,7 @@ async def edit_message_media( else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) elif isinstance(media, types.InputMediaDocument): - if os.path.isfile(media.media): + if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), diff --git a/pyrogram/types/input_media/input_media.py b/pyrogram/types/input_media/input_media.py index 8e2f3a7b1a..bd60aeb3e1 100644 --- a/pyrogram/types/input_media/input_media.py +++ b/pyrogram/types/input_media/input_media.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import List +from typing import List, Union, BinaryIO from ..messages_and_media import MessageEntity from ..object import Object @@ -36,7 +36,7 @@ class InputMedia(Object): def __init__( self, - media: str, + media: Union[str, BinaryIO], caption: str = "", parse_mode: str = None, caption_entities: List[MessageEntity] = None diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py index 04aa940edc..2eae1a66f0 100644 --- a/pyrogram/types/input_media/input_media_animation.py +++ b/pyrogram/types/input_media/input_media_animation.py @@ -27,7 +27,7 @@ class InputMediaAnimation(InputMedia): """An animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent inside an album. Parameters: - media (``str``): + media (``str`` | ``BinaryIO``): 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 or diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py index b4bb7575be..cc91e7bd5c 100644 --- a/pyrogram/types/input_media/input_media_audio.py +++ b/pyrogram/types/input_media/input_media_audio.py @@ -29,7 +29,7 @@ class InputMediaAudio(InputMedia): It is intended to be used with :meth:`~pyrogram.Client.send_media_group`. Parameters: - media (``str``): + media (``str`` | ``BinaryIO``): 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 or diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py index 91dfc7d673..3e4d510b95 100644 --- a/pyrogram/types/input_media/input_media_document.py +++ b/pyrogram/types/input_media/input_media_document.py @@ -27,7 +27,7 @@ class InputMediaDocument(InputMedia): """A generic file to be sent inside an album. Parameters: - media (``str``): + media (``str`` | ``BinaryIO``): 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 or diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py index bad4e3ef3a..c163cba9fb 100644 --- a/pyrogram/types/input_media/input_media_video.py +++ b/pyrogram/types/input_media/input_media_video.py @@ -28,7 +28,7 @@ class InputMediaVideo(InputMedia): It is intended to be used with :obj:`~pyrogram.Client.send_media_group`. Parameters: - media (``str``): + media (``str`` | ``BinaryIO``): 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 or From bc9161c354ab65c9363d363a1935fe9c1d8cf889 Mon Sep 17 00:00:00 2001 From: Nick <64551534+null-nick@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:59:55 +0200 Subject: [PATCH 335/539] Update API schema to Layer 144 (#1050) --- compiler/api/source/main_api.tl | 44 +++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 3f44fe0fbe..bf8a37ee72 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -169,6 +169,7 @@ messageActionSetChatTheme#aa786345 emoticon:string = MessageAction; messageActionChatJoinedByRequest#ebbca3cb = MessageAction; messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction; messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction; +messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = MessageAction; dialog#a8edd0f5 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -218,7 +219,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason; inputReportReasonIllegalDrugs#a8eb2be = ReportReason; inputReportReasonPersonalDetails#9ec7863d = ReportReason; -userFull#8c72ea81 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights = UserFull; +userFull#c4b1fc3f flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; contact#145ade0b user_id:long mutual:Bool = Contact; @@ -300,7 +301,7 @@ updateDeleteChannelMessages#c32d5b12 channel_id:long messages:Vector pts:in updateChannelMessageViews#f226ac08 channel_id:long id:int views:int = Update; updateChatParticipantAdmin#d7ca61a2 chat_id:long user_id:long is_admin:Bool version:int = Update; updateNewStickerSet#688a30aa stickerset:messages.StickerSet = Update; -updateStickerSetsOrder#bb2d201 flags:# masks:flags.0?true order:Vector = Update; +updateStickerSetsOrder#bb2d201 flags:# masks:flags.0?true emojis:flags.1?true order:Vector = Update; updateStickerSets#43ae3dec = Update; updateSavedGifs#9375341e = Update; updateBotInlineQuery#496f379c flags:# query_id:long user_id:long query:string geo:flags.0?GeoPoint peer_type:flags.1?InlineQueryPeerType offset:string = Update; @@ -369,6 +370,7 @@ updateWebViewResultSent#1592b79d query_id:long = Update; updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update; updateSavedRingtones#74d8be99 = Update; updateTranscribedAudio#84cd5a flags:# pending:flags.0?true peer:Peer msg_id:int transcription_id:long text:string = Update; +updateReadFeaturedEmojiStickers#fb4c496c = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -471,6 +473,7 @@ inputPrivacyKeyForwards#a4dd4c08 = InputPrivacyKey; inputPrivacyKeyProfilePhoto#5719bacc = InputPrivacyKey; inputPrivacyKeyPhoneNumber#352dafa = InputPrivacyKey; inputPrivacyKeyAddedByPhone#d1219bdd = InputPrivacyKey; +inputPrivacyKeyVoiceMessages#aee69d68 = InputPrivacyKey; privacyKeyStatusTimestamp#bc2eab30 = PrivacyKey; privacyKeyChatInvite#500e6dfa = PrivacyKey; @@ -480,6 +483,7 @@ privacyKeyForwards#69ec56a3 = PrivacyKey; privacyKeyProfilePhoto#96151fed = PrivacyKey; privacyKeyPhoneNumber#d19ae46d = PrivacyKey; privacyKeyAddedByPhone#42ffd42b = PrivacyKey; +privacyKeyVoiceMessages#697f414 = PrivacyKey; inputPrivacyValueAllowContacts#d09e07b = InputPrivacyRule; inputPrivacyValueAllowAll#184b35ce = InputPrivacyRule; @@ -510,6 +514,7 @@ documentAttributeVideo#ef02ce6 flags:# round_message:flags.0?true supports_strea documentAttributeAudio#9852f9c6 flags:# voice:flags.10?true duration:int title:flags.0?string performer:flags.1?string waveform:flags.2?bytes = DocumentAttribute; documentAttributeFilename#15590068 file_name:string = DocumentAttribute; documentAttributeHasStickers#9801d2f7 = DocumentAttribute; +documentAttributeCustomEmoji#fd149899 flags:# free:flags.0?true alt:string stickerset:InputStickerSet = DocumentAttribute; messages.stickersNotModified#f1749a22 = messages.Stickers; messages.stickers#30a6ec7e hash:long stickers:Vector = messages.Stickers; @@ -553,8 +558,9 @@ inputStickerSetShortName#861cc8a0 short_name:string = InputStickerSet; inputStickerSetAnimatedEmoji#28703c8 = InputStickerSet; inputStickerSetDice#e67f520e emoticon:string = InputStickerSet; inputStickerSetAnimatedEmojiAnimations#cde3739 = InputStickerSet; +inputStickerSetPremiumGifts#c88b3b02 = InputStickerSet; -stickerSet#d7df217a flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true videos:flags.6?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int count:int hash:int = StickerSet; +stickerSet#2dd14edc flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true videos:flags.6?true emojis:flags.7?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int thumb_document_id:flags.8?long count:int hash:int = StickerSet; messages.stickerSet#b60a24a6 set:StickerSet packs:Vector documents:Vector = messages.StickerSet; messages.stickerSetNotModified#d3f924eb = messages.StickerSet; @@ -606,6 +612,7 @@ messageEntityStrike#bf0693d4 offset:int length:int = MessageEntity; messageEntityBlockquote#20df5d0 offset:int length:int = MessageEntity; messageEntityBankCard#761e6af4 offset:int length:int = MessageEntity; messageEntitySpoiler#32ca960f offset:int length:int = MessageEntity; +messageEntityCustomEmoji#c8cf05f8 offset:int length:int document_id:long = MessageEntity; inputChannelEmpty#ee8c1e86 = InputChannel; inputChannel#f35aec28 channel_id:long access_hash:long = InputChannel; @@ -720,7 +727,7 @@ 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#c6dc0c66 count:int = messages.FeaturedStickers; -messages.featuredStickers#84c02310 hash:long count:int sets:Vector unread:Vector = messages.FeaturedStickers; +messages.featuredStickers#be382906 flags:# premium:flags.0?true hash:long count:int sets:Vector unread:Vector = messages.FeaturedStickers; messages.recentStickersNotModified#b17f890 = messages.RecentStickers; messages.recentStickers#88d37c56 hash:long packs:Vector stickers:Vector dates:Vector = messages.RecentStickers; @@ -732,6 +739,7 @@ messages.stickerSetInstallResultArchive#35e410a8 sets:Vector stickerSetCovered#6410a5d2 set:StickerSet cover:Document = StickerSetCovered; stickerSetMultiCovered#3407e51b set:StickerSet covers:Vector = StickerSetCovered; +stickerSetFullCovered#1aed5ee5 set:StickerSet packs:Vector documents:Vector = StickerSetCovered; maskCoords#aed6dbb2 n:int x:double y:double zoom:double = MaskCoords; @@ -820,10 +828,11 @@ inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector inputWebFileLocation#c239d686 url:string access_hash:long = InputWebFileLocation; inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w:int h:int zoom:int scale:int = InputWebFileLocation; +inputWebFileAudioAlbumThumbLocation#f46fe924 flags:# small:flags.2?true document:flags.0?InputDocument title:flags.1?string performer:flags.1?string = InputWebFileLocation; upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile; -payments.paymentForm#b0133b37 flags:# can_save_credentials:flags.2?true password_missing:flags.3?true form_id:long bot_id:long title:string description:string photo:flags.5?WebDocument invoice:Invoice provider_id:long url:string native_provider:flags.4?string native_params:flags.4?DataJSON saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?PaymentSavedCredentials users:Vector = payments.PaymentForm; +payments.paymentForm#a0058751 flags:# can_save_credentials:flags.2?true password_missing:flags.3?true form_id:long bot_id:long title:string description:string photo:flags.5?WebDocument invoice:Invoice provider_id:long url:string native_provider:flags.4?string native_params:flags.4?DataJSON additional_methods:flags.6?Vector saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?Vector users:Vector = payments.PaymentForm; payments.validatedRequestedInfo#d1451883 flags:# id:flags.0?string shipping_options:flags.1?Vector = payments.ValidatedRequestedInfo; @@ -1365,6 +1374,13 @@ messages.transcribedAudio#93752c52 flags:# pending:flags.0?true transcription_id help.premiumPromo#8a4f3c29 status_text:string status_entities:Vector video_sections:Vector videos:Vector currency:string monthly_amount:long users:Vector = help.PremiumPromo; +inputStorePaymentPremiumSubscription#a6751e66 flags:# restore:flags.0?true = InputStorePaymentPurpose; +inputStorePaymentGiftPremium#616f7fe8 user_id:InputUser currency:string amount:long = InputStorePaymentPurpose; + +premiumGiftOption#74c34319 flags:# months:int currency:string amount:long bot_url:string store_product:flags.0?string = PremiumGiftOption; + +paymentFormMethod#88f8f21b url:string title:string = PaymentFormMethod; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1408,7 +1424,7 @@ account.checkUsername#2714d86c username:string = Bool; account.updateUsername#3e0bdd7c username:string = User; account.getPrivacy#dadbc950 key:InputPrivacyKey = account.PrivacyRules; account.setPrivacy#c9f81ce8 key:InputPrivacyKey rules:Vector = account.PrivacyRules; -account.deleteAccount#418d4e0b reason:string = Bool; +account.deleteAccount#a2c0cf74 flags:# reason:string password:flags.0?InputCheckPasswordSRP = Bool; account.getAccountTTL#8fc711d = AccountDaysTTL; account.setAccountTTL#2442485e ttl:AccountDaysTTL = Bool; account.sendChangePhoneCode#82574ae5 phone_number:string settings:CodeSettings = auth.SentCode; @@ -1546,7 +1562,7 @@ messages.getMessagesViews#5784d3e1 peer:InputPeer id:Vector increment:Bool messages.editChatAdmin#a85bd1c2 chat_id:long user_id:InputUser is_admin:Bool = Bool; messages.migrateChat#a2875319 chat_id:long = Updates; messages.searchGlobal#4bc6589a flags:# folder_id:flags.0?int q:string filter:MessagesFilter min_date:int max_date:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; -messages.reorderStickerSets#78337739 flags:# masks:flags.0?true order:Vector = Bool; +messages.reorderStickerSets#78337739 flags:# masks:flags.0?true emojis:flags.1?true order:Vector = Bool; messages.getDocumentByHash#b1f2061f sha256:bytes size:long mime_type:string = Document; messages.getSavedGifs#5cf09635 hash:long = messages.SavedGifs; messages.saveGif#327a30cb id:InputDocument unsave:Bool = Bool; @@ -1566,7 +1582,7 @@ messages.readFeaturedStickers#5b118126 id:Vector = Bool; messages.getRecentStickers#9da9403b flags:# attached:flags.0?true hash:long = messages.RecentStickers; messages.saveRecentSticker#392718f8 flags:# attached:flags.0?true id:InputDocument unsave:Bool = Bool; messages.clearRecentStickers#8999602d flags:# attached:flags.0?true = Bool; -messages.getArchivedStickers#57f17692 flags:# masks:flags.0?true offset_id:long limit:int = messages.ArchivedStickers; +messages.getArchivedStickers#57f17692 flags:# masks:flags.0?true emojis:flags.1?true offset_id:long limit:int = messages.ArchivedStickers; messages.getMaskStickers#640f82b8 hash:long = messages.AllStickers; messages.getAttachedStickers#cc5b67cc media:InputStickeredMedia = Vector; messages.setGameScore#8ef8ecc0 flags:# edit_message:flags.0?true force:flags.1?true peer:InputPeer id:int user_id:InputUser score:int = Updates; @@ -1667,6 +1683,9 @@ messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInl messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates; messages.transcribeAudio#269e9a49 peer:InputPeer msg_id:int = messages.TranscribedAudio; messages.rateTranscribedAudio#7f1d072f peer:InputPeer msg_id:int transcription_id:long good:Bool = Bool; +messages.getCustomEmojiDocuments#d9ab0f54 document_id:Vector = Vector; +messages.getEmojiStickers#fbfca18f hash:long = messages.AllStickers; +messages.getFeaturedEmojiStickers#ecf6736 hash:long = messages.FeaturedStickers; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1770,10 +1789,9 @@ payments.getSavedInfo#227d824b = payments.SavedInfo; payments.clearSavedInfo#d83d70c1 flags:# credentials:flags.0?true info:flags.1?true = Bool; payments.getBankCardData#2e79d779 number:string = payments.BankCardData; payments.exportInvoice#f91b065 invoice_media:InputMedia = payments.ExportedInvoice; -payments.assignAppStoreTransaction#fec13c6 flags:# restore:flags.0?true transaction_id:string receipt:bytes = Updates; -payments.assignPlayMarketTransaction#4faa4aed purchase_token:string = Updates; -payments.restorePlayMarketReceipt#d164e36a receipt:bytes = Updates; -payments.canPurchasePremium#aa6a90c8 = Bool; +payments.assignAppStoreTransaction#80ed747d receipt:bytes purpose:InputStorePaymentPurpose = Updates; +payments.assignPlayMarketTransaction#dffd50d3 receipt:DataJSON purpose:InputStorePaymentPurpose = Updates; +payments.canPurchasePremium#9fc19eb6 purpose:InputStorePaymentPurpose = Bool; payments.requestRecurringPayment#146e958d user_id:InputUser recurring_init_charge:string invoice_media:InputMedia = Updates; stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet; @@ -1831,4 +1849,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 143 \ No newline at end of file +// LAYER 144 \ No newline at end of file From e1923508f68c00892e460009c28153181db6c0e4 Mon Sep 17 00:00:00 2001 From: Davide Galilei <43778739+DavideGalilei@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:07:31 +0200 Subject: [PATCH 336/539] Fixed edit_inline_media once again (#1052) Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- .../methods/messages/edit_inline_media.py | 108 +++++++++++------- 1 file changed, 64 insertions(+), 44 deletions(-) diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 4126c802fb..81aa30ee6b 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -18,6 +18,7 @@ import os import re +import io import asyncio import io @@ -77,21 +78,41 @@ async def edit_inline_media( caption = media.caption parse_mode = media.parse_mode - if isinstance(media, types.InputMediaPhoto): - if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): + is_photo = isinstance(media, types.InputMediaPhoto) + + is_bytes_io = isinstance(media.media, io.BytesIO) + is_uploaded_file = is_bytes_io or os.path.isfile(media.media) + + is_external_url = not is_uploaded_file and re.match("^https?://", media.media) + + if is_bytes_io and not hasattr(media.media, "name"): + media.media.name = "media" + + if is_uploaded_file: + filename_attribute = [ + raw.types.DocumentAttributeFilename( + file_name=media.media.name if is_bytes_io else os.path.basename(media.media) + ) + ] + else: + filename_attribute = [] + + + if is_photo: + if is_uploaded_file: media = raw.types.InputMediaUploadedPhoto( file=await self.save_file(media.media) ) - elif re.match("^https?://", media.media): + elif is_external_url: media = raw.types.InputMediaPhotoExternal( url=media.media ) else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) elif isinstance(media, types.InputMediaVideo): - if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): + if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(media.media) or "video/mp4", + mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "video/mp4", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), attributes=[ @@ -100,22 +121,19 @@ async def edit_inline_media( duration=media.duration, w=media.width, h=media.height - ), - raw.types.DocumentAttributeFilename( - file_name=os.path.basename(media.media) ) - ] + ] + filename_attribute ) - elif re.match("^https?://", media.media): + elif is_external_url: media = raw.types.InputMediaDocumentExternal( url=media.media ) else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) elif isinstance(media, types.InputMediaAudio): - if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): + if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(media.media) or "audio/mpeg", + mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "audio/mpeg", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), attributes=[ @@ -123,22 +141,19 @@ async def edit_inline_media( duration=media.duration, performer=media.performer, title=media.title - ), - raw.types.DocumentAttributeFilename( - file_name=os.path.basename(media.media) ) - ] + ] + filename_attribute ) - elif re.match("^https?://", media.media): + elif is_external_url: media = raw.types.InputMediaDocumentExternal( url=media.media ) else: media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO) elif isinstance(media, types.InputMediaAnimation): - if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): + if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(media.media) or "video/mp4", + mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "video/mp4", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), attributes=[ @@ -148,33 +163,26 @@ async def edit_inline_media( w=media.width, h=media.height ), - raw.types.DocumentAttributeFilename( - file_name=os.path.basename(media.media) - ), raw.types.DocumentAttributeAnimated() - ], + ] + filename_attribute, nosound_video=True ) - elif re.match("^https?://", media.media): + elif is_external_url: media = raw.types.InputMediaDocumentExternal( url=media.media ) else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) elif isinstance(media, types.InputMediaDocument): - if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): + if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(media.media) or "application/zip", + mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "application/zip", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), - attributes=[ - raw.types.DocumentAttributeFilename( - file_name=os.path.basename(media.media) - ) - ], + attributes=filename_attribute, force_file=True ) - elif re.match("^https?://", media.media): + elif is_external_url: media = raw.types.InputMediaDocumentExternal( url=media.media ) @@ -186,25 +194,37 @@ async def edit_inline_media( session = await get_session(self, dc_id) - actual_media = await self.invoke( - raw.functions.messages.UploadMedia( - peer=raw.types.InputPeerSelf(), - media=media + + if is_uploaded_file: + uploaded_media = await self.invoke( + raw.functions.messages.UploadMedia( + peer=raw.types.InputPeerSelf(), + media=media + ) + ) + + actual_media = raw.types.InputMediaPhoto( + id=raw.types.InputPhoto( + id=uploaded_media.photo.id, + access_hash=uploaded_media.photo.access_hash, + file_reference=uploaded_media.photo.file_reference + ) + ) if is_photo else raw.types.InputMediaDocument( + id=raw.types.InputDocument( + id=uploaded_media.document.id, + access_hash=uploaded_media.document.access_hash, + file_reference=uploaded_media.document.file_reference + ) ) - ) + else: + actual_media = media for i in range(self.MAX_RETRIES): try: return await session.invoke( raw.functions.messages.EditInlineBotMessage( id=unpacked, - media=raw.types.InputMediaDocument( - id=raw.types.InputDocument( - id=actual_media.document.id, - access_hash=actual_media.document.access_hash, - file_reference=actual_media.document.file_reference - ) - ), + media=actual_media, reply_markup=await reply_markup.write(self) if reply_markup else None, **await self.parser.parse(caption, parse_mode) ), From c26c1004ad94f032db28ded23dd630f9f8af000e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:08:07 +0200 Subject: [PATCH 337/539] Update Pyrogram to v2.0.36 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 95fa60c7ba..2e6ca3ac4d 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.35" +__version__ = "2.0.36" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From cd69fb6d76193175a8dd2a298c69802e921479fb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Aug 2022 17:18:08 +0200 Subject: [PATCH 338/539] Add support for CUSTOM_EMOJI message entity type --- pyrogram/enums/message_entity_type.py | 3 +++ .../types/messages_and_media/message_entity.py | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pyrogram/enums/message_entity_type.py b/pyrogram/enums/message_entity_type.py index 34655d37f9..4db75f93f7 100644 --- a/pyrogram/enums/message_entity_type.py +++ b/pyrogram/enums/message_entity_type.py @@ -77,5 +77,8 @@ class MessageEntityType(AutoName): BANK_CARD = raw.types.MessageEntityBankCard "Bank card text" + CUSTOM_EMOJI = raw.types.MessageEntityCustomEmoji + "Custom emoji" + UNKNOWN = raw.types.MessageEntityUnknown "Unknown message entity type" diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index 8a880a1fad..ac14b62143 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -40,13 +40,17 @@ class MessageEntity(Object): Length of the entity in UTF-16 code units. url (``str``, *optional*): - For "text_link" only, url that will be opened after user taps on the text. + For :obj:`~pyrogram.enums.MessageEntityType.TEXT_LINK` only, url that will be opened after user taps on the text. user (:obj:`~pyrogram.types.User`, *optional*): - For "text_mention" only, the mentioned user. + For :obj:`~pyrogram.enums.MessageEntityType.TEXT_MENTION` only, the mentioned user. - language (``str``. *optional*): + language (``str``, *optional*): For "pre" only, the programming language of the entity text. + + custom_emoji_id (``int``, *optional*): + For :obj:`~pyrogram.enums.MessageEntityType.CUSTOM_EMOJI` only, unique identifier of the custom emoji. + Use :meth:`~pyrogram.Client.get_custom_emoji_stickers` to get full information about the sticker. """ def __init__( @@ -58,7 +62,8 @@ def __init__( length: int, url: str = None, user: "types.User" = None, - language: str = None + language: str = None, + custom_emoji_id: int = None ): super().__init__(client) @@ -68,6 +73,7 @@ def __init__( self.url = url self.user = user self.language = language + self.custom_emoji_id = custom_emoji_id @staticmethod def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["MessageEntity"]: @@ -87,6 +93,7 @@ def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["M url=getattr(entity, "url", None), user=types.User._parse(client, users.get(user_id, None)), language=getattr(entity, "language", None), + custom_emoji_id=getattr(entity, "document_id", None), client=client ) @@ -105,6 +112,9 @@ async def write(self): if self.language is None: args.pop("language") + if self.custom_emoji_id is None: + args.pop("custom_emoji_id") + entity = self.type.value if entity is raw.types.MessageEntityMentionName: From 8c399323c875b31b8417d6893f78dc38d978dceb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Aug 2022 17:33:13 +0200 Subject: [PATCH 339/539] Add new method get_custom_emoji_stickers --- compiler/docs/compiler.py | 1 + pyrogram/methods/messages/__init__.py | 4 +- .../messages/get_custom_emoji_stickers.py | 60 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/messages/get_custom_emoji_stickers.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index a1cc115eae..05ab23fd53 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -194,6 +194,7 @@ def get_title_list(s: str) -> list: get_discussion_message get_discussion_replies get_discussion_replies_count + get_custom_emoji_stickers """, chats=""" Chats diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index dafce11e4f..7a5d2d49be 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -31,6 +31,7 @@ from .forward_messages import ForwardMessages from .get_chat_history import GetChatHistory from .get_chat_history_count import GetChatHistoryCount +from .get_custom_emoji_stickers import GetCustomEmojiStickers from .get_discussion_message import GetDiscussionMessage from .get_discussion_replies import GetDiscussionReplies from .get_discussion_replies_count import GetDiscussionRepliesCount @@ -112,6 +113,7 @@ class Messages( SendReaction, GetDiscussionReplies, GetDiscussionRepliesCount, - StreamMedia + StreamMedia, + GetCustomEmojiStickers ): pass diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py new file mode 100644 index 0000000000..de5d8d4a61 --- /dev/null +++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py @@ -0,0 +1,60 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 typing import List + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class GetCustomEmojiStickers: + async def get_custom_emoji_stickers( + self: "pyrogram.Client", + custom_emoji_ids: List[int], + ) -> List["types.Sticker"]: + """Get information about custom emoji stickers by their identifiers. + + Parameters: + custom_emoji_ids (``int``): + List of custom emoji identifiers. + At most 200 custom emoji identifiers can be specified. + + Returns: + List of :obj:`~pyrogram.types.Sticker`: On success, a list of sticker objects is returned. + """ + result = await self.invoke( + raw.functions.messages.GetCustomEmojiDocuments( + document_id=custom_emoji_ids + ) + ) + + stickers = [] + for item in result: + attributes = {type(i): i for i in item.attributes} + + sticker = await types.Sticker._parse( + self, item, + attributes[raw.types.DocumentAttributeImageSize], + attributes[raw.types.DocumentAttributeCustomEmoji], + attributes[raw.types.DocumentAttributeFilename].file_name + ) + + stickers.append(sticker) + + return pyrogram.types.List(stickers) From 78fe290b404a4368ad0b700418afcb9e8fb72dc7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Aug 2022 17:38:41 +0200 Subject: [PATCH 340/539] Update Pyrogram to v2.0.37 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2e6ca3ac4d..406c48077f 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.36" +__version__ = "2.0.37" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 9aefff9f8db13ea4a962fc13d3ad10d96db1508b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Aug 2022 18:20:05 +0200 Subject: [PATCH 341/539] Fix join applications for public chats --- pyrogram/types/user_and_chats/chat_invite_link.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat_invite_link.py b/pyrogram/types/user_and_chats/chat_invite_link.py index 7aaa56a8cf..59f6315ba5 100644 --- a/pyrogram/types/user_and_chats/chat_invite_link.py +++ b/pyrogram/types/user_and_chats/chat_invite_link.py @@ -18,6 +18,7 @@ from datetime import datetime from typing import Dict +from typing import Optional import pyrogram from pyrogram import raw, utils @@ -103,7 +104,10 @@ def _parse( client: "pyrogram.Client", invite: "raw.base.ExportedChatInvite", users: Dict[int, "raw.types.User"] = None - ) -> "ChatInviteLink": + ) -> Optional["ChatInviteLink"]: + if not isinstance(invite, raw.types.ChatInviteExported): + return None + creator = ( types.User._parse(client, users[invite.admin_id]) if users is not None From 6c34c83a3ea82bd0c3d4f0e7bdff6f54c2f7bdbc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Aug 2022 18:20:31 +0200 Subject: [PATCH 342/539] Update Pyrogram to v2.0.38 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 406c48077f..863baf92d4 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.37" +__version__ = "2.0.38" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 6b7e5dcd1aa498795a2db6ae6b012ebb6aee2a5c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Aug 2022 10:46:48 +0200 Subject: [PATCH 343/539] Fix sending custom emoji --- pyrogram/types/messages_and_media/message_entity.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index ac14b62143..d2bf654dcd 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -112,8 +112,9 @@ async def write(self): if self.language is None: args.pop("language") - if self.custom_emoji_id is None: - args.pop("custom_emoji_id") + args.pop("custom_emoji_id") + if self.custom_emoji_id is not None: + args["document_id"] = self.custom_emoji_id entity = self.type.value From 95de5f7eae4f53b600310f165b6f973c6f8895f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=D1=91Nya?= <47749563+L3Nya@users.noreply.github.com> Date: Sun, 14 Aug 2022 11:50:48 +0300 Subject: [PATCH 344/539] Fix determining video sticker resolution. Add sticker duration to Sticker type (#1065) --- .../methods/messages/get_custom_emoji_stickers.py | 5 +++-- pyrogram/types/messages_and_media/message.py | 3 ++- pyrogram/types/messages_and_media/sticker.py | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py index de5d8d4a61..8e1b2a4c9e 100644 --- a/pyrogram/methods/messages/get_custom_emoji_stickers.py +++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py @@ -50,9 +50,10 @@ async def get_custom_emoji_stickers( sticker = await types.Sticker._parse( self, item, - attributes[raw.types.DocumentAttributeImageSize], + attributes[raw.types.DocumentAttributeImageSize] if raw.types.DocumentAttributeImageSize in attributes else None, attributes[raw.types.DocumentAttributeCustomEmoji], - attributes[raw.types.DocumentAttributeFilename].file_name + attributes[raw.types.DocumentAttributeFilename].file_name, + attributes[raw.types.DocumentAttributeVideo] if raw.types.DocumentAttributeVideo in attributes else None ) stickers.append(sticker) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 56e4d7feec..06d9d716fe 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -700,7 +700,8 @@ async def _parse( client, doc, attributes.get(raw.types.DocumentAttributeImageSize, None), attributes[raw.types.DocumentAttributeSticker], - file_name + file_name, + attributes.get(raw.types.DocumentAttributeVideo, None) ) media_type = enums.MessageMediaType.STICKER elif raw.types.DocumentAttributeVideo in attributes: diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index 201b579f17..019fc180c7 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -50,6 +50,9 @@ class Sticker(Object): is_video (``bool``): True, if the sticker is a video sticker + duration (``int``): + Video sticker duration in seconds. + file_name (``str``, *optional*): Sticker file name. @@ -84,6 +87,7 @@ def __init__( height: int, is_animated: bool, is_video: bool, + duration: int = None, file_name: str = None, mime_type: str = None, file_size: int = None, @@ -148,7 +152,8 @@ async def _parse( sticker: "raw.types.Document", image_size_attributes: "raw.types.DocumentAttributeImageSize", sticker_attributes: "raw.types.DocumentAttributeSticker", - file_name: str + file_name: str, + video_attributes: "raw.types.DocumentAttributeVideo" ) -> "Sticker": sticker_set = sticker_attributes.stickerset @@ -170,10 +175,11 @@ async def _parse( file_unique_type=FileUniqueType.DOCUMENT, media_id=sticker.id ).encode(), - width=image_size_attributes.w if image_size_attributes else 512, - height=image_size_attributes.h if image_size_attributes else 512, + width=image_size_attributes.w if image_size_attributes else (video_attributes.w if video_attributes else 512), + height=image_size_attributes.h if image_size_attributes else (video_attributes.h if video_attributes else 512), is_animated=sticker.mime_type == "application/x-tgsticker", is_video=sticker.mime_type == "video/webm", + duration=video_attributes.duration if video_attributes else None, # TODO: mask_position set_name=set_name, emoji=sticker_attributes.alt or None, From 2e46514012167b84d5f984fcd00917af0420866d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Aug 2022 11:19:01 +0200 Subject: [PATCH 345/539] Refactor Sticker parsing --- .../messages/get_custom_emoji_stickers.py | 10 +----- pyrogram/types/messages_and_media/message.py | 8 +---- pyrogram/types/messages_and_media/sticker.py | 36 ++++++++++++------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py index 8e1b2a4c9e..f781bf6e55 100644 --- a/pyrogram/methods/messages/get_custom_emoji_stickers.py +++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py @@ -47,15 +47,7 @@ async def get_custom_emoji_stickers( stickers = [] for item in result: attributes = {type(i): i for i in item.attributes} - - sticker = await types.Sticker._parse( - self, item, - attributes[raw.types.DocumentAttributeImageSize] if raw.types.DocumentAttributeImageSize in attributes else None, - attributes[raw.types.DocumentAttributeCustomEmoji], - attributes[raw.types.DocumentAttributeFilename].file_name, - attributes[raw.types.DocumentAttributeVideo] if raw.types.DocumentAttributeVideo in attributes else None - ) - + sticker = await types.Sticker._parse(self, item, attributes) stickers.append(sticker) return pyrogram.types.List(stickers) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 06d9d716fe..146e37c4a9 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -696,13 +696,7 @@ async def _parse( animation = types.Animation._parse(client, doc, video_attributes, file_name) media_type = enums.MessageMediaType.ANIMATION elif raw.types.DocumentAttributeSticker in attributes: - sticker = await types.Sticker._parse( - client, doc, - attributes.get(raw.types.DocumentAttributeImageSize, None), - attributes[raw.types.DocumentAttributeSticker], - file_name, - attributes.get(raw.types.DocumentAttributeVideo, None) - ) + sticker = await types.Sticker._parse(client, doc, attributes) media_type = enums.MessageMediaType.STICKER elif raw.types.DocumentAttributeVideo in attributes: video_attributes = attributes[raw.types.DocumentAttributeVideo] diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index 019fc180c7..56ddf2afed 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from datetime import datetime -from typing import List +from typing import List, Dict, Type import pyrogram from pyrogram import raw, utils @@ -50,9 +50,6 @@ class Sticker(Object): is_video (``bool``): True, if the sticker is a video sticker - duration (``int``): - Video sticker duration in seconds. - file_name (``str``, *optional*): Sticker file name. @@ -87,7 +84,6 @@ def __init__( height: int, is_animated: bool, is_video: bool, - duration: int = None, file_name: str = None, mime_type: str = None, file_size: int = None, @@ -150,11 +146,16 @@ async def _get_sticker_set_name(invoke, input_sticker_set_id): async def _parse( client, sticker: "raw.types.Document", - image_size_attributes: "raw.types.DocumentAttributeImageSize", - sticker_attributes: "raw.types.DocumentAttributeSticker", - file_name: str, - video_attributes: "raw.types.DocumentAttributeVideo" + document_attributes: Dict[Type["raw.base.DocumentAttribute"], "raw.base.DocumentAttribute"], ) -> "Sticker": + sticker_attributes = document_attributes.get( + raw.types.DocumentAttributeSticker, + document_attributes[raw.types.DocumentAttributeCustomEmoji] + ) + image_size_attributes = document_attributes.get(raw.types.DocumentAttributeImageSize, None) + file_name = getattr(document_attributes.get(raw.types.DocumentAttributeFilename, None), "file_name", None) + video_attributes = document_attributes.get(raw.types.DocumentAttributeVideo, None) + sticker_set = sticker_attributes.stickerset if isinstance(sticker_set, raw.types.InputStickerSetID): @@ -175,11 +176,22 @@ async def _parse( file_unique_type=FileUniqueType.DOCUMENT, media_id=sticker.id ).encode(), - width=image_size_attributes.w if image_size_attributes else (video_attributes.w if video_attributes else 512), - height=image_size_attributes.h if image_size_attributes else (video_attributes.h if video_attributes else 512), + width=( + image_size_attributes.w + if image_size_attributes + else video_attributes.w + if video_attributes + else 512 + ), + height=( + image_size_attributes.h + if image_size_attributes + else video_attributes.h + if video_attributes + else 512 + ), is_animated=sticker.mime_type == "application/x-tgsticker", is_video=sticker.mime_type == "video/webm", - duration=video_attributes.duration if video_attributes else None, # TODO: mask_position set_name=set_name, emoji=sticker_attributes.alt or None, From bb450d1cefcaf7f9d08808a5c8fbe63b04479e00 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Aug 2022 11:31:10 +0200 Subject: [PATCH 346/539] Update Pyrogram to v2.0.39 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 863baf92d4..1b1b385120 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.38" +__version__ = "2.0.39" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 803f8f0073a38a3c0724354e76f1f358fa5c252d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Aug 2022 22:37:09 +0200 Subject: [PATCH 347/539] Fix Sticker parsing --- pyrogram/types/messages_and_media/sticker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index 56ddf2afed..de266b2fd2 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -148,10 +148,12 @@ async def _parse( sticker: "raw.types.Document", document_attributes: Dict[Type["raw.base.DocumentAttribute"], "raw.base.DocumentAttribute"], ) -> "Sticker": - sticker_attributes = document_attributes.get( - raw.types.DocumentAttributeSticker, - document_attributes[raw.types.DocumentAttributeCustomEmoji] + sticker_attributes = ( + document_attributes[raw.types.DocumentAttributeSticker] + if raw.types.DocumentAttributeSticker in document_attributes + else document_attributes[raw.types.DocumentAttributeCustomEmoji] ) + image_size_attributes = document_attributes.get(raw.types.DocumentAttributeImageSize, None) file_name = getattr(document_attributes.get(raw.types.DocumentAttributeFilename, None), "file_name", None) video_attributes = document_attributes.get(raw.types.DocumentAttributeVideo, None) From 2242adb5984e5e09ff970a3c6853e972c5c8ccd8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Aug 2022 22:37:26 +0200 Subject: [PATCH 348/539] Update Pyrogram to v2.0.40 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 1b1b385120..6b03880911 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.39" +__version__ = "2.0.40" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From f5bcce7c3f96e9ebfb87791f69ee96f649ab481c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Aug 2022 08:59:06 +0200 Subject: [PATCH 349/539] Add support for custom emoji in HTML --- docs/source/topics/text-formatting.rst | 2 ++ pyrogram/parser/html.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index 4e11fb7410..00aa0cf8c8 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -122,6 +122,8 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.HTML` to the *parse_mode* inline fixed-width code + 🔥 +
     pre-formatted
       fixed-width
diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index d9a8d36876..29c8c4a6b9 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -75,6 +75,10 @@ def handle_starttag(self, tag, attrs):
             else:
                 entity = raw.types.MessageEntityTextUrl
                 extra["url"] = url
+        elif tag == "emoji":
+            entity = raw.types.MessageEntityCustomEmoji
+            custom_emoji_id = int(attrs.get("id"))
+            extra["document_id"] = custom_emoji_id
         else:
             return
 
@@ -185,6 +189,10 @@ def unparse(text: str, entities: list):
                 user = entity.user
                 start_tag = f''
                 end_tag = ""
+            elif entity_type == MessageEntityType.CUSTOM_EMOJI:
+                custom_emoji_id = entity.custom_emoji_id
+                start_tag = f''
+                end_tag = ""
             else:
                 continue
 

From ac0941109904d644578c7a971a19540dc01862ad Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 16 Aug 2022 08:59:32 +0200
Subject: [PATCH 350/539] Update Pyrogram to v2.0.41

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 6b03880911..bd8ee26292 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.40"
+__version__ = "2.0.41"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From cb5431d976e11ea9444075e4de88b8e23ffbf35b Mon Sep 17 00:00:00 2001
From: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
Date: Wed, 17 Aug 2022 23:58:47 +0800
Subject: [PATCH 351/539] Fix get_custom_emoji_stickers parameter type in docs
 (#1066)

* Fix get_custom_emoji_stickers Int type

* Fix misleading docstring

* Update get_custom_emoji_stickers.py

* Update get_custom_emoji_stickers.py

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/methods/messages/get_custom_emoji_stickers.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py
index f781bf6e55..335f4ce9d5 100644
--- a/pyrogram/methods/messages/get_custom_emoji_stickers.py
+++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py
@@ -31,7 +31,7 @@ async def get_custom_emoji_stickers(
         """Get information about custom emoji stickers by their identifiers.
 
         Parameters:
-            custom_emoji_ids (``int``):
+            custom_emoji_ids (List of ``int``):
                 List of custom emoji identifiers.
                 At most 200 custom emoji identifiers can be specified.
 

From 371700ddec1080f5802868f0e2887d2fe384d791 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 28 Aug 2022 13:59:03 +0200
Subject: [PATCH 352/539] Update FAQ

---
 docs/source/faq/index.rst                           |  4 ++--
 ...d-oserror-timeouterror-connection-lost-reset.rst | 12 ++++++++++++
 ...t-send-raised-exception-oserror-timeouterror.rst | 13 -------------
 3 files changed, 14 insertions(+), 15 deletions(-)
 create mode 100644 docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
 delete mode 100644 docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst

diff --git a/docs/source/faq/index.rst b/docs/source/faq/index.rst
index e5bef2be0f..3d4a00362b 100644
--- a/docs/source/faq/index.rst
+++ b/docs/source/faq/index.rst
@@ -19,7 +19,7 @@ This FAQ page provides answers to common questions about Pyrogram and, to some e
 - :doc:`uploading-with-urls-gives-error-webpage-curl-failed`
 - :doc:`sqlite3-operationalerror-database-is-locked`
 - :doc:`sqlite3-interfaceerror-error-binding-parameter`
-- :doc:`socket-send-raised-exception-oserror-timeouterror`
+- :doc:`socket-send-oserror-timeouterror-connection-lost-reset`
 - :doc:`how-to-avoid-flood-waits`
 - :doc:`the-account-has-been-limited-deactivated`
 
@@ -40,6 +40,6 @@ This FAQ page provides answers to common questions about Pyrogram and, to some e
     uploading-with-urls-gives-error-webpage-curl-failed
     sqlite3-operationalerror-database-is-locked
     sqlite3-interfaceerror-error-binding-parameter
-    socket-send-raised-exception-oserror-timeouterror
+    socket-send-oserror-timeouterror-connection-lost-reset
     how-to-avoid-flood-waits
     the-account-has-been-limited-deactivated
\ No newline at end of file
diff --git a/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst b/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
new file mode 100644
index 0000000000..85c5065015
--- /dev/null
+++ b/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
@@ -0,0 +1,12 @@
+socket.send(), OSError(), TimeoutError(), Connection lost/reset
+===============================================================
+
+If you get any of these errors chances are you ended up with a slow or inconsistent network connection.
+Another reason could be because you are blocking the event loop for too long.
+
+You can consider the following:
+
+- Use Pyrogram asynchronously in its intended way.
+- Use shorter non-asynchronous processing loops.
+- Use ``asyncio.sleep()`` instead of ``time.sleep()``.
+- Use a stable network connection.
diff --git a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst b/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst
deleted file mode 100644
index 4d9aa89de9..0000000000
--- a/docs/source/faq/socket-send-raised-exception-oserror-timeouterror.rst
+++ /dev/null
@@ -1,13 +0,0 @@
-socket.send() raised exception, OSError(), TimeoutError()
-=========================================================
-
-If you get this error chances are you or Telegram ended up with a slow or inconsistent network connection, which
-triggers internal timeouts due to data not being sent/received in time. Another reason could be because you are blocking
-the event loop for too long, most likely due to an improper use of non-asynchronous or threaded operations which may
-lead to blocking code that prevents the event loop from running properly.
-
-You can consider the following:
-
-- Use Pyrogram asynchronously in its intended way.
-- Use shorter non-asynchronous processing loops.
-- Use ``asyncio.sleep()`` instead of ``time.sleep()``.

From 95aae430a8ac5922553f3d15b6e6fd388828359f Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 28 Aug 2022 16:43:45 +0200
Subject: [PATCH 353/539] Fix serialization of empty optional lists

---
 compiler/api/compiler.py               | 2 +-
 pyrogram/methods/messages/send_poll.py | 7 +------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 7cbce6f396..c5372bff75 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -444,7 +444,7 @@ def start(format: bool = False):
                     sub_type = arg_type.split("<")[1][:-1]
 
                     write_types += "\n        "
-                    write_types += f"if self.{arg_name}:\n            "
+                    write_types += f"if self.{arg_name} is not None:\n            "
                     write_types += "b.write(Vector(self.{}{}))\n        ".format(
                         arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
                     )
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index 3f6f35d240..c5b606f1d0 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -131,15 +131,10 @@ async def send_poll(
                 await app.send_poll(chat_id, "Is this a poll question?", ["Yes", "No", "Maybe"])
         """
 
-        message, entities = (await utils.parse_text_entities(
+        solution, solution_entities = (await utils.parse_text_entities(
             self, explanation, explanation_parse_mode, explanation_entities
         )).values()
 
-        # For some reason passing None or [] as solution_entities will lead to INPUT_CONSTRUCTOR_INVALID_00
-        # Add a dummy message entity with no length as workaround
-        solution = message or None
-        solution_entities = entities or ([raw.types.MessageEntityBold(offset=0, length=0)] if solution else None)
-
         r = await self.invoke(
             raw.functions.messages.SendMedia(
                 peer=await self.resolve_peer(chat_id),

From f6e0e58f86ebf9f905ef72451adc6ece9a5c05f6 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 28 Aug 2022 16:44:07 +0200
Subject: [PATCH 354/539] Update Pyrogram to v2.0.42

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index bd8ee26292..0af921c26a 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.41"
+__version__ = "2.0.42"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From ed008dd3bb9e225c954812764f27391a44fea701 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 28 Aug 2022 20:32:43 +0200
Subject: [PATCH 355/539] Fix message entity parsing and serialization

---
 pyrogram/methods/messages/send_message.py        | 2 +-
 pyrogram/methods/messages/send_poll.py           | 2 +-
 pyrogram/parser/html.py                          | 2 +-
 pyrogram/parser/parser.py                        | 2 +-
 pyrogram/types/authorization/terms_of_service.py | 2 +-
 pyrogram/utils.py                                | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py
index 0a7ab6d102..b365880ed5 100644
--- a/pyrogram/methods/messages/send_message.py
+++ b/pyrogram/methods/messages/send_message.py
@@ -159,7 +159,7 @@ async def send_message(
                 entities=[
                     types.MessageEntity._parse(None, entity, {})
                     for entity in entities
-                ],
+                ] if entities else None,
                 client=self
             )
 
diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py
index c5b606f1d0..207cff9faf 100644
--- a/pyrogram/methods/messages/send_poll.py
+++ b/pyrogram/methods/messages/send_poll.py
@@ -155,7 +155,7 @@ async def send_poll(
                     ),
                     correct_answers=[bytes([correct_option_id])] if correct_option_id is not None else None,
                     solution=solution,
-                    solution_entities=solution_entities
+                    solution_entities=solution_entities or []
                 ),
                 message="",
                 silent=disable_notification,
diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index 29c8c4a6b9..dee8a49dd4 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -149,7 +149,7 @@ async def parse(self, text: str):
 
         return {
             "message": utils.remove_surrogates(parser.text),
-            "entities": sorted(entities, key=lambda e: e.offset)
+            "entities": sorted(entities, key=lambda e: e.offset) or None
         }
 
     @staticmethod
diff --git a/pyrogram/parser/parser.py b/pyrogram/parser/parser.py
index 16701b39ee..0ce2b2375c 100644
--- a/pyrogram/parser/parser.py
+++ b/pyrogram/parser/parser.py
@@ -49,7 +49,7 @@ async def parse(self, text: str, mode: Optional[enums.ParseMode] = None):
             return await self.html.parse(text)
 
         if mode == enums.ParseMode.DISABLED:
-            return {"message": text, "entities": []}
+            return {"message": text, "entities": None}
 
         raise ValueError(f'Invalid parse mode "{mode}"')
 
diff --git a/pyrogram/types/authorization/terms_of_service.py b/pyrogram/types/authorization/terms_of_service.py
index 7e1376ea1d..3c5ffa6c6d 100644
--- a/pyrogram/types/authorization/terms_of_service.py
+++ b/pyrogram/types/authorization/terms_of_service.py
@@ -52,5 +52,5 @@ def _parse(terms_of_service: "raw.types.help.TermsOfService") -> "TermsOfService
             entities=[
                 types.MessageEntity._parse(None, entity, {})
                 for entity in terms_of_service.entities
-            ]
+            ] if terms_of_service.entities else None
         )
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index b6a8d6bfb6..f7fe59706d 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -349,7 +349,7 @@ async def parse_text_entities(
         for entity in entities:
             entity._client = client
 
-        text, entities = text, [await entity.write() for entity in entities]
+        text, entities = text, [await entity.write() for entity in entities] or None
     else:
         text, entities = (await client.parser.parse(text, parse_mode)).values()
 

From 3bd082094632b026a3bc5ac5c24741daab564d36 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 28 Aug 2022 20:33:03 +0200
Subject: [PATCH 356/539] Update Pyrogram to v2.0.43

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 0af921c26a..65f78d0035 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.42"
+__version__ = "2.0.43"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 7055ee648e1a862d185277fb336c1d59ad3ee9bc Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 1 Sep 2022 21:27:59 +0200
Subject: [PATCH 357/539] Update get_peer_by_username query

---
 pyrogram/storage/sqlite_storage.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py
index f7fbb55bec..15e5ddc0c5 100644
--- a/pyrogram/storage/sqlite_storage.py
+++ b/pyrogram/storage/sqlite_storage.py
@@ -151,7 +151,8 @@ async def get_peer_by_id(self, peer_id: int):
 
     async def get_peer_by_username(self, username: str):
         r = self.conn.execute(
-            "SELECT id, access_hash, type, last_update_on FROM peers WHERE username = ?",
+            "SELECT id, access_hash, type, last_update_on FROM peers WHERE username = ?"
+            "ORDER BY last_update_on DESC",
             (username,)
         ).fetchone()
 

From 94c0031ed722d9248f176ba8dbc07a61b4829134 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 1 Sep 2022 21:28:18 +0200
Subject: [PATCH 358/539] Update Pyrogram to v2.0.44

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 65f78d0035..1989402303 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.43"
+__version__ = "2.0.44"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 88af58f246ceb4723215e52777318ebee7bd2eaa Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 2 Sep 2022 14:25:13 +0200
Subject: [PATCH 359/539] Fix nonce checks

---
 pyrogram/connection/transport/tcp/tcp_abridged_o.py     | 2 +-
 pyrogram/connection/transport/tcp/tcp_intermediate_o.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
index 12a832f6a9..c5a9f65f64 100644
--- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
@@ -42,7 +42,7 @@ async def connect(self, address: tuple):
         while True:
             nonce = bytearray(os.urandom(64))
 
-            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:4] != b"\x00" * 4:
+            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
                 nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xef
                 break
 
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
index 5b267661db..20eca3d4b9 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
@@ -42,7 +42,7 @@ async def connect(self, address: tuple):
         while True:
             nonce = bytearray(os.urandom(64))
 
-            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:4] != b"\x00" * 4:
+            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
                 nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xee
                 break
 

From 14c530327243cc390774601aa3638cc3ba433ff7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 2 Sep 2022 14:25:29 +0200
Subject: [PATCH 360/539] Update Pyrogram to v2.0.45

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 1989402303..4b21dc3bb6 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.44"
+__version__ = "2.0.45"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 761e4735d3701c5910450fb4ac8f6e09c7ff8d09 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 2 Sep 2022 14:44:02 +0200
Subject: [PATCH 361/539] More nonce check fixes

---
 pyrogram/connection/transport/tcp/tcp_abridged_o.py     | 2 +-
 pyrogram/connection/transport/tcp/tcp_intermediate_o.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
index c5a9f65f64..6f57ab1154 100644
--- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py
@@ -42,7 +42,7 @@ async def connect(self, address: tuple):
         while True:
             nonce = bytearray(os.urandom(64))
 
-            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
+            if bytes([nonce[0]]) != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
                 nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xef
                 break
 
diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
index 20eca3d4b9..48b2d44520 100644
--- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
+++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py
@@ -42,7 +42,7 @@ async def connect(self, address: tuple):
         while True:
             nonce = bytearray(os.urandom(64))
 
-            if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
+            if bytes([nonce[0]]) != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:8] != b"\x00" * 4:
                 nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xee
                 break
 

From 3632400956def8a8fa4219ac3f4c11c24e954f07 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 2 Sep 2022 14:44:16 +0200
Subject: [PATCH 362/539] Update Pyrogram to v2.0.46

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 4b21dc3bb6..92cccf4515 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.45"
+__version__ = "2.0.46"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 2cd0f386025865396bcb7905150be8b00fa242f1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:08:35 +0200
Subject: [PATCH 363/539] Update API schema to Layer 145

---
 compiler/api/source/main_api.tl | 98 ++++++++++++++++++++++++---------
 1 file changed, 73 insertions(+), 25 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index bf8a37ee72..465446b489 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -88,7 +88,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType;
 storage.fileWebp#1081464c = storage.FileType;
 
 userEmpty#d3bc4b7a id:long = User;
-user#3ff6ecb0 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User;
+user#5d99adee flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus = User;
 
 userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto;
 userProfilePhoto#82d1f706 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto;
@@ -106,8 +106,8 @@ chatForbidden#6592a1a7 id:long title:string = Chat;
 channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
 channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat;
 
-chatFull#d18ee226 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?Vector = ChatFull;
-channelFull#ea68a619 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?Vector = ChatFull;
+chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull;
+channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull;
 
 chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant;
 chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant;
@@ -302,7 +302,7 @@ updateChannelMessageViews#f226ac08 channel_id:long id:int views:int = Update;
 updateChatParticipantAdmin#d7ca61a2 chat_id:long user_id:long is_admin:Bool version:int = Update;
 updateNewStickerSet#688a30aa stickerset:messages.StickerSet = Update;
 updateStickerSetsOrder#bb2d201 flags:# masks:flags.0?true emojis:flags.1?true order:Vector = Update;
-updateStickerSets#43ae3dec = Update;
+updateStickerSets#31c24808 flags:# masks:flags.0?true emojis:flags.1?true = Update;
 updateSavedGifs#9375341e = Update;
 updateBotInlineQuery#496f379c flags:# query_id:long user_id:long query:string geo:flags.0?GeoPoint peer_type:flags.1?InlineQueryPeerType offset:string = Update;
 updateBotInlineSend#12f12a07 flags:# user_id:long query:string geo:flags.0?GeoPoint id:string msg_id:flags.1?InputBotInlineMessageID = Update;
@@ -371,6 +371,10 @@ updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update;
 updateSavedRingtones#74d8be99 = Update;
 updateTranscribedAudio#84cd5a flags:# pending:flags.0?true peer:Peer msg_id:int transcription_id:long text:string = Update;
 updateReadFeaturedEmojiStickers#fb4c496c = Update;
+updateUserEmojiStatus#28373599 user_id:long emoji_status:EmojiStatus = Update;
+updateRecentEmojiStatuses#30f443db = Update;
+updateRecentReactions#6f7863f4 = Update;
+updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update;
 
 updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
 
@@ -397,7 +401,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 this_port_only:flags.5?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption;
 
-config#330b4067 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 pfs_enabled:flags.13?true force_try_ipv6:flags.14?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 pinned_infolder_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 base_lang_pack_version:flags.2?int = Config;
+config#232566ac 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 pfs_enabled:flags.13?true force_try_ipv6:flags.14?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 pinned_infolder_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 base_lang_pack_version:flags.2?int reactions_default:flags.15?Reaction = Config;
 
 nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc;
 
@@ -535,7 +539,7 @@ authorization#ad01d61d flags:# current:flags.0?true official_app:flags.1?true pa
 
 account.authorizations#4bff8ea0 authorization_ttl_days:int authorizations:Vector = account.Authorizations;
 
-account.password#185b184f flags:# has_recovery:flags.0?true has_secure_values:flags.1?true has_password:flags.2?true current_algo:flags.2?PasswordKdfAlgo srp_B:flags.2?bytes srp_id:flags.2?long hint:flags.3?string email_unconfirmed_pattern:flags.4?string new_algo:PasswordKdfAlgo new_secure_algo:SecurePasswordKdfAlgo secure_random:bytes pending_reset_date:flags.5?int = account.Password;
+account.password#957b50fb flags:# has_recovery:flags.0?true has_secure_values:flags.1?true has_password:flags.2?true current_algo:flags.2?PasswordKdfAlgo srp_B:flags.2?bytes srp_id:flags.2?long hint:flags.3?string email_unconfirmed_pattern:flags.4?string new_algo:PasswordKdfAlgo new_secure_algo:SecurePasswordKdfAlgo secure_random:bytes pending_reset_date:flags.5?int login_email_pattern:flags.6?string = account.Password;
 
 account.passwordSettings#9a5c33e5 flags:# email:flags.0?string secure_settings:flags.1?SecureSecretSettings = account.PasswordSettings;
 
@@ -559,6 +563,8 @@ inputStickerSetAnimatedEmoji#28703c8 = InputStickerSet;
 inputStickerSetDice#e67f520e emoticon:string = InputStickerSet;
 inputStickerSetAnimatedEmojiAnimations#cde3739 = InputStickerSet;
 inputStickerSetPremiumGifts#c88b3b02 = InputStickerSet;
+inputStickerSetEmojiGenericAnimations#4c4d4ce = InputStickerSet;
+inputStickerSetEmojiDefaultStatuses#29d0f5ee = InputStickerSet;
 
 stickerSet#2dd14edc flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true videos:flags.6?true emojis:flags.7?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int thumb_document_id:flags.8?long count:int hash:int = StickerSet;
 
@@ -694,6 +700,8 @@ auth.sentCodeTypeSms#c000bba2 length:int = auth.SentCodeType;
 auth.sentCodeTypeCall#5353e5a7 length:int = auth.SentCodeType;
 auth.sentCodeTypeFlashCall#ab03c6d9 pattern:string = auth.SentCodeType;
 auth.sentCodeTypeMissedCall#82006484 prefix:string length:int = auth.SentCodeType;
+auth.sentCodeTypeEmailCode#5a159841 flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int next_phone_login_date:flags.2?int = auth.SentCodeType;
+auth.sentCodeTypeSetUpEmailRequired#a5491dea flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true = auth.SentCodeType;
 
 messages.botCallbackAnswer#36585ea4 flags:# alert:flags.1?true has_url:flags.3?true native_ui:flags.4?true message:flags.0?string url:flags.2?string cache_time:int = messages.BotCallbackAnswer;
 
@@ -920,7 +928,7 @@ channelAdminLogEventActionChangeHistoryTTL#6e941a38 prev_value:int new_value:int
 channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatInvite approved_by:long = ChannelAdminLogEventAction;
 channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
 channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction;
-channelAdminLogEventActionChangeAvailableReactions#9cf7f76a prev_value:Vector new_value:Vector = ChannelAdminLogEventAction;
+channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions = ChannelAdminLogEventAction;
 
 channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent;
 
@@ -1297,7 +1305,7 @@ searchResultPosition#7f648b67 msg_id:int date:int offset:int = SearchResultsPosi
 
 messages.searchResultsPositions#53b22baf count:int positions:Vector = messages.SearchResultsPositions;
 
-channels.sendAsPeers#8356cda9 peers:Vector chats:Vector users:Vector = channels.SendAsPeers;
+channels.sendAsPeers#f496b0c6 peers:Vector chats:Vector users:Vector = channels.SendAsPeers;
 
 users.userFull#3b6d152e full_user:UserFull chats:Vector users:Vector = users.UserFull;
 
@@ -1305,7 +1313,7 @@ messages.peerSettings#6880b94d settings:PeerSettings chats:Vector users:Ve
 
 auth.loggedOut#c3a2835f flags:# future_auth_token:flags.0?bytes = auth.LoggedOut;
 
-reactionCount#6fb250d1 flags:# chosen:flags.0?true reaction:string count:int = ReactionCount;
+reactionCount#a3d1cb80 flags:# chosen_order:flags.0?int reaction:Reaction count:int = ReactionCount;
 
 messageReactions#4f2b9479 flags:# min:flags.0?true can_see_list:flags.2?true results:Vector recent_reactions:flags.1?Vector = MessageReactions;
 
@@ -1319,7 +1327,7 @@ messages.availableReactions#768e3aad hash:int reactions:Vector video_sections:Vector videos:Vector currency:string monthly_amount:long users:Vector = help.PremiumPromo;
+help.premiumPromo#5334759c status_text:string status_entities:Vector video_sections:Vector videos:Vector period_options:Vector users:Vector = help.PremiumPromo;
 
 inputStorePaymentPremiumSubscription#a6751e66 flags:# restore:flags.0?true = InputStorePaymentPurpose;
 inputStorePaymentGiftPremium#616f7fe8 user_id:InputUser currency:string amount:long = InputStorePaymentPurpose;
@@ -1381,6 +1389,39 @@ premiumGiftOption#74c34319 flags:# months:int currency:string amount:long bot_ur
 
 paymentFormMethod#88f8f21b url:string title:string = PaymentFormMethod;
 
+emojiStatusEmpty#2de11aae = EmojiStatus;
+emojiStatus#929b619d document_id:long = EmojiStatus;
+emojiStatusUntil#fa30a8c7 document_id:long until:int = EmojiStatus;
+
+account.emojiStatusesNotModified#d08ce645 = account.EmojiStatuses;
+account.emojiStatuses#90c467d1 hash:long statuses:Vector = account.EmojiStatuses;
+
+reactionEmpty#79f5d419 = Reaction;
+reactionEmoji#1b2286b8 emoticon:string = Reaction;
+reactionCustomEmoji#8935fc73 document_id:long = Reaction;
+
+chatReactionsNone#eafc32bc = ChatReactions;
+chatReactionsAll#52928bca flags:# allow_custom:flags.0?true = ChatReactions;
+chatReactionsSome#661d4037 reactions:Vector = ChatReactions;
+
+messages.reactionsNotModified#b06fdbdf = messages.Reactions;
+messages.reactions#eafdf716 hash:long reactions:Vector = messages.Reactions;
+
+emailVerifyPurposeLoginSetup#4345be73 phone_number:string phone_code_hash:string = EmailVerifyPurpose;
+emailVerifyPurposeLoginChange#527d22eb = EmailVerifyPurpose;
+emailVerifyPurposePassport#bbf51685 = EmailVerifyPurpose;
+
+emailVerificationCode#922e55a9 code:string = EmailVerification;
+emailVerificationGoogle#db909ec2 token:string = EmailVerification;
+emailVerificationApple#96d074fd token:string = EmailVerification;
+
+account.emailVerified#2b96cd1b email:string = account.EmailVerified;
+account.emailVerifiedLogin#e1bb0d61 email:string sent_code:auth.SentCode = account.EmailVerified;
+
+premiumSubscriptionOption#b6f11ebe flags:# current:flags.1?true can_purchase_upgrade:flags.2?true months:int currency:string amount:long bot_url:string store_product:flags.0?string = PremiumSubscriptionOption;
+
+sendAsPeer#b81c7034 flags:# premium_required:flags.0?true peer:Peer = SendAsPeer;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1393,7 +1434,7 @@ invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X;
 
 auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode;
 auth.signUp#80eee427 phone_number:string phone_code_hash: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.signIn#8d52a951 flags:# phone_number:string phone_code_hash:string phone_code:flags.0?string email_verification:flags.1?EmailVerification = auth.Authorization;
 auth.logOut#3e72ba19 = auth.LoggedOut;
 auth.resetAuthorizations#9fab0d1a = Bool;
 auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization;
@@ -1449,8 +1490,8 @@ account.getAuthorizationForm#a929597a bot_id:long scope:string public_key:string
 account.acceptAuthorization#f3ed4c73 bot_id:long scope:string public_key:string value_hashes:Vector credentials:SecureCredentialsEncrypted = Bool;
 account.sendVerifyPhoneCode#a5a356f9 phone_number:string settings:CodeSettings = auth.SentCode;
 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.sendVerifyEmailCode#98e037bb purpose:EmailVerifyPurpose email:string = account.SentEmailCode;
+account.verifyEmail#32da4cf purpose:EmailVerifyPurpose verification:EmailVerification = account.EmailVerified;
 account.initTakeoutSession#8ef3eab0 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?long = account.Takeout;
 account.finishTakeoutSession#1d2652ee flags:# success:flags.0?true = Bool;
 account.confirmPasswordEmail#8fdf1920 code:string = Bool;
@@ -1487,6 +1528,10 @@ account.changeAuthorizationSettings#40f48462 flags:# hash:long encrypted_request
 account.getSavedRingtones#e1902288 hash:long = account.SavedRingtones;
 account.saveRingtone#3dea5b03 id:InputDocument unsave:Bool = account.SavedRingtone;
 account.uploadRingtone#831a83a2 file:InputFile file_name:string mime_type:string = Document;
+account.updateEmojiStatus#fbd3de6b emoji_status:EmojiStatus = Bool;
+account.getDefaultEmojiStatuses#d6753386 hash:long = account.EmojiStatuses;
+account.getRecentEmojiStatuses#f578105 hash:long = account.EmojiStatuses;
+account.clearRecentEmojiStatuses#18201aae = Bool;
 
 users.getUsers#d91a548 id:Vector = Vector;
 users.getFullUser#b60f5918 id:InputUser = users.UserFull;
@@ -1523,8 +1568,8 @@ messages.deleteHistory#b08f922a flags:# just_clear:flags.0?true revoke:flags.1?t
 messages.deleteMessages#e58e95d2 flags:# revoke:flags.0?true id:Vector = messages.AffectedMessages;
 messages.receivedMessages#5a954c0 max_id:int = Vector;
 messages.setTyping#58943ee2 flags:# peer:InputPeer top_msg_id:flags.0?int action:SendMessageAction = Bool;
-messages.sendMessage#d9d75a4 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
-messages.sendMedia#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMessage#d9d75a4 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMedia#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.forwardMessages#cc30290b flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true drop_author:flags.11?true drop_media_captions:flags.12?true noforwards:flags.14?true from_peer:InputPeer id:Vector random_id:Vector to_peer:InputPeer schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.reportSpam#cf1592db peer:InputPeer = Bool;
 messages.getPeerSettings#efd9a6a2 peer:InputPeer = messages.PeerSettings;
@@ -1604,7 +1649,7 @@ messages.faveSticker#b9ffc55b id:InputDocument unfave:Bool = Bool;
 messages.getUnreadMentions#46578472 peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
 messages.readMentions#f0189d3 peer:InputPeer = messages.AffectedHistory;
 messages.getRecentLocations#702a40e0 peer:InputPeer limit:int hash:long = messages.Messages;
-messages.sendMultiMedia#f803138f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMultiMedia#f803138f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.uploadEncryptedFile#5057c497 peer:InputEncryptedChat file:InputEncryptedFile = EncryptedFile;
 messages.searchStickerSets#35705b8a flags:# exclude_featured:flags.0?true q:string hash:long = messages.FoundStickerSets;
 messages.getSplitRanges#1cff7e08 = Vector;
@@ -1663,12 +1708,12 @@ messages.hideChatJoinRequest#7fe7e815 flags:# approved:flags.0?true peer:InputPe
 messages.hideAllChatJoinRequests#e085f4ea flags:# approved:flags.0?true peer:InputPeer link:flags.1?string = Updates;
 messages.toggleNoForwards#b11eafa2 peer:InputPeer enabled:Bool = Updates;
 messages.saveDefaultSendAs#ccfddf96 peer:InputPeer send_as:InputPeer = Bool;
-messages.sendReaction#25690ce4 flags:# big:flags.1?true peer:InputPeer msg_id:int reaction:flags.0?string = Updates;
+messages.sendReaction#d30d78d4 flags:# big:flags.1?true add_to_recent:flags.2?true peer:InputPeer msg_id:int reaction:flags.0?Vector = Updates;
 messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector = Updates;
-messages.getMessageReactionsList#e0ee6b77 flags:# peer:InputPeer id:int reaction:flags.0?string offset:flags.1?string limit:int = messages.MessageReactionsList;
-messages.setChatAvailableReactions#14050ea6 peer:InputPeer available_reactions:Vector = Updates;
+messages.getMessageReactionsList#461b3f48 flags:# peer:InputPeer id:int reaction:flags.0?Reaction offset:flags.1?string limit:int = messages.MessageReactionsList;
+messages.setChatAvailableReactions#feb16771 peer:InputPeer available_reactions:ChatReactions = Updates;
 messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions;
-messages.setDefaultReaction#d960c4d4 reaction:string = Bool;
+messages.setDefaultReaction#4f47a016 reaction:Reaction = Bool;
 messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?int text:flags.1?string from_lang:flags.2?string to_lang:string = messages.TranslatedText;
 messages.getUnreadReactions#e85bae1a peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
 messages.readReactions#82e251d7 peer:InputPeer = messages.AffectedHistory;
@@ -1676,9 +1721,9 @@ messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = mes
 messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots;
 messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
 messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool;
-messages.requestWebView#91b15831 flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = WebViewResult;
+messages.requestWebView#fc87a53c flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON platform:string reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = WebViewResult;
 messages.prolongWebView#ea5fbcce flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = Bool;
-messages.requestSimpleWebView#6abb2f73 flags:# bot:InputUser url:string theme_params:flags.0?DataJSON = SimpleWebViewResult;
+messages.requestSimpleWebView#299bec8e flags:# bot:InputUser url:string theme_params:flags.0?DataJSON platform:string = SimpleWebViewResult;
 messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
 messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates;
 messages.transcribeAudio#269e9a49 peer:InputPeer msg_id:int = messages.TranscribedAudio;
@@ -1686,6 +1731,10 @@ messages.rateTranscribedAudio#7f1d072f peer:InputPeer msg_id:int transcription_i
 messages.getCustomEmojiDocuments#d9ab0f54 document_id:Vector = Vector;
 messages.getEmojiStickers#fbfca18f hash:long = messages.AllStickers;
 messages.getFeaturedEmojiStickers#ecf6736 hash:long = messages.FeaturedStickers;
+messages.reportReaction#3f64c076 peer:InputPeer id:int reaction_peer:InputPeer = Bool;
+messages.getTopReactions#bb8125ba limit:int hash:long = messages.Reactions;
+messages.getRecentReactions#39461db2 limit:int hash:long = messages.Reactions;
+messages.clearRecentReactions#9dfeefb4 = Bool;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1792,7 +1841,6 @@ payments.exportInvoice#f91b065 invoice_media:InputMedia = payments.ExportedInvoi
 payments.assignAppStoreTransaction#80ed747d receipt:bytes purpose:InputStorePaymentPurpose = Updates;
 payments.assignPlayMarketTransaction#dffd50d3 receipt:DataJSON purpose:InputStorePaymentPurpose = Updates;
 payments.canPurchasePremium#9fc19eb6 purpose:InputStorePaymentPurpose = Bool;
-payments.requestRecurringPayment#146e958d user_id:InputUser recurring_init_charge:string invoice_media:InputMedia = Updates;
 
 stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet;
 stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet;
@@ -1849,4 +1897,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 144
\ No newline at end of file
+// LAYER 145
\ No newline at end of file

From 7a53c3da5769fc55037d40206a6a6cf12e2dbfa2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:10:27 +0200
Subject: [PATCH 364/539] Add support for emoji status

---
 compiler/docs/compiler.py                     |  1 +
 pyrogram/types/user_and_chats/__init__.py     |  4 +-
 pyrogram/types/user_and_chats/emoji_status.py | 67 +++++++++++++++++++
 pyrogram/types/user_and_chats/user.py         |  6 ++
 4 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 pyrogram/types/user_and_chats/emoji_status.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 05ab23fd53..a6f82f3229 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -385,6 +385,7 @@ def get_title_list(s: str) -> list:
             ChatJoiner
             Dialog
             Restriction
+            EmojiStatus
         """,
         messages_media="""
         Messages & Media
diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py
index a9b633599f..60ebd30980 100644
--- a/pyrogram/types/user_and_chats/__init__.py
+++ b/pyrogram/types/user_and_chats/__init__.py
@@ -30,6 +30,7 @@
 from .chat_preview import ChatPreview
 from .chat_privileges import ChatPrivileges
 from .dialog import Dialog
+from .emoji_status import EmojiStatus
 from .invite_link_importer import InviteLinkImporter
 from .restriction import Restriction
 from .user import User
@@ -59,5 +60,6 @@
     "VideoChatScheduled",
     "ChatJoinRequest",
     "ChatPrivileges",
-    "ChatJoiner"
+    "ChatJoiner",
+    "EmojiStatus"
 ]
diff --git a/pyrogram/types/user_and_chats/emoji_status.py b/pyrogram/types/user_and_chats/emoji_status.py
new file mode 100644
index 0000000000..99159dbc95
--- /dev/null
+++ b/pyrogram/types/user_and_chats/emoji_status.py
@@ -0,0 +1,67 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 datetime import datetime
+from typing import Optional
+
+import pyrogram
+from pyrogram import raw
+from pyrogram import utils
+from ..object import Object
+
+
+class EmojiStatus(Object):
+    """A user emoji status.
+
+    Parameters:
+        custom_emoji_id (``int``):
+            Custom emoji id.
+
+        until_date (:py:obj:`~datetime.datetime`, *optional*):
+            Valid until date.
+    """
+
+    def __init__(
+        self,
+        *,
+        client: "pyrogram.Client" = None,
+        custom_emoji_id: int,
+        until_date: Optional[datetime] = None
+    ):
+        super().__init__(client)
+
+        self.custom_emoji_id = custom_emoji_id
+        self.until_date = until_date
+
+    @staticmethod
+    def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatus"]:
+        if isinstance(emoji_status, raw.types.EmojiStatusEmpty):
+            return None
+
+        if isinstance(emoji_status, raw.types.EmojiStatus):
+            return EmojiStatus(
+                client=client,
+                custom_emoji_id=emoji_status.document_id
+            )
+
+        if isinstance(emoji_status, raw.types.EmojiStatusUntil):
+            return EmojiStatus(
+                client=client,
+                custom_emoji_id=emoji_status.document_id,
+                until_date=utils.timestamp_to_datetime(emoji_status.until)
+            )
diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index 4df3b17e76..2c9b58f8b6 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -121,6 +121,9 @@ class User(Object, Update):
         language_code (``str``, *optional*):
             IETF language tag of the user's language.
 
+        emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*):
+            Emoji status.
+
         dc_id (``int``, *optional*):
             User's or bot's assigned DC (data center). Available only in case the user has set a public profile photo.
             Note that this information is approximate; it is based on where Telegram stores a user profile pictures and
@@ -167,6 +170,7 @@ def __init__(
         next_offline_date: datetime = None,
         username: str = None,
         language_code: str = None,
+        emoji_status: Optional[str] = None,
         dc_id: int = None,
         phone_number: str = None,
         photo: "types.ChatPhoto" = None,
@@ -193,6 +197,7 @@ def __init__(
         self.next_offline_date = next_offline_date
         self.username = username
         self.language_code = language_code
+        self.emoji_status = emoji_status
         self.dc_id = dc_id
         self.phone_number = phone_number
         self.photo = photo
@@ -229,6 +234,7 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]:
             **User._parse_status(user.status, user.bot),
             username=user.username,
             language_code=user.lang_code,
+            emoji_status=types.EmojiStatus._parse(client, user.emoji_status),
             dc_id=getattr(user.photo, "dc_id", None),
             phone_number=user.phone,
             photo=types.ChatPhoto._parse(client, user.photo, user.id, user.access_hash),

From 1fb04b76163ea258924410204992c89255c98a94 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:41:53 +0200
Subject: [PATCH 365/539] Update EmojiStatus

---
 pyrogram/types/user_and_chats/emoji_status.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/pyrogram/types/user_and_chats/emoji_status.py b/pyrogram/types/user_and_chats/emoji_status.py
index 99159dbc95..746c98ef2c 100644
--- a/pyrogram/types/user_and_chats/emoji_status.py
+++ b/pyrogram/types/user_and_chats/emoji_status.py
@@ -50,9 +50,6 @@ def __init__(
 
     @staticmethod
     def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatus"]:
-        if isinstance(emoji_status, raw.types.EmojiStatusEmpty):
-            return None
-
         if isinstance(emoji_status, raw.types.EmojiStatus):
             return EmojiStatus(
                 client=client,
@@ -65,3 +62,5 @@ def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatu
                 custom_emoji_id=emoji_status.document_id,
                 until_date=utils.timestamp_to_datetime(emoji_status.until)
             )
+
+        return None

From fe7fcf344832b7092db70d0fb8175bbb37b805f2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:42:16 +0200
Subject: [PATCH 366/539] Update reaction.py

---
 pyrogram/types/messages_and_media/reaction.py | 48 +++++++++++++++----
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/pyrogram/types/messages_and_media/reaction.py b/pyrogram/types/messages_and_media/reaction.py
index 83dda5829b..9d6b9e24b2 100644
--- a/pyrogram/types/messages_and_media/reaction.py
+++ b/pyrogram/types/messages_and_media/reaction.py
@@ -16,7 +16,10 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import Optional
+
 import pyrogram
+from pyrogram import raw
 from ..object import Object
 
 
@@ -24,26 +27,53 @@ class Reaction(Object):
     """Contains information about a reaction.
 
     Parameters:
-        emoji (``str``):
+        emoji (``str``, *optional*):
             Reaction emoji.
 
-        count (``int``):
-            Reaction count.
+        custom_emoji_id (``int``, *optional*):
+            Custom emoji id.
 
-        chosen (``bool``):
-            Whether this is the chosen reaction.
+        count (``int``, *optional*):
+            Reaction count.
     """
 
     def __init__(
         self,
         *,
         client: "pyrogram.Client" = None,
-        emoji: str,
-        count: int,
-        chosen: bool
+        emoji: Optional[str] = None,
+        custom_emoji_id: Optional[int] = None,
+        count: Optional[int] = None
     ):
         super().__init__(client)
 
         self.emoji = emoji
+        self.custom_emoji_id = custom_emoji_id
         self.count = count
-        self.chosen = chosen
+
+    @staticmethod
+    def _parse(
+        client: "pyrogram.Client",
+        reaction: "raw.base.Reaction"
+    ) -> "Reaction":
+        if isinstance(reaction, raw.types.ReactionEmoji):
+            return Reaction(
+                client=client,
+                emoji=reaction.emoticon
+            )
+
+        if isinstance(reaction, raw.types.ReactionCustomEmoji):
+            return Reaction(
+                client=client,
+                custom_emoji_id=reaction.document_id
+            )
+
+    @staticmethod
+    def _parse_count(
+        client: "pyrogram.Client",
+        reaction_count: "raw.base.ReactionCount"
+    ) -> "Reaction":
+        reaction = Reaction._parse(client, reaction_count.reaction)
+        reaction.count = reaction_count.count
+
+        return reaction

From 9eb7589a7fbeb2986d987c38870edf8174d6deac Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:43:38 +0200
Subject: [PATCH 367/539] Add chat_reactions.py

---
 pyrogram/types/user_and_chats/__init__.py     |  4 +-
 pyrogram/types/user_and_chats/chat.py         |  6 +-
 .../types/user_and_chats/chat_reactions.py    | 69 +++++++++++++++++++
 3 files changed, 75 insertions(+), 4 deletions(-)
 create mode 100644 pyrogram/types/user_and_chats/chat_reactions.py

diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py
index 60ebd30980..348ecd9f3c 100644
--- a/pyrogram/types/user_and_chats/__init__.py
+++ b/pyrogram/types/user_and_chats/__init__.py
@@ -29,6 +29,7 @@
 from .chat_photo import ChatPhoto
 from .chat_preview import ChatPreview
 from .chat_privileges import ChatPrivileges
+from .chat_reactions import ChatReactions
 from .dialog import Dialog
 from .emoji_status import EmojiStatus
 from .invite_link_importer import InviteLinkImporter
@@ -61,5 +62,6 @@
     "ChatJoinRequest",
     "ChatPrivileges",
     "ChatJoiner",
-    "EmojiStatus"
+    "EmojiStatus",
+    "ChatReactions"
 ]
diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index dc345bbc63..aa727952e5 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -126,7 +126,7 @@ class Chat(Object):
             The default "send_as" chat.
             Returned only in :meth:`~pyrogram.Client.get_chat`.
 
-        available_reactions (List of ``str``, *optional*):
+        available_reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*):
             Available reactions in the chat.
             Returned only in :meth:`~pyrogram.Client.get_chat`.
     """
@@ -162,7 +162,7 @@ def __init__(
         distance: int = None,
         linked_chat: "types.Chat" = None,
         send_as_chat: "types.Chat" = None,
-        available_reactions: List[str] = None
+        available_reactions: Optional[List["types.Reaction"]] = None
     ):
         super().__init__(client)
 
@@ -345,7 +345,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
             if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported):
                 parsed_chat.invite_link = full_chat.exported_invite.link
 
-            parsed_chat.available_reactions = full_chat.available_reactions or None
+            parsed_chat.available_reactions = types.ChatReactions._parse(client, full_chat.available_reactions)
 
         return parsed_chat
 
diff --git a/pyrogram/types/user_and_chats/chat_reactions.py b/pyrogram/types/user_and_chats/chat_reactions.py
new file mode 100644
index 0000000000..057fb96654
--- /dev/null
+++ b/pyrogram/types/user_and_chats/chat_reactions.py
@@ -0,0 +1,69 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Optional, List
+
+import pyrogram
+from pyrogram import raw, types
+from ..object import Object
+
+
+class ChatReactions(Object):
+    """A chat reactions
+
+    Parameters:
+        all_are_enabled (``bool``, *optional*)
+
+        allow_custom_emoji (``bool``, *optional*):
+            Whether custom emoji are allowed or not.
+
+        reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*):
+            Reactions available.
+    """
+
+    def __init__(
+        self,
+        *,
+        client: "pyrogram.Client" = None,
+        all_are_enabled: Optional[bool] = None,
+        allow_custom_emoji: Optional[bool] = None,
+        reactions: Optional[List["types.Reaction"]] = None,
+    ):
+        super().__init__(client)
+
+        self.all_are_enabled = all_are_enabled
+        self.allow_custom_emoji = allow_custom_emoji
+        self.reactions = reactions
+
+    @staticmethod
+    def _parse(client, chat_reactions: "raw.base.ChatReactions") -> Optional["ChatReactions"]:
+        if isinstance(chat_reactions, raw.types.ChatReactionsAll):
+            return ChatReactions(
+                client=client,
+                all_are_enabled=True,
+                allow_custom_emoji=chat_reactions.allow_custom
+            )
+
+        if isinstance(chat_reactions, raw.types.ChatReactionsSome):
+            return ChatReactions(
+                client=client,
+                reactions=[types.Reaction._parse(client, reaction)
+                           for reaction in chat_reactions.reactions]
+            )
+
+        return None

From 6496a87029a6b0987d3825b8a22d08474fc92aa9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:46:37 +0200
Subject: [PATCH 368/539] Add message_reactions.py

---
 pyrogram/types/messages_and_media/__init__.py |  3 +-
 pyrogram/types/messages_and_media/message.py  |  3 +-
 .../messages_and_media/message_reactions.py   | 56 +++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)
 create mode 100644 pyrogram/types/messages_and_media/message_reactions.py

diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py
index 3a18b2a5bf..54dfd56043 100644
--- a/pyrogram/types/messages_and_media/__init__.py
+++ b/pyrogram/types/messages_and_media/__init__.py
@@ -38,9 +38,10 @@
 from .voice import Voice
 from .web_app_data import WebAppData
 from .web_page import WebPage
+from .message_reactions import MessageReactions
 
 __all__ = [
     "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
     "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice",
-    "Reaction", "WebAppData"
+    "Reaction", "WebAppData", "MessageReactions"
 ]
diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 146e37c4a9..40386af0f8 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -742,8 +742,7 @@ async def _parse(
             from_user = types.User._parse(client, users.get(user_id, None))
             sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
 
-            reactions = [types.Reaction(emoji=r.reaction, count=r.count, chosen=r.chosen)
-                         for r in message.reactions.results] if message.reactions else None
+            reactions = types.MessageReactions._parse(client, message.reactions)
 
             parsed_message = Message(
                 id=message.id,
diff --git a/pyrogram/types/messages_and_media/message_reactions.py b/pyrogram/types/messages_and_media/message_reactions.py
new file mode 100644
index 0000000000..8f057cf559
--- /dev/null
+++ b/pyrogram/types/messages_and_media/message_reactions.py
@@ -0,0 +1,56 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Optional, List
+
+import pyrogram
+from pyrogram import raw, types
+from ..object import Object
+
+
+class MessageReactions(Object):
+    """Contains information about a message reactions.
+
+    Parameters:
+        reactions (List of :obj:`~pyrogram.types.Reaction`):
+            Reactions list.
+    """
+
+    def __init__(
+        self,
+        *,
+        client: "pyrogram.Client" = None,
+        reactions: Optional[List["types.Reaction"]] = None,
+    ):
+        super().__init__(client)
+
+        self.reactions = reactions
+
+    @staticmethod
+    def _parse(
+        client: "pyrogram.Client",
+        message_reactions: Optional["raw.base.MessageReactions"] = None
+    ) -> Optional["MessageReactions"]:
+        if not message_reactions:
+            return None
+
+        return MessageReactions(
+            client=client,
+            reactions=[types.Reaction._parse_count(client, reaction)
+                       for reaction in message_reactions.results]
+        )

From 06c62c5b4c5ad038d5072e57f74d280526a7392e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:47:17 +0200
Subject: [PATCH 369/539] Add MessageReactions and ChatReactions to the docs

---
 compiler/docs/compiler.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index a6f82f3229..f642f288e9 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -414,6 +414,8 @@ def get_title_list(s: str) -> list:
             VideoChatEnded
             VideoChatMembersInvited
             WebAppData
+            MessageReactions
+            ChatReactions
         """,
         bot_keyboards="""
         Bot keyboards

From f7319858e1e6743a31a81eabe6ada8a78eae9146 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 13:58:01 +0200
Subject: [PATCH 370/539] Update Pyrogram to v2.0.47

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 92cccf4515..19c7e0c369 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.46"
+__version__ = "2.0.47"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 04b343f61b9e85cdcc2a81b20267097a5a4eedab Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 14:06:46 +0200
Subject: [PATCH 371/539] Add get_default_emoji_statuses method

---
 compiler/docs/compiler.py                     |  1 +
 pyrogram/methods/users/__init__.py            |  2 +
 .../users/get_default_emoji_statuses.py       | 43 +++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 pyrogram/methods/users/get_default_emoji_statuses.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index f642f288e9..149cdcf005 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -251,6 +251,7 @@ def get_title_list(s: str) -> list:
             block_user
             unblock_user
             get_common_chats
+            get_default_emoji_statuses
         """,
         invite_links="""
         Invite Links
diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py
index 2ed719e8fc..52c4699f8c 100644
--- a/pyrogram/methods/users/__init__.py
+++ b/pyrogram/methods/users/__init__.py
@@ -21,6 +21,7 @@
 from .get_chat_photos import GetChatPhotos
 from .get_chat_photos_count import GetChatPhotosCount
 from .get_common_chats import GetCommonChats
+from .get_default_emoji_statuses import GetDefaultEmojiStatuses
 from .get_me import GetMe
 from .get_users import GetUsers
 from .set_profile_photo import SetProfilePhoto
@@ -41,5 +42,6 @@ class Users(
     GetChatPhotosCount,
     UnblockUser,
     UpdateProfile,
+    GetDefaultEmojiStatuses
 ):
     pass
diff --git a/pyrogram/methods/users/get_default_emoji_statuses.py b/pyrogram/methods/users/get_default_emoji_statuses.py
new file mode 100644
index 0000000000..b4d707bde0
--- /dev/null
+++ b/pyrogram/methods/users/get_default_emoji_statuses.py
@@ -0,0 +1,43 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 import raw
+from pyrogram import types
+
+
+class GetDefaultEmojiStatuses:
+    async def get_default_emoji_statuses(
+        self: "pyrogram.Client",
+    ) -> types.List["types.EmojiStatus"]:
+        """Get the default emoji statuses.
+
+        Returns:
+            List of :obj:`~pyrogram.types.EmojiStatus`: On success, a list of emoji statuses is returned.
+
+        Example:
+            .. code-block:: python
+
+                default_emoji_statuses = await app.get_default_emoji_statuses()
+                print(default_emoji_statuses)
+        """
+        r = await self.invoke(
+            raw.functions.account.GetDefaultEmojiStatuses(hash=0)
+        )
+
+        return types.List([types.EmojiStatus._parse(self, i) for i in r.statuses])

From 5d11c03b4ee74e805391b1955683a617c881052f Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 14:18:12 +0200
Subject: [PATCH 372/539] Add set_emoji_status method

---
 compiler/docs/compiler.py                     |  1 +
 pyrogram/methods/users/__init__.py            |  4 +-
 pyrogram/methods/users/set_emoji_status.py    | 56 +++++++++++++++++++
 pyrogram/types/user_and_chats/emoji_status.py | 11 ++++
 4 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 pyrogram/methods/users/set_emoji_status.py

diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 149cdcf005..12a4d97221 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -252,6 +252,7 @@ def get_title_list(s: str) -> list:
             unblock_user
             get_common_chats
             get_default_emoji_statuses
+            set_emoji_status
         """,
         invite_links="""
         Invite Links
diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py
index 52c4699f8c..31fda1dc3a 100644
--- a/pyrogram/methods/users/__init__.py
+++ b/pyrogram/methods/users/__init__.py
@@ -24,6 +24,7 @@
 from .get_default_emoji_statuses import GetDefaultEmojiStatuses
 from .get_me import GetMe
 from .get_users import GetUsers
+from .set_emoji_status import SetEmojiStatus
 from .set_profile_photo import SetProfilePhoto
 from .set_username import SetUsername
 from .unblock_user import UnblockUser
@@ -42,6 +43,7 @@ class Users(
     GetChatPhotosCount,
     UnblockUser,
     UpdateProfile,
-    GetDefaultEmojiStatuses
+    GetDefaultEmojiStatuses,
+    SetEmojiStatus
 ):
     pass
diff --git a/pyrogram/methods/users/set_emoji_status.py b/pyrogram/methods/users/set_emoji_status.py
new file mode 100644
index 0000000000..288e966b20
--- /dev/null
+++ b/pyrogram/methods/users/set_emoji_status.py
@@ -0,0 +1,56 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 typing import Optional
+
+import pyrogram
+from pyrogram import raw, types
+
+
+class SetEmojiStatus:
+    async def set_emoji_status(
+        self: "pyrogram.Client",
+        emoji_status: Optional["types.EmojiStatus"] = None
+    ) -> bool:
+        """Set the emoji status.
+
+        Parameters:
+            emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*):
+                The emoji status to set. None to remove.
+
+        Returns:
+            ``bool``: On success, True is returned.
+
+        Example:
+            .. code-block:: python
+
+                from pyrogram import types
+
+                await app.set_emoji_status(types.EmojiStatus(custom_emoji_id=1234567890987654321))
+        """
+        await self.invoke(
+            raw.functions.account.UpdateEmojiStatus(
+                emoji_status=(
+                    emoji_status.write()
+                    if emoji_status
+                    else raw.types.EmojiStatusEmpty()
+                )
+            )
+        )
+
+        return True
diff --git a/pyrogram/types/user_and_chats/emoji_status.py b/pyrogram/types/user_and_chats/emoji_status.py
index 746c98ef2c..50b46bfa46 100644
--- a/pyrogram/types/user_and_chats/emoji_status.py
+++ b/pyrogram/types/user_and_chats/emoji_status.py
@@ -64,3 +64,14 @@ def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatu
             )
 
         return None
+
+    def write(self):
+        if self.until_date:
+            return raw.types.EmojiStatusUntil(
+                document_id=self.custom_emoji_id,
+                until=utils.datetime_to_timestamp(self.until_date)
+            )
+
+        return raw.types.EmojiStatus(
+            document_id=self.custom_emoji_id
+        )

From 210f538d552577249b1e42b9635fab06b2be9262 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 14:18:51 +0200
Subject: [PATCH 373/539] Update Pyrogram to v2.0.48

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 19c7e0c369..fb73f17f68 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.47"
+__version__ = "2.0.48"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 1db03c4351b56e620af6a8a0c604aa5a5ce79ff5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 14:23:52 +0200
Subject: [PATCH 374/539] Fix for older Python versions

---
 pyrogram/methods/users/get_default_emoji_statuses.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pyrogram/methods/users/get_default_emoji_statuses.py b/pyrogram/methods/users/get_default_emoji_statuses.py
index b4d707bde0..8c85a3c202 100644
--- a/pyrogram/methods/users/get_default_emoji_statuses.py
+++ b/pyrogram/methods/users/get_default_emoji_statuses.py
@@ -16,6 +16,8 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
+from typing import List
+
 import pyrogram
 from pyrogram import raw
 from pyrogram import types
@@ -24,7 +26,7 @@
 class GetDefaultEmojiStatuses:
     async def get_default_emoji_statuses(
         self: "pyrogram.Client",
-    ) -> types.List["types.EmojiStatus"]:
+    ) -> List["types.EmojiStatus"]:
         """Get the default emoji statuses.
 
         Returns:

From 1a1075090d67ad32229f7a346d7c1950479de9d2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 3 Sep 2022 14:24:10 +0200
Subject: [PATCH 375/539] Update Pyrogram to v2.0.49

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index fb73f17f68..98f6b3afee 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.48"
+__version__ = "2.0.49"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From e0fdcc7f3a33bac9e501a5922a55ef2871bf0c17 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 5 Sep 2022 18:18:42 +0200
Subject: [PATCH 376/539] Fix send_reaction Fixes #1086

---
 pyrogram/methods/messages/send_reaction.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py
index 1ede4ead79..b1e6540b68 100644
--- a/pyrogram/methods/messages/send_reaction.py
+++ b/pyrogram/methods/messages/send_reaction.py
@@ -63,7 +63,7 @@ async def send_reaction(
             raw.functions.messages.SendReaction(
                 peer=await self.resolve_peer(chat_id),
                 msg_id=message_id,
-                reaction=emoji,
+                reaction=[raw.types.ReactionEmoji(emoticon=emoji)] if emoji else None,
                 big=big
             )
         )

From 8490cfa0a92e2d57b6de9728b1d18ee3071be5b4 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 5 Sep 2022 18:19:02 +0200
Subject: [PATCH 377/539] Update Pyrogram to v2.0.50

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 98f6b3afee..b72afd0ceb 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.49"
+__version__ = "2.0.50"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From f9aacd814a60b60f61c8d989bdaeb9fa92492a24 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Sep 2022 19:04:47 +0200
Subject: [PATCH 378/539] Update poll parsing

---
 pyrogram/types/messages_and_media/message.py |  3 +-
 pyrogram/types/messages_and_media/poll.py    | 78 ++++++++++++++++----
 2 files changed, 64 insertions(+), 17 deletions(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 40386af0f8..c49fd0f6c7 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -827,7 +827,8 @@ async def _parse(
                     except MessageIdsEmpty:
                         pass
 
-            client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
+            if not parsed_message.poll:  # Do not cache poll messages
+                client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
 
             return parsed_message
 
diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py
index 9d4c5118cb..cdb97ea100 100644
--- a/pyrogram/types/messages_and_media/poll.py
+++ b/pyrogram/types/messages_and_media/poll.py
@@ -16,10 +16,11 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-from typing import List, Union
+from datetime import datetime
+from typing import List, Union, Optional
 
 import pyrogram
-from pyrogram import raw, enums
+from pyrogram import raw, enums, utils
 from pyrogram import types
 from ..object import Object
 from ..update import Update
@@ -53,8 +54,26 @@ class Poll(Object, Update):
         allows_multiple_answers (``bool``, *optional*):
             True, if the poll allows multiple answers.
 
-        chosen_option (``int``, *optional*):
-            Index of your chosen option (0-9), None in case you haven't voted yet.
+        chosen_option_id (``int``, *optional*):
+            0-based index of the chosen option), None in case of no vote yet.
+
+        correct_option_id (``int``, *optional*):
+            0-based identifier of the correct answer option.
+            Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to
+            the private chat with the bot.
+
+        explanation (``str``, *optional*):
+            Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll,
+            0-200 characters.
+
+        explanation_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
+            Special entities like usernames, URLs, bot commands, etc. that appear in the explanation.
+
+        open_period (``int``, *optional*):
+            Amount of time in seconds the poll will be active after creation.
+
+        close_date (:py:obj:`~datetime.datetime`, *optional*):
+            Point in time when the poll will be automatically closed.
     """
 
     def __init__(
@@ -69,8 +88,12 @@ def __init__(
         is_anonymous: bool = None,
         type: "enums.PollType" = None,
         allows_multiple_answers: bool = None,
-        # correct_option_id: int,
-        chosen_option: int = None
+        chosen_option_id: Optional[int] = None,
+        correct_option_id: Optional[int] = None,
+        explanation: Optional[str] = None,
+        explanation_entities: Optional[List["types.MessageEntity"]] = None,
+        open_period: Optional[int] = None,
+        close_date: Optional[datetime] = None
     ):
         super().__init__(client)
 
@@ -82,14 +105,21 @@ def __init__(
         self.is_anonymous = is_anonymous
         self.type = type
         self.allows_multiple_answers = allows_multiple_answers
-        # self.correct_option_id = correct_option_id
-        self.chosen_option = chosen_option
+        self.chosen_option_id = chosen_option_id
+        self.correct_option_id = correct_option_id
+        self.explanation = explanation
+        self.explanation_entities = explanation_entities
+        self.open_period = open_period
+        self.close_date = close_date
 
     @staticmethod
     def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.UpdateMessagePoll"]) -> "Poll":
-        poll = media_poll.poll  # type: raw.types.Poll
-        results = media_poll.results.results
-        chosen_option = None
+        poll: raw.types.Poll = media_poll.poll
+        poll_results: raw.types.PollResults = media_poll.results
+        results: List[raw.types.PollAnswerVoters] = poll_results.results
+
+        chosen_option_id = None
+        correct_option_id = None
         options = []
 
         for i, answer in enumerate(poll.answers):
@@ -100,7 +130,10 @@ def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.Up
                 voter_count = result.voters
 
                 if result.chosen:
-                    chosen_option = i
+                    chosen_option_id = i
+
+                if result.correct:
+                    correct_option_id = i
 
             options.append(
                 types.PollOption(
@@ -120,7 +153,15 @@ def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.Up
             is_anonymous=not poll.public_voters,
             type=enums.PollType.QUIZ if poll.quiz else enums.PollType.REGULAR,
             allows_multiple_answers=poll.multiple_choice,
-            chosen_option=chosen_option,
+            chosen_option_id=chosen_option_id,
+            correct_option_id=correct_option_id,
+            explanation=poll_results.solution,
+            explanation_entities=[
+                types.MessageEntity._parse(client, i, {})
+                for i in poll_results.solution_entities
+            ] if poll_results.solution_entities else None,
+            open_period=poll.close_period,
+            close_date=utils.timestamp_to_datetime(poll.close_date),
             client=client
         )
 
@@ -130,12 +171,16 @@ def _parse_update(client, update: "raw.types.UpdateMessagePoll"):
             return Poll._parse(client, update)
 
         results = update.results.results
-        chosen_option = None
+        chosen_option_id = None
+        correct_option_id = None
         options = []
 
         for i, result in enumerate(results):
             if result.chosen:
-                chosen_option = i
+                chosen_option_id = i
+
+            if result.correct:
+                correct_option_id = i
 
             options.append(
                 types.PollOption(
@@ -152,6 +197,7 @@ def _parse_update(client, update: "raw.types.UpdateMessagePoll"):
             options=options,
             total_voter_count=update.results.total_voters,
             is_closed=False,
-            chosen_option=chosen_option,
+            chosen_option_id=chosen_option_id,
+            correct_option_id=correct_option_id,
             client=client
         )

From 7558e04cfc6aaeb8630cffe0d8fd9f77d4141d4d Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Sep 2022 19:05:09 +0200
Subject: [PATCH 379/539] Update Pyrogram to v2.0.51

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index b72afd0ceb..839f43f7b0 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.50"
+__version__ = "2.0.51"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 6dced525ab67d9bfa9a8d26f02f0a87327eed8d7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 15 Sep 2022 12:15:13 +0200
Subject: [PATCH 380/539] Update example

---
 pyrogram/methods/users/delete_profile_photos.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py
index 2e7615444f..4ee8b7b51d 100644
--- a/pyrogram/methods/users/delete_profile_photos.py
+++ b/pyrogram/methods/users/delete_profile_photos.py
@@ -43,7 +43,7 @@ async def delete_profile_photos(
             .. code-block:: python
 
                 # Get the photos to be deleted
-                photos = list(await app.get_chat_photos("me"))
+                photos = [p async for p in app.get_chat_photos("me")]
 
                 # Delete one photo
                 await app.delete_profile_photos(photos[0].file_id)

From 8fd79c93c75a15a25562d5bb835a1d96d3df35f7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 15 Sep 2022 16:51:46 +0200
Subject: [PATCH 381/539] Update API schema to Layer 146

---
 compiler/api/source/main_api.tl | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 465446b489..9d71625f9d 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -46,7 +46,7 @@ inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string pro
 inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = InputMedia;
 inputMediaDocumentExternal#fb52dc99 flags:# url:string ttl_seconds:flags.0?int = InputMedia;
 inputMediaGame#d33f43f3 id:InputGame = InputMedia;
-inputMediaInvoice#d9799874 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:flags.1?string = InputMedia;
+inputMediaInvoice#8eb5a6d5 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:flags.1?string extended_media:flags.2?InputMedia = InputMedia;
 inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia;
 inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector solution:flags.1?string solution_entities:flags.1?Vector = InputMedia;
 inputMediaDice#e66fbf7b emoticon:string = InputMedia;
@@ -132,7 +132,7 @@ messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true document:flags.0?Do
 messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia;
 messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia;
 messageMediaGame#fdb19008 game:Game = MessageMedia;
-messageMediaInvoice#84551347 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string = MessageMedia;
+messageMediaInvoice#f6a548d3 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string extended_media:flags.4?MessageExtendedMedia = MessageMedia;
 messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;
 messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;
 messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia;
@@ -375,6 +375,7 @@ updateUserEmojiStatus#28373599 user_id:long emoji_status:EmojiStatus = Update;
 updateRecentEmojiStatuses#30f443db = Update;
 updateRecentReactions#6f7863f4 = Update;
 updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update;
+updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update;
 
 updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
 
@@ -1422,6 +1423,9 @@ premiumSubscriptionOption#b6f11ebe flags:# current:flags.1?true can_purchase_upg
 
 sendAsPeer#b81c7034 flags:# premium_required:flags.0?true peer:Peer = SendAsPeer;
 
+messageExtendedMediaPreview#ad628cc8 flags:# w:flags.0?int h:flags.0?int thumb:flags.1?PhotoSize video_duration:flags.2?int = MessageExtendedMedia;
+messageExtendedMedia#ee479c64 media:MessageMedia = MessageExtendedMedia;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1735,6 +1739,7 @@ messages.reportReaction#3f64c076 peer:InputPeer id:int reaction_peer:InputPeer =
 messages.getTopReactions#bb8125ba limit:int hash:long = messages.Reactions;
 messages.getRecentReactions#39461db2 limit:int hash:long = messages.Reactions;
 messages.clearRecentReactions#9dfeefb4 = Bool;
+messages.getExtendedMedia#84f80814 peer:InputPeer id:Vector = Updates;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1897,4 +1902,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 145
\ No newline at end of file
+// LAYER 146
\ No newline at end of file

From 9f94aee9f8183e5a7222057a0c4753fee4016ed5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 15 Sep 2022 16:52:14 +0200
Subject: [PATCH 382/539] Update Pyrogram to v2.0.52

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 839f43f7b0..9c34c9a786 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.51"
+__version__ = "2.0.52"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 53584bc1dbd19c9b956d9c78932ec792c7744cf3 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 15:44:18 +0200
Subject: [PATCH 383/539] Add chosen_order to Reaction

---
 pyrogram/types/messages_and_media/reaction.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/pyrogram/types/messages_and_media/reaction.py b/pyrogram/types/messages_and_media/reaction.py
index 9d6b9e24b2..17e08ff578 100644
--- a/pyrogram/types/messages_and_media/reaction.py
+++ b/pyrogram/types/messages_and_media/reaction.py
@@ -35,6 +35,10 @@ class Reaction(Object):
 
         count (``int``, *optional*):
             Reaction count.
+
+        chosen_order (``int``, *optional*):
+            Chosen reaction order.
+            Available for chosen reactions.
     """
 
     def __init__(
@@ -43,13 +47,15 @@ def __init__(
         client: "pyrogram.Client" = None,
         emoji: Optional[str] = None,
         custom_emoji_id: Optional[int] = None,
-        count: Optional[int] = None
+        count: Optional[int] = None,
+        chosen_order: Optional[int] = None
     ):
         super().__init__(client)
 
         self.emoji = emoji
         self.custom_emoji_id = custom_emoji_id
         self.count = count
+        self.chosen_order = chosen_order
 
     @staticmethod
     def _parse(
@@ -75,5 +81,6 @@ def _parse_count(
     ) -> "Reaction":
         reaction = Reaction._parse(client, reaction_count.reaction)
         reaction.count = reaction_count.count
+        reaction.chosen_order = reaction_count.chosen_order
 
         return reaction

From 81895d74c7e677c2d64b768b3c166bc2555d5993 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 16:04:07 +0200
Subject: [PATCH 384/539] Fix Chat.available_reactions type hint

---
 pyrogram/types/user_and_chats/chat.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py
index aa727952e5..f37542fb0c 100644
--- a/pyrogram/types/user_and_chats/chat.py
+++ b/pyrogram/types/user_and_chats/chat.py
@@ -126,7 +126,7 @@ class Chat(Object):
             The default "send_as" chat.
             Returned only in :meth:`~pyrogram.Client.get_chat`.
 
-        available_reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*):
+        available_reactions (:obj:`~pyrogram.types.ChatReactions`, *optional*):
             Available reactions in the chat.
             Returned only in :meth:`~pyrogram.Client.get_chat`.
     """
@@ -162,7 +162,7 @@ def __init__(
         distance: int = None,
         linked_chat: "types.Chat" = None,
         send_as_chat: "types.Chat" = None,
-        available_reactions: Optional[List["types.Reaction"]] = None
+        available_reactions: Optional["types.ChatReactions"] = None
     ):
         super().__init__(client)
 

From 468ebf50cf596b73175aa5826a44e5be00becb78 Mon Sep 17 00:00:00 2001
From: Nyan <93275906+el-garro@users.noreply.github.com>
Date: Sun, 18 Sep 2022 11:24:51 -0400
Subject: [PATCH 385/539] Add tempfile deletion in case of asyncio task
 cancellation. (#1080)

---
 pyrogram/client.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index d30a5e9a80..f4cee803a5 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -737,6 +737,12 @@ async def handle_download(self, packet):
                 os.remove(file.name)
 
             return None
+        except asyncio.CancelledError:
+            if not in_memory:
+                file.close()
+                os.remove(file.name)
+                
+            raise asyncio.CancelledError()
         else:
             if in_memory:
                 file.name = file_name

From 3940ca9611d3d7061996e4ee35e57136d87626f9 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 17:32:02 +0200
Subject: [PATCH 386/539] Revamp handling of partial downloads

---
 pyrogram/client.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index f4cee803a5..4ab7c3447b 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -25,7 +25,6 @@
 import re
 import shutil
 import sys
-import tempfile
 from concurrent.futures.thread import ThreadPoolExecutor
 from hashlib import sha256
 from importlib import import_module
@@ -726,32 +725,29 @@ def load_plugins(self):
 
     async def handle_download(self, packet):
         file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet
-        file = BytesIO() if in_memory else tempfile.NamedTemporaryFile("wb", delete=False)
 
+        os.makedirs(directory, exist_ok=True)
+        temp_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + ".temp"
+        file = BytesIO() if in_memory else open(temp_file_path, "wb")
+
+        # noinspection PyBroadException
         try:
             async for chunk in self.get_file(file_id, file_size, 0, 0, progress, progress_args):
                 file.write(chunk)
-        except pyrogram.StopTransmission:
+        except BaseException:
             if not in_memory:
                 file.close()
-                os.remove(file.name)
+                os.remove(temp_file_path)
 
             return None
-        except asyncio.CancelledError:
-            if not in_memory:
-                file.close()
-                os.remove(file.name)
-                
-            raise asyncio.CancelledError()
         else:
             if in_memory:
                 file.name = file_name
                 return file
             else:
-                file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name)))
-                os.makedirs(directory, exist_ok=True)
                 file.close()
-                shutil.move(file.name, file_path)
+                file_path = os.path.splitext(temp_file_path)[0]
+                shutil.move(temp_file_path, file_path)
                 return file_path
 
     async def get_file(

From 2d547ccf8c1c87dd2e8866d8fd72eba816cc0ff1 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 17:33:16 +0200
Subject: [PATCH 387/539] Update Pyrogram to v2.0.53

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 9c34c9a786..2465ddf769 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.52"
+__version__ = "2.0.53"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 71f263b30d3acfe079b3b72b3d2fed39d6325850 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 17:55:50 +0200
Subject: [PATCH 388/539] Re-raise asyncio.CancelledError to avoid
 continuations

---
 pyrogram/client.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index 4ab7c3447b..6f07395ad8 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -730,15 +730,17 @@ async def handle_download(self, packet):
         temp_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + ".temp"
         file = BytesIO() if in_memory else open(temp_file_path, "wb")
 
-        # noinspection PyBroadException
         try:
             async for chunk in self.get_file(file_id, file_size, 0, 0, progress, progress_args):
                 file.write(chunk)
-        except BaseException:
+        except BaseException as e:
             if not in_memory:
                 file.close()
                 os.remove(temp_file_path)
 
+            if isinstance(e, asyncio.CancelledError):
+                raise e
+
             return None
         else:
             if in_memory:

From a2fe5b3e79ff9e44ec37293323b0ab844d371587 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 18 Sep 2022 17:56:05 +0200
Subject: [PATCH 389/539] Update Pyrogram to v2.0.54

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 2465ddf769..70188abcbb 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.53"
+__version__ = "2.0.54"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 4edaa21c199e85386989e49901ff90facec9ffde Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 20 Sep 2022 16:39:53 +0200
Subject: [PATCH 390/539] Don't create download dirs for in-memory downloads

---
 pyrogram/client.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/client.py b/pyrogram/client.py
index 6f07395ad8..67f059e96b 100644
--- a/pyrogram/client.py
+++ b/pyrogram/client.py
@@ -726,7 +726,7 @@ def load_plugins(self):
     async def handle_download(self, packet):
         file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet
 
-        os.makedirs(directory, exist_ok=True)
+        os.makedirs(directory, exist_ok=True) if not in_memory else None
         temp_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + ".temp"
         file = BytesIO() if in_memory else open(temp_file_path, "wb")
 

From 862285e1e69da8fa8701218a7ba66e1614abbd5e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 20 Sep 2022 16:40:36 +0200
Subject: [PATCH 391/539] Update Pyrogram to v2.0.55

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 70188abcbb..1331a5d59d 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.54"
+__version__ = "2.0.55"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 2870ae84e73cf37dc4a489299275f3584a9f773d Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 22 Sep 2022 15:26:42 +0200
Subject: [PATCH 392/539] Move get_me() call into start()

---
 pyrogram/methods/auth/initialize.py | 2 --
 pyrogram/methods/utilities/start.py | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py
index 26c9d0bf8c..1e7915e00e 100644
--- a/pyrogram/methods/auth/initialize.py
+++ b/pyrogram/methods/auth/initialize.py
@@ -44,8 +44,6 @@ async def initialize(
 
         self.load_plugins()
 
-        self.me = await self.get_me()
-
         await self.dispatcher.start()
 
         self.is_initialized = True
diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index bf5468fbe6..20b451be32 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -71,4 +71,6 @@ async def main():
             raise
         else:
             await self.initialize()
+            self.me = await self.get_me()
+
             return self

From f407f88395e71eb2b534b6e9afe16ab90cd9e5bb Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 22 Sep 2022 15:27:03 +0200
Subject: [PATCH 393/539] Update Pyrogram to v2.0.56

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 1331a5d59d..bf6c5e25f2 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.55"
+__version__ = "2.0.56"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From ec476aa293d58ba1b46a4b6b61d947326d7387c7 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 23 Sep 2022 09:50:11 +0200
Subject: [PATCH 394/539] Call get_me() before initializing the client

---
 pyrogram/methods/utilities/start.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py
index 20b451be32..95cd9fc585 100644
--- a/pyrogram/methods/utilities/start.py
+++ b/pyrogram/methods/utilities/start.py
@@ -70,7 +70,7 @@ async def main():
             await self.disconnect()
             raise
         else:
-            await self.initialize()
             self.me = await self.get_me()
+            await self.initialize()
 
             return self

From 0e68bf35b70901e8d24bebbacf31a1609b18971f Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 23 Sep 2022 09:50:31 +0200
Subject: [PATCH 395/539] Update Pyrogram to v2.0.57

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index bf6c5e25f2..e9dcc31f0b 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.56"
+__version__ = "2.0.57"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 8077eb41303b07367d38e8eafa3c0884182274d0 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 6 Oct 2022 12:03:05 +0200
Subject: [PATCH 396/539] Update docs

---
 .gitignore                                    |   2 +
 Makefile                                      |  28 +-
 compiler/api/compiler.py                      | 104 ++++--
 compiler/docs/template/bound-methods.rst      |   4 -
 compiler/docs/template/methods.rst            |   4 -
 compiler/docs/template/toctree.txt            |   2 +
 compiler/docs/template/types.rst              |   4 -
 docs/requirements.txt                         |   4 -
 docs/source/api/client.rst                    |  24 --
 docs/source/api/decorators.rst                |  68 ----
 docs/source/api/enums/ChatAction.rst          |   8 -
 docs/source/api/enums/ChatEventAction.rst     |   8 -
 docs/source/api/enums/ChatMemberStatus.rst    |   8 -
 docs/source/api/enums/ChatMembersFilter.rst   |   8 -
 docs/source/api/enums/ChatType.rst            |   8 -
 docs/source/api/enums/MessageEntityType.rst   |   8 -
 docs/source/api/enums/MessageMediaType.rst    |   8 -
 docs/source/api/enums/MessageServiceType.rst  |   8 -
 docs/source/api/enums/MessagesFilter.rst      |   8 -
 docs/source/api/enums/NextCodeType.rst        |   8 -
 docs/source/api/enums/ParseMode.rst           |   8 -
 docs/source/api/enums/PollType.rst            |   8 -
 docs/source/api/enums/SentCodeType.rst        |   8 -
 docs/source/api/enums/UserStatus.rst          |   8 -
 docs/source/api/enums/cleanup.html            |   9 -
 docs/source/api/enums/index.rst               |  47 ---
 docs/source/api/errors/bad-request.rst        |   7 -
 docs/source/api/errors/flood.rst              |   7 -
 docs/source/api/errors/forbidden.rst          |   7 -
 docs/source/api/errors/index.rst              |  37 ---
 .../api/errors/internal-server-error.rst      |   7 -
 docs/source/api/errors/not-acceptable.rst     |   7 -
 docs/source/api/errors/see-other.rst          |   7 -
 docs/source/api/errors/unauthorized.rst       |   7 -
 docs/source/api/filters.rst                   |  11 -
 docs/source/api/handlers.rst                  |  66 ----
 docs/source/conf.py                           |  91 ------
 .../client-started-but-nothing-happens.rst    |  11 -
 ...alling-stop-restart-add-remove-handler.rst |  12 -
 docs/source/faq/how-to-avoid-flood-waits.rst  |  23 --
 docs/source/faq/how-to-use-webhooks.rst       |   9 -
 docs/source/faq/index.rst                     |  45 ---
 ...ing-the-account-to-another-data-center.rst |  10 -
 docs/source/faq/peer-id-invalid-error.rst     |  14 -
 ...ror-timeouterror-connection-lost-reset.rst |  12 -
 ...interfaceerror-error-binding-parameter.rst |  13 -
 ...e3-operationalerror-database-is-locked.rst |  17 -
 ...e-account-has-been-limited-deactivated.rst |  16 -
 .../unicodeencodeerror-codec-cant-encode.rst  |   7 -
 ...h-urls-gives-error-webpage-curl-failed.rst |   7 -
 ...le-clients-at-once-on-the-same-account.rst |   7 -
 ...same-file-id-across-different-accounts.rst |   6 -
 ...-ip-addresses-of-telegram-data-centers.rst |  30 --
 .../why-is-the-api-key-needed-for-bots.rst    |  12 -
 ...eacting-slowly-in-supergroups-channels.rst |  18 --
 docs/source/index.rst                         | 172 ----------
 docs/source/intro/install.rst                 |  50 ---
 docs/source/intro/quickstart.rst              |  56 ----
 docs/source/start/auth.rst                    |  93 ------
 docs/source/start/errors.rst                  | 101 ------
 docs/source/start/examples/bot_keyboards.rst  |  68 ----
 .../start/examples/callback_queries.rst       |  21 --
 docs/source/start/examples/echo_bot.rst       |  21 --
 .../start/examples/get_chat_history.rst       |  20 --
 .../start/examples/get_chat_members.rst       |  22 --
 docs/source/start/examples/get_dialogs.rst    |  19 --
 docs/source/start/examples/hello_world.rst    |  20 --
 docs/source/start/examples/index.rst          |  46 ---
 docs/source/start/examples/inline_queries.rst |  59 ----
 docs/source/start/examples/raw_updates.rst    |  18 --
 .../source/start/examples/use_inline_bots.rst |  25 --
 docs/source/start/examples/welcome_bot.rst    |  30 --
 docs/source/start/invoking.rst                | 110 -------
 docs/source/start/setup.rst                   |  40 ---
 docs/source/start/updates.rst                 |  78 -----
 docs/source/support.rst                       |  63 ----
 docs/source/topics/advanced-usage.rst         | 124 -------
 docs/source/topics/client-settings.rst        |  46 ---
 docs/source/topics/create-filters.rst         | 109 -------
 docs/source/topics/debugging.rst              | 122 -------
 docs/source/topics/more-on-updates.rst        | 226 -------------
 docs/source/topics/mtproto-vs-botapi.rst      | 112 -------
 docs/source/topics/proxy.rst                  |  34 --
 docs/source/topics/scheduling.rst             |  65 ----
 docs/source/topics/serializing.rst            |  56 ----
 docs/source/topics/smart-plugins.rst          | 306 ------------------
 docs/source/topics/speedups.rst               |  88 -----
 docs/source/topics/storage-engines.rst        |  90 ------
 docs/source/topics/synchronous.rst            |  88 -----
 docs/source/topics/test-servers.rst           |  41 ---
 docs/source/topics/text-formatting.rst        | 243 --------------
 docs/source/topics/use-filters.rst            | 114 -------
 docs/source/topics/voice-calls.rst            |  19 --
 93 files changed, 85 insertions(+), 3865 deletions(-)
 delete mode 100644 docs/requirements.txt
 delete mode 100644 docs/source/api/client.rst
 delete mode 100644 docs/source/api/decorators.rst
 delete mode 100644 docs/source/api/enums/ChatAction.rst
 delete mode 100644 docs/source/api/enums/ChatEventAction.rst
 delete mode 100644 docs/source/api/enums/ChatMemberStatus.rst
 delete mode 100644 docs/source/api/enums/ChatMembersFilter.rst
 delete mode 100644 docs/source/api/enums/ChatType.rst
 delete mode 100644 docs/source/api/enums/MessageEntityType.rst
 delete mode 100644 docs/source/api/enums/MessageMediaType.rst
 delete mode 100644 docs/source/api/enums/MessageServiceType.rst
 delete mode 100644 docs/source/api/enums/MessagesFilter.rst
 delete mode 100644 docs/source/api/enums/NextCodeType.rst
 delete mode 100644 docs/source/api/enums/ParseMode.rst
 delete mode 100644 docs/source/api/enums/PollType.rst
 delete mode 100644 docs/source/api/enums/SentCodeType.rst
 delete mode 100644 docs/source/api/enums/UserStatus.rst
 delete mode 100644 docs/source/api/enums/cleanup.html
 delete mode 100644 docs/source/api/enums/index.rst
 delete mode 100644 docs/source/api/errors/bad-request.rst
 delete mode 100644 docs/source/api/errors/flood.rst
 delete mode 100644 docs/source/api/errors/forbidden.rst
 delete mode 100644 docs/source/api/errors/index.rst
 delete mode 100644 docs/source/api/errors/internal-server-error.rst
 delete mode 100644 docs/source/api/errors/not-acceptable.rst
 delete mode 100644 docs/source/api/errors/see-other.rst
 delete mode 100644 docs/source/api/errors/unauthorized.rst
 delete mode 100644 docs/source/api/filters.rst
 delete mode 100644 docs/source/api/handlers.rst
 delete mode 100644 docs/source/conf.py
 delete mode 100644 docs/source/faq/client-started-but-nothing-happens.rst
 delete mode 100644 docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst
 delete mode 100644 docs/source/faq/how-to-avoid-flood-waits.rst
 delete mode 100644 docs/source/faq/how-to-use-webhooks.rst
 delete mode 100644 docs/source/faq/index.rst
 delete mode 100644 docs/source/faq/migrating-the-account-to-another-data-center.rst
 delete mode 100644 docs/source/faq/peer-id-invalid-error.rst
 delete mode 100644 docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
 delete mode 100644 docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst
 delete mode 100644 docs/source/faq/sqlite3-operationalerror-database-is-locked.rst
 delete mode 100644 docs/source/faq/the-account-has-been-limited-deactivated.rst
 delete mode 100644 docs/source/faq/unicodeencodeerror-codec-cant-encode.rst
 delete mode 100644 docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst
 delete mode 100644 docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst
 delete mode 100644 docs/source/faq/using-the-same-file-id-across-different-accounts.rst
 delete mode 100644 docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst
 delete mode 100644 docs/source/faq/why-is-the-api-key-needed-for-bots.rst
 delete mode 100644 docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst
 delete mode 100644 docs/source/index.rst
 delete mode 100644 docs/source/intro/install.rst
 delete mode 100644 docs/source/intro/quickstart.rst
 delete mode 100644 docs/source/start/auth.rst
 delete mode 100644 docs/source/start/errors.rst
 delete mode 100644 docs/source/start/examples/bot_keyboards.rst
 delete mode 100644 docs/source/start/examples/callback_queries.rst
 delete mode 100644 docs/source/start/examples/echo_bot.rst
 delete mode 100644 docs/source/start/examples/get_chat_history.rst
 delete mode 100644 docs/source/start/examples/get_chat_members.rst
 delete mode 100644 docs/source/start/examples/get_dialogs.rst
 delete mode 100644 docs/source/start/examples/hello_world.rst
 delete mode 100644 docs/source/start/examples/index.rst
 delete mode 100644 docs/source/start/examples/inline_queries.rst
 delete mode 100644 docs/source/start/examples/raw_updates.rst
 delete mode 100644 docs/source/start/examples/use_inline_bots.rst
 delete mode 100644 docs/source/start/examples/welcome_bot.rst
 delete mode 100644 docs/source/start/invoking.rst
 delete mode 100644 docs/source/start/setup.rst
 delete mode 100644 docs/source/start/updates.rst
 delete mode 100644 docs/source/support.rst
 delete mode 100644 docs/source/topics/advanced-usage.rst
 delete mode 100644 docs/source/topics/client-settings.rst
 delete mode 100644 docs/source/topics/create-filters.rst
 delete mode 100644 docs/source/topics/debugging.rst
 delete mode 100644 docs/source/topics/more-on-updates.rst
 delete mode 100644 docs/source/topics/mtproto-vs-botapi.rst
 delete mode 100644 docs/source/topics/proxy.rst
 delete mode 100644 docs/source/topics/scheduling.rst
 delete mode 100644 docs/source/topics/serializing.rst
 delete mode 100644 docs/source/topics/smart-plugins.rst
 delete mode 100644 docs/source/topics/speedups.rst
 delete mode 100644 docs/source/topics/storage-engines.rst
 delete mode 100644 docs/source/topics/synchronous.rst
 delete mode 100644 docs/source/topics/test-servers.rst
 delete mode 100644 docs/source/topics/text-formatting.rst
 delete mode 100644 docs/source/topics/use-filters.rst
 delete mode 100644 docs/source/topics/voice-calls.rst

diff --git a/.gitignore b/.gitignore
index ff9ee02406..7a99a5db85 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,10 @@
 # Development
+docs
 *.session
 config.ini
 main.py
 unknown_errors.txt
+.DS_Store
 
 # Pyrogram generated code
 pyrogram/errors/exceptions/
diff --git a/Makefile b/Makefile
index 0d19832945..81dfe6c901 100644
--- a/Makefile
+++ b/Makefile
@@ -1,53 +1,33 @@
 VENV := venv
 PYTHON := $(VENV)/bin/python
+HOST = $(shell ifconfig | grep "inet " | tail -1 | cut -d\  -f2)
 
 RM := rm -rf
 
-.PHONY: venv build docs
+.PHONY: venv clean-build clean-api clean api build
 
 venv:
 	$(RM) $(VENV)
 	python3 -m venv $(VENV)
 	$(PYTHON) -m pip install -U pip wheel setuptools
-	$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt -r docs/requirements.txt
+	$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt
 	@echo "Created venv with $$($(PYTHON) --version)"
 
 clean-build:
 	$(RM) *.egg-info build dist
 
-clean-docs:
-	$(RM) docs/build
-	$(RM) docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram
-
 clean-api:
 	$(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types
 
 clean:
 	make clean-build
-	make clean-docs
 	make clean-api
 
 api:
 	cd compiler/api && ../../$(PYTHON) compiler.py
 	cd compiler/errors && ../../$(PYTHON) compiler.py
 
-docs-live:
-	make clean-docs
-	cd compiler/docs && ../../$(PYTHON) compiler.py
-	$(RM) docs/source/telegram
-	$(VENV)/bin/sphinx-autobuild \
-		--host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2) \
-		--watch pyrogram --watch docs/resources \
-		-b html "docs/source" "docs/build/html" -j auto
-
-docs:
-	make clean-docs
-	cd compiler/docs && ../../$(PYTHON) compiler.py
-	$(VENV)/bin/sphinx-build \
-		-b html "docs/source" "docs/build/html" -j auto
-
 build:
-	make clean-build
-	make clean-api
+	make clean
 	$(PYTHON) setup.py sdist
 	$(PYTHON) setup.py bdist_wheel
\ No newline at end of file
diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index c5372bff75..c29b7ed87f 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.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 json
 import os
 import re
 import shutil
@@ -59,6 +60,16 @@
 namespaces_to_constructors = {}
 namespaces_to_functions = {}
 
+try:
+    with open("docs.json") as f:
+        docs = json.load(f)
+except FileNotFoundError:
+    docs = {
+        "type": {},
+        "constructor": {},
+        "method": {}
+    }
+
 
 class Combinator(NamedTuple):
     section: str
@@ -149,7 +160,7 @@ def remove_whitespaces(source: str) -> str:
     return "\n".join(lines)
 
 
-def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool = False):
+def get_docstring_arg_type(t: str):
     if t in CORE_TYPES:
         if t == "long":
             return "``int`` ``64-bit``"
@@ -167,9 +178,9 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
     elif t == "TLObject" or t == "X":
         return "Any object from :obj:`~pyrogram.raw.types`"
     elif t == "!X":
-        return "Any method from :obj:`~pyrogram.raw.functions`"
+        return "Any function from :obj:`~pyrogram.raw.functions`"
     elif t.lower().startswith("vector"):
-        return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1], True)
+        return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1])
     else:
         return f":obj:`{t} `"
 
@@ -183,10 +194,7 @@ def get_references(t: str, kind: str):
         raise ValueError("Invalid kind")
 
     if t:
-        return "\n            ".join(
-            f"- :obj:`{i} `"
-            for i in t
-        ), len(t)
+        return "\n            ".join(t), len(t)
 
     return None, 0
 
@@ -315,17 +323,33 @@ def start(format: bool = False):
 
         constructors = sorted(types_to_constructors[qualtype])
         constr_count = len(constructors)
-        items = "\n            ".join([f"- :obj:`{c} `" for c in constructors])
+        items = "\n            ".join([f"{c}" for c in constructors])
+
+        type_docs = docs["type"].get(qualtype, None)
+
+        if type_docs:
+            type_docs = type_docs["desc"]
+        else:
+            type_docs = "Telegram API base type."
 
-        docstring = f"This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n"
-        docstring += f"    Constructors:\n        .. hlist::\n            :columns: 2\n\n            {items}"
+        docstring = type_docs
+
+        docstring += f"\n\n    Constructors:\n" \
+                     f"        This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" \
+                     f"        .. currentmodule:: pyrogram.raw.types\n\n" \
+                     f"        .. autosummary::\n" \
+                     f"            :nosignatures:\n\n" \
+                     f"            {items}"
 
         references, ref_count = get_references(qualtype, "types")
 
         if references:
-            docstring += f"\n\n    See Also:\n        This object can be returned by " \
-                         f"{ref_count} method{'s' if ref_count > 1 else ''}:" \
-                         f"\n\n        .. hlist::\n            :columns: 2\n\n            " + references
+            docstring += f"\n\n    Functions:\n        This object can be returned by " \
+                         f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" \
+                         f"        .. currentmodule:: pyrogram.raw.functions\n\n" \
+                         f"        .. autosummary::\n" \
+                         f"            :nosignatures:\n\n" \
+                         f"            " + references
 
         with open(dir_path / f"{snake(module)}.py", "w") as f:
             f.write(
@@ -359,41 +383,67 @@ def start(format: bool = False):
         docstring = ""
         docstring_args = []
 
+        if c.section == "functions":
+            combinator_docs = docs["method"]
+        else:
+            combinator_docs = docs["constructor"]
+
         for i, arg in enumerate(sorted_args):
             arg_name, arg_type = arg
             is_optional = FLAGS_RE.match(arg_type)
             flag_number = is_optional.group(1) if is_optional else -1
             arg_type = arg_type.split("?")[-1]
 
+            arg_docs = combinator_docs.get(c.qualname, None)
+
+            if arg_docs:
+                arg_docs = arg_docs["params"].get(arg_name, "N/A")
+            else:
+                arg_docs = "N/A"
+
             docstring_args.append(
-                "{}{}: {}".format(
+                "{} ({}{}):\n            {}\n".format(
                     arg_name,
-                    " (optional)".format(flag_number) if is_optional else "",
-                    get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
+                    get_docstring_arg_type(arg_type),
+                    ", *optional*".format(flag_number) if is_optional else "",
+                    arg_docs
                 )
             )
 
         if c.section == "types":
-            docstring += f"This object is a constructor of the base type :obj:`~pyrogram.raw.base.{c.qualtype}`.\n\n"
-        else:
-            docstring += f"Telegram API method.\n\n"
+            constructor_docs = docs["constructor"].get(c.qualname, None)
 
-        docstring += f"    Details:\n        - Layer: ``{layer}``\n        - ID: ``{c.id[2:].upper()}``\n\n"
+            if constructor_docs:
+                constructor_docs = constructor_docs["desc"]
+            else:
+                constructor_docs = "Telegram API type."
 
-        if docstring_args:
-            docstring += "    Parameters:\n        " + "\n        ".join(docstring_args)
+            docstring += constructor_docs + "\n"
+            docstring += f"\n    Constructor of :obj:`~pyrogram.raw.base.{c.qualtype}`."
         else:
-            docstring += "    **No parameters required.**"
+            function_docs = docs["method"].get(c.qualname, None)
+
+            if function_docs:
+                docstring += function_docs["desc"] + "\n"
+            else:
+                docstring += f"Telegram API function."
+
+        docstring += f"\n\n    Details:\n        - Layer: ``{layer}``\n        - ID: ``{c.id[2:].upper()}``\n\n"
+        docstring += f"    Parameters:\n        " + \
+                     (f"\n        ".join(docstring_args) if docstring_args else "No parameters required.\n")
 
         if c.section == "functions":
-            docstring += "\n\n    Returns:\n        " + get_docstring_arg_type(c.qualtype)
+            docstring += "\n    Returns:\n        " + get_docstring_arg_type(c.qualtype)
         else:
             references, count = get_references(c.qualname, "constructors")
 
             if references:
-                docstring += f"\n\n    See Also:\n        This object can be returned by " \
-                             f"{count} method{'s' if count > 1 else ''}:" \
-                             f"\n\n        .. hlist::\n            :columns: 2\n\n            " + references
+                docstring += f"\n    Functions:\n        This object can be returned by " \
+                             f"{count} function{'s' if count > 1 else ''}.\n\n" \
+                             f"        .. currentmodule:: pyrogram.raw.functions\n\n" \
+                             f"        .. autosummary::\n" \
+                             f"            :nosignatures:\n\n" \
+                             f"            " + references
 
         write_types = read_types = "" if c.has_flags else "# No flags\n        "
 
diff --git a/compiler/docs/template/bound-methods.rst b/compiler/docs/template/bound-methods.rst
index 33261d42b2..1e16e32ce9 100644
--- a/compiler/docs/template/bound-methods.rst
+++ b/compiler/docs/template/bound-methods.rst
@@ -19,10 +19,6 @@ some of the required arguments.
 
     app.run()
 
-.. contents:: Contents
-    :backlinks: none
-    :local:
-
 -----
 
 .. currentmodule:: pyrogram.types
diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst
index 1620350de8..f76e249def 100644
--- a/compiler/docs/template/methods.rst
+++ b/compiler/docs/template/methods.rst
@@ -14,10 +14,6 @@ the main package directly.
     with app:
         app.send_message("me", "hi")
 
-.. contents:: Contents
-    :backlinks: none
-    :local:
-
 -----
 
 .. currentmodule:: pyrogram.Client
diff --git a/compiler/docs/template/toctree.txt b/compiler/docs/template/toctree.txt
index 717276c40e..7a36e4a592 100644
--- a/compiler/docs/template/toctree.txt
+++ b/compiler/docs/template/toctree.txt
@@ -4,4 +4,6 @@
 .. module:: {module}
 
 .. toctree::
+    :titlesonly:
+
     {entities}
\ No newline at end of file
diff --git a/compiler/docs/template/types.rst b/compiler/docs/template/types.rst
index 2011a61100..e404ad4cdf 100644
--- a/compiler/docs/template/types.rst
+++ b/compiler/docs/template/types.rst
@@ -17,10 +17,6 @@ are only returned by other methods. You also don't need to import them, unless y
 
     To tell whether a field is set or not, do a simple boolean check: ``if message.photo: ...``.
 
-.. contents:: Contents
-    :backlinks: none
-    :local:
-
 -----
 
 .. currentmodule:: pyrogram.types
diff --git a/docs/requirements.txt b/docs/requirements.txt
deleted file mode 100644
index 7283c8ba69..0000000000
--- a/docs/requirements.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-sphinx
-sphinx_rtd_theme==1.0.0
-sphinx_copybutton
-sphinx-autobuild
\ No newline at end of file
diff --git a/docs/source/api/client.rst b/docs/source/api/client.rst
deleted file mode 100644
index 3db28693dc..0000000000
--- a/docs/source/api/client.rst
+++ /dev/null
@@ -1,24 +0,0 @@
-Pyrogram Client
-===============
-
-You have entered the API Reference section where you can find detailed information about Pyrogram's API. The main Client
-class, all available methods and types, filters, handlers, decorators and bound-methods detailed descriptions can be
-found starting from this page.
-
-This page is about the Client class, which exposes high-level methods for an easy access to the API.
-
-.. code-block:: python
-
-    from pyrogram import Client
-
-    app = Client("my_account")
-
-    with app:
-        app.send_message("me", "Hi!")
-
------
-
-Details
--------
-
-.. autoclass:: pyrogram.Client()
diff --git a/docs/source/api/decorators.rst b/docs/source/api/decorators.rst
deleted file mode 100644
index 2e7a04f263..0000000000
--- a/docs/source/api/decorators.rst
+++ /dev/null
@@ -1,68 +0,0 @@
-Decorators
-==========
-
-Decorators are able to register callback functions for handling updates in a much easier and cleaner way compared to
-:doc:`Handlers `; they do so by instantiating the correct handler and calling
-:meth:`~pyrogram.Client.add_handler` automatically. All you need to do is adding the decorators on top of your
-functions.
-
-.. code-block:: python
-
-    from pyrogram import Client
-
-    app = Client("my_account")
-
-
-    @app.on_message()
-    def log(client, message):
-        print(message)
-
-
-    app.run()
-
-.. contents:: Contents
-    :backlinks: none
-    :depth: 1
-    :local:
-
------
-
-.. currentmodule:: pyrogram
-
-Index
------
-
-.. hlist::
-    :columns: 3
-
-    - :meth:`~Client.on_message`
-    - :meth:`~Client.on_edited_message`
-    - :meth:`~Client.on_callback_query`
-    - :meth:`~Client.on_inline_query`
-    - :meth:`~Client.on_chosen_inline_result`
-    - :meth:`~Client.on_chat_member_updated`
-    - :meth:`~Client.on_chat_join_request`
-    - :meth:`~Client.on_deleted_messages`
-    - :meth:`~Client.on_user_status`
-    - :meth:`~Client.on_poll`
-    - :meth:`~Client.on_disconnect`
-    - :meth:`~Client.on_raw_update`
-
------
-
-Details
--------
-
-.. Decorators
-.. autodecorator:: pyrogram.Client.on_message()
-.. autodecorator:: pyrogram.Client.on_edited_message()
-.. autodecorator:: pyrogram.Client.on_callback_query()
-.. autodecorator:: pyrogram.Client.on_inline_query()
-.. autodecorator:: pyrogram.Client.on_chosen_inline_result()
-.. autodecorator:: pyrogram.Client.on_chat_member_updated()
-.. autodecorator:: pyrogram.Client.on_chat_join_request()
-.. autodecorator:: pyrogram.Client.on_deleted_messages()
-.. autodecorator:: pyrogram.Client.on_user_status()
-.. autodecorator:: pyrogram.Client.on_poll()
-.. autodecorator:: pyrogram.Client.on_disconnect()
-.. autodecorator:: pyrogram.Client.on_raw_update()
diff --git a/docs/source/api/enums/ChatAction.rst b/docs/source/api/enums/ChatAction.rst
deleted file mode 100644
index b66df5fd73..0000000000
--- a/docs/source/api/enums/ChatAction.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ChatAction
-==========
-
-.. autoclass:: pyrogram.enums.ChatAction()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatEventAction.rst b/docs/source/api/enums/ChatEventAction.rst
deleted file mode 100644
index 0403e781db..0000000000
--- a/docs/source/api/enums/ChatEventAction.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ChatEventAction
-===============
-
-.. autoclass:: pyrogram.enums.ChatEventAction()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatMemberStatus.rst b/docs/source/api/enums/ChatMemberStatus.rst
deleted file mode 100644
index bff23eda66..0000000000
--- a/docs/source/api/enums/ChatMemberStatus.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ChatMemberStatus
-================
-
-.. autoclass:: pyrogram.enums.ChatMemberStatus()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatMembersFilter.rst b/docs/source/api/enums/ChatMembersFilter.rst
deleted file mode 100644
index 5a970ffc6e..0000000000
--- a/docs/source/api/enums/ChatMembersFilter.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ChatMembersFilter
-=================
-
-.. autoclass:: pyrogram.enums.ChatMembersFilter()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ChatType.rst b/docs/source/api/enums/ChatType.rst
deleted file mode 100644
index dd653055fa..0000000000
--- a/docs/source/api/enums/ChatType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ChatType
-========
-
-.. autoclass:: pyrogram.enums.ChatType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageEntityType.rst b/docs/source/api/enums/MessageEntityType.rst
deleted file mode 100644
index c7a8965f12..0000000000
--- a/docs/source/api/enums/MessageEntityType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-MessageEntityType
-=================
-
-.. autoclass:: pyrogram.enums.MessageEntityType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageMediaType.rst b/docs/source/api/enums/MessageMediaType.rst
deleted file mode 100644
index 04e439d20e..0000000000
--- a/docs/source/api/enums/MessageMediaType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-MessageMediaType
-================
-
-.. autoclass:: pyrogram.enums.MessageMediaType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessageServiceType.rst b/docs/source/api/enums/MessageServiceType.rst
deleted file mode 100644
index 2de56818d8..0000000000
--- a/docs/source/api/enums/MessageServiceType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-MessageServiceType
-==================
-
-.. autoclass:: pyrogram.enums.MessageServiceType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/MessagesFilter.rst b/docs/source/api/enums/MessagesFilter.rst
deleted file mode 100644
index 090907076a..0000000000
--- a/docs/source/api/enums/MessagesFilter.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-MessagesFilter
-==============
-
-.. autoclass:: pyrogram.enums.MessagesFilter()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/NextCodeType.rst b/docs/source/api/enums/NextCodeType.rst
deleted file mode 100644
index 46164e47d6..0000000000
--- a/docs/source/api/enums/NextCodeType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-NextCodeType
-============
-
-.. autoclass:: pyrogram.enums.NextCodeType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/ParseMode.rst b/docs/source/api/enums/ParseMode.rst
deleted file mode 100644
index 1bcc74da04..0000000000
--- a/docs/source/api/enums/ParseMode.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-ParseMode
-=========
-
-.. autoclass:: pyrogram.enums.ParseMode()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/PollType.rst b/docs/source/api/enums/PollType.rst
deleted file mode 100644
index d00f9ce8a8..0000000000
--- a/docs/source/api/enums/PollType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-PollType
-========
-
-.. autoclass:: pyrogram.enums.PollType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/SentCodeType.rst b/docs/source/api/enums/SentCodeType.rst
deleted file mode 100644
index d738b195b1..0000000000
--- a/docs/source/api/enums/SentCodeType.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-SentCodeType
-============
-
-.. autoclass:: pyrogram.enums.SentCodeType()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/UserStatus.rst b/docs/source/api/enums/UserStatus.rst
deleted file mode 100644
index c9a77e1bf9..0000000000
--- a/docs/source/api/enums/UserStatus.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-UserStatus
-==========
-
-.. autoclass:: pyrogram.enums.UserStatus()
-    :members:
-
-.. raw:: html
-    :file: ./cleanup.html
\ No newline at end of file
diff --git a/docs/source/api/enums/cleanup.html b/docs/source/api/enums/cleanup.html
deleted file mode 100644
index bb9db7801a..0000000000
--- a/docs/source/api/enums/cleanup.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
\ No newline at end of file
diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst
deleted file mode 100644
index bd9f8b1da7..0000000000
--- a/docs/source/api/enums/index.rst
+++ /dev/null
@@ -1,47 +0,0 @@
-Enumerations
-============
-
-This page is about Pyrogram enumerations.
-Enumerations are types that hold a group of related values to be used whenever a constant value is required.
-They will help you deal with those values in a type-safe way and also enable code completion so that you can be sure
-to apply only a valid value among the expected ones.
-
------
-
-.. currentmodule:: pyrogram.enums
-
-.. autosummary::
-    :nosignatures:
-
-    ChatAction
-    ChatEventAction
-    ChatMemberStatus
-    ChatMembersFilter
-    ChatType
-    MessageEntityType
-    MessageMediaType
-    MessageServiceType
-    MessagesFilter
-    ParseMode
-    PollType
-    SentCodeType
-    NextCodeType
-    UserStatus
-
-.. toctree::
-    :hidden:
-
-    ChatAction
-    ChatEventAction
-    ChatMemberStatus
-    ChatMembersFilter
-    ChatType
-    MessageEntityType
-    MessageMediaType
-    MessageServiceType
-    MessagesFilter
-    ParseMode
-    PollType
-    SentCodeType
-    NextCodeType
-    UserStatus
\ No newline at end of file
diff --git a/docs/source/api/errors/bad-request.rst b/docs/source/api/errors/bad-request.rst
deleted file mode 100644
index ab13fdabb2..0000000000
--- a/docs/source/api/errors/bad-request.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-400 - BadRequest
-----------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/400_BAD_REQUEST.tsv
-    :delim: tab
-    :header-rows: 1
diff --git a/docs/source/api/errors/flood.rst b/docs/source/api/errors/flood.rst
deleted file mode 100644
index e01e012274..0000000000
--- a/docs/source/api/errors/flood.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-420 - Flood
------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/420_FLOOD.tsv
-    :delim: tab
-    :header-rows: 1
\ No newline at end of file
diff --git a/docs/source/api/errors/forbidden.rst b/docs/source/api/errors/forbidden.rst
deleted file mode 100644
index c2a8dcb80b..0000000000
--- a/docs/source/api/errors/forbidden.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-403 - Forbidden
----------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/403_FORBIDDEN.tsv
-    :delim: tab
-    :header-rows: 1
\ No newline at end of file
diff --git a/docs/source/api/errors/index.rst b/docs/source/api/errors/index.rst
deleted file mode 100644
index be2b80d46a..0000000000
--- a/docs/source/api/errors/index.rst
+++ /dev/null
@@ -1,37 +0,0 @@
-RPC Errors
-==========
-
-All Pyrogram API errors live inside the ``errors`` sub-package: ``pyrogram.errors``.
-The errors ids listed here are shown as *UPPER_SNAKE_CASE*, but the actual exception names to import from Pyrogram
-follow the usual *PascalCase* convention.
-
-.. code-block:: python
-
-    from pyrogram.errors import FloodWait
-
-    try:
-        ...
-    except FloodWait as e:
-        ...
-
-.. hlist::
-    :columns: 1
-
-    - :doc:`see-other`
-    - :doc:`bad-request`
-    - :doc:`unauthorized`
-    - :doc:`forbidden`
-    - :doc:`not-acceptable`
-    - :doc:`flood`
-    - :doc:`internal-server-error`
-
-.. toctree::
-    :hidden:
-
-    see-other
-    bad-request
-    unauthorized
-    forbidden
-    not-acceptable
-    flood
-    internal-server-error
\ No newline at end of file
diff --git a/docs/source/api/errors/internal-server-error.rst b/docs/source/api/errors/internal-server-error.rst
deleted file mode 100644
index 996d77eba5..0000000000
--- a/docs/source/api/errors/internal-server-error.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-500 - InternalServerError
--------------------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv
-    :delim: tab
-    :header-rows: 1
\ No newline at end of file
diff --git a/docs/source/api/errors/not-acceptable.rst b/docs/source/api/errors/not-acceptable.rst
deleted file mode 100644
index 79cfa8bcaf..0000000000
--- a/docs/source/api/errors/not-acceptable.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-406 - NotAcceptable
--------------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/406_NOT_ACCEPTABLE.tsv
-    :delim: tab
-    :header-rows: 1
\ No newline at end of file
diff --git a/docs/source/api/errors/see-other.rst b/docs/source/api/errors/see-other.rst
deleted file mode 100644
index 629b955764..0000000000
--- a/docs/source/api/errors/see-other.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-303 - SeeOther
---------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/303_SEE_OTHER.tsv
-    :delim: tab
-    :header-rows: 1
\ No newline at end of file
diff --git a/docs/source/api/errors/unauthorized.rst b/docs/source/api/errors/unauthorized.rst
deleted file mode 100644
index c56abeecc3..0000000000
--- a/docs/source/api/errors/unauthorized.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-401 - Unauthorized
-------------------
-
-.. csv-table::
-    :file: ../../../../compiler/errors/source/401_UNAUTHORIZED.tsv
-    :delim: tab
-    :header-rows: 1
diff --git a/docs/source/api/filters.rst b/docs/source/api/filters.rst
deleted file mode 100644
index eb3c9522b3..0000000000
--- a/docs/source/api/filters.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-Update Filters
-==============
-
-Filters are objects that can be used to filter the content of incoming updates.
-:doc:`Read more about how filters work <../topics/use-filters>`.
-
-Details
--------
-
-.. automodule:: pyrogram.filters
-    :members:
diff --git a/docs/source/api/handlers.rst b/docs/source/api/handlers.rst
deleted file mode 100644
index 8a8ac71477..0000000000
--- a/docs/source/api/handlers.rst
+++ /dev/null
@@ -1,66 +0,0 @@
-Update Handlers
-===============
-
-Handlers are used to instruct Pyrogram about which kind of updates you'd like to handle with your callback functions.
-For a much more convenient way of registering callback functions have a look at :doc:`Decorators ` instead.
-
-.. code-block:: python
-
-    from pyrogram import Client
-    from pyrogram.handlers import MessageHandler
-
-    app = Client("my_account")
-
-
-    def dump(client, message):
-        print(message)
-
-
-    app.add_handler(MessageHandler(dump))
-
-    app.run()
-
-.. contents:: Contents
-    :backlinks: none
-    :depth: 1
-    :local:
-
------
-
-.. currentmodule:: pyrogram.handlers
-
-Index
------
-
-.. hlist::
-    :columns: 3
-
-    - :class:`MessageHandler`
-    - :class:`EditedMessageHandler`
-    - :class:`DeletedMessagesHandler`
-    - :class:`CallbackQueryHandler`
-    - :class:`InlineQueryHandler`
-    - :class:`ChosenInlineResultHandler`
-    - :class:`ChatMemberUpdatedHandler`
-    - :class:`UserStatusHandler`
-    - :class:`PollHandler`
-    - :class:`DisconnectHandler`
-    - :class:`RawUpdateHandler`
-
------
-
-Details
--------
-
-.. Handlers
-.. autoclass:: MessageHandler()
-.. autoclass:: EditedMessageHandler()
-.. autoclass:: DeletedMessagesHandler()
-.. autoclass:: CallbackQueryHandler()
-.. autoclass:: InlineQueryHandler()
-.. autoclass:: ChosenInlineResultHandler()
-.. autoclass:: ChatMemberUpdatedHandler()
-.. autoclass:: UserStatusHandler()
-.. autoclass:: PollHandler()
-.. autoclass:: DisconnectHandler()
-.. autoclass:: RawUpdateHandler()
diff --git a/docs/source/conf.py b/docs/source/conf.py
deleted file mode 100644
index 3071cdc17b..0000000000
--- a/docs/source/conf.py
+++ /dev/null
@@ -1,91 +0,0 @@
-#  Pyrogram - Telegram MTProto API Client Library for Python
-#  Copyright (C) 2017-present Dan 
-#
-#  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
-import sys
-
-sys.path.insert(0, os.path.abspath("../.."))
-
-from pyrogram import __version__
-
-from pygments.styles.friendly import FriendlyStyle
-
-FriendlyStyle.background_color = "#f3f2f1"
-
-project = "Pyrogram"
-copyright = f"2017-present, Dan"
-author = "Dan"
-
-version = ".".join(__version__.split(".")[:-1])
-
-extensions = [
-    "sphinx.ext.autodoc",
-    "sphinx.ext.napoleon",
-    "sphinx.ext.autosummary",
-    "sphinx.ext.intersphinx",
-    "sphinx_copybutton"
-]
-
-intersphinx_mapping = {
-    "python": ("https://docs.python.org/3", None)
-}
-
-master_doc = "index"
-source_suffix = ".rst"
-autodoc_member_order = "bysource"
-
-templates_path = ["../resources/templates"]
-html_copy_source = False
-
-napoleon_use_rtype = False
-napoleon_use_param = False
-
-pygments_style = "friendly"
-
-copybutton_prompt_text = "$ "
-
-suppress_warnings = ["image.not_readable"]
-
-html_title = "Pyrogram Documentation"
-html_theme = "sphinx_rtd_theme"
-html_static_path = ["../resources/static"]
-html_show_sourcelink = True
-html_show_copyright = False
-html_theme_options = {
-    "canonical_url": "https://docs.pyrogram.org/",
-    "collapse_navigation": True,
-    "sticky_navigation": False,
-    "logo_only": True,
-    "display_version": False,
-    "style_external_links": True
-}
-
-html_logo = "../resources/static/img/pyrogram.png"
-html_favicon = "../resources/static/img/favicon.ico"
-
-latex_engine = "xelatex"
-latex_logo = "../resources/static/img/pyrogram.png"
-
-latex_elements = {
-    "pointsize": "12pt",
-    "fontpkg": r"""
-        \setmainfont{Open Sans}
-        \setsansfont{Bitter}
-        \setmonofont{Ubuntu Mono}
-        """
-}
diff --git a/docs/source/faq/client-started-but-nothing-happens.rst b/docs/source/faq/client-started-but-nothing-happens.rst
deleted file mode 100644
index ab85f51832..0000000000
--- a/docs/source/faq/client-started-but-nothing-happens.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-Client started, but nothing happens
-===================================
-
-A possible cause might be network issues, either yours or Telegram's. To check this, add the following code at
-the top of your script and run it again. You should see some error mentioning a socket timeout or an unreachable
-network:
-
-.. code-block:: python
-
-    import logging
-    logging.basicConfig(level=logging.INFO)
\ No newline at end of file
diff --git a/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst b/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst
deleted file mode 100644
index 37d47a6444..0000000000
--- a/docs/source/faq/code-hangs-when-calling-stop-restart-add-remove-handler.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-Code hangs when calling stop, restart, add/remove_handler
-=========================================================
-
-You tried to ``.stop()``, ``.restart()``, ``.add_handler()`` or ``.remove_handler()`` inside a running handler, but
-that can't be done because the way Pyrogram deals with handlers would make it hang.
-
-When calling one of the methods above inside an event handler, Pyrogram needs to wait for all running handlers to finish
-in order to continue. Since your handler is blocking the execution by waiting for the called method to finish
-and since Pyrogram needs to wait for your handler to finish, you are left with a deadlock.
-
-The solution to this problem is to pass ``block=False`` to such methods so that they return immediately and the actual
-code called asynchronously.
\ No newline at end of file
diff --git a/docs/source/faq/how-to-avoid-flood-waits.rst b/docs/source/faq/how-to-avoid-flood-waits.rst
deleted file mode 100644
index 06d1cdc2a9..0000000000
--- a/docs/source/faq/how-to-avoid-flood-waits.rst
+++ /dev/null
@@ -1,23 +0,0 @@
-How to avoid Flood Waits?
-=========================
-
-Slow things down and make less requests. Moreover, exact limits are unknown and can change anytime based on normal
-usages.
-
-When a flood wait happens the server will tell you how much time to wait before continuing.
-The following shows how to catch the exception in your code and wait the required seconds.
-
-.. code-block:: python
-
-  import asyncio
-  from pyrogram.errors import FloodWait
-
-  ...
-      try:
-          ...  # Your code
-      except FloodWait as e:
-          await asyncio.sleep(e.value)  # Wait "value" seconds before continuing
-  ...
-
-
-More info about error handling can be found :doc:`here <../start/errors>`.
diff --git a/docs/source/faq/how-to-use-webhooks.rst b/docs/source/faq/how-to-use-webhooks.rst
deleted file mode 100644
index b0dd4008cd..0000000000
--- a/docs/source/faq/how-to-use-webhooks.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-How to use webhooks?
-====================
-
-There is no webhook in Pyrogram, simply because there is no HTTP involved. However, a similar technique is
-being used to make receiving updates efficient.
-
-Pyrogram uses persistent connections via TCP sockets to interact with the server and instead of actively asking for
-updates every time (polling), Pyrogram will sit down and wait for the server to send updates by itself the very moment
-they are available (server push).
diff --git a/docs/source/faq/index.rst b/docs/source/faq/index.rst
deleted file mode 100644
index 3d4a00362b..0000000000
--- a/docs/source/faq/index.rst
+++ /dev/null
@@ -1,45 +0,0 @@
-Frequently Asked Questions
-==========================
-
-This FAQ page provides answers to common questions about Pyrogram and, to some extent, Telegram in general.
-
-**Contents**
-
-- :doc:`why-is-the-api-key-needed-for-bots`
-- :doc:`how-to-use-webhooks`
-- :doc:`using-the-same-file-id-across-different-accounts`
-- :doc:`using-multiple-clients-at-once-on-the-same-account`
-- :doc:`client-started-but-nothing-happens`
-- :doc:`what-are-the-ip-addresses-of-telegram-data-centers`
-- :doc:`migrating-the-account-to-another-data-center`
-- :doc:`why-is-the-client-reacting-slowly-in-supergroups-channels`
-- :doc:`peer-id-invalid-error`
-- :doc:`code-hangs-when-calling-stop-restart-add-remove-handler`
-- :doc:`unicodeencodeerror-codec-cant-encode`
-- :doc:`uploading-with-urls-gives-error-webpage-curl-failed`
-- :doc:`sqlite3-operationalerror-database-is-locked`
-- :doc:`sqlite3-interfaceerror-error-binding-parameter`
-- :doc:`socket-send-oserror-timeouterror-connection-lost-reset`
-- :doc:`how-to-avoid-flood-waits`
-- :doc:`the-account-has-been-limited-deactivated`
-
-.. toctree::
-    :hidden:
-
-    why-is-the-api-key-needed-for-bots
-    how-to-use-webhooks
-    using-the-same-file-id-across-different-accounts
-    using-multiple-clients-at-once-on-the-same-account
-    client-started-but-nothing-happens
-    what-are-the-ip-addresses-of-telegram-data-centers
-    migrating-the-account-to-another-data-center
-    why-is-the-client-reacting-slowly-in-supergroups-channels
-    peer-id-invalid-error
-    code-hangs-when-calling-stop-restart-add-remove-handler
-    unicodeencodeerror-codec-cant-encode
-    uploading-with-urls-gives-error-webpage-curl-failed
-    sqlite3-operationalerror-database-is-locked
-    sqlite3-interfaceerror-error-binding-parameter
-    socket-send-oserror-timeouterror-connection-lost-reset
-    how-to-avoid-flood-waits
-    the-account-has-been-limited-deactivated
\ No newline at end of file
diff --git a/docs/source/faq/migrating-the-account-to-another-data-center.rst b/docs/source/faq/migrating-the-account-to-another-data-center.rst
deleted file mode 100644
index 7ae76a1e36..0000000000
--- a/docs/source/faq/migrating-the-account-to-another-data-center.rst
+++ /dev/null
@@ -1,10 +0,0 @@
-Migrating the account to another data center
-============================================
-
-This question is asked by people who find their account always being connected to one DC (data center), but are
-connecting from a place far away, thus resulting in slower interactions when using the API because of the greater
-physical distance between the user and the associated DC.
-
-When registering an account for the first time, is up to Telegram to decide which DC the new user is going to be
-created in. It's also up to the server to decide whether to automatically migrate a user in case of prolonged usages
-from a distant location.
\ No newline at end of file
diff --git a/docs/source/faq/peer-id-invalid-error.rst b/docs/source/faq/peer-id-invalid-error.rst
deleted file mode 100644
index 197ea8374d..0000000000
--- a/docs/source/faq/peer-id-invalid-error.rst
+++ /dev/null
@@ -1,14 +0,0 @@
-PEER_ID_INVALID error
-=====================
-
-This error could mean several things:
-
-- The chat id you tried to use is simply wrong, check it again.
-- The chat id refers to a group or channel you are not a member of.
-- The chat id argument you passed is in form of a string; you have to convert it into an integer with ``int(chat_id)``.
-- The chat id refers to a user or chat your current session hasn't met yet.
-
-About the last point: in order for you to meet a user and thus communicate with them, you should ask yourself how to
-contact people using official apps. The answer is the same for Pyrogram too and involves normal usages such as searching
-for usernames, meeting them in a common group, having their phone contacts saved, getting a message mentioning them
-or obtaining the dialogs list.
\ No newline at end of file
diff --git a/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst b/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
deleted file mode 100644
index 85c5065015..0000000000
--- a/docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-socket.send(), OSError(), TimeoutError(), Connection lost/reset
-===============================================================
-
-If you get any of these errors chances are you ended up with a slow or inconsistent network connection.
-Another reason could be because you are blocking the event loop for too long.
-
-You can consider the following:
-
-- Use Pyrogram asynchronously in its intended way.
-- Use shorter non-asynchronous processing loops.
-- Use ``asyncio.sleep()`` instead of ``time.sleep()``.
-- Use a stable network connection.
diff --git a/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst b/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst
deleted file mode 100644
index 5d148186b6..0000000000
--- a/docs/source/faq/sqlite3-interfaceerror-error-binding-parameter.rst
+++ /dev/null
@@ -1,13 +0,0 @@
-sqlite3.InterfaceError: Error binding parameter
-===============================================
-
-This error occurs when you pass a chat id value of the wrong type when trying to call a method. Most likely, you
-accidentally passed the whole user or chat object instead of the id or username.
-
-.. code-block:: python
-
-    # Wrong. You passed the whole Chat instance
-    app.send_message(chat, "text")
-
-    # Correct
-    app.send_message(chat.id, "text")
\ No newline at end of file
diff --git a/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst b/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst
deleted file mode 100644
index b5cb2d8293..0000000000
--- a/docs/source/faq/sqlite3-operationalerror-database-is-locked.rst
+++ /dev/null
@@ -1,17 +0,0 @@
-sqlite3.OperationalError: database is locked
-============================================
-
-This error occurs when more than one process is using the same session file, that is, when you run two or more clients
-at the same time using the same session name or in case another program has accessed the file.
-
-For example, it could occur when a background script is still running and you forgot about it. In this case, you either
-restart your system or find and kill the process that is locking the database. On Unix based systems, you can try the
-following:
-
-#. ``cd`` into your session file directory.
-#. ``fuser my_account.session`` to find the process id.
-#. ``kill 1234`` to gracefully stop the process.
-#. If the last command doesn't help, use ``kill -9 1234`` instead.
-
-If you want to run multiple clients on the same account, you must authorize your account (either user or bot)
-from the beginning every time, and use different session names for each parallel client you are going to use.
\ No newline at end of file
diff --git a/docs/source/faq/the-account-has-been-limited-deactivated.rst b/docs/source/faq/the-account-has-been-limited-deactivated.rst
deleted file mode 100644
index 79d589eaf8..0000000000
--- a/docs/source/faq/the-account-has-been-limited-deactivated.rst
+++ /dev/null
@@ -1,16 +0,0 @@
-The account has been limited/deactivated
-========================================
-
-Pyrogram is a framework that interfaces with Telegram; it is at your commands, meaning it only does what you tell it to
-do, the rest is up to you and Telegram (see `Telegram's ToS`_).
-
-If you found your account being limited/deactivated, it could be due spam/flood/abuse of the API or the usage of certain
-virtual/VoIP numbers.
-
-If you think your account was limited/deactivated by mistake, you can write to recover@telegram.org, contact
-`@SpamBot`_ or use `this form`_.
-
-.. _@SpamBot: https://t.me/spambot
-.. _this form: https://telegram.org/support
-.. _Telegram's ToS: https://telegram.org/tos
-
diff --git a/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst b/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst
deleted file mode 100644
index a4511ce5d1..0000000000
--- a/docs/source/faq/unicodeencodeerror-codec-cant-encode.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-UnicodeEncodeError: '...' codec can't encode ...
-================================================
-
-Where ```` might be *ascii*, *cp932*, *charmap* or anything else other than *utf-8*. This error usually
-shows up when you try to print something and has very little to do with Pyrogram itself as it is strictly related to
-your own terminal. To fix it, either find a way to change the encoding settings of your terminal to UTF-8 or switch to
-another terminal altogether.
diff --git a/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst b/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst
deleted file mode 100644
index 2b7c5a7e9f..0000000000
--- a/docs/source/faq/uploading-with-urls-gives-error-webpage-curl-failed.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-Uploading with URLs gives error WEBPAGE_CURL_FAILED
-===================================================
-
-When uploading media files using an URL, the server automatically tries to download the media and uploads it to the
-Telegram cloud. This error usually happens in case the provided URL is not publicly accessible by Telegram itself or the
-media file is too large. In such cases, your only option is to download the media yourself and upload it from your
-local machine.
\ No newline at end of file
diff --git a/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst b/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst
deleted file mode 100644
index ab73b29c1d..0000000000
--- a/docs/source/faq/using-multiple-clients-at-once-on-the-same-account.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-Using multiple clients at once on the same account
-==================================================
-
-Both user and bot accounts are able to run multiple sessions in parallel. However, you must not use the same session
-in more than one client at the same time. The correct way to run multiple clients on the same account is by authorizing
-your account (either user or bot) from the beginning each time, and use one separate session for each parallel client.
-
diff --git a/docs/source/faq/using-the-same-file-id-across-different-accounts.rst b/docs/source/faq/using-the-same-file-id-across-different-accounts.rst
deleted file mode 100644
index 00305ef12d..0000000000
--- a/docs/source/faq/using-the-same-file-id-across-different-accounts.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-Using the same file_id across different accounts
-================================================
-
-Telegram file_id strings are bound to the account which generated them. An attempt in using a foreign file id will
-result in errors such as ``[400 MEDIA_EMPTY]``. The only exception are stickers' file ids; you can use them across
-different accounts without any problem.
\ No newline at end of file
diff --git a/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst b/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst
deleted file mode 100644
index c951230ba6..0000000000
--- a/docs/source/faq/what-are-the-ip-addresses-of-telegram-data-centers.rst
+++ /dev/null
@@ -1,30 +0,0 @@
-What are the IP addresses of Telegram Data Centers?
-===================================================
-
-Telegram is currently composed by a decentralized, multi-DC infrastructure (currently 5 DCs, each of which can
-work independently) spread across different locations worldwide. However, some of the less busy DCs have been lately
-dismissed and their IP addresses are now kept as aliases to the nearest one.
-
-.. csv-table:: Production Environment
-    :header: ID, Location, IPv4, IPv6
-    :widths: auto
-    :align: center
-
-    DC1, "MIA, Miami FL, USA", ``149.154.175.53``, ``2001:b28:f23d:f001::a``
-    DC2, "AMS, Amsterdam, NL", ``149.154.167.51``, ``2001:67c:4e8:f002::a``
-    DC3*, "MIA, Miami FL, USA", ``149.154.175.100``, ``2001:b28:f23d:f003::a``
-    DC4, "AMS, Amsterdam, NL", ``149.154.167.91``, ``2001:67c:4e8:f004::a``
-    DC5, "SIN, Singapore, SG", ``91.108.56.130``, ``2001:b28:f23f:f005::a``
-
-.. csv-table:: Test Environment
-    :header: ID, Location, IPv4, IPv6
-    :widths: auto
-    :align: center
-
-    DC1, "MIA, Miami FL, USA", ``149.154.175.10``, ``2001:b28:f23d:f001::e``
-    DC2, "AMS, Amsterdam, NL", ``149.154.167.40``, ``2001:67c:4e8:f002::e``
-    DC3*, "MIA, Miami FL, USA", ``149.154.175.117``, ``2001:b28:f23d:f003::e``
-
-.. centered:: More info about the Test Environment can be found :doc:`here <../topics/test-servers>`.
-
-***** Alias DC
\ No newline at end of file
diff --git a/docs/source/faq/why-is-the-api-key-needed-for-bots.rst b/docs/source/faq/why-is-the-api-key-needed-for-bots.rst
deleted file mode 100644
index 2e062d405d..0000000000
--- a/docs/source/faq/why-is-the-api-key-needed-for-bots.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-Why is the API key needed for bots?
-===================================
-
-Requests against the official bot API endpoints are made via JSON/HTTP and are handled by an intermediate server
-application that implements the MTProto protocol and uses its own API key to communicate with the MTProto servers.
-
-.. figure:: //_static/img/mtproto-vs-bot-api.png
-    :align: center
-
-Using MTProto is the only way to communicate with the actual Telegram servers, and the main API requires developers to
-identify applications by means of a unique key; the bot token identifies a bot as a user and replaces the user's phone
-number only.
\ No newline at end of file
diff --git a/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst b/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst
deleted file mode 100644
index 4d19616469..0000000000
--- a/docs/source/faq/why-is-the-client-reacting-slowly-in-supergroups-channels.rst
+++ /dev/null
@@ -1,18 +0,0 @@
-Why is the client reacting slowly in supergroups/channels?
-==========================================================
-
-Because of how Telegram works internally, every message you receive and send must pass through the creator's DC, and in
-the worst case where you, the creator and another member all belong to three different DCs, the other member messages
-have to go through from their DC to the creator's DC and finally to your DC. This is applied to each message and member
-of a supergroup/channel and the process will inevitably take its time.
-
-Another reason that makes responses come slowly is that messages are dispatched by priority. Depending on the kind
-of member, some users receive messages faster than others and for big and busy supergroups the delay might become
-noticeable, especially if you are among the lower end of the priority list:
-
-1. Creator.
-2. Administrators.
-3. Bots.
-4. Mentioned users.
-5. Recent online users.
-6. Everyone else.
\ No newline at end of file
diff --git a/docs/source/index.rst b/docs/source/index.rst
deleted file mode 100644
index d96223cb13..0000000000
--- a/docs/source/index.rst
+++ /dev/null
@@ -1,172 +0,0 @@
-Welcome to Pyrogram
-===================
-
-.. raw:: html
-
-    
-
-    

- Telegram MTProto API Framework for Python - -
- - Homepage - - • - - Development - - • - - Releases - - • - - News - -

- -.. code-block:: python - - from pyrogram import Client, filters - - app = Client("my_account") - - - @app.on_message(filters.private) - async def hello(client, message): - await message.reply("Hello from Pyrogram!") - - - app.run() - -**Pyrogram** is a modern, elegant and asynchronous :doc:`MTProto API ` framework. -It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity -(bot API alternative) using Python. - -Support -------- - -If you'd like to support Pyrogram, you can consider: - -- `Become a GitHub sponsor `_. -- `Become a LiberaPay patron `_. -- `Become an OpenCollective backer `_. - -How the Documentation is Organized ----------------------------------- - -Contents are organized into sections composed of self-contained topics which can be all accessed from the sidebar, or by -following them in order using the :guilabel:`Next` button at the end of each page. -You can also switch to Dark or Light theme or leave on Auto (follows system preferences) by using the dedicated button -in the top left corner. - -Here below you can, instead, find a list of the most relevant pages for a quick access. - -First Steps -^^^^^^^^^^^ - -.. hlist:: - :columns: 1 - - - :doc:`Quick Start `: Overview to get you started quickly. - - :doc:`Invoking Methods `: How to call Pyrogram's methods. - - :doc:`Handling Updates `: How to handle Telegram updates. - - :doc:`Error Handling `: How to handle API errors correctly. - -API Reference -^^^^^^^^^^^^^ - -.. hlist:: - :columns: 1 - - - :doc:`Pyrogram Client `: Reference details about the Client class. - - :doc:`Available Methods `: List of available high-level methods. - - :doc:`Available Types `: List of available high-level types. - - :doc:`Enumerations `: List of available enumerations. - - :doc:`Bound Methods `: List of convenient bound methods. - -Meta -^^^^ - -.. hlist:: - :columns: 1 - - - :doc:`Pyrogram FAQ `: Answers to common Pyrogram questions. - - :doc:`Support Pyrogram `: Ways to show your appreciation. - - :doc:`Release Notes `: Release notes for Pyrogram releases. - -.. toctree:: - :hidden: - :caption: Introduction - - intro/quickstart - intro/install - -.. toctree:: - :hidden: - :caption: Getting Started - - start/setup - start/auth - start/invoking - start/updates - start/errors - start/examples/index - -.. toctree:: - :hidden: - :caption: API Reference - - api/client - api/methods/index - api/types/index - api/bound-methods/index - api/enums/index - api/handlers - api/decorators - api/errors/index - api/filters - -.. toctree:: - :hidden: - :caption: Topic Guides - - topics/use-filters - topics/create-filters - topics/more-on-updates - topics/client-settings - topics/speedups - topics/text-formatting - topics/synchronous - topics/smart-plugins - topics/storage-engines - topics/serializing - topics/proxy - topics/scheduling - topics/mtproto-vs-botapi - topics/debugging - topics/test-servers - topics/advanced-usage - topics/voice-calls - -.. toctree:: - :hidden: - :caption: Meta - - faq/index - support - releases/index - -.. toctree:: - :hidden: - :caption: Telegram Raw API - - telegram/functions/index - telegram/types/index - telegram/base/index \ No newline at end of file diff --git a/docs/source/intro/install.rst b/docs/source/intro/install.rst deleted file mode 100644 index c45c384489..0000000000 --- a/docs/source/intro/install.rst +++ /dev/null @@ -1,50 +0,0 @@ -Install Guide -============= - -Being a modern Python framework, Pyrogram requires an up to date version of Python to be installed in your system. -We recommend using the latest versions of both Python 3 and pip. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Install Pyrogram ----------------- - -- The easiest way to install and upgrade Pyrogram to its latest stable version is by using **pip**: - - .. code-block:: text - - $ pip3 install -U pyrogram - -- or, with :doc:`TgCrypto <../topics/speedups>` as extra requirement (recommended): - - .. code-block:: text - - $ pip3 install -U pyrogram tgcrypto - -Bleeding Edge -------------- - -You can install the development version from the git ``master`` branch using this command: - -.. code-block:: text - - $ pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip - -Verifying ---------- - -To verify that Pyrogram is correctly installed, open a Python shell and import it. -If no error shows up you are good to go. - -.. parsed-literal:: - - >>> import pyrogram - >>> pyrogram.__version__ - 'x.y.z' - -.. _`Github repo`: http://github.com/pyrogram/pyrogram diff --git a/docs/source/intro/quickstart.rst b/docs/source/intro/quickstart.rst deleted file mode 100644 index 29c355e7c7..0000000000 --- a/docs/source/intro/quickstart.rst +++ /dev/null @@ -1,56 +0,0 @@ -Quick Start -=========== - -The next few steps serve as a quick start to see Pyrogram in action as fast as possible. - -Get Pyrogram Real Fast ----------------------- - -.. admonition :: Cloud Credits - :class: tip - - If you need a cloud server to host your applications, try Hetzner Cloud. You can sign up with - `this link `_ to get €20 in cloud credits. - -1. Install Pyrogram with ``pip3 install -U pyrogram``. - -2. Get your own Telegram API key from https://my.telegram.org/apps. - -3. Open the text editor of your choice and paste the following: - - .. code-block:: python - - import asyncio - from pyrogram import Client - - api_id = 12345 - api_hash = "0123456789abcdef0123456789abcdef" - - - async def main(): - async with Client("my_account", api_id, api_hash) as app: - await app.send_message("me", "Greetings from **Pyrogram**!") - - - asyncio.run(main()) - -4. Replace *api_id* and *api_hash* values with your own. - -5. Save the file as ``hello.py``. - -6. Run the script with ``python3 hello.py`` - -7. Follow the instructions on your terminal to login. - -8. Watch Pyrogram send a message to yourself. - -Enjoy the API -------------- - -That was just a quick overview. In the next few pages of the introduction, we'll take a much more in-depth look of what -we have just done above. - -If you are feeling eager to continue you can take a shortcut to :doc:`../start/invoking` and come back -later to learn some more details. - -.. _community: https://t.me/Pyrogram diff --git a/docs/source/start/auth.rst b/docs/source/start/auth.rst deleted file mode 100644 index ba28ac69b7..0000000000 --- a/docs/source/start/auth.rst +++ /dev/null @@ -1,93 +0,0 @@ -Authorization -============= - -Once a :doc:`project is set up `, you will still have to follow a few steps before you can actually use Pyrogram to make -API calls. This section provides all the information you need in order to authorize yourself as user or bot. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -User Authorization ------------------- - -In order to use the API, Telegram requires that users be authorized via their phone numbers. -Pyrogram automatically manages this process, all you need to do is create an instance of the -:class:`~pyrogram.Client` class by passing to it a ``name`` of your choice (e.g.: "my_account") and call -the :meth:`~pyrogram.Client.run` method: - -.. code-block:: python - - from pyrogram import Client - - api_id = 12345 - api_hash = "0123456789abcdef0123456789abcdef" - - app = Client("my_account", api_id=api_id, api_hash=api_hash) - - app.run() - -This starts an interactive shell asking you to input your **phone number**, including your `Country Code`_ (the plus -``+`` and minus ``-`` symbols can be omitted) and the **phone code** you will receive in your devices that are already -authorized or via SMS: - -.. code-block:: text - - Enter phone number: +1-123-456-7890 - Is "+1-123-456-7890" correct? (y/n): y - Enter phone code: 12345 - Logged in successfully - -After successfully authorizing yourself, a new file called ``my_account.session`` will be created allowing Pyrogram to -execute API calls with your identity. This file is personal and will be loaded again when you restart your app. -You can now remove the api_id and api_hash values from the code as they are not needed anymore. - -.. note:: - - The code above does nothing except asking for credentials and keeping the client online, hit :guilabel:`CTRL+C` now - to stop your application and keep reading. - -Bot Authorization ------------------ - -Bots are a special kind of users that are authorized via their tokens (instead of phone numbers), which are created by -the `Bot Father`_. Bot tokens replace the users' phone numbers only — you still need to -:doc:`configure a Telegram API key <../start/setup>` with Pyrogram, even when using bots. - -The authorization process is automatically managed. All you need to do is choose a ``name`` (can be anything, -usually your bot username) and pass your bot token using the ``bot_token`` parameter. The session file will be named -after the session name, which will be ``my_bot.session`` for the example below. - -.. code-block:: python - - from pyrogram import Client - - api_id = 12345 - api_hash = "0123456789abcdef0123456789abcdef" - bot_token = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" - - app = Client( - "my_bot", - api_id=api_id, api_hash=api_hash, - bot_token=bot_token - ) - - app.run() - -.. _Country Code: https://en.wikipedia.org/wiki/List_of_country_calling_codes -.. _Bot Father: https://t.me/botfather - -.. note:: - - The API key (api_id and api_hash) and the bot_token are not required anymore after a successful authorization. - This means you can now simply use the following: - - .. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - app.run() \ No newline at end of file diff --git a/docs/source/start/errors.rst b/docs/source/start/errors.rst deleted file mode 100644 index 402fea8b7c..0000000000 --- a/docs/source/start/errors.rst +++ /dev/null @@ -1,101 +0,0 @@ -Error Handling -============== - -Errors can be correctly handled with ``try...except`` blocks in order to control the behaviour of your application. -Pyrogram errors all live inside the ``errors`` package: - -.. code-block:: python - - from pyrogram import errors - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -RPCError --------- - -The father of all errors is named ``RPCError`` and is able to catch all Telegram API related errors. -This error is raised every time a method call against Telegram's API was unsuccessful. - -.. code-block:: python - - from pyrogram.errors import RPCError - -.. warning:: - - Avoid catching this error everywhere, especially when no feedback is given (i.e. by logging/printing the full error - traceback), because it makes it impossible to understand what went wrong. - -Error Categories ----------------- - -The ``RPCError`` packs together all the possible errors Telegram could raise, but to make things tidier, Pyrogram -provides categories of errors, which are named after the common HTTP errors and are subclass-ed from the ``RPCError``: - -.. code-block:: python - - from pyrogram.errors import BadRequest, Forbidden, ... - -- :doc:`303 - SeeOther <../api/errors/see-other>` -- :doc:`400 - BadRequest <../api/errors/bad-request>` -- :doc:`401 - Unauthorized <../api/errors/unauthorized>` -- :doc:`403 - Forbidden <../api/errors/forbidden>` -- :doc:`406 - NotAcceptable <../api/errors/not-acceptable>` -- :doc:`420 - Flood <../api/errors/flood>` -- :doc:`500 - InternalServerError <../api/errors/internal-server-error>` - -Single Errors -------------- - -For a fine-grained control over every single error, Pyrogram does also expose errors that deal each with a specific -issue. For example: - -.. code-block:: python - - from pyrogram.errors import FloodWait - -These errors subclass directly from the category of errors they belong to, which in turn subclass from the father -``RPCError``, thus building a class of error hierarchy such as this: - -- RPCError - - BadRequest - - ``MessageEmpty`` - - ``UsernameOccupied`` - - ``...`` - - InternalServerError - - ``RpcCallFail`` - - ``InterDcCallError`` - - ``...`` - - ``...`` - -.. _Errors: api/errors - -Unknown Errors --------------- - -In case Pyrogram does not know anything about a specific error yet, it raises a generic error from its known category, -for example, an unknown error with error code ``400``, will be raised as a ``BadRequest``. This way you can catch the -whole category of errors and be sure to also handle these unknown errors. - -Errors with Values ------------------- - -Exception objects may also contain some informative values. For example, ``FloodWait`` holds the amount of seconds you -have to wait before you can try again, some other errors contain the DC number on which the request must be repeated on. -The value is stored in the ``value`` attribute of the exception object: - -.. code-block:: python - - import asyncio - from pyrogram.errors import FloodWait - - ... - try: - ... # Your code - except FloodWait as e: - await asyncio.sleep(e.value) # Wait N seconds before continuing - ... \ No newline at end of file diff --git a/docs/source/start/examples/bot_keyboards.rst b/docs/source/start/examples/bot_keyboards.rst deleted file mode 100644 index b774a80e7e..0000000000 --- a/docs/source/start/examples/bot_keyboards.rst +++ /dev/null @@ -1,68 +0,0 @@ -bot_keyboards -============= - -This example will show you how to send normal and inline keyboards (as bot). - -You must log-in as a regular bot in order to send keyboards (use the token from @BotFather). -Any attempt in sending keyboards with a user account will be simply ignored by the server. - -send_message() is used as example, but a keyboard can be sent with any other send_* methods, -like send_audio(), send_document(), send_location(), etc... - -.. code-block:: python - - from pyrogram import Client - from pyrogram.types import (ReplyKeyboardMarkup, InlineKeyboardMarkup, - InlineKeyboardButton) - - # Create a client using your bot token - app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") - - - async def main(): - async with app: - await app.send_message( - "me", # Edit this - "This is a ReplyKeyboardMarkup example", - reply_markup=ReplyKeyboardMarkup( - [ - ["A", "B", "C", "D"], # First row - ["E", "F", "G"], # Second row - ["H", "I"], # Third row - ["J"] # Fourth row - ], - resize_keyboard=True # Make the keyboard smaller - ) - ) - - await app.send_message( - "me", # Edit this - "This is a InlineKeyboardMarkup example", - reply_markup=InlineKeyboardMarkup( - [ - [ # First row - InlineKeyboardButton( # Generates a callback query when pressed - "Button", - callback_data="data" - ), - InlineKeyboardButton( # Opens a web URL - "URL", - url="https://docs.pyrogram.org" - ), - ], - [ # Second row - InlineKeyboardButton( # Opens the inline interface - "Choose chat", - switch_inline_query="pyrogram" - ), - InlineKeyboardButton( # Opens the inline interface in the current chat - "Inline here", - switch_inline_query_current_chat="pyrogram" - ) - ] - ] - ) - ) - - - app.run(main()) \ No newline at end of file diff --git a/docs/source/start/examples/callback_queries.rst b/docs/source/start/examples/callback_queries.rst deleted file mode 100644 index 64da57b39a..0000000000 --- a/docs/source/start/examples/callback_queries.rst +++ /dev/null @@ -1,21 +0,0 @@ -callback_queries -================ - -This example shows how to handle callback queries, i.e.: queries coming from inline button presses. -It uses the @on_callback_query decorator to register a CallbackQueryHandler. - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") - - - @app.on_callback_query() - async def answer(client, callback_query): - await callback_query.answer( - f"Button contains: '{callback_query.data}'", - show_alert=True) - - - app.run() # Automatically start() and idle() \ No newline at end of file diff --git a/docs/source/start/examples/echo_bot.rst b/docs/source/start/examples/echo_bot.rst deleted file mode 100644 index de8288b5e4..0000000000 --- a/docs/source/start/examples/echo_bot.rst +++ /dev/null @@ -1,21 +0,0 @@ -echo_bot -======== - -This simple echo bot replies to every private text message. - -It uses the ``@on_message`` decorator to register a ``MessageHandler`` and applies two filters on it: -``filters.text`` and ``filters.private`` to make sure it will reply to private text messages only. - -.. code-block:: python - - from pyrogram import Client, filters - - app = Client("my_account") - - - @app.on_message(filters.text & filters.private) - async def echo(client, message): - await message.reply(message.text) - - - app.run() # Automatically start() and idle() \ No newline at end of file diff --git a/docs/source/start/examples/get_chat_history.rst b/docs/source/start/examples/get_chat_history.rst deleted file mode 100644 index 59939948b3..0000000000 --- a/docs/source/start/examples/get_chat_history.rst +++ /dev/null @@ -1,20 +0,0 @@ -get_history -=========== - -This example shows how to get the full message history of a chat, starting from the latest message. - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - async def main(): - async with app: - # "me" refers to your own chat (Saved Messages) - async for message in app.get_chat_history("me"): - print(message) - - - app.run(main()) \ No newline at end of file diff --git a/docs/source/start/examples/get_chat_members.rst b/docs/source/start/examples/get_chat_members.rst deleted file mode 100644 index 26636ca344..0000000000 --- a/docs/source/start/examples/get_chat_members.rst +++ /dev/null @@ -1,22 +0,0 @@ -get_chat_members -================ - -This example shows how to get all the members of a chat. - -.. code-block:: python - - from pyrogram import Client - - # Target channel/supergroup - TARGET = -100123456789 - - app = Client("my_account") - - - async def main(): - async with app: - async for member in app.get_chat_members(TARGET): - print(member) - - - app.run(main()) \ No newline at end of file diff --git a/docs/source/start/examples/get_dialogs.rst b/docs/source/start/examples/get_dialogs.rst deleted file mode 100644 index e5b1060966..0000000000 --- a/docs/source/start/examples/get_dialogs.rst +++ /dev/null @@ -1,19 +0,0 @@ -get_dialogs -=========== - -This example shows how to get the full dialogs list (as user). - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - async def main(): - async with app: - async for dialog in app.get_dialogs(): - print(dialog.chat.title or dialog.chat.first_name) - - - app.run(main()) \ No newline at end of file diff --git a/docs/source/start/examples/hello_world.rst b/docs/source/start/examples/hello_world.rst deleted file mode 100644 index 2902241e8c..0000000000 --- a/docs/source/start/examples/hello_world.rst +++ /dev/null @@ -1,20 +0,0 @@ -hello_world -=========== - -This example demonstrates a basic API usage - -.. code-block:: python - - from pyrogram import Client - - # Create a new Client instance - app = Client("my_account") - - - async def main(): - async with app: - # Send a message, Markdown is enabled by default - await app.send_message("me", "Hi there! I'm using **Pyrogram**") - - - app.run(main()) diff --git a/docs/source/start/examples/index.rst b/docs/source/start/examples/index.rst deleted file mode 100644 index d47b60e80d..0000000000 --- a/docs/source/start/examples/index.rst +++ /dev/null @@ -1,46 +0,0 @@ -Examples -======== - -This page contains example scripts to show you how Pyrogram looks like. - -Every script is working right away (provided you correctly set up your credentials), meaning you can simply copy-paste -and run. The only things you have to change are session names and target chats, where applicable. - -The examples listed below can be treated as building blocks for your own applications and are meant to be simple enough -to give you a basic idea. - ------ - -.. csv-table:: - :header: Example, Description - :widths: auto - :align: center - - :doc:`hello_world`, "Demonstration of basic API usage" - :doc:`echo_bot`, "Echo every private text message" - :doc:`welcome_bot`, "The Welcome Bot in @PyrogramChat" - :doc:`get_chat_history`, "Get the full message history of a chat" - :doc:`get_chat_members`, "Get all the members of a chat" - :doc:`get_dialogs`, "Get all of your dialog chats" - :doc:`callback_queries`, "Handle callback queries (as bot) coming from inline button presses" - :doc:`inline_queries`, "Handle inline queries (as bot) and answer with results" - :doc:`use_inline_bots`, "Query an inline bot (as user) and send a result to a chat" - :doc:`bot_keyboards`, "Send normal and inline keyboards using regular bots" - :doc:`raw_updates`, "Handle raw updates (old, should be avoided)" - -For more advanced examples, see https://snippets.pyrogram.org. - -.. toctree:: - :hidden: - - hello_world - echo_bot - welcome_bot - get_chat_history - get_chat_members - get_dialogs - callback_queries - inline_queries - use_inline_bots - bot_keyboards - raw_updates diff --git a/docs/source/start/examples/inline_queries.rst b/docs/source/start/examples/inline_queries.rst deleted file mode 100644 index b78c6e1cb8..0000000000 --- a/docs/source/start/examples/inline_queries.rst +++ /dev/null @@ -1,59 +0,0 @@ -inline_queries -============== - -This example shows how to handle inline queries. - -Two results are generated when users invoke the bot inline mode, e.g.: @pyrogrambot hi. -It uses the @on_inline_query decorator to register an InlineQueryHandler. - -.. code-block:: python - - from pyrogram import Client - from pyrogram.types import (InlineQueryResultArticle, InputTextMessageContent, - InlineKeyboardMarkup, InlineKeyboardButton) - - app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") - - - @app.on_inline_query() - async def answer(client, inline_query): - await inline_query.answer( - results=[ - InlineQueryResultArticle( - title="Installation", - input_message_content=InputTextMessageContent( - "Here's how to install **Pyrogram**" - ), - url="https://docs.pyrogram.org/intro/install", - description="How to install Pyrogram", - reply_markup=InlineKeyboardMarkup( - [ - [InlineKeyboardButton( - "Open website", - url="https://docs.pyrogram.org/intro/install" - )] - ] - ) - ), - InlineQueryResultArticle( - title="Usage", - input_message_content=InputTextMessageContent( - "Here's how to use **Pyrogram**" - ), - url="https://docs.pyrogram.org/start/invoking", - description="How to use Pyrogram", - reply_markup=InlineKeyboardMarkup( - [ - [InlineKeyboardButton( - "Open website", - url="https://docs.pyrogram.org/start/invoking" - )] - ] - ) - ) - ], - cache_time=1 - ) - - - app.run() # Automatically start() and idle() \ No newline at end of file diff --git a/docs/source/start/examples/raw_updates.rst b/docs/source/start/examples/raw_updates.rst deleted file mode 100644 index 463a45a80b..0000000000 --- a/docs/source/start/examples/raw_updates.rst +++ /dev/null @@ -1,18 +0,0 @@ -raw_updates -=========== - -This example shows how to handle raw updates. - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - @app.on_raw_update() - async def raw(client, update, users, chats): - print(update) - - - app.run() # Automatically start() and idle() diff --git a/docs/source/start/examples/use_inline_bots.rst b/docs/source/start/examples/use_inline_bots.rst deleted file mode 100644 index 8a2a72acc4..0000000000 --- a/docs/source/start/examples/use_inline_bots.rst +++ /dev/null @@ -1,25 +0,0 @@ -use_inline_bots -=============== - -This example shows how to query an inline bot (as user). - -.. code-block:: python - - from pyrogram import Client - - # Create a new Client - app = Client("my_account") - - - async def main(): - async with app: - # Get bot results for "hello" from the inline bot @vid - bot_results = await app.get_inline_bot_results("vid", "hello") - - # Send the first result to your own chat (Saved Messages) - await app.send_inline_bot_result( - "me", bot_results.query_id, - bot_results.results[0].id) - - - app.run(main()) \ No newline at end of file diff --git a/docs/source/start/examples/welcome_bot.rst b/docs/source/start/examples/welcome_bot.rst deleted file mode 100644 index 4e30ea7f0a..0000000000 --- a/docs/source/start/examples/welcome_bot.rst +++ /dev/null @@ -1,30 +0,0 @@ -welcome_bot -=========== - -This example uses the ``emoji`` module to easily add emoji in your text messages and ``filters`` -to make it only work for specific messages in a specific chat. - -.. code-block:: python - - from pyrogram import Client, emoji, filters - - # Target chat. Can also be a list of multiple chat ids/usernames - TARGET = -100123456789 - # Welcome message template - MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.org/)'s group chat {}!" - - app = Client("my_account") - - - # Filter in only new_chat_members updates generated in TARGET chat - @app.on_message(filters.chat(TARGET) & filters.new_chat_members) - async def welcome(client, message): - # Build the new members list (with mentions) by using their first_name - new_members = [u.mention for u in message.new_chat_members] - # Build the welcome message by using an emoji and the list we built above - text = MESSAGE.format(emoji.SPARKLES, ", ".join(new_members)) - # Send the welcome message, without the web page preview - await message.reply_text(text, disable_web_page_preview=True) - - - app.run() # Automatically start() and idle() \ No newline at end of file diff --git a/docs/source/start/invoking.rst b/docs/source/start/invoking.rst deleted file mode 100644 index 415ef848b4..0000000000 --- a/docs/source/start/invoking.rst +++ /dev/null @@ -1,110 +0,0 @@ -Invoking Methods -================ - -At this point, we have successfully :doc:`installed Pyrogram <../intro/install>` and :doc:`authorized ` our -account; we are now aiming towards the core of the framework. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Basic Usage ------------ - -Making API calls with Pyrogram is very simple. Here's a basic example we are going to examine step by step: - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - async def main(): - async with app: - await app.send_message("me", "Hi!") - - - app.run(main()) - -Step-by-step -^^^^^^^^^^^^ - -#. Let's begin by importing the Client class. - - .. code-block:: python - - from pyrogram import Client - -#. Now instantiate a new Client object, "my_account" is a session name of your choice. - - .. code-block:: python - - app = Client("my_account") - -#. Async methods must be invoked within an async context. - Here we define an async function and put our code inside. Also notice the ``await`` keyword in front of the method - call; this is required for all asynchronous methods. - - .. code-block:: python - - async def main(): - async with app: - await app.send_message("me", "Hi!") - -#. Finally, we tell Python to schedule our ``main()`` async function by using Pyrogram's :meth:`~pyrogram.Client.run` - method. - - .. code-block:: python - - app.run(main()) - -Context Manager ---------------- - -The ``async with`` statement starts a context manager, which is used as a shortcut for starting, executing and stopping -the Client, asynchronously. It does so by automatically calling :meth:`~pyrogram.Client.start` and -:meth:`~pyrogram.Client.stop` in a more convenient way which also gracefully stops the client, even in case of -unhandled exceptions in your code. - -Below there's the same example as above, but without the use of the context manager: - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - async def main(): - await app.start() - await app.send_message("me", "Hi!") - await app.stop() - - - app.run(main()) - -Using asyncio.run() -------------------- - -Alternatively to the :meth:`~pyrogram.Client.run` method, you can use Python's ``asyncio.run()`` to execute the main -function, with one little caveat: the Client instance (and possibly other asyncio resources you are going to use) must -be instantiated inside the main function. - -.. code-block:: python - - import asyncio - from pyrogram import Client - - - async def main(): - app = Client("my_account") - - async with app: - await app.send_message("me", "Hi!") - - - asyncio.run(main()) \ No newline at end of file diff --git a/docs/source/start/setup.rst b/docs/source/start/setup.rst deleted file mode 100644 index b8fd6effd7..0000000000 --- a/docs/source/start/setup.rst +++ /dev/null @@ -1,40 +0,0 @@ -Project Setup -============= - -We have just :doc:`installed Pyrogram <../intro/install>`. In this page we'll discuss what you need to do in order to set up a -project with the framework. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -API Key -------- - -The first step requires you to obtain a valid Telegram API key (api_id and api_hash pair): - -#. Visit https://my.telegram.org/apps and log in with your Telegram account. -#. Fill out the form with your details and register a new Telegram application. -#. Done. The API key consists of two parts: **api_id** and **api_hash**. Keep it secret. - -.. note:: - - The API key defines a token for a Telegram *application* you are going to build. - This means that you are able to authorize multiple users or bots with a single API key. - -Configuration -------------- - -Having the API key from the previous step in handy, we can now begin to configure a Pyrogram project: pass your API key to Pyrogram by using the *api_id* and *api_hash* parameters of the Client class: - -.. code-block:: python - - from pyrogram import Client - - api_id = 12345 - api_hash = "0123456789abcdef0123456789abcdef" - - app = Client("my_account", api_id=api_id, api_hash=api_hash) \ No newline at end of file diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst deleted file mode 100644 index 685128c21c..0000000000 --- a/docs/source/start/updates.rst +++ /dev/null @@ -1,78 +0,0 @@ -Handling Updates -================ - -:doc:`Invoking API methods ` sequentially is one way to use Pyrogram. This page deals with Telegram updates -and how to handle new incoming messages or other events in Pyrogram. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Defining Updates ----------------- - -Updates are events that happen in your Telegram account (incoming messages, new members join, -bot button presses, etc.), which are meant to notify you about a new specific state that has changed. These updates are -handled by registering one or more callback functions in your app using :doc:`Handlers <../api/handlers>`. - -Each handler deals with a specific event and once a matching update arrives from Telegram, your registered callback -function will be called back by the framework and its body executed. - -Registering a Handler ---------------------- - -To explain how handlers work let's examine the one which will be in charge for handling :class:`~pyrogram.types.Message` -updates coming from all around your chats. Every other kind of handler shares the same setup logic and you should not -have troubles settings them up once you learn from this section. - -Using Decorators -^^^^^^^^^^^^^^^^ - -The most elegant way to register a message handler is by using the :meth:`~pyrogram.Client.on_message` decorator: - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - - @app.on_message() - async def my_handler(client, message): - await message.forward("me") - - - app.run() - -The defined function ``my_handler``, which accepts the two arguments *(client, message)*, will be the function that gets -executed every time a new message arrives. - -In the last line we see again the :meth:`~pyrogram.Client.run` method, this time used without any argument. -Its purpose here is simply to automatically :meth:`~pyrogram.Client.start`, keep the Client online so that it can listen -for updates and :meth:`~pyrogram.Client.stop` it once you hit ``CTRL+C``. - -Using add_handler() -^^^^^^^^^^^^^^^^^^^ - -The :meth:`~pyrogram.Client.add_handler` method takes any handler instance that wraps around your defined callback -function and registers it in your Client. It is useful in case you want to programmatically add handlers. - -.. code-block:: python - - from pyrogram import Client - from pyrogram.handlers import MessageHandler - - - async def my_function(client, message): - await message.forward("me") - - - app = Client("my_account") - - my_handler = MessageHandler(my_function) - app.add_handler(my_handler) - - app.run() diff --git a/docs/source/support.rst b/docs/source/support.rst deleted file mode 100644 index 8efa4bc19f..0000000000 --- a/docs/source/support.rst +++ /dev/null @@ -1,63 +0,0 @@ -Support Pyrogram -================ - -.. raw:: html - - - -
- Star - - Fork -
- -
- -Pyrogram is a free and open source project. -If you enjoy Pyrogram and would like to show your appreciation, consider donating or becoming -a sponsor of the project. You can support Pyrogram via the ways shown below: - ------ - -GitHub Sponsor --------------- - -`Become a GitHub sponsor `_. - -.. raw:: html - - Sponsor - ------ - -LiberaPay Patron ----------------- - -`Become a LiberaPay patron `_. - -.. raw:: html - - - ------ - -OpenCollective Backer ---------------------- - -`Become an OpenCollective backer `_ - -.. raw:: html - - \ No newline at end of file diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst deleted file mode 100644 index df99042d1b..0000000000 --- a/docs/source/topics/advanced-usage.rst +++ /dev/null @@ -1,124 +0,0 @@ -Advanced Usage -============== - -Pyrogram's API -- which consists of well documented :doc:`methods <../api/methods/index>` and -:doc:`types <../api/types/index>` -- exists to provide an easier interface to the more complex Telegram API. - -In this section, you'll be shown the alternative way of communicating with Telegram using Pyrogram: the main "raw" -Telegram API with its functions and types. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Telegram Raw API ----------------- - -If you can't find a high-level method for your needs or if you want complete, low-level access to the whole -Telegram API, you have to use the raw :mod:`~pyrogram.raw.functions` and :mod:`~pyrogram.raw.types`. - -As already hinted, raw functions and types can be less convenient. This section will therefore explain some pitfalls to -take into consideration when working with the raw API. - -.. tip:: - - Every available high-level method in Pyrogram is built on top of these raw functions. - -Invoking Functions ------------------- - -Unlike the :doc:`methods <../api/methods/index>` found in Pyrogram's API, which can be called in the usual simple way, -functions to be invoked from the raw Telegram API have a different way of usage. - -First of all, both :doc:`raw functions <../telegram/functions/index>` and :doc:`raw types <../telegram/types/index>` -live in their respective packages (and sub-packages): ``pyrogram.raw.functions``, ``pyrogram.raw.types``. They all exist -as Python classes, meaning you need to create an instance of each every time you need them and fill them in with the -correct values using named arguments. - -Next, to actually invoke the raw function you have to use the :meth:`~pyrogram.Client.invoke` method provided by the -Client class and pass the function object you created. - -Here's some examples: - -- Update first name, last name and bio: - - .. code-block:: python - - from pyrogram import Client - from pyrogram.raw import functions - - async with Client("my_account") as app: - await app.invoke( - functions.account.UpdateProfile( - first_name="First Name", last_name="Last Name", - about="New bio text" - ) - ) - -- Set online/offline status: - - .. code-block:: python - - from pyrogram import Client - from pyrogram.raw import functions, types - - async with Client("my_account") as app: - # Set online status - await app.invoke(functions.account.UpdateStatus(offline=False)) - - # Set offline status - await app.invoke(functions.account.UpdateStatus(offline=True)) - -- Get chat info: - - .. code-block:: python - - from pyrogram import Client - from pyrogram.raw import functions, types - - async with Client("my_account") as app: - r = await app.invoke( - functions.channels.GetFullChannel( - channel=app.resolve_peer("username") - ) - ) - - print(r) - -Chat IDs --------- - -The way Telegram works makes it not possible to directly send a message to a user or a chat by using their IDs only. -Instead, a pair of ``id`` and ``access_hash`` wrapped in a so called ``InputPeer`` is always needed. Pyrogram allows -sending messages with IDs only thanks to cached access hashes. - -There are three different InputPeer types, one for each kind of Telegram entity. -Whenever an InputPeer is needed you must pass one of these: - -- :class:`~pyrogram.raw.types.InputPeerUser` - Users -- :class:`~pyrogram.raw.types.InputPeerChat` - Basic Chats -- :class:`~pyrogram.raw.types.InputPeerChannel` - Channels & Supergroups - -But you don't necessarily have to manually instantiate each object because Pyrogram already provides -:meth:`~pyrogram.Client.resolve_peer` as a convenience utility method that returns the correct InputPeer -by accepting a peer ID only. - -Another thing to take into consideration about chat IDs is the way they are represented: they are all integers and -all positive within their respective raw types. - -Things are different when working with Pyrogram's API because having them in the same space could lead to -collisions, and that's why Pyrogram uses a slightly different representation for each kind of ID. - -For example, given the ID *123456789*, here's how Pyrogram can tell entities apart: - -- ``+ID`` User: *123456789* -- ``-ID`` Chat: *-123456789* -- ``-100ID`` Channel or Supergroup: *-100123456789* - -So, every time you take a raw ID, make sure to translate it into the correct ID when you want to use it with an -high-level method. - -.. _Community: https://t.me/Pyrogram \ No newline at end of file diff --git a/docs/source/topics/client-settings.rst b/docs/source/topics/client-settings.rst deleted file mode 100644 index 02dce71375..0000000000 --- a/docs/source/topics/client-settings.rst +++ /dev/null @@ -1,46 +0,0 @@ -Client Settings -=============== - -You can control the way your client appears in the Active Sessions menu of an official client by changing some client -settings. By default you will see something like the following: - -- Device Model: ``CPython x.y.z`` -- Application: ``Pyrogram x.y.z`` -- System Version: ``Linux x.y.z`` - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Set Custom Values ------------------ - -To set custom values, you can pass the arguments directly in the Client's constructor. - -.. code-block:: python - - app = Client( - "my_account", - app_version="1.2.3", - device_model="PC", - system_version="Linux" - ) - -Set Custom Languages --------------------- - -To tell Telegram in which language should speak to you (terms of service, bots, service messages, ...) you can -set ``lang_code`` in `ISO 639-1 `_ standard (defaults to "en", -English). - -With the following code we make Telegram know we want it to speak in Italian (it): - -.. code-block:: python - - app = Client( - "my_account", - lang_code="it", - ) \ No newline at end of file diff --git a/docs/source/topics/create-filters.rst b/docs/source/topics/create-filters.rst deleted file mode 100644 index f8c05af620..0000000000 --- a/docs/source/topics/create-filters.rst +++ /dev/null @@ -1,109 +0,0 @@ -Creating Filters -================ - -Pyrogram already provides lots of built-in :class:`~pyrogram.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 you can use -:meth:`filters.create() `. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Custom Filters --------------- - -An example to demonstrate how custom filters work is to show how to create and use one for the -:class:`~pyrogram.handlers.CallbackQueryHandler`. Note that callback queries updates are only received by bots as result -of a user pressing an inline button attached to the bot's message; create and :doc:`authorize your bot <../start/auth>`, -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.types import InlineKeyboardMarkup, InlineKeyboardButton - - await app.send_message( - "username", # Change this to your username or id - "Pyrogram custom filter test", - reply_markup=InlineKeyboardMarkup( - [[InlineKeyboardButton("Press me", "pyrogram")]] - ) - ) - -Basic Filters -------------- - -For this basic filter we will be using only the first parameter of :meth:`~pyrogram.filters.create`. - -The heart of a filter is its callback function, which accepts three arguments *(self, client, update)* and returns -either ``True``, in case you want the update to pass the filter or ``False`` otherwise. - -In this example we are matching the query data to "pyrogram", which means that the filter will only allow callback -queries containing "pyrogram" as data: - -.. code-block:: python - - from pyrogram import filters - - async def func(_, __, query): - return query.data == "pyrogram" - - static_data_filter = filters.create(func) - - -The first two arguments of the callback function are unused here and because of this we named them using underscores. - -Finally, the filter usage remains the same: - -.. code-block:: python - - @app.on_callback_query(static_data_filter) - async def pyrogram_data(_, query): - query.answer("it works!") - -Filters with Arguments ----------------------- - -A more flexible filter would be one that accepts "pyrogram" or any other string as argument at usage time. -A dynamic filter like this will make use of named arguments for the :meth:`~pyrogram.filters.create` method and the -first argument of the callback function, which is a reference to the filter object itself holding the extra data passed -via named arguments. - -This is how a dynamic custom filter looks like: - -.. code-block:: python - - from pyrogram import filters - - def dynamic_data_filter(data): - async def func(flt, _, query): - return flt.data == query.data - - # "data" kwarg is accessed with "flt.data" above - return filters.create(func, data=data) - -And finally its usage: - -.. code-block:: python - - @app.on_callback_query(dynamic_data_filter("pyrogram")) - async def pyrogram_data(_, query): - query.answer("it works!") - - -Method Calls Inside Filters ---------------------------- - -The missing piece we haven't covered yet is the second argument of a filter callback function, namely, the ``client`` -argument. This is a reference to the :obj:`~pyrogram.Client` instance that is running the filter and it is useful in -case you would like to make some API calls before deciding whether the filter should allow the update or not: - -.. code-block:: python - - async def func(_, client, query): - # r = await client.some_api_method() - # check response "r" and decide to return True or False - ... \ No newline at end of file diff --git a/docs/source/topics/debugging.rst b/docs/source/topics/debugging.rst deleted file mode 100644 index 1c0ac069f9..0000000000 --- a/docs/source/topics/debugging.rst +++ /dev/null @@ -1,122 +0,0 @@ -Debugging -========= - -When working with the API, chances are you'll stumble upon bugs, get stuck and start wondering how to continue. Nothing -to actually worry about since Pyrogram provides some commodities to help you in this. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Caveman Debugging ------------------ - - *The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.* - - -- Brian Kernighan, "Unix for Beginners" (1979) - -Adding ``print()`` statements in crucial parts of your code is by far the most ancient, yet efficient technique for -debugging programs, especially considering the concurrent nature of the framework itself. Pyrogram goodness in this -respect comes with the fact that any object can be nicely printed just by calling ``print(obj)``, thus giving to you -an insight of all its inner details. - -Consider the following code: - -.. code-block:: python - - me = await app.get_users("me") - print(me) # User - -This will show a JSON representation of the object returned by :meth:`~pyrogram.Client.get_users`, which is a -:class:`~pyrogram.types.User` instance, in this case. The output on your terminal will be something similar to this: - -.. code-block:: json - - { - "_": "User", - "id": 123456789, - "is_self": true, - "is_contact": false, - "is_mutual_contact": false, - "is_deleted": false, - "is_bot": false, - "is_verified": false, - "is_restricted": false, - "is_support": false, - "first_name": "Pyrogram", - "photo": { - "_": "ChatPhoto", - "small_file_id": "AbCdE...EdCbA", - "small_photo_unique_id": "VwXyZ...ZyXwV", - "big_file_id": "AbCdE...EdCbA", - "big_photo_unique_id": "VwXyZ...ZyXwV" - } - } - -As you've probably guessed already, Pyrogram objects can be nested. That's how compound data are built, and nesting -keeps going until we are left with base data types only, such as ``str``, ``int``, ``bool``, etc. - -Accessing Attributes --------------------- - -Even though you see a JSON output, it doesn't mean we are dealing with dictionaries; in fact, all Pyrogram types are -fully-fledged Python objects and the correct way to access any attribute of them is by using the dot notation ``.``: - -.. code-block:: python - - photo = me.photo - print(photo) # ChatPhoto - -.. code-block:: json - - { - "_": "ChatPhoto", - "small_file_id": "AbCdE...EdCbA", - "small_photo_unique_id": "VwXyZ...ZyXwV", - "big_file_id": "AbCdE...EdCbA", - "big_photo_unique_id": "VwXyZ...ZyXwV" - } - -Checking an Object's Type -------------------------- - -Another thing worth talking about is how to tell and check for an object's type. - -As you noticed already, when printing an object you'll see the special attribute ``"_"``. This is just a visual thing -useful to show humans the object type, but doesn't really exist anywhere; any attempt in accessing it will lead to an -error. The correct way to get the object type is by using the built-in function ``type()``: - -.. code-block:: python - - status = me.status - print(type(status)) - -.. code-block:: text - - - -And to check if an object is an instance of a given class, you use the built-in function ``isinstance()``: - -.. code-block:: python - :name: this-py - - from pyrogram.types import UserStatus - - status = me.status - print(isinstance(status, UserStatus)) - -.. code-block:: text - - True - -.. raw:: html - - \ No newline at end of file diff --git a/docs/source/topics/more-on-updates.rst b/docs/source/topics/more-on-updates.rst deleted file mode 100644 index 18c1a68af3..0000000000 --- a/docs/source/topics/more-on-updates.rst +++ /dev/null @@ -1,226 +0,0 @@ -More on Updates -=============== - -Here we'll show some advanced usages when working with :doc:`update handlers <../start/updates>` and -:doc:`filters `. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Handler Groups --------------- - -If you register handlers with overlapping (conflicting) filters, only the first one is executed and any other handler -will be ignored. This is intended by design. - -In order to handle the very same update more than once, you have to register your handler in a different dispatching -group. Dispatching groups hold one or more handlers and are processed sequentially, they are identified by a number -(number 0 being the default) and sorted, that is, a lower group number has a higher priority: - -For example, take these two handlers: - -.. code-block:: python - - @app.on_message(filters.text | filters.sticker) - async def text_or_sticker(client, message): - print("Text or Sticker") - - - @app.on_message(filters.text) - async def just_text(client, message): - print("Just Text") - -Here, ``just_text`` is never executed because ``text_or_sticker``, which has been registered first, already handles -texts (``filters.text`` is shared and conflicting). To enable it, register the handler using a different group: - -.. code-block:: python - - @app.on_message(filters.text, group=1) - async def just_text(client, message): - print("Just Text") - -Or, if you want ``just_text`` to be executed *before* ``text_or_sticker`` (note ``-1``, which is less than ``0``): - -.. code-block:: python - - @app.on_message(filters.text, group=-1) - async def just_text(client, message): - print("Just Text") - -With :meth:`~pyrogram.Client.add_handler` (without decorators) the same can be achieved with: - -.. code-block:: python - - app.add_handler(MessageHandler(just_text, filters.text), -1) - -Update propagation ------------------- - -Registering multiple handlers, each in a different group, becomes useful when you want to handle the same update more -than once. Any incoming update will be sequentially processed by all of your registered functions by respecting the -groups priority policy described above. Even in case any handler raises an unhandled exception, Pyrogram will still -continue to propagate the same update to the next groups until all the handlers are done. Example: - -.. code-block:: python - - @app.on_message(filters.private) - async def _(client, message): - print(0) - - - @app.on_message(filters.private, group=1) - async def _(client, message): - raise Exception("Unhandled exception!") # Simulate an unhandled exception - - - @app.on_message(filters.private, group=2) - async def _(client, message): - print(2) - -All these handlers will handle the same kind of messages, that are, messages sent or received in private chats. -The output for each incoming update will therefore be: - -.. code-block:: text - - 0 - Exception: Unhandled exception! - 2 - -Stop Propagation -^^^^^^^^^^^^^^^^ - -In order to prevent further propagation of an update in the dispatching phase, you can do *one* of the following: - -- Call the update's bound-method ``.stop_propagation()`` (preferred way). -- Manually ``raise StopPropagation`` exception (more suitable for raw updates only). - -.. note:: - - Internally, the propagation is stopped by handling a custom exception. ``.stop_propagation()`` is just an elegant - and intuitive way to ``raise StopPropagation``; this also means that any code coming *after* calling the method - won't be executed as your function just raised an exception to signal the dispatcher not to propagate the - update anymore. - -Example with ``stop_propagation()``: - -.. code-block:: python - - @app.on_message(filters.private) - async def _(client, message): - print(0) - - - @app.on_message(filters.private, group=1) - async def _(client, message): - print(1) - message.stop_propagation() - - - @app.on_message(filters.private, group=2) - async def _(client, message): - print(2) - -Example with ``raise StopPropagation``: - -.. code-block:: python - - from pyrogram import StopPropagation - - @app.on_message(filters.private) - async def _(client, message): - print(0) - - - @app.on_message(filters.private, group=1) - async ef _(client, message): - print(1) - raise StopPropagation - - - @app.on_message(filters.private, group=2) - async def _(client, message): - print(2) - -Each handler is registered in a different group, but the handler in group number 2 will never be executed because the -propagation was stopped earlier. The output of both (equivalent) examples will be: - -.. code-block:: text - - 0 - 1 - -Continue Propagation -^^^^^^^^^^^^^^^^^^^^ - -As opposed to `stopping the update propagation <#stop-propagation>`_ and also as an alternative to the -`handler groups <#handler-groups>`_, you can signal the internal dispatcher to continue the update propagation within -**the same group** despite having conflicting filters in the next registered handler. This allows you to register -multiple handlers with overlapping filters in the same group; to let the dispatcher process the next handler you can do -*one* of the following in each handler you want to grant permission to continue: - -- Call the update's bound-method ``.continue_propagation()`` (preferred way). -- Manually ``raise ContinuePropagation`` exception (more suitable for raw updates only). - -.. note:: - - Internally, the propagation is continued by handling a custom exception. ``.continue_propagation()`` is just an - elegant and intuitive way to ``raise ContinuePropagation``; this also means that any code coming *after* calling the - method won't be executed as your function just raised an exception to signal the dispatcher to continue with the - next available handler. - - -Example with ``continue_propagation()``: - -.. code-block:: python - - @app.on_message(filters.private) - async def _(client, message): - print(0) - message.continue_propagation() - - - @app.on_message(filters.private) - async def _(client, message): - print(1) - message.continue_propagation() - - - @app.on_message(filters.private) - async def _(client, message): - print(2) - -Example with ``raise ContinuePropagation``: - -.. code-block:: python - - from pyrogram import ContinuePropagation - - @app.on_message(filters.private) - async def _(client, message): - print(0) - raise ContinuePropagation - - - @app.on_message(filters.private) - async def _(client, message): - print(1) - raise ContinuePropagation - - - @app.on_message(filters.private) - async def _(client, message): - print(2) - -Three handlers are registered in the same group, and all of them will be executed because the propagation was continued -in each handler (except in the last one, where is useless to do so since there is no more handlers after). -The output of both (equivalent) examples will be: - -.. code-block:: text - - 0 - 1 - 2 diff --git a/docs/source/topics/mtproto-vs-botapi.rst b/docs/source/topics/mtproto-vs-botapi.rst deleted file mode 100644 index 9681c1eb65..0000000000 --- a/docs/source/topics/mtproto-vs-botapi.rst +++ /dev/null @@ -1,112 +0,0 @@ -MTProto vs. Bot API -=================== - -Pyrogram is a framework written from the ground up that acts as a fully-fledged Telegram client based on the MTProto -API. This means that Pyrogram is able to execute any official client and bot API action and more. This page will -therefore show you why Pyrogram might be a better choice for your project by comparing the two APIs, but first, let's -make it clear what actually is the MTProto and the Bot API. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -What is the MTProto API? ------------------------- - -`MTProto`_, took alone, is the name of the custom-made, open and encrypted communication protocol created by Telegram -itself --- it's the only protocol used to exchange information between a client and the actual Telegram servers. - -The MTProto API on the other hand, is what people for convenience call the main Telegram API in order to distinguish it -from the Bot API. The main Telegram API is able to authorize both users and bots and is built on top of the MTProto -encryption protocol by means of `binary data serialized`_ in a specific way, as described by the `TL language`_, and -delivered using UDP, TCP or even HTTP as transport-layer protocol. Clients that make use of Telegram's main API, such as -Pyrogram, implement all these details. - -.. _MTProto: https://core.telegram.org/mtproto -.. _binary data serialized: https://core.telegram.org/mtproto/serialize -.. _TL language: https://core.telegram.org/mtproto/TL - -What is the Bot API? --------------------- - -The `Bot API`_ is an HTTP(S) interface for building normal bots using a sub-set of the main Telegram API. Bots are -special accounts that are authorized via tokens instead of phone numbers. The Bot API is built yet again on top of the -main Telegram API, but runs on an intermediate server application that in turn communicates with the actual Telegram -servers using MTProto. - -.. figure:: //_static/img/mtproto-vs-bot-api.png - :align: center - -.. _Bot API: https://core.telegram.org/bots/api - -Advantages of the MTProto API ------------------------------ - -Here is a non-exhaustive list of all the advantages in using MTProto-based libraries -- such as Pyrogram -- instead of -the official HTTP Bot API. Using Pyrogram you can: - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Authorize both user and bot identities** - - :guilabel:`--` The Bot API only allows bot accounts - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Upload & download any file, up to 2000 MiB each (~2 GB)** - - :guilabel:`--` The Bot API allows uploads and downloads of files only up to 50 MB / 20 MB in size (respectively). - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Has less overhead due to direct connections to Telegram** - - :guilabel:`--` The Bot API uses an intermediate server to handle HTTP requests before they are sent to the actual - Telegram servers. - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Run multiple sessions at once (for both user and bot identities)** - - :guilabel:`--` The Bot API intermediate server will terminate any other session in case you try to use the same - bot again in a parallel connection. - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Has much more detailed types and powerful methods** - - :guilabel:`--` The Bot API types often miss some useful information about Telegram entities and some of the - methods are limited as well. - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Obtain information about any message existing in a chat using their ids** - - :guilabel:`--` The Bot API simply doesn't support this - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Retrieve the whole chat members list of either public or private chats** - - :guilabel:`--` The Bot API simply doesn't support this - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Receive extra updates, such as the one about a user name change** - - :guilabel:`--` The Bot API simply doesn't support this - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Has more meaningful errors in case something went wrong** - - :guilabel:`--` The Bot API reports less detailed errors - -.. hlist:: - :columns: 1 - - - :guilabel:`+` **Get API version updates, and thus new features, sooner** - - :guilabel:`--` The Bot API is simply slower in implementing new features diff --git a/docs/source/topics/proxy.rst b/docs/source/topics/proxy.rst deleted file mode 100644 index 286743493d..0000000000 --- a/docs/source/topics/proxy.rst +++ /dev/null @@ -1,34 +0,0 @@ -Proxy Settings -============== - -Pyrogram supports proxies with and without authentication. This feature allows Pyrogram to exchange data with Telegram -through an intermediate SOCKS 4/5 or HTTP (CONNECT) proxy server. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Usage ------ - -To use Pyrogram with a proxy, use the *proxy* parameter in the Client class. If your proxy doesn't require authorization -you can omit ``username`` and ``password``. - -.. code-block:: python - - from pyrogram import Client - - proxy = { - "scheme": "socks5", # "socks4", "socks5" and "http" are supported - "hostname": "11.22.33.44", - "port": 1234, - "username": "username", - "password": "password" - } - - app = Client("my_account", proxy=proxy) - - app.run() diff --git a/docs/source/topics/scheduling.rst b/docs/source/topics/scheduling.rst deleted file mode 100644 index a67a92548a..0000000000 --- a/docs/source/topics/scheduling.rst +++ /dev/null @@ -1,65 +0,0 @@ -Scheduling Tasks -================ - -Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is -useful, for example, to send recurring messages to specific chats or users. - -This page will show examples on how to integrate Pyrogram with ``apscheduler`` in both asynchronous and -non-asynchronous contexts. For more detailed information, you can visit and learn from the library documentation. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Using apscheduler ------------------ - -- Install with ``pip3 install apscheduler`` -- Documentation: https://apscheduler.readthedocs.io - -Asynchronously -^^^^^^^^^^^^^^ - -.. code-block:: python - - from apscheduler.schedulers.asyncio import AsyncIOScheduler - - from pyrogram import Client - - app = Client("my_account") - - - async def job(): - await app.send_message("me", "Hi!") - - - scheduler = AsyncIOScheduler() - scheduler.add_job(job, "interval", seconds=3) - - scheduler.start() - app.run() - -Non-Asynchronously -^^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - from apscheduler.schedulers.background import BackgroundScheduler - - from pyrogram import Client - - app = Client("my_account") - - - def job(): - app.send_message("me", "Hi!") - - - scheduler = BackgroundScheduler() - scheduler.add_job(job, "interval", seconds=3) - - scheduler.start() - app.run() diff --git a/docs/source/topics/serializing.rst b/docs/source/topics/serializing.rst deleted file mode 100644 index 3dc644f880..0000000000 --- a/docs/source/topics/serializing.rst +++ /dev/null @@ -1,56 +0,0 @@ -Object Serialization -==================== - -Serializing means converting a Pyrogram object, which exists as Python class instance, to a text string that can be -easily shared and stored anywhere. Pyrogram provides two formats for serializing its objects: one good looking for -humans and another more compact for machines that is able to recover the original structures. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -For Humans - str(obj) ---------------------- - -If you want a nicely formatted, human readable JSON representation of any object in the API you can use ``str(obj)``. - -.. code-block:: python - - ... - - async with app: - r = await app.get_chat("me") - print(str(r)) - -.. tip:: - - When using ``print()`` you don't actually need to use ``str()`` on the object because it is called automatically, we - have done that above just to show you how to explicitly convert a Pyrogram object to JSON. - -For Machines - repr(obj) ------------------------- - -If you want to share or store objects for future references in a more compact way, you can use ``repr(obj)``. While -still pretty much readable, this format is not intended for humans. The advantage of this format is that once you -serialize your object, you can use ``eval()`` to get back the original structure; just make sure to ``import pyrogram``, -as the process requires the package to be in scope. - -.. code-block:: python - - import pyrogram - - ... - - async with app: - r = await app.get_chat("me") - - print(repr(r)) - print(eval(repr(r)) == r) # True - -.. note:: - - Type definitions are subject to changes between versions. You should make sure to store and load objects using the - same Pyrogram version. \ No newline at end of file diff --git a/docs/source/topics/smart-plugins.rst b/docs/source/topics/smart-plugins.rst deleted file mode 100644 index c378c9d81f..0000000000 --- a/docs/source/topics/smart-plugins.rst +++ /dev/null @@ -1,306 +0,0 @@ -Smart Plugins -============= - -Pyrogram embeds a smart, lightweight yet powerful plugin system that is meant to further simplify the organization -of large projects and to provide a way for creating pluggable (modular) components that can be easily shared across -different Pyrogram applications with minimal boilerplate code. - -.. tip:: - - Smart Plugins are completely optional and disabled by default. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Introduction ------------- - -Prior to the Smart Plugin system, pluggable handlers were already possible. For example, if you wanted to modularize -your applications, you had to put your function definitions in separate files and register them inside your main script -after importing your modules, like this: - -.. note:: - - This is an example application that replies in private chats with two messages: one containing the same - text message you sent and the other containing the reversed text message. - - Example: *"Pyrogram"* replies with *"Pyrogram"* and *"margoryP"* - -.. code-block:: text - - myproject/ - handlers.py - main.py - -- ``handlers.py`` - - .. code-block:: python - - async def echo(client, message): - await message.reply(message.text) - - - async def echo_reversed(client, message): - await message.reply(message.text[::-1]) - -- ``main.py`` - - .. code-block:: python - - from pyrogram import Client, filters - from pyrogram.handlers import MessageHandler - - from handlers import echo, echo_reversed - - app = Client("my_account") - - app.add_handler( - MessageHandler( - echo, - filters.text & filters.private)) - - app.add_handler( - MessageHandler( - echo_reversed, - filters.text & filters.private), - group=1) - - app.run() - -This is already nice and doesn't add *too much* boilerplate code, but things can get boring still; you have to -manually ``import``, manually :meth:`~pyrogram.Client.add_handler` and manually instantiate each -:class:`~pyrogram.handlers.MessageHandler` object because you can't use decorators for your functions. -So, what if you could? Smart Plugins solve this issue by taking care of handlers registration automatically. - -Using Smart Plugins -------------------- - -Setting up your Pyrogram project to accommodate Smart Plugins is pretty straightforward: - -#. Create a new folder to store all the plugins (e.g.: "plugins", "handlers", ...). -#. Put your python files full of plugins inside. Organize them as you wish. -#. Enable plugins in your Client. - -.. note:: - - This is the same example application as shown above, written using the Smart Plugin system. - -.. code-block:: text - - myproject/ - plugins/ - handlers.py - main.py - -- ``plugins/handlers.py`` - - .. code-block:: python - - from pyrogram import Client, filters - - - @Client.on_message(filters.text & filters.private) - async def echo(client, message): - await message.reply(message.text) - - - @Client.on_message(filters.text & filters.private, group=1) - async def echo_reversed(client, message): - await message.reply(message.text[::-1]) - -- ``main.py`` - - .. code-block:: python - - from pyrogram import Client - - plugins = dict(root="plugins") - - Client("my_account", plugins=plugins).run() - - -The first important thing to note is the new ``plugins`` folder. You can put *any python file* in *any subfolder* and -each file can contain *any decorated function* (handlers) with one limitation: within a single module (file) you must -use different names for each decorated function. - -The second thing is telling Pyrogram where to look for your plugins: you can use the Client parameter "plugins"; -the *root* value must match the name of your plugins root folder. Your Pyrogram Client instance will **automatically** -scan the folder upon starting to search for valid handlers and register them for you. - -Then you'll notice you can now use decorators. That's right, you can apply the usual decorators to your callback -functions in a static way, i.e. **without having the Client instance around**: simply use ``@Client`` (Client class) -instead of the usual ``@app`` (Client instance) and things will work just the same. - -Specifying the Plugins to include ---------------------------------- - -By default, if you don't explicitly supply a list of plugins, every valid one found inside your plugins root folder will -be included by following the alphabetical order of the directory structure (files and subfolders); the single handlers -found inside each module will be, instead, loaded in the order they are defined, from top to bottom. - -.. note:: - - Remember: there can be at most one handler, within a group, dealing with a specific update. Plugins with overlapping - filters included a second time will not work, by design. Learn more at :doc:`More on Updates `. - -This default loading behaviour is usually enough, but sometimes you want to have more control on what to include (or -exclude) and in which exact order to load plugins. The way to do this is to make use of ``include`` and ``exclude`` -directives in the dictionary passed as Client argument. Here's how they work: - -- If both ``include`` and ``exclude`` are omitted, all plugins are loaded as described above. -- If ``include`` is given, only the specified plugins will be loaded, in the order they are passed. -- If ``exclude`` is given, the plugins specified here will be unloaded. - -The ``include`` and ``exclude`` value is a **list of strings**. Each string containing the path of the module relative -to the plugins root folder, in Python notation (dots instead of slashes). - - E.g.: ``subfolder.module`` refers to ``plugins/subfolder/module.py``, with ``root="plugins"``. - -You can also choose the order in which the single handlers inside a module are loaded, thus overriding the default -top-to-bottom loading policy. You can do this by appending the name of the functions to the module path, each one -separated by a blank space. - - E.g.: ``subfolder.module fn2 fn1 fn3`` will load *fn2*, *fn1* and *fn3* from *subfolder.module*, in this order. - -Examples -^^^^^^^^ - -Given this plugins folder structure with three modules, each containing their own handlers (fn1, fn2, etc...), which are -also organized in subfolders: - -.. code-block:: text - - myproject/ - plugins/ - subfolder1/ - plugins1.py - - fn1 - - fn2 - - fn3 - subfolder2/ - plugins2.py - ... - plugins0.py - ... - ... - -- Load every handler from every module, namely *plugins0.py*, *plugins1.py* and *plugins2.py* in alphabetical order - (files) and definition order (handlers inside files): - - .. code-block:: python - - plugins = dict(root="plugins") - - Client("my_account", plugins=plugins).run() - -- Load only handlers defined inside *plugins2.py* and *plugins0.py*, in this order: - - .. code-block:: python - - plugins = dict( - root="plugins", - include=[ - "subfolder2.plugins2", - "plugins0" - ] - ) - - Client("my_account", plugins=plugins).run() - -- Load everything except the handlers inside *plugins2.py*: - - .. code-block:: python - - plugins = dict( - root="plugins", - exclude=["subfolder2.plugins2"] - ) - - Client("my_account", plugins=plugins).run() - -- Load only *fn3*, *fn1* and *fn2* (in this order) from *plugins1.py*: - - .. code-block:: python - - plugins = dict( - root="plugins", - include=["subfolder1.plugins1 fn3 fn1 fn2"] - ) - - Client("my_account", plugins=plugins).run() - -Load/Unload Plugins at Runtime ------------------------------- - -In the previous section we've explained how to specify which plugins to load and which to ignore before your Client -starts. Here we'll show, instead, how to unload and load again a previously registered plugin at runtime. - -Each function decorated with the usual ``on_message`` decorator (or any other decorator that deals with Telegram -updates) will be modified in such a way that a special ``handlers`` attribute pointing to a list of tuples of -*(handler: Handler, group: int)* is attached to the function object itself. - -- ``plugins/handlers.py`` - - .. code-block:: python - - @Client.on_message(filters.text & filters.private) - async def echo(client, message): - await message.reply(message.text) - - print(echo) - print(echo.handlers) - -- Printing ``echo`` will show something like ````. - -- Printing ``echo.handlers`` will reveal the handlers, that is, a list of tuples containing the actual handlers and - the groups they were registered on ``[(, 0)]``. - -Unloading -^^^^^^^^^ - -In order to unload a plugin, all you need to do is obtain a reference to it by importing the relevant module and call -:meth:`~pyrogram.Client.remove_handler` Client's method with your function's *handler* instance: - -- ``main.py`` - - .. code-block:: python - - from plugins.handlers import echo - - handlers = echo.handlers - - for h in handlers: - app.remove_handler(*h) - -The star ``*`` operator is used to unpack the tuple into positional arguments so that *remove_handler* will receive -exactly what is needed. The same could have been achieved with: - -.. code-block:: python - - handlers = echo.handlers - handler, group = handlers[0] - - app.remove_handler(handler, group) - -Loading -^^^^^^^ - -Similarly to the unloading process, in order to load again a previously unloaded plugin you do the same, but this time -using :meth:`~pyrogram.Client.add_handler` instead. Example: - -- ``main.py`` - - .. code-block:: python - - from plugins.handlers import echo - - ... - - handlers = echo.handlers - - for h in handlers: - app.add_handler(*h) \ No newline at end of file diff --git a/docs/source/topics/speedups.rst b/docs/source/topics/speedups.rst deleted file mode 100644 index 821b26f4df..0000000000 --- a/docs/source/topics/speedups.rst +++ /dev/null @@ -1,88 +0,0 @@ -Speedups -======== - -Pyrogram's speed can be boosted up by using TgCrypto and uvloop. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -TgCrypto --------- - -TgCrypto_ is a high-performance, easy-to-install cryptography library specifically written in C for Pyrogram as a Python -extension. It is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram -requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC. - -Installation -^^^^^^^^^^^^ - -.. code-block:: bash - - $ pip3 install -U tgcrypto - -Usage -^^^^^ - -Pyrogram will automatically make use of TgCrypto when detected, all you need to do is to install it. - -uvloop ------- - -uvloop_ is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses -libuv under the hood. It makes asyncio 2-4x faster. - -Installation -^^^^^^^^^^^^ - -.. code-block:: bash - - $ pip3 install -U uvloop - -Usage -^^^^^ - -Call ``uvloop.install()`` before calling ``asyncio.run()`` or ``app.run()``. - -.. code-block:: python - - import asyncio - import uvloop - - from pyrogram import Client - - - async def main(): - app = Client("my_account") - - async with app: - print(await app.get_me()) - - - uvloop.install() - asyncio.run(main()) - -The ``uvloop.install()`` call also needs to be placed before creating a Client instance. - -.. code-block:: python - - import uvloop - from pyrogram import Client - - uvloop.install() - - app = Client("my_account") - - - @app.on_message() - async def hello(client, message): - print(await client.get_me()) - - - app.run() - -.. _TgCrypto: https://github.com/pyrogram/tgcrypto -.. _uvloop: https://github.com/MagicStack/uvloop diff --git a/docs/source/topics/storage-engines.rst b/docs/source/topics/storage-engines.rst deleted file mode 100644 index 34147917ee..0000000000 --- a/docs/source/topics/storage-engines.rst +++ /dev/null @@ -1,90 +0,0 @@ -Storage Engines -=============== - -Every time you login to Telegram, some personal piece of data are created and held by both parties (the client, Pyrogram -and the server, Telegram). This session data is uniquely bound to your own account, indefinitely (until you logout or -decide to manually terminate it) and is used to authorize a client to execute API calls on behalf of your identity. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Persisting Sessions -------------------- - -In order to make a client reconnect successfully between restarts, that is, without having to start a new -authorization process from scratch each time, Pyrogram needs to store the generated session data somewhere. - -Different Storage Engines -------------------------- - -Pyrogram offers two different types of storage engines: a **File Storage** and a **Memory Storage**. -These engines are well integrated in the framework and require a minimal effort to set up. Here's how they work: - -File Storage -^^^^^^^^^^^^ - -This is the most common storage engine. It is implemented by using **SQLite**, which will store the session details. -The database will be saved to disk as a single portable file and is designed to efficiently store and retrieve -data whenever they are needed. - -To use this type of engine, simply pass any name of your choice to the ``name`` parameter of the -:obj:`~pyrogram.Client` constructor, as usual: - -.. code-block:: python - - from pyrogram import Client - - async with Client("my_account") as app: - print(await app.get_me()) - -Once you successfully log in (either with a user or a bot identity), a session file will be created and saved to disk as -``my_account.session``. Any subsequent client restart will make Pyrogram search for a file named that way and the -session database will be automatically loaded. - -Memory Storage -^^^^^^^^^^^^^^ - -In case you don't want to have any session file saved to disk, you can use an in-memory storage by passing True to the -``in_memory`` parameter of the :obj:`~pyrogram.Client` constructor: - -.. code-block:: python - - from pyrogram import Client - - async with Client("my_account", in_memory=True) as app: - print(await app.get_me()) - -This storage engine is still backed by SQLite, but the database exists purely in memory. This means that, once you stop -a client, the entire database is discarded and the session details used for logging in again will be lost forever. - -Session Strings ---------------- - -In case you want to use an in-memory storage, but also want to keep access to the session you created, call -:meth:`~pyrogram.Client.export_session_string` anytime before stopping the client... - -.. code-block:: python - - from pyrogram import Client - - async with Client("my_account", in_memory=True) as app: - print(await app.export_session_string()) - -...and save the resulting string. You can use this string by passing it as Client argument the next time you want to -login using the same session; the storage used will still be in-memory: - -.. code-block:: python - - from pyrogram import Client - - session_string = "...ZnUIFD8jsjXTb8g_vpxx48k1zkov9sapD-tzjz-S4WZv70M..." - - async with Client("my_account", session_string=session_string) as app: - print(await app.get_me()) - -Session strings are useful when you want to run authorized Pyrogram clients on platforms where their ephemeral -filesystems makes it harder for a file-based storage engine to properly work as intended. diff --git a/docs/source/topics/synchronous.rst b/docs/source/topics/synchronous.rst deleted file mode 100644 index 0a677b0e50..0000000000 --- a/docs/source/topics/synchronous.rst +++ /dev/null @@ -1,88 +0,0 @@ -Synchronous Usage -================= - -Pyrogram is an asynchronous framework and as such is subject to the asynchronous rules. It can, however, run in -synchronous mode (also known as non-asynchronous or sync/non-async for short). This mode exists mainly as a convenience -way for invoking methods without the need of ``async``/``await`` keywords and the extra boilerplate, but **it's not the -intended way to use the framework**. - -You can use Pyrogram in this synchronous mode when you want to write something short and contained without the -async boilerplate or in case you want to combine Pyrogram with other libraries that are not async. - -.. warning:: - - You have to be very careful when using the framework in its synchronous, non-native form, especially when combined - with other non-async libraries because thread blocking operations that clog the asynchronous event loop underneath - will make the program run erratically. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Synchronous Invocations ------------------------ - -The following is a standard example of running asynchronous functions with Python's asyncio. -Pyrogram is being used inside the main function with its asynchronous interface. - -.. code-block:: python - - import asyncio - from pyrogram import Client - - - async def main(): - app = Client("my_account") - - async with app: - await app.send_message("me", "Hi!") - - - asyncio.run(main()) - -To run Pyrogram synchronously, use the non-async context manager as shown in the following example. -As you can see, the non-async example becomes less cluttered. - -.. code-block:: python - - from pyrogram import Client - - app = Client("my_account") - - with app: - app.send_message("me", "Hi!") - -Synchronous handlers --------------------- - -You can also have synchronous handlers; you only need to define the callback function without using ``async def`` and -invoke API methods by not placing ``await`` in front of them. Mixing ``def`` and ``async def`` handlers together is also -possible. - -.. code-block:: python - - @app.on_message() - async def handler1(client, message): - await message.forward("me") - - @app.on_edited_message() - def handler2(client, message): - message.forward("me") - -uvloop usage ------------- - -When using Pyrogram in its synchronous mode combined with uvloop, you need to call ``uvloop.install()`` before importing -Pyrogram. - -.. code-block:: python - - import uvloop - uvloop.install() - - from pyrogram import Client - - ... \ No newline at end of file diff --git a/docs/source/topics/test-servers.rst b/docs/source/topics/test-servers.rst deleted file mode 100644 index 1ccfe286c8..0000000000 --- a/docs/source/topics/test-servers.rst +++ /dev/null @@ -1,41 +0,0 @@ -Test Servers -============ - -If you wish to test your application in a separate environment, Pyrogram is able to authorize your account into -Telegram's test servers without hassle. All you need to do is start a new session (e.g.: "my_account_test") using -``test_mode=True``: - -.. code-block:: python - - from pyrogram import Client - - async with Client("my_account_test", test_mode=True) as app: - print(await app.get_me()) - -.. note:: - - If this is the first time you login into test servers, you will be asked to register your account first. - Accounts registered on test servers reside in a different, parallel instance of a Telegram server. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Test Mode in Official Apps --------------------------- - -You can also login yourself into test servers using official desktop apps, such as Telegram Web and Telegram Desktop: - -- **Telegram Web**: Login here: https://web.telegram.org/?test=1 -- **Telegram Desktop**: Hold ``Alt+Shift`` and right click on "Add account", then choose "Test server". - -Test Numbers ------------- - -Beside normal numbers, the test environment allows you to login with reserved test numbers. -Valid phone numbers follow the pattern ``99966XYYYY``, where ``X`` is the DC number (1 to 3) and ``YYYY`` are random -numbers. Users with such numbers always get ``XXXXX`` or ``XXXXXX`` as the confirmation code (the DC number, repeated -five or six times). \ No newline at end of file diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst deleted file mode 100644 index 00aa0cf8c8..0000000000 --- a/docs/source/topics/text-formatting.rst +++ /dev/null @@ -1,243 +0,0 @@ -Text Formatting -=============== - -.. role:: strike - :class: strike - -.. role:: underline - :class: underline - -.. role:: bold-underline - :class: bold-underline - -.. role:: strike-italic - :class: strike-italic - -Pyrogram uses a custom Markdown dialect for text formatting which adds some unique features that make writing styled -texts easier in both Markdown and HTML. You can send sophisticated text messages and media captions using a -variety of decorations that can also be nested in order to combine multiple styles together. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Basic Styles ------------- - -When formatting your messages, you can choose between Markdown-style, HTML-style or both (default). The following is a -list of the basic styles currently supported by Pyrogram. - -- **bold** -- *italic* -- :strike:`strike` -- :underline:`underline` -- spoiler -- `text URL `_ -- `user text mention `_ -- ``inline fixed-width code`` -- .. code-block:: text - - pre-formatted - fixed-width - code block - -Markdown Style --------------- - -To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the *parse_mode* parameter when using -:meth:`~pyrogram.Client.send_message`. Use the following syntax in your message: - -.. code-block:: text - - **bold** - - __italic__ - - --underline-- - - ~~strike~~ - - ||spoiler|| - - [text URL](https://pyrogram.org/) - - [text user mention](tg://user?id=123456789) - - `inline fixed-width code` - - ``` - pre-formatted - fixed-width - code block - ``` - -**Example**: - -.. code-block:: python - - from pyrogram import enums - - await app.send_message( - "me", - ( - "**bold**, " - "__italic__, " - "--underline--, " - "~~strike~~, " - "||spoiler||, " - "[URL](https://pyrogram.org), " - "`code`, " - "```" - "for i in range(10):\n" - " print(i)" - "```" - ), - parse_mode=enums.ParseMode.MARKDOWN - ) - -HTML Style ----------- - -To strictly use this mode, pass :obj:`~pyrogram.enums.HTML` to the *parse_mode* parameter when using -:meth:`~pyrogram.Client.send_message`. The following tags are currently supported: - -.. code-block:: text - - bold, bold - - italic, italic - - underline - - strike, strike, strike - - spoiler - - text URL - - inline mention - - inline fixed-width code - - 🔥 - -
-    pre-formatted
-      fixed-width
-        code block
-    
- -**Example**: - -.. code-block:: python - - from pyrogram import enums - - await app.send_message( - "me", - ( - "bold, " - "italic, " - "underline, " - "strike, " - "spoiler, " - "URL, " - "code\n\n" - "
"
-            "for i in range(10):\n"
-            "    print(i)"
-            "
" - ), - parse_mode=enums.ParseMode.HTML - ) - -.. note:: - - All ``<``, ``>`` and ``&`` symbols that are not a part of a tag or an HTML entity must be replaced with the - corresponding HTML entities (``<`` with ``<``, ``>`` with ``>`` and ``&`` with ``&``). You can use this - snippet to quickly escape those characters: - - .. code-block:: python - - import html - - text = "" - text = html.escape(text) - - print(text) - - .. code-block:: text - - <my text> - -Different Styles ----------------- - -By default, when ignoring the *parse_mode* parameter, both Markdown and HTML styles are enabled together. -This means you can combine together both syntaxes in the same text: - -.. code-block:: python - - await app.send_message("me", "**bold**, italic") - -Result: - - **bold**, *italic* - -If you don't like this behaviour you can always choose to only enable either Markdown or HTML in strict mode by passing -:obj:`~pyrogram.enums.MARKDOWN` or :obj:`~pyrogram.enums.HTML` as argument to the *parse_mode* parameter. - -.. code-block:: python - - from pyrogram import enums - - await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.MARKDOWN) - await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.HTML) - -Result: - - **bold**, italic - - \*\*bold**, *italic* - -In case you want to completely turn off the style parser, simply pass :obj:`~pyrogram.enums.DISABLED` to *parse_mode*. -The text will be sent as-is. - -.. code-block:: python - - from pyrogram import enums - - await app.send_message("me", "**bold**, italic", parse_mode=enums.ParseMode.DISABLED) - -Result: - - \*\*bold**, italic - -Nested and Overlapping Entities -------------------------------- - -You can also style texts with more than one decoration at once by nesting entities together. For example, you can send -a text message with both :bold-underline:`bold and underline` styles, or a text that has both :strike-italic:`italic and -strike` styles, and you can still combine both Markdown and HTML together. - -Here there are some example texts you can try sending: - -**Markdown**: - -- ``**bold, --underline--**`` -- ``**bold __italic --underline ~~strike~~--__**`` -- ``**bold __and** italic__`` - -**HTML**: - -- ``bold, underline`` -- ``bold italic underline strike`` -- ``bold and italic`` - -**Combined**: - -- ``--you can combine HTML with **Markdown**--`` -- ``**and also overlap** --entities this way--`` diff --git a/docs/source/topics/use-filters.rst b/docs/source/topics/use-filters.rst deleted file mode 100644 index ab7296af85..0000000000 --- a/docs/source/topics/use-filters.rst +++ /dev/null @@ -1,114 +0,0 @@ -Using Filters -============= - -So far we've seen :doc:`how to register a callback function <../start/updates>` that executes every time an update comes -from the server, but there's much more than that to come. - -Here we'll discuss about :obj:`~pyrogram.filters`. Filters enable a fine-grain control over what kind of -updates are allowed or not to be passed in your callback functions, based on their inner details. - -.. contents:: Contents - :backlinks: none - :depth: 1 - :local: - ------ - -Single Filters --------------- - -Let's start right away with a simple example: - -- This example will show you how to **only** handle messages containing a :class:`~pyrogram.types.Sticker` object and - ignore any other message. Filters are passed as the first argument of the decorator: - - .. code-block:: python - - from pyrogram import filters - - - @app.on_message(filters.sticker) - async def my_handler(client, message): - print(message) - -- or, without decorators. Here filters are passed as the second argument of the handler constructor; the first is the - callback function itself: - - .. code-block:: python - - from pyrogram import filters - from pyrogram.handlers import MessageHandler - - - async def my_handler(client, message): - print(message) - - - app.add_handler(MessageHandler(my_handler, filters.sticker)) - -Combining Filters ------------------ - -Filters can be used in a more advanced way by inverting and combining more filters together using bitwise -operators ``~``, ``&`` and ``|``: - -- 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 **or** a **photo**. - - .. code-block:: python - - @app.on_message(filters.text | filters.photo) - async 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)) - async def my_handler(client, message): - print(message) - -Advanced Filters ----------------- - -Some filters, like :meth:`~pyrogram.filters.command` or :meth:`~pyrogram.filters.regex` -can also accept arguments: - -- Message is either a */start* or */help* **command**. - - .. code-block:: python - - @app.on_message(filters.command(["start", "help"])) - async def my_handler(client, message): - print(message) - -- Message is a **text** message or a media **caption** matching the given **regex** pattern. - - .. code-block:: python - - @app.on_message(filters.regex("pyrogram")) - async 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")) - async def start_command(client, message): - print("This is the /start command") - - - @app.on_message(filters.command("help")) - async def help_command(client, message): - print("This is the /help command") - - - @app.on_message(filters.chat("PyrogramChat")) - async def from_pyrogramchat(client, message): - print("New message in @PyrogramChat") diff --git a/docs/source/topics/voice-calls.rst b/docs/source/topics/voice-calls.rst deleted file mode 100644 index aef4030ca8..0000000000 --- a/docs/source/topics/voice-calls.rst +++ /dev/null @@ -1,19 +0,0 @@ -Voice Calls -=========== - -Both private voice calls and group voice calls are currently supported by third-party, external libraries that integrate -with Pyrogram. - -Libraries ---------- - -There are currently two main libraries (with very similar names) you can use: - -1. https://github.com/pytgcalls/pytgcalls -2. https://github.com/MarshalX/tgcalls - -Older implementations ---------------------- - -An older implementation of Telegram voice calls can be found at https://github.com/bakatrouble/pylibtgvoip (currently -outdated due to the deprecation of the Telegram VoIP library used underneath). \ No newline at end of file From bb44f3624791e770d47efc7550d1a70c869a016e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 14 Oct 2022 11:54:26 +0200 Subject: [PATCH 397/539] Add usable-by labels for methods --- pyrogram/methods/advanced/invoke.py | 2 ++ pyrogram/methods/advanced/resolve_peer.py | 2 ++ pyrogram/methods/advanced/save_file.py | 2 ++ pyrogram/methods/auth/accept_terms_of_service.py | 2 ++ pyrogram/methods/auth/check_password.py | 2 ++ pyrogram/methods/auth/get_password_hint.py | 2 ++ pyrogram/methods/auth/log_out.py | 2 ++ pyrogram/methods/auth/recover_password.py | 2 ++ pyrogram/methods/auth/resend_code.py | 2 ++ pyrogram/methods/auth/send_code.py | 2 ++ pyrogram/methods/auth/send_recovery_code.py | 2 ++ pyrogram/methods/auth/sign_in.py | 2 ++ pyrogram/methods/auth/sign_in_bot.py | 2 ++ pyrogram/methods/auth/sign_up.py | 2 ++ pyrogram/methods/bots/answer_callback_query.py | 2 ++ pyrogram/methods/bots/answer_inline_query.py | 2 ++ pyrogram/methods/bots/answer_web_app_query.py | 2 ++ pyrogram/methods/bots/delete_bot_commands.py | 2 ++ pyrogram/methods/bots/get_bot_commands.py | 2 ++ pyrogram/methods/bots/get_bot_default_privileges.py | 2 ++ pyrogram/methods/bots/get_chat_menu_button.py | 2 ++ pyrogram/methods/bots/get_game_high_scores.py | 2 ++ pyrogram/methods/bots/get_inline_bot_results.py | 2 ++ pyrogram/methods/bots/request_callback_answer.py | 2 ++ pyrogram/methods/bots/send_game.py | 2 ++ pyrogram/methods/bots/send_inline_bot_result.py | 2 ++ pyrogram/methods/bots/set_bot_commands.py | 2 ++ pyrogram/methods/bots/set_bot_default_privileges.py | 2 ++ pyrogram/methods/bots/set_chat_menu_button.py | 2 ++ pyrogram/methods/bots/set_game_score.py | 2 ++ pyrogram/methods/chats/add_chat_members.py | 2 ++ pyrogram/methods/chats/archive_chats.py | 2 ++ pyrogram/methods/chats/ban_chat_member.py | 2 ++ pyrogram/methods/chats/create_channel.py | 2 ++ pyrogram/methods/chats/create_group.py | 2 ++ pyrogram/methods/chats/create_supergroup.py | 2 ++ pyrogram/methods/chats/delete_channel.py | 2 ++ pyrogram/methods/chats/delete_chat_photo.py | 2 ++ pyrogram/methods/chats/delete_supergroup.py | 2 ++ pyrogram/methods/chats/delete_user_history.py | 2 ++ pyrogram/methods/chats/get_chat.py | 2 ++ pyrogram/methods/chats/get_chat_event_log.py | 4 +++- pyrogram/methods/chats/get_chat_member.py | 2 ++ pyrogram/methods/chats/get_chat_members.py | 2 ++ pyrogram/methods/chats/get_chat_members_count.py | 2 ++ pyrogram/methods/chats/get_chat_online_count.py | 2 ++ pyrogram/methods/chats/get_dialogs.py | 2 ++ pyrogram/methods/chats/get_dialogs_count.py | 9 ++++++--- pyrogram/methods/chats/get_nearby_chats.py | 2 ++ pyrogram/methods/chats/get_send_as_chats.py | 2 ++ pyrogram/methods/chats/join_chat.py | 2 ++ pyrogram/methods/chats/leave_chat.py | 2 ++ pyrogram/methods/chats/mark_chat_unread.py | 2 ++ pyrogram/methods/chats/pin_chat_message.py | 2 ++ pyrogram/methods/chats/promote_chat_member.py | 2 ++ pyrogram/methods/chats/restrict_chat_member.py | 2 ++ pyrogram/methods/chats/set_administrator_title.py | 2 ++ pyrogram/methods/chats/set_chat_description.py | 2 ++ pyrogram/methods/chats/set_chat_permissions.py | 2 ++ pyrogram/methods/chats/set_chat_photo.py | 2 ++ pyrogram/methods/chats/set_chat_protected_content.py | 2 ++ pyrogram/methods/chats/set_chat_title.py | 2 ++ pyrogram/methods/chats/set_chat_username.py | 2 ++ pyrogram/methods/chats/set_send_as_chat.py | 2 ++ pyrogram/methods/chats/set_slow_mode.py | 2 ++ pyrogram/methods/chats/unarchive_chats.py | 2 ++ pyrogram/methods/chats/unban_chat_member.py | 2 ++ pyrogram/methods/chats/unpin_all_chat_messages.py | 2 ++ pyrogram/methods/chats/unpin_chat_message.py | 2 ++ pyrogram/methods/contacts/add_contact.py | 2 ++ pyrogram/methods/contacts/delete_contacts.py | 2 ++ pyrogram/methods/contacts/get_contacts.py | 2 ++ pyrogram/methods/contacts/get_contacts_count.py | 2 ++ pyrogram/methods/contacts/import_contacts.py | 2 ++ .../invite_links/approve_all_chat_join_requests.py | 2 ++ .../methods/invite_links/approve_chat_join_request.py | 4 +++- pyrogram/methods/invite_links/create_chat_invite_link.py | 2 ++ .../invite_links/decline_all_chat_join_requests.py | 2 ++ .../methods/invite_links/decline_chat_join_request.py | 4 +++- .../invite_links/delete_chat_admin_invite_links.py | 2 ++ pyrogram/methods/invite_links/delete_chat_invite_link.py | 2 ++ pyrogram/methods/invite_links/edit_chat_invite_link.py | 2 ++ pyrogram/methods/invite_links/export_chat_invite_link.py | 2 ++ .../methods/invite_links/get_chat_admin_invite_links.py | 2 ++ .../invite_links/get_chat_admin_invite_links_count.py | 2 ++ .../invite_links/get_chat_admins_with_invite_links.py | 4 +++- pyrogram/methods/invite_links/get_chat_invite_link.py | 2 ++ .../methods/invite_links/get_chat_invite_link_joiners.py | 2 ++ .../invite_links/get_chat_invite_link_joiners_count.py | 2 ++ pyrogram/methods/invite_links/get_chat_join_requests.py | 2 ++ pyrogram/methods/invite_links/revoke_chat_invite_link.py | 2 ++ pyrogram/methods/messages/copy_media_group.py | 2 ++ pyrogram/methods/messages/copy_message.py | 2 ++ pyrogram/methods/messages/delete_messages.py | 2 ++ pyrogram/methods/messages/download_media.py | 2 ++ pyrogram/methods/messages/edit_inline_caption.py | 2 ++ pyrogram/methods/messages/edit_inline_media.py | 2 ++ pyrogram/methods/messages/edit_inline_reply_markup.py | 2 ++ pyrogram/methods/messages/edit_inline_text.py | 2 ++ pyrogram/methods/messages/edit_message_caption.py | 2 ++ pyrogram/methods/messages/edit_message_media.py | 2 ++ pyrogram/methods/messages/edit_message_reply_markup.py | 2 ++ pyrogram/methods/messages/edit_message_text.py | 2 ++ pyrogram/methods/messages/forward_messages.py | 2 ++ pyrogram/methods/messages/get_chat_history.py | 2 ++ pyrogram/methods/messages/get_chat_history_count.py | 2 ++ pyrogram/methods/messages/get_custom_emoji_stickers.py | 2 ++ pyrogram/methods/messages/get_discussion_message.py | 2 ++ pyrogram/methods/messages/get_discussion_replies.py | 2 ++ .../methods/messages/get_discussion_replies_count.py | 2 ++ pyrogram/methods/messages/get_media_group.py | 4 +++- pyrogram/methods/messages/get_messages.py | 2 ++ pyrogram/methods/messages/read_chat_history.py | 2 ++ pyrogram/methods/messages/retract_vote.py | 2 ++ pyrogram/methods/messages/search_global.py | 2 ++ pyrogram/methods/messages/search_global_count.py | 2 ++ pyrogram/methods/messages/search_messages.py | 2 ++ pyrogram/methods/messages/search_messages_count.py | 2 ++ pyrogram/methods/messages/send_animation.py | 2 ++ pyrogram/methods/messages/send_audio.py | 2 ++ pyrogram/methods/messages/send_cached_media.py | 2 ++ pyrogram/methods/messages/send_chat_action.py | 2 ++ pyrogram/methods/messages/send_contact.py | 2 ++ pyrogram/methods/messages/send_dice.py | 2 ++ pyrogram/methods/messages/send_document.py | 2 ++ pyrogram/methods/messages/send_location.py | 2 ++ pyrogram/methods/messages/send_media_group.py | 2 ++ pyrogram/methods/messages/send_message.py | 2 ++ pyrogram/methods/messages/send_photo.py | 2 ++ pyrogram/methods/messages/send_poll.py | 2 ++ pyrogram/methods/messages/send_reaction.py | 2 ++ pyrogram/methods/messages/send_sticker.py | 2 ++ pyrogram/methods/messages/send_venue.py | 2 ++ pyrogram/methods/messages/send_video.py | 2 ++ pyrogram/methods/messages/send_video_note.py | 2 ++ pyrogram/methods/messages/send_voice.py | 2 ++ pyrogram/methods/messages/stop_poll.py | 2 ++ pyrogram/methods/messages/stream_media.py | 2 ++ pyrogram/methods/messages/vote_poll.py | 2 ++ pyrogram/methods/password/change_cloud_password.py | 2 ++ pyrogram/methods/password/enable_cloud_password.py | 2 ++ pyrogram/methods/password/remove_cloud_password.py | 2 ++ pyrogram/methods/users/block_user.py | 2 ++ pyrogram/methods/users/delete_profile_photos.py | 2 ++ pyrogram/methods/users/get_chat_photos.py | 2 ++ pyrogram/methods/users/get_chat_photos_count.py | 2 ++ pyrogram/methods/users/get_common_chats.py | 2 ++ pyrogram/methods/users/get_default_emoji_statuses.py | 2 ++ pyrogram/methods/users/get_me.py | 2 ++ pyrogram/methods/users/get_users.py | 2 ++ pyrogram/methods/users/set_emoji_status.py | 2 ++ pyrogram/methods/users/set_profile_photo.py | 2 ++ pyrogram/methods/users/set_username.py | 2 ++ pyrogram/methods/users/unblock_user.py | 2 ++ pyrogram/methods/users/update_profile.py | 2 ++ 155 files changed, 319 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/advanced/invoke.py b/pyrogram/methods/advanced/invoke.py index 9ae25d0084..0af771adc8 100644 --- a/pyrogram/methods/advanced/invoke.py +++ b/pyrogram/methods/advanced/invoke.py @@ -46,6 +46,8 @@ async def invoke( :obj:`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). + .. include:: /_includes/usable-by/users-bots.rst + Parameters: query (``RawFunction``): The API Schema function filled with proper arguments. diff --git a/pyrogram/methods/advanced/resolve_peer.py b/pyrogram/methods/advanced/resolve_peer.py index 80fe7975b0..ebb8ff4475 100644 --- a/pyrogram/methods/advanced/resolve_peer.py +++ b/pyrogram/methods/advanced/resolve_peer.py @@ -42,6 +42,8 @@ async def resolve_peer( :obj:`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). + .. include:: /_includes/usable-by/users-bots.rst + Parameters: peer_id (``int`` | ``str``): The peer id you want to extract the InputPeer from. diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index 6a43deac6f..c7f3a953e8 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -53,6 +53,8 @@ async def save_file( :obj:`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). + .. include:: /_includes/usable-by/users-bots.rst + Parameters: path (``str`` | ``BinaryIO``): The path of the file you want to upload that exists on your local machine or a binary file-like object diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py index 3bc5fbad27..cc1fcf5453 100644 --- a/pyrogram/methods/auth/accept_terms_of_service.py +++ b/pyrogram/methods/auth/accept_terms_of_service.py @@ -27,6 +27,8 @@ async def accept_terms_of_service( ) -> bool: """Accept the given terms of service. + .. include:: /_includes/usable-by/users.rst + Parameters: terms_of_service_id (``str``): The terms of service identifier. diff --git a/pyrogram/methods/auth/check_password.py b/pyrogram/methods/auth/check_password.py index 9d8b08abfa..39aa82fcc0 100644 --- a/pyrogram/methods/auth/check_password.py +++ b/pyrogram/methods/auth/check_password.py @@ -33,6 +33,8 @@ async def check_password( ) -> "types.User": """Check your Two-Step Verification password and log in. + .. include:: /_includes/usable-by/users.rst + Parameters: password (``str``): Your Two-Step Verification password. diff --git a/pyrogram/methods/auth/get_password_hint.py b/pyrogram/methods/auth/get_password_hint.py index af6557589a..a57f7c8075 100644 --- a/pyrogram/methods/auth/get_password_hint.py +++ b/pyrogram/methods/auth/get_password_hint.py @@ -30,6 +30,8 @@ async def get_password_hint( ) -> str: """Get your Two-Step Verification password hint. + .. include:: /_includes/usable-by/users.rst + Returns: ``str``: On success, the password hint as string is returned. """ diff --git a/pyrogram/methods/auth/log_out.py b/pyrogram/methods/auth/log_out.py index b4a29f8273..84b7db64cd 100644 --- a/pyrogram/methods/auth/log_out.py +++ b/pyrogram/methods/auth/log_out.py @@ -33,6 +33,8 @@ async def log_out( When you log out, the current client is stopped and the storage session deleted. No more API calls can be made until you start the client and re-authorize again. + .. include:: /_includes/usable-by/users-bots.rst + Returns: ``bool``: On success, True is returned. diff --git a/pyrogram/methods/auth/recover_password.py b/pyrogram/methods/auth/recover_password.py index 9f75a93f79..0a34750752 100644 --- a/pyrogram/methods/auth/recover_password.py +++ b/pyrogram/methods/auth/recover_password.py @@ -32,6 +32,8 @@ async def recover_password( ) -> "types.User": """Recover your password with a recovery code and log in. + .. include:: /_includes/usable-by/users.rst + Parameters: recovery_code (``str``): The recovery code sent via email. diff --git a/pyrogram/methods/auth/resend_code.py b/pyrogram/methods/auth/resend_code.py index 4210e04d9b..9644ac4f54 100644 --- a/pyrogram/methods/auth/resend_code.py +++ b/pyrogram/methods/auth/resend_code.py @@ -36,6 +36,8 @@ async def resend_code( The type of the code to be re-sent is specified in the *next_type* attribute of the :obj:`~pyrogram.types.SentCode` object returned by :meth:`send_code`. + .. include:: /_includes/usable-by/users.rst + Parameters: phone_number (``str``): Phone number in international format (includes the country prefix). diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py index 5f7f70915d..92ffc99996 100644 --- a/pyrogram/methods/auth/send_code.py +++ b/pyrogram/methods/auth/send_code.py @@ -34,6 +34,8 @@ async def send_code( ) -> "types.SentCode": """Send the confirmation code to the given phone number. + .. include:: /_includes/usable-by/users.rst + Parameters: phone_number (``str``): Phone number in international format (includes the country prefix). diff --git a/pyrogram/methods/auth/send_recovery_code.py b/pyrogram/methods/auth/send_recovery_code.py index d1f23bf965..9a25f3c68f 100644 --- a/pyrogram/methods/auth/send_recovery_code.py +++ b/pyrogram/methods/auth/send_recovery_code.py @@ -30,6 +30,8 @@ async def send_recovery_code( ) -> str: """Send a code to your email to recover your password. + .. include:: /_includes/usable-by/users.rst + Returns: ``str``: On success, the hidden email pattern is returned and a recovery code is sent to that email. diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py index c328c95850..9d77f1cd37 100644 --- a/pyrogram/methods/auth/sign_in.py +++ b/pyrogram/methods/auth/sign_in.py @@ -35,6 +35,8 @@ async def sign_in( ) -> Union["types.User", "types.TermsOfService", bool]: """Authorize a user in Telegram with a valid confirmation code. + .. include:: /_includes/usable-by/users.rst + Parameters: phone_number (``str``): Phone number in international format (includes the country prefix). diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py index dd322a8e66..09a2f28379 100644 --- a/pyrogram/methods/auth/sign_in_bot.py +++ b/pyrogram/methods/auth/sign_in_bot.py @@ -34,6 +34,8 @@ async def sign_in_bot( ) -> "types.User": """Authorize a bot using its bot token generated by BotFather. + .. include:: /_includes/usable-by/bots.rst + Parameters: bot_token (``str``): The bot token generated by BotFather diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py index 6700fee481..f09a779d8a 100644 --- a/pyrogram/methods/auth/sign_up.py +++ b/pyrogram/methods/auth/sign_up.py @@ -35,6 +35,8 @@ async def sign_up( ) -> "types.User": """Register a new user in Telegram. + .. include:: /_includes/usable-by/users.rst + Parameters: phone_number (``str``): Phone number in international format (includes the country prefix). diff --git a/pyrogram/methods/bots/answer_callback_query.py b/pyrogram/methods/bots/answer_callback_query.py index 95d479314a..a6d8747cd5 100644 --- a/pyrogram/methods/bots/answer_callback_query.py +++ b/pyrogram/methods/bots/answer_callback_query.py @@ -32,6 +32,8 @@ async def answer_callback_query( """Send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. + .. include:: /_includes/usable-by/bots.rst + Parameters: callback_query_id (``str``): Unique identifier for the query to be answered. diff --git a/pyrogram/methods/bots/answer_inline_query.py b/pyrogram/methods/bots/answer_inline_query.py index e9acd9375d..c3a450a015 100644 --- a/pyrogram/methods/bots/answer_inline_query.py +++ b/pyrogram/methods/bots/answer_inline_query.py @@ -39,6 +39,8 @@ async def answer_inline_query( A maximum of 50 results per query is allowed. + .. include:: /_includes/usable-by/bots.rst + Parameters: inline_query_id (``str``): Unique identifier for the answered query. diff --git a/pyrogram/methods/bots/answer_web_app_query.py b/pyrogram/methods/bots/answer_web_app_query.py index f887e28098..74f56079bb 100644 --- a/pyrogram/methods/bots/answer_web_app_query.py +++ b/pyrogram/methods/bots/answer_web_app_query.py @@ -30,6 +30,8 @@ async def answer_web_app_query( """Set the result of an interaction with a `Web App `_ and send a corresponding message on behalf of the user to the chat from which the query originated. + .. include:: /_includes/usable-by/bots.rst + Parameters: web_app_query_id (``str``): Unique identifier for the answered query. diff --git a/pyrogram/methods/bots/delete_bot_commands.py b/pyrogram/methods/bots/delete_bot_commands.py index 2e638aed7f..e8173d32d9 100644 --- a/pyrogram/methods/bots/delete_bot_commands.py +++ b/pyrogram/methods/bots/delete_bot_commands.py @@ -32,6 +32,8 @@ async def delete_bot_commands( The commands passed will overwrite any command set previously. This method can be used by the own bot only. + .. include:: /_includes/usable-by/bots.rst + Parameters: scope (:obj:`~pyrogram.types.BotCommandScope`, *optional*): An object describing the scope of users for which the commands are relevant. diff --git a/pyrogram/methods/bots/get_bot_commands.py b/pyrogram/methods/bots/get_bot_commands.py index f62b63754a..78deff30fd 100644 --- a/pyrogram/methods/bots/get_bot_commands.py +++ b/pyrogram/methods/bots/get_bot_commands.py @@ -34,6 +34,8 @@ async def get_bot_commands( The commands passed will overwrite any command set previously. This method can be used by the own bot only. + .. include:: /_includes/usable-by/bots.rst + Parameters: scope (:obj:`~pyrogram.types.BotCommandScope`, *optional*): An object describing the scope of users for which the commands are relevant. diff --git a/pyrogram/methods/bots/get_bot_default_privileges.py b/pyrogram/methods/bots/get_bot_default_privileges.py index e1f70fa1e8..217d9b4384 100644 --- a/pyrogram/methods/bots/get_bot_default_privileges.py +++ b/pyrogram/methods/bots/get_bot_default_privileges.py @@ -30,6 +30,8 @@ async def get_bot_default_privileges( ) -> Optional["types.ChatPrivileges"]: """Get the current default privileges of the bot. + .. include:: /_includes/usable-by/bots.rst + Parameters: for_channels (``bool``, *optional*): Pass True to get default privileges of the bot in channels. Otherwise, default privileges of the bot diff --git a/pyrogram/methods/bots/get_chat_menu_button.py b/pyrogram/methods/bots/get_chat_menu_button.py index 8fb61b0173..9d143d5819 100644 --- a/pyrogram/methods/bots/get_chat_menu_button.py +++ b/pyrogram/methods/bots/get_chat_menu_button.py @@ -30,6 +30,8 @@ async def get_chat_menu_button( ) -> "types.MenuButton": """Get the current value of the bot's menu button in a private chat, or the default menu button. + .. include:: /_includes/usable-by/bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/get_game_high_scores.py b/pyrogram/methods/bots/get_game_high_scores.py index 555e9af5e3..068ecab889 100644 --- a/pyrogram/methods/bots/get_game_high_scores.py +++ b/pyrogram/methods/bots/get_game_high_scores.py @@ -32,6 +32,8 @@ async def get_game_high_scores( ) -> List["types.GameHighScore"]: """Get data for high score tables. + .. include:: /_includes/usable-by/bots.rst + Parameters: user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/get_inline_bot_results.py b/pyrogram/methods/bots/get_inline_bot_results.py index 3ef1d4dea0..7cb0aa127d 100644 --- a/pyrogram/methods/bots/get_inline_bot_results.py +++ b/pyrogram/methods/bots/get_inline_bot_results.py @@ -35,6 +35,8 @@ async def get_inline_bot_results( """Get bot results via inline queries. You can then send a result using :meth:`~pyrogram.Client.send_inline_bot_result` + .. include:: /_includes/usable-by/users.rst + Parameters: bot (``int`` | ``str``): Unique identifier of the inline bot you want to get results from. You can specify diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py index 9c0626a56e..22debcbe21 100644 --- a/pyrogram/methods/bots/request_callback_answer.py +++ b/pyrogram/methods/bots/request_callback_answer.py @@ -33,6 +33,8 @@ async def request_callback_answer( """Request a callback answer from bots. This is the equivalent of clicking an inline button containing callback data. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/send_game.py b/pyrogram/methods/bots/send_game.py index e4181166f7..60155a6fe6 100644 --- a/pyrogram/methods/bots/send_game.py +++ b/pyrogram/methods/bots/send_game.py @@ -40,6 +40,8 @@ async def send_game( ) -> "types.Message": """Send a game. + .. include:: /_includes/usable-by/bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py index ebe5ca8d24..0f31880636 100644 --- a/pyrogram/methods/bots/send_inline_bot_result.py +++ b/pyrogram/methods/bots/send_inline_bot_result.py @@ -34,6 +34,8 @@ async def send_inline_bot_result( """Send an inline bot result. Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results` + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/set_bot_commands.py b/pyrogram/methods/bots/set_bot_commands.py index 7dfbf10979..f6f7e6c992 100644 --- a/pyrogram/methods/bots/set_bot_commands.py +++ b/pyrogram/methods/bots/set_bot_commands.py @@ -34,6 +34,8 @@ async def set_bot_commands( The commands passed will overwrite any command set previously. This method can be used by the own bot only. + .. include:: /_includes/usable-by/bots.rst + Parameters: commands (List of :obj:`~pyrogram.types.BotCommand`): A list of bot commands. diff --git a/pyrogram/methods/bots/set_bot_default_privileges.py b/pyrogram/methods/bots/set_bot_default_privileges.py index 52e480266b..2890ee1ae1 100644 --- a/pyrogram/methods/bots/set_bot_default_privileges.py +++ b/pyrogram/methods/bots/set_bot_default_privileges.py @@ -31,6 +31,8 @@ async def set_bot_default_privileges( These privileges will be suggested to users, but they are are free to modify the list before adding the bot. + .. include:: /_includes/usable-by/bots.rst + Parameters: privileges (:obj:`~pyrogram.types.ChatPrivileges`): New default privileges. None to clear. diff --git a/pyrogram/methods/bots/set_chat_menu_button.py b/pyrogram/methods/bots/set_chat_menu_button.py index 87e26c036c..fa5af85ceb 100644 --- a/pyrogram/methods/bots/set_chat_menu_button.py +++ b/pyrogram/methods/bots/set_chat_menu_button.py @@ -31,6 +31,8 @@ async def set_chat_menu_button( ) -> bool: """Change the bot's menu button in a private chat, or the default menu button. + .. include:: /_includes/usable-by/bots.rst + Parameters: chat_id (``int`` | ``str``, *optional*): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/bots/set_game_score.py b/pyrogram/methods/bots/set_game_score.py index f9008e4435..b3b58b2362 100644 --- a/pyrogram/methods/bots/set_game_score.py +++ b/pyrogram/methods/bots/set_game_score.py @@ -36,6 +36,8 @@ async def set_game_score( # inline_message_id: str = None): TODO Add inline_message_id """Set the score of the specified user in a game. + .. include:: /_includes/usable-by/bots.rst + Parameters: user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/add_chat_members.py b/pyrogram/methods/chats/add_chat_members.py index 2bf145f907..b560a6affc 100644 --- a/pyrogram/methods/chats/add_chat_members.py +++ b/pyrogram/methods/chats/add_chat_members.py @@ -31,6 +31,8 @@ async def add_chat_members( ) -> bool: """Add new chat members to a group, supergroup or channel + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): The group, supergroup or channel id diff --git a/pyrogram/methods/chats/archive_chats.py b/pyrogram/methods/chats/archive_chats.py index 40544e0fdc..661b450cff 100644 --- a/pyrogram/methods/chats/archive_chats.py +++ b/pyrogram/methods/chats/archive_chats.py @@ -29,6 +29,8 @@ async def archive_chats( ) -> bool: """Archive one or more chats. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_ids (``int`` | ``str`` | List[``int``, ``str``]): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py index 16a1308247..635c48b5da 100644 --- a/pyrogram/methods/chats/ban_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -41,6 +41,8 @@ async def ban_chat_member( off in the target group. Otherwise members may only be removed by the group's creator or by the member that added them. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/create_channel.py b/pyrogram/methods/chats/create_channel.py index 2a1497789d..292fa97dd7 100644 --- a/pyrogram/methods/chats/create_channel.py +++ b/pyrogram/methods/chats/create_channel.py @@ -28,6 +28,8 @@ async def create_channel( ) -> "types.Chat": """Create a new broadcast channel. + .. include:: /_includes/usable-by/users.rst + Parameters: title (``str``): The channel title. diff --git a/pyrogram/methods/chats/create_group.py b/pyrogram/methods/chats/create_group.py index a2ffa8de66..027315de2a 100644 --- a/pyrogram/methods/chats/create_group.py +++ b/pyrogram/methods/chats/create_group.py @@ -35,6 +35,8 @@ async def create_group( If you want to create a new supergroup, use :meth:`~pyrogram.Client.create_supergroup` instead. + .. include:: /_includes/usable-by/users.rst + Parameters: title (``str``): The group title. diff --git a/pyrogram/methods/chats/create_supergroup.py b/pyrogram/methods/chats/create_supergroup.py index 04da148a90..d1cbbbd890 100644 --- a/pyrogram/methods/chats/create_supergroup.py +++ b/pyrogram/methods/chats/create_supergroup.py @@ -32,6 +32,8 @@ async def create_supergroup( If you want to create a new basic group, use :meth:`~pyrogram.Client.create_group` instead. + .. include:: /_includes/usable-by/users.rst + Parameters: title (``str``): The supergroup title. diff --git a/pyrogram/methods/chats/delete_channel.py b/pyrogram/methods/chats/delete_channel.py index 7aad47d033..374d89a6f4 100644 --- a/pyrogram/methods/chats/delete_channel.py +++ b/pyrogram/methods/chats/delete_channel.py @@ -29,6 +29,8 @@ async def delete_channel( ) -> bool: """Delete a channel. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): The id of the channel to be deleted. diff --git a/pyrogram/methods/chats/delete_chat_photo.py b/pyrogram/methods/chats/delete_chat_photo.py index 058b7fdb29..1984bc0cc2 100644 --- a/pyrogram/methods/chats/delete_chat_photo.py +++ b/pyrogram/methods/chats/delete_chat_photo.py @@ -31,6 +31,8 @@ async def delete_chat_photo( You must be an administrator in the chat for this to work and must have the appropriate admin rights. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/delete_supergroup.py b/pyrogram/methods/chats/delete_supergroup.py index 39d5a07d91..ebd60befa8 100644 --- a/pyrogram/methods/chats/delete_supergroup.py +++ b/pyrogram/methods/chats/delete_supergroup.py @@ -29,6 +29,8 @@ async def delete_supergroup( ) -> bool: """Delete a supergroup. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): The id of the supergroup to be deleted. diff --git a/pyrogram/methods/chats/delete_user_history.py b/pyrogram/methods/chats/delete_user_history.py index 4411ddbd24..7769c7c3c0 100644 --- a/pyrogram/methods/chats/delete_user_history.py +++ b/pyrogram/methods/chats/delete_user_history.py @@ -30,6 +30,8 @@ async def delete_user_history( ) -> bool: """Delete all messages sent by a certain user in a supergroup. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py index d3246447a7..e2289935a9 100644 --- a/pyrogram/methods/chats/get_chat.py +++ b/pyrogram/methods/chats/get_chat.py @@ -34,6 +34,8 @@ async def get_chat( Information include current name of the user for one-on-one conversations, current username of a user, group or channel, etc. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat_event_log.py b/pyrogram/methods/chats/get_chat_event_log.py index 622fe0bc0f..06fa01c849 100644 --- a/pyrogram/methods/chats/get_chat_event_log.py +++ b/pyrogram/methods/chats/get_chat_event_log.py @@ -38,7 +38,9 @@ async def get_chat_event_log( Only available for supergroups and channels. Requires administrator rights. Results are returned in reverse chronological order (i.e., newest first). - Args: + .. include:: /_includes/usable-by/users.rst + + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py index 526cf744ca..53d2faad83 100644 --- a/pyrogram/methods/chats/get_chat_member.py +++ b/pyrogram/methods/chats/get_chat_member.py @@ -32,6 +32,8 @@ async def get_chat_member( ) -> "types.ChatMember": """Get information about one member of a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index 3e11872cb1..49fb0a094d 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -70,6 +70,8 @@ async def get_chat_members( A chat can be either a basic group, a supergroup or a channel. Requires administrator rights in channels. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat_members_count.py b/pyrogram/methods/chats/get_chat_members_count.py index e2f7fa8b92..2680702833 100644 --- a/pyrogram/methods/chats/get_chat_members_count.py +++ b/pyrogram/methods/chats/get_chat_members_count.py @@ -29,6 +29,8 @@ async def get_chat_members_count( ) -> int: """Get the number of members in a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py index 45c60d978b..6ecd5727dd 100644 --- a/pyrogram/methods/chats/get_chat_online_count.py +++ b/pyrogram/methods/chats/get_chat_online_count.py @@ -29,6 +29,8 @@ async def get_chat_online_count( ) -> int: """Get the number of members that are currently online in a chat. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/get_dialogs.py b/pyrogram/methods/chats/get_dialogs.py index 2869a6a1ed..3509ccbcca 100644 --- a/pyrogram/methods/chats/get_dialogs.py +++ b/pyrogram/methods/chats/get_dialogs.py @@ -29,6 +29,8 @@ async def get_dialogs( ) -> Optional[AsyncGenerator["types.Dialog", None]]: """Get a user's dialogs sequentially. + .. include:: /_includes/usable-by/users.rst + Parameters: limit (``int``, *optional*): Limits the number of dialogs to be retrieved. diff --git a/pyrogram/methods/chats/get_dialogs_count.py b/pyrogram/methods/chats/get_dialogs_count.py index 3d96732cf1..ae22eb5cff 100644 --- a/pyrogram/methods/chats/get_dialogs_count.py +++ b/pyrogram/methods/chats/get_dialogs_count.py @@ -27,9 +27,12 @@ async def get_dialogs_count( ) -> int: """Get the total count of your dialogs. - pinned_only (``bool``, *optional*): - Pass True if you want to count only pinned dialogs. - Defaults to False. + .. include:: /_includes/usable-by/users.rst + + Parameters: + pinned_only (``bool``, *optional*): + Pass True if you want to count only pinned dialogs. + Defaults to False. Returns: ``int``: On success, the dialogs count is returned. diff --git a/pyrogram/methods/chats/get_nearby_chats.py b/pyrogram/methods/chats/get_nearby_chats.py index 2ebd930644..8d1163ac9d 100644 --- a/pyrogram/methods/chats/get_nearby_chats.py +++ b/pyrogram/methods/chats/get_nearby_chats.py @@ -32,6 +32,8 @@ async def get_nearby_chats( ) -> List["types.Chat"]: """Get nearby chats. + .. include:: /_includes/usable-by/users.rst + Parameters: latitude (``float``): Latitude of the location. diff --git a/pyrogram/methods/chats/get_send_as_chats.py b/pyrogram/methods/chats/get_send_as_chats.py index 2ad3b8b561..c9a358c398 100644 --- a/pyrogram/methods/chats/get_send_as_chats.py +++ b/pyrogram/methods/chats/get_send_as_chats.py @@ -30,6 +30,8 @@ async def get_send_as_chats( ) -> List["types.Chat"]: """Get the list of "send_as" chats available. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/join_chat.py b/pyrogram/methods/chats/join_chat.py index 07d7b2a7e2..2ef82cff31 100644 --- a/pyrogram/methods/chats/join_chat.py +++ b/pyrogram/methods/chats/join_chat.py @@ -30,6 +30,8 @@ async def join_chat( ) -> "types.Chat": """Join a group chat or channel. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat in form of a *t.me/joinchat/* link, a username of the target diff --git a/pyrogram/methods/chats/leave_chat.py b/pyrogram/methods/chats/leave_chat.py index 942173f469..b974e38771 100644 --- a/pyrogram/methods/chats/leave_chat.py +++ b/pyrogram/methods/chats/leave_chat.py @@ -30,6 +30,8 @@ async def leave_chat( ): """Leave a group chat or channel. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/chats/mark_chat_unread.py b/pyrogram/methods/chats/mark_chat_unread.py index 62cb8bee31..45aec2f878 100644 --- a/pyrogram/methods/chats/mark_chat_unread.py +++ b/pyrogram/methods/chats/mark_chat_unread.py @@ -29,6 +29,8 @@ async def mark_chat_unread( ) -> bool: """Mark a chat as unread. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/pin_chat_message.py b/pyrogram/methods/chats/pin_chat_message.py index 0eaa152513..8ec06e7b13 100644 --- a/pyrogram/methods/chats/pin_chat_message.py +++ b/pyrogram/methods/chats/pin_chat_message.py @@ -34,6 +34,8 @@ async def pin_chat_message( 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. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/promote_chat_member.py b/pyrogram/methods/chats/promote_chat_member.py index 46ffe44681..e453903773 100644 --- a/pyrogram/methods/chats/promote_chat_member.py +++ b/pyrogram/methods/chats/promote_chat_member.py @@ -34,6 +34,8 @@ async def promote_chat_member( You must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py index 717ba60bd2..6e42b364ee 100644 --- a/pyrogram/methods/chats/restrict_chat_member.py +++ b/pyrogram/methods/chats/restrict_chat_member.py @@ -37,6 +37,8 @@ async def restrict_chat_member( You must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_administrator_title.py b/pyrogram/methods/chats/set_administrator_title.py index 15f9dea5ef..2c77066ed7 100644 --- a/pyrogram/methods/chats/set_administrator_title.py +++ b/pyrogram/methods/chats/set_administrator_title.py @@ -34,6 +34,8 @@ async def set_administrator_title( If you are an administrator of a supergroup (i.e. not the owner), you can only set the title of other administrators who have been promoted by you. If you are the owner, you can change every administrator's title. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_description.py b/pyrogram/methods/chats/set_chat_description.py index 3eee92cae2..563e990c4c 100644 --- a/pyrogram/methods/chats/set_chat_description.py +++ b/pyrogram/methods/chats/set_chat_description.py @@ -31,6 +31,8 @@ async def set_chat_description( """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. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_permissions.py b/pyrogram/methods/chats/set_chat_permissions.py index d1280ea725..d8ec0cf02b 100644 --- a/pyrogram/methods/chats/set_chat_permissions.py +++ b/pyrogram/methods/chats/set_chat_permissions.py @@ -34,6 +34,8 @@ async def set_chat_permissions( You must be an administrator in the group or a supergroup for this to work and must have the *can_restrict_members* admin rights. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py index 615eca253e..f3db532991 100644 --- a/pyrogram/methods/chats/set_chat_photo.py +++ b/pyrogram/methods/chats/set_chat_photo.py @@ -41,6 +41,8 @@ async def set_chat_photo( You must be an administrator in the chat for this to work and must have the appropriate admin rights. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_protected_content.py b/pyrogram/methods/chats/set_chat_protected_content.py index ee72d7228e..b6a89c1190 100644 --- a/pyrogram/methods/chats/set_chat_protected_content.py +++ b/pyrogram/methods/chats/set_chat_protected_content.py @@ -30,6 +30,8 @@ async def set_chat_protected_content( ) -> bool: """Set the chat protected content setting. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_title.py b/pyrogram/methods/chats/set_chat_title.py index e2c270e6d2..9a963571c0 100644 --- a/pyrogram/methods/chats/set_chat_title.py +++ b/pyrogram/methods/chats/set_chat_title.py @@ -36,6 +36,8 @@ async def set_chat_title( In regular groups (non-supergroups), this method will only work if the "All Members Are Admins" setting is off. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_chat_username.py b/pyrogram/methods/chats/set_chat_username.py index 2d4bc08a88..e6d64e98c1 100644 --- a/pyrogram/methods/chats/set_chat_username.py +++ b/pyrogram/methods/chats/set_chat_username.py @@ -32,6 +32,8 @@ async def set_chat_username( To set your own username (for users only, not bots) you can use :meth:`~pyrogram.Client.set_username`. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``) Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_send_as_chat.py b/pyrogram/methods/chats/set_send_as_chat.py index 4cb50aed0c..15201f3bea 100644 --- a/pyrogram/methods/chats/set_send_as_chat.py +++ b/pyrogram/methods/chats/set_send_as_chat.py @@ -32,6 +32,8 @@ async def set_send_as_chat( Use :meth:`~pyrogram.Client.get_send_as_chats` to get all the "send_as" chats available for use. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/set_slow_mode.py b/pyrogram/methods/chats/set_slow_mode.py index ca68c87f46..60e88e6de5 100644 --- a/pyrogram/methods/chats/set_slow_mode.py +++ b/pyrogram/methods/chats/set_slow_mode.py @@ -30,6 +30,8 @@ async def set_slow_mode( ) -> bool: """Set the slow mode interval for a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/unarchive_chats.py b/pyrogram/methods/chats/unarchive_chats.py index c518fe912c..4d2cb0e411 100644 --- a/pyrogram/methods/chats/unarchive_chats.py +++ b/pyrogram/methods/chats/unarchive_chats.py @@ -29,6 +29,8 @@ async def unarchive_chats( ) -> bool: """Unarchive one or more chats. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_ids (``int`` | ``str`` | List[``int``, ``str``]): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py index 46c2241e72..bbe7b45492 100644 --- a/pyrogram/methods/chats/unban_chat_member.py +++ b/pyrogram/methods/chats/unban_chat_member.py @@ -32,6 +32,8 @@ async def unban_chat_member( The user will **not** return to the group or channel automatically, but will be able to join via link, etc. You must be an administrator for this to work. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/unpin_all_chat_messages.py b/pyrogram/methods/chats/unpin_all_chat_messages.py index 866ca7c0b7..25a53caf62 100644 --- a/pyrogram/methods/chats/unpin_all_chat_messages.py +++ b/pyrogram/methods/chats/unpin_all_chat_messages.py @@ -31,6 +31,8 @@ async def unpin_all_chat_messages( If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/chats/unpin_chat_message.py b/pyrogram/methods/chats/unpin_chat_message.py index 5b3768c096..6c8e036e0d 100644 --- a/pyrogram/methods/chats/unpin_chat_message.py +++ b/pyrogram/methods/chats/unpin_chat_message.py @@ -32,6 +32,8 @@ async def unpin_chat_message( 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. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/contacts/add_contact.py b/pyrogram/methods/contacts/add_contact.py index ae7566b2fd..9c4faa7e48 100644 --- a/pyrogram/methods/contacts/add_contact.py +++ b/pyrogram/methods/contacts/add_contact.py @@ -34,6 +34,8 @@ async def add_contact( ): """Add an existing Telegram user as contact, even without a phone number. + .. include:: /_includes/usable-by/users.rst + Parameters: user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py index 448e849a22..b4b2c628a3 100644 --- a/pyrogram/methods/contacts/delete_contacts.py +++ b/pyrogram/methods/contacts/delete_contacts.py @@ -29,6 +29,8 @@ async def delete_contacts( ) -> Union["types.User", List["types.User"], None]: """Delete contacts from your Telegram address book. + .. include:: /_includes/usable-by/users.rst + Parameters: user_ids (``int`` | ``str`` | List of ``int`` or ``str``): A single user id/username o a list of user identifiers (id or username). diff --git a/pyrogram/methods/contacts/get_contacts.py b/pyrogram/methods/contacts/get_contacts.py index 110d93a321..763f9a3058 100644 --- a/pyrogram/methods/contacts/get_contacts.py +++ b/pyrogram/methods/contacts/get_contacts.py @@ -32,6 +32,8 @@ async def get_contacts( ) -> List["types.User"]: """Get contacts from your Telegram address book. + .. include:: /_includes/usable-by/users.rst + Returns: List of :obj:`~pyrogram.types.User`: On success, a list of users is returned. diff --git a/pyrogram/methods/contacts/get_contacts_count.py b/pyrogram/methods/contacts/get_contacts_count.py index a709b6769f..56120bac71 100644 --- a/pyrogram/methods/contacts/get_contacts_count.py +++ b/pyrogram/methods/contacts/get_contacts_count.py @@ -26,6 +26,8 @@ async def get_contacts_count( ) -> int: """Get the total count of contacts from your Telegram address book. + .. include:: /_includes/usable-by/users.rst + Returns: ``int``: On success, the contacts count is returned. diff --git a/pyrogram/methods/contacts/import_contacts.py b/pyrogram/methods/contacts/import_contacts.py index 11df315be8..aa8fd4ae37 100644 --- a/pyrogram/methods/contacts/import_contacts.py +++ b/pyrogram/methods/contacts/import_contacts.py @@ -30,6 +30,8 @@ async def import_contacts( ): """Import contacts to your Telegram address book. + .. include:: /_includes/usable-by/users.rst + Parameters: contacts (List of :obj:`~pyrogram.types.InputPhoneContact`): The contact list to be added diff --git a/pyrogram/methods/invite_links/approve_all_chat_join_requests.py b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py index ec2fc1bc6c..06894bc896 100644 --- a/pyrogram/methods/invite_links/approve_all_chat_join_requests.py +++ b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py @@ -30,6 +30,8 @@ async def approve_all_chat_join_requests( ) -> bool: """Approve all pending join requests in a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/approve_chat_join_request.py b/pyrogram/methods/invite_links/approve_chat_join_request.py index 3cd2248902..2fc4e6d309 100644 --- a/pyrogram/methods/invite_links/approve_chat_join_request.py +++ b/pyrogram/methods/invite_links/approve_chat_join_request.py @@ -30,9 +30,11 @@ async def approve_chat_join_request( ) -> bool: """Approve a chat join request. - The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator + You must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py index 703d3d1434..ccf8d6505a 100644 --- a/pyrogram/methods/invite_links/create_chat_invite_link.py +++ b/pyrogram/methods/invite_links/create_chat_invite_link.py @@ -39,6 +39,8 @@ async def create_chat_invite_link( The link can be revoked using the method :meth:`~pyrogram.Client.revoke_chat_invite_link`. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/decline_all_chat_join_requests.py b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py index 620e26245e..4ce32de8c0 100644 --- a/pyrogram/methods/invite_links/decline_all_chat_join_requests.py +++ b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py @@ -30,6 +30,8 @@ async def decline_all_chat_join_requests( ) -> bool: """Decline all pending join requests in a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/decline_chat_join_request.py b/pyrogram/methods/invite_links/decline_chat_join_request.py index 94e3c2fe7f..9a35b8ee4b 100644 --- a/pyrogram/methods/invite_links/decline_chat_join_request.py +++ b/pyrogram/methods/invite_links/decline_chat_join_request.py @@ -30,9 +30,11 @@ async def decline_chat_join_request( ) -> bool: """Decline a chat join request. - The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator + You must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py index 8ba6754d0a..6e1275066d 100644 --- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py @@ -30,6 +30,8 @@ async def delete_chat_admin_invite_links( ) -> bool: """Delete all revoked invite links of an administrator. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py index 1f38e46cc4..a5915979e7 100644 --- a/pyrogram/methods/invite_links/delete_chat_invite_link.py +++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py @@ -30,6 +30,8 @@ async def delete_chat_invite_link( ) -> bool: """Delete an already revoked invite link. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py index 9951684787..553c25dd17 100644 --- a/pyrogram/methods/invite_links/edit_chat_invite_link.py +++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py @@ -38,6 +38,8 @@ async def edit_chat_invite_link( You must be an administrator in the chat for this to work and must have the appropriate admin rights. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py index ae40391fe0..f06caf0f9a 100644 --- a/pyrogram/methods/invite_links/export_chat_invite_link.py +++ b/pyrogram/methods/invite_links/export_chat_invite_link.py @@ -39,6 +39,8 @@ async def export_chat_invite_link( :meth:`~pyrogram.Client.get_chat` method. If your bot needs to generate a new invite link replacing its previous one, use this method again. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py index 1c79ce273c..c845902e4e 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py @@ -38,6 +38,8 @@ async def get_chat_admin_invite_links( As an administrator you can only get your own links you have exported. As the chat or channel owner you can get everyones links. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py index c26af5063c..68479a61f3 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py @@ -31,6 +31,8 @@ async def get_chat_admin_invite_links_count( ) -> int: """Get the count of the invite links created by an administrator in a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py index 61e082bc0e..d5bf6569ad 100644 --- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py @@ -31,7 +31,9 @@ async def get_chat_admins_with_invite_links( You must be the owner of a chat for this to work. - Args: + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). diff --git a/pyrogram/methods/invite_links/get_chat_invite_link.py b/pyrogram/methods/invite_links/get_chat_invite_link.py index 7447933658..8ad575f34a 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link.py @@ -31,6 +31,8 @@ async def get_chat_invite_link( ) -> "types.ChatInviteLink": """Get detailed information about a chat invite link. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py index cfd6873433..d03d108311 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py @@ -32,6 +32,8 @@ async def get_chat_invite_link_joiners( ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: """Get the members who joined the chat with the invite link. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py index 084fbae570..715053e611 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py @@ -30,6 +30,8 @@ async def get_chat_invite_link_joiners_count( ) -> int: """Get the count of the members who joined the chat with the invite link. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/get_chat_join_requests.py b/pyrogram/methods/invite_links/get_chat_join_requests.py index 9a9bc38793..ee6fe7e388 100644 --- a/pyrogram/methods/invite_links/get_chat_join_requests.py +++ b/pyrogram/methods/invite_links/get_chat_join_requests.py @@ -32,6 +32,8 @@ async def get_chat_join_requests( ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: """Get the pending join requests of a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/invite_links/revoke_chat_invite_link.py b/pyrogram/methods/invite_links/revoke_chat_invite_link.py index a334bb8de2..ff55a04e03 100644 --- a/pyrogram/methods/invite_links/revoke_chat_invite_link.py +++ b/pyrogram/methods/invite_links/revoke_chat_invite_link.py @@ -35,6 +35,8 @@ async def revoke_chat_invite_link( You must be an administrator in the chat for this to work and must have the appropriate admin rights. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier for the target chat or username of the target channel/supergroup diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index de47465d27..52911ea0bc 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -36,6 +36,8 @@ async def copy_media_group( ) -> List["types.Message"]: """Copy a media group by providing one of the message ids. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py index b114a9e0af..66b7e37cb3 100644 --- a/pyrogram/methods/messages/copy_message.py +++ b/pyrogram/methods/messages/copy_message.py @@ -51,6 +51,8 @@ async def copy_message( The method is analogous to the method :meth:`~Client.forward_messages`, but the copied message doesn't have a link to the original message. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/delete_messages.py b/pyrogram/methods/messages/delete_messages.py index 523ecd544c..07c3a7b85b 100644 --- a/pyrogram/methods/messages/delete_messages.py +++ b/pyrogram/methods/messages/delete_messages.py @@ -31,6 +31,8 @@ async def delete_messages( ) -> int: """Delete messages, including service messages. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py index d46bd50391..4f44ff254f 100644 --- a/pyrogram/methods/messages/download_media.py +++ b/pyrogram/methods/messages/download_media.py @@ -40,6 +40,8 @@ async def download_media( ) -> Optional[Union[str, BinaryIO]]: """Download the media from a message. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: message (:obj:`~pyrogram.types.Message` | ``str``): Pass a Message containing the media, the media itself (message.audio, message.video, ...) or a file id diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py index 0996d34e68..69c7333416 100644 --- a/pyrogram/methods/messages/edit_inline_caption.py +++ b/pyrogram/methods/messages/edit_inline_caption.py @@ -32,6 +32,8 @@ async def edit_inline_caption( ) -> bool: """Edit the caption of inline media messages. + .. include:: /_includes/usable-by/bots.rst + Parameters: inline_message_id (``str``): Identifier of the inline message. diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 81aa30ee6b..77fa673ae6 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -45,6 +45,8 @@ async def edit_inline_media( When the inline message is edited, a new file can't be uploaded. Use a previously uploaded file via its file_id or specify a URL. + .. include:: /_includes/usable-by/bots.rst + Parameters: inline_message_id (``str``): Required if *chat_id* and *message_id* are not specified. diff --git a/pyrogram/methods/messages/edit_inline_reply_markup.py b/pyrogram/methods/messages/edit_inline_reply_markup.py index 4e06e447f7..e2ef40e160 100644 --- a/pyrogram/methods/messages/edit_inline_reply_markup.py +++ b/pyrogram/methods/messages/edit_inline_reply_markup.py @@ -31,6 +31,8 @@ async def edit_inline_reply_markup( ) -> bool: """Edit only the reply markup of inline messages sent via the bot (for inline bots). + .. include:: /_includes/usable-by/bots.rst + Parameters: inline_message_id (``str``): Identifier of the inline message. diff --git a/pyrogram/methods/messages/edit_inline_text.py b/pyrogram/methods/messages/edit_inline_text.py index 9caee55aaf..354c55a339 100644 --- a/pyrogram/methods/messages/edit_inline_text.py +++ b/pyrogram/methods/messages/edit_inline_text.py @@ -36,6 +36,8 @@ async def edit_inline_text( ) -> bool: """Edit the text of inline messages. + .. include:: /_includes/usable-by/bots.rst + Parameters: inline_message_id (``str``): Identifier of the inline message. diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py index d3b311db6e..2e4a45a694 100644 --- a/pyrogram/methods/messages/edit_message_caption.py +++ b/pyrogram/methods/messages/edit_message_caption.py @@ -34,6 +34,8 @@ async def edit_message_caption( ) -> "types.Message": """Edit the caption of media messages. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index a3840f2374..16efb5b858 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -42,6 +42,8 @@ async def edit_message_media( If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, the message type can be changed arbitrarily. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/edit_message_reply_markup.py b/pyrogram/methods/messages/edit_message_reply_markup.py index 088e646ddb..1cd75c1a8b 100644 --- a/pyrogram/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/methods/messages/edit_message_reply_markup.py @@ -32,6 +32,8 @@ async def edit_message_reply_markup( ) -> "types.Message": """Edit only the reply markup of messages sent by the bot. + .. include:: /_includes/usable-by/bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py index 94852de582..540b6aa63c 100644 --- a/pyrogram/methods/messages/edit_message_text.py +++ b/pyrogram/methods/messages/edit_message_text.py @@ -37,6 +37,8 @@ async def edit_message_text( ) -> "types.Message": """Edit the text of messages. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/forward_messages.py b/pyrogram/methods/messages/forward_messages.py index be7b2ab5ef..8635e17101 100644 --- a/pyrogram/methods/messages/forward_messages.py +++ b/pyrogram/methods/messages/forward_messages.py @@ -36,6 +36,8 @@ async def forward_messages( ) -> Union["types.Message", List["types.Message"]]: """Forward messages of any kind. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_chat_history.py b/pyrogram/methods/messages/get_chat_history.py index a7fcc491e9..b384c6ba8f 100644 --- a/pyrogram/methods/messages/get_chat_history.py +++ b/pyrogram/methods/messages/get_chat_history.py @@ -62,6 +62,8 @@ async def get_chat_history( The messages are returned in reverse chronological order. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_chat_history_count.py b/pyrogram/methods/messages/get_chat_history_count.py index 46f61eb056..1926224b35 100644 --- a/pyrogram/methods/messages/get_chat_history_count.py +++ b/pyrogram/methods/messages/get_chat_history_count.py @@ -38,6 +38,8 @@ async def get_chat_history_count( a **private** or a **basic group** chat has with a single method call. To overcome this limitation, Pyrogram has to iterate over all the messages. Channels and supergroups are not affected by this limitation. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py index 335f4ce9d5..7a71f0587c 100644 --- a/pyrogram/methods/messages/get_custom_emoji_stickers.py +++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py @@ -30,6 +30,8 @@ async def get_custom_emoji_stickers( ) -> List["types.Sticker"]: """Get information about custom emoji stickers by their identifiers. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: custom_emoji_ids (List of ``int``): List of custom emoji identifiers. diff --git a/pyrogram/methods/messages/get_discussion_message.py b/pyrogram/methods/messages/get_discussion_message.py index 93510e211e..58a6b7044d 100644 --- a/pyrogram/methods/messages/get_discussion_message.py +++ b/pyrogram/methods/messages/get_discussion_message.py @@ -34,6 +34,8 @@ async def get_discussion_message( Reply to the returned message to leave a comment on the linked channel post or to continue the discussion thread. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_discussion_replies.py b/pyrogram/methods/messages/get_discussion_replies.py index 467cca8d2b..dd23751bb1 100644 --- a/pyrogram/methods/messages/get_discussion_replies.py +++ b/pyrogram/methods/messages/get_discussion_replies.py @@ -31,6 +31,8 @@ async def get_discussion_replies( ) -> Optional[AsyncGenerator["types.Message", None]]: """Get the message replies of a discussion thread. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_discussion_replies_count.py b/pyrogram/methods/messages/get_discussion_replies_count.py index 260be802eb..bbb90ac3a2 100644 --- a/pyrogram/methods/messages/get_discussion_replies_count.py +++ b/pyrogram/methods/messages/get_discussion_replies_count.py @@ -30,6 +30,8 @@ async def get_discussion_replies_count( ) -> int: """Get the total count of replies in a discussion thread. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_media_group.py b/pyrogram/methods/messages/get_media_group.py index b50d4785af..97770d90f5 100644 --- a/pyrogram/methods/messages/get_media_group.py +++ b/pyrogram/methods/messages/get_media_group.py @@ -32,7 +32,9 @@ async def get_media_group( message_id: int ) -> List["types.Message"]: """Get the media group a message belongs to. - + + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index 17d80e58a6..3f398c36eb 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -42,6 +42,8 @@ async def get_messages( You can retrieve up to 200 messages at once. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/read_chat_history.py b/pyrogram/methods/messages/read_chat_history.py index b3cc3bfc4c..4b96273936 100644 --- a/pyrogram/methods/messages/read_chat_history.py +++ b/pyrogram/methods/messages/read_chat_history.py @@ -30,6 +30,8 @@ async def read_chat_history( ) -> bool: """Mark a chat's message history as read. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py index 8420a4a318..c456f4d08b 100644 --- a/pyrogram/methods/messages/retract_vote.py +++ b/pyrogram/methods/messages/retract_vote.py @@ -31,6 +31,8 @@ async def retract_vote( ) -> "types.Poll": """Retract your vote in a poll. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/search_global.py b/pyrogram/methods/messages/search_global.py index 5e54a965c8..f566c98150 100644 --- a/pyrogram/methods/messages/search_global.py +++ b/pyrogram/methods/messages/search_global.py @@ -40,6 +40,8 @@ async def search_global( Due to server-side limitations, you can only get up to around ~10,000 messages and each message retrieved will not have any *reply_to_message* field. + .. include:: /_includes/usable-by/users.rst + Parameters: query (``str``, *optional*): Text query string. diff --git a/pyrogram/methods/messages/search_global_count.py b/pyrogram/methods/messages/search_global_count.py index 2e559ded9f..8323a821d2 100644 --- a/pyrogram/methods/messages/search_global_count.py +++ b/pyrogram/methods/messages/search_global_count.py @@ -30,6 +30,8 @@ async def search_global_count( If you want to get the actual messages, see :meth:`~pyrogram.Client.search_global`. + .. include:: /_includes/usable-by/users.rst + Parameters: query (``str``, *optional*): Text query string. diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py index 1f9fa3c76e..4497ff1cd3 100644 --- a/pyrogram/methods/messages/search_messages.py +++ b/pyrogram/methods/messages/search_messages.py @@ -72,6 +72,8 @@ async def search_messages( If you want to get the messages count only, see :meth:`~pyrogram.Client.search_messages_count`. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/search_messages_count.py b/pyrogram/methods/messages/search_messages_count.py index 09f778559b..ea9ae4d18e 100644 --- a/pyrogram/methods/messages/search_messages_count.py +++ b/pyrogram/methods/messages/search_messages_count.py @@ -34,6 +34,8 @@ async def search_messages_count( If you want to get the actual messages, see :meth:`~pyrogram.Client.search_messages`. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index efa9cb1671..ec85dc0569 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -59,6 +59,8 @@ async def send_animation( ) -> Optional["types.Message"]: """Send animation files (animation or H.264/MPEG-4 AVC video without sound). + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index f4552832fe..7a81df0195 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -60,6 +60,8 @@ async def send_audio( For sending voice messages, use the :meth:`~pyrogram.Client.send_voice` method instead. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_cached_media.py b/pyrogram/methods/messages/send_cached_media.py index f0e04d7232..5a9e2e1f1a 100644 --- a/pyrogram/methods/messages/send_cached_media.py +++ b/pyrogram/methods/messages/send_cached_media.py @@ -50,6 +50,8 @@ async def send_cached_media( It does the same as calling the relevant method for sending media using a file_id, thus saving you from the hassle of using the correct method for the media the file_id is pointing to. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py index 15b5ac0853..44b16628f8 100644 --- a/pyrogram/methods/messages/send_chat_action.py +++ b/pyrogram/methods/messages/send_chat_action.py @@ -30,6 +30,8 @@ async def send_chat_action( ) -> bool: """Tell the other party that something is happening on your side. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_contact.py b/pyrogram/methods/messages/send_contact.py index cedcd0b25b..30f7abd315 100644 --- a/pyrogram/methods/messages/send_contact.py +++ b/pyrogram/methods/messages/send_contact.py @@ -45,6 +45,8 @@ async def send_contact( ) -> "types.Message": """Send phone contacts. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_dice.py b/pyrogram/methods/messages/send_dice.py index 942f681ff0..c657d85dd9 100644 --- a/pyrogram/methods/messages/send_dice.py +++ b/pyrogram/methods/messages/send_dice.py @@ -42,6 +42,8 @@ async def send_dice( ) -> Optional["types.Message"]: """Send a dice with a random value from 1 to 6. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_document.py b/pyrogram/methods/messages/send_document.py index 99c90fbb25..b0a4a531e3 100644 --- a/pyrogram/methods/messages/send_document.py +++ b/pyrogram/methods/messages/send_document.py @@ -56,6 +56,8 @@ async def send_document( ) -> Optional["types.Message"]: """Send generic files. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_location.py b/pyrogram/methods/messages/send_location.py index fe7d1ed16d..2bd17681b0 100644 --- a/pyrogram/methods/messages/send_location.py +++ b/pyrogram/methods/messages/send_location.py @@ -43,6 +43,8 @@ async def send_location( ) -> "types.Message": """Send points on the map. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index 43eb9d7c2b..0dfbbaa236 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -49,6 +49,8 @@ async def send_media_group( ) -> List["types.Message"]: """Send a group of photos or videos as an album. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_message.py b/pyrogram/methods/messages/send_message.py index b365880ed5..ad73f9a182 100644 --- a/pyrogram/methods/messages/send_message.py +++ b/pyrogram/methods/messages/send_message.py @@ -45,6 +45,8 @@ async def send_message( ) -> "types.Message": """Send text messages. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 6add68cd6c..994f0c9322 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -53,6 +53,8 @@ async def send_photo( ) -> Optional["types.Message"]: """Send photos. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py index 207cff9faf..267dcb6dad 100644 --- a/pyrogram/methods/messages/send_poll.py +++ b/pyrogram/methods/messages/send_poll.py @@ -53,6 +53,8 @@ async def send_poll( ) -> "types.Message": """Send a new poll. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_reaction.py b/pyrogram/methods/messages/send_reaction.py index b1e6540b68..f4d1d34340 100644 --- a/pyrogram/methods/messages/send_reaction.py +++ b/pyrogram/methods/messages/send_reaction.py @@ -32,6 +32,8 @@ async def send_reaction( ) -> bool: """Send a reaction to a message. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_sticker.py b/pyrogram/methods/messages/send_sticker.py index 2fc4565cb5..ccfaada51e 100644 --- a/pyrogram/methods/messages/send_sticker.py +++ b/pyrogram/methods/messages/send_sticker.py @@ -50,6 +50,8 @@ async def send_sticker( ) -> Optional["types.Message"]: """Send static .webp or animated .tgs stickers. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_venue.py b/pyrogram/methods/messages/send_venue.py index e8cc760b30..4d3167bf00 100644 --- a/pyrogram/methods/messages/send_venue.py +++ b/pyrogram/methods/messages/send_venue.py @@ -47,6 +47,8 @@ async def send_venue( ) -> "types.Message": """Send information about a venue. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index 669b42ec05..c20530641c 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -60,6 +60,8 @@ async def send_video( ) -> Optional["types.Message"]: """Send video files. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_video_note.py b/pyrogram/methods/messages/send_video_note.py index bf33cdb724..9c615d3116 100644 --- a/pyrogram/methods/messages/send_video_note.py +++ b/pyrogram/methods/messages/send_video_note.py @@ -52,6 +52,8 @@ async def send_video_note( ) -> Optional["types.Message"]: """Send video messages. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index 5947ecc23d..266702fd83 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -54,6 +54,8 @@ async def send_voice( ) -> Optional["types.Message"]: """Send audio files. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py index 6104403f5c..89a33434b7 100644 --- a/pyrogram/methods/messages/stop_poll.py +++ b/pyrogram/methods/messages/stop_poll.py @@ -34,6 +34,8 @@ async def stop_poll( Stopped polls can't be reopened and nobody will be able to vote in it anymore. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/messages/stream_media.py b/pyrogram/methods/messages/stream_media.py index 91ffefd7ee..b432badb4c 100644 --- a/pyrogram/methods/messages/stream_media.py +++ b/pyrogram/methods/messages/stream_media.py @@ -36,6 +36,8 @@ async def stream_media( You can use this method to partially download a file into memory or to selectively download chunks of file. The chunk maximum size is 1 MiB (1024 * 1024 bytes). + .. include:: /_includes/usable-by/users-bots.rst + Parameters: message (:obj:`~pyrogram.types.Message` | ``str``): Pass a Message containing the media, the media itself (message.audio, message.video, ...) or a file id diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py index 72a912deae..620fac5a15 100644 --- a/pyrogram/methods/messages/vote_poll.py +++ b/pyrogram/methods/messages/vote_poll.py @@ -32,6 +32,8 @@ async def vote_poll( ) -> "types.Poll": """Vote a poll. + .. include:: /_includes/usable-by/users.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/password/change_cloud_password.py b/pyrogram/methods/password/change_cloud_password.py index c5e8bd27c7..29540d653b 100644 --- a/pyrogram/methods/password/change_cloud_password.py +++ b/pyrogram/methods/password/change_cloud_password.py @@ -32,6 +32,8 @@ async def change_cloud_password( ) -> bool: """Change your Two-Step Verification password (Cloud Password) with a new one. + .. include:: /_includes/usable-by/users.rst + Parameters: current_password (``str``): Your current password. diff --git a/pyrogram/methods/password/enable_cloud_password.py b/pyrogram/methods/password/enable_cloud_password.py index a6533dbf70..8f5e59c570 100644 --- a/pyrogram/methods/password/enable_cloud_password.py +++ b/pyrogram/methods/password/enable_cloud_password.py @@ -34,6 +34,8 @@ async def enable_cloud_password( This password will be asked when you log-in on a new device in addition to the SMS code. + .. include:: /_includes/usable-by/users.rst + Parameters: password (``str``): Your password. diff --git a/pyrogram/methods/password/remove_cloud_password.py b/pyrogram/methods/password/remove_cloud_password.py index dab37d8635..0ec16e12cd 100644 --- a/pyrogram/methods/password/remove_cloud_password.py +++ b/pyrogram/methods/password/remove_cloud_password.py @@ -28,6 +28,8 @@ async def remove_cloud_password( ) -> bool: """Turn off the Two-Step Verification security feature (Cloud Password) on your account. + .. include:: /_includes/usable-by/users.rst + Parameters: password (``str``): Your current password. diff --git a/pyrogram/methods/users/block_user.py b/pyrogram/methods/users/block_user.py index f14479558e..25cd0ce84e 100644 --- a/pyrogram/methods/users/block_user.py +++ b/pyrogram/methods/users/block_user.py @@ -29,6 +29,8 @@ async def block_user( ) -> bool: """Block a user. + .. include:: /_includes/usable-by/users.rst + Parameters: user_id (``int`` | ``str``):: Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/methods/users/delete_profile_photos.py b/pyrogram/methods/users/delete_profile_photos.py index 4ee8b7b51d..2b52d02f59 100644 --- a/pyrogram/methods/users/delete_profile_photos.py +++ b/pyrogram/methods/users/delete_profile_photos.py @@ -31,6 +31,8 @@ async def delete_profile_photos( ) -> bool: """Delete your own profile photos. + .. include:: /_includes/usable-by/users.rst + Parameters: photo_ids (``str`` | List of ``str``): A single :obj:`~pyrogram.types.Photo` id as string or multiple ids as list of strings for deleting diff --git a/pyrogram/methods/users/get_chat_photos.py b/pyrogram/methods/users/get_chat_photos.py index d3bc1f1feb..d22c68dcd8 100644 --- a/pyrogram/methods/users/get_chat_photos.py +++ b/pyrogram/methods/users/get_chat_photos.py @@ -30,6 +30,8 @@ async def get_chat_photos( ) -> Optional[AsyncGenerator["types.Photo", None]]: """Get a chat or a user profile photos sequentially. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/users/get_chat_photos_count.py b/pyrogram/methods/users/get_chat_photos_count.py index eca186a820..d4cf1594f1 100644 --- a/pyrogram/methods/users/get_chat_photos_count.py +++ b/pyrogram/methods/users/get_chat_photos_count.py @@ -29,6 +29,8 @@ async def get_chat_photos_count( ) -> int: """Get the total count of photos for a chat. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/users/get_common_chats.py b/pyrogram/methods/users/get_common_chats.py index a45bda6f4c..31e2bac38e 100644 --- a/pyrogram/methods/users/get_common_chats.py +++ b/pyrogram/methods/users/get_common_chats.py @@ -30,6 +30,8 @@ async def get_common_chats( ) -> List["types.Chat"]: """Get the common chats you have with a user. + .. include:: /_includes/usable-by/users.rst + Parameters: user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. diff --git a/pyrogram/methods/users/get_default_emoji_statuses.py b/pyrogram/methods/users/get_default_emoji_statuses.py index 8c85a3c202..cd3768b9a4 100644 --- a/pyrogram/methods/users/get_default_emoji_statuses.py +++ b/pyrogram/methods/users/get_default_emoji_statuses.py @@ -29,6 +29,8 @@ async def get_default_emoji_statuses( ) -> List["types.EmojiStatus"]: """Get the default emoji statuses. + .. include:: /_includes/usable-by/users-bots.rst + Returns: List of :obj:`~pyrogram.types.EmojiStatus`: On success, a list of emoji statuses is returned. diff --git a/pyrogram/methods/users/get_me.py b/pyrogram/methods/users/get_me.py index 610a11af53..a8df3ae9f3 100644 --- a/pyrogram/methods/users/get_me.py +++ b/pyrogram/methods/users/get_me.py @@ -27,6 +27,8 @@ async def get_me( ) -> "types.User": """Get your own user identity. + .. include:: /_includes/usable-by/users-bots.rst + Returns: :obj:`~pyrogram.types.User`: Information about the own logged in user/bot. diff --git a/pyrogram/methods/users/get_users.py b/pyrogram/methods/users/get_users.py index 384dded0af..39821a8c5d 100644 --- a/pyrogram/methods/users/get_users.py +++ b/pyrogram/methods/users/get_users.py @@ -32,6 +32,8 @@ async def get_users( """Get information about a user. You can retrieve up to 200 users at once. + .. include:: /_includes/usable-by/users-bots.rst + Parameters: user_ids (``int`` | ``str`` | Iterable of ``int`` or ``str``): A list of User identifiers (id or username) or a single user id/username. diff --git a/pyrogram/methods/users/set_emoji_status.py b/pyrogram/methods/users/set_emoji_status.py index 288e966b20..2d8c77cc02 100644 --- a/pyrogram/methods/users/set_emoji_status.py +++ b/pyrogram/methods/users/set_emoji_status.py @@ -29,6 +29,8 @@ async def set_emoji_status( ) -> bool: """Set the emoji status. + .. include:: /_includes/usable-by/users.rst + Parameters: emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*): The emoji status to set. None to remove. diff --git a/pyrogram/methods/users/set_profile_photo.py b/pyrogram/methods/users/set_profile_photo.py index 86aaf31f6d..e08e669c4e 100644 --- a/pyrogram/methods/users/set_profile_photo.py +++ b/pyrogram/methods/users/set_profile_photo.py @@ -39,6 +39,8 @@ async def set_profile_photo( This method only works for Users. Bots profile photos must be set using BotFather. + .. include:: /_includes/usable-by/users.rst + Parameters: photo (``str`` | ``BinaryIO``, *optional*): Profile photo to set. diff --git a/pyrogram/methods/users/set_username.py b/pyrogram/methods/users/set_username.py index 6f070bc5f2..d336628eec 100644 --- a/pyrogram/methods/users/set_username.py +++ b/pyrogram/methods/users/set_username.py @@ -33,6 +33,8 @@ async def set_username( them from scratch using BotFather. To set a channel or supergroup username you can use :meth:`~pyrogram.Client.set_chat_username`. + .. include:: /_includes/usable-by/users.rst + Parameters: username (``str`` | ``None``): Username to set. "" (empty string) or None to remove it. diff --git a/pyrogram/methods/users/unblock_user.py b/pyrogram/methods/users/unblock_user.py index 4809aa6ba6..db4fdddcff 100644 --- a/pyrogram/methods/users/unblock_user.py +++ b/pyrogram/methods/users/unblock_user.py @@ -29,6 +29,8 @@ async def unblock_user( ) -> bool: """Unblock a user. + .. include:: /_includes/usable-by/users.rst + Parameters: user_id (``int`` | ``str``):: Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/methods/users/update_profile.py b/pyrogram/methods/users/update_profile.py index 31f12508f5..6c10d16c9d 100644 --- a/pyrogram/methods/users/update_profile.py +++ b/pyrogram/methods/users/update_profile.py @@ -31,6 +31,8 @@ async def update_profile( You can omit the parameters you don't want to change. + .. include:: /_includes/usable-by/users.rst + Parameters: first_name (``str``, *optional*): The new first name. From bf52ec1e944d224c449fda32a900c46000a7e666 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 15 Oct 2022 15:49:36 +0200 Subject: [PATCH 398/539] Update usable-by labels --- pyrogram/methods/invite_links/approve_all_chat_join_requests.py | 2 +- pyrogram/methods/invite_links/decline_all_chat_join_requests.py | 2 +- pyrogram/methods/invite_links/delete_chat_admin_invite_links.py | 2 +- pyrogram/methods/invite_links/delete_chat_invite_link.py | 2 +- pyrogram/methods/invite_links/get_chat_admin_invite_links.py | 2 +- .../methods/invite_links/get_chat_admin_invite_links_count.py | 2 +- .../methods/invite_links/get_chat_admins_with_invite_links.py | 2 +- pyrogram/methods/invite_links/get_chat_invite_link_joiners.py | 2 +- .../methods/invite_links/get_chat_invite_link_joiners_count.py | 2 +- pyrogram/methods/invite_links/get_chat_join_requests.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pyrogram/methods/invite_links/approve_all_chat_join_requests.py b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py index 06894bc896..623fd87fcc 100644 --- a/pyrogram/methods/invite_links/approve_all_chat_join_requests.py +++ b/pyrogram/methods/invite_links/approve_all_chat_join_requests.py @@ -30,7 +30,7 @@ async def approve_all_chat_join_requests( ) -> bool: """Approve all pending join requests in a chat. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/decline_all_chat_join_requests.py b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py index 4ce32de8c0..9cf5095507 100644 --- a/pyrogram/methods/invite_links/decline_all_chat_join_requests.py +++ b/pyrogram/methods/invite_links/decline_all_chat_join_requests.py @@ -30,7 +30,7 @@ async def decline_all_chat_join_requests( ) -> bool: """Decline all pending join requests in a chat. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py index 6e1275066d..32ef1de5e7 100644 --- a/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/delete_chat_admin_invite_links.py @@ -30,7 +30,7 @@ async def delete_chat_admin_invite_links( ) -> bool: """Delete all revoked invite links of an administrator. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/delete_chat_invite_link.py b/pyrogram/methods/invite_links/delete_chat_invite_link.py index a5915979e7..82db623abe 100644 --- a/pyrogram/methods/invite_links/delete_chat_invite_link.py +++ b/pyrogram/methods/invite_links/delete_chat_invite_link.py @@ -30,7 +30,7 @@ async def delete_chat_invite_link( ) -> bool: """Delete an already revoked invite link. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py index c845902e4e..62acca10e8 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links.py @@ -38,7 +38,7 @@ async def get_chat_admin_invite_links( As an administrator you can only get your own links you have exported. As the chat or channel owner you can get everyones links. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py index 68479a61f3..528876ed4e 100644 --- a/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py +++ b/pyrogram/methods/invite_links/get_chat_admin_invite_links_count.py @@ -31,7 +31,7 @@ async def get_chat_admin_invite_links_count( ) -> int: """Get the count of the invite links created by an administrator in a chat. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py index d5bf6569ad..f283e53464 100644 --- a/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py +++ b/pyrogram/methods/invite_links/get_chat_admins_with_invite_links.py @@ -31,7 +31,7 @@ async def get_chat_admins_with_invite_links( You must be the owner of a chat for this to work. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py index d03d108311..c1fc43a71f 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners.py @@ -32,7 +32,7 @@ async def get_chat_invite_link_joiners( ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: """Get the members who joined the chat with the invite link. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py index 715053e611..c591be1927 100644 --- a/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py +++ b/pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py @@ -30,7 +30,7 @@ async def get_chat_invite_link_joiners_count( ) -> int: """Get the count of the members who joined the chat with the invite link. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/methods/invite_links/get_chat_join_requests.py b/pyrogram/methods/invite_links/get_chat_join_requests.py index ee6fe7e388..a75498e2f6 100644 --- a/pyrogram/methods/invite_links/get_chat_join_requests.py +++ b/pyrogram/methods/invite_links/get_chat_join_requests.py @@ -32,7 +32,7 @@ async def get_chat_join_requests( ) -> Optional[AsyncGenerator["types.ChatJoiner", None]]: """Get the pending join requests of a chat. - .. include:: /_includes/usable-by/users-bots.rst + .. include:: /_includes/usable-by/users.rst Parameters: chat_id (``int`` | ``str``): From 9ade92c85525ecd439ab52506047991220664040 Mon Sep 17 00:00:00 2001 From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com> Date: Sat, 15 Oct 2022 18:19:38 +0200 Subject: [PATCH 399/539] Add languages to "pre" tags (HTML and Markdown) #1118 * added `language` to entities when unparsing (both markdown and html) * added `language` to entities also when parsing (html only) * Update html.py * Update markdown.py * Update markdown.py * Update markdown.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/parser/html.py | 8 ++++++-- pyrogram/parser/markdown.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index dee8a49dd4..af70c5cb34 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -61,7 +61,7 @@ def handle_starttag(self, tag, attrs): entity = raw.types.MessageEntityCode elif tag == "pre": entity = raw.types.MessageEntityPre - extra["language"] = "" + extra["language"] = attrs.get("language", "") elif tag == "spoiler": entity = raw.types.MessageEntitySpoiler elif tag == "a": @@ -172,9 +172,13 @@ def unparse(text: str, entities: list): name = entity_type.name[0].lower() start_tag = f"<{name}>" end_tag = f"" + elif entity_type == MessageEntityType.PRE: + name = entity_type.name.lower() + language = getattr(entity, "language", "") or "" + start_tag = f'<{name} language="{language}">' if language else f"<{name}>" + end_tag = f"" elif entity_type in ( MessageEntityType.CODE, - MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE, MessageEntityType.SPOILER, ): diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index 364793406a..6219d9583d 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -105,6 +105,12 @@ async def parse(self, text: str, strict: bool = False): delims.remove(delim) tag = CLOSING_TAG.format(tag) + if delim == PRE_DELIM and delim in delims: + delim_and_language = text[text.find(PRE_DELIM):].split("\n")[0] + language = delim_and_language[len(PRE_DELIM):] + text = utils.replace_once(text, delim_and_language, f'
', start)
+                continue
+
             text = utils.replace_once(text, delim, tag, start)
 
         return await self.html.parse(text)
@@ -130,7 +136,11 @@ def unparse(text: str, entities: list):
                 start_tag = end_tag = STRIKE_DELIM
             elif entity_type == MessageEntityType.CODE:
                 start_tag = end_tag = CODE_DELIM
-            elif entity_type in (MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE):
+            elif entity_type == MessageEntityType.PRE:
+                language = getattr(entity, "language", "") or ""
+                start_tag = f"{PRE_DELIM}{language}\n"
+                end_tag = f"\n{PRE_DELIM}"
+            elif entity_type == MessageEntityType.BLOCKQUOTE:
                 start_tag = end_tag = PRE_DELIM
             elif entity_type == MessageEntityType.SPOILER:
                 start_tag = end_tag = SPOILER_DELIM

From b660115a603c14938dc518688054b1b5181487a4 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 15 Oct 2022 18:20:46 +0200
Subject: [PATCH 400/539] Update Pyrogram to v2.0.58

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index e9dcc31f0b..0852e565b5 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.57"
+__version__ = "2.0.58"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 3eda82d0aff94c24d2ba1ecd5767de5ae70c09e2 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 16 Oct 2022 12:07:24 +0200
Subject: [PATCH 401/539] Update html.py

---
 pyrogram/parser/html.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index af70c5cb34..7ed2a5be10 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -117,7 +117,8 @@ def __init__(self, client: Optional["pyrogram.Client"]):
         self.client = client
 
     async def parse(self, text: str):
-        # Strip whitespace characters from the end of the message, but preserve closing tags
+        # Strip whitespaces from the beginning and the end, but preserve closing tags
+        text = re.sub(r"^\s*(<[\w<>=\s\"]*>)\s*", r"\1", text)
         text = re.sub(r"\s*(]*>)\s*$", r"\1", text)
 
         parser = Parser(self.client)

From ef92389ed029ddc4d95e2d234cf3d302774c7e7d Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 16 Oct 2022 12:07:57 +0200
Subject: [PATCH 402/539] Update Pyrogram to v2.0.59

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 0852e565b5..924bb27644 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.58"
+__version__ = "2.0.59"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From a374e0175d524cbd43ea64801fc0c5b11eb959fd Mon Sep 17 00:00:00 2001
From: Nick <64551534+null-nick@users.noreply.github.com>
Date: Sun, 13 Nov 2022 13:55:44 +0100
Subject: [PATCH 403/539] Update API schema to Layer 148

---
 compiler/api/source/main_api.tl | 94 ++++++++++++++++++++++-----------
 1 file changed, 64 insertions(+), 30 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index 9d71625f9d..e89ef9ff49 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -88,7 +88,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType;
 storage.fileWebp#1081464c = storage.FileType;
 
 userEmpty#d3bc4b7a id:long = User;
-user#5d99adee flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus = User;
+user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User;
 
 userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto;
 userProfilePhoto#82d1f706 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto;
@@ -103,7 +103,7 @@ userStatusLastMonth#77ebc742 = UserStatus;
 chatEmpty#29562865 id:long = Chat;
 chat#41cbf256 flags:# creator:flags.0?true left:flags.2?true deactivated:flags.5?true call_active:flags.23?true call_not_empty:flags.24?true noforwards:flags.25?true id:long title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat;
 chatForbidden#6592a1a7 id:long title:string = Chat;
-channel#8261ac61 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
+channel#83259464 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true forum:flags.30?true flags2:# id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int usernames:flags2.0?Vector = Chat;
 channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat;
 
 chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull;
@@ -170,6 +170,8 @@ messageActionChatJoinedByRequest#ebbca3cb = MessageAction;
 messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction;
 messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction;
 messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = MessageAction;
+messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction;
+messageActionTopicEdit#b18a431c flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = MessageAction;
 
 dialog#a8edd0f5 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
 dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
@@ -198,6 +200,7 @@ inputNotifyPeer#b8bc5b0c peer:InputPeer = InputNotifyPeer;
 inputNotifyUsers#193b4417 = InputNotifyPeer;
 inputNotifyChats#4a95e84e = InputNotifyPeer;
 inputNotifyBroadcasts#b1db7c7e = InputNotifyPeer;
+inputNotifyForumTopic#5c467992 peer:InputPeer top_msg_id:int = InputNotifyPeer;
 
 inputPeerNotifySettings#df1f002b flags:# show_previews:flags.0?Bool silent:flags.1?Bool mute_until:flags.2?int sound:flags.3?NotificationSound = InputPeerNotifySettings;
 
@@ -276,7 +279,7 @@ updateUserTyping#c01e857f user_id:long action:SendMessageAction = Update;
 updateChatUserTyping#83487af0 chat_id:long from_id:Peer action:SendMessageAction = Update;
 updateChatParticipants#7761198 participants:ChatParticipants = Update;
 updateUserStatus#e5bdf8de user_id:long status:UserStatus = Update;
-updateUserName#c3f202e0 user_id:long first_name:string last_name:string username:string = Update;
+updateUserName#a7848924 user_id:long first_name:string last_name:string usernames:Vector = Update;
 updateUserPhoto#f227868c user_id:long date:int photo:UserProfilePhoto previous:Bool = Update;
 updateNewEncryptedMessage#12bcbd9a message:EncryptedMessage qts:int = Update;
 updateEncryptedChatTyping#1710f156 chat_id:int = Update;
@@ -311,7 +314,7 @@ updateBotCallbackQuery#b9cfc48d flags:# query_id:long user_id:long peer:Peer msg
 updateEditMessage#e40370a3 message:Message pts:int pts_count:int = Update;
 updateInlineBotCallbackQuery#691e9052 flags:# query_id:long user_id:long msg_id:InputBotInlineMessageID chat_instance:long data:flags.0?bytes game_short_name:flags.1?string = Update;
 updateReadChannelOutbox#b75f99a9 channel_id:long max_id:int = Update;
-updateDraftMessage#ee2bb969 peer:Peer draft:DraftMessage = Update;
+updateDraftMessage#1b49ec6d flags:# peer:Peer top_msg_id:flags.0?int draft:DraftMessage = Update;
 updateReadFeaturedStickers#571d2742 = Update;
 updateRecentStickers#9a422c20 = Update;
 updateConfig#a229dd06 = Update;
@@ -327,7 +330,7 @@ updatePhoneCall#ab0f6b1e phone_call:PhoneCall = Update;
 updateLangPackTooLong#46560264 lang_code:string = Update;
 updateLangPack#56022f4d difference:LangPackDifference = Update;
 updateFavedStickers#e511996d = Update;
-updateChannelReadMessagesContents#44bdd535 channel_id:long messages:Vector = Update;
+updateChannelReadMessagesContents#ea29055d flags:# channel_id:long top_msg_id:flags.0?int messages:Vector = Update;
 updateContactsReset#7084a7be = Update;
 updateChannelAvailableMessages#b23fc698 channel_id:long available_min_id:int = Update;
 updateDialogUnreadMark#e16459c3 flags:# unread:flags.0?true peer:DialogPeer = Update;
@@ -364,7 +367,7 @@ updateGroupCallConnection#b783982 flags:# presentation:flags.0?true params:DataJ
 updateBotCommands#4d712f2e peer:Peer bot_id:long commands:Vector = Update;
 updatePendingJoinRequests#7063c3db peer:Peer requests_pending:int recent_requesters:Vector = Update;
 updateBotChatInviteRequester#11dfa986 peer:Peer date:int user_id:long about:string invite:ExportedChatInvite qts:int = Update;
-updateMessageReactions#154798c3 peer:Peer msg_id:int reactions:MessageReactions = Update;
+updateMessageReactions#5e1b3cb8 flags:# peer:Peer msg_id:int top_msg_id:flags.0?int reactions:MessageReactions = Update;
 updateAttachMenuBots#17b7a20b = Update;
 updateWebViewResultSent#1592b79d query_id:long = Update;
 updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update;
@@ -376,6 +379,7 @@ updateRecentEmojiStatuses#30f443db = Update;
 updateRecentReactions#6f7863f4 = Update;
 updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update;
 updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update;
+updateChannelPinnedTopic#f694b0ae flags:# channel_id:long topic_id:flags.0?int = Update;
 
 updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
 
@@ -448,6 +452,7 @@ notifyPeer#9fd40bd8 peer:Peer = NotifyPeer;
 notifyUsers#b4c83b4c = NotifyPeer;
 notifyChats#c007cec3 = NotifyPeer;
 notifyBroadcasts#d612e8ef = NotifyPeer;
+notifyForumTopic#226e6308 peer:Peer top_msg_id:int = NotifyPeer;
 
 sendMessageTypingAction#16bf744e = SendMessageAction;
 sendMessageCancelAction#fd5ec8f5 = SendMessageAction;
@@ -566,10 +571,11 @@ inputStickerSetAnimatedEmojiAnimations#cde3739 = InputStickerSet;
 inputStickerSetPremiumGifts#c88b3b02 = InputStickerSet;
 inputStickerSetEmojiGenericAnimations#4c4d4ce = InputStickerSet;
 inputStickerSetEmojiDefaultStatuses#29d0f5ee = InputStickerSet;
+inputStickerSetEmojiDefaultTopicIcons#44c1f8e9 = InputStickerSet;
 
 stickerSet#2dd14edc flags:# archived:flags.1?true official:flags.2?true masks:flags.3?true animated:flags.5?true videos:flags.6?true emojis:flags.7?true installed_date:flags.0?int id:long access_hash:long title:string short_name:string thumbs:flags.4?Vector thumb_dc_id:flags.4?int thumb_version:flags.4?int thumb_document_id:flags.8?long count:int hash:int = StickerSet;
 
-messages.stickerSet#b60a24a6 set:StickerSet packs:Vector documents:Vector = messages.StickerSet;
+messages.stickerSet#6e153f16 set:StickerSet packs:Vector keywords:Vector documents:Vector = messages.StickerSet;
 messages.stickerSetNotModified#d3f924eb = messages.StickerSet;
 
 botCommand#c27ac8c7 command:string description:string = BotCommand;
@@ -748,7 +754,7 @@ messages.stickerSetInstallResultArchive#35e410a8 sets:Vector
 
 stickerSetCovered#6410a5d2 set:StickerSet cover:Document = StickerSetCovered;
 stickerSetMultiCovered#3407e51b set:StickerSet covers:Vector = StickerSetCovered;
-stickerSetFullCovered#1aed5ee5 set:StickerSet packs:Vector documents:Vector = StickerSetCovered;
+stickerSetFullCovered#40d13c0e set:StickerSet packs:Vector keywords:Vector documents:Vector = StickerSetCovered;
 
 maskCoords#aed6dbb2 n:int x:double y:double zoom:double = MaskCoords;
 
@@ -930,12 +936,18 @@ channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatI
 channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
 channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction;
 channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions = ChannelAdminLogEventAction;
+channelAdminLogEventActionChangeUsernames#f04fb3a9 prev_value:Vector new_value:Vector = ChannelAdminLogEventAction;
+channelAdminLogEventActionToggleForum#2cc6383 new_value:Bool = ChannelAdminLogEventAction;
+channelAdminLogEventActionCreateTopic#58707d28 topic:ForumTopic = ChannelAdminLogEventAction;
+channelAdminLogEventActionEditTopic#f06fe208 prev_topic:ForumTopic new_topic:ForumTopic = ChannelAdminLogEventAction;
+channelAdminLogEventActionDeleteTopic#ae168909 topic:ForumTopic = ChannelAdminLogEventAction;
+channelAdminLogEventActionPinTopic#5d8d353b flags:# prev_topic:flags.0?ForumTopic new_topic:flags.1?ForumTopic = ChannelAdminLogEventAction;
 
 channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent;
 
 channels.adminLogResults#ed8af74d events:Vector chats:Vector users:Vector = channels.AdminLogResults;
 
-channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true group_call:flags.14?true invites:flags.15?true send:flags.16?true = ChannelAdminLogEventsFilter;
+channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true group_call:flags.14?true invites:flags.15?true send:flags.16?true forums:flags.17?true = ChannelAdminLogEventsFilter;
 
 popularContact#5ce14175 client_id:long importers:int = PopularContact;
 
@@ -1093,9 +1105,9 @@ chatOnlines#f041e250 onlines:int = ChatOnlines;
 
 statsURL#47a971e0 url:string = StatsURL;
 
-chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true manage_call:flags.11?true other:flags.12?true = ChatAdminRights;
+chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true manage_call:flags.11?true other:flags.12?true manage_topics:flags.13?true = ChatAdminRights;
 
-chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true until_date:int = ChatBannedRights;
+chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true manage_topics:flags.18?true until_date:int = ChatBannedRights;
 
 inputWallPaper#e630b979 id:long access_hash:long = InputWallPaper;
 inputWallPaperSlug#72091c80 slug:string = InputWallPaper;
@@ -1226,7 +1238,7 @@ messages.messageViews#b6c4f543 views:Vector chats:Vector use
 
 messages.discussionMessage#a6341782 flags:# messages:Vector max_id:flags.0?int read_inbox_max_id:flags.1?int read_outbox_max_id:flags.2?int unread_count:int chats:Vector users:Vector = messages.DiscussionMessage;
 
-messageReplyHeader#a6d57763 flags:# reply_to_scheduled:flags.2?true reply_to_msg_id:int reply_to_peer_id:flags.0?Peer reply_to_top_id:flags.1?int = MessageReplyHeader;
+messageReplyHeader#a6d57763 flags:# reply_to_scheduled:flags.2?true forum_topic:flags.3?true reply_to_msg_id:int reply_to_peer_id:flags.0?Peer reply_to_top_id:flags.1?int = MessageReplyHeader;
 
 messageReplies#83d60fc2 flags:# comments:flags.0?true replies:int replies_pts:int recent_repliers:flags.1?Vector channel_id:flags.0?long max_id:flags.2?int read_max_id:flags.3?int = MessageReplies;
 
@@ -1294,9 +1306,10 @@ account.resetPasswordFailedWait#e3779861 retry_date:int = account.ResetPasswordR
 account.resetPasswordRequestedWait#e9effc7d until_date:int = account.ResetPasswordResult;
 account.resetPasswordOk#e926d63e = account.ResetPasswordResult;
 
-sponsoredMessage#3a836df8 flags:# recommended:flags.5?true random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage;
+sponsoredMessage#3a836df8 flags:# recommended:flags.5?true show_peer_photo:flags.6?true random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage;
 
-messages.sponsoredMessages#65a4c7d5 messages:Vector chats:Vector users:Vector = messages.SponsoredMessages;
+messages.sponsoredMessages#c9ee1d87 flags:# posts_between:flags.0?int messages:Vector chats:Vector users:Vector = messages.SponsoredMessages;
+messages.sponsoredMessagesEmpty#1839490f = messages.SponsoredMessages;
 
 searchResultsCalendarPeriod#c9b0539f date:int min_msg_id:int max_msg_id:int count:int = SearchResultsCalendarPeriod;
 
@@ -1426,6 +1439,15 @@ sendAsPeer#b81c7034 flags:# premium_required:flags.0?true peer:Peer = SendAsPeer
 messageExtendedMediaPreview#ad628cc8 flags:# w:flags.0?int h:flags.0?int thumb:flags.1?PhotoSize video_duration:flags.2?int = MessageExtendedMedia;
 messageExtendedMedia#ee479c64 media:MessageMedia = MessageExtendedMedia;
 
+stickerKeyword#fcfeb29c document_id:long keyword:Vector = StickerKeyword;
+
+username#b4073647 flags:# editable:flags.0?true active:flags.1?true username:string = Username;
+
+forumTopicDeleted#23f109b id:int = ForumTopic;
+forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic;
+
+messages.forumTopics#367617d3 flags:# order_by_create_date:flags.0?true count:int topics:Vector messages:Vector chats:Vector users:Vector pts:int = messages.ForumTopics;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1516,7 +1538,7 @@ account.createTheme#652e4400 flags:# slug:string title:string document:flags.2?I
 account.updateTheme#2bf40ccc flags:# format:string theme:InputTheme slug:flags.0?string title:flags.1?string document:flags.2?InputDocument settings:flags.3?Vector = Theme;
 account.saveTheme#f257106c theme:InputTheme unsave:Bool = Bool;
 account.installTheme#c727bb3b flags:# dark:flags.0?true theme:flags.1?InputTheme format:flags.2?string base_theme:flags.3?BaseTheme = Bool;
-account.getTheme#8d9d742b format:string theme:InputTheme document_id:long = Theme;
+account.getTheme#3a5869ec format:string theme:InputTheme = Theme;
 account.getThemes#7206e458 format:string hash:long = account.Themes;
 account.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool;
 account.getContentSettings#8b9b4dae = account.ContentSettings;
@@ -1536,6 +1558,8 @@ account.updateEmojiStatus#fbd3de6b emoji_status:EmojiStatus = Bool;
 account.getDefaultEmojiStatuses#d6753386 hash:long = account.EmojiStatuses;
 account.getRecentEmojiStatuses#f578105 hash:long = account.EmojiStatuses;
 account.clearRecentEmojiStatuses#18201aae = Bool;
+account.reorderUsernames#ef500eab order:Vector = Bool;
+account.toggleUsername#58d6b376 username:string active:Bool = Bool;
 
 users.getUsers#d91a548 id:Vector = Vector;
 users.getFullUser#b60f5918 id:InputUser = users.UserFull;
@@ -1572,9 +1596,9 @@ messages.deleteHistory#b08f922a flags:# just_clear:flags.0?true revoke:flags.1?t
 messages.deleteMessages#e58e95d2 flags:# revoke:flags.0?true id:Vector = messages.AffectedMessages;
 messages.receivedMessages#5a954c0 max_id:int = Vector;
 messages.setTyping#58943ee2 flags:# peer:InputPeer top_msg_id:flags.0?int action:SendMessageAction = Bool;
-messages.sendMessage#d9d75a4 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
-messages.sendMedia#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
-messages.forwardMessages#cc30290b flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true drop_author:flags.11?true drop_media_captions:flags.12?true noforwards:flags.14?true from_peer:InputPeer id:Vector random_id:Vector to_peer:InputPeer schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMessage#1cc20387 flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int top_msg_id:flags.9?int message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMedia#7547c966 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int top_msg_id:flags.9?int media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.forwardMessages#c661bbc4 flags:# silent:flags.5?true background:flags.6?true with_my_score:flags.8?true drop_author:flags.11?true drop_media_captions:flags.12?true noforwards:flags.14?true from_peer:InputPeer id:Vector random_id:Vector to_peer:InputPeer top_msg_id:flags.9?int schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.reportSpam#cf1592db peer:InputPeer = Bool;
 messages.getPeerSettings#efd9a6a2 peer:InputPeer = messages.PeerSettings;
 messages.report#8953ab4e peer:InputPeer id:Vector reason:ReportReason message:string = Bool;
@@ -1617,14 +1641,14 @@ messages.getSavedGifs#5cf09635 hash:long = messages.SavedGifs;
 messages.saveGif#327a30cb id:InputDocument unsave:Bool = Bool;
 messages.getInlineBotResults#514e999d flags:# bot:InputUser peer:InputPeer geo_point:flags.0?InputGeoPoint query:string offset:string = messages.BotResults;
 messages.setInlineBotResults#eb5ea206 flags:# gallery:flags.0?true private:flags.1?true query_id:long results:Vector cache_time:int next_offset:flags.2?string switch_pm:flags.3?InlineBotSwitchPM = Bool;
-messages.sendInlineBotResult#7aa11297 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true hide_via:flags.11?true peer:InputPeer reply_to_msg_id:flags.0?int random_id:long query_id:long id:string schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendInlineBotResult#d3fbdccb flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true hide_via:flags.11?true peer:InputPeer reply_to_msg_id:flags.0?int top_msg_id:flags.9?int random_id:long query_id:long id:string schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.getMessageEditData#fda68d36 peer:InputPeer id:int = messages.MessageEditData;
 messages.editMessage#48f71778 flags:# no_webpage:flags.1?true peer:InputPeer id:int message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.15?int = Updates;
 messages.editInlineBotMessage#83557dba flags:# no_webpage:flags.1?true id:InputBotInlineMessageID message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector = Bool;
 messages.getBotCallbackAnswer#9342ca07 flags:# game:flags.1?true peer:InputPeer msg_id:int data:flags.0?bytes password:flags.2?InputCheckPasswordSRP = messages.BotCallbackAnswer;
 messages.setBotCallbackAnswer#d58f130a flags:# alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string cache_time:int = Bool;
 messages.getPeerDialogs#e470bcfd peers:Vector = messages.PeerDialogs;
-messages.saveDraft#bc39e14b flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int peer:InputPeer message:string entities:flags.3?Vector = Bool;
+messages.saveDraft#b4331e3f flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int top_msg_id:flags.2?int peer:InputPeer message:string entities:flags.3?Vector = Bool;
 messages.getAllDrafts#6a3f8d65 = Updates;
 messages.getFeaturedStickers#64780b14 hash:long = messages.FeaturedStickers;
 messages.readFeaturedStickers#5b118126 id:Vector = Bool;
@@ -1650,10 +1674,10 @@ messages.uploadMedia#519bc2b1 peer:InputPeer media:InputMedia = MessageMedia;
 messages.sendScreenshotNotification#c97df020 peer:InputPeer reply_to_msg_id:int random_id:long = Updates;
 messages.getFavedStickers#4f1aaa9 hash:long = messages.FavedStickers;
 messages.faveSticker#b9ffc55b id:InputDocument unfave:Bool = Bool;
-messages.getUnreadMentions#46578472 peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
-messages.readMentions#f0189d3 peer:InputPeer = messages.AffectedHistory;
+messages.getUnreadMentions#f107e790 flags:# peer:InputPeer top_msg_id:flags.0?int offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
+messages.readMentions#36e5bf4d flags:# peer:InputPeer top_msg_id:flags.0?int = messages.AffectedHistory;
 messages.getRecentLocations#702a40e0 peer:InputPeer limit:int hash:long = messages.Messages;
-messages.sendMultiMedia#f803138f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
+messages.sendMultiMedia#b6f11a1c flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int top_msg_id:flags.9?int multi_media:Vector schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates;
 messages.uploadEncryptedFile#5057c497 peer:InputEncryptedChat file:InputEncryptedFile = EncryptedFile;
 messages.searchStickerSets#35705b8a flags:# exclude_featured:flags.0?true q:string hash:long = messages.FoundStickerSets;
 messages.getSplitRanges#1cff7e08 = Vector;
@@ -1670,7 +1694,7 @@ messages.getEmojiKeywords#35a0e062 lang_code:string = EmojiKeywordsDifference;
 messages.getEmojiKeywordsDifference#1508b6af lang_code:string from_version:int = EmojiKeywordsDifference;
 messages.getEmojiKeywordsLanguages#4e9963b2 lang_codes:Vector = Vector;
 messages.getEmojiURL#d5b10c26 lang_code:string = EmojiURL;
-messages.getSearchCounters#732eef00 peer:InputPeer filters:Vector = Vector;
+messages.getSearchCounters#ae7cc1 flags:# peer:InputPeer top_msg_id:flags.0?int filters:Vector = Vector;
 messages.requestUrlAuth#198fb446 flags:# peer:flags.1?InputPeer msg_id:flags.1?int button_id:flags.1?int url:flags.2?string = UrlAuthResult;
 messages.acceptUrlAuth#b12c7125 flags:# write_allowed:flags.0?true peer:flags.1?InputPeer msg_id:flags.1?int button_id:flags.1?int url:flags.2?string = UrlAuthResult;
 messages.hidePeerSettingsBar#4facb138 peer:InputPeer = Bool;
@@ -1688,7 +1712,7 @@ messages.getOldFeaturedStickers#7ed094a1 offset:int limit:int hash:long = messag
 messages.getReplies#22ddd30c peer:InputPeer msg_id:int offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int hash:long = messages.Messages;
 messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage;
 messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool;
-messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory;
+messages.unpinAllMessages#ee22b9a8 flags:# peer:InputPeer top_msg_id:flags.0?int = messages.AffectedHistory;
 messages.deleteChat#5bd0ee50 chat_id:long = Bool;
 messages.deletePhoneCallHistory#f9cbe409 flags:# revoke:flags.0?true = messages.AffectedFoundMessages;
 messages.checkHistoryImport#43fe19f3 import_head:string = messages.HistoryImportParsed;
@@ -1719,14 +1743,14 @@ messages.setChatAvailableReactions#feb16771 peer:InputPeer available_reactions:C
 messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions;
 messages.setDefaultReaction#4f47a016 reaction:Reaction = Bool;
 messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?int text:flags.1?string from_lang:flags.2?string to_lang:string = messages.TranslatedText;
-messages.getUnreadReactions#e85bae1a peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
-messages.readReactions#82e251d7 peer:InputPeer = messages.AffectedHistory;
+messages.getUnreadReactions#3223495b flags:# peer:InputPeer top_msg_id:flags.0?int offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
+messages.readReactions#54aa7f8e flags:# peer:InputPeer top_msg_id:flags.0?int = messages.AffectedHistory;
 messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = messages.Messages;
 messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots;
 messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
 messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool;
-messages.requestWebView#fc87a53c flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON platform:string reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = WebViewResult;
-messages.prolongWebView#ea5fbcce flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = Bool;
+messages.requestWebView#178b480b flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON platform:string reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = WebViewResult;
+messages.prolongWebView#7ff34309 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = Bool;
 messages.requestSimpleWebView#299bec8e flags:# bot:InputUser url:string theme_params:flags.0?DataJSON platform:string = SimpleWebViewResult;
 messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
 messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates;
@@ -1824,6 +1848,16 @@ channels.getSendAs#dc770ee peer:InputPeer = channels.SendAsPeers;
 channels.deleteParticipantHistory#367544db channel:InputChannel participant:InputPeer = messages.AffectedHistory;
 channels.toggleJoinToSend#e4cb9580 channel:InputChannel enabled:Bool = Updates;
 channels.toggleJoinRequest#4c2985b6 channel:InputChannel enabled:Bool = Updates;
+channels.reorderUsernames#b45ced1d channel:InputChannel order:Vector = Bool;
+channels.toggleUsername#50f24105 channel:InputChannel username:string active:Bool = Bool;
+channels.deactivateAllUsernames#a245dd3 channel:InputChannel = Bool;
+channels.toggleForum#a4298b29 channel:InputChannel enabled:Bool = Updates;
+channels.createForumTopic#f40c0224 flags:# channel:InputChannel title:string icon_color:flags.0?int icon_emoji_id:flags.3?long random_id:long send_as:flags.2?InputPeer = Updates;
+channels.getForumTopics#de560d1 flags:# channel:InputChannel q:flags.0?string offset_date:int offset_id:int offset_topic:int limit:int = messages.ForumTopics;
+channels.getForumTopicsByID#b0831eb9 channel:InputChannel topics:Vector = messages.ForumTopics;
+channels.editForumTopic#6c883e2d flags:# channel:InputChannel topic_id:int title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = Updates;
+channels.updatePinnedForumTopic#6c2d9026 channel:InputChannel topic_id:int pinned:Bool = Updates;
+channels.deleteTopicHistory#34435f2d channel:InputChannel top_msg_id:int = messages.AffectedHistory;
 
 bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON;
 bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool;
@@ -1902,4 +1936,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 146
\ No newline at end of file
+// LAYER 148

From 035bbbb76eb2a6d58d7e909e97a01660e2c62852 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 13 Nov 2022 14:13:22 +0100
Subject: [PATCH 404/539] Update python.yml

---
 .github/workflows/python.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml
index 9d25f33f7b..e12233fb20 100644
--- a/.github/workflows/python.yml
+++ b/.github/workflows/python.yml
@@ -9,10 +9,10 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, macos-latest]
-        python-version: ["3.7", "3.8", "3.9", "3.10"]
+        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
 
       - name: Set up Python ${{ matrix.python-version }}
         uses: actions/setup-python@v2

From b423730dcbd59d650362ade56457e156805b1c2b Mon Sep 17 00:00:00 2001
From: Sam <100821827+01101sam@users.noreply.github.com>
Date: Sun, 13 Nov 2022 21:18:42 +0800
Subject: [PATCH 405/539] Fix on_disconnect decorator not working (#1134)

* Fix on_disconnect decorator not working

* Remove useless if else statment in on_raw_update
---
 pyrogram/methods/decorators/on_disconnect.py | 5 +++++
 pyrogram/methods/decorators/on_raw_update.py | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/pyrogram/methods/decorators/on_disconnect.py b/pyrogram/methods/decorators/on_disconnect.py
index ae54800f86..26aa62f8fb 100644
--- a/pyrogram/methods/decorators/on_disconnect.py
+++ b/pyrogram/methods/decorators/on_disconnect.py
@@ -32,6 +32,11 @@ def on_disconnect(self=None) -> Callable:
         def decorator(func: Callable) -> Callable:
             if isinstance(self, pyrogram.Client):
                 self.add_handler(pyrogram.handlers.DisconnectHandler(func))
+            else:
+                if not hasattr(func, "handlers"):
+                    func.handlers = []
+
+                func.handlers.append((pyrogram.handlers.DisconnectHandler(func), 0))
 
             return func
 
diff --git a/pyrogram/methods/decorators/on_raw_update.py b/pyrogram/methods/decorators/on_raw_update.py
index dffc50b924..644bc8a5b9 100644
--- a/pyrogram/methods/decorators/on_raw_update.py
+++ b/pyrogram/methods/decorators/on_raw_update.py
@@ -46,7 +46,7 @@ def decorator(func: Callable) -> Callable:
                 func.handlers.append(
                     (
                         pyrogram.handlers.RawUpdateHandler(func),
-                        group if self is None else group
+                        group
                     )
                 )
 

From c98963973ee38100e482ec28e231124275ebd342 Mon Sep 17 00:00:00 2001
From: Ihor Boichuk <107807464+IhorBoichuk@users.noreply.github.com>
Date: Sun, 13 Nov 2022 15:22:12 +0200
Subject: [PATCH 406/539] Add Message.forwards field (#1103)

* Added missing field: forwards

* Update message.py

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/types/messages_and_media/message.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index c49fd0f6c7..5ea1584d80 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -254,6 +254,9 @@ class Message(Object, Update):
 
         views (``int``, *optional*):
             Channel post views.
+	    
+	forwards (``int``, *optional*):
+            Channel post forwards.
 
         via_bot (:obj:`~pyrogram.types.User`):
             The information of the bot that generated the message from an inline query of a user.
@@ -361,6 +364,7 @@ def __init__(
         pinned_message: "Message" = None,
         game_high_score: int = None,
         views: int = None,
+	forwards: int = None,
         via_bot: "types.User" = None,
         outgoing: bool = None,
         matches: List[Match] = None,
@@ -436,6 +440,7 @@ def __init__(
         self.pinned_message = pinned_message
         self.game_high_score = game_high_score
         self.views = views
+        self.forwards = forwards
         self.via_bot = via_bot
         self.outgoing = outgoing
         self.matches = matches
@@ -800,6 +805,7 @@ async def _parse(
                 poll=poll,
                 dice=dice,
                 views=message.views,
+                forwards=message.forwards,
                 via_bot=types.User._parse(client, users.get(message.via_bot_id, None)),
                 outgoing=message.out,
                 reply_markup=reply_markup,

From 1b02a6a148fc87009bd6e60d9a0cf842543a6096 Mon Sep 17 00:00:00 2001
From: Albert Einstein <73480087+AlbertEinsteinTG@users.noreply.github.com>
Date: Sun, 13 Nov 2022 18:53:30 +0530
Subject: [PATCH 407/539] Add __all__ for better enums suggestions (#1126)

---
 pyrogram/enums/__init__.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py
index f847b3cf57..d19c7044ff 100644
--- a/pyrogram/enums/__init__.py
+++ b/pyrogram/enums/__init__.py
@@ -30,3 +30,20 @@
 from .poll_type import PollType
 from .sent_code_type import SentCodeType
 from .user_status import UserStatus
+
+__all__ = [
+    'ChatAction', 
+    'ChatEventAction', 
+    'ChatMemberStatus', 
+    'ChatMembersFilter', 
+    'ChatType', 
+    'MessageEntityType', 
+    'MessageMediaType', 
+    'MessageServiceType', 
+    'MessagesFilter', 
+    'NextCodeType', 
+    'ParseMode', 
+    'PollType', 
+    'SentCodeType', 
+    'UserStatus'
+]

From b848e052254e9f23a4e52b2f87b794f26cb42cd8 Mon Sep 17 00:00:00 2001
From: Artem Kvrvgv <50778263+kvrvgv@users.noreply.github.com>
Date: Sun, 13 Nov 2022 16:25:19 +0300
Subject: [PATCH 408/539] Fix copy_message return type hint (#1128)

* fixed copy_message method type-hint

* Update copy_message.py

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/methods/messages/copy_message.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py
index 66b7e37cb3..0b6624b28d 100644
--- a/pyrogram/methods/messages/copy_message.py
+++ b/pyrogram/methods/messages/copy_message.py
@@ -45,7 +45,7 @@ async def copy_message(
             "types.ReplyKeyboardRemove",
             "types.ForceReply"
         ] = None
-    ) -> List["types.Message"]:
+    ) -> "types.Message":
         """Copy messages of any kind.
 
         The method is analogous to the method :meth:`~Client.forward_messages`, but the copied message doesn't have a

From 31b32184c927a4793bb5222624394e735b6722f8 Mon Sep 17 00:00:00 2001
From: "ALi.w" 
Date: Sun, 13 Nov 2022 16:57:19 +0330
Subject: [PATCH 409/539] Use getattr to get outgoing attribute in filters.me
 (#1137)

* Use getattr to get outgoing attribute from the message in me_filter.
Fixes #1136.

Signed-off-by: Aliwoto 

* Update filters.py

Signed-off-by: Aliwoto 
Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
---
 pyrogram/filters.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/filters.py b/pyrogram/filters.py
index f31b385ed4..ac2dbf20fd 100644
--- a/pyrogram/filters.py
+++ b/pyrogram/filters.py
@@ -164,7 +164,7 @@ async def all_filter(_, __, ___):
 
 # region me_filter
 async def me_filter(_, __, m: Message):
-    return bool(m.from_user and m.from_user.is_self or m.outgoing)
+    return bool(m.from_user and m.from_user.is_self or getattr(m, "outgoing", False))
 
 
 me = create(me_filter)

From 0e64ebc0be1f84a8afd02a8a2c984df802faab3d Mon Sep 17 00:00:00 2001
From: Deekshith SH 
Date: Sun, 13 Nov 2022 18:58:18 +0530
Subject: [PATCH 410/539] Fix typo (#1029)

---
 pyrogram/methods/contacts/delete_contacts.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/methods/contacts/delete_contacts.py b/pyrogram/methods/contacts/delete_contacts.py
index b4b2c628a3..7f08f29730 100644
--- a/pyrogram/methods/contacts/delete_contacts.py
+++ b/pyrogram/methods/contacts/delete_contacts.py
@@ -33,7 +33,7 @@ async def delete_contacts(
 
         Parameters:
             user_ids (``int`` | ``str`` | List of ``int`` or ``str``):
-                A single user id/username o a list of user identifiers (id or username).
+                A single user id/username or a list of user identifiers (id or username).
 
         Returns:
             :obj:`~pyrogram.types.User` | List of :obj:`~pyrogram.types.User` | ``None``: In case *user_ids* was an

From 23d953237e448c803a83e1cc3282041ac80acfc5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 13 Nov 2022 14:29:06 +0100
Subject: [PATCH 411/539] Update Pyrogram to v2.0.60

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 924bb27644..c5ad84d488 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.59"
+__version__ = "2.0.60"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 1699ef0d4c6ed9f3e986e703de6680107e4e0bc0 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 15 Nov 2022 11:13:53 +0100
Subject: [PATCH 412/539] Disable parse mode when copying messages The entities
 are already taken from the original message

---
 pyrogram/types/messages_and_media/message.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index 5ea1584d80..eb9d654f47 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -3057,6 +3057,7 @@ async def copy(
                 chat_id,
                 text=self.text,
                 entities=self.entities,
+                parse_mode=enums.ParseMode.DISABLED,
                 disable_web_page_preview=not self.web_page,
                 disable_notification=disable_notification,
                 reply_to_message_id=reply_to_message_id,

From e3e9731973952952b854676819c1b99e7858e910 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 15 Nov 2022 11:15:05 +0100
Subject: [PATCH 413/539] Update Pyrogram to v2.0.61

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index c5ad84d488..e2fd5d3d59 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.60"
+__version__ = "2.0.61"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 2aae10193e9f792b39edaa88a99bde92bf499cf5 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 18 Nov 2022 12:14:31 +0100
Subject: [PATCH 414/539] Add tag command to Makefile

---
 Makefile | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 81dfe6c901..930d3be406 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
 VENV := venv
 PYTHON := $(VENV)/bin/python
 HOST = $(shell ifconfig | grep "inet " | tail -1 | cut -d\  -f2)
+TAG = v$(shell grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2)
 
 RM := rm -rf
 
@@ -30,4 +31,12 @@ api:
 build:
 	make clean
 	$(PYTHON) setup.py sdist
-	$(PYTHON) setup.py bdist_wheel
\ No newline at end of file
+	$(PYTHON) setup.py bdist_wheel
+
+tag:
+	git tag $(TAG)
+	git push origin $(TAG)
+
+dtag:
+	git tag -d $(TAG)
+	git push origin -d $(TAG)
\ No newline at end of file

From 9b6cb070b98c3a117dc5ce1db1c973048496aec4 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 18 Nov 2022 12:14:49 +0100
Subject: [PATCH 415/539] Update Pyrogram to v2.0.62

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index e2fd5d3d59..026fb9512c 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.61"
+__version__ = "2.0.62"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From b81c379548c9c08218f1d8c5d3e24d6fc9bc2031 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 25 Nov 2022 22:11:35 +0100
Subject: [PATCH 416/539] Update API schema to Layer 149

---
 compiler/api/source/main_api.tl | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index e89ef9ff49..e83a3b5ad5 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -244,7 +244,7 @@ messages.dialogsNotModified#f0e3e596 count:int = messages.Dialogs;
 
 messages.messages#8c718e87 messages:Vector chats:Vector users:Vector = messages.Messages;
 messages.messagesSlice#3a54685e flags:# inexact:flags.1?true count:int next_rate:flags.0?int offset_id_offset:flags.2?int messages:Vector chats:Vector users:Vector = messages.Messages;
-messages.channelMessages#64479808 flags:# inexact:flags.1?true pts:int count:int offset_id_offset:flags.2?int messages:Vector chats:Vector users:Vector = messages.Messages;
+messages.channelMessages#c776ba4e flags:# inexact:flags.1?true pts:int count:int offset_id_offset:flags.2?int messages:Vector topics:Vector chats:Vector users:Vector = messages.Messages;
 messages.messagesNotModified#74535f21 count:int = messages.Messages;
 
 messages.chats#64ff9fd5 chats:Vector = messages.Chats;
@@ -379,7 +379,8 @@ updateRecentEmojiStatuses#30f443db = Update;
 updateRecentReactions#6f7863f4 = Update;
 updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update;
 updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update;
-updateChannelPinnedTopic#f694b0ae flags:# channel_id:long topic_id:flags.0?int = Update;
+updateChannelPinnedTopic#192efbe3 flags:# pinned:flags.0?true channel_id:long topic_id:int = Update;
+updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector = Update;
 
 updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
 
@@ -1444,7 +1445,7 @@ stickerKeyword#fcfeb29c document_id:long keyword:Vector = StickerKeyword
 username#b4073647 flags:# editable:flags.0?true active:flags.1?true username:string = Username;
 
 forumTopicDeleted#23f109b id:int = ForumTopic;
-forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic;
+forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true short:flags.5?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic;
 
 messages.forumTopics#367617d3 flags:# order_by_create_date:flags.0?true count:int topics:Vector messages:Vector chats:Vector users:Vector pts:int = messages.ForumTopics;
 
@@ -1858,6 +1859,7 @@ channels.getForumTopicsByID#b0831eb9 channel:InputChannel topics:Vector = m
 channels.editForumTopic#6c883e2d flags:# channel:InputChannel topic_id:int title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = Updates;
 channels.updatePinnedForumTopic#6c2d9026 channel:InputChannel topic_id:int pinned:Bool = Updates;
 channels.deleteTopicHistory#34435f2d channel:InputChannel top_msg_id:int = messages.AffectedHistory;
+channels.reorderPinnedForumTopics#2950a18f flags:# force:flags.0?true channel:InputChannel order:Vector = Updates;
 
 bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON;
 bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool;
@@ -1936,4 +1938,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 148
+// LAYER 149
\ No newline at end of file

From 70b673890837749c06e7cd170d934bf9eda75e6b Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 25 Nov 2022 22:11:57 +0100
Subject: [PATCH 417/539] Update Pyrogram to v2.0.63

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 026fb9512c..aeb70a9a71 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.62"
+__version__ = "2.0.63"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 1d7852a44b6e60e42aab85afd8977a1ee9dcd88f Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 13:59:06 +0100
Subject: [PATCH 418/539] Update API schema to Layer 150

---
 compiler/api/source/main_api.tl | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl
index e83a3b5ad5..e4f1ac0e9c 100644
--- a/compiler/api/source/main_api.tl
+++ b/compiler/api/source/main_api.tl
@@ -107,7 +107,7 @@ channel#83259464 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.
 channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat;
 
 chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull;
-channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull;
+channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull;
 
 chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant;
 chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant;
@@ -163,7 +163,7 @@ messageActionContactSignUp#f3f25f76 = MessageAction;
 messageActionGeoProximityReached#98e0d697 from_id:Peer to_id:Peer distance:int = MessageAction;
 messageActionGroupCall#7a0d7f42 flags:# call:InputGroupCall duration:flags.0?int = MessageAction;
 messageActionInviteToGroupCall#502f92f7 call:InputGroupCall users:Vector = MessageAction;
-messageActionSetMessagesTTL#aa1afbfd period:int = MessageAction;
+messageActionSetMessagesTTL#3c134d7b flags:# period:int auto_setting_from:flags.0?long = MessageAction;
 messageActionGroupCallScheduled#b3a07661 call:InputGroupCall schedule_date:int = MessageAction;
 messageActionSetChatTheme#aa786345 emoticon:string = MessageAction;
 messageActionChatJoinedByRequest#ebbca3cb = MessageAction;
@@ -171,9 +171,9 @@ messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction;
 messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction;
 messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = MessageAction;
 messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction;
-messageActionTopicEdit#b18a431c flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = MessageAction;
+messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction;
 
-dialog#a8edd0f5 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
+dialog#d58a08c6 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog;
 dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
 
 photoEmpty#2331b22d id:long = Photo;
@@ -702,6 +702,7 @@ auth.codeTypeSms#72a3158c = auth.CodeType;
 auth.codeTypeCall#741cd3e3 = auth.CodeType;
 auth.codeTypeFlashCall#226ccefb = auth.CodeType;
 auth.codeTypeMissedCall#d61ad6ee = auth.CodeType;
+auth.codeTypeFragmentSms#6ed998c = auth.CodeType;
 
 auth.sentCodeTypeApp#3dbb5986 length:int = auth.SentCodeType;
 auth.sentCodeTypeSms#c000bba2 length:int = auth.SentCodeType;
@@ -710,6 +711,7 @@ auth.sentCodeTypeFlashCall#ab03c6d9 pattern:string = auth.SentCodeType;
 auth.sentCodeTypeMissedCall#82006484 prefix:string length:int = auth.SentCodeType;
 auth.sentCodeTypeEmailCode#5a159841 flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int next_phone_login_date:flags.2?int = auth.SentCodeType;
 auth.sentCodeTypeSetUpEmailRequired#a5491dea flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true = auth.SentCodeType;
+auth.sentCodeTypeFragmentSms#d9565c39 url:string length:int = auth.SentCodeType;
 
 messages.botCallbackAnswer#36585ea4 flags:# alert:flags.1?true has_url:flags.3?true native_ui:flags.4?true message:flags.0?string url:flags.2?string cache_time:int = messages.BotCallbackAnswer;
 
@@ -943,6 +945,7 @@ channelAdminLogEventActionCreateTopic#58707d28 topic:ForumTopic = ChannelAdminLo
 channelAdminLogEventActionEditTopic#f06fe208 prev_topic:ForumTopic new_topic:ForumTopic = ChannelAdminLogEventAction;
 channelAdminLogEventActionDeleteTopic#ae168909 topic:ForumTopic = ChannelAdminLogEventAction;
 channelAdminLogEventActionPinTopic#5d8d353b flags:# prev_topic:flags.0?ForumTopic new_topic:flags.1?ForumTopic = ChannelAdminLogEventAction;
+channelAdminLogEventActionToggleAntiSpam#64f36dfc new_value:Bool = ChannelAdminLogEventAction;
 
 channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent;
 
@@ -1445,10 +1448,14 @@ stickerKeyword#fcfeb29c document_id:long keyword:Vector = StickerKeyword
 username#b4073647 flags:# editable:flags.0?true active:flags.1?true username:string = Username;
 
 forumTopicDeleted#23f109b id:int = ForumTopic;
-forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true short:flags.5?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic;
+forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true short:flags.5?true hidden:flags.6?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic;
 
 messages.forumTopics#367617d3 flags:# order_by_create_date:flags.0?true count:int topics:Vector messages:Vector chats:Vector users:Vector pts:int = messages.ForumTopics;
 
+defaultHistoryTTL#43b46b20 period:int = DefaultHistoryTTL;
+
+exportedContactToken#41bf109b url:string expires:int = ExportedContactToken;
+
 ---functions---
 
 invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1478,6 +1485,7 @@ auth.exportLoginToken#b7e085fe api_id:int api_hash:string except_ids:Vector = Bool;
 account.unregisterDevice#6a0d3206 token_type:int token:string other_uids:Vector = Bool;
@@ -1587,6 +1595,8 @@ contacts.acceptContact#f831a20f id:InputUser = Updates;
 contacts.getLocated#d348bc44 flags:# background:flags.1?true geo_point:InputGeoPoint self_expires:flags.0?int = Updates;
 contacts.blockFromReplies#29a8962c flags:# delete_message:flags.0?true delete_history:flags.1?true report_spam:flags.2?true msg_id:int = Updates;
 contacts.resolvePhone#8af94344 phone:string = contacts.ResolvedPeer;
+contacts.exportContactToken#f8654027 = ExportedContactToken;
+contacts.importContactToken#13005788 token:string = User;
 
 messages.getMessages#63c66506 id:Vector = messages.Messages;
 messages.getDialogs#a0f4cb4f flags:# exclude_pinned:flags.0?true folder_id:flags.1?int offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:long = messages.Dialogs;
@@ -1609,7 +1619,7 @@ messages.editChatTitle#73783ffd chat_id:long title:string = Updates;
 messages.editChatPhoto#35ddd674 chat_id:long photo:InputChatPhoto = Updates;
 messages.addChatUser#f24753e3 chat_id:long user_id:InputUser fwd_limit:int = Updates;
 messages.deleteChatUser#a2185cab flags:# revoke_history:flags.0?true chat_id:long user_id:InputUser = Updates;
-messages.createChat#9cb126e users:Vector title:string = Updates;
+messages.createChat#34a818 flags:# users:Vector title:string ttl_period:flags.0?int = Updates;
 messages.getDhConfig#26cf8950 version:int random_length:int = messages.DhConfig;
 messages.requestEncryption#f64daf43 user_id:InputUser random_id:int g_a:bytes = EncryptedChat;
 messages.acceptEncryption#3dbc0415 peer:InputEncryptedChat g_b:bytes key_fingerprint:long = EncryptedChat;
@@ -1765,6 +1775,8 @@ messages.getTopReactions#bb8125ba limit:int hash:long = messages.Reactions;
 messages.getRecentReactions#39461db2 limit:int hash:long = messages.Reactions;
 messages.clearRecentReactions#9dfeefb4 = Bool;
 messages.getExtendedMedia#84f80814 peer:InputPeer id:Vector = Updates;
+messages.setDefaultHistoryTTL#9eb51445 period:int = Bool;
+messages.getDefaultHistoryTTL#658b7188 = DefaultHistoryTTL;
 
 updates.getState#edd4882a = updates.State;
 updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1816,7 +1828,7 @@ channels.getParticipants#77ced9d0 channel:InputChannel filter:ChannelParticipant
 channels.getParticipant#a0ab6cc6 channel:InputChannel participant:InputPeer = channels.ChannelParticipant;
 channels.getChannels#a7f6bbb id:Vector = messages.Chats;
 channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull;
-channels.createChannel#3d5fb10f flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string = Updates;
+channels.createChannel#91006707 flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string ttl_period:flags.4?int = Updates;
 channels.editAdmin#d33c8902 channel:InputChannel user_id:InputUser admin_rights:ChatAdminRights rank:string = Updates;
 channels.editTitle#566decd0 channel:InputChannel title:string = Updates;
 channels.editPhoto#f12e57c9 channel:InputChannel photo:InputChatPhoto = Updates;
@@ -1856,10 +1868,12 @@ channels.toggleForum#a4298b29 channel:InputChannel enabled:Bool = Updates;
 channels.createForumTopic#f40c0224 flags:# channel:InputChannel title:string icon_color:flags.0?int icon_emoji_id:flags.3?long random_id:long send_as:flags.2?InputPeer = Updates;
 channels.getForumTopics#de560d1 flags:# channel:InputChannel q:flags.0?string offset_date:int offset_id:int offset_topic:int limit:int = messages.ForumTopics;
 channels.getForumTopicsByID#b0831eb9 channel:InputChannel topics:Vector = messages.ForumTopics;
-channels.editForumTopic#6c883e2d flags:# channel:InputChannel topic_id:int title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = Updates;
+channels.editForumTopic#f4dfa185 flags:# channel:InputChannel topic_id:int title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = Updates;
 channels.updatePinnedForumTopic#6c2d9026 channel:InputChannel topic_id:int pinned:Bool = Updates;
 channels.deleteTopicHistory#34435f2d channel:InputChannel top_msg_id:int = messages.AffectedHistory;
 channels.reorderPinnedForumTopics#2950a18f flags:# force:flags.0?true channel:InputChannel order:Vector = Updates;
+channels.toggleAntiSpam#68f3e4eb channel:InputChannel enabled:Bool = Updates;
+channels.reportAntiSpamFalsePositive#a850a693 channel:InputChannel msg_id:int = Bool;
 
 bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON;
 bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool;
@@ -1938,4 +1952,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
 stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
 stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
 
-// LAYER 149
\ No newline at end of file
+// LAYER 150
\ No newline at end of file

From fb85a142775b3163af4a3005bb9b5848c4c4ab01 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 14:15:46 +0100
Subject: [PATCH 419/539] Update Pyrogram to v2.0.64

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index aeb70a9a71..f860e0cd58 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.63"
+__version__ = "2.0.64"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From d734fbb180f4e8d080ef008cdd575b150c893891 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 18:08:38 +0100
Subject: [PATCH 420/539] Fix User.emoji_status type hint

---
 pyrogram/types/user_and_chats/user.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py
index 2c9b58f8b6..e981357826 100644
--- a/pyrogram/types/user_and_chats/user.py
+++ b/pyrogram/types/user_and_chats/user.py
@@ -170,7 +170,7 @@ def __init__(
         next_offline_date: datetime = None,
         username: str = None,
         language_code: str = None,
-        emoji_status: Optional[str] = None,
+        emoji_status: Optional["types.EmojiStatus"] = None,
         dc_id: int = None,
         phone_number: str = None,
         photo: "types.ChatPhoto" = None,

From 3cf1ac7d92377372cd16bb54f2dd2ea789118c51 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 18:09:42 +0100
Subject: [PATCH 421/539] Update the order in which media messages are parsed

---
 pyrogram/types/messages_and_media/message.py | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py
index eb9d654f47..d844b06054 100644
--- a/pyrogram/types/messages_and_media/message.py
+++ b/pyrogram/types/messages_and_media/message.py
@@ -364,7 +364,7 @@ def __init__(
         pinned_message: "Message" = None,
         game_high_score: int = None,
         views: int = None,
-	forwards: int = None,
+        forwards: int = None,
         via_bot: "types.User" = None,
         outgoing: bool = None,
         matches: List[Match] = None,
@@ -687,16 +687,7 @@ async def _parse(
                             ), "file_name", None
                         )
 
-                        if raw.types.DocumentAttributeAudio in attributes:
-                            audio_attributes = attributes[raw.types.DocumentAttributeAudio]
-
-                            if audio_attributes.voice:
-                                voice = types.Voice._parse(client, doc, audio_attributes)
-                                media_type = enums.MessageMediaType.VOICE
-                            else:
-                                audio = types.Audio._parse(client, doc, audio_attributes, file_name)
-                                media_type = enums.MessageMediaType.AUDIO
-                        elif raw.types.DocumentAttributeAnimated in attributes:
+                        if raw.types.DocumentAttributeAnimated in attributes:
                             video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
                             animation = types.Animation._parse(client, doc, video_attributes, file_name)
                             media_type = enums.MessageMediaType.ANIMATION
@@ -712,6 +703,15 @@ async def _parse(
                             else:
                                 video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
                                 media_type = enums.MessageMediaType.VIDEO
+                        elif raw.types.DocumentAttributeAudio in attributes:
+                            audio_attributes = attributes[raw.types.DocumentAttributeAudio]
+
+                            if audio_attributes.voice:
+                                voice = types.Voice._parse(client, doc, audio_attributes)
+                                media_type = enums.MessageMediaType.VOICE
+                            else:
+                                audio = types.Audio._parse(client, doc, audio_attributes, file_name)
+                                media_type = enums.MessageMediaType.AUDIO
                         else:
                             document = types.Document._parse(client, doc, file_name)
                             media_type = enums.MessageMediaType.DOCUMENT

From ad773455a74ef6db7c1752734b6fe9b6647870c6 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 18:10:36 +0100
Subject: [PATCH 422/539] Update Pyrogram to v2.0.65

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index f860e0cd58..a7c9049bf8 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.64"
+__version__ = "2.0.65"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From 2ed000381d60bf8da9b0bec57693425b24b50c9d Mon Sep 17 00:00:00 2001
From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com>
Date: Tue, 6 Dec 2022 18:29:27 +0100
Subject: [PATCH 423/539] Update the HTML logic to output well-formed elements
 (#1155)

* unparsing html entities with deque

* unparsing using a stack (recursive)
---
 pyrogram/parser/html.py | 55 ++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 17 deletions(-)

diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index 7ed2a5be10..4afeea2bd9 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -155,11 +155,10 @@ async def parse(self, text: str):
 
     @staticmethod
     def unparse(text: str, entities: list):
-        text = utils.add_surrogates(text)
-
-        entities_offsets = []
-
-        for entity in entities:
+        def parse_one(entity):
+            """
+            Parses a single entity and returns (start_tag, start), (end_tag, end)
+            """
             entity_type = entity.type
             start = entity.offset
             end = start + entity.length
@@ -199,21 +198,43 @@ def unparse(text: str, entities: list):
                 start_tag = f''
                 end_tag = ""
             else:
-                continue
+                return
+
+            return (start_tag, start), (end_tag, end)
+
+        def recursive(entity_i: int) -> int:
+            """
+            Takes the index of the entity to start parsing from, returns the number of parsed entities inside it.
+            Uses entities_offsets as a stack, pushing (start_tag, start) first, then parsing nested entities,
+            and finally pushing (end_tag, end) to the stack.
+            No need to sort at the end.
+            """
+            this = parse_one(entities[entity_i])
+            if this is None:
+                return 1
+            (start_tag, start), (end_tag, end) = this
+            entities_offsets.append((start_tag, start))
+            internal_i = entity_i + 1
+            # while the next entity is inside the current one, keep parsing
+            while internal_i < len(entities) and entities[internal_i].offset < end:
+                internal_i += recursive(internal_i)
+            entities_offsets.append((end_tag, end))
+            return internal_i - entity_i
+
+        text = utils.add_surrogates(text)
+
+        entities_offsets = []
 
-            entities_offsets.append((start_tag, start,))
-            entities_offsets.append((end_tag, end,))
+        # probably useless because entities are already sorted by telegram
+        entities.sort(key=lambda e: (e.offset, -e.length))
 
-        entities_offsets = map(
-            lambda x: x[1],
-            sorted(
-                enumerate(entities_offsets),
-                key=lambda x: (x[1][1], x[0]),
-                reverse=True
-            )
-        )
+        # main loop for first-level entities
+        i = 0
+        while i < len(entities):
+            i += recursive(i)
 
-        for entity, offset in entities_offsets:
+        # no need to sort, but still add entities starting from the end
+        for entity, offset in reversed(entities_offsets):
             text = text[:offset] + entity + text[offset:]
 
         return utils.remove_surrogates(text)

From 38e9745a80a5b5adc47bc8525648fd87cc73ead8 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 18:50:43 +0100
Subject: [PATCH 424/539] Update Pyrogram to v2.0.66

---
 pyrogram/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index a7c9049bf8..11a2359e9a 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -16,7 +16,7 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see .
 
-__version__ = "2.0.65"
+__version__ = "2.0.66"
 __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
 __copyright__ = "Copyright (C) 2017-present Dan "
 

From db6bc2df1913d2c844537a8b9669d8e21c855f48 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Tue, 6 Dec 2022 19:11:23 +0100
Subject: [PATCH 425/539] Add tests for HTML.unparse

---
 tests/parser/__init__.py  |  17 ++++++
 tests/parser/test_html.py | 120 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+)
 create mode 100644 tests/parser/__init__.py
 create mode 100644 tests/parser/test_html.py

diff --git a/tests/parser/__init__.py b/tests/parser/__init__.py
new file mode 100644
index 0000000000..46887cb7a5
--- /dev/null
+++ b/tests/parser/__init__.py
@@ -0,0 +1,17 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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 .
diff --git a/tests/parser/test_html.py b/tests/parser/test_html.py
new file mode 100644
index 0000000000..170b9031bd
--- /dev/null
+++ b/tests/parser/test_html.py
@@ -0,0 +1,120 @@
+#  Pyrogram - Telegram MTProto API Client Library for Python
+#  Copyright (C) 2017-present Dan 
+#
+#  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.parser.html import HTML
+
+
+# expected: the expected unparsed HTML
+# text: original text without entities
+# entities: message entities coming from the server
+
+def test_html_unparse_bold():
+    expected = "bold"
+    text = "bold"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.BOLD, offset=0, length=4)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_italic():
+    expected = "italic"
+    text = "italic"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.ITALIC, offset=0, length=6)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_underline():
+    expected = "underline"
+    text = "underline"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=0, length=9)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_strike():
+    expected = "strike"
+    text = "strike"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.STRIKETHROUGH, offset=0, length=6)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_spoiler():
+    expected = "spoiler"
+    text = "spoiler"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.SPOILER, offset=0, length=7)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_url():
+    expected = 'URL'
+    text = "URL"
+    entities = pyrogram.types.List([pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.TEXT_LINK,
+                                                                 offset=0, length=3, url='https://pyrogram.org/')])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_code():
+    expected = 'code'
+    text = "code"
+    entities = pyrogram.types.List(
+        [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.CODE, offset=0, length=4)])
+
+    assert HTML.unparse(text=text, entities=entities) == expected
+
+
+def test_html_unparse_pre():
+    expected = """
for i in range(10):
+    print(i)
""" + + text = """for i in range(10): + print(i)""" + + entities = pyrogram.types.List([pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.PRE, offset=0, + length=32, language='python')]) + + assert HTML.unparse(text=text, entities=entities) == expected + + +def test_html_unparse_mixed(): + expected = "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd" \ + "eeeeeeeeeeffffffffffgggggggggghhhhhhhhhh" + text = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhh" + entities = pyrogram.types.List( + [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.BOLD, offset=0, length=14), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.ITALIC, offset=7, length=7), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=10, length=4), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=14, length=9), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.ITALIC, offset=14, length=9), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=23, length=10), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.STRIKETHROUGH, offset=30, length=3), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.STRIKETHROUGH, offset=33, length=10), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.SPOILER, offset=38, length=5), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.SPOILER, offset=43, length=10), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.CODE, offset=57, length=10)]) + + assert HTML.unparse(text=text, entities=entities) == expected From fd2819ca7f581f0ed3bbad6873aeb27a233272fd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:11:47 +0100 Subject: [PATCH 426/539] Update Pyrogram to v2.0.67 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 11a2359e9a..ffb70e5c12 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.66" +__version__ = "2.0.67" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 669b39927b7fb48bd7464fc2bb7497ed8c75efb6 Mon Sep 17 00:00:00 2001 From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:09:31 +0100 Subject: [PATCH 427/539] Escape text inside entity when building unparsed text (#1156) --- pyrogram/parser/html.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 4afeea2bd9..c574e6ffb1 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -233,8 +233,10 @@ def recursive(entity_i: int) -> int: while i < len(entities): i += recursive(i) + last_offset = entities_offsets[-1][1] # no need to sort, but still add entities starting from the end for entity, offset in reversed(entities_offsets): - text = text[:offset] + entity + text[offset:] + text = text[:offset] + entity + html.escape(text[offset:last_offset]) + text[last_offset:] + last_offset = offset return utils.remove_surrogates(text) From 7090dcba6807f9594d065514ced1ee2f89cf65be Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:12:27 +0100 Subject: [PATCH 428/539] Add more tests for HTML.unparse --- tests/parser/test_html.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/parser/test_html.py b/tests/parser/test_html.py index 170b9031bd..0027290561 100644 --- a/tests/parser/test_html.py +++ b/tests/parser/test_html.py @@ -118,3 +118,22 @@ def test_html_unparse_mixed(): pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.CODE, offset=57, length=10)]) assert HTML.unparse(text=text, entities=entities) == expected + + +def test_html_unparse_escaped(): + expected = "<b>bold</b>" + text = "bold" + entities = pyrogram.types.List( + [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.BOLD, offset=0, length=11)]) + + assert HTML.unparse(text=text, entities=entities) == expected + + +def test_html_unparse_escaped_nested(): + expected = "<b>bold <u>underline</u> bold</b>" + text = "bold underline bold" + entities = pyrogram.types.List( + [pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.BOLD, offset=0, length=33), + pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=8, length=16)]) + + assert HTML.unparse(text=text, entities=entities) == expected From 86515bb9d18ff21e8f2b33d8a80dd9076f88c832 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:12:46 +0100 Subject: [PATCH 429/539] Update Pyrogram to v2.0.68 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index ffb70e5c12..a9a7d15bf8 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.67" +__version__ = "2.0.68" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 217bcb1dfb409cd8afd5bf54826f6c7bfe30971c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Dec 2022 21:33:46 +0100 Subject: [PATCH 430/539] Fix HTML unparsing when there's no entities --- pyrogram/parser/html.py | 11 ++++++----- tests/parser/test_html.py | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index c574e6ffb1..987281b177 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -233,10 +233,11 @@ def recursive(entity_i: int) -> int: while i < len(entities): i += recursive(i) - last_offset = entities_offsets[-1][1] - # no need to sort, but still add entities starting from the end - for entity, offset in reversed(entities_offsets): - text = text[:offset] + entity + html.escape(text[offset:last_offset]) + text[last_offset:] - last_offset = offset + if entities_offsets: + last_offset = entities_offsets[-1][1] + # no need to sort, but still add entities starting from the end + for entity, offset in reversed(entities_offsets): + text = text[:offset] + entity + html.escape(text[offset:last_offset]) + text[last_offset:] + last_offset = offset return utils.remove_surrogates(text) diff --git a/tests/parser/test_html.py b/tests/parser/test_html.py index 0027290561..b9138f3cf1 100644 --- a/tests/parser/test_html.py +++ b/tests/parser/test_html.py @@ -137,3 +137,11 @@ def test_html_unparse_escaped_nested(): pyrogram.types.MessageEntity(type=pyrogram.enums.MessageEntityType.UNDERLINE, offset=8, length=16)]) assert HTML.unparse(text=text, entities=entities) == expected + + +def test_html_unparse_no_entities(): + expected = "text" + text = "text" + entities = [] + + assert HTML.unparse(text=text, entities=entities) == expected From 73554b9d38209c2eccdce28c29c5b8ed2d06f0cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Dec 2022 21:34:09 +0100 Subject: [PATCH 431/539] Update Pyrogram to v2.0.69 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a9a7d15bf8..3a44eb364d 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.68" +__version__ = "2.0.69" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From a76269ddaf09958590fccdeb416b6ade69801f06 Mon Sep 17 00:00:00 2001 From: Anton Kovalevich Date: Mon, 12 Dec 2022 20:53:09 +0000 Subject: [PATCH 432/539] Handle all given updates, avoid short circuit (#1162) --- pyrogram/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 67f059e96b..b88ea6918c 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -485,7 +485,10 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra async def handle_updates(self, updates): if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): - is_min = (await self.fetch_peers(updates.users)) or (await self.fetch_peers(updates.chats)) + is_min = any(( + await self.fetch_peers(updates.users), + await self.fetch_peers(updates.chats), + )) users = {u.id: u for u in updates.users} chats = {c.id: c for c in updates.chats} From aeea07f83d9becd356ed2752ae5aea68f0fc168f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:54:07 +0100 Subject: [PATCH 433/539] Update Pyrogram to v2.0.70 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 3a44eb364d..7cb81726f8 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.69" +__version__ = "2.0.70" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From a9e7d15bf6f5f69ca8f6154178003f6ede01ce76 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 15:40:56 +0100 Subject: [PATCH 434/539] Add a watchdog for incoming updates --- pyrogram/client.py | 25 +++++++++++++++++++++++++ pyrogram/methods/auth/initialize.py | 3 +++ pyrogram/methods/auth/terminate.py | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/pyrogram/client.py b/pyrogram/client.py index b88ea6918c..52c1d84428 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -26,6 +26,7 @@ import shutil import sys from concurrent.futures.thread import ThreadPoolExecutor +from datetime import datetime, timedelta from hashlib import sha256 from importlib import import_module from io import StringIO, BytesIO @@ -185,6 +186,9 @@ class Client(Methods): WORKERS = min(32, (os.cpu_count() or 0) + 4) # os.cpu_count() can be None WORKDIR = PARENT_DIR + # Interval of seconds in which the updates watchdog will kick in + UPDATES_WATCHDOG_INTERVAL = 5 * 60 + mimetypes = MimeTypes() mimetypes.readfp(StringIO(mime_types)) @@ -273,6 +277,13 @@ def __init__( self.message_cache = Cache(10000) + # Sometimes, for some reason, the server will stop sending updates and will only respond to pings. + # This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again + # after some idle time has been detected. + self.updates_watchdog_task = None + self.updates_watchdog_event = asyncio.Event() + self.last_update_time = datetime.now() + self.loop = asyncio.get_event_loop() def __enter__(self): @@ -293,6 +304,18 @@ async def __aexit__(self, *args): except ConnectionError: pass + async def updates_watchdog(self): + while True: + try: + await asyncio.wait_for(self.updates_watchdog_event.wait(), self.UPDATES_WATCHDOG_INTERVAL) + except asyncio.TimeoutError: + pass + else: + break + + if datetime.now() - self.last_update_time > timedelta(seconds=self.UPDATES_WATCHDOG_INTERVAL): + await self.invoke(raw.functions.updates.GetState()) + async def authorize(self) -> User: if self.bot_token: return await self.sign_in_bot(self.bot_token) @@ -484,6 +507,8 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra return is_min async def handle_updates(self, updates): + self.last_update_time = datetime.now() + if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): is_min = any(( await self.fetch_peers(updates.users), diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index 1e7915e00e..7188b66817 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.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 asyncio import logging import pyrogram @@ -46,4 +47,6 @@ async def initialize( await self.dispatcher.start() + self.updates_watchdog_task = asyncio.create_task(self.updates_watchdog()) + self.is_initialized = True diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 707c25e90e..d70103d03e 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -51,4 +51,11 @@ async def terminate( self.media_sessions.clear() + self.updates_watchdog_event.set() + + if self.updates_watchdog_task is not None: + await self.updates_watchdog_task + + self.updates_watchdog_event.clear() + self.is_initialized = False From ccb58f503c0d8344740e9209d70aa2fe7982db35 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 15:41:34 +0100 Subject: [PATCH 435/539] Update Pyrogram to v2.0.71 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 7cb81726f8..ee0ca0214e 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.70" +__version__ = "2.0.71" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 81573bce764fa4c2e5bd9ea1b0451154c7fe014e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:20:27 +0100 Subject: [PATCH 436/539] Remove threading.Lock usages --- pyrogram/storage/sqlite_storage.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py index 15e5ddc0c5..e28b9b746e 100644 --- a/pyrogram/storage/sqlite_storage.py +++ b/pyrogram/storage/sqlite_storage.py @@ -19,7 +19,6 @@ import inspect import sqlite3 import time -from threading import Lock from typing import List, Tuple, Any from pyrogram import raw @@ -98,10 +97,9 @@ def __init__(self, name: str): super().__init__(name) self.conn = None # type: sqlite3.Connection - self.lock = Lock() def create(self): - with self.lock, self.conn: + with self.conn: self.conn.executescript(SCHEMA) self.conn.execute( @@ -119,24 +117,20 @@ async def open(self): async def save(self): await self.date(int(time.time())) - - with self.lock: - self.conn.commit() + self.conn.commit() async def close(self): - with self.lock: - self.conn.close() + self.conn.close() async def delete(self): raise NotImplementedError async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): - with self.lock: - self.conn.executemany( - "REPLACE INTO peers (id, access_hash, type, username, phone_number)" - "VALUES (?, ?, ?, ?, ?)", - peers - ) + self.conn.executemany( + "REPLACE INTO peers (id, access_hash, type, username, phone_number)" + "VALUES (?, ?, ?, ?, ?)", + peers + ) async def get_peer_by_id(self, peer_id: int): r = self.conn.execute( @@ -185,7 +179,7 @@ def _get(self): def _set(self, value: Any): attr = inspect.stack()[2].function - with self.lock, self.conn: + with self.conn: self.conn.execute( f"UPDATE sessions SET {attr} = ?", (value,) @@ -221,7 +215,7 @@ def version(self, value: int = object): "SELECT number FROM version" ).fetchone()[0] else: - with self.lock, self.conn: + with self.conn: self.conn.execute( "UPDATE version SET number = ?", (value,) From 8afd4597fa0904eb6564d9521e4c81bc05d66188 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:20:44 +0100 Subject: [PATCH 437/539] Update Pyrogram to v2.0.72 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index ee0ca0214e..c58c007e4e 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.71" +__version__ = "2.0.72" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From c4a47b99ae66467b547744d280694ac5f5e307da Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Sat, 24 Dec 2022 03:36:00 +0800 Subject: [PATCH 438/539] Add support for Fragment SMS codes (#1170) --- pyrogram/client.py | 3 ++- pyrogram/enums/next_code_type.py | 3 +++ pyrogram/enums/sent_code_type.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 52c1d84428..238b2efbf5 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -356,7 +356,8 @@ async def authorize(self) -> User: enums.SentCodeType.APP: "Telegram app", enums.SentCodeType.SMS: "SMS", enums.SentCodeType.CALL: "phone call", - enums.SentCodeType.FLASH_CALL: "phone flash call" + enums.SentCodeType.FLASH_CALL: "phone flash call", + enums.SentCodeType.FRAGMENT_SMS: "Fragment SMS", } print(f"The confirmation code has been sent via {sent_code_descriptions[sent_code.type]}") diff --git a/pyrogram/enums/next_code_type.py b/pyrogram/enums/next_code_type.py index eadaf191a1..7b3137a7ad 100644 --- a/pyrogram/enums/next_code_type.py +++ b/pyrogram/enums/next_code_type.py @@ -34,3 +34,6 @@ class NextCodeType(AutoName): SMS = raw.types.auth.CodeTypeSms "The code was sent via SMS." + + FRAGMENT_SMS = raw.types.auth.CodeTypeFragmentSms + "The code was sent via Fragment SMS." diff --git a/pyrogram/enums/sent_code_type.py b/pyrogram/enums/sent_code_type.py index bee9de3fcb..e3ec61120a 100644 --- a/pyrogram/enums/sent_code_type.py +++ b/pyrogram/enums/sent_code_type.py @@ -37,3 +37,6 @@ class SentCodeType(AutoName): SMS = raw.types.auth.SentCodeTypeSms "The code was sent via SMS." + + FRAGMENT_SMS = raw.types.auth.SentCodeTypeFragmentSms + "The code was sent via Fragment SMS." From 265f5fc72e37bba28824b5d661370976d37200be Mon Sep 17 00:00:00 2001 From: KyMaP13 Date: Sat, 24 Dec 2022 00:40:31 +0500 Subject: [PATCH 439/539] Add VOICE_MESSAGES_FORBIDDEN (#1151) * add VOICE_MESSAGES_FORBIDDEN * Update 400_BAD_REQUEST.tsv Co-authored-by: onefedov Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/errors/source/400_BAD_REQUEST.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 877c967b37..1ad4c6a593 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -340,6 +340,7 @@ USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_NOT_PARTICIPANT The user is not a member of this chat VIDEO_CONTENT_TYPE_INVALID The video content type is invalid (i.e.: not streamable) VIDEO_FILE_INVALID The video file is invalid +VOICE_MESSAGES_FORBIDDEN Voice messages are restricted VOLUME_LOC_NOT_FOUND The volume location can't be found WALLPAPER_FILE_INVALID The provided file cannot be used as a wallpaper WALLPAPER_INVALID The input wallpaper was not valid From f350691c698c0cdc339128544e30d820a158d08b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:41:31 +0100 Subject: [PATCH 440/539] Update Pyrogram to v2.0.73 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index c58c007e4e..fac98532ce 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.72" +__version__ = "2.0.73" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 84d60b56b3b32bda046570881bed12aaea4222a8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 16:15:07 +0100 Subject: [PATCH 441/539] Switch to non-blocking sockets & use a send queue --- pyrogram/connection/connection.py | 6 ++--- pyrogram/connection/transport/tcp/tcp.py | 30 +++++++++++++++++------- pyrogram/session/auth.py | 2 +- pyrogram/session/session.py | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 618c92a510..73c2312f83 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -57,7 +57,7 @@ async def connect(self): await self.protocol.connect(self.address) except OSError as e: log.warning(f"Unable to connect due to network issues: {e}") - self.protocol.close() + await self.protocol.close() await asyncio.sleep(1) else: log.info("Connected! {} DC{}{} - IPv{} - {}".format( @@ -72,8 +72,8 @@ async def connect(self): log.warning("Connection failed! Trying again...") raise TimeoutError - def close(self): - self.protocol.close() + async def close(self): + await self.protocol.close() log.info("Disconnected") async def send(self, data: bytes): diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index c0efb625ab..4524c7a8b9 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -21,7 +21,7 @@ import logging import socket import time -from concurrent.futures import ThreadPoolExecutor +from typing import Optional try: import socks @@ -76,17 +76,21 @@ def __init__(self, ipv6: bool, proxy: dict): else socket.AF_INET ) + self.socket.setblocking(False) self.socket.settimeout(TCP.TIMEOUT) - async def connect(self, address: tuple): - # The socket used by the whole logic is blocking and thus it blocks when connecting. - # Offload the task to a thread executor to avoid blocking the main event loop. - with ThreadPoolExecutor(1) as executor: - await self.loop.run_in_executor(executor, self.socket.connect, address) + self.send_queue = asyncio.Queue() + self.send_task = None + async def connect(self, address: tuple): + await asyncio.get_event_loop().sock_connect(self.socket, address) self.reader, self.writer = await asyncio.open_connection(sock=self.socket) + self.send_task = asyncio.create_task(self.send_worker()) + + async def close(self): + await self.send_queue.put(None) + await self.send_task - def close(self): try: self.writer.close() except AttributeError: @@ -100,8 +104,16 @@ def close(self): time.sleep(0.001) self.socket.close() - async def send(self, data: bytes): - async with self.lock: + async def send(self, data: Optional[bytes]): + await self.send_queue.put(data) + + async def send_worker(self): + while True: + data = await self.send_queue.get() + + if data is None: + break + self.writer.write(data) await self.writer.drain() diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 7df4fede30..0bb393985b 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -258,4 +258,4 @@ async def create(self): else: return auth_key finally: - self.connection.close() + await self.connection.close() diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index a6537bb9a4..5e5d93fa01 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -157,7 +157,7 @@ async def stop(self): self.ping_task_event.clear() - self.connection.close() + await self.connection.close() if self.network_task: await self.network_task From f30510ab7d18c87e4e7af9781a3004cd95441948 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 16:15:37 +0100 Subject: [PATCH 442/539] Update Pyrogram to v2.0.74 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index fac98532ce..0840af4bc7 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.73" +__version__ = "2.0.74" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 1cb17152f8642097e00818a9a963936bc4b1d05a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:15:10 +0100 Subject: [PATCH 443/539] Keep a timeout while connecting and set non-blocking afterwards Also fix an await to None value --- pyrogram/connection/transport/tcp/tcp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 4524c7a8b9..ce8c090969 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -76,7 +76,6 @@ def __init__(self, ipv6: bool, proxy: dict): else socket.AF_INET ) - self.socket.setblocking(False) self.socket.settimeout(TCP.TIMEOUT) self.send_queue = asyncio.Queue() @@ -86,10 +85,13 @@ async def connect(self, address: tuple): await asyncio.get_event_loop().sock_connect(self.socket, address) self.reader, self.writer = await asyncio.open_connection(sock=self.socket) self.send_task = asyncio.create_task(self.send_worker()) + self.socket.setblocking(False) async def close(self): await self.send_queue.put(None) - await self.send_task + + if self.send_task is not None: + await self.send_task try: self.writer.close() From 91160bf834a486047a3c2eb3bcfa78277f10847f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:15:23 +0100 Subject: [PATCH 444/539] Update Pyrogram to v2.0.75 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 0840af4bc7..40d1179c9b 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.74" +__version__ = "2.0.75" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From deb560a05154f5371dc708d150da7a2b1fc1dea1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:26:40 +0100 Subject: [PATCH 445/539] Remove unused variables --- pyrogram/connection/transport/tcp/tcp.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index ce8c090969..1d0296b8e1 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -45,9 +45,6 @@ def __init__(self, ipv6: bool, proxy: dict): self.reader = None # type: asyncio.StreamReader self.writer = None # type: asyncio.StreamWriter - self.lock = asyncio.Lock() - self.loop = asyncio.get_event_loop() - if proxy: hostname = proxy.get("hostname") From f12005b5d0dfa85ec435a4812873077a9c143bde Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:30:23 +0100 Subject: [PATCH 446/539] Use Python's standard sockets in case of no proxy --- pyrogram/connection/transport/tcp/tcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 1d0296b8e1..13ddb8e212 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -68,7 +68,7 @@ def __init__(self, ipv6: bool, proxy: dict): log.info(f"Using proxy {hostname}") else: - self.socket = socks.socksocket( + self.socket = socket.socket( socket.AF_INET6 if ipv6 else socket.AF_INET ) From 13e8c419917abbb22cd69d0334412cc2645e3df1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:32:02 +0100 Subject: [PATCH 447/539] Update Pyrogram to v2.0.76 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 40d1179c9b..3186ab1889 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.75" +__version__ = "2.0.76" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From c7d362990f1de45fcc950ae5b4d13bfd03ef3108 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:53:24 +0100 Subject: [PATCH 448/539] Add back a reference to the loop --- pyrogram/connection/transport/tcp/tcp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 13ddb8e212..67b5385d20 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -45,6 +45,8 @@ def __init__(self, ipv6: bool, proxy: dict): self.reader = None # type: asyncio.StreamReader self.writer = None # type: asyncio.StreamWriter + self.loop = asyncio.get_event_loop() + if proxy: hostname = proxy.get("hostname") From b3825c209e03f9293116f20b62479744dab22d0f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 24 Dec 2022 17:53:49 +0100 Subject: [PATCH 449/539] Update Pyrogram to v2.0.77 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 3186ab1889..313bc9ace9 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.76" +__version__ = "2.0.77" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From dbf2e471b552b8e3012d89ef8acc21ac7929ea15 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 10:26:30 +0100 Subject: [PATCH 450/539] Fix usages of removed attributes --- pyrogram/storage/file_storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py index 986787cd95..a2ebdf9efb 100644 --- a/pyrogram/storage/file_storage.py +++ b/pyrogram/storage/file_storage.py @@ -38,13 +38,13 @@ def update(self): version = self.version() if version == 1: - with self.lock, self.conn: + with self.conn: self.conn.execute("DELETE FROM peers") version += 1 if version == 2: - with self.lock, self.conn: + with self.conn: self.conn.execute("ALTER TABLE sessions ADD api_id INTEGER") version += 1 From 87ae79e0e2a68a7e215ac7a006cda207361e4087 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 10:29:00 +0100 Subject: [PATCH 451/539] Remove special cases for older Python versions --- pyrogram/storage/file_storage.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py index a2ebdf9efb..aebe917671 100644 --- a/pyrogram/storage/file_storage.py +++ b/pyrogram/storage/file_storage.py @@ -63,10 +63,7 @@ async def open(self): self.update() with self.conn: - try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum - self.conn.execute("VACUUM") - except sqlite3.OperationalError: - pass + self.conn.execute("VACUUM") async def delete(self): os.remove(self.database) From 4c32a15cfdd3aef38bbee8a6863615461aad5424 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 10:30:56 +0100 Subject: [PATCH 452/539] Remove unneeded threading.Lock --- pyrogram/session/internals/seq_no.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pyrogram/session/internals/seq_no.py b/pyrogram/session/internals/seq_no.py index 0abc4a2f72..79501d9863 100644 --- a/pyrogram/session/internals/seq_no.py +++ b/pyrogram/session/internals/seq_no.py @@ -16,19 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from threading import Lock - class SeqNo: def __init__(self): self.content_related_messages_sent = 0 - self.lock = Lock() def __call__(self, is_content_related: bool) -> int: - with self.lock: - seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) + seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) - if is_content_related: - self.content_related_messages_sent += 1 + if is_content_related: + self.content_related_messages_sent += 1 - return seq_no + return seq_no From 13094f1d8b92b83366f652274b2efa678ee29aa7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 10:31:40 +0100 Subject: [PATCH 453/539] Update Pyrogram to v2.0.78 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 313bc9ace9..3d5656dfea 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.77" +__version__ = "2.0.78" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ae028ab4b67b2c7aab9726a48aeabb0b5432be91 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:55:40 +0100 Subject: [PATCH 454/539] Switch back to local system time synchronization perf_counter will stop counting when the system goes to sleep, causing the generation of invalid message ids after waking up which in turn put the client into a never ending reconnecting loop due to check mismatches caused by the time not being synced anymore. It's also unclear whether perf_counter stays in sync during long runs. --- pyrogram/session/internals/msg_id.py | 20 +++++--------------- pyrogram/session/session.py | 3 --- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/pyrogram/session/internals/msg_id.py b/pyrogram/session/internals/msg_id.py index 871a10b6c8..58e3087c51 100644 --- a/pyrogram/session/internals/msg_id.py +++ b/pyrogram/session/internals/msg_id.py @@ -17,29 +17,19 @@ # along with Pyrogram. If not, see . import logging -from datetime import datetime -from time import perf_counter +import time log = logging.getLogger(__name__) class MsgId: - reference_clock = 0 last_time = 0 - msg_id_offset = 0 - server_time = 0 + offset = 0 def __new__(cls) -> int: - now = perf_counter() - cls.reference_clock + cls.server_time - cls.msg_id_offset = cls.msg_id_offset + 4 if now == cls.last_time else 0 - msg_id = int(now * 2 ** 32) + cls.msg_id_offset + now = time.time() + cls.offset = (cls.offset + 4) if now == cls.last_time else 0 + msg_id = int(now * 2 ** 32) + cls.offset cls.last_time = now return msg_id - - @classmethod - def set_server_time(cls, server_time: int): - if not cls.server_time: - cls.reference_clock = perf_counter() - cls.server_time = server_time - log.info(f"Time synced: {datetime.utcfromtimestamp(server_time)} UTC") diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 5e5d93fa01..6c3dbc03f2 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -203,9 +203,6 @@ async def handle_packet(self, packet): log.debug(data) for msg in messages: - if msg.seq_no == 0: - MsgId.set_server_time(msg.msg_id / (2 ** 32)) - if msg.seq_no % 2 != 0: if msg.msg_id in self.pending_acks: continue From b23e34494ee5fc25214167fdb49a449eaa040426 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 15:08:02 +0100 Subject: [PATCH 455/539] Add messages for mismatched checks --- pyrogram/client.py | 5 ++++- pyrogram/crypto/mtproto.py | 29 ++++++++++++------------ pyrogram/errors/__init__.py | 12 +++++----- pyrogram/session/auth.py | 44 +++++++++++++++++++++++++++---------- pyrogram/session/session.py | 3 ++- 5 files changed, 59 insertions(+), 34 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 238b2efbf5..5ff18f29a5 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -982,7 +982,10 @@ async def get_file( # https://core.telegram.org/cdn#verifying-files for i, h in enumerate(hashes): cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] - CDNFileHashMismatch.check(h.hash == sha256(cdn_chunk).digest()) + CDNFileHashMismatch.check( + h.hash == sha256(cdn_chunk).digest(), + "h.hash == sha256(cdn_chunk).digest()" + ) yield decrypted_chunk diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index c893e3e538..e147c22a3e 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -62,7 +62,7 @@ def unpack( auth_key_id: bytes, stored_msg_ids: List[int] ) -> Message: - SecurityCheckMismatch.check(b.read(8) == auth_key_id) + SecurityCheckMismatch.check(b.read(8) == auth_key_id, "b.read(8) == auth_key_id") msg_key = b.read(16) aes_key, aes_iv = kdf(auth_key, msg_key, False) @@ -70,7 +70,7 @@ def unpack( data.read(8) # Salt # https://core.telegram.org/mtproto/security_guidelines#checking-session-id - SecurityCheckMismatch.check(data.read(8) == session_id) + SecurityCheckMismatch.check(data.read(8) == session_id, "data.read(8) == session_id") try: message = Message.read(data) @@ -88,39 +88,40 @@ def unpack( # https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key # 96 = 88 + 8 (incoming message) - SecurityCheckMismatch.check(msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24]) + SecurityCheckMismatch.check( + msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24], + "msg_key == sha256(auth_key[96:96 + 32] + data.getvalue()).digest()[8:24]" + ) # https://core.telegram.org/mtproto/security_guidelines#checking-message-length data.seek(32) # Get to the payload, skip salt (8) + session_id (8) + msg_id (8) + seq_no (4) + length (4) payload = data.read() padding = payload[message.length:] - SecurityCheckMismatch.check(12 <= len(padding) <= 1024) - SecurityCheckMismatch.check(len(payload) % 4 == 0) + SecurityCheckMismatch.check(12 <= len(padding) <= 1024, "12 <= len(padding) <= 1024") + SecurityCheckMismatch.check(len(payload) % 4 == 0, "len(payload) % 4 == 0") # https://core.telegram.org/mtproto/security_guidelines#checking-msg-id - SecurityCheckMismatch.check(message.msg_id % 2 != 0) + SecurityCheckMismatch.check(message.msg_id % 2 != 0, "message.msg_id % 2 != 0") if len(stored_msg_ids) > STORED_MSG_IDS_MAX_SIZE: del stored_msg_ids[:STORED_MSG_IDS_MAX_SIZE // 2] if stored_msg_ids: - # Ignored message: msg_id is lower than all of the stored values if message.msg_id < stored_msg_ids[0]: - raise SecurityCheckMismatch + raise SecurityCheckMismatch("The msg_id is lower than all the stored values") - # Ignored message: msg_id is equal to any of the stored values if message.msg_id in stored_msg_ids: - raise SecurityCheckMismatch + raise SecurityCheckMismatch("The msg_id is equal to any of the stored values") time_diff = (message.msg_id - MsgId()) / 2 ** 32 - # Ignored message: msg_id belongs over 30 seconds in the future if time_diff > 30: - raise SecurityCheckMismatch + raise SecurityCheckMismatch("The msg_id belongs to over 30 seconds in the future. " + "Most likely the client time has to be synchronized.") - # Ignored message: msg_id belongs over 300 seconds in the past if time_diff < -300: - raise SecurityCheckMismatch + raise SecurityCheckMismatch("The msg_id belongs to over 300 seconds in the past. " + "Most likely the client time has to be synchronized.") bisect.insort(stored_msg_ids, message.msg_id) diff --git a/pyrogram/errors/__init__.py b/pyrogram/errors/__init__.py index 0ae393620e..aa3a042c54 100644 --- a/pyrogram/errors/__init__.py +++ b/pyrogram/errors/__init__.py @@ -45,21 +45,21 @@ class SecurityError(Exception): """Generic security error.""" @classmethod - def check(cls, cond: bool): + def check(cls, cond: bool, msg: str): """Raises this exception if the condition is false""" if not cond: - raise cls + raise cls(f"Check failed: {msg}") class SecurityCheckMismatch(SecurityError): """Raised when a security check mismatch occurs.""" - def __init__(self): - super().__init__("A security check mismatch has occurred.") + def __init__(self, msg: str = None): + super().__init__("A security check mismatch has occurred." if msg is None else msg) class CDNFileHashMismatch(SecurityError): """Raised when a CDN file hash mismatch occurs.""" - def __init__(self): - super().__init__("A CDN file hash mismatch has occurred.") + def __init__(self, msg: str = None): + super().__init__("A CDN file hash mismatch has occurred." if msg is None else msg) diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 0bb393985b..973bad8bbe 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -211,33 +211,51 @@ async def create(self): # Security checks ####################### - SecurityCheckMismatch.check(dh_prime == prime.CURRENT_DH_PRIME) + SecurityCheckMismatch.check(dh_prime == prime.CURRENT_DH_PRIME, "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 g_b = int.from_bytes(g_b, "big") - SecurityCheckMismatch.check(1 < g < dh_prime - 1) - SecurityCheckMismatch.check(1 < g_a < dh_prime - 1) - SecurityCheckMismatch.check(1 < g_b < dh_prime - 1) - SecurityCheckMismatch.check(2 ** (2048 - 64) < g_a < dh_prime - 2 ** (2048 - 64)) - SecurityCheckMismatch.check(2 ** (2048 - 64) < g_b < dh_prime - 2 ** (2048 - 64)) + SecurityCheckMismatch.check(1 < g < dh_prime - 1, "1 < g < dh_prime - 1") + SecurityCheckMismatch.check(1 < g_a < dh_prime - 1, "1 < g_a < dh_prime - 1") + SecurityCheckMismatch.check(1 < g_b < dh_prime - 1, "1 < g_b < dh_prime - 1") + SecurityCheckMismatch.check( + 2 ** (2048 - 64) < g_a < dh_prime - 2 ** (2048 - 64), + "2 ** (2048 - 64) < g_a < dh_prime - 2 ** (2048 - 64)" + ) + SecurityCheckMismatch.check( + 2 ** (2048 - 64) < g_b < dh_prime - 2 ** (2048 - 64), + "2 ** (2048 - 64) < g_b < dh_prime - 2 ** (2048 - 64)" + ) log.debug("g_a and g_b validation: OK") # https://core.telegram.org/mtproto/security_guidelines#checking-sha1-hash-values answer = server_dh_inner_data.write() # Call .write() to remove padding - SecurityCheckMismatch.check(answer_with_hash[:20] == sha1(answer).digest()) + SecurityCheckMismatch.check( + answer_with_hash[:20] == sha1(answer).digest(), + "answer_with_hash[:20] == sha1(answer).digest()" + ) log.debug("SHA1 hash values check: OK") # https://core.telegram.org/mtproto/security_guidelines#checking-nonce-server-nonce-and-new-nonce-fields # 1st message - SecurityCheckMismatch.check(nonce == res_pq.nonce) + SecurityCheckMismatch.check(nonce == res_pq.nonce, "nonce == res_pq.nonce") # 2nd message server_nonce = int.from_bytes(server_nonce, "little", signed=True) - SecurityCheckMismatch.check(nonce == server_dh_params.nonce) - SecurityCheckMismatch.check(server_nonce == server_dh_params.server_nonce) + SecurityCheckMismatch.check(nonce == server_dh_params.nonce, "nonce == server_dh_params.nonce") + SecurityCheckMismatch.check( + server_nonce == server_dh_params.server_nonce, + "server_nonce == server_dh_params.server_nonce" + ) # 3rd message - SecurityCheckMismatch.check(nonce == set_client_dh_params_answer.nonce) - SecurityCheckMismatch.check(server_nonce == set_client_dh_params_answer.server_nonce) + SecurityCheckMismatch.check( + nonce == set_client_dh_params_answer.nonce, + "nonce == set_client_dh_params_answer.nonce" + ) + SecurityCheckMismatch.check( + server_nonce == set_client_dh_params_answer.server_nonce, + "server_nonce == set_client_dh_params_answer.server_nonce" + ) server_nonce = server_nonce.to_bytes(16, "little", signed=True) log.debug("Nonce fields check: OK") @@ -248,6 +266,8 @@ async def create(self): log.info(f"Done auth key exchange: {set_client_dh_params_answer.__class__.__name__}") except Exception as e: + log.info(f"Retrying due to {type(e).__name__}: {e}") + if retries_left: retries_left -= 1 else: diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 6c3dbc03f2..ed4982458b 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -188,7 +188,8 @@ async def handle_packet(self, packet): self.auth_key_id, self.stored_msg_ids ) - except SecurityCheckMismatch: + except SecurityCheckMismatch as e: + log.info(f"Discarding packet: {e}") return messages = ( From ce8c242eb45d0d0e84fea3180249addeb3ece6ff Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 15:14:12 +0100 Subject: [PATCH 456/539] Revert to triggering a reconnection when skipping invalid packets --- pyrogram/session/session.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index ed4982458b..fe13c743de 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -190,6 +190,7 @@ async def handle_packet(self, packet): ) except SecurityCheckMismatch as e: log.info(f"Discarding packet: {e}") + await self.connection.close() return messages = ( From 3d5e9d841f2625a4262c2129cb9ff44bdbd5740e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 25 Dec 2022 15:28:26 +0100 Subject: [PATCH 457/539] Update Pyrogram to v2.0.79 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 3d5656dfea..dc3cb7c555 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.78" +__version__ = "2.0.79" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 9eaaf105c18f18db12857b782ecf4d0081997847 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:18:41 +0100 Subject: [PATCH 458/539] Update requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bf6641539c..68abeee58d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ pyaes==1.6.1 -pysocks==1.7.1 From 7e5d59354493e46cfd6acfe75ea72b8ce23e015c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:19:26 +0100 Subject: [PATCH 459/539] Keep lang_code lowercase --- pyrogram/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 5ff18f29a5..9a0bce94ec 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -227,7 +227,7 @@ def __init__( self.app_version = app_version self.device_model = device_model self.system_version = system_version - self.lang_code = lang_code + self.lang_code = lang_code.lower() self.ipv6 = ipv6 self.proxy = proxy self.test_mode = test_mode From 9ee1807e42ba1c02b9f052c9d5695a3faaea865c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:23:57 +0100 Subject: [PATCH 460/539] Don't raise write() and close() exceptions --- pyrogram/connection/transport/tcp/tcp.py | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 67b5385d20..c3185a5fa0 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -93,19 +93,13 @@ async def close(self): await self.send_task try: - self.writer.close() - except AttributeError: - try: - self.socket.shutdown(socket.SHUT_RDWR) - except OSError: - pass - finally: - # A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout. - # This is a workaround that seems to fix the occasional delayed stop of a client. - time.sleep(0.001) - self.socket.close() - - async def send(self, data: Optional[bytes]): + if self.writer is not None: + self.writer.close() + await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT) + except Exception as e: + log.info("Close exception: %s %s", type(e).__name__, e) + + async def send(self, data: bytes): await self.send_queue.put(data) async def send_worker(self): @@ -115,8 +109,11 @@ async def send_worker(self): if data is None: break - self.writer.write(data) - await self.writer.drain() + try: + self.writer.write(data) + await self.writer.drain() + except Exception as e: + log.info("Send exception: %s %s", type(e).__name__, e) async def recv(self, length: int = 0): data = b"" From 6aae3a9c77e52102de905556f17227f15f2ff5fe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:25:22 +0100 Subject: [PATCH 461/539] Always use non-blocking sockets --- pyrogram/connection/transport/tcp/tcp.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index c3185a5fa0..213922e603 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -42,8 +42,11 @@ class TCP: def __init__(self, ipv6: bool, proxy: dict): self.socket = None - self.reader = None # type: asyncio.StreamReader - self.writer = None # type: asyncio.StreamWriter + self.reader = None + self.writer = None + + self.send_queue = asyncio.Queue() + self.send_task = None self.loop = asyncio.get_event_loop() @@ -75,16 +78,16 @@ def __init__(self, ipv6: bool, proxy: dict): else socket.AF_INET ) - self.socket.settimeout(TCP.TIMEOUT) - - self.send_queue = asyncio.Queue() - self.send_task = None + self.socket.setblocking(False) async def connect(self, address: tuple): - await asyncio.get_event_loop().sock_connect(self.socket, address) + try: + await asyncio.wait_for(asyncio.get_event_loop().sock_connect(self.socket, address), TCP.TIMEOUT) + except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 + raise TimeoutError("Connection timed out") + self.reader, self.writer = await asyncio.open_connection(sock=self.socket) self.send_task = asyncio.create_task(self.send_worker()) - self.socket.setblocking(False) async def close(self): await self.send_queue.put(None) From dd4e41f63f998c64d269989111ca6d3b42b95588 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:28:06 +0100 Subject: [PATCH 462/539] Make the use of proxies an optional dependency --- pyrogram/connection/transport/tcp/tcp.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 213922e603..a59e1081a9 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,18 +20,11 @@ import ipaddress import logging import socket -import time -from typing import Optional try: import socks -except ImportError as e: - e.msg = ( - "PySocks is missing and Pyrogram can't run without. " - "Please install it using \"pip3 install pysocks\"." - ) - - raise e +except ImportError: + socks = None log = logging.getLogger(__name__) @@ -50,7 +43,10 @@ def __init__(self, ipv6: bool, proxy: dict): self.loop = asyncio.get_event_loop() - if proxy: + if proxy and not socks: + log.warning("Can't use proxy because pysocks is not installed") + + if proxy and socks: hostname = proxy.get("hostname") try: @@ -71,7 +67,7 @@ def __init__(self, ipv6: bool, proxy: dict): password=proxy.get("password", None) ) - log.info(f"Using proxy {hostname}") + log.info("Using proxy %s", hostname) else: self.socket = socket.socket( socket.AF_INET6 if ipv6 From 7182a7cff755fa068b42bdf1eaaba27b1b5859f5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:29:05 +0100 Subject: [PATCH 463/539] Update connection.py --- pyrogram/connection/connection.py | 44 +++++++++++-------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 73c2312f83..69cbb813a1 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -20,67 +20,53 @@ import logging from typing import Optional -from .transport import * +from .transport import TCP, TCPAbridgedO from ..session.internals import DataCenter log = logging.getLogger(__name__) class Connection: - MAX_RETRIES = 3 + MAX_CONNECTION_ATTEMPTS = 3 - MODES = { - 0: TCPFull, - 1: TCPAbridged, - 2: TCPIntermediate, - 3: TCPAbridgedO, - 4: TCPIntermediateO - } - - def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3): + def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False): self.dc_id = dc_id self.test_mode = test_mode self.ipv6 = ipv6 self.proxy = proxy self.media = media - self.address = DataCenter(dc_id, test_mode, ipv6, media) - self.mode = self.MODES.get(mode, TCPAbridged) - self.protocol = None # type: TCP + self.address = DataCenter(dc_id, test_mode, ipv6, media) + self.protocol: TCP = None async def connect(self): - for i in range(Connection.MAX_RETRIES): - self.protocol = self.mode(self.ipv6, self.proxy) + for i in range(Connection.MAX_CONNECTION_ATTEMPTS): + self.protocol = TCPAbridgedO(self.ipv6, self.proxy) try: log.info("Connecting...") await self.protocol.connect(self.address) except OSError as e: - log.warning(f"Unable to connect due to network issues: {e}") + log.warning("Unable to connect due to network issues: %s", e) await self.protocol.close() await asyncio.sleep(1) else: - log.info("Connected! {} DC{}{} - IPv{} - {}".format( - "Test" if self.test_mode else "Production", - self.dc_id, - " (media)" if self.media else "", - "6" if self.ipv6 else "4", - self.mode.__name__, - )) + log.info("Connected! %s DC%s%s - IPv%s", + "Test" if self.test_mode else "Production", + self.dc_id, + " (media)" if self.media else "", + "6" if self.ipv6 else "4") break else: log.warning("Connection failed! Trying again...") - raise TimeoutError + raise ConnectionError async def close(self): await self.protocol.close() log.info("Disconnected") async def send(self, data: bytes): - try: - await self.protocol.send(data) - except Exception as e: - raise OSError(e) + await self.protocol.send(data) async def recv(self) -> Optional[bytes]: return await self.protocol.recv() From d298c62c6dea4c6fc0a5d8384a123481a21df2b0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:34:49 +0100 Subject: [PATCH 464/539] Update session.py --- pyrogram/session/session.py | 97 +++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index fe13c743de..2a22c2bdbb 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -32,7 +32,7 @@ ) from pyrogram.raw.all import layer from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts -from .internals import MsgId, MsgFactory +from .internals import MsgFactory log = logging.getLogger(__name__) @@ -85,9 +85,9 @@ def __init__( self.ping_task = None self.ping_task_event = asyncio.Event() - self.network_task = None + self.recv_task = None - self.is_connected = asyncio.Event() + self.is_started = asyncio.Event() self.loop = asyncio.get_event_loop() @@ -104,7 +104,7 @@ async def start(self): try: await self.connection.connect() - self.network_task = self.loop.create_task(self.network_worker()) + self.recv_task = self.loop.create_task(self.recv_worker()) await self.send(raw.functions.Ping(ping_id=0), timeout=self.START_TIMEOUT) @@ -128,14 +128,13 @@ async def start(self): self.ping_task = self.loop.create_task(self.ping_worker()) - log.info(f"Session initialized: Layer {layer}") - log.info(f"Device: {self.client.device_model} - {self.client.app_version}") - log.info(f"System: {self.client.system_version} ({self.client.lang_code.upper()})") - + log.info("Session initialized: Layer %s", layer) + log.info("Device: %s - %s", self.client.device_model, self.client.app_version) + log.info("System: %s (%s)", self.client.system_version, self.client.lang_code) except AuthKeyDuplicated as e: await self.stop() raise e - except (OSError, TimeoutError, RPCError): + except (OSError, RPCError): await self.stop() except Exception as e: await self.stop() @@ -143,12 +142,12 @@ async def start(self): else: break - self.is_connected.set() + self.is_started.set() log.info("Session started") async def stop(self): - self.is_connected.clear() + self.is_started.clear() self.ping_task_event.set() @@ -159,17 +158,14 @@ async def stop(self): await self.connection.close() - if self.network_task: - await self.network_task - - for i in self.results.values(): - i.event.set() + if self.recv_task: + await self.recv_task if not self.is_media and callable(self.client.disconnect_handler): try: await self.client.disconnect_handler(self.client) except Exception as e: - log.error(e, exc_info=True) + log.exception(e) log.info("Session stopped") @@ -189,7 +185,7 @@ async def handle_packet(self, packet): self.stored_msg_ids ) except SecurityCheckMismatch as e: - log.info(f"Discarding packet: {e}") + log.info("Discarding packet: %s", e) await self.connection.close() return @@ -199,10 +195,7 @@ async def handle_packet(self, packet): else [data] ) - # Call log.debug twice because calling it once by appending "data" to the previous string (i.e. f"Kind: {data}") - # will cause "data" to be evaluated as string every time instead of only when debug is actually enabled. - log.debug("Received:") - log.debug(data) + log.debug("Received: %s", data) for msg in messages: if msg.seq_no % 2 != 0: @@ -235,11 +228,11 @@ async def handle_packet(self, packet): self.results[msg_id].event.set() if len(self.pending_acks) >= self.ACKS_THRESHOLD: - log.debug(f"Send {len(self.pending_acks)} acks") + log.debug("Sending %s acks", len(self.pending_acks)) try: await self.send(raw.types.MsgsAck(msg_ids=list(self.pending_acks)), False) - except (OSError, TimeoutError): + except OSError: pass else: self.pending_acks.clear() @@ -261,12 +254,12 @@ async def ping_worker(self): ping_id=0, disconnect_delay=self.WAIT_TIMEOUT + 10 ), False ) - except (OSError, TimeoutError, RPCError): + except (OSError, RPCError): pass log.info("PingTask stopped") - async def network_worker(self): + async def recv_worker(self): log.info("NetworkTask started") while True: @@ -274,9 +267,9 @@ async def network_worker(self): if packet is None or len(packet) == 4: if packet: - log.warning(f'Server sent "{Int.read(BytesIO(packet))}"') + log.warning('Server sent "%s"', Int.read(BytesIO(packet))) - if self.is_connected.is_set(): + if self.is_started.is_set(): self.loop.create_task(self.restart()) break @@ -289,13 +282,7 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float message = self.msg_factory(data) msg_id = message.msg_id - if wait_response: - self.results[msg_id] = Result() - - # Call log.debug twice because calling it once by appending "data" to the previous string (i.e. f"Kind: {data}") - # will cause "data" to be evaluated as string every time instead of only when debug is actually enabled. - log.debug(f"Sent:") - log.debug(message) + log.debug("Sent: %s", message) payload = await self.loop.run_in_executor( pyrogram.crypto_executor, @@ -307,34 +294,35 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float self.auth_key_id ) - try: - await self.connection.send(payload) - except OSError as e: - self.results.pop(msg_id, None) - raise e + await self.connection.send(payload) if wait_response: + self.results[msg_id] = Result() + try: await asyncio.wait_for(self.results[msg_id].event.wait(), timeout) except asyncio.TimeoutError: pass - finally: - result = self.results.pop(msg_id).value + + result = self.results.pop(msg_id).value if result is None: - raise TimeoutError - elif isinstance(result, raw.types.RpcError): + raise TimeoutError("Response timed out") + + if isinstance(result, raw.types.RpcError): if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): data = data.query RPCError.raise_it(result, type(data)) - elif isinstance(result, raw.types.BadMsgNotification): + + if isinstance(result, raw.types.BadMsgNotification): raise BadMsgNotification(result.error_code) - elif isinstance(result, raw.types.BadServerSalt): + + if isinstance(result, raw.types.BadServerSalt): self.salt = result.new_server_salt return await self.send(data, wait_response, timeout) - else: - return result + + return result async def invoke( self, @@ -344,7 +332,7 @@ async def invoke( sleep_threshold: float = SLEEP_THRESHOLD ): try: - await asyncio.wait_for(self.is_connected.wait(), self.WAIT_TIMEOUT) + await asyncio.wait_for(self.is_started.wait(), self.WAIT_TIMEOUT) except asyncio.TimeoutError: pass @@ -364,16 +352,19 @@ async def invoke( if amount > sleep_threshold >= 0: raise - log.warning(f'[{self.client.name}] Waiting for {amount} seconds before continuing ' - f'(required by "{query_name}")') + log.warning('[%s] Waiting for %s seconds before continuing (required by "%s")', + self.client.name, amount, query_name) await asyncio.sleep(amount) - except (OSError, TimeoutError, InternalServerError, ServiceUnavailable) as e: + except (OSError, InternalServerError, ServiceUnavailable) as e: if retries == 0: raise e from None (log.warning if retries < 2 else log.info)( - f'[{Session.MAX_RETRIES - retries + 1}] Retrying "{query_name}" due to {str(e) or repr(e)}') + '[%s] Retrying "%s" due to: %s', + Session.MAX_RETRIES - retries + 1, + query_name, str(e) or repr(e) + ) await asyncio.sleep(0.5) From 01cd8bb57f5ade27abb287cf01bf146181985a8d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:38:12 +0100 Subject: [PATCH 465/539] Optimize log calls --- pyrogram/client.py | 14 ++++++------ pyrogram/dispatcher.py | 10 ++++---- pyrogram/methods/advanced/save_file.py | 4 ++-- pyrogram/methods/auth/terminate.py | 2 +- pyrogram/methods/utilities/start.py | 2 +- pyrogram/parser/html.py | 4 ++-- pyrogram/session/auth.py | 24 ++++++++++---------- pyrogram/types/messages_and_media/message.py | 10 ++++---- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 9a0bce94ec..36ab4e4cf7 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -396,7 +396,7 @@ async def authorize(self) -> User: except BadRequest as e: print(e.MESSAGE) except Exception as e: - log.error(e, exc_info=True) + log.exception(e) raise else: self.password = None @@ -684,11 +684,11 @@ def load_plugins(self): try: module = import_module(module_path) except ImportError: - log.warning(f'[{self.name}] [LOAD] Ignoring non-existent module "{module_path}"') + log.warning('[%s] [LOAD] Ignoring non-existent module "%s"', self.name, module_path) continue if "__path__" in dir(module): - log.warning(f'[{self.name}] [LOAD] Ignoring namespace "{module_path}"') + log.warning('[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path) continue if handlers is None: @@ -719,11 +719,11 @@ def load_plugins(self): try: module = import_module(module_path) except ImportError: - log.warning(f'[{self.name}] [UNLOAD] Ignoring non-existent module "{module_path}"') + log.warning('[%s] [UNLOAD] Ignoring non-existent module "%s"', self.name, module_path) continue if "__path__" in dir(module): - log.warning(f'[{self.name}] [UNLOAD] Ignoring namespace "{module_path}"') + log.warning('[%s] [UNLOAD] Ignoring namespace "%s"', self.name, module_path) continue if handlers is None: @@ -750,7 +750,7 @@ def load_plugins(self): log.info('[{}] Successfully loaded {} plugin{} from "{}"'.format( self.name, count, "s" if count > 1 else "", root)) else: - log.warning(f'[{self.name}] No plugin loaded from "{root}"') + log.warning('[%s] No plugin loaded from "%s"', self.name, root) async def handle_download(self, packet): file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet @@ -1012,7 +1012,7 @@ async def get_file( except pyrogram.StopTransmission: raise except Exception as e: - log.error(e, exc_info=True) + log.exception(e) def guess_mime_type(self, filename: str) -> Optional[str]: return self.mimetypes.guess_type(filename)[0] diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index b0ad87f71a..6e503cebb3 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -151,7 +151,7 @@ async def start(self): self.loop.create_task(self.handler_worker(self.locks_list[-1])) ) - log.info(f"Started {self.client.workers} HandlerTasks") + log.info("Started %s HandlerTasks", self.client.workers) async def stop(self): if not self.client.no_updates: @@ -164,7 +164,7 @@ async def stop(self): self.handler_worker_tasks.clear() self.groups.clear() - log.info(f"Stopped {self.client.workers} HandlerTasks") + log.info("Stopped %s HandlerTasks", self.client.workers) def add_handler(self, handler, group: int): async def fn(): @@ -226,7 +226,7 @@ async def handler_worker(self, lock): if await handler.check(self.client, parsed_update): args = (parsed_update,) except Exception as e: - log.error(e, exc_info=True) + log.exception(e) continue elif isinstance(handler, RawUpdateHandler): @@ -250,10 +250,10 @@ async def handler_worker(self, lock): except pyrogram.ContinuePropagation: continue except Exception as e: - log.error(e, exc_info=True) + log.exception(e) break except pyrogram.StopPropagation: pass except Exception as e: - log.error(e, exc_info=True) + log.exception(e) diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index c7f3a953e8..b99a3c43b5 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -107,7 +107,7 @@ async def worker(session): try: await session.invoke(data) except Exception as e: - log.error(e) + log.exception(e) part_size = 512 * 1024 @@ -201,7 +201,7 @@ async def worker(session): except StopTransmission: raise except Exception as e: - log.error(e, exc_info=True) + log.exception(e) else: if is_big: return raw.types.InputFileBig( diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index d70103d03e..70cfc80e65 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -41,7 +41,7 @@ async def terminate( if self.takeout_id: await self.invoke(raw.functions.account.FinishTakeoutSession()) - log.warning(f"Takeout session {self.takeout_id} finished") + log.warning("Takeout session %s finished", self.takeout_id) await self.storage.save() await self.dispatcher.stop() diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py index 95cd9fc585..19a7eb7cf3 100644 --- a/pyrogram/methods/utilities/start.py +++ b/pyrogram/methods/utilities/start.py @@ -63,7 +63,7 @@ async def main(): if not await self.storage.is_bot() and self.takeout: self.takeout_id = (await self.invoke(raw.functions.account.InitTakeoutSession())).id - log.warning(f"Takeout session {self.takeout_id} initiated") + log.warning("Takeout session %s initiated", self.takeout_id) await self.invoke(raw.functions.updates.GetState()) except (Exception, KeyboardInterrupt): diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 987281b177..7edb7f3c99 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -103,7 +103,7 @@ def handle_endtag(self, tag): line, offset = self.getpos() offset += 1 - log.debug(f"Unmatched closing tag at line {line}:{offset}") + log.debug("Unmatched closing tag at line %s:%s", tag, line, offset) else: if not self.tag_entities[tag]: self.tag_entities.pop(tag) @@ -131,7 +131,7 @@ async def parse(self, text: str): for tag, entities in parser.tag_entities.items(): unclosed_tags.append(f"<{tag}> (x{len(entities)})") - log.warning(f"Unclosed tags: {', '.join(unclosed_tags)}") + log.warning("Unclosed tags: %s", ", ".join(unclosed_tags)) entities = [] diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 973bad8bbe..c5d9cd9a50 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -79,34 +79,34 @@ async def create(self): self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy) try: - log.info(f"Start creating a new auth key on DC{self.dc_id}") + log.info("Start creating a new auth key on DC%s", self.dc_id) await self.connection.connect() # Step 1; Step 2 nonce = int.from_bytes(urandom(16), "little", signed=True) - log.debug(f"Send req_pq: {nonce}") + log.debug("Send req_pq: %s", nonce) res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce)) - log.debug(f"Got ResPq: {res_pq.server_nonce}") - log.debug(f"Server public key fingerprints: {res_pq.server_public_key_fingerprints}") + log.debug("Got ResPq: %s", res_pq.server_nonce) + log.debug("Server public key fingerprints: %s", res_pq.server_public_key_fingerprints) for i in res_pq.server_public_key_fingerprints: if i in rsa.server_public_keys: - log.debug(f"Using fingerprint: {i}") + log.debug("Using fingerprint: %s", i) public_key_fingerprint = i break else: - log.debug(f"Fingerprint unknown: {i}") + log.debug("Fingerprint unknown: %s", i) else: raise Exception("Public key not found") # Step 3 pq = int.from_bytes(res_pq.pq, "big") - log.debug(f"Start PQ factorization: {pq}") + log.debug("Start PQ factorization: %s", pq) start = time.time() g = prime.decompose(pq) p, q = sorted((g, pq // g)) # p < q - log.debug(f"Done PQ factorization ({round(time.time() - start, 3)}s): {p} {q}") + log.debug("Done PQ factorization (%ss): %s %s", round(time.time() - start, 3), p, q) # Step 4 server_nonce = res_pq.server_nonce @@ -168,7 +168,7 @@ async def create(self): dh_prime = int.from_bytes(server_dh_inner_data.dh_prime, "big") delta_time = server_dh_inner_data.server_time - time.time() - log.debug(f"Delta time: {round(delta_time, 3)}") + log.debug("Delta time: %s", round(delta_time, 3)) # Step 6 g = server_dh_inner_data.g @@ -262,11 +262,11 @@ async def create(self): # Step 9 server_salt = aes.xor(new_nonce[:8], server_nonce[:8]) - log.debug(f"Server salt: {int.from_bytes(server_salt, 'little')}") + log.debug("Server salt: %s", int.from_bytes(server_salt, "little")) - log.info(f"Done auth key exchange: {set_client_dh_params_answer.__class__.__name__}") + log.info("Done auth key exchange: %s", set_client_dh_params_answer.__class__.__name__) except Exception as e: - log.info(f"Retrying due to {type(e).__name__}: {e}") + log.info("Retrying due to %s: %s", type(e).__name__, e) if retries_left: retries_left -= 1 diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index d844b06054..ef249771fd 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -3045,13 +3045,13 @@ async def copy( RPCError: In case of a Telegram RPC error. """ if self.service: - log.warning(f"Service messages cannot be copied. " - f"chat_id: {self.chat.id}, message_id: {self.id}") + log.warning("Service messages cannot be copied. chat_id: %s, message_id: %s", + self.chat.id, self.id) elif self.game and not await self._client.storage.is_bot(): - log.warning(f"Users cannot send messages with Game media type. " - f"chat_id: {self.chat.id}, message_id: {self.id}") + log.warning("Users cannot send messages with Game media type. chat_id: %s, message_id: %s", + self.chat.id, self.id) elif self.empty: - log.warning(f"Empty messages cannot be copied. ") + log.warning("Empty messages cannot be copied.") elif self.text: return await self._client.send_message( chat_id, From 6b54467a0d6611f3dd60ec76a9dacdb170a25082 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:38:58 +0100 Subject: [PATCH 466/539] Update Pyrogram to v2.0.80 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index dc3cb7c555..af92632364 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.79" +__version__ = "2.0.80" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From ab45707f0f5ab9a7a20475701ab20e385692bcf4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:47:37 +0100 Subject: [PATCH 467/539] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 68abeee58d..bf6641539c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ pyaes==1.6.1 +pysocks==1.7.1 From 8b87c6ace3d867c3003b7a9c03d93648b96ef18d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:48:03 +0100 Subject: [PATCH 468/539] Update tcp.py --- pyrogram/connection/transport/tcp/tcp.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index a59e1081a9..13b6e7ded0 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,11 +20,7 @@ import ipaddress import logging import socket - -try: - import socks -except ImportError: - socks = None +import socks log = logging.getLogger(__name__) @@ -43,10 +39,7 @@ def __init__(self, ipv6: bool, proxy: dict): self.loop = asyncio.get_event_loop() - if proxy and not socks: - log.warning("Can't use proxy because pysocks is not installed") - - if proxy and socks: + if proxy: hostname = proxy.get("hostname") try: From 916be081163ea64902d99b4f40da47072caca68d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 16:48:30 +0100 Subject: [PATCH 469/539] Update Pyrogram to v2.0.81 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index af92632364..7d63406e9c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.80" +__version__ = "2.0.81" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 235dde2251a28df7149795563184c8920f0ca9d5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 20:11:58 +0100 Subject: [PATCH 470/539] Update exception message --- 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 2a22c2bdbb..3899aa528d 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -307,7 +307,7 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float result = self.results.pop(msg_id).value if result is None: - raise TimeoutError("Response timed out") + raise TimeoutError("Request timed out") if isinstance(result, raw.types.RpcError): if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): From a81b8a22545f2b18c7df7f59cd8d458e1c7589f3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 20:12:20 +0100 Subject: [PATCH 471/539] Update Pyrogram to v2.0.82 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 7d63406e9c..57483b6337 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.81" +__version__ = "2.0.82" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From bff583ed7562c20c3f1818a3cf05bf6051987320 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:26:55 +0100 Subject: [PATCH 472/539] Revert some of the latest changes --- pyrogram/client.py | 25 --------- pyrogram/connection/connection.py | 13 +++-- pyrogram/connection/transport/tcp/tcp.py | 64 ++++++++++-------------- pyrogram/methods/auth/initialize.py | 3 -- pyrogram/methods/auth/terminate.py | 7 --- pyrogram/session/auth.py | 2 +- pyrogram/session/internals/seq_no.py | 12 +++-- pyrogram/session/session.py | 36 +++++++------ pyrogram/storage/file_storage.py | 9 ++-- pyrogram/storage/sqlite_storage.py | 26 ++++++---- 10 files changed, 86 insertions(+), 111 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 36ab4e4cf7..63e4b47273 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -26,7 +26,6 @@ import shutil import sys from concurrent.futures.thread import ThreadPoolExecutor -from datetime import datetime, timedelta from hashlib import sha256 from importlib import import_module from io import StringIO, BytesIO @@ -186,9 +185,6 @@ class Client(Methods): WORKERS = min(32, (os.cpu_count() or 0) + 4) # os.cpu_count() can be None WORKDIR = PARENT_DIR - # Interval of seconds in which the updates watchdog will kick in - UPDATES_WATCHDOG_INTERVAL = 5 * 60 - mimetypes = MimeTypes() mimetypes.readfp(StringIO(mime_types)) @@ -277,13 +273,6 @@ def __init__( self.message_cache = Cache(10000) - # Sometimes, for some reason, the server will stop sending updates and will only respond to pings. - # This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again - # after some idle time has been detected. - self.updates_watchdog_task = None - self.updates_watchdog_event = asyncio.Event() - self.last_update_time = datetime.now() - self.loop = asyncio.get_event_loop() def __enter__(self): @@ -304,18 +293,6 @@ async def __aexit__(self, *args): except ConnectionError: pass - async def updates_watchdog(self): - while True: - try: - await asyncio.wait_for(self.updates_watchdog_event.wait(), self.UPDATES_WATCHDOG_INTERVAL) - except asyncio.TimeoutError: - pass - else: - break - - if datetime.now() - self.last_update_time > timedelta(seconds=self.UPDATES_WATCHDOG_INTERVAL): - await self.invoke(raw.functions.updates.GetState()) - async def authorize(self) -> User: if self.bot_token: return await self.sign_in_bot(self.bot_token) @@ -508,8 +485,6 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra return is_min async def handle_updates(self, updates): - self.last_update_time = datetime.now() - if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): is_min = any(( await self.fetch_peers(updates.users), diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 69cbb813a1..051d3c526b 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -48,7 +48,7 @@ async def connect(self): await self.protocol.connect(self.address) except OSError as e: log.warning("Unable to connect due to network issues: %s", e) - await self.protocol.close() + self.protocol.close() await asyncio.sleep(1) else: log.info("Connected! %s DC%s%s - IPv%s", @@ -59,14 +59,17 @@ async def connect(self): break else: log.warning("Connection failed! Trying again...") - raise ConnectionError + raise TimeoutError - async def close(self): - await self.protocol.close() + def close(self): + self.protocol.close() log.info("Disconnected") async def send(self, data: bytes): - await self.protocol.send(data) + try: + await self.protocol.send(data) + except Exception as e: + raise OSError(e) async def recv(self) -> Optional[bytes]: return await self.protocol.recv() diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 13b6e7ded0..beb2e58a2a 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,6 +20,9 @@ import ipaddress import logging import socket +import time +from concurrent.futures import ThreadPoolExecutor + import socks log = logging.getLogger(__name__) @@ -31,12 +34,10 @@ class TCP: def __init__(self, ipv6: bool, proxy: dict): self.socket = None - self.reader = None - self.writer = None - - self.send_queue = asyncio.Queue() - self.send_task = None + self.reader = None # type: asyncio.StreamReader + self.writer = None # type: asyncio.StreamWriter + self.lock = asyncio.Lock() self.loop = asyncio.get_event_loop() if proxy: @@ -62,50 +63,39 @@ def __init__(self, ipv6: bool, proxy: dict): log.info("Using proxy %s", hostname) else: - self.socket = socket.socket( + self.socket = socks.socksocket( socket.AF_INET6 if ipv6 else socket.AF_INET ) - self.socket.setblocking(False) + self.socket.settimeout(TCP.TIMEOUT) async def connect(self, address: tuple): - try: - await asyncio.wait_for(asyncio.get_event_loop().sock_connect(self.socket, address), TCP.TIMEOUT) - except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 - raise TimeoutError("Connection timed out") + # The socket used by the whole logic is blocking and thus it blocks when connecting. + # Offload the task to a thread executor to avoid blocking the main event loop. + with ThreadPoolExecutor(1) as executor: + await self.loop.run_in_executor(executor, self.socket.connect, address) self.reader, self.writer = await asyncio.open_connection(sock=self.socket) - self.send_task = asyncio.create_task(self.send_worker()) - - async def close(self): - await self.send_queue.put(None) - - if self.send_task is not None: - await self.send_task + def close(self): try: - if self.writer is not None: - self.writer.close() - await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT) - except Exception as e: - log.info("Close exception: %s %s", type(e).__name__, e) + self.writer.close() + except AttributeError: + try: + self.socket.shutdown(socket.SHUT_RDWR) + except OSError: + pass + finally: + # A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout. + # This is a workaround that seems to fix the occasional delayed stop of a client. + time.sleep(0.001) + self.socket.close() async def send(self, data: bytes): - await self.send_queue.put(data) - - async def send_worker(self): - while True: - data = await self.send_queue.get() - - if data is None: - break - - try: - self.writer.write(data) - await self.writer.drain() - except Exception as e: - log.info("Send exception: %s %s", type(e).__name__, e) + async with self.lock: + self.writer.write(data) + await self.writer.drain() async def recv(self, length: int = 0): data = b"" diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index 7188b66817..1e7915e00e 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import asyncio import logging import pyrogram @@ -47,6 +46,4 @@ async def initialize( await self.dispatcher.start() - self.updates_watchdog_task = asyncio.create_task(self.updates_watchdog()) - self.is_initialized = True diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 70cfc80e65..5ecb6758ef 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -51,11 +51,4 @@ async def terminate( self.media_sessions.clear() - self.updates_watchdog_event.set() - - if self.updates_watchdog_task is not None: - await self.updates_watchdog_task - - self.updates_watchdog_event.clear() - self.is_initialized = False diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index c5d9cd9a50..d51e18f843 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -278,4 +278,4 @@ async def create(self): else: return auth_key finally: - await self.connection.close() + self.connection.close() diff --git a/pyrogram/session/internals/seq_no.py b/pyrogram/session/internals/seq_no.py index 79501d9863..0abc4a2f72 100644 --- a/pyrogram/session/internals/seq_no.py +++ b/pyrogram/session/internals/seq_no.py @@ -16,15 +16,19 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from threading import Lock + class SeqNo: def __init__(self): self.content_related_messages_sent = 0 + self.lock = Lock() def __call__(self, is_content_related: bool) -> int: - seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) + with self.lock: + seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) - if is_content_related: - self.content_related_messages_sent += 1 + if is_content_related: + self.content_related_messages_sent += 1 - return seq_no + return seq_no diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 3899aa528d..5135af6987 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -156,11 +156,14 @@ async def stop(self): self.ping_task_event.clear() - await self.connection.close() + self.connection.close() if self.recv_task: await self.recv_task + for i in self.results.values(): + i.event.set() + if not self.is_media and callable(self.client.disconnect_handler): try: await self.client.disconnect_handler(self.client) @@ -185,8 +188,7 @@ async def handle_packet(self, packet): self.stored_msg_ids ) except SecurityCheckMismatch as e: - log.info("Discarding packet: %s", e) - await self.connection.close() + log.warning("Discarding packet: %s", e) return messages = ( @@ -282,6 +284,9 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float message = self.msg_factory(data) msg_id = message.msg_id + if wait_response: + self.results[msg_id] = Result() + log.debug("Sent: %s", message) payload = await self.loop.run_in_executor( @@ -294,35 +299,34 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float self.auth_key_id ) - await self.connection.send(payload) + try: + await self.connection.send(payload) + except OSError as e: + self.results.pop(msg_id, None) + raise e if wait_response: - self.results[msg_id] = Result() - try: await asyncio.wait_for(self.results[msg_id].event.wait(), timeout) except asyncio.TimeoutError: pass - - result = self.results.pop(msg_id).value + finally: + result = self.results.pop(msg_id).value if result is None: raise TimeoutError("Request timed out") - - if isinstance(result, raw.types.RpcError): + elif isinstance(result, raw.types.RpcError): if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): data = data.query RPCError.raise_it(result, type(data)) - - if isinstance(result, raw.types.BadMsgNotification): + elif isinstance(result, raw.types.BadMsgNotification): raise BadMsgNotification(result.error_code) - - if isinstance(result, raw.types.BadServerSalt): + elif isinstance(result, raw.types.BadServerSalt): self.salt = result.new_server_salt return await self.send(data, wait_response, timeout) - - return result + else: + return result async def invoke( self, diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py index aebe917671..986787cd95 100644 --- a/pyrogram/storage/file_storage.py +++ b/pyrogram/storage/file_storage.py @@ -38,13 +38,13 @@ def update(self): version = self.version() if version == 1: - with self.conn: + with self.lock, self.conn: self.conn.execute("DELETE FROM peers") version += 1 if version == 2: - with self.conn: + with self.lock, self.conn: self.conn.execute("ALTER TABLE sessions ADD api_id INTEGER") version += 1 @@ -63,7 +63,10 @@ async def open(self): self.update() with self.conn: - self.conn.execute("VACUUM") + try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum + self.conn.execute("VACUUM") + except sqlite3.OperationalError: + pass async def delete(self): os.remove(self.database) diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py index e28b9b746e..15e5ddc0c5 100644 --- a/pyrogram/storage/sqlite_storage.py +++ b/pyrogram/storage/sqlite_storage.py @@ -19,6 +19,7 @@ import inspect import sqlite3 import time +from threading import Lock from typing import List, Tuple, Any from pyrogram import raw @@ -97,9 +98,10 @@ def __init__(self, name: str): super().__init__(name) self.conn = None # type: sqlite3.Connection + self.lock = Lock() def create(self): - with self.conn: + with self.lock, self.conn: self.conn.executescript(SCHEMA) self.conn.execute( @@ -117,20 +119,24 @@ async def open(self): async def save(self): await self.date(int(time.time())) - self.conn.commit() + + with self.lock: + self.conn.commit() async def close(self): - self.conn.close() + with self.lock: + self.conn.close() async def delete(self): raise NotImplementedError async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): - self.conn.executemany( - "REPLACE INTO peers (id, access_hash, type, username, phone_number)" - "VALUES (?, ?, ?, ?, ?)", - peers - ) + with self.lock: + self.conn.executemany( + "REPLACE INTO peers (id, access_hash, type, username, phone_number)" + "VALUES (?, ?, ?, ?, ?)", + peers + ) async def get_peer_by_id(self, peer_id: int): r = self.conn.execute( @@ -179,7 +185,7 @@ def _get(self): def _set(self, value: Any): attr = inspect.stack()[2].function - with self.conn: + with self.lock, self.conn: self.conn.execute( f"UPDATE sessions SET {attr} = ?", (value,) @@ -215,7 +221,7 @@ def version(self, value: int = object): "SELECT number FROM version" ).fetchone()[0] else: - with self.conn: + with self.lock, self.conn: self.conn.execute( "UPDATE version SET number = ?", (value,) From 03d60cdfe656d527c510a7924a0b2332fb8398e7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:30:14 +0100 Subject: [PATCH 473/539] Update Pyrogram to v2.0.83 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 57483b6337..a1accaf2ee 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.82" +__version__ = "2.0.83" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 9bf742abc0bb6342749ce108fa49dd9c2bedb646 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Dec 2022 13:40:42 +0100 Subject: [PATCH 474/539] Introduce back some previously reverted changes --- pyrogram/client.py | 25 +++++++++++++ pyrogram/connection/connection.py | 13 +++---- pyrogram/connection/transport/tcp/tcp.py | 45 +++++++++++------------- pyrogram/methods/auth/initialize.py | 3 ++ pyrogram/methods/auth/terminate.py | 7 ++++ pyrogram/session/auth.py | 2 +- pyrogram/session/internals/msg_id.py | 4 +-- pyrogram/session/internals/seq_no.py | 12 +++---- pyrogram/session/session.py | 40 ++++++++++----------- pyrogram/storage/file_storage.py | 9 ++--- pyrogram/storage/sqlite_storage.py | 26 ++++++-------- 11 files changed, 98 insertions(+), 88 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 63e4b47273..36ab4e4cf7 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -26,6 +26,7 @@ import shutil import sys from concurrent.futures.thread import ThreadPoolExecutor +from datetime import datetime, timedelta from hashlib import sha256 from importlib import import_module from io import StringIO, BytesIO @@ -185,6 +186,9 @@ class Client(Methods): WORKERS = min(32, (os.cpu_count() or 0) + 4) # os.cpu_count() can be None WORKDIR = PARENT_DIR + # Interval of seconds in which the updates watchdog will kick in + UPDATES_WATCHDOG_INTERVAL = 5 * 60 + mimetypes = MimeTypes() mimetypes.readfp(StringIO(mime_types)) @@ -273,6 +277,13 @@ def __init__( self.message_cache = Cache(10000) + # Sometimes, for some reason, the server will stop sending updates and will only respond to pings. + # This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again + # after some idle time has been detected. + self.updates_watchdog_task = None + self.updates_watchdog_event = asyncio.Event() + self.last_update_time = datetime.now() + self.loop = asyncio.get_event_loop() def __enter__(self): @@ -293,6 +304,18 @@ async def __aexit__(self, *args): except ConnectionError: pass + async def updates_watchdog(self): + while True: + try: + await asyncio.wait_for(self.updates_watchdog_event.wait(), self.UPDATES_WATCHDOG_INTERVAL) + except asyncio.TimeoutError: + pass + else: + break + + if datetime.now() - self.last_update_time > timedelta(seconds=self.UPDATES_WATCHDOG_INTERVAL): + await self.invoke(raw.functions.updates.GetState()) + async def authorize(self) -> User: if self.bot_token: return await self.sign_in_bot(self.bot_token) @@ -485,6 +508,8 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra return is_min async def handle_updates(self, updates): + self.last_update_time = datetime.now() + if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): is_min = any(( await self.fetch_peers(updates.users), diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 051d3c526b..69cbb813a1 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -48,7 +48,7 @@ async def connect(self): await self.protocol.connect(self.address) except OSError as e: log.warning("Unable to connect due to network issues: %s", e) - self.protocol.close() + await self.protocol.close() await asyncio.sleep(1) else: log.info("Connected! %s DC%s%s - IPv%s", @@ -59,17 +59,14 @@ async def connect(self): break else: log.warning("Connection failed! Trying again...") - raise TimeoutError + raise ConnectionError - def close(self): - self.protocol.close() + async def close(self): + await self.protocol.close() log.info("Disconnected") async def send(self, data: bytes): - try: - await self.protocol.send(data) - except Exception as e: - raise OSError(e) + await self.protocol.send(data) async def recv(self) -> Optional[bytes]: return await self.protocol.recv() diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index beb2e58a2a..6aff86af22 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,9 +20,6 @@ import ipaddress import logging import socket -import time -from concurrent.futures import ThreadPoolExecutor - import socks log = logging.getLogger(__name__) @@ -34,8 +31,8 @@ class TCP: def __init__(self, ipv6: bool, proxy: dict): self.socket = None - self.reader = None # type: asyncio.StreamReader - self.writer = None # type: asyncio.StreamWriter + self.reader = None + self.writer = None self.lock = asyncio.Lock() self.loop = asyncio.get_event_loop() @@ -63,39 +60,37 @@ def __init__(self, ipv6: bool, proxy: dict): log.info("Using proxy %s", hostname) else: - self.socket = socks.socksocket( + self.socket = socket.socket( socket.AF_INET6 if ipv6 else socket.AF_INET ) - self.socket.settimeout(TCP.TIMEOUT) + self.socket.setblocking(False) async def connect(self, address: tuple): - # The socket used by the whole logic is blocking and thus it blocks when connecting. - # Offload the task to a thread executor to avoid blocking the main event loop. - with ThreadPoolExecutor(1) as executor: - await self.loop.run_in_executor(executor, self.socket.connect, address) + try: + await asyncio.wait_for(asyncio.get_event_loop().sock_connect(self.socket, address), TCP.TIMEOUT) + except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 + raise TimeoutError("Connection timed out") self.reader, self.writer = await asyncio.open_connection(sock=self.socket) - def close(self): + async def close(self): try: - self.writer.close() - except AttributeError: - try: - self.socket.shutdown(socket.SHUT_RDWR) - except OSError: - pass - finally: - # A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout. - # This is a workaround that seems to fix the occasional delayed stop of a client. - time.sleep(0.001) - self.socket.close() + if self.writer is not None: + self.writer.close() + await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT) + except Exception as e: + log.warning("Close exception: %s %s", type(e).__name__, e) async def send(self, data: bytes): async with self.lock: - self.writer.write(data) - await self.writer.drain() + try: + if self.writer is not None: + self.writer.write(data) + await self.writer.drain() + except Exception as e: + log.warning("Send exception: %s %s", type(e).__name__, e) async def recv(self, length: int = 0): data = b"" diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index 1e7915e00e..7188b66817 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.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 asyncio import logging import pyrogram @@ -46,4 +47,6 @@ async def initialize( await self.dispatcher.start() + self.updates_watchdog_task = asyncio.create_task(self.updates_watchdog()) + self.is_initialized = True diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 5ecb6758ef..70cfc80e65 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -51,4 +51,11 @@ async def terminate( self.media_sessions.clear() + self.updates_watchdog_event.set() + + if self.updates_watchdog_task is not None: + await self.updates_watchdog_task + + self.updates_watchdog_event.clear() + self.is_initialized = False diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index d51e18f843..c5d9cd9a50 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -278,4 +278,4 @@ async def create(self): else: return auth_key finally: - self.connection.close() + await self.connection.close() diff --git a/pyrogram/session/internals/msg_id.py b/pyrogram/session/internals/msg_id.py index 58e3087c51..da2e264ff6 100644 --- a/pyrogram/session/internals/msg_id.py +++ b/pyrogram/session/internals/msg_id.py @@ -27,9 +27,9 @@ class MsgId: offset = 0 def __new__(cls) -> int: - now = time.time() + now = int(time.time()) cls.offset = (cls.offset + 4) if now == cls.last_time else 0 - msg_id = int(now * 2 ** 32) + cls.offset + msg_id = (now * 2 ** 32) + cls.offset cls.last_time = now return msg_id diff --git a/pyrogram/session/internals/seq_no.py b/pyrogram/session/internals/seq_no.py index 0abc4a2f72..79501d9863 100644 --- a/pyrogram/session/internals/seq_no.py +++ b/pyrogram/session/internals/seq_no.py @@ -16,19 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from threading import Lock - class SeqNo: def __init__(self): self.content_related_messages_sent = 0 - self.lock = Lock() def __call__(self, is_content_related: bool) -> int: - with self.lock: - seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) + seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) - if is_content_related: - self.content_related_messages_sent += 1 + if is_content_related: + self.content_related_messages_sent += 1 - return seq_no + return seq_no diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 5135af6987..df7ae6c483 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -44,11 +44,11 @@ def __init__(self): class Session: - START_TIMEOUT = 1 + START_TIMEOUT = 5 WAIT_TIMEOUT = 15 SLEEP_THRESHOLD = 10 - MAX_RETRIES = 5 - ACKS_THRESHOLD = 8 + MAX_RETRIES = 10 + ACKS_THRESHOLD = 10 PING_INTERVAL = 5 def __init__( @@ -156,14 +156,11 @@ async def stop(self): self.ping_task_event.clear() - self.connection.close() + await self.connection.close() if self.recv_task: await self.recv_task - for i in self.results.values(): - i.event.set() - if not self.is_media and callable(self.client.disconnect_handler): try: await self.client.disconnect_handler(self.client) @@ -189,6 +186,7 @@ async def handle_packet(self, packet): ) except SecurityCheckMismatch as e: log.warning("Discarding packet: %s", e) + await self.connection.close() return messages = ( @@ -284,9 +282,6 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float message = self.msg_factory(data) msg_id = message.msg_id - if wait_response: - self.results[msg_id] = Result() - log.debug("Sent: %s", message) payload = await self.loop.run_in_executor( @@ -299,34 +294,35 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float self.auth_key_id ) - try: - await self.connection.send(payload) - except OSError as e: - self.results.pop(msg_id, None) - raise e + await self.connection.send(payload) if wait_response: + self.results[msg_id] = Result() + try: await asyncio.wait_for(self.results[msg_id].event.wait(), timeout) except asyncio.TimeoutError: pass - finally: - result = self.results.pop(msg_id).value + + result = self.results.pop(msg_id).value if result is None: raise TimeoutError("Request timed out") - elif isinstance(result, raw.types.RpcError): + + if isinstance(result, raw.types.RpcError): if isinstance(data, (raw.functions.InvokeWithoutUpdates, raw.functions.InvokeWithTakeout)): data = data.query RPCError.raise_it(result, type(data)) - elif isinstance(result, raw.types.BadMsgNotification): + + if isinstance(result, raw.types.BadMsgNotification): raise BadMsgNotification(result.error_code) - elif isinstance(result, raw.types.BadServerSalt): + + if isinstance(result, raw.types.BadServerSalt): self.salt = result.new_server_salt return await self.send(data, wait_response, timeout) - else: - return result + + return result async def invoke( self, diff --git a/pyrogram/storage/file_storage.py b/pyrogram/storage/file_storage.py index 986787cd95..aebe917671 100644 --- a/pyrogram/storage/file_storage.py +++ b/pyrogram/storage/file_storage.py @@ -38,13 +38,13 @@ def update(self): version = self.version() if version == 1: - with self.lock, self.conn: + with self.conn: self.conn.execute("DELETE FROM peers") version += 1 if version == 2: - with self.lock, self.conn: + with self.conn: self.conn.execute("ALTER TABLE sessions ADD api_id INTEGER") version += 1 @@ -63,10 +63,7 @@ async def open(self): self.update() with self.conn: - try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum - self.conn.execute("VACUUM") - except sqlite3.OperationalError: - pass + self.conn.execute("VACUUM") async def delete(self): os.remove(self.database) diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py index 15e5ddc0c5..e28b9b746e 100644 --- a/pyrogram/storage/sqlite_storage.py +++ b/pyrogram/storage/sqlite_storage.py @@ -19,7 +19,6 @@ import inspect import sqlite3 import time -from threading import Lock from typing import List, Tuple, Any from pyrogram import raw @@ -98,10 +97,9 @@ def __init__(self, name: str): super().__init__(name) self.conn = None # type: sqlite3.Connection - self.lock = Lock() def create(self): - with self.lock, self.conn: + with self.conn: self.conn.executescript(SCHEMA) self.conn.execute( @@ -119,24 +117,20 @@ async def open(self): async def save(self): await self.date(int(time.time())) - - with self.lock: - self.conn.commit() + self.conn.commit() async def close(self): - with self.lock: - self.conn.close() + self.conn.close() async def delete(self): raise NotImplementedError async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): - with self.lock: - self.conn.executemany( - "REPLACE INTO peers (id, access_hash, type, username, phone_number)" - "VALUES (?, ?, ?, ?, ?)", - peers - ) + self.conn.executemany( + "REPLACE INTO peers (id, access_hash, type, username, phone_number)" + "VALUES (?, ?, ?, ?, ?)", + peers + ) async def get_peer_by_id(self, peer_id: int): r = self.conn.execute( @@ -185,7 +179,7 @@ def _get(self): def _set(self, value: Any): attr = inspect.stack()[2].function - with self.lock, self.conn: + with self.conn: self.conn.execute( f"UPDATE sessions SET {attr} = ?", (value,) @@ -221,7 +215,7 @@ def version(self, value: int = object): "SELECT number FROM version" ).fetchone()[0] else: - with self.lock, self.conn: + with self.conn: self.conn.execute( "UPDATE version SET number = ?", (value,) From dc3b8a5e01ff7a94243ef158b415d1dca5b15431 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Dec 2022 14:55:07 +0100 Subject: [PATCH 475/539] Tweak file upload settings Multiple sessions as used in the current implementation were causing a variety of network related issues. Use one session only instead. Multiple workers within the same session are fine as long as they are not too many, otherwise the server will start replying with -429 (too many requests). Setting the queue size to 1 helps in having a more linear upload progress. --- pyrogram/methods/advanced/save_file.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index b99a3c43b5..5ecac6d80e 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -134,23 +134,19 @@ async def worker(session): file_total_parts = int(math.ceil(file_size / part_size)) is_big = file_size > 10 * 1024 * 1024 - pool_size = 3 if is_big else 1 workers_count = 4 if is_big else 1 is_missing_part = file_id is not None file_id = file_id or self.rnd_id() md5_sum = md5() if not is_big and not is_missing_part else None - pool = [ - Session( - self, await self.storage.dc_id(), await self.storage.auth_key(), - await self.storage.test_mode(), is_media=True - ) for _ in range(pool_size) - ] - workers = [self.loop.create_task(worker(session)) for session in pool for _ in range(workers_count)] - queue = asyncio.Queue(16) + session = Session( + self, await self.storage.dc_id(), await self.storage.auth_key(), + await self.storage.test_mode(), is_media=True + ) + workers = [self.loop.create_task(worker(session)) for _ in range(workers_count)] + queue = asyncio.Queue(1) try: - for session in pool: - await session.start() + await session.start() fp.seek(part_size * file_part) @@ -223,8 +219,7 @@ async def worker(session): await asyncio.gather(*workers) - for session in pool: - await session.stop() + await session.stop() if isinstance(path, (str, PurePath)): fp.close() From 52effe19d58368bf0d8884272f07fe5d2148aab8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Dec 2022 14:56:34 +0100 Subject: [PATCH 476/539] Update Pyrogram to v2.0.84 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a1accaf2ee..70f9bd931c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.83" +__version__ = "2.0.84" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From cf06939a55f37ffa05b0bca1155981e1fa09f206 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Dec 2022 22:23:05 +0100 Subject: [PATCH 477/539] Workaround proxy sockets not timing out properly --- pyrogram/connection/transport/tcp/tcp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 6aff86af22..22b367ae45 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,6 +20,7 @@ import ipaddress import logging import socket + import socks log = logging.getLogger(__name__) @@ -58,6 +59,8 @@ def __init__(self, ipv6: bool, proxy: dict): password=proxy.get("password", None) ) + self.socket.settimeout(TCP.TIMEOUT) + log.info("Using proxy %s", hostname) else: self.socket = socket.socket( @@ -65,7 +68,7 @@ def __init__(self, ipv6: bool, proxy: dict): else socket.AF_INET ) - self.socket.setblocking(False) + self.socket.setblocking(False) async def connect(self, address: tuple): try: From 1fa6f3b924d95cc4a6a5b37bcebf924acd75ba0d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Dec 2022 22:24:21 +0100 Subject: [PATCH 478/539] Update Pyrogram to v2.0.85 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 70f9bd931c..9d4bd6f9e4 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.84" +__version__ = "2.0.85" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 2dca5aeac20b2e3a6762c01e0b28a375ad97e6a6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:14:04 +0100 Subject: [PATCH 479/539] Handle proxy socket connections using thread executors --- pyrogram/connection/transport/tcp/tcp.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 22b367ae45..168f06a52e 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -20,6 +20,7 @@ import ipaddress import logging import socket +from concurrent.futures import ThreadPoolExecutor import socks @@ -38,6 +39,8 @@ def __init__(self, ipv6: bool, proxy: dict): self.lock = asyncio.Lock() self.loop = asyncio.get_event_loop() + self.proxy = proxy + if proxy: hostname = proxy.get("hostname") @@ -71,10 +74,14 @@ def __init__(self, ipv6: bool, proxy: dict): self.socket.setblocking(False) async def connect(self, address: tuple): - try: - await asyncio.wait_for(asyncio.get_event_loop().sock_connect(self.socket, address), TCP.TIMEOUT) - except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 - raise TimeoutError("Connection timed out") + if self.proxy: + with ThreadPoolExecutor(1) as executor: + await self.loop.run_in_executor(executor, self.socket.connect, address) + else: + try: + await asyncio.wait_for(asyncio.get_event_loop().sock_connect(self.socket, address), TCP.TIMEOUT) + except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 + raise TimeoutError("Connection timed out") self.reader, self.writer = await asyncio.open_connection(sock=self.socket) From 5ca422b31425da9c0d3cb070d1856496bd046170 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:19:28 +0100 Subject: [PATCH 480/539] Create a future result before sending its request --- pyrogram/session/session.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index df7ae6c483..e64ea7930b 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -282,6 +282,9 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float message = self.msg_factory(data) msg_id = message.msg_id + if wait_response: + self.results[msg_id] = Result() + log.debug("Sent: %s", message) payload = await self.loop.run_in_executor( @@ -297,8 +300,6 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float await self.connection.send(payload) if wait_response: - self.results[msg_id] = Result() - try: await asyncio.wait_for(self.results[msg_id].event.wait(), timeout) except asyncio.TimeoutError: From 1daa05a35cd2c089c4aed946dddb7ae2bef92d3d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:21:05 +0100 Subject: [PATCH 481/539] Raise and handle send errors in order to immediately act upon --- pyrogram/connection/transport/tcp/tcp.py | 1 + pyrogram/session/session.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 168f06a52e..08a435cee9 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -101,6 +101,7 @@ async def send(self, data: bytes): await self.writer.drain() except Exception as e: log.warning("Send exception: %s %s", type(e).__name__, e) + raise OSError(e) async def recv(self, length: int = 0): data = b"" diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index e64ea7930b..6a7fc505be 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -297,7 +297,11 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float self.auth_key_id ) - await self.connection.send(payload) + try: + await self.connection.send(payload) + except OSError as e: + self.results.pop(msg_id, None) + raise e if wait_response: try: From 82c81c10bdc9ca1bba13b7efcea39b5219334603 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:22:19 +0100 Subject: [PATCH 482/539] Update Pyrogram to v2.0.86 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 9d4bd6f9e4..1a53bb76a0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.85" +__version__ = "2.0.86" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From d890e5346cc9e6946b6e42addf1aad980e8369a9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:44:02 +0100 Subject: [PATCH 483/539] Clear stored_msg_ids on session stop --- pyrogram/session/session.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 6a7fc505be..3ce96a8ff3 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -149,6 +149,8 @@ async def start(self): async def stop(self): self.is_started.clear() + self.stored_msg_ids.clear() + self.ping_task_event.set() if self.ping_task is not None: From 7ee47b220d103bf1725f69913654f73a9a57b8e9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:44:25 +0100 Subject: [PATCH 484/539] Update Pyrogram to v2.0.87 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 1a53bb76a0..4b55e4f15e 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.86" +__version__ = "2.0.87" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From cf1e31c413dc6b5ad03b4b78a73fc256b3e537c7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:33:58 +0100 Subject: [PATCH 485/539] Apply security checks to each message in the container --- pyrogram/crypto/mtproto.py | 30 +------------------- pyrogram/session/session.py | 55 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index e147c22a3e..6d1521a47b 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -16,18 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import bisect from hashlib import sha256 from io import BytesIO from os import urandom -from typing import List from pyrogram.errors import SecurityCheckMismatch from pyrogram.raw.core import Message, Long from . import aes -from ..session.internals import MsgId - -STORED_MSG_IDS_MAX_SIZE = 1000 * 2 def kdf(auth_key: bytes, msg_key: bytes, outgoing: bool) -> tuple: @@ -59,8 +54,7 @@ def unpack( b: BytesIO, session_id: bytes, auth_key: bytes, - auth_key_id: bytes, - stored_msg_ids: List[int] + auth_key_id: bytes ) -> Message: SecurityCheckMismatch.check(b.read(8) == auth_key_id, "b.read(8) == auth_key_id") @@ -103,26 +97,4 @@ def unpack( # https://core.telegram.org/mtproto/security_guidelines#checking-msg-id SecurityCheckMismatch.check(message.msg_id % 2 != 0, "message.msg_id % 2 != 0") - if len(stored_msg_ids) > STORED_MSG_IDS_MAX_SIZE: - del stored_msg_ids[:STORED_MSG_IDS_MAX_SIZE // 2] - - if stored_msg_ids: - if message.msg_id < stored_msg_ids[0]: - raise SecurityCheckMismatch("The msg_id is lower than all the stored values") - - if message.msg_id in stored_msg_ids: - raise SecurityCheckMismatch("The msg_id is equal to any of the stored values") - - time_diff = (message.msg_id - MsgId()) / 2 ** 32 - - if time_diff > 30: - raise SecurityCheckMismatch("The msg_id belongs to over 30 seconds in the future. " - "Most likely the client time has to be synchronized.") - - if time_diff < -300: - raise SecurityCheckMismatch("The msg_id belongs to over 300 seconds in the past. " - "Most likely the client time has to be synchronized.") - - bisect.insort(stored_msg_ids, message.msg_id) - return message diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 3ce96a8ff3..54814906fa 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import asyncio +import bisect import logging import os from hashlib import sha1 @@ -32,7 +33,7 @@ ) from pyrogram.raw.all import layer from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalts -from .internals import MsgFactory +from .internals import MsgId, MsgFactory log = logging.getLogger(__name__) @@ -50,6 +51,7 @@ class Session: MAX_RETRIES = 10 ACKS_THRESHOLD = 10 PING_INTERVAL = 5 + STORED_MSG_IDS_MAX_SIZE = 1000 * 2 def __init__( self, @@ -176,20 +178,14 @@ async def restart(self): await self.start() async def handle_packet(self, packet): - try: - data = await self.loop.run_in_executor( - pyrogram.crypto_executor, - mtproto.unpack, - BytesIO(packet), - self.session_id, - self.auth_key, - self.auth_key_id, - self.stored_msg_ids - ) - except SecurityCheckMismatch as e: - log.warning("Discarding packet: %s", e) - await self.connection.close() - return + data = await self.loop.run_in_executor( + pyrogram.crypto_executor, + mtproto.unpack, + BytesIO(packet), + self.session_id, + self.auth_key, + self.auth_key_id + ) messages = ( data.body.messages @@ -206,6 +202,33 @@ async def handle_packet(self, packet): else: self.pending_acks.add(msg.msg_id) + try: + if len(self.stored_msg_ids) > Session.STORED_MSG_IDS_MAX_SIZE: + del self.stored_msg_ids[:Session.STORED_MSG_IDS_MAX_SIZE // 2] + + if self.stored_msg_ids: + if msg.msg_id < self.stored_msg_ids[0]: + raise SecurityCheckMismatch("The msg_id is lower than all the stored values") + + if msg.msg_id in self.stored_msg_ids: + raise SecurityCheckMismatch("The msg_id is equal to any of the stored values") + + time_diff = (msg.msg_id - MsgId()) / 2 ** 32 + + if time_diff > 30: + raise SecurityCheckMismatch("The msg_id belongs to over 30 seconds in the future. " + "Most likely the client time has to be synchronized.") + + if time_diff < -300: + raise SecurityCheckMismatch("The msg_id belongs to over 300 seconds in the past. " + "Most likely the client time has to be synchronized.") + except SecurityCheckMismatch as e: + log.warning("Discarding packet: %s", e) + await self.connection.close() + return + else: + bisect.insort(self.stored_msg_ids, msg.msg_id) + if isinstance(msg.body, (raw.types.MsgDetailedInfo, raw.types.MsgNewDetailedInfo)): self.pending_acks.add(msg.body.answer_msg_id) continue @@ -323,7 +346,7 @@ async def send(self, data: TLObject, wait_response: bool = True, timeout: float RPCError.raise_it(result, type(data)) if isinstance(result, raw.types.BadMsgNotification): - raise BadMsgNotification(result.error_code) + log.warning("%s: %s", BadMsgNotification.__name__, BadMsgNotification(result.error_code)) if isinstance(result, raw.types.BadServerSalt): self.salt = result.new_server_salt From fbf722d2653064afe3c751841e10dc5d5a830a1c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:35:06 +0100 Subject: [PATCH 486/539] Update Pyrogram to v2.0.88 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 4b55e4f15e..35bf819bbd 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.87" +__version__ = "2.0.88" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From e0dda5ab26ed2952e0ba70ffb0b147adb86b1c3b Mon Sep 17 00:00:00 2001 From: Nick <64551534+null-nick@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:10:37 +0100 Subject: [PATCH 487/539] Update API schema to Layer 151 (#1182) --- compiler/api/source/main_api.tl | 43 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index e4f1ac0e9c..df85bdf82c 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -36,15 +36,15 @@ inputFile#f52ff27f id:long parts:int name:string md5_checksum:string = InputFile inputFileBig#fa4f0bb5 id:long parts:int name:string = InputFile; 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; +inputMediaUploadedPhoto#1e287d04 flags:# spoiler:flags.2?true file:InputFile stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; +inputMediaPhoto#b3ba0635 flags:# spoiler:flags.1?true id:InputPhoto ttl_seconds:flags.0?int = InputMedia; inputMediaGeoPoint#f9c44144 geo_point:InputGeoPoint = InputMedia; inputMediaContact#f8ab7dfb phone_number:string first_name:string last_name:string vcard:string = InputMedia; -inputMediaUploadedDocument#5b38c6c1 flags:# nosound_video:flags.3?true force_file:flags.4?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; -inputMediaDocument#33473058 flags:# id:InputDocument ttl_seconds:flags.0?int query:flags.1?string = InputMedia; +inputMediaUploadedDocument#5b38c6c1 flags:# nosound_video:flags.3?true force_file:flags.4?true spoiler:flags.5?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; +inputMediaDocument#33473058 flags:# spoiler:flags.2?true id:InputDocument ttl_seconds:flags.0?int query:flags.1?string = InputMedia; inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string = InputMedia; -inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = InputMedia; -inputMediaDocumentExternal#fb52dc99 flags:# url:string ttl_seconds:flags.0?int = InputMedia; +inputMediaPhotoExternal#e5bbfe1a flags:# spoiler:flags.1?true url:string ttl_seconds:flags.0?int = InputMedia; +inputMediaDocumentExternal#fb52dc99 flags:# spoiler:flags.1?true url:string ttl_seconds:flags.0?int = InputMedia; inputMediaGame#d33f43f3 id:InputGame = InputMedia; inputMediaInvoice#8eb5a6d5 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:flags.1?string extended_media:flags.2?InputMedia = InputMedia; inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia; @@ -91,7 +91,7 @@ userEmpty#d3bc4b7a id:long = User; user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; -userProfilePhoto#82d1f706 flags:# has_video:flags.0?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto; +userProfilePhoto#82d1f706 flags:# has_video:flags.0?true personal:flags.2?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto; userStatusEmpty#9d05049 = UserStatus; userStatusOnline#edb93949 expires:int = UserStatus; @@ -107,7 +107,7 @@ channel#83259464 flags:# creator:flags.0?true left:flags.2?true broadcast:flags. channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat; chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull; -channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull; +channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull; chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant; chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant; @@ -124,11 +124,11 @@ message#38116ee0 flags:# out:flags.1?true mentioned:flags.4?true media_unread:fl messageService#2b085862 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?Peer peer_id:Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction ttl_period:flags.25?int = Message; messageMediaEmpty#3ded6320 = MessageMedia; -messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia; +messageMediaPhoto#695150d7 flags:# spoiler:flags.3?true photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia; messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; messageMediaContact#70322949 phone_number:string first_name:string last_name:string vcard:string user_id:long = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; -messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; +messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true spoiler:flags.4?true document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia; messageMediaGame#fdb19008 game:Game = MessageMedia; @@ -172,6 +172,8 @@ messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction; messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = MessageAction; messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction; messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction; +messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction; +messageActionAttachMenuBotAllowed#e7e75f97 = MessageAction; dialog#d58a08c6 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -222,7 +224,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason; inputReportReasonIllegalDrugs#a8eb2be = ReportReason; inputReportReasonPersonalDetails#9ec7863d = ReportReason; -userFull#c4b1fc3f flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true id:long about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; +userFull#f8d32aed flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; contact#145ade0b user_id:long mutual:Bool = Contact; @@ -280,7 +282,6 @@ updateChatUserTyping#83487af0 chat_id:long from_id:Peer action:SendMessageAction updateChatParticipants#7761198 participants:ChatParticipants = Update; updateUserStatus#e5bdf8de user_id:long status:UserStatus = Update; updateUserName#a7848924 user_id:long first_name:string last_name:string usernames:Vector = Update; -updateUserPhoto#f227868c user_id:long date:int photo:UserProfilePhoto previous:Bool = Update; updateNewEncryptedMessage#12bcbd9a message:EncryptedMessage qts:int = Update; updateEncryptedChatTyping#1710f156 chat_id:int = Update; updateEncryption#b4a2e88d chat:EncryptedChat date:int = Update; @@ -381,6 +382,7 @@ updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?tru updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update; updateChannelPinnedTopic#192efbe3 flags:# pinned:flags.0?true channel_id:long topic_id:int = Update; updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector = Update; +updateUser#20529438 user_id:long = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -525,7 +527,7 @@ documentAttributeVideo#ef02ce6 flags:# round_message:flags.0?true supports_strea documentAttributeAudio#9852f9c6 flags:# voice:flags.10?true duration:int title:flags.0?string performer:flags.1?string waveform:flags.2?bytes = DocumentAttribute; documentAttributeFilename#15590068 file_name:string = DocumentAttribute; documentAttributeHasStickers#9801d2f7 = DocumentAttribute; -documentAttributeCustomEmoji#fd149899 flags:# free:flags.0?true alt:string stickerset:InputStickerSet = DocumentAttribute; +documentAttributeCustomEmoji#fd149899 flags:# free:flags.0?true text_color:flags.1?true alt:string stickerset:InputStickerSet = DocumentAttribute; messages.stickersNotModified#f1749a22 = messages.Stickers; messages.stickers#30a6ec7e hash:long stickers:Vector = messages.Stickers; @@ -603,7 +605,7 @@ keyboardButtonRow#77608b83 buttons:Vector = KeyboardButtonRow; replyKeyboardHide#a03e5b85 flags:# selective:flags.2?true = ReplyMarkup; replyKeyboardForceReply#86b40b08 flags:# single_use:flags.1?true selective:flags.2?true placeholder:flags.3?string = ReplyMarkup; -replyKeyboardMarkup#85dd99d1 flags:# resize:flags.0?true single_use:flags.1?true selective:flags.2?true rows:Vector placeholder:flags.3?string = ReplyMarkup; +replyKeyboardMarkup#85dd99d1 flags:# resize:flags.0?true single_use:flags.1?true selective:flags.2?true persistent:flags.4?true rows:Vector placeholder:flags.3?string = ReplyMarkup; replyInlineMarkup#48a30254 rows:Vector = ReplyMarkup; messageEntityUnknown#bb92ba95 offset:int length:int = MessageEntity; @@ -758,6 +760,7 @@ messages.stickerSetInstallResultArchive#35e410a8 sets:Vector stickerSetCovered#6410a5d2 set:StickerSet cover:Document = StickerSetCovered; stickerSetMultiCovered#3407e51b set:StickerSet covers:Vector = StickerSetCovered; stickerSetFullCovered#40d13c0e set:StickerSet packs:Vector keywords:Vector documents:Vector = StickerSetCovered; +stickerSetNoCovered#77b15d1c set:StickerSet = StickerSetCovered; maskCoords#aed6dbb2 n:int x:double y:double zoom:double = MaskCoords; @@ -1357,7 +1360,7 @@ attachMenuBotIconColor#4576f3f0 name:string color:int = AttachMenuBotIconColor; attachMenuBotIcon#b2a7386b flags:# name:string icon:Document colors:flags.0?Vector = AttachMenuBotIcon; -attachMenuBot#c8aa2cd2 flags:# inactive:flags.0?true has_settings:flags.1?true bot_id:long short_name:string peer_types:Vector icons:Vector = AttachMenuBot; +attachMenuBot#c8aa2cd2 flags:# inactive:flags.0?true has_settings:flags.1?true request_write_access:flags.2?true bot_id:long short_name:string peer_types:Vector icons:Vector = AttachMenuBot; attachMenuBotsNotModified#f1d88a5c = AttachMenuBots; attachMenuBots#3c4301c0 hash:long bots:Vector users:Vector = AttachMenuBots; @@ -1759,7 +1762,7 @@ messages.readReactions#54aa7f8e flags:# peer:InputPeer top_msg_id:flags.0?int = messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = messages.Messages; messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots; messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot; -messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool; +messages.toggleBotInAttachMenu#69f59d69 flags:# write_allowed:flags.0?true bot:InputUser enabled:Bool = Bool; messages.requestWebView#178b480b flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON platform:string reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = WebViewResult; messages.prolongWebView#7ff34309 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = Bool; messages.requestSimpleWebView#299bec8e flags:# bot:InputUser url:string theme_params:flags.0?DataJSON platform:string = SimpleWebViewResult; @@ -1782,10 +1785,11 @@ updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference; -photos.updateProfilePhoto#72d4742c id:InputPhoto = photos.Photo; -photos.uploadProfilePhoto#89f30f69 flags:# file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = photos.Photo; +photos.updateProfilePhoto#1c3d5956 flags:# fallback:flags.0?true id:InputPhoto = photos.Photo; +photos.uploadProfilePhoto#89f30f69 flags:# fallback:flags.3?true file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = photos.Photo; photos.deletePhotos#87cf7f2f id:Vector = Vector; photos.getUserPhotos#91cd32a8 user_id:InputUser offset:int max_id:long limit:int = photos.Photos; +photos.uploadContactProfilePhoto#b91a83bf flags:# suggest:flags.3?true save:flags.4?true user_id:InputUser file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = photos.Photo; upload.saveFilePart#b304a621 file_id:long file_part:int bytes:bytes = Bool; upload.getFile#be5335be flags:# precise:flags.0?true cdn_supported:flags.1?true location:InputFileLocation offset:long limit:int = upload.File; @@ -1874,6 +1878,7 @@ channels.deleteTopicHistory#34435f2d channel:InputChannel top_msg_id:int = messa channels.reorderPinnedForumTopics#2950a18f flags:# force:flags.0?true channel:InputChannel order:Vector = Updates; channels.toggleAntiSpam#68f3e4eb channel:InputChannel enabled:Bool = Updates; channels.reportAntiSpamFalsePositive#a850a693 channel:InputChannel msg_id:int = Bool; +channels.toggleParticipantsHidden#6a6e7854 channel:InputChannel enabled:Bool = Updates; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1952,4 +1957,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 150 \ No newline at end of file +// LAYER 151 From ef29b3c519b8459ba207b603a528acd5590014c4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:06:51 +0100 Subject: [PATCH 488/539] Add the field has_media_spoiler to the class Message --- pyrogram/types/messages_and_media/message.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index ef249771fd..6397d6f43d 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -136,6 +136,9 @@ class Message(Object, Update): has_protected_content (``bool``, *optional*): True, if the message can't be forwarded. + has_media_spoiler (``bool``, *optional*): + True, if the message media is covered by a spoiler animation. + text (``str``, *optional*): For text messages, the actual UTF-8 text of the message, 0-4096 characters. If the message contains entities (bold, italic, ...) you can access *text.markdown* or @@ -332,6 +335,7 @@ def __init__( media_group_id: str = None, author_signature: str = None, has_protected_content: bool = None, + has_media_spoiler: bool = None, text: Str = None, entities: List["types.MessageEntity"] = None, caption_entities: List["types.MessageEntity"] = None, @@ -408,6 +412,7 @@ def __init__( self.media_group_id = media_group_id self.author_signature = author_signature self.has_protected_content = has_protected_content + self.has_media_spoiler = has_media_spoiler self.text = text self.entities = entities self.caption_entities = caption_entities @@ -777,6 +782,7 @@ async def _parse( ), author_signature=message.post_author, has_protected_content=message.noforwards, + has_media_spoiler=media and media.spoiler, forward_from=forward_from, forward_sender_name=forward_sender_name, forward_from_chat=forward_from_chat, From c707a4baaee5cccb79c618f715020983b966b8bf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:08:55 +0100 Subject: [PATCH 489/539] Add the parameter has_spoiler to relevant send_* media methods - send_photo() - send_video() - send_animation() --- pyrogram/methods/messages/send_animation.py | 9 ++++++++- pyrogram/methods/messages/send_photo.py | 13 ++++++++++--- pyrogram/methods/messages/send_video.py | 9 ++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index ec85dc0569..bac16bac9f 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -39,6 +39,7 @@ async def send_animation( unsave: bool = False, parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, duration: int = 0, width: int = 0, height: int = 0, @@ -88,6 +89,9 @@ async def send_animation( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the animation needs to be covered with a spoiler animation. + duration (``int``, *optional*): Duration of sent animation in seconds. @@ -180,6 +184,7 @@ async def progress(current, total): mime_type=self.guess_mime_type(animation) or "video/mp4", file=file, thumb=thumb, + spoiler=has_spoiler, attributes=[ raw.types.DocumentAttributeVideo( supports_streaming=True, @@ -193,7 +198,8 @@ async def progress(current, total): ) elif re.match("^https?://", animation): media = raw.types.InputMediaDocumentExternal( - url=animation + url=animation, + spoiler=has_spoiler ) else: media = utils.get_input_media_from_file_id(animation, FileType.ANIMATION) @@ -204,6 +210,7 @@ async def progress(current, total): mime_type=self.guess_mime_type(file_name or animation.name) or "video/mp4", file=file, thumb=thumb, + spoiler=has_spoiler, attributes=[ raw.types.DocumentAttributeVideo( supports_streaming=True, diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 994f0c9322..61298a5c68 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -37,6 +37,7 @@ async def send_photo( caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None, @@ -78,6 +79,9 @@ async def send_photo( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the photo needs to be covered with a spoiler animation. + ttl_seconds (``int``, *optional*): Self-Destruct Timer. If you set a timer, the photo will self-destruct in *ttl_seconds* @@ -149,12 +153,14 @@ async def send_photo( file = await self.save_file(photo, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedPhoto( file=file, - ttl_seconds=ttl_seconds + ttl_seconds=ttl_seconds, + spoiler=has_spoiler, ) elif re.match("^https?://", photo): media = raw.types.InputMediaPhotoExternal( url=photo, - ttl_seconds=ttl_seconds + ttl_seconds=ttl_seconds, + spoiler=has_spoiler ) else: media = utils.get_input_media_from_file_id(photo, FileType.PHOTO, ttl_seconds=ttl_seconds) @@ -162,7 +168,8 @@ async def send_photo( file = await self.save_file(photo, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedPhoto( file=file, - ttl_seconds=ttl_seconds + ttl_seconds=ttl_seconds, + spoiler=has_spoiler ) while True: diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index c20530641c..e869dd172d 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -38,6 +38,7 @@ async def send_video( caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, ttl_seconds: int = None, duration: int = 0, width: int = 0, @@ -85,6 +86,9 @@ async def send_video( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the video needs to be covered with a spoiler animation. + ttl_seconds (``int``, *optional*): Self-Destruct Timer. If you set a timer, the video will self-destruct in *ttl_seconds* @@ -185,6 +189,7 @@ async def progress(current, total): mime_type=self.guess_mime_type(video) or "video/mp4", file=file, ttl_seconds=ttl_seconds, + spoiler=has_spoiler, thumb=thumb, attributes=[ raw.types.DocumentAttributeVideo( @@ -199,7 +204,8 @@ async def progress(current, total): elif re.match("^https?://", video): media = raw.types.InputMediaDocumentExternal( url=video, - ttl_seconds=ttl_seconds + ttl_seconds=ttl_seconds, + spoiler=has_spoiler ) else: media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=ttl_seconds) @@ -210,6 +216,7 @@ async def progress(current, total): mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4", file=file, ttl_seconds=ttl_seconds, + spoiler=has_spoiler, thumb=thumb, attributes=[ raw.types.DocumentAttributeVideo( From 06996d24ff7353c6a5a1118b273a48c6abe02c03 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:09:21 +0100 Subject: [PATCH 490/539] Add media_spoiler filter --- pyrogram/filters.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index ac2dbf20fd..b52dfe601d 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -425,6 +425,17 @@ async def dice_filter(_, __, m: Message): """Filter messages that contain :obj:`~pyrogram.types.Dice` objects.""" +# endregion + +# region media_spoiler +async def media_spoiler_filter(_, __, m: Message): + return bool(m.has_media_spoiler) + + +media_spoiler = create(media_spoiler_filter) +"""Filter media messages that contain a spoiler.""" + + # endregion # region private_filter @@ -731,6 +742,7 @@ async def linked_channel_filter(_, __, m: Message): linked_channel = create(linked_channel_filter) """Filter messages that are automatically forwarded from the linked channel to the group chat.""" + # endregion From a116ea42c8427ea48f1ed38856016bb943ca234f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:10:20 +0100 Subject: [PATCH 491/539] Add the field has_spoiler to relevant InputMedia* classes - InputMediaPhoto - InputMediaVideo - InputMediaAnimation --- pyrogram/types/input_media/input_media_animation.py | 7 ++++++- pyrogram/types/input_media/input_media_photo.py | 8 +++++++- pyrogram/types/input_media/input_media_video.py | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pyrogram/types/input_media/input_media_animation.py b/pyrogram/types/input_media/input_media_animation.py index 2eae1a66f0..2e91a2147b 100644 --- a/pyrogram/types/input_media/input_media_animation.py +++ b/pyrogram/types/input_media/input_media_animation.py @@ -59,6 +59,9 @@ class InputMediaAnimation(InputMedia): duration (``int``, *optional*): Animation duration. + + has_spoiler (``bool``, *optional*): + Pass True if the photo needs to be covered with a spoiler animation. """ def __init__( @@ -70,7 +73,8 @@ def __init__( caption_entities: List[MessageEntity] = None, width: int = 0, height: int = 0, - duration: int = 0 + duration: int = 0, + has_spoiler: bool = None ): super().__init__(media, caption, parse_mode, caption_entities) @@ -78,3 +82,4 @@ def __init__( self.width = width self.height = height self.duration = duration + self.has_spoiler = has_spoiler diff --git a/pyrogram/types/input_media/input_media_photo.py b/pyrogram/types/input_media/input_media_photo.py index ce8b41a218..f4fd0e0305 100644 --- a/pyrogram/types/input_media/input_media_photo.py +++ b/pyrogram/types/input_media/input_media_photo.py @@ -45,6 +45,9 @@ class InputMediaPhoto(InputMedia): caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + has_spoiler (``bool``, *optional*): + Pass True if the photo needs to be covered with a spoiler animation. """ def __init__( @@ -52,6 +55,9 @@ def __init__( media: Union[str, BinaryIO], caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: List[MessageEntity] = None + caption_entities: List[MessageEntity] = None, + has_spoiler: bool = None ): super().__init__(media, caption, parse_mode, caption_entities) + + self.has_spoiler = has_spoiler diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py index c163cba9fb..ab1823d339 100644 --- a/pyrogram/types/input_media/input_media_video.py +++ b/pyrogram/types/input_media/input_media_video.py @@ -63,6 +63,9 @@ class InputMediaVideo(InputMedia): supports_streaming (``bool``, *optional*): Pass True, if the uploaded video is suitable for streaming. + + has_spoiler (``bool``, *optional*): + Pass True if the photo needs to be covered with a spoiler animation. """ def __init__( @@ -75,7 +78,8 @@ def __init__( width: int = 0, height: int = 0, duration: int = 0, - supports_streaming: bool = True + supports_streaming: bool = True, + has_spoiler: bool = None, ): super().__init__(media, caption, parse_mode, caption_entities) @@ -84,3 +88,4 @@ def __init__( self.height = height self.duration = duration self.supports_streaming = supports_streaming + self.has_spoiler = has_spoiler From 50d87bf5e9665bb91b7d3bf1b976ccec3959d9ca Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:10:53 +0100 Subject: [PATCH 492/539] Add the field is_persistent to the class ReplyKeyboardMarkup --- .../types/bots_and_keyboards/reply_keyboard_markup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py index b62f6dcff7..2949c3e206 100644 --- a/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py +++ b/pyrogram/types/bots_and_keyboards/reply_keyboard_markup.py @@ -31,6 +31,10 @@ class ReplyKeyboardMarkup(Object): keyboard (List of List of :obj:`~pyrogram.types.KeyboardButton`): List of button rows, each represented by a List of KeyboardButton objects. + is_persistent (``bool``, *optional*): + Requests clients to always show the keyboard when the regular keyboard is hidden. + Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. + resize_keyboard (``bool``, *optional*): Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of @@ -55,6 +59,7 @@ class ReplyKeyboardMarkup(Object): def __init__( self, keyboard: List[List[Union["types.KeyboardButton", str]]], + is_persistent: bool = None, resize_keyboard: bool = None, one_time_keyboard: bool = None, selective: bool = None, @@ -63,13 +68,14 @@ def __init__( super().__init__() self.keyboard = keyboard + self.is_persistent = is_persistent self.resize_keyboard = resize_keyboard self.one_time_keyboard = one_time_keyboard self.selective = selective self.placeholder = placeholder @staticmethod - def read(kb): + def read(kb: "raw.base.ReplyMarkup"): keyboard = [] for i in kb.rows: @@ -82,6 +88,7 @@ def read(kb): return ReplyKeyboardMarkup( keyboard=keyboard, + is_persistent=kb.persistent, resize_keyboard=kb.resize, one_time_keyboard=kb.single_use, selective=kb.selective, @@ -100,5 +107,6 @@ async def write(self, _: "pyrogram.Client"): resize=self.resize_keyboard or None, single_use=self.one_time_keyboard or None, selective=self.selective or None, + persistent=self.is_persistent or None, placeholder=self.placeholder or None ) From e8bd6396344cb08310f32610150943f7c73a213f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:12:42 +0100 Subject: [PATCH 493/539] Add media spoiler support for other relevant methods - send_media_group() - edit_message_media() - edit_inline_media() --- .../methods/messages/edit_inline_media.py | 77 ++++++++++--------- .../methods/messages/edit_message_media.py | 49 +++++++----- pyrogram/methods/messages/send_media_group.py | 32 +++++--- 3 files changed, 91 insertions(+), 67 deletions(-) diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 77fa673ae6..7ab424a4f2 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -16,11 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import os -import re -import io import asyncio import io +import os +import re import pyrogram from pyrogram import raw @@ -80,8 +79,6 @@ async def edit_inline_media( caption = media.caption parse_mode = media.parse_mode - is_photo = isinstance(media, types.InputMediaPhoto) - is_bytes_io = isinstance(media.media, io.BytesIO) is_uploaded_file = is_bytes_io or os.path.isfile(media.media) @@ -99,15 +96,16 @@ async def edit_inline_media( else: filename_attribute = [] - - if is_photo: + if isinstance(media, types.InputMediaPhoto): if is_uploaded_file: media = raw.types.InputMediaUploadedPhoto( - file=await self.save_file(media.media) + file=await self.save_file(media.media), + spoiler=media.has_spoiler ) elif is_external_url: media = raw.types.InputMediaPhotoExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) @@ -117,18 +115,20 @@ async def edit_inline_media( mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "video/mp4", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), + spoiler=media.has_spoiler, attributes=[ - raw.types.DocumentAttributeVideo( - supports_streaming=media.supports_streaming or None, - duration=media.duration, - w=media.width, - h=media.height - ) - ] + filename_attribute + raw.types.DocumentAttributeVideo( + supports_streaming=media.supports_streaming or None, + duration=media.duration, + w=media.width, + h=media.height + ) + ] + filename_attribute ) elif is_external_url: media = raw.types.InputMediaDocumentExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) @@ -139,12 +139,12 @@ async def edit_inline_media( thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), attributes=[ - raw.types.DocumentAttributeAudio( - duration=media.duration, - performer=media.performer, - title=media.title - ) - ] + filename_attribute + raw.types.DocumentAttributeAudio( + duration=media.duration, + performer=media.performer, + title=media.title + ) + ] + filename_attribute ) elif is_external_url: media = raw.types.InputMediaDocumentExternal( @@ -158,20 +158,22 @@ async def edit_inline_media( mime_type=(None if is_bytes_io else self.guess_mime_type(media.media)) or "video/mp4", thumb=await self.save_file(media.thumb), file=await self.save_file(media.media), + spoiler=media.has_spoiler, attributes=[ - raw.types.DocumentAttributeVideo( - supports_streaming=True, - duration=media.duration, - w=media.width, - h=media.height - ), - raw.types.DocumentAttributeAnimated() - ] + filename_attribute, + raw.types.DocumentAttributeVideo( + supports_streaming=True, + duration=media.duration, + w=media.width, + h=media.height + ), + raw.types.DocumentAttributeAnimated() + ] + filename_attribute, nosound_video=True ) elif is_external_url: media = raw.types.InputMediaDocumentExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) @@ -196,7 +198,6 @@ async def edit_inline_media( session = await get_session(self, dc_id) - if is_uploaded_file: uploaded_media = await self.invoke( raw.functions.messages.UploadMedia( @@ -210,13 +211,15 @@ async def edit_inline_media( id=uploaded_media.photo.id, access_hash=uploaded_media.photo.access_hash, file_reference=uploaded_media.photo.file_reference - ) - ) if is_photo else raw.types.InputMediaDocument( + ), + spoiler=getattr(media, "has_spoiler", None) + ) if isinstance(media, types.InputMediaPhoto) else raw.types.InputMediaDocument( id=raw.types.InputDocument( id=uploaded_media.document.id, access_hash=uploaded_media.document.access_hash, - file_reference=uploaded_media.document.file_reference - ) + file_reference=uploaded_media.document.file_reference + ), + spoiler=getattr(media, "has_spoiler", None) ) else: actual_media = media diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index 16efb5b858..5a34f13875 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -16,9 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import io import os import re -import io from typing import Union import pyrogram @@ -93,36 +93,40 @@ async def edit_message_media( if isinstance(media, types.InputMediaPhoto): if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): - media = await self.invoke( + uploaded_media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( - file=await self.save_file(media.media) + file=await self.save_file(media.media), + spoiler=media.has_spoiler ) ) ) media = raw.types.InputMediaPhoto( id=raw.types.InputPhoto( - id=media.photo.id, - access_hash=media.photo.access_hash, - file_reference=media.photo.file_reference - ) + id=uploaded_media.photo.id, + access_hash=uploaded_media.photo.access_hash, + file_reference=uploaded_media.photo.file_reference + ), + spoiler=media.has_spoiler ) elif re.match("^https?://", media.media): media = raw.types.InputMediaPhotoExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO) elif isinstance(media, types.InputMediaVideo): if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): - media = await self.invoke( + uploaded_media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "video/mp4", thumb=await self.save_file(media.thumb), + spoiler=media.has_spoiler, file=await self.save_file(media.media), attributes=[ raw.types.DocumentAttributeVideo( @@ -141,14 +145,16 @@ async def edit_message_media( media = raw.types.InputMediaDocument( id=raw.types.InputDocument( - id=media.document.id, - access_hash=media.document.access_hash, - file_reference=media.document.file_reference - ) + id=uploaded_media.document.id, + access_hash=uploaded_media.document.access_hash, + file_reference=uploaded_media.document.file_reference + ), + spoiler=media.has_spoiler ) elif re.match("^https?://", media.media): media = raw.types.InputMediaDocumentExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO) @@ -190,12 +196,13 @@ async def edit_message_media( media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO) elif isinstance(media, types.InputMediaAnimation): if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): - media = await self.invoke( + uploaded_media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedDocument( mime_type=self.guess_mime_type(media.media) or "video/mp4", thumb=await self.save_file(media.thumb), + spoiler=media.has_spoiler, file=await self.save_file(media.media), attributes=[ raw.types.DocumentAttributeVideo( @@ -215,14 +222,16 @@ async def edit_message_media( media = raw.types.InputMediaDocument( id=raw.types.InputDocument( - id=media.document.id, - access_hash=media.document.access_hash, - file_reference=media.document.file_reference - ) + id=uploaded_media.document.id, + access_hash=uploaded_media.document.access_hash, + file_reference=uploaded_media.document.file_reference + ), + spoiler=media.has_spoiler ) elif re.match("^https?://", media.media): media = raw.types.InputMediaDocumentExternal( - url=media.media + url=media.media, + spoiler=media.has_spoiler ) else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index 0dfbbaa236..a8b905de23 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -100,7 +100,8 @@ async def send_media_group( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( - file=await self.save_file(i.media) + file=await self.save_file(i.media), + spoiler=i.has_spoiler ) ) ) @@ -110,14 +111,16 @@ async def send_media_group( id=media.photo.id, access_hash=media.photo.access_hash, file_reference=media.photo.file_reference - ) + ), + spoiler=i.has_spoiler ) elif re.match("^https?://", i.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPhotoExternal( - url=i.media + url=i.media, + spoiler=i.has_spoiler ) ) ) @@ -127,7 +130,8 @@ async def send_media_group( id=media.photo.id, access_hash=media.photo.access_hash, file_reference=media.photo.file_reference - ) + ), + spoiler=i.has_spoiler ) else: media = utils.get_input_media_from_file_id(i.media, FileType.PHOTO) @@ -136,7 +140,8 @@ async def send_media_group( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaUploadedPhoto( - file=await self.save_file(i.media) + file=await self.save_file(i.media), + spoiler=i.has_spoiler ) ) ) @@ -146,7 +151,8 @@ async def send_media_group( id=media.photo.id, access_hash=media.photo.access_hash, file_reference=media.photo.file_reference - ) + ), + spoiler=i.has_spoiler ) elif isinstance(i, types.InputMediaVideo): if isinstance(i.media, str): @@ -157,6 +163,7 @@ async def send_media_group( media=raw.types.InputMediaUploadedDocument( file=await self.save_file(i.media), thumb=await self.save_file(i.thumb), + spoiler=i.has_spoiler, mime_type=self.guess_mime_type(i.media) or "video/mp4", attributes=[ raw.types.DocumentAttributeVideo( @@ -176,14 +183,16 @@ async def send_media_group( id=media.document.id, access_hash=media.document.access_hash, file_reference=media.document.file_reference - ) + ), + spoiler=i.has_spoiler ) elif re.match("^https?://", i.media): media = await self.invoke( raw.functions.messages.UploadMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaDocumentExternal( - url=i.media + url=i.media, + spoiler=i.has_spoiler ) ) ) @@ -193,7 +202,8 @@ async def send_media_group( id=media.document.id, access_hash=media.document.access_hash, file_reference=media.document.file_reference - ) + ), + spoiler=i.has_spoiler ) else: media = utils.get_input_media_from_file_id(i.media, FileType.VIDEO) @@ -204,6 +214,7 @@ async def send_media_group( media=raw.types.InputMediaUploadedDocument( file=await self.save_file(i.media), thumb=await self.save_file(i.thumb), + spoiler=i.has_spoiler, mime_type=self.guess_mime_type(getattr(i.media, "name", "video.mp4")) or "video/mp4", attributes=[ raw.types.DocumentAttributeVideo( @@ -223,7 +234,8 @@ async def send_media_group( id=media.document.id, access_hash=media.document.access_hash, file_reference=media.document.file_reference - ) + ), + spoiler=i.has_spoiler ) elif isinstance(i, types.InputMediaAudio): if isinstance(i.media, str): From 5d3abd3ab03e8b64ff143028ecbeb224f676512a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:14:42 +0100 Subject: [PATCH 494/539] Update Pyrogram to v2.0.89 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 35bf819bbd..0ef8af6d1a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.88" +__version__ = "2.0.89" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 1e6209da3be0cee0306a53dcc1a22e115eea0a27 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:55:52 +0100 Subject: [PATCH 495/539] Add support for email sign in codes Fixes #1183 --- pyrogram/client.py | 1 + pyrogram/enums/sent_code_type.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/pyrogram/client.py b/pyrogram/client.py index 36ab4e4cf7..f4f6eee3ee 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -358,6 +358,7 @@ async def authorize(self) -> User: enums.SentCodeType.CALL: "phone call", enums.SentCodeType.FLASH_CALL: "phone flash call", enums.SentCodeType.FRAGMENT_SMS: "Fragment SMS", + enums.SentCodeType.EMAIL_CODE: "email code" } print(f"The confirmation code has been sent via {sent_code_descriptions[sent_code.type]}") diff --git a/pyrogram/enums/sent_code_type.py b/pyrogram/enums/sent_code_type.py index e3ec61120a..474ed6b0f3 100644 --- a/pyrogram/enums/sent_code_type.py +++ b/pyrogram/enums/sent_code_type.py @@ -40,3 +40,6 @@ class SentCodeType(AutoName): FRAGMENT_SMS = raw.types.auth.SentCodeTypeFragmentSms "The code was sent via Fragment SMS." + + EMAIL_CODE = raw.types.auth.SentCodeTypeEmailCode + "The code was sent via email." From 3b0dee7dd5409614c32b3572423aef9172a73d54 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:56:19 +0100 Subject: [PATCH 496/539] Update Pyrogram to v2.0.90 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 0ef8af6d1a..0b126c94ab 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.89" +__version__ = "2.0.90" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 2de8f1921cd68a88d5b3a6755c10baf85d1685fe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 18:07:15 +0100 Subject: [PATCH 497/539] Fix resolving peers for users with multiple usernames This currently makes it work for the first available username only --- pyrogram/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index f4f6eee3ee..7848c1f5b9 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -487,7 +487,11 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra if isinstance(peer, raw.types.User): peer_id = peer.id access_hash = peer.access_hash - username = (peer.username or "").lower() or None + username = ( + peer.username.lower() if peer.username + else peer.usernames[0].username.lower() if peer.usernames + else None + ) phone_number = peer.phone peer_type = "bot" if peer.bot else "user" elif isinstance(peer, (raw.types.Chat, raw.types.ChatForbidden)): From fbd62f959658a7da6ce76e589ca9419f02702a77 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 18:07:55 +0100 Subject: [PATCH 498/539] Update Pyrogram to v2.0.91 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 0b126c94ab..be51f7bb0a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.90" +__version__ = "2.0.91" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From a09c5a3b987be316a6deacc97699fc2ae9515f2a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 20:16:25 +0100 Subject: [PATCH 499/539] Set has_media_spoiler only in case of Photo, Video or Animation media --- pyrogram/types/messages_and_media/message.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 6397d6f43d..1835f63225 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -663,11 +663,13 @@ async def _parse( media = message.media media_type = None + has_media_spoiler = None if media: if isinstance(media, raw.types.MessageMediaPhoto): photo = types.Photo._parse(client, media.photo, media.ttl_seconds) media_type = enums.MessageMediaType.PHOTO + has_media_spoiler = media.spoiler elif isinstance(media, raw.types.MessageMediaGeo): location = types.Location._parse(client, media.geo) media_type = enums.MessageMediaType.LOCATION @@ -696,6 +698,7 @@ async def _parse( video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None) animation = types.Animation._parse(client, doc, video_attributes, file_name) media_type = enums.MessageMediaType.ANIMATION + has_media_spoiler = media.spoiler elif raw.types.DocumentAttributeSticker in attributes: sticker = await types.Sticker._parse(client, doc, attributes) media_type = enums.MessageMediaType.STICKER @@ -708,6 +711,7 @@ async def _parse( else: video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds) media_type = enums.MessageMediaType.VIDEO + has_media_spoiler = media.spoiler elif raw.types.DocumentAttributeAudio in attributes: audio_attributes = attributes[raw.types.DocumentAttributeAudio] @@ -782,7 +786,7 @@ async def _parse( ), author_signature=message.post_author, has_protected_content=message.noforwards, - has_media_spoiler=media and media.spoiler, + has_media_spoiler=has_media_spoiler, forward_from=forward_from, forward_sender_name=forward_sender_name, forward_from_chat=forward_from_chat, From 526aaa0f9dc2918773796058557aa041185b0ac1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 30 Dec 2022 20:18:23 +0100 Subject: [PATCH 500/539] Update Pyrogram to v2.0.92 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index be51f7bb0a..d5497ab586 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.91" +__version__ = "2.0.92" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 6752af8796041b1a8f0810fd7ea5ac5dee807149 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 31 Dec 2022 19:01:42 +0100 Subject: [PATCH 501/539] Add error messages for transport errors --- pyrogram/session/session.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 54814906fa..0dd3430539 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -53,6 +53,12 @@ class Session: PING_INTERVAL = 5 STORED_MSG_IDS_MAX_SIZE = 1000 * 2 + TRANSPORT_ERRORS = { + 404: "auth key not found", + 429: "transport flood", + 444: "invalid DC" + } + def __init__( self, client: "pyrogram.Client", @@ -292,7 +298,12 @@ async def recv_worker(self): if packet is None or len(packet) == 4: if packet: - log.warning('Server sent "%s"', Int.read(BytesIO(packet))) + error_code = -Int.read(BytesIO(packet)) + + log.warning( + "Server sent transport error: %s (%s)", + error_code, Session.TRANSPORT_ERRORS.get(error_code, "unknown error") + ) if self.is_started.is_set(): self.loop.create_task(self.restart()) From b19764d5dc9e2d59a4ccbb7f520f78505800656b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 31 Dec 2022 19:02:20 +0100 Subject: [PATCH 502/539] Update Pyrogram to v2.0.93 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index d5497ab586..5b8f537c1d 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.92" +__version__ = "2.0.93" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 8441ce2f4790f81655fe48f6fda57dad432ee798 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jan 2023 17:11:02 +0100 Subject: [PATCH 503/539] Limit the amount of concurrent transmissions --- pyrogram/client.py | 356 ++++++++++++------------- pyrogram/methods/advanced/save_file.py | 227 ++++++++-------- 2 files changed, 285 insertions(+), 298 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 7848c1f5b9..81828f5a6d 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -44,7 +44,7 @@ from pyrogram.errors import ( SessionPasswordNeeded, VolumeLocNotFound, ChannelPrivate, - AuthBytesInvalid, BadRequest + BadRequest ) from pyrogram.handlers.handler import Handler from pyrogram.methods import Methods @@ -266,6 +266,9 @@ def __init__( self.media_sessions = {} self.media_sessions_lock = asyncio.Lock() + self.save_file_lock = asyncio.Lock() + self.get_file_lock = asyncio.Lock() + self.is_connected = None self.is_initialized = None @@ -795,204 +798,93 @@ async def get_file( progress: Callable = None, progress_args: tuple = () ) -> Optional[AsyncGenerator[bytes, None]]: - dc_id = file_id.dc_id - - async with self.media_sessions_lock: - session = self.media_sessions.get(dc_id, None) + async with self.get_file_lock: + file_type = file_id.file_type - if session is None: - if dc_id != await self.storage.dc_id(): - session = Session( - self, dc_id, await Auth(self, dc_id, await self.storage.test_mode()).create(), - await self.storage.test_mode(), is_media=True + if file_type == FileType.CHAT_PHOTO: + if file_id.chat_id > 0: + peer = raw.types.InputPeerUser( + user_id=file_id.chat_id, + access_hash=file_id.chat_access_hash ) - await session.start() - - for _ in range(3): - exported_auth = await self.invoke( - raw.functions.auth.ExportAuthorization( - dc_id=dc_id - ) + else: + if file_id.chat_access_hash == 0: + peer = raw.types.InputPeerChat( + chat_id=-file_id.chat_id ) - - try: - await session.invoke( - raw.functions.auth.ImportAuthorization( - id=exported_auth.id, - bytes=exported_auth.bytes - ) - ) - except AuthBytesInvalid: - continue - else: - break else: - await session.stop() - raise AuthBytesInvalid - else: - session = Session( - self, dc_id, await self.storage.auth_key(), - await self.storage.test_mode(), is_media=True - ) - await session.start() - - self.media_sessions[dc_id] = session - - file_type = file_id.file_type + peer = raw.types.InputPeerChannel( + channel_id=utils.get_channel_id(file_id.chat_id), + access_hash=file_id.chat_access_hash + ) - if file_type == FileType.CHAT_PHOTO: - if file_id.chat_id > 0: - peer = raw.types.InputPeerUser( - user_id=file_id.chat_id, - access_hash=file_id.chat_access_hash + location = raw.types.InputPeerPhotoFileLocation( + peer=peer, + photo_id=file_id.media_id, + big=file_id.thumbnail_source == ThumbnailSource.CHAT_PHOTO_BIG + ) + elif file_type == FileType.PHOTO: + location = raw.types.InputPhotoFileLocation( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + thumb_size=file_id.thumbnail_size ) else: - if file_id.chat_access_hash == 0: - peer = raw.types.InputPeerChat( - chat_id=-file_id.chat_id - ) - else: - peer = raw.types.InputPeerChannel( - channel_id=utils.get_channel_id(file_id.chat_id), - access_hash=file_id.chat_access_hash - ) + location = raw.types.InputDocumentFileLocation( + id=file_id.media_id, + access_hash=file_id.access_hash, + file_reference=file_id.file_reference, + thumb_size=file_id.thumbnail_size + ) - location = raw.types.InputPeerPhotoFileLocation( - peer=peer, - photo_id=file_id.media_id, - big=file_id.thumbnail_source == ThumbnailSource.CHAT_PHOTO_BIG - ) - elif file_type == FileType.PHOTO: - location = raw.types.InputPhotoFileLocation( - id=file_id.media_id, - access_hash=file_id.access_hash, - file_reference=file_id.file_reference, - thumb_size=file_id.thumbnail_size - ) - else: - location = raw.types.InputDocumentFileLocation( - id=file_id.media_id, - access_hash=file_id.access_hash, - file_reference=file_id.file_reference, - thumb_size=file_id.thumbnail_size - ) + current = 0 + total = abs(limit) or (1 << 31) - 1 + chunk_size = 1024 * 1024 + offset_bytes = abs(offset) * chunk_size - current = 0 - total = abs(limit) or (1 << 31) - 1 - chunk_size = 1024 * 1024 - offset_bytes = abs(offset) * chunk_size + dc_id = file_id.dc_id - try: - r = await session.invoke( - raw.functions.upload.GetFile( - location=location, - offset=offset_bytes, - limit=chunk_size - ), - sleep_threshold=30 + session = Session( + self, dc_id, + await Auth(self, dc_id, await self.storage.test_mode()).create() + if dc_id != await self.storage.dc_id() + else await self.storage.auth_key(), + await self.storage.test_mode(), + is_media=True ) - if isinstance(r, raw.types.upload.File): - while True: - chunk = r.bytes - - yield chunk - - current += 1 - offset_bytes += chunk_size + try: + await session.start() - if progress: - func = functools.partial( - progress, - min(offset_bytes, file_size) - if file_size != 0 - else offset_bytes, - file_size, - *progress_args + if dc_id != await self.storage.dc_id(): + exported_auth = await self.invoke( + raw.functions.auth.ExportAuthorization( + dc_id=dc_id ) - - if inspect.iscoroutinefunction(progress): - await func() - else: - await self.loop.run_in_executor(self.executor, func) - - if len(chunk) < chunk_size or current >= total: - break - - r = await session.invoke( - raw.functions.upload.GetFile( - location=location, - offset=offset_bytes, - limit=chunk_size - ), - sleep_threshold=30 ) - elif isinstance(r, raw.types.upload.FileCdnRedirect): - async with self.media_sessions_lock: - cdn_session = self.media_sessions.get(r.dc_id, None) - - if cdn_session is None: - cdn_session = Session( - self, r.dc_id, await Auth(self, r.dc_id, await self.storage.test_mode()).create(), - await self.storage.test_mode(), is_media=True, is_cdn=True + await session.invoke( + raw.functions.auth.ImportAuthorization( + id=exported_auth.id, + bytes=exported_auth.bytes ) + ) - await cdn_session.start() - - self.media_sessions[r.dc_id] = cdn_session + r = await session.invoke( + raw.functions.upload.GetFile( + location=location, + offset=offset_bytes, + limit=chunk_size + ), + sleep_threshold=30 + ) - try: + if isinstance(r, raw.types.upload.File): while True: - r2 = await cdn_session.invoke( - raw.functions.upload.GetCdnFile( - file_token=r.file_token, - offset=offset_bytes, - limit=chunk_size - ) - ) - - if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded): - try: - await session.invoke( - raw.functions.upload.ReuploadCdnFile( - file_token=r.file_token, - request_token=r2.request_token - ) - ) - except VolumeLocNotFound: - break - else: - continue - - chunk = r2.bytes + chunk = r.bytes - # https://core.telegram.org/cdn#decrypting-files - decrypted_chunk = aes.ctr256_decrypt( - chunk, - r.encryption_key, - bytearray( - r.encryption_iv[:-4] - + (offset_bytes // 16).to_bytes(4, "big") - ) - ) - - hashes = await session.invoke( - raw.functions.upload.GetCdnFileHashes( - file_token=r.file_token, - offset=offset_bytes - ) - ) - - # https://core.telegram.org/cdn#verifying-files - for i, h in enumerate(hashes): - cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] - CDNFileHashMismatch.check( - h.hash == sha256(cdn_chunk).digest(), - "h.hash == sha256(cdn_chunk).digest()" - ) - - yield decrypted_chunk + yield chunk current += 1 offset_bytes += chunk_size @@ -1000,7 +892,9 @@ async def get_file( if progress: func = functools.partial( progress, - min(offset_bytes, file_size) if file_size != 0 else offset_bytes, + min(offset_bytes, file_size) + if file_size != 0 + else offset_bytes, file_size, *progress_args ) @@ -1012,12 +906,104 @@ async def get_file( if len(chunk) < chunk_size or current >= total: break - except Exception as e: - raise e - except pyrogram.StopTransmission: - raise - except Exception as e: - log.exception(e) + + r = await session.invoke( + raw.functions.upload.GetFile( + location=location, + offset=offset_bytes, + limit=chunk_size + ), + sleep_threshold=30 + ) + + elif isinstance(r, raw.types.upload.FileCdnRedirect): + cdn_session = Session( + self, r.dc_id, await Auth(self, r.dc_id, await self.storage.test_mode()).create(), + await self.storage.test_mode(), is_media=True, is_cdn=True + ) + + try: + await cdn_session.start() + + while True: + r2 = await cdn_session.invoke( + raw.functions.upload.GetCdnFile( + file_token=r.file_token, + offset=offset_bytes, + limit=chunk_size + ) + ) + + if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded): + try: + await session.invoke( + raw.functions.upload.ReuploadCdnFile( + file_token=r.file_token, + request_token=r2.request_token + ) + ) + except VolumeLocNotFound: + break + else: + continue + + chunk = r2.bytes + + # https://core.telegram.org/cdn#decrypting-files + decrypted_chunk = aes.ctr256_decrypt( + chunk, + r.encryption_key, + bytearray( + r.encryption_iv[:-4] + + (offset_bytes // 16).to_bytes(4, "big") + ) + ) + + hashes = await session.invoke( + raw.functions.upload.GetCdnFileHashes( + file_token=r.file_token, + offset=offset_bytes + ) + ) + + # https://core.telegram.org/cdn#verifying-files + for i, h in enumerate(hashes): + cdn_chunk = decrypted_chunk[h.limit * i: h.limit * (i + 1)] + CDNFileHashMismatch.check( + h.hash == sha256(cdn_chunk).digest(), + "h.hash == sha256(cdn_chunk).digest()" + ) + + yield decrypted_chunk + + current += 1 + offset_bytes += chunk_size + + if progress: + func = functools.partial( + progress, + min(offset_bytes, file_size) if file_size != 0 else offset_bytes, + file_size, + *progress_args + ) + + if inspect.iscoroutinefunction(progress): + await func() + else: + await self.loop.run_in_executor(self.executor, func) + + if len(chunk) < chunk_size or current >= total: + break + except Exception as e: + raise e + finally: + await cdn_session.stop() + except pyrogram.StopTransmission: + raise + except Exception as e: + log.exception(e) + finally: + await session.stop() def guess_mime_type(self, filename: str) -> Optional[str]: return self.mimetypes.guess_type(filename)[0] diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index 5ecac6d80e..e683fe52d9 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -94,132 +94,133 @@ async def save_file( Raises: RPCError: In case of a Telegram RPC error. """ - if path is None: - return None + async with self.save_file_lock: + if path is None: + return None - async def worker(session): - while True: - data = await queue.get() + async def worker(session): + while True: + data = await queue.get() - if data is None: - return + if data is None: + return - try: - await session.invoke(data) - except Exception as e: - log.exception(e) + try: + await session.invoke(data) + except Exception as e: + log.exception(e) - part_size = 512 * 1024 + part_size = 512 * 1024 - if isinstance(path, (str, PurePath)): - fp = open(path, "rb") - elif isinstance(path, io.IOBase): - fp = path - else: - raise ValueError("Invalid file. Expected a file path as string or a binary (not text) file pointer") - - file_name = getattr(fp, "name", "file.jpg") - - fp.seek(0, os.SEEK_END) - file_size = fp.tell() - fp.seek(0) - - if file_size == 0: - raise ValueError("File size equals to 0 B") - - file_size_limit_mib = 4000 if self.me.is_premium else 2000 - - if file_size > file_size_limit_mib * 1024 * 1024: - raise ValueError(f"Can't upload files bigger than {file_size_limit_mib} MiB") - - file_total_parts = int(math.ceil(file_size / part_size)) - is_big = file_size > 10 * 1024 * 1024 - workers_count = 4 if is_big else 1 - is_missing_part = file_id is not None - 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, await self.storage.dc_id(), await self.storage.auth_key(), - await self.storage.test_mode(), is_media=True - ) - workers = [self.loop.create_task(worker(session)) for _ in range(workers_count)] - queue = asyncio.Queue(1) - - try: - await session.start() + if isinstance(path, (str, PurePath)): + fp = open(path, "rb") + elif isinstance(path, io.IOBase): + fp = path + else: + raise ValueError("Invalid file. Expected a file path as string or a binary (not text) file pointer") + + file_name = getattr(fp, "name", "file.jpg") + + fp.seek(0, os.SEEK_END) + file_size = fp.tell() + fp.seek(0) + + if file_size == 0: + raise ValueError("File size equals to 0 B") + + file_size_limit_mib = 4000 if self.me.is_premium else 2000 + + if file_size > file_size_limit_mib * 1024 * 1024: + raise ValueError(f"Can't upload files bigger than {file_size_limit_mib} MiB") + + file_total_parts = int(math.ceil(file_size / part_size)) + is_big = file_size > 10 * 1024 * 1024 + workers_count = 4 if is_big else 1 + is_missing_part = file_id is not None + 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, await self.storage.dc_id(), await self.storage.auth_key(), + await self.storage.test_mode(), is_media=True + ) + workers = [self.loop.create_task(worker(session)) for _ in range(workers_count)] + queue = asyncio.Queue(1) + + try: + await session.start() + + fp.seek(part_size * file_part) + + while True: + chunk = fp.read(part_size) + + if not chunk: + if not is_big and not is_missing_part: + md5_sum = "".join([hex(i)[2:].zfill(2) for i in md5_sum.digest()]) + break + + if is_big: + rpc = raw.functions.upload.SaveBigFilePart( + file_id=file_id, + file_part=file_part, + file_total_parts=file_total_parts, + bytes=chunk + ) + else: + rpc = raw.functions.upload.SaveFilePart( + file_id=file_id, + file_part=file_part, + bytes=chunk + ) - fp.seek(part_size * file_part) + await queue.put(rpc) - while True: - chunk = fp.read(part_size) + if is_missing_part: + return - if not chunk: if not is_big and not is_missing_part: - md5_sum = "".join([hex(i)[2:].zfill(2) for i in md5_sum.digest()]) - break - + md5_sum.update(chunk) + + file_part += 1 + + if progress: + func = functools.partial( + progress, + min(file_part * part_size, file_size), + file_size, + *progress_args + ) + + if inspect.iscoroutinefunction(progress): + await func() + else: + await self.loop.run_in_executor(self.executor, func) + except StopTransmission: + raise + except Exception as e: + log.exception(e) + else: if is_big: - rpc = raw.functions.upload.SaveBigFilePart( - file_id=file_id, - file_part=file_part, - file_total_parts=file_total_parts, - bytes=chunk + return raw.types.InputFileBig( + id=file_id, + parts=file_total_parts, + name=file_name, + ) else: - rpc = raw.functions.upload.SaveFilePart( - file_id=file_id, - file_part=file_part, - bytes=chunk + return raw.types.InputFile( + id=file_id, + parts=file_total_parts, + name=file_name, + md5_checksum=md5_sum ) + finally: + for _ in workers: + await queue.put(None) - await queue.put(rpc) - - if is_missing_part: - return - - if not is_big and not is_missing_part: - md5_sum.update(chunk) + await asyncio.gather(*workers) - file_part += 1 + await session.stop() - if progress: - func = functools.partial( - progress, - min(file_part * part_size, file_size), - file_size, - *progress_args - ) - - if inspect.iscoroutinefunction(progress): - await func() - else: - await self.loop.run_in_executor(self.executor, func) - except StopTransmission: - raise - except Exception as e: - log.exception(e) - else: - if is_big: - return raw.types.InputFileBig( - id=file_id, - parts=file_total_parts, - name=file_name, - - ) - else: - return raw.types.InputFile( - id=file_id, - parts=file_total_parts, - name=file_name, - md5_checksum=md5_sum - ) - finally: - for _ in workers: - await queue.put(None) - - await asyncio.gather(*workers) - - await session.stop() - - if isinstance(path, (str, PurePath)): - fp.close() + if isinstance(path, (str, PurePath)): + fp.close() From aa2f18922540225de9eb266ebeee72d4ca8905d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jan 2023 17:11:22 +0100 Subject: [PATCH 504/539] Update Pyrogram to v2.0.94 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 5b8f537c1d..5e3a6b086f 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.93" +__version__ = "2.0.94" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 388c534e1f7e45b75ddca536a865dfcdfe4d6991 Mon Sep 17 00:00:00 2001 From: Nick <64551534+null-nick@users.noreply.github.com> Date: Sun, 8 Jan 2023 17:20:36 +0100 Subject: [PATCH 505/539] Add BOT_ONESIDE_NOT_AVAIL to known errors (#1073) * `BOT_ONESIDE_NOT_AVAIL` * Update 400_BAD_REQUEST.tsv Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/errors/source/400_BAD_REQUEST.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 1ad4c6a593..52d229ecc3 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -355,3 +355,4 @@ WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media YOU_BLOCKED_USER You blocked this user ENTITY_BOUNDS_INVALID The message entity bounds are invalid +BOT_ONESIDE_NOT_AVAIL Bots can't pin messages for one side only in private chats From 24018532c887a61171cabc7c233caec31b41f1d3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jan 2023 17:22:15 +0100 Subject: [PATCH 506/539] Add INVITE_REQUEST_SENT to known errors --- compiler/errors/source/400_BAD_REQUEST.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 52d229ecc3..7ba6e90afa 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -356,3 +356,4 @@ WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media YOU_BLOCKED_USER You blocked this user ENTITY_BOUNDS_INVALID The message entity bounds are invalid BOT_ONESIDE_NOT_AVAIL Bots can't pin messages for one side only in private chats +INVITE_REQUEST_SENT The request to join this chat or channel has been successfully sent From f9a9673011bdd4d589d7b493a3f0bdd214059645 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 8 Jan 2023 17:22:42 +0100 Subject: [PATCH 507/539] Update Pyrogram to v2.0.95 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 5e3a6b086f..fe075d685a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.94" +__version__ = "2.0.95" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 043734f02b2dc3a239525028ec186354c251037b Mon Sep 17 00:00:00 2001 From: Mahesh <44301650+Mahesh0253@users.noreply.github.com> Date: Mon, 9 Jan 2023 19:32:20 +0530 Subject: [PATCH 508/539] Add BUTTON_USER_PRIVACY_RESTRICTED to the list of known errors (#1193) * Add BUTTON_USER_PRIVACY_RESTRICTED to known errors * Update 400_BAD_REQUEST.tsv Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- compiler/errors/source/400_BAD_REQUEST.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 7ba6e90afa..3707dee461 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -38,6 +38,7 @@ BROADCAST_REQUIRED The request can only be used with a channel BUTTON_DATA_INVALID The button callback data is invalid or too large BUTTON_TYPE_INVALID The type of one of the buttons you provided is invalid BUTTON_URL_INVALID The button url is invalid +BUTTON_USER_PRIVACY_RESTRICTED The privacy settings of the user specified in a keyboard button do not allow creating such button CALL_ALREADY_ACCEPTED The call is already accepted CALL_ALREADY_DECLINED The call is already declined CALL_PEER_INVALID The provided call peer object is invalid From d53e1c235b0814e6a2d5260fd4668f42c92b5348 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:19:55 +0100 Subject: [PATCH 509/539] Lower the logging level of some log calls --- pyrogram/client.py | 2 +- pyrogram/connection/transport/tcp/tcp.py | 4 ++-- pyrogram/methods/auth/terminate.py | 2 +- pyrogram/methods/utilities/start.py | 2 +- pyrogram/parser/html.py | 2 +- pyrogram/session/session.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 81828f5a6d..90aeb1f90e 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -540,7 +540,7 @@ async def handle_updates(self, updates): pts_count = getattr(update, "pts_count", None) if isinstance(update, raw.types.UpdateChannelTooLong): - log.warning(update) + log.info(update) if isinstance(update, raw.types.UpdateNewChannelMessage) and is_min: message = update.message diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 08a435cee9..82ef033be4 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -91,7 +91,7 @@ async def close(self): self.writer.close() await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT) except Exception as e: - log.warning("Close exception: %s %s", type(e).__name__, e) + log.info("Close exception: %s %s", type(e).__name__, e) async def send(self, data: bytes): async with self.lock: @@ -100,7 +100,7 @@ async def send(self, data: bytes): self.writer.write(data) await self.writer.drain() except Exception as e: - log.warning("Send exception: %s %s", type(e).__name__, e) + log.info("Send exception: %s %s", type(e).__name__, e) raise OSError(e) async def recv(self, length: int = 0): diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 70cfc80e65..d5fd949cba 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -41,7 +41,7 @@ async def terminate( if self.takeout_id: await self.invoke(raw.functions.account.FinishTakeoutSession()) - log.warning("Takeout session %s finished", self.takeout_id) + log.info("Takeout session %s finished", self.takeout_id) await self.storage.save() await self.dispatcher.stop() diff --git a/pyrogram/methods/utilities/start.py b/pyrogram/methods/utilities/start.py index 19a7eb7cf3..d8314da182 100644 --- a/pyrogram/methods/utilities/start.py +++ b/pyrogram/methods/utilities/start.py @@ -63,7 +63,7 @@ async def main(): if not await self.storage.is_bot() and self.takeout: self.takeout_id = (await self.invoke(raw.functions.account.InitTakeoutSession())).id - log.warning("Takeout session %s initiated", self.takeout_id) + log.info("Takeout session %s initiated", self.takeout_id) await self.invoke(raw.functions.updates.GetState()) except (Exception, KeyboardInterrupt): diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 7edb7f3c99..46722a8c40 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -131,7 +131,7 @@ async def parse(self, text: str): for tag, entities in parser.tag_entities.items(): unclosed_tags.append(f"<{tag}> (x{len(entities)})") - log.warning("Unclosed tags: %s", ", ".join(unclosed_tags)) + log.info("Unclosed tags: %s", ", ".join(unclosed_tags)) entities = [] diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 0dd3430539..664416be41 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -229,7 +229,7 @@ async def handle_packet(self, packet): raise SecurityCheckMismatch("The msg_id belongs to over 300 seconds in the past. " "Most likely the client time has to be synchronized.") except SecurityCheckMismatch as e: - log.warning("Discarding packet: %s", e) + log.info("Discarding packet: %s", e) await self.connection.close() return else: From a58e19827a524b713222c1e0e2da2fb7eb3a79ae Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:22:10 +0100 Subject: [PATCH 510/539] Sort the lists of known errors --- compiler/errors/source/400_BAD_REQUEST.tsv | 10 +++++----- compiler/errors/source/403_FORBIDDEN.tsv | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 3707dee461..08ecb7a676 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -28,6 +28,7 @@ BOT_INLINE_DISABLED The inline feature of the bot is disabled BOT_INVALID This is not a valid bot BOT_METHOD_INVALID The method can't be used by bots BOT_MISSING This method can only be run by a bot +BOT_ONESIDE_NOT_AVAIL Bots can't pin messages for one side only in private chats BOT_PAYMENTS_DISABLED This method can only be run by a bot BOT_POLLS_DISABLED Sending polls by bots has been disabled BOT_RESPONSE_TIMEOUT The bot did not answer to the callback query in time @@ -101,6 +102,7 @@ ENCRYPTION_ALREADY_DECLINED The secret chat is already declined ENCRYPTION_DECLINED The secret chat was declined ENCRYPTION_ID_INVALID The provided secret chat id is invalid ENTITIES_TOO_LONG The entity provided contains data that is too long, or you passed too many entities to this message +ENTITY_BOUNDS_INVALID The message entity bounds are invalid ENTITY_MENTION_USER_INVALID The mentioned entity is not an user ERROR_TEXT_EMPTY The provided error message is empty EXPIRE_DATE_INVALID The expiration date is invalid @@ -154,6 +156,7 @@ INPUT_USER_DEACTIVATED The target user has been deleted/deactivated INVITE_HASH_EMPTY The invite hash is empty INVITE_HASH_EXPIRED The chat invite link is no longer valid INVITE_HASH_INVALID The invite link hash is invalid +INVITE_REQUEST_SENT The request to join this chat or channel has been successfully sent INVITE_REVOKED_MISSING The action required a chat invite link to be revoked first LANG_PACK_INVALID The provided language pack is invalid LASTNAME_INVALID The last name is invalid @@ -297,8 +300,8 @@ STICKER_INVALID The provided sticker is invalid STICKER_PNG_DIMENSIONS The sticker png dimensions are invalid STICKER_PNG_NOPNG Stickers must be png files but the provided image was not a png STICKER_TGS_NOTGS A tgs sticker file was expected, but something else was provided -STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided STICKER_THUMB_PNG_NOPNG A png sticker thumbnail file was expected, but something else was provided +STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided TAKEOUT_INVALID The takeout id is invalid TAKEOUT_REQUIRED The method must be invoked inside a takeout session TEMP_AUTH_KEY_EMPTY The temporary auth key provided is empty @@ -354,7 +357,4 @@ WEBDOCUMENT_URL_EMPTY The web document URL is empty WEBDOCUMENT_URL_INVALID The web document URL is invalid WEBPAGE_CURL_FAILED Telegram server could not fetch the provided URL WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media -YOU_BLOCKED_USER You blocked this user -ENTITY_BOUNDS_INVALID The message entity bounds are invalid -BOT_ONESIDE_NOT_AVAIL Bots can't pin messages for one side only in private chats -INVITE_REQUEST_SENT The request to join this chat or channel has been successfully sent +YOU_BLOCKED_USER You blocked this user \ No newline at end of file diff --git a/compiler/errors/source/403_FORBIDDEN.tsv b/compiler/errors/source/403_FORBIDDEN.tsv index 69777cd249..027f2e852e 100644 --- a/compiler/errors/source/403_FORBIDDEN.tsv +++ b/compiler/errors/source/403_FORBIDDEN.tsv @@ -15,6 +15,7 @@ INLINE_BOT_REQUIRED The action must be performed through an inline bot callback MESSAGE_AUTHOR_REQUIRED You are not the author of this message MESSAGE_DELETE_FORBIDDEN You don't have rights to delete messages in this chat, most likely because you are not the author of them POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method +PREMIUM_ACCOUNT_REQUIRED This action requires a premium account RIGHT_FORBIDDEN You don't have enough rights for this action, or you tried to set one or more admin rights that can't be applied to this kind of chat (channel or supergroup) SENSITIVE_CHANGE_FORBIDDEN Your sensitive content settings can't be changed at this time TAKEOUT_REQUIRED The method must be invoked inside a takeout session @@ -24,5 +25,4 @@ USER_INVALID The provided user is invalid USER_IS_BLOCKED The user is blocked USER_NOT_MUTUAL_CONTACT The provided user is not a mutual contact USER_PRIVACY_RESTRICTED The user's privacy settings is preventing you to perform this action -USER_RESTRICTED You are limited/restricted. You can't perform this action -PREMIUM_ACCOUNT_REQUIRED This action requires a premium account \ No newline at end of file +USER_RESTRICTED You are limited/restricted. You can't perform this action \ No newline at end of file From 2a7110e257171858ed701625660df227cfba7a85 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:22:36 +0100 Subject: [PATCH 511/539] Update Pyrogram to v2.0.96 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index fe075d685a..db401a85c3 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.95" +__version__ = "2.0.96" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 82b8c7792e028a7ea5f855f2e7e1fe13bdabbfcb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:19:15 +0100 Subject: [PATCH 512/539] Allow to specify a limit to concurrent transmissions --- pyrogram/client.py | 17 +++++++++++++---- pyrogram/methods/advanced/save_file.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 90aeb1f90e..9de55621f8 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -172,6 +172,11 @@ class Client(Methods): Pass True to hide the password when typing it during the login. Defaults to False, because ``getpass`` (the library used) is known to be problematic in some terminal environments. + + max_concurrent_transmissions (``bool``, *optional*): + Set the maximum amount of concurrent transmissions (uploads & downloads). + A value that is too high may result in network related issues. + Defaults to 1. """ APP_VERSION = f"Pyrogram {__version__}" @@ -189,6 +194,8 @@ class Client(Methods): # Interval of seconds in which the updates watchdog will kick in UPDATES_WATCHDOG_INTERVAL = 5 * 60 + MAX_CONCURRENT_TRANSMISSIONS = 1 + mimetypes = MimeTypes() mimetypes.readfp(StringIO(mime_types)) @@ -217,7 +224,8 @@ def __init__( no_updates: bool = None, takeout: bool = None, sleep_threshold: int = Session.SLEEP_THRESHOLD, - hide_password: bool = False + hide_password: bool = False, + max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS ): super().__init__() @@ -245,6 +253,7 @@ def __init__( self.takeout = takeout self.sleep_threshold = sleep_threshold self.hide_password = hide_password + self.max_concurrent_transmissions = max_concurrent_transmissions self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler") @@ -266,8 +275,8 @@ def __init__( self.media_sessions = {} self.media_sessions_lock = asyncio.Lock() - self.save_file_lock = asyncio.Lock() - self.get_file_lock = asyncio.Lock() + self.save_file_semaphore = asyncio.Semaphore(self.max_concurrent_transmissions) + self.get_file_semaphore = asyncio.Semaphore(self.max_concurrent_transmissions) self.is_connected = None self.is_initialized = None @@ -798,7 +807,7 @@ async def get_file( progress: Callable = None, progress_args: tuple = () ) -> Optional[AsyncGenerator[bytes, None]]: - async with self.get_file_lock: + async with self.get_file_semaphore: file_type = file_id.file_type if file_type == FileType.CHAT_PHOTO: diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index e683fe52d9..453a62af17 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -94,7 +94,7 @@ async def save_file( Raises: RPCError: In case of a Telegram RPC error. """ - async with self.save_file_lock: + async with self.save_file_semaphore: if path is None: return None From 283246a6b828706e3f2a66c19f62a41665a60338 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:25:10 +0100 Subject: [PATCH 513/539] Change connection mode --- pyrogram/connection/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 69cbb813a1..1107673f1a 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -20,7 +20,7 @@ import logging from typing import Optional -from .transport import TCP, TCPAbridgedO +from .transport import TCP, TCPAbridged from ..session.internals import DataCenter log = logging.getLogger(__name__) @@ -41,7 +41,7 @@ def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: async def connect(self): for i in range(Connection.MAX_CONNECTION_ATTEMPTS): - self.protocol = TCPAbridgedO(self.ipv6, self.proxy) + self.protocol = TCPAbridged(self.ipv6, self.proxy) try: log.info("Connecting...") From 245b7e653db22fdb5273c04af646bf3bc69db5e0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:25:42 +0100 Subject: [PATCH 514/539] Tweak Session timeouts --- 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 664416be41..0ed967a1a2 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -45,7 +45,7 @@ def __init__(self): class Session: - START_TIMEOUT = 5 + START_TIMEOUT = 2 WAIT_TIMEOUT = 15 SLEEP_THRESHOLD = 10 MAX_RETRIES = 10 From cfbc848dcf0c73acc279516e168651f95b2e2a4a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:26:08 +0100 Subject: [PATCH 515/539] Update Pyrogram to v2.0.97 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index db401a85c3..e280c304a1 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.96" +__version__ = "2.0.97" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 22e2b7ff62bfe7ea0fd3cff71f35af8e2c04683c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:30:08 +0100 Subject: [PATCH 516/539] Update bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index b03ff7dc5e..1150af6099 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -4,6 +4,7 @@ body: - type: checkboxes attributes: label: Checklist + description: Invalid, incomplete or inadequate issue reports will not be considered options: - label: I am sure the error is coming from Pyrogram's code and not elsewhere required: true @@ -34,7 +35,7 @@ body: - type: textarea attributes: label: Code example - description: Provide a [minimal, reproducible](https://stackoverflow.com/help/minimal-reproducible-example) and properly formatted example (if applicable) + description: Provide a [minimal, complete, consistently reproducible](https://stackoverflow.com/help/minimal-reproducible-example) and properly formatted example involving normal usages (if applicable) placeholder: | from pyrogram import Client ... From 5c5dce662025b0cc59106f526b7f1d3fe949361a Mon Sep 17 00:00:00 2001 From: Nick <64551534+null-nick@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:34:43 +0100 Subject: [PATCH 517/539] Update API schema to Layer 152 (#1207) --- compiler/api/source/main_api.tl | 72 +++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index df85bdf82c..670bd8dc91 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -52,7 +52,7 @@ inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector s inputMediaDice#e66fbf7b emoticon:string = InputMedia; inputChatPhotoEmpty#1ca48f57 = InputChatPhoto; -inputChatUploadedPhoto#c642724e flags:# file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = InputChatPhoto; +inputChatUploadedPhoto#bdcdaec0 flags:# file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.3?VideoSize = InputChatPhoto; inputChatPhoto#8953ad37 id:InputPhoto = InputChatPhoto; inputGeoPointEmpty#e4c123d6 = InputGeoPoint; @@ -106,8 +106,8 @@ chatForbidden#6592a1a7 id:long title:string = Chat; channel#83259464 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true forum:flags.30?true flags2:# id:long access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int usernames:flags2.0?Vector = Chat; channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat; -chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull; -channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull; +chatFull#c9d31138 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true translations_disabled:flags.19?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions = ChatFull; +channelFull#f2355507 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true translations_disabled:flags2.3?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions = ChatFull; chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant; chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant; @@ -174,6 +174,7 @@ messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_ messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction; messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction; messageActionAttachMenuBotAllowed#e7e75f97 = MessageAction; +messageActionRequestedPeer#fe77345d button_id:int peer:Peer = MessageAction; dialog#d58a08c6 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -192,8 +193,9 @@ geoPointEmpty#1117dd5f = GeoPoint; geoPoint#b2a2f663 flags:# long:double lat:double access_hash:long accuracy_radius:flags.0?int = GeoPoint; auth.sentCode#5e002502 flags:# type:auth.SentCodeType phone_code_hash:string next_type:flags.1?auth.CodeType timeout:flags.2?int = auth.SentCode; +auth.sentCodeSuccess#2390fe44 authorization:auth.Authorization = auth.SentCode; -auth.authorization#33fb7bb8 flags:# setup_password_required:flags.1?true otherwise_relogin_days:flags.1?int tmp_sessions:flags.0?int user:User = auth.Authorization; +auth.authorization#2ea2c0d4 flags:# setup_password_required:flags.1?true otherwise_relogin_days:flags.1?int tmp_sessions:flags.0?int future_auth_token:flags.2?bytes user:User = auth.Authorization; auth.authorizationSignUpRequired#44747e9a flags:# terms_of_service:flags.0?help.TermsOfService = auth.Authorization; auth.exportedAuthorization#b434e2b8 id:long bytes:bytes = auth.ExportedAuthorization; @@ -224,7 +226,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason; inputReportReasonIllegalDrugs#a8eb2be = ReportReason; inputReportReasonPersonalDetails#9ec7863d = ReportReason; -userFull#f8d32aed flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; +userFull#f8d32aed flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; contact#145ade0b user_id:long mutual:Bool = Contact; @@ -383,6 +385,7 @@ updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageE updateChannelPinnedTopic#192efbe3 flags:# pinned:flags.0?true channel_id:long topic_id:int = Update; updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector = Update; updateUser#20529438 user_id:long = Update; +updateAutoSaveSettings#ec05b097 = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -600,6 +603,7 @@ inputKeyboardButtonUserProfile#e988037b text:string user_id:InputUser = Keyboard keyboardButtonUserProfile#308660c1 text:string user_id:long = KeyboardButton; keyboardButtonWebView#13767230 text:string url:string = KeyboardButton; keyboardButtonSimpleWebView#a0c0505c text:string url:string = KeyboardButton; +keyboardButtonRequestPeer#d0b468c text:string button_id:int peer_type:RequestPeerType = KeyboardButton; keyboardButtonRow#77608b83 buttons:Vector = KeyboardButtonRow; @@ -714,6 +718,7 @@ auth.sentCodeTypeMissedCall#82006484 prefix:string length:int = auth.SentCodeTyp auth.sentCodeTypeEmailCode#5a159841 flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int next_phone_login_date:flags.2?int = auth.SentCodeType; auth.sentCodeTypeSetUpEmailRequired#a5491dea flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true = auth.SentCodeType; auth.sentCodeTypeFragmentSms#d9565c39 url:string length:int = auth.SentCodeType; +auth.sentCodeTypeFirebaseSms#e57b1432 flags:# nonce:flags.0?bytes receipt:flags.1?string push_timeout:flags.1?int length:int = auth.SentCodeType; messages.botCallbackAnswer#36585ea4 flags:# alert:flags.1?true has_url:flags.3?true native_ui:flags.4?true message:flags.0?string url:flags.2?string cache_time:int = messages.BotCallbackAnswer; @@ -1114,7 +1119,7 @@ statsURL#47a971e0 url:string = StatsURL; chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true manage_call:flags.11?true other:flags.12?true manage_topics:flags.13?true = ChatAdminRights; -chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true manage_topics:flags.18?true until_date:int = ChatBannedRights; +chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true manage_topics:flags.18?true send_photos:flags.19?true send_videos:flags.20?true send_roundvideos:flags.21?true send_audios:flags.22?true send_voices:flags.23?true send_docs:flags.24?true send_plain:flags.25?true until_date:int = ChatBannedRights; inputWallPaper#e630b979 id:long access_hash:long = InputWallPaper; inputWallPaperSlug#72091c80 slug:string = InputWallPaper; @@ -1123,7 +1128,7 @@ inputWallPaperNoFile#967a462e id:long = InputWallPaper; account.wallPapersNotModified#1c199183 = account.WallPapers; account.wallPapers#cdc3858c hash:long wallpapers:Vector = account.WallPapers; -codeSettings#8a6469c2 flags:# allow_flashcall:flags.0?true current_number:flags.1?true allow_app_hash:flags.4?true allow_missed_call:flags.5?true logout_tokens:flags.6?Vector = CodeSettings; +codeSettings#ad253d78 flags:# allow_flashcall:flags.0?true current_number:flags.1?true allow_app_hash:flags.4?true allow_missed_call:flags.5?true allow_firebase:flags.7?true logout_tokens:flags.6?Vector token:flags.8?string app_sandbox:flags.8?Bool = CodeSettings; wallPaperSettings#1dc1bca4 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int = WallPaperSettings; @@ -1221,6 +1226,8 @@ help.promoDataEmpty#98f6ac75 expires:int = help.PromoData; help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:Peer chats:Vector users:Vector psa_type:flags.1?string psa_message:flags.2?string = help.PromoData; videoSize#de33b094 flags:# type:string w:int h:int size:int video_start_ts:flags.0?double = VideoSize; +videoSizeEmojiMarkup#f85c413c emoji_id:long background_colors:Vector = VideoSize; +videoSizeStickerMarkup#da082fe stickerset:InputStickerSet sticker_id:long background_colors:Vector = VideoSize; statsGroupTopPoster#9d04af9b user_id:long messages:int avg_chars:int = StatsGroupTopPoster; @@ -1345,9 +1352,6 @@ availableReaction#c077ec01 flags:# inactive:flags.0?true premium:flags.2?true re messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions; messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions; -messages.translateNoResult#67ca4737 = messages.TranslatedText; -messages.translateResultText#a214f7d0 text:string = messages.TranslatedText; - messagePeerReaction#b156fe9c flags:# big:flags.0?true unread:flags.1?true peer_id:Peer reaction:Reaction = MessagePeerReaction; groupCallStreamChannel#80eb48af channel:int scale:int last_timestamp_ms:long = GroupCallStreamChannel; @@ -1403,7 +1407,7 @@ messages.transcribedAudio#93752c52 flags:# pending:flags.0?true transcription_id help.premiumPromo#5334759c status_text:string status_entities:Vector video_sections:Vector videos:Vector period_options:Vector users:Vector = help.PremiumPromo; -inputStorePaymentPremiumSubscription#a6751e66 flags:# restore:flags.0?true = InputStorePaymentPurpose; +inputStorePaymentPremiumSubscription#a6751e66 flags:# restore:flags.0?true upgrade:flags.1?true = InputStorePaymentPurpose; inputStorePaymentGiftPremium#616f7fe8 user_id:InputUser currency:string amount:long = InputStorePaymentPurpose; premiumGiftOption#74c34319 flags:# months:int currency:string amount:long bot_url:string store_product:flags.0?string = PremiumGiftOption; @@ -1439,7 +1443,7 @@ emailVerificationApple#96d074fd token:string = EmailVerification; account.emailVerified#2b96cd1b email:string = account.EmailVerified; account.emailVerifiedLogin#e1bb0d61 email:string sent_code:auth.SentCode = account.EmailVerified; -premiumSubscriptionOption#b6f11ebe flags:# current:flags.1?true can_purchase_upgrade:flags.2?true months:int currency:string amount:long bot_url:string store_product:flags.0?string = PremiumSubscriptionOption; +premiumSubscriptionOption#5f2d1df2 flags:# current:flags.1?true can_purchase_upgrade:flags.2?true transaction:flags.3?string months:int currency:string amount:long bot_url:string store_product:flags.0?string = PremiumSubscriptionOption; sendAsPeer#b81c7034 flags:# premium_required:flags.0?true peer:Peer = SendAsPeer; @@ -1459,6 +1463,28 @@ defaultHistoryTTL#43b46b20 period:int = DefaultHistoryTTL; exportedContactToken#41bf109b url:string expires:int = ExportedContactToken; +requestPeerTypeUser#5f3b8a00 flags:# bot:flags.0?Bool premium:flags.1?Bool = RequestPeerType; +requestPeerTypeChat#c9f06e1b flags:# creator:flags.0?true bot_participant:flags.5?true has_username:flags.3?Bool forum:flags.4?Bool user_admin_rights:flags.1?ChatAdminRights bot_admin_rights:flags.2?ChatAdminRights = RequestPeerType; +requestPeerTypeBroadcast#339bef6c flags:# creator:flags.0?true has_username:flags.3?Bool user_admin_rights:flags.1?ChatAdminRights bot_admin_rights:flags.2?ChatAdminRights = RequestPeerType; + +emojiListNotModified#481eadfa = EmojiList; +emojiList#7a1e11d1 hash:long document_id:Vector = EmojiList; + +emojiGroup#7a9abda9 title:string icon_emoji_id:long emoticons:Vector = EmojiGroup; + +messages.emojiGroupsNotModified#6fb4ad87 = messages.EmojiGroups; +messages.emojiGroups#881fb94b hash:int groups:Vector = messages.EmojiGroups; + +textWithEntities#751f3146 text:string entities:Vector = TextWithEntities; + +messages.translateResult#33db32f8 result:Vector = messages.TranslatedText; + +autoSaveSettings#c84834ce flags:# photos:flags.0?true videos:flags.1?true video_max_size:flags.2?long = AutoSaveSettings; + +autoSaveException#81602d47 peer:Peer settings:AutoSaveSettings = AutoSaveException; + +account.autoSaveSettings#4c3e069d users_settings:AutoSaveSettings chats_settings:AutoSaveSettings broadcasts_settings:AutoSaveSettings exceptions:Vector chats:Vector users:Vector = account.AutoSaveSettings; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1489,6 +1515,7 @@ auth.importLoginToken#95ac5ce4 token:bytes = auth.LoginToken; auth.acceptLoginToken#e894ad4d token:bytes = Authorization; auth.checkRecoveryPassword#d36bf79 code:string = Bool; auth.importWebTokenAuthorization#2db873a9 api_id:int api_hash:string web_auth_token:string = auth.Authorization; +auth.requestFirebaseSms#89464b50 flags:# phone_number:string phone_code_hash:string safety_net_token:flags.0?string ios_push_secret:flags.1?string = Bool; account.registerDevice#ec86017a flags:# no_muted:flags.0?true token_type:int token:string app_sandbox:Bool secret:bytes other_uids:Vector = Bool; account.unregisterDevice#6a0d3206 token_type:int token:string other_uids:Vector = Bool; @@ -1572,6 +1599,11 @@ account.getRecentEmojiStatuses#f578105 hash:long = account.EmojiStatuses; account.clearRecentEmojiStatuses#18201aae = Bool; account.reorderUsernames#ef500eab order:Vector = Bool; account.toggleUsername#58d6b376 username:string active:Bool = Bool; +account.getDefaultProfilePhotoEmojis#e2750328 hash:long = EmojiList; +account.getDefaultGroupPhotoEmojis#915860ae hash:long = EmojiList; +account.getAutoSaveSettings#adcbbcda = account.AutoSaveSettings; +account.saveAutoSaveSettings#d69b8361 flags:# users:flags.0?true chats:flags.1?true broadcasts:flags.2?true peer:flags.3?InputPeer settings:AutoSaveSettings = Bool; +account.deleteAutoSaveExceptions#53bc0020 = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#b60f5918 id:InputUser = users.UserFull; @@ -1756,7 +1788,7 @@ messages.getMessageReactionsList#461b3f48 flags:# peer:InputPeer id:int reaction messages.setChatAvailableReactions#feb16771 peer:InputPeer available_reactions:ChatReactions = Updates; messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions; messages.setDefaultReaction#4f47a016 reaction:Reaction = Bool; -messages.translateText#24ce6dee flags:# peer:flags.0?InputPeer msg_id:flags.0?int text:flags.1?string from_lang:flags.2?string to_lang:string = messages.TranslatedText; +messages.translateText#63183030 flags:# peer:flags.0?InputPeer id:flags.0?Vector text:flags.1?Vector to_lang:string = messages.TranslatedText; messages.getUnreadReactions#3223495b flags:# peer:InputPeer top_msg_id:flags.0?int offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages; messages.readReactions#54aa7f8e flags:# peer:InputPeer top_msg_id:flags.0?int = messages.AffectedHistory; messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = messages.Messages; @@ -1780,16 +1812,22 @@ messages.clearRecentReactions#9dfeefb4 = Bool; messages.getExtendedMedia#84f80814 peer:InputPeer id:Vector = Updates; messages.setDefaultHistoryTTL#9eb51445 period:int = Bool; messages.getDefaultHistoryTTL#658b7188 = DefaultHistoryTTL; +messages.sendBotRequestedPeer#fe38d01b peer:InputPeer msg_id:int button_id:int requested_peer:InputPeer = Updates; +messages.getEmojiGroups#7488ce5b hash:int = messages.EmojiGroups; +messages.getEmojiStatusGroups#2ecd56cd hash:int = messages.EmojiGroups; +messages.getEmojiProfilePhotoGroups#21a548f3 hash:int = messages.EmojiGroups; +messages.searchCustomEmoji#2c11c0d7 emoticon:string hash:long = EmojiList; +messages.togglePeerTranslations#e47cb579 flags:# disabled:flags.0?true peer:InputPeer = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference; photos.updateProfilePhoto#1c3d5956 flags:# fallback:flags.0?true id:InputPhoto = photos.Photo; -photos.uploadProfilePhoto#89f30f69 flags:# fallback:flags.3?true file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = photos.Photo; +photos.uploadProfilePhoto#93c9a51 flags:# fallback:flags.3?true file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.4?VideoSize = photos.Photo; photos.deletePhotos#87cf7f2f id:Vector = Vector; photos.getUserPhotos#91cd32a8 user_id:InputUser offset:int max_id:long limit:int = photos.Photos; -photos.uploadContactProfilePhoto#b91a83bf flags:# suggest:flags.3?true save:flags.4?true user_id:InputUser file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double = photos.Photo; +photos.uploadContactProfilePhoto#e14c4a71 flags:# suggest:flags.3?true save:flags.4?true user_id:InputUser file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.5?VideoSize = photos.Photo; upload.saveFilePart#b304a621 file_id:long file_part:int bytes:bytes = Bool; upload.getFile#be5335be flags:# precise:flags.0?true cdn_supported:flags.1?true location:InputFileLocation offset:long limit:int = upload.File; @@ -1832,7 +1870,7 @@ channels.getParticipants#77ced9d0 channel:InputChannel filter:ChannelParticipant channels.getParticipant#a0ab6cc6 channel:InputChannel participant:InputPeer = channels.ChannelParticipant; channels.getChannels#a7f6bbb id:Vector = messages.Chats; channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull; -channels.createChannel#91006707 flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string ttl_period:flags.4?int = Updates; +channels.createChannel#91006707 flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true forum:flags.5?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string ttl_period:flags.4?int = Updates; channels.editAdmin#d33c8902 channel:InputChannel user_id:InputUser admin_rights:ChatAdminRights rank:string = Updates; channels.editTitle#566decd0 channel:InputChannel title:string = Updates; channels.editPhoto#f12e57c9 channel:InputChannel photo:InputChatPhoto = Updates; @@ -1957,4 +1995,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 151 +// LAYER 152 From 53cb3f29c7d98dec6deccc32dfe04b26affa2f3b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:44:07 +0100 Subject: [PATCH 518/539] Update Pyrogram to v2.0.98 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e280c304a1..2c3b460e9d 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.97" +__version__ = "2.0.98" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From f040aefc9f074c59b387ec08cc80deea42760b98 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:03:09 +0100 Subject: [PATCH 519/539] Update bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 1150af6099..3b0ff4ee2d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -4,7 +4,7 @@ body: - type: checkboxes attributes: label: Checklist - description: Invalid, incomplete or inadequate issue reports will not be considered + description: Invalid, incomplete or inadequate issue reports may not be taken into consideration options: - label: I am sure the error is coming from Pyrogram's code and not elsewhere required: true From 2e82fcecff01dee0df2969135a96c317a39a1894 Mon Sep 17 00:00:00 2001 From: Jins Mathew <68688737+jinspalakkattu@users.noreply.github.com> Date: Sat, 11 Feb 2023 12:08:29 +0300 Subject: [PATCH 520/539] Add missing has_spoiler parameter to reply_{animation,photo,video} --- pyrogram/types/messages_and_media/message.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 1835f63225..62a85b7593 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -989,6 +989,7 @@ async def reply_animation( caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, duration: int = 0, width: int = 0, height: int = 0, @@ -1042,6 +1043,9 @@ async def reply_animation( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the animation needs to be covered with a spoiler animation. + duration (``int``, *optional*): Duration of sent animation in seconds. @@ -1110,6 +1114,7 @@ async def reply_animation( caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, + has_spoiler=has_spoiler, duration=duration, width=width, height=height, @@ -1886,6 +1891,7 @@ async def reply_photo( caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None, @@ -1936,6 +1942,9 @@ async def reply_photo( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the photo needs to be covered with a spoiler animation. + ttl_seconds (``int``, *optional*): Self-Destruct Timer. If you set a timer, the photo will self-destruct in *ttl_seconds* @@ -1994,6 +2003,7 @@ async def reply_photo( caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, + has_spoiler=has_spoiler, ttl_seconds=ttl_seconds, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, @@ -2352,6 +2362,7 @@ async def reply_video( caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, + has_spoiler: bool = None, ttl_seconds: int = None, duration: int = 0, width: int = 0, @@ -2407,6 +2418,9 @@ async def reply_video( caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + has_spoiler (``bool``, *optional*): + Pass True if the video needs to be covered with a spoiler animation. + ttl_seconds (``int``, *optional*): Self-Destruct Timer. If you set a timer, the video will self-destruct in *ttl_seconds* @@ -2483,6 +2497,7 @@ async def reply_video( caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, + has_spoiler=has_spoiler, ttl_seconds=ttl_seconds, duration=duration, width=width, From 96ffc7efcd32a65b73ea1bf609faf08492d93b99 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:09:03 +0100 Subject: [PATCH 521/539] Update Pyrogram to v2.0.99 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2c3b460e9d..3e9848420c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.98" +__version__ = "2.0.99" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 787eabd940aa1439086b67fc96cb922fe12ef24e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 26 Feb 2023 11:08:27 +0100 Subject: [PATCH 522/539] Update send_inline_bot_result return type hint --- pyrogram/methods/bots/send_inline_bot_result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/methods/bots/send_inline_bot_result.py b/pyrogram/methods/bots/send_inline_bot_result.py index 0f31880636..f29d8eb9cd 100644 --- a/pyrogram/methods/bots/send_inline_bot_result.py +++ b/pyrogram/methods/bots/send_inline_bot_result.py @@ -30,7 +30,7 @@ async def send_inline_bot_result( result_id: str, disable_notification: bool = None, reply_to_message_id: int = None - ): + ) -> "raw.base.Updates": """Send an inline bot result. Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results` @@ -56,7 +56,7 @@ async def send_inline_bot_result( If the message is a reply, ID of the original message. Returns: - :obj:`~pyrogram.types.Message`: On success, the sent inline result message is returned. + :obj:`~pyrogram.raw.base.Updates`: Currently, on success, a raw result is returned. Example: .. code-block:: python From d6476ce57e85cc4b655a4cb23b8f1e8958eab8de Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 26 Feb 2023 11:09:21 +0100 Subject: [PATCH 523/539] Update Pyrogram to v2.0.100 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 3e9848420c..a0a56ef54e 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.99" +__version__ = "2.0.100" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From a3a4a0204c382bc2e4038f8c6cb9a7e215603c48 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:45:32 +0100 Subject: [PATCH 524/539] Update chat username parsing in case of multiple usernames --- pyrogram/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 9de55621f8..f213c57a76 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -513,7 +513,11 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra elif isinstance(peer, (raw.types.Channel, raw.types.ChannelForbidden)): peer_id = utils.get_channel_id(peer.id) access_hash = peer.access_hash - username = (getattr(peer, "username", None) or "").lower() or None + username = ( + peer.username.lower() if peer.username + else peer.usernames[0].username.lower() if peer.usernames + else None + ) peer_type = "channel" if peer.broadcast else "supergroup" else: continue From fb3f9acc181cb176386e695a2ec942f28d9669b6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:45:56 +0100 Subject: [PATCH 525/539] Update Pyrogram to v2.0.101 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a0a56ef54e..a07e75f330 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.100" +__version__ = "2.0.101" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 0a90d54010df1712048c270fe1378337f275e483 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:52:03 +0100 Subject: [PATCH 526/539] Separate cases between Channel and ChannelForbidden --- pyrogram/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index f213c57a76..c74634ea8e 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -510,7 +510,7 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra peer_id = -peer.id access_hash = 0 peer_type = "group" - elif isinstance(peer, (raw.types.Channel, raw.types.ChannelForbidden)): + elif isinstance(peer, raw.types.Channel): peer_id = utils.get_channel_id(peer.id) access_hash = peer.access_hash username = ( @@ -519,6 +519,10 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra else None ) peer_type = "channel" if peer.broadcast else "supergroup" + elif isinstance(peer, raw.types.ChannelForbidden): + peer_id = utils.get_channel_id(peer.id) + access_hash = peer.access_hash + peer_type = "channel" if peer.broadcast else "supergroup" else: continue From abed55aea9d6687a8054282d8ee2d964ec39e23a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:52:37 +0100 Subject: [PATCH 527/539] Update Pyrogram to v2.0.102 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a07e75f330..4b74f269ec 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.101" +__version__ = "2.0.102" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 8cff5594c0eefe67f8aa36d6b12689a76e5d54ee Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:29:04 +0200 Subject: [PATCH 528/539] Update API schema to Layer 155 --- compiler/api/source/main_api.tl | 52 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 670bd8dc91..8c5c12ecf3 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -156,7 +156,7 @@ messageActionPaymentSent#96163f56 flags:# recurring_init:flags.2?true recurring_ messageActionPhoneCall#80e11a7f flags:# video:flags.2?true call_id:long reason:flags.0?PhoneCallDiscardReason duration:flags.1?int = MessageAction; messageActionScreenshotTaken#4792929b = MessageAction; messageActionCustomAction#fae69f56 message:string = MessageAction; -messageActionBotAllowed#abe9affe domain:string = MessageAction; +messageActionBotAllowed#c516d679 flags:# attach_menu:flags.1?true domain:flags.0?string app:flags.2?BotApp = MessageAction; messageActionSecureValuesSentMe#1b287353 values:Vector credentials:SecureCredentialsEncrypted = MessageAction; messageActionSecureValuesSent#d95c6154 types:Vector = MessageAction; messageActionContactSignUp#f3f25f76 = MessageAction; @@ -173,7 +173,6 @@ messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = Messa messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction; messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction; messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction; -messageActionAttachMenuBotAllowed#e7e75f97 = MessageAction; messageActionRequestedPeer#fe77345d button_id:int peer:Peer = MessageAction; dialog#d58a08c6 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog; @@ -386,6 +385,7 @@ updateChannelPinnedTopic#192efbe3 flags:# pinned:flags.0?true channel_id:long to updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector = Update; updateUser#20529438 user_id:long = Update; updateAutoSaveSettings#ec05b097 = Update; +updateGroupInvitePrivacyForbidden#ccf08ad6 user_id:long = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -412,7 +412,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 this_port_only:flags.5?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; -config#232566ac 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 pfs_enabled:flags.13?true force_try_ipv6:flags.14?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 pinned_infolder_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 base_lang_pack_version:flags.2?int reactions_default:flags.15?Reaction = Config; +config#cc1a241e flags:# default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true force_try_ipv6:flags.14?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 edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int channels_read_media_period:int tmp_sessions:flags.0?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 base_lang_pack_version:flags.2?int reactions_default:flags.15?Reaction autologin_token:flags.16?string = Config; nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc; @@ -698,7 +698,7 @@ botInlineMessageMediaInvoice#354a9b09 flags:# shipping_address_requested:flags.1 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; -messages.botResults#947ca848 flags:# gallery:flags.0?true query_id:long next_offset:flags.1?string switch_pm:flags.2?InlineBotSwitchPM results:Vector cache_time:int users:Vector = messages.BotResults; +messages.botResults#e021f2f6 flags:# gallery:flags.0?true query_id:long next_offset:flags.1?string switch_pm:flags.2?InlineBotSwitchPM switch_webview:flags.3?InlineBotWebView results:Vector cache_time:int users:Vector = messages.BotResults; exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink; @@ -878,7 +878,7 @@ account.tmpPassword#db64fd34 tmp_password:bytes valid_until:int = account.TmpPas shippingOption#b6213cdf id:string title:string prices:Vector = ShippingOption; -inputStickerSetItem#ffa0a496 flags:# document:InputDocument emoji:string mask_coords:flags.0?MaskCoords = InputStickerSetItem; +inputStickerSetItem#32da9e9c flags:# document:InputDocument emoji:string mask_coords:flags.0?MaskCoords keywords:flags.1?string = InputStickerSetItem; inputPhoneCall#1e36fded id:long access_hash:long = InputPhoneCall; @@ -1320,7 +1320,7 @@ account.resetPasswordFailedWait#e3779861 retry_date:int = account.ResetPasswordR account.resetPasswordRequestedWait#e9effc7d until_date:int = account.ResetPasswordResult; account.resetPasswordOk#e926d63e = account.ResetPasswordResult; -sponsoredMessage#3a836df8 flags:# recommended:flags.5?true show_peer_photo:flags.6?true random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector = SponsoredMessage; +sponsoredMessage#fc25b828 flags:# recommended:flags.5?true show_peer_photo:flags.6?true random_id:bytes from_id:flags.3?Peer chat_invite:flags.4?ChatInvite chat_invite_hash:flags.4?string channel_post:flags.2?int start_param:flags.0?string message:string entities:flags.1?Vector sponsor_info:flags.7?string additional_info:flags.8?string = SponsoredMessage; messages.sponsoredMessages#c9ee1d87 flags:# posts_between:flags.0?int messages:Vector chats:Vector users:Vector = messages.SponsoredMessages; messages.sponsoredMessagesEmpty#1839490f = messages.SponsoredMessages; @@ -1352,7 +1352,7 @@ availableReaction#c077ec01 flags:# inactive:flags.0?true premium:flags.2?true re messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions; messages.availableReactions#768e3aad hash:int reactions:Vector = messages.AvailableReactions; -messagePeerReaction#b156fe9c flags:# big:flags.0?true unread:flags.1?true peer_id:Peer reaction:Reaction = MessagePeerReaction; +messagePeerReaction#8c79b63c flags:# big:flags.0?true unread:flags.1?true peer_id:Peer date:int reaction:Reaction = MessagePeerReaction; groupCallStreamChannel#80eb48af channel:int scale:int last_timestamp_ms:long = GroupCallStreamChannel; @@ -1485,6 +1485,23 @@ autoSaveException#81602d47 peer:Peer settings:AutoSaveSettings = AutoSaveExcepti account.autoSaveSettings#4c3e069d users_settings:AutoSaveSettings chats_settings:AutoSaveSettings broadcasts_settings:AutoSaveSettings exceptions:Vector chats:Vector users:Vector = account.AutoSaveSettings; +help.appConfigNotModified#7cde641d = help.AppConfig; +help.appConfig#dd18782e hash:int config:JSONValue = help.AppConfig; + +inputBotAppID#a920bd7a id:long access_hash:long = InputBotApp; +inputBotAppShortName#908c0407 bot_id:InputUser short_name:string = InputBotApp; + +botAppNotModified#5da674b7 = BotApp; +botApp#95fcd1d6 flags:# id:long access_hash:long short_name:string title:string description:string photo:Photo document:flags.0?Document hash:long = BotApp; + +messages.botApp#eb50adf5 flags:# inactive:flags.0?true request_write_access:flags.1?true app:BotApp = messages.BotApp; + +appWebViewResultUrl#3c1b4f0d url:string = AppWebViewResult; + +inlineBotWebView#b57295d5 text:string url:string = InlineBotWebView; + +readParticipantDate#4a4ff172 user_id:long date:int = ReadParticipantDate; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1686,7 +1703,7 @@ messages.getDocumentByHash#b1f2061f sha256:bytes size:long mime_type:string = Do messages.getSavedGifs#5cf09635 hash:long = messages.SavedGifs; messages.saveGif#327a30cb id:InputDocument unsave:Bool = Bool; messages.getInlineBotResults#514e999d flags:# bot:InputUser peer:InputPeer geo_point:flags.0?InputGeoPoint query:string offset:string = messages.BotResults; -messages.setInlineBotResults#eb5ea206 flags:# gallery:flags.0?true private:flags.1?true query_id:long results:Vector cache_time:int next_offset:flags.2?string switch_pm:flags.3?InlineBotSwitchPM = Bool; +messages.setInlineBotResults#bb12a419 flags:# gallery:flags.0?true private:flags.1?true query_id:long results:Vector cache_time:int next_offset:flags.2?string switch_pm:flags.3?InlineBotSwitchPM switch_webview:flags.4?InlineBotWebView = Bool; messages.sendInlineBotResult#d3fbdccb flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true hide_via:flags.11?true peer:InputPeer reply_to_msg_id:flags.0?int top_msg_id:flags.9?int random_id:long query_id:long id:string schedule_date:flags.10?int send_as:flags.13?InputPeer = Updates; messages.getMessageEditData#fda68d36 peer:InputPeer id:int = messages.MessageEditData; messages.editMessage#48f71778 flags:# no_webpage:flags.1?true peer:InputPeer id:int message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector schedule_date:flags.15?int = Updates; @@ -1775,7 +1792,7 @@ messages.getChatInviteImporters#df04dd4e flags:# requested:flags.0?true peer:Inp messages.setHistoryTTL#b80e5fe4 peer:InputPeer period:int = Updates; messages.checkHistoryImportPeer#5dc60f03 peer:InputPeer = messages.CheckedHistoryImportPeer; messages.setChatTheme#e63be13f peer:InputPeer emoticon:string = Updates; -messages.getMessageReadParticipants#2c6f97b7 peer:InputPeer msg_id:int = Vector; +messages.getMessageReadParticipants#31c1c44f peer:InputPeer msg_id:int = Vector; messages.getSearchResultsCalendar#49f0bde9 peer:InputPeer filter:MessagesFilter offset_id:int offset_date:int = messages.SearchResultsCalendar; messages.getSearchResultsPositions#6e9583a3 peer:InputPeer filter:MessagesFilter offset_id:int limit:int = messages.SearchResultsPositions; messages.hideChatJoinRequest#7fe7e815 flags:# approved:flags.0?true peer:InputPeer user_id:InputUser = Updates; @@ -1797,7 +1814,7 @@ messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot; messages.toggleBotInAttachMenu#69f59d69 flags:# write_allowed:flags.0?true bot:InputUser enabled:Bool = Bool; messages.requestWebView#178b480b flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON platform:string reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = WebViewResult; messages.prolongWebView#7ff34309 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int top_msg_id:flags.9?int send_as:flags.13?InputPeer = Bool; -messages.requestSimpleWebView#299bec8e flags:# bot:InputUser url:string theme_params:flags.0?DataJSON platform:string = SimpleWebViewResult; +messages.requestSimpleWebView#299bec8e flags:# from_switch_webview:flags.1?true bot:InputUser url:string theme_params:flags.0?DataJSON platform:string = SimpleWebViewResult; messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent; messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates; messages.transcribeAudio#269e9a49 peer:InputPeer msg_id:int = messages.TranscribedAudio; @@ -1818,6 +1835,8 @@ messages.getEmojiStatusGroups#2ecd56cd hash:int = messages.EmojiGroups; messages.getEmojiProfilePhotoGroups#21a548f3 hash:int = messages.EmojiGroups; messages.searchCustomEmoji#2c11c0d7 emoticon:string hash:long = EmojiList; messages.togglePeerTranslations#e47cb579 flags:# disabled:flags.0?true peer:InputPeer = Bool; +messages.getBotApp#34fdc5c3 app:InputBotApp hash:long = messages.BotApp; +messages.requestAppWebView#8c5a3b3c flags:# write_allowed:flags.0?true peer:InputPeer app:InputBotApp start_param:flags.1?string theme_params:flags.2?DataJSON platform:string = AppWebViewResult; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1850,7 +1869,7 @@ help.getRecentMeUrls#3dc0f114 referer:string = help.RecentMeUrls; help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate; help.acceptTermsOfService#ee72f79a id:DataJSON = Bool; help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo; -help.getAppConfig#98914110 = JSONValue; +help.getAppConfig#61e3f854 hash:int = help.AppConfig; help.saveAppLog#6f02f748 events:Vector = Bool; help.getPassportConfig#c661ad08 hash:int = help.PassportConfig; help.getSupportName#d360e72c = help.SupportName; @@ -1927,6 +1946,8 @@ bots.setBotMenuButton#4504d54f user_id:InputUser button:BotMenuButton = Bool; bots.getBotMenuButton#9c60eb28 user_id:InputUser = BotMenuButton; bots.setBotBroadcastDefaultAdminRights#788464e1 admin_rights:ChatAdminRights = Bool; bots.setBotGroupDefaultAdminRights#925ec9ea admin_rights:ChatAdminRights = Bool; +bots.setBotInfo#a365df7a flags:# lang_code:string about:flags.0?string description:flags.1?string = Bool; +bots.getBotInfo#75ec12e6 lang_code:string = Vector; payments.getPaymentForm#37148dbb flags:# invoice:InputInvoice theme_params:flags.0?DataJSON = payments.PaymentForm; payments.getPaymentReceipt#2478d1cc peer:InputPeer msg_id:int = payments.PaymentReceipt; @@ -1940,13 +1961,16 @@ payments.assignAppStoreTransaction#80ed747d receipt:bytes purpose:InputStorePaym payments.assignPlayMarketTransaction#dffd50d3 receipt:DataJSON purpose:InputStorePaymentPurpose = Updates; payments.canPurchasePremium#9fc19eb6 purpose:InputStorePaymentPurpose = Bool; -stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet; +stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true animated:flags.1?true videos:flags.4?true emojis:flags.5?true text_color:flags.6?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet; stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet; stickers.changeStickerPosition#ffb6d4ca sticker:InputDocument position:int = messages.StickerSet; stickers.addStickerToSet#8653febe stickerset:InputStickerSet sticker:InputStickerSetItem = messages.StickerSet; -stickers.setStickerSetThumb#9a364e30 stickerset:InputStickerSet thumb:InputDocument = messages.StickerSet; +stickers.setStickerSetThumb#a76a5392 flags:# stickerset:InputStickerSet thumb:flags.0?InputDocument thumb_document_id:flags.1?long = messages.StickerSet; stickers.checkShortName#284b3639 short_name:string = Bool; stickers.suggestShortName#4dafc503 title:string = stickers.SuggestedShortName; +stickers.changeSticker#f5537ebc flags:# sticker:InputDocument emoji:flags.0?string mask_coords:flags.1?MaskCoords keywords:flags.2?string = messages.StickerSet; +stickers.renameStickerSet#124b1c00 stickerset:InputStickerSet title:string = messages.StickerSet; +stickers.deleteStickerSet#87704394 stickerset:InputStickerSet = Bool; phone.getCallConfig#55451fa9 = DataJSON; phone.requestCall#42ff96ed flags:# video:flags.0?true user_id:InputUser random_id:int g_a_hash:bytes protocol:PhoneCallProtocol = phone.PhoneCall; @@ -1995,4 +2019,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 152 +// LAYER 155 From 68c7bd6e12c5339919f68f346208cebe1aed28d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:29:32 +0200 Subject: [PATCH 529/539] Update Pyrogram to v2.0.103 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 4b74f269ec..e4e23fd03f 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.102" +__version__ = "2.0.103" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From bb678a4fb6ca41fe3d7c441989aab84273445546 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:56:12 +0200 Subject: [PATCH 530/539] Update API schema to Layer 158 --- compiler/api/source/main_api.tl | 64 +++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 8c5c12ecf3..7fd74edb3d 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -88,7 +88,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType; storage.fileWebp#1081464c = storage.FileType; userEmpty#d3bc4b7a id:long = User; -user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User; +user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; userProfilePhoto#82d1f706 flags:# has_video:flags.0?true personal:flags.2?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto; @@ -169,11 +169,13 @@ messageActionSetChatTheme#aa786345 emoticon:string = MessageAction; messageActionChatJoinedByRequest#ebbca3cb = MessageAction; messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction; messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction; -messageActionGiftPremium#aba0f5c6 currency:string amount:long months:int = MessageAction; +messageActionGiftPremium#c83d6aec flags:# currency:string amount:long months:int crypto_currency:flags.0?string crypto_amount:flags.0?long = MessageAction; messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction; messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction; messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction; messageActionRequestedPeer#fe77345d button_id:int peer:Peer = MessageAction; +messageActionSetChatWallPaper#bc44a927 wallpaper:WallPaper = MessageAction; +messageActionSetSameChatWallPaper#c0787d6d wallpaper:WallPaper = MessageAction; dialog#d58a08c6 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 unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -225,7 +227,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason; inputReportReasonIllegalDrugs#a8eb2be = ReportReason; inputReportReasonPersonalDetails#9ec7863d = ReportReason; -userFull#f8d32aed flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector = UserFull; +userFull#93eadb53 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector wallpaper:flags.24?WallPaper = UserFull; contact#145ade0b user_id:long mutual:Bool = Contact; @@ -363,7 +365,7 @@ updateGroupCallParticipants#f2ebdb4e call:InputGroupCall participants:Vector = Update; @@ -593,7 +595,7 @@ keyboardButtonUrl#258aff05 text:string url:string = KeyboardButton; keyboardButtonCallback#35bbdb6b flags:# requires_password:flags.0?true text:string data:bytes = KeyboardButton; keyboardButtonRequestPhone#b16a6c29 text:string = KeyboardButton; keyboardButtonRequestGeoLocation#fc796b3f text:string = KeyboardButton; -keyboardButtonSwitchInline#568a748 flags:# same_peer:flags.0?true text:string query:string = KeyboardButton; +keyboardButtonSwitchInline#93b9fbb5 flags:# same_peer:flags.0?true text:string query:string peer_types:flags.1?Vector = KeyboardButton; keyboardButtonGame#50f41ccf text:string = KeyboardButton; keyboardButtonBuy#afd93fbb text:string = KeyboardButton; keyboardButtonUrlAuth#10b78d29 flags:# text:string fwd_text:flags.0?string url:string button_id:int = KeyboardButton; @@ -715,7 +717,7 @@ auth.sentCodeTypeSms#c000bba2 length:int = auth.SentCodeType; auth.sentCodeTypeCall#5353e5a7 length:int = auth.SentCodeType; auth.sentCodeTypeFlashCall#ab03c6d9 pattern:string = auth.SentCodeType; auth.sentCodeTypeMissedCall#82006484 prefix:string length:int = auth.SentCodeType; -auth.sentCodeTypeEmailCode#5a159841 flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int next_phone_login_date:flags.2?int = auth.SentCodeType; +auth.sentCodeTypeEmailCode#f450f59b flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int reset_available_period:flags.3?int reset_pending_date:flags.4?int = auth.SentCodeType; auth.sentCodeTypeSetUpEmailRequired#a5491dea flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true = auth.SentCodeType; auth.sentCodeTypeFragmentSms#d9565c39 url:string length:int = auth.SentCodeType; auth.sentCodeTypeFirebaseSms#e57b1432 flags:# nonce:flags.0?bytes receipt:flags.1?string push_timeout:flags.1?int length:int = auth.SentCodeType; @@ -937,7 +939,7 @@ channelAdminLogEventActionDiscardGroupCall#db9f9140 call:InputGroupCall = Channe channelAdminLogEventActionParticipantMute#f92424d2 participant:GroupCallParticipant = ChannelAdminLogEventAction; channelAdminLogEventActionParticipantUnmute#e64429c0 participant:GroupCallParticipant = ChannelAdminLogEventAction; channelAdminLogEventActionToggleGroupCallSetting#56d6a247 join_muted:Bool = ChannelAdminLogEventAction; -channelAdminLogEventActionParticipantJoinByInvite#5cdada77 invite:ExportedChatInvite = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantJoinByInvite#fe9fc158 flags:# via_chatlist:flags.0?true invite:ExportedChatInvite = ChannelAdminLogEventAction; channelAdminLogEventActionExportedInviteDelete#5a50fca4 invite:ExportedChatInvite = ChannelAdminLogEventAction; channelAdminLogEventActionExportedInviteRevoke#410a134e invite:ExportedChatInvite = ChannelAdminLogEventAction; channelAdminLogEventActionExportedInviteEdit#e90ebb59 prev_invite:ExportedChatInvite new_invite:ExportedChatInvite = ChannelAdminLogEventAction; @@ -1205,6 +1207,7 @@ payments.bankCardData#3e24e573 title:string open_urls:Vector = dialogFilter#7438f7e8 flags:# contacts:flags.0?true non_contacts:flags.1?true groups:flags.2?true broadcasts:flags.3?true bots:flags.4?true exclude_muted:flags.11?true exclude_read:flags.12?true exclude_archived:flags.13?true id:int title:string emoticon:flags.25?string pinned_peers:Vector include_peers:Vector exclude_peers:Vector = DialogFilter; dialogFilterDefault#363293ae = DialogFilter; +dialogFilterChatlist#d64a04a8 flags:# has_my_invites:flags.26?true id:int title:string emoticon:flags.25?string pinned_peers:Vector include_peers:Vector = DialogFilter; dialogFilterSuggested#77744d4a filter:DialogFilter description:string = DialogFilterSuggested; @@ -1276,6 +1279,7 @@ inlineQueryPeerTypePM#833c0fac = InlineQueryPeerType; inlineQueryPeerTypeChat#d766c50a = InlineQueryPeerType; inlineQueryPeerTypeMegagroup#5ec4be43 = InlineQueryPeerType; inlineQueryPeerTypeBroadcast#6334ee9a = InlineQueryPeerType; +inlineQueryPeerTypeBotPM#e3b2d0c = InlineQueryPeerType; messages.historyImport#1662af0b id:long = messages.HistoryImport; @@ -1283,7 +1287,7 @@ messages.historyImportParsed#5e0fb7b9 flags:# pm:flags.0?true group:flags.1?true messages.affectedFoundMessages#ef8d3e6c pts:int pts_count:int offset:int messages:Vector = messages.AffectedFoundMessages; -chatInviteImporter#8c5adfd9 flags:# requested:flags.0?true user_id:long date:int about:flags.2?string approved_by:flags.1?long = ChatInviteImporter; +chatInviteImporter#8c5adfd9 flags:# requested:flags.0?true via_chatlist:flags.3?true user_id:long date:int about:flags.2?string approved_by:flags.1?long = ChatInviteImporter; messages.exportedChatInvites#bdc62dcc count:int invites:Vector users:Vector = messages.ExportedChatInvites; @@ -1502,6 +1506,21 @@ inlineBotWebView#b57295d5 text:string url:string = InlineBotWebView; readParticipantDate#4a4ff172 user_id:long date:int = ReadParticipantDate; +inputChatlistDialogFilter#f3e0da33 filter_id:int = InputChatlist; + +exportedChatlistInvite#c5181ac flags:# title:string url:string peers:Vector = ExportedChatlistInvite; + +chatlists.exportedChatlistInvite#10e6e3a6 filter:DialogFilter invite:ExportedChatlistInvite = chatlists.ExportedChatlistInvite; + +chatlists.exportedInvites#10ab6dc7 invites:Vector chats:Vector users:Vector = chatlists.ExportedInvites; + +chatlists.chatlistInviteAlready#fa87f659 filter_id:int missing_peers:Vector already_peers:Vector chats:Vector users:Vector = chatlists.ChatlistInvite; +chatlists.chatlistInvite#1dcd839d flags:# title:string emoticon:flags.0?string peers:Vector chats:Vector users:Vector = chatlists.ChatlistInvite; + +chatlists.chatlistUpdates#93bd878d missing_peers:Vector chats:Vector users:Vector = chatlists.ChatlistUpdates; + +bots.botInfo#e8a775b0 name:string about:string description:string = bots.BotInfo; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1533,6 +1552,7 @@ auth.acceptLoginToken#e894ad4d token:bytes = Authorization; auth.checkRecoveryPassword#d36bf79 code:string = Bool; auth.importWebTokenAuthorization#2db873a9 api_id:int api_hash:string web_auth_token:string = auth.Authorization; auth.requestFirebaseSms#89464b50 flags:# phone_number:string phone_code_hash:string safety_net_token:flags.0?string ios_push_secret:flags.1?string = Bool; +auth.resetLoginEmail#7e960193 phone_number:string phone_code_hash:string = auth.SentCode; account.registerDevice#ec86017a flags:# no_muted:flags.0?true token_type:int token:string app_sandbox:Bool secret:bytes other_uids:Vector = Bool; account.unregisterDevice#6a0d3206 token_type:int token:string other_uids:Vector = Bool; @@ -1583,7 +1603,7 @@ account.getContactSignUpNotification#9f07c728 = Bool; account.setContactSignUpNotification#cff43f61 silent:Bool = Bool; account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates; account.getWallPaper#fc8ddbea wallpaper:InputWallPaper = WallPaper; -account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper; +account.uploadWallPaper#e39a8f03 flags:# for_chat:flags.0?true file:InputFile mime_type:string settings:WallPaperSettings = WallPaper; account.saveWallPaper#6c5a5b37 wallpaper:InputWallPaper unsave:Bool settings:WallPaperSettings = Bool; account.installWallPaper#feed5769 wallpaper:InputWallPaper settings:WallPaperSettings = Bool; account.resetWallPapers#bb3b9804 = Bool; @@ -1837,13 +1857,14 @@ messages.searchCustomEmoji#2c11c0d7 emoticon:string hash:long = EmojiList; messages.togglePeerTranslations#e47cb579 flags:# disabled:flags.0?true peer:InputPeer = Bool; messages.getBotApp#34fdc5c3 app:InputBotApp hash:long = messages.BotApp; messages.requestAppWebView#8c5a3b3c flags:# write_allowed:flags.0?true peer:InputPeer app:InputBotApp start_param:flags.1?string theme_params:flags.2?DataJSON platform:string = AppWebViewResult; +messages.setChatWallPaper#8ffacae1 flags:# peer:InputPeer wallpaper:flags.0?InputWallPaper settings:flags.2?WallPaperSettings id:flags.1?int = Updates; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference; -photos.updateProfilePhoto#1c3d5956 flags:# fallback:flags.0?true id:InputPhoto = photos.Photo; -photos.uploadProfilePhoto#93c9a51 flags:# fallback:flags.3?true file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.4?VideoSize = photos.Photo; +photos.updateProfilePhoto#9e82039 flags:# fallback:flags.0?true bot:flags.1?InputUser id:InputPhoto = photos.Photo; +photos.uploadProfilePhoto#388a3b5 flags:# fallback:flags.3?true bot:flags.5?InputUser file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.4?VideoSize = photos.Photo; photos.deletePhotos#87cf7f2f id:Vector = Vector; photos.getUserPhotos#91cd32a8 user_id:InputUser offset:int max_id:long limit:int = photos.Photos; photos.uploadContactProfilePhoto#e14c4a71 flags:# suggest:flags.3?true save:flags.4?true user_id:InputUser file:flags.0?InputFile video:flags.1?InputFile video_start_ts:flags.2?double video_emoji_markup:flags.5?VideoSize = photos.Photo; @@ -1946,8 +1967,10 @@ bots.setBotMenuButton#4504d54f user_id:InputUser button:BotMenuButton = Bool; bots.getBotMenuButton#9c60eb28 user_id:InputUser = BotMenuButton; bots.setBotBroadcastDefaultAdminRights#788464e1 admin_rights:ChatAdminRights = Bool; bots.setBotGroupDefaultAdminRights#925ec9ea admin_rights:ChatAdminRights = Bool; -bots.setBotInfo#a365df7a flags:# lang_code:string about:flags.0?string description:flags.1?string = Bool; -bots.getBotInfo#75ec12e6 lang_code:string = Vector; +bots.setBotInfo#10cf3123 flags:# bot:flags.2?InputUser lang_code:string name:flags.3?string about:flags.0?string description:flags.1?string = Bool; +bots.getBotInfo#dcd914fd flags:# bot:flags.0?InputUser lang_code:string = bots.BotInfo; +bots.reorderUsernames#9709b1c2 bot:InputUser order:Vector = Bool; +bots.toggleUsername#53ca973 bot:InputUser username:string active:Bool = Bool; payments.getPaymentForm#37148dbb flags:# invoice:InputInvoice theme_params:flags.0?DataJSON = payments.PaymentForm; payments.getPaymentReceipt#2478d1cc peer:InputPeer msg_id:int = payments.PaymentReceipt; @@ -2011,7 +2034,6 @@ langpack.getLanguages#42c6978f lang_pack:string = Vector; langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage; folders.editPeerFolders#6847d0ab folder_peers:Vector = Updates; -folders.deleteFolder#1c295881 folder_id:int = Updates; stats.getBroadcastStats#ab42441a flags:# dark:flags.0?true channel:InputChannel = stats.BroadcastStats; stats.loadAsyncGraph#621d5fa0 flags:# token:string x:flags.0?long = StatsGraph; @@ -2019,4 +2041,16 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 155 +chatlists.exportChatlistInvite#8472478e chatlist:InputChatlist title:string peers:Vector = chatlists.ExportedChatlistInvite; +chatlists.deleteExportedInvite#719c5c5e chatlist:InputChatlist slug:string = Bool; +chatlists.editExportedInvite#653db63d flags:# chatlist:InputChatlist slug:string title:flags.1?string peers:flags.2?Vector = ExportedChatlistInvite; +chatlists.getExportedInvites#ce03da83 chatlist:InputChatlist = chatlists.ExportedInvites; +chatlists.checkChatlistInvite#41c10fff slug:string = chatlists.ChatlistInvite; +chatlists.joinChatlistInvite#a6b1e39a slug:string peers:Vector = Updates; +chatlists.getChatlistUpdates#89419521 chatlist:InputChatlist = chatlists.ChatlistUpdates; +chatlists.joinChatlistUpdates#e089f8f5 chatlist:InputChatlist peers:Vector = Updates; +chatlists.hideChatlistUpdates#66e486fb chatlist:InputChatlist = Bool; +chatlists.getLeaveChatlistSuggestions#fdbcd714 chatlist:InputChatlist = Vector; +chatlists.leaveChatlist#74fae13a chatlist:InputChatlist peers:Vector = Updates; + +// LAYER 158 From cea21ad6d035957b52d693b56433e1a7ccd97b3b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:56:56 +0200 Subject: [PATCH 531/539] Update Pyrogram to v2.0.104 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e4e23fd03f..6f9d1fce71 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.103" +__version__ = "2.0.104" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From e24d5b1cf56cdaec5c1cc0e3993b135f529f17ce Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Apr 2023 19:54:39 +0200 Subject: [PATCH 532/539] Add RSA public keys & IP addresses for some CDN DCs --- pyrogram/crypto/rsa.py | 80 ++++++++++++++++++----- pyrogram/session/internals/data_center.py | 6 +- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/pyrogram/crypto/rsa.py b/pyrogram/crypto/rsa.py index 3fd7d67ba3..25c2322957 100644 --- a/pyrogram/crypto/rsa.py +++ b/pyrogram/crypto/rsa.py @@ -153,25 +153,25 @@ int("010001", 16) # Exponent ), - # 6427105915145367799 - 0x15931aac70e0d30f7 - (1 << 64): PublicKey( # CDN DC-121 + # -7395192255793472640 + 0x995effd323b5db80 - (1 << 64): PublicKey( # CDN DC-121 # -----BEGIN RSA PUBLIC KEY----- - # MIIBCgKCAQEA+Lf3PvgE1yxbJUCMaEAkV0QySTVpnaDjiednB5RbtNWjCeqSVakY - # HbqqGMIIv5WCGdFdrqOfMNcNSstPtSU6R9UmRw6tquOIykpSuUOje9H+4XVIKquj - # yL2ISdK+4ZOMl4hCMkqauw4bP1Sbr03vZRQbU6qEA04V4j879BAyBVhr3WG9+Zi+ - # t5XfGSTgSExPYEl8rZNHYNV5RB+BuroVH2HLTOpT/mJVfikYpgjfWF5ldezV4Wo9 - # LSH0cZGSFIaeJl8d0A8Eiy5B9gtBO8mL+XfQRKOOmr7a4BM4Ro2de5rr2i2od7hY - # Xd3DO9FRSl4y1zA8Am48Rfd95WHF3N/OmQIDAQAB + # MIIBCgKCAQEA4tWHcGJlElkxuxKQJwFjJaulmVHgdxNA3wgI2E8XbNnA88y51Xog + # V5m8BEYuTSP4llXZY4ZSJW5VlFXnmsJT/hmjyeFqqTajyAW6nb9vwZX291QvqD/1 + # ZCFBy7TLvCM0lbNIEhcLMf33ZV8AetLAd+uRLF6QHosys5w0iJ7x+UbGwDxyfeic + # 8EJJnsKaXrUOwRycMRN+V/zDySa0EYl1u1EB1MDX1/jIV1IQEbLvdBH4vsVTVEdW + # KHlzOcFzT9qX/g8XibCPiHLJvqQb8hVibvs9NaANyClcBEt3mOucG1/46Lilkc/K + # d4nlCcohk0jIHNp8symUzNWRPUGmTs3SPwIDAQAB # -----END RSA PUBLIC KEY----- int( - "F8B7F73EF804D72C5B25408C6840245744324935699DA0E389E76707945BB4D5" - "A309EA9255A9181DBAAA18C208BF958219D15DAEA39F30D70D4ACB4FB5253A47" - "D526470EADAAE388CA4A52B943A37BD1FEE175482AABA3C8BD8849D2BEE1938C" - "978842324A9ABB0E1B3F549BAF4DEF65141B53AA84034E15E23F3BF410320558" - "6BDD61BDF998BEB795DF1924E0484C4F60497CAD934760D579441F81BABA151F" - "61CB4CEA53FE62557E2918A608DF585E6575ECD5E16A3D2D21F471919214869E" - "265F1DD00F048B2E41F60B413BC98BF977D044A38E9ABEDAE01338468D9D7B9A" - "EBDA2DA877B8585DDDC33BD1514A5E32D7303C026E3C45F77DE561C5DCDFCE99", + "E2D587706265125931BB129027016325ABA59951E0771340DF0808D84F176CD9" + "C0F3CCB9D57A205799BC04462E4D23F89655D9638652256E559455E79AC253FE" + "19A3C9E16AA936A3C805BA9DBF6FC195F6F7542FA83FF5642141CBB4CBBC2334" + "95B34812170B31FDF7655F007AD2C077EB912C5E901E8B32B39C34889EF1F946" + "C6C03C727DE89CF042499EC29A5EB50EC11C9C31137E57FCC3C926B4118975BB" + "5101D4C0D7D7F8C857521011B2EF7411F8BEC55354475628797339C1734FDA97" + "FE0F1789B08F8872C9BEA41BF215626EFB3D35A00DC8295C044B7798EB9C1B5F" + "F8E8B8A591CFCA7789E509CA219348C81CDA7CB32994CCD5913D41A64ECDD23F", 16 ), # Modulus int("010001", 16) # Exponent @@ -199,6 +199,54 @@ 16 ), # Modulus int("010001", 16) # Exponent + ), + + # -3997872768018684475 + 0xc884b3e62d09e5c5 - (1 << 64): PublicKey( # CDN DC-201 + # -----BEGIN RSA PUBLIC KEY----- + # MIIBCgKCAQEAug6fETVb7NkXYYu5ueZuM0pqw1heuqUrZNYomQN0lS0o7i6mAWwb + # 1/FiscFK+y4LQSSEx+oUzXAhjmll9fmb4e7PbUiXo8MuXO0Rj3e5416DXfTiOYGW + # XlFRV0aQzu8agy1epKwkFDidnmy7g5rJJV0q1+3eR+Jk2OEc/B6lMAOv3fBU6xhE + # ZByN9gqc6fvkNo13PQ8JYZUSGttzLlYy76uFmvFBhRsJU+LNQ2+bsTHwafSffVYl + # Z2boJOblvqbRWe453CzssaSWywGXOQmWvVbEe7F8q1ki/s7S8BxYWrhSLJ6bsu9V + # ZWnIHD9vB34QF8IABPRE93mhCOHBqJxSBQIDAQAB + # -----END RSA PUBLIC KEY----- + int( + "BA0E9F11355BECD917618BB9B9E66E334A6AC3585EBAA52B64D628990374952D" + "28EE2EA6016C1BD7F162B1C14AFB2E0B412484C7EA14CD70218E6965F5F99BE1" + "EECF6D4897A3C32E5CED118F77B9E35E835DF4E23981965E5151574690CEEF1A" + "832D5EA4AC2414389D9E6CBB839AC9255D2AD7EDDE47E264D8E11CFC1EA53003" + "AFDDF054EB1844641C8DF60A9CE9FBE4368D773D0F096195121ADB732E5632EF" + "AB859AF141851B0953E2CD436F9BB131F069F49F7D56256766E824E6E5BEA6D1" + "59EE39DC2CECB1A496CB0197390996BD56C47BB17CAB5922FECED2F01C585AB8" + "522C9E9BB2EF556569C81C3F6F077E1017C20004F444F779A108E1C1A89C5205", + 16 + ), # Modulus + int("010001", 16) # Exponent + ), + + # -4960899639492471258 + 0xbb27580fd5b01626 - (1 << 64): PublicKey( # CDN DC-203 + # -----BEGIN RSA PUBLIC KEY----- + # MIIBCgKCAQEAv/L6td+mj7Dl81NHfu+Xf1KNtvZPR1tS5xFqkiUson1u7D2ulK05 + # jM8HKvpV1o+1HPPqhaXhasvsX90u3TIHRQ0zuJKJxKAiZo3GK7phHozjAJ9VUFbO + # 7jKAa5BTE9tXgA5ZwJAiQWb3U6ykwRzk3fFRe5WaW7xfVUiepxyWGdr1eecoWCfB + # af1TCXfcS7vcyljNT03pwt2YyS5iXE5IB5wBB5yqSSm4GYtWWR67UjIsXBd77TRp + # foLGpfOdUHxBz4ZSj8D76m1zlpID5J2pF6bH4+ZCz0SUpv3j7bE8WFlvgMfwEPhw + # xMYidRGayq9YlLlYd4D+Yoq0U6jS3MWTRQIDAQAB + # -----END RSA PUBLIC KEY----- + int( + "BFF2FAB5DFA68FB0E5F353477EEF977F528DB6F64F475B52E7116A92252CA27D" + "6EEC3DAE94AD398CCF072AFA55D68FB51CF3EA85A5E16ACBEC5FDD2EDD320745" + "0D33B89289C4A022668DC62BBA611E8CE3009F555056CEEE32806B905313DB57" + "800E59C090224166F753ACA4C11CE4DDF1517B959A5BBC5F55489EA71C9619DA" + "F579E7285827C169FD530977DC4BBBDCCA58CD4F4DE9C2DD98C92E625C4E4807" + "9C01079CAA4929B8198B56591EBB52322C5C177BED34697E82C6A5F39D507C41" + "CF86528FC0FBEA6D73969203E49DA917A6C7E3E642CF4494A6FDE3EDB13C5859" + "6F80C7F010F870C4C62275119ACAAF5894B9587780FE628AB453A8D2DCC59345", + 16 + ), # Modulus + int("010001", 16) # Exponent ) } diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index 4fce19aa24..187fde7d9f 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -31,7 +31,8 @@ class DataCenter: 2: "149.154.167.51", 3: "149.154.175.100", 4: "149.154.167.91", - 5: "91.108.56.130" + 5: "91.108.56.130", + 203: "91.105.192.100" } PROD_MEDIA = { @@ -55,7 +56,8 @@ class DataCenter: PROD_IPV6_MEDIA = { 2: "2001:067c:04e8:f002:0000:0000:0000:000b", - 4: "2001:067c:04e8:f004:0000:0000:0000:000b" + 4: "2001:067c:04e8:f004:0000:0000:0000:000b", + 203: "2a0a:f280:0203:000a:5000:0000:0000:0100" } def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]: From d9d68529aa6ca24066244e054d0bf87b0606d2c8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Apr 2023 19:55:05 +0200 Subject: [PATCH 533/539] Update Pyrogram to v2.0.105 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 6f9d1fce71..db59589fa0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.104" +__version__ = "2.0.105" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From 2ff67c72aa97447b4439f52e56cd5362b8c77492 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Apr 2023 20:23:42 +0200 Subject: [PATCH 534/539] Move the CDN DC IPv6 to the correct mapping --- pyrogram/session/internals/data_center.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index 187fde7d9f..d314626352 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -51,13 +51,13 @@ class DataCenter: 2: "2001:67c:4e8:f002::a", 3: "2001:b28:f23d:f003::a", 4: "2001:67c:4e8:f004::a", - 5: "2001:b28:f23f:f005::a" + 5: "2001:b28:f23f:f005::a", + 203: "2a0a:f280:0203:000a:5000:0000:0000:0100" } PROD_IPV6_MEDIA = { 2: "2001:067c:04e8:f002:0000:0000:0000:000b", - 4: "2001:067c:04e8:f004:0000:0000:0000:000b", - 203: "2a0a:f280:0203:000a:5000:0000:0000:0100" + 4: "2001:067c:04e8:f004:0000:0000:0000:000b" } def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]: From efac17198b5fcaec1c2628c4bba0c288a4d617d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Apr 2023 20:24:00 +0200 Subject: [PATCH 535/539] Update Pyrogram to v2.0.106 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index db59589fa0..9a6a44accb 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__version__ = "2.0.105" +__version__ = "2.0.106" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2017-present Dan " From f67ce7833b98780f3456c909caef8b8f45757156 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:16:06 +0100 Subject: [PATCH 536/539] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 930d3be406..32f30a8520 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TAG = v$(shell grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2) RM := rm -rf -.PHONY: venv clean-build clean-api clean api build +.PHONY: venv clean-build clean-api clean api build tag dtag venv: $(RM) $(VENV) From dc7379f5ebd3403b069aca4f93f10ad1db6ae793 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:16:42 +0100 Subject: [PATCH 537/539] Update MANIFEST.in --- MANIFEST.in | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index b1f5bc04f3..395ca54ee9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,11 +1,13 @@ -## Include +# Include files include README.md COPYING COPYING.lesser NOTICE requirements.txt recursive-include compiler *.py *.tl *.tsv *.txt recursive-include tests *.py -## Exclude +# Exclude files +exclude pyrogram/raw/all.py + +# Prune directories prune pyrogram/errors/exceptions prune pyrogram/raw/functions prune pyrogram/raw/types prune pyrogram/raw/base -exclude pyrogram/raw/all.py From f5788f350d6bc1dae8c32ec8613977b0c36906bc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:19:55 +0100 Subject: [PATCH 538/539] Update .github templates --- .github/FUNDING.yml | 3 --- .github/ISSUE_TEMPLATE/config.yml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 19d0cd78d1..0000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -github: delivrance -liberapay: delivrance -open_collective: pyrogram diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 453151d8bd..80d40a188d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ blank_issues_enabled: false contact_links: - name: Ask Pyrogram related questions url: https://stackoverflow.com/questions/tagged/pyrogram - about: This place is only for reporting issues about Pyrogram. You can ask questions at StackOverflow. + about: This place is only for reporting issues about Pyrogram. You can ask questions on StackOverflow. - name: Join the Telegram channel url: https://t.me/pyrogram about: Join the official channel and stay tuned for news, updates and announcements. \ No newline at end of file From 30de1e21e3e8b5949971ba0bba56bb818ba43b71 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:20:42 +0100 Subject: [PATCH 539/539] Update README.md --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6b904e2987..e250b40668 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- Pyrogram + Pyrogram
Telegram MTProto API Framework for Python @@ -24,6 +24,9 @@ ## Pyrogram +> [!NOTE] +> The project is no longer maintained or supported. Thanks for appreciating it. + > Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots ``` python @@ -44,14 +47,6 @@ app.run() framework. It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity (bot API alternative) using Python. -### Support - -If you'd like to support Pyrogram, you can consider: - -- [Become a GitHub sponsor](https://github.com/sponsors/delivrance). -- [Become a LiberaPay patron](https://liberapay.com/delivrance). -- [Become an OpenCollective backer](https://opencollective.com/pyrogram). - ### Key Features - **Ready**: Install Pyrogram with pip and start building your applications right away.