From d5517f4d5fb13b6a459315865ae3a756f59d2837 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Jun 2019 14:19:50 +0200 Subject: [PATCH 1/8] Rename Object to TLObject --- compiler/api/compiler.py | 14 +++++++------- compiler/api/template/mtproto.txt | 2 +- pyrogram/api/__init__.py | 4 ++-- pyrogram/api/core/__init__.py | 2 +- pyrogram/api/core/future_salt.py | 4 ++-- pyrogram/api/core/future_salts.py | 4 ++-- pyrogram/api/core/gzip_packed.py | 8 ++++---- pyrogram/api/core/list.py | 6 +++--- pyrogram/api/core/message.py | 8 ++++---- pyrogram/api/core/msg_container.py | 4 ++-- pyrogram/api/core/primitives/bool.py | 6 +++--- pyrogram/api/core/primitives/bytes.py | 4 ++-- pyrogram/api/core/primitives/double.py | 4 ++-- pyrogram/api/core/primitives/int.py | 4 ++-- pyrogram/api/core/primitives/null.py | 4 ++-- pyrogram/api/core/primitives/vector.py | 12 ++++++------ pyrogram/api/core/{object.py => tl_object.py} | 13 ++++++++----- pyrogram/client/client.py | 4 ++-- pyrogram/session/auth.py | 10 +++++----- pyrogram/session/internals/msg_factory.py | 4 ++-- pyrogram/session/session.py | 6 +++--- 21 files changed, 65 insertions(+), 62 deletions(-) rename pyrogram/api/core/{object.py => tl_object.py} (86%) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 64e88c9d..0ecc9212 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -53,10 +53,10 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool return "``{}``".format(t.lower()) elif t == "true": return "``bool``" - elif t == "Object" or t == "X": - return "Any object from :obj:`pyrogram.api.types`" + elif t == "TLObject" or t == "X": + return "Any object from :obj:`~pyrogram.api.types`" elif t == "!X": - return "Any method from :obj:`pyrogram.api.functions`" + return "Any method from :obj:`~pyrogram.api.functions`" elif t.startswith("Vector"): return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1], True, is_pyrogram_type) else: @@ -394,7 +394,7 @@ def start(): ) read_types += "\n " - read_types += "{} = Object.read(b{}) if flags & (1 << {}) else []\n ".format( + read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else []\n ".format( arg_name, ", {}".format(sub_type.title()) if sub_type in core_types else "", index ) else: @@ -403,7 +403,7 @@ def start(): write_types += "b.write(self.{}.write())\n ".format(arg_name) read_types += "\n " - read_types += "{} = Object.read(b) if flags & (1 << {}) else None\n ".format( + read_types += "{} = TLObject.read(b) if flags & (1 << {}) else None\n ".format( arg_name, index ) else: @@ -422,7 +422,7 @@ def start(): ) read_types += "\n " - read_types += "{} = Object.read(b{})\n ".format( + read_types += "{} = TLObject.read(b{})\n ".format( arg_name, ", {}".format(sub_type.title()) if sub_type in core_types else "" ) else: @@ -430,7 +430,7 @@ def start(): write_types += "b.write(self.{}.write())\n ".format(arg_name) read_types += "\n " - read_types += "{} = Object.read(b)\n ".format(arg_name) + read_types += "{} = TLObject.read(b)\n ".format(arg_name) if c.docs: description = c.docs.split("|")[0].split("§")[1] diff --git a/compiler/api/template/mtproto.txt b/compiler/api/template/mtproto.txt index c63525d6..d7d3c7b7 100644 --- a/compiler/api/template/mtproto.txt +++ b/compiler/api/template/mtproto.txt @@ -5,7 +5,7 @@ from io import BytesIO from pyrogram.api.core import * -class {class_name}(Object): +class {class_name}(TLObject): """{docstring_args} """ diff --git a/pyrogram/api/__init__.py b/pyrogram/api/__init__.py index e57f0661..8d7831ff 100644 --- a/pyrogram/api/__init__.py +++ b/pyrogram/api/__init__.py @@ -19,8 +19,8 @@ from importlib import import_module from .all import objects -from .core.object import Object +from .core.tl_object import TLObject for k, v in objects.items(): path, name = v.rsplit(".", 1) - Object.all[k] = getattr(import_module(path), name) + TLObject.all[k] = getattr(import_module(path), name) diff --git a/pyrogram/api/core/__init__.py b/pyrogram/api/core/__init__.py index bf596446..f27a26a5 100644 --- a/pyrogram/api/core/__init__.py +++ b/pyrogram/api/core/__init__.py @@ -22,7 +22,7 @@ from .gzip_packed import GzipPacked from .list import List from .message import Message from .msg_container import MsgContainer -from .object import Object +from .tl_object import TLObject from .primitives import ( Bool, BoolTrue, BoolFalse, Bytes, Double, Int, Long, Int128, Int256, Null, String, Vector diff --git a/pyrogram/api/core/future_salt.py b/pyrogram/api/core/future_salt.py index c4ccea3d..699a416f 100644 --- a/pyrogram/api/core/future_salt.py +++ b/pyrogram/api/core/future_salt.py @@ -18,11 +18,11 @@ from io import BytesIO -from .object import Object +from .tl_object import TLObject from .primitives import Int, Long -class FutureSalt(Object): +class FutureSalt(TLObject): ID = 0x0949d9dc __slots__ = ["valid_since", "valid_until", "salt"] diff --git a/pyrogram/api/core/future_salts.py b/pyrogram/api/core/future_salts.py index 91ee7b51..c749c569 100644 --- a/pyrogram/api/core/future_salts.py +++ b/pyrogram/api/core/future_salts.py @@ -19,11 +19,11 @@ from io import BytesIO from . import FutureSalt -from .object import Object +from .tl_object import TLObject from .primitives import Int, Long -class FutureSalts(Object): +class FutureSalts(TLObject): ID = 0xae500895 __slots__ = ["req_msg_id", "now", "salts"] diff --git a/pyrogram/api/core/gzip_packed.py b/pyrogram/api/core/gzip_packed.py index 135c36bf..4b212184 100644 --- a/pyrogram/api/core/gzip_packed.py +++ b/pyrogram/api/core/gzip_packed.py @@ -19,24 +19,24 @@ from gzip import compress, decompress from io import BytesIO -from .object import Object +from .tl_object import TLObject from .primitives import Int, Bytes -class GzipPacked(Object): +class GzipPacked(TLObject): ID = 0x3072cfa1 __slots__ = ["packed_data"] QUALNAME = "GzipPacked" - def __init__(self, packed_data: Object): + def __init__(self, packed_data: TLObject): self.packed_data = packed_data @staticmethod def read(b: BytesIO, *args) -> "GzipPacked": # Return the Object itself instead of a GzipPacked wrapping it - return Object.read( + return TLObject.read( BytesIO( decompress( Bytes.read(b) diff --git a/pyrogram/api/core/list.py b/pyrogram/api/core/list.py index 922ec64d..4b309a6d 100644 --- a/pyrogram/api/core/list.py +++ b/pyrogram/api/core/list.py @@ -16,13 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .object import Object +from .tl_object import TLObject -class List(list, Object): +class List(list, TLObject): __slots__ = [] def __repr__(self): return "pyrogram.api.core.List([{}])".format( - ",".join(Object.__repr__(i) for i in self) + ",".join(TLObject.__repr__(i) for i in self) ) diff --git a/pyrogram/api/core/message.py b/pyrogram/api/core/message.py index 5b2e5b64..db123db3 100644 --- a/pyrogram/api/core/message.py +++ b/pyrogram/api/core/message.py @@ -18,18 +18,18 @@ from io import BytesIO -from .object import Object +from .tl_object import TLObject from .primitives import Int, Long -class Message(Object): +class Message(TLObject): ID = 0x5bb8e511 # hex(crc32(b"message msg_id:long seqno:int bytes:int body:Object = Message")) __slots__ = ["msg_id", "seq_no", "length", "body"] QUALNAME = "Message" - def __init__(self, body: Object, msg_id: int, seq_no: int, length: int): + def __init__(self, body: TLObject, msg_id: int, seq_no: int, length: int): self.msg_id = msg_id self.seq_no = seq_no self.length = length @@ -42,7 +42,7 @@ class Message(Object): length = Int.read(b) body = b.read(length) - return Message(Object.read(BytesIO(body)), msg_id, seq_no, length) + return Message(TLObject.read(BytesIO(body)), msg_id, seq_no, length) def write(self) -> bytes: b = BytesIO() diff --git a/pyrogram/api/core/msg_container.py b/pyrogram/api/core/msg_container.py index bfc41333..7a17087e 100644 --- a/pyrogram/api/core/msg_container.py +++ b/pyrogram/api/core/msg_container.py @@ -19,11 +19,11 @@ from io import BytesIO from .message import Message -from .object import Object +from .tl_object import TLObject from .primitives import Int -class MsgContainer(Object): +class MsgContainer(TLObject): ID = 0x73f1f8dc __slots__ = ["messages"] diff --git a/pyrogram/api/core/primitives/bool.py b/pyrogram/api/core/primitives/bool.py index 117ee7a4..0d3732e0 100644 --- a/pyrogram/api/core/primitives/bool.py +++ b/pyrogram/api/core/primitives/bool.py @@ -18,10 +18,10 @@ from io import BytesIO -from ..object import Object +from ..tl_object import TLObject -class BoolFalse(Object): +class BoolFalse(TLObject): ID = 0xbc799737 value = False @@ -38,7 +38,7 @@ class BoolTrue(BoolFalse): value = True -class Bool(Object): +class Bool(TLObject): @classmethod def read(cls, b: BytesIO) -> bool: return int.from_bytes(b.read(4), "little") == BoolTrue.ID diff --git a/pyrogram/api/core/primitives/bytes.py b/pyrogram/api/core/primitives/bytes.py index 8030b598..f511fef3 100644 --- a/pyrogram/api/core/primitives/bytes.py +++ b/pyrogram/api/core/primitives/bytes.py @@ -18,10 +18,10 @@ from io import BytesIO -from ..object import Object +from ..tl_object import TLObject -class Bytes(Object): +class Bytes(TLObject): @staticmethod def read(b: BytesIO, *args) -> bytes: length = int.from_bytes(b.read(1), "little") diff --git a/pyrogram/api/core/primitives/double.py b/pyrogram/api/core/primitives/double.py index 3dcaa461..067d08bd 100644 --- a/pyrogram/api/core/primitives/double.py +++ b/pyrogram/api/core/primitives/double.py @@ -19,10 +19,10 @@ from io import BytesIO from struct import unpack, pack -from ..object import Object +from ..tl_object import TLObject -class Double(Object): +class Double(TLObject): @staticmethod def read(b: BytesIO, *args) -> float: return unpack("d", b.read(8))[0] diff --git a/pyrogram/api/core/primitives/int.py b/pyrogram/api/core/primitives/int.py index 7833a610..ea43983c 100644 --- a/pyrogram/api/core/primitives/int.py +++ b/pyrogram/api/core/primitives/int.py @@ -18,10 +18,10 @@ from io import BytesIO -from ..object import Object +from ..tl_object import TLObject -class Int(Object): +class Int(TLObject): SIZE = 4 @classmethod diff --git a/pyrogram/api/core/primitives/null.py b/pyrogram/api/core/primitives/null.py index d2d3b1c0..ffddea94 100644 --- a/pyrogram/api/core/primitives/null.py +++ b/pyrogram/api/core/primitives/null.py @@ -18,10 +18,10 @@ from io import BytesIO -from ..object import Object +from ..tl_object import TLObject -class Null(Object): +class Null(TLObject): ID = 0x56730bcc @staticmethod diff --git a/pyrogram/api/core/primitives/vector.py b/pyrogram/api/core/primitives/vector.py index 720486f2..641b33ef 100644 --- a/pyrogram/api/core/primitives/vector.py +++ b/pyrogram/api/core/primitives/vector.py @@ -20,31 +20,31 @@ from io import BytesIO from . import Int from ..list import List -from ..object import Object +from ..tl_object import TLObject -class Vector(Object): +class Vector(TLObject): ID = 0x1cb5c415 # Method added to handle the special case when a query returns a bare Vector (of Ints); # i.e., RpcResult body starts with 0x1cb5c415 (Vector Id) - e.g., messages.GetMessagesViews. @staticmethod - def _read(b: BytesIO) -> Object or int: + def _read(b: BytesIO) -> TLObject or int: try: - return Object.read(b) + return TLObject.read(b) except KeyError: b.seek(-4, 1) return Int.read(b) @staticmethod - def read(b: BytesIO, t: Object = None) -> list: + def read(b: BytesIO, t: TLObject = None) -> list: return List( t.read(b) if t else Vector._read(b) for _ in range(Int.read(b)) ) - def __new__(cls, value: list, t: Object = None) -> bytes: + def __new__(cls, value: list, t: TLObject = None) -> bytes: return b"".join( [Int(cls.ID, False), Int(len(value))] + [ diff --git a/pyrogram/api/core/object.py b/pyrogram/api/core/tl_object.py similarity index 86% rename from pyrogram/api/core/object.py rename to pyrogram/api/core/tl_object.py index 9d1a4852..4b951404 100644 --- a/pyrogram/api/core/object.py +++ b/pyrogram/api/core/tl_object.py @@ -21,7 +21,7 @@ from io import BytesIO from json import dumps -class Object: +class TLObject: all = {} __slots__ = [] @@ -30,13 +30,13 @@ class Object: @staticmethod def read(b: BytesIO, *args): # TODO: Rename b -> data - return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args) + return TLObject.all[int.from_bytes(b.read(4), "little")].read(b, *args) def write(self, *args) -> bytes: pass @staticmethod - def default(obj: "Object"): + def default(obj: "TLObject"): if isinstance(obj, bytes): return repr(obj) @@ -50,7 +50,7 @@ class Object: ) def __str__(self) -> str: - return dumps(self, indent=4, default=Object.default, ensure_ascii=False) + return dumps(self, indent=4, default=TLObject.default, ensure_ascii=False) def __repr__(self) -> str: return "pyrogram.api.{}({})".format( @@ -62,7 +62,7 @@ class Object: ) ) - def __eq__(self, other: "Object") -> bool: + def __eq__(self, other: "TLObject") -> bool: for attr in self.__slots__: try: if getattr(self, attr) != getattr(other, attr): @@ -77,3 +77,6 @@ class Object: def __getitem__(self, item): return getattr(self, item) + + def __setitem__(self, key, value): + setattr(self, key, value) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2ba6b8fa..08a3072e 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -37,7 +37,7 @@ from threading import Thread from typing import Union, List from pyrogram.api import functions, types -from pyrogram.api.core import Object +from pyrogram.api.core import TLObject from pyrogram.client.handlers import DisconnectHandler from pyrogram.client.handlers.handler import Handler from pyrogram.client.methods.password.utils import compute_check @@ -998,7 +998,7 @@ class Client(Methods, BaseClient): log.debug("{} stopped".format(name)) - def send(self, data: Object, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT): + def send(self, data: TLObject, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT): """Send raw Telegram queries. This method makes it possible to manually call every single Telegram API method in a low-level manner. diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 89e5b61f..fb6e7ca3 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -23,7 +23,7 @@ from io import BytesIO from os import urandom from pyrogram.api import functions, types -from pyrogram.api.core import Object, Long, Int +from pyrogram.api.core import TLObject, Long, Int from pyrogram.connection import Connection from pyrogram.crypto import AES, RSA, Prime from .internals import MsgId @@ -43,7 +43,7 @@ class Auth: self.connection = None @staticmethod - def pack(data: Object) -> bytes: + def pack(data: TLObject) -> bytes: return ( bytes(8) + Long(MsgId()) @@ -54,9 +54,9 @@ class Auth: @staticmethod def unpack(b: BytesIO): b.seek(20) # Skip auth_key_id (8), message_id (8) and message_length (4) - return Object.read(b) + return TLObject.read(b) - def send(self, data: Object): + def send(self, data: TLObject): data = self.pack(data) self.connection.send(data) response = BytesIO(self.connection.recv()) @@ -158,7 +158,7 @@ class Auth: answer_with_hash = AES.ige256_decrypt(encrypted_answer, tmp_aes_key, tmp_aes_iv) answer = answer_with_hash[20:] - server_dh_inner_data = Object.read(BytesIO(answer)) + server_dh_inner_data = TLObject.read(BytesIO(answer)) log.debug("Done decrypting answer") diff --git a/pyrogram/session/internals/msg_factory.py b/pyrogram/session/internals/msg_factory.py index 7d922ec3..2b833ce8 100644 --- a/pyrogram/session/internals/msg_factory.py +++ b/pyrogram/session/internals/msg_factory.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.api.core import Message, MsgContainer, Object +from pyrogram.api.core import Message, MsgContainer, TLObject from pyrogram.api.functions import Ping from pyrogram.api.types import MsgsAck, HttpWait from .msg_id import MsgId @@ -29,7 +29,7 @@ class MsgFactory: def __init__(self): self.seq_no = SeqNo() - def __call__(self, body: Object) -> Message: + def __call__(self, body: TLObject) -> Message: return Message( body, MsgId(), diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index e4260be4..8ef5570c 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -30,7 +30,7 @@ import pyrogram from pyrogram import __copyright__, __license__, __version__ from pyrogram.api import functions, types, core from pyrogram.api.all import layer -from pyrogram.api.core import Message, Object, MsgContainer, Long, FutureSalt, Int +from pyrogram.api.core import Message, TLObject, MsgContainer, Long, FutureSalt, Int from pyrogram.connection import Connection from pyrogram.crypto import AES, KDF from pyrogram.errors import RPCError, InternalServerError, AuthKeyDuplicated @@ -391,7 +391,7 @@ class Session: log.debug("RecvThread stopped") - def _send(self, data: Object, wait_response: bool = True, timeout: float = WAIT_TIMEOUT): + def _send(self, data: TLObject, wait_response: bool = True, timeout: float = WAIT_TIMEOUT): message = self.msg_factory(data) msg_id = message.msg_id @@ -422,7 +422,7 @@ class Session: else: return result - def send(self, data: Object, retries: int = MAX_RETRIES, timeout: float = WAIT_TIMEOUT): + def send(self, data: TLObject, retries: int = MAX_RETRIES, timeout: float = WAIT_TIMEOUT): self.is_connected.wait(self.WAIT_TIMEOUT) try: From 9a44c79a82080de0ecb11728f4f4259c30db9577 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 3 Jun 2019 16:56:37 +0200 Subject: [PATCH 2/8] Rename PyrogramType to Object --- .../client/types/inline_mode/inline_query.py | 4 +- .../types/inline_mode/inline_query_result.py | 4 +- .../todo/inline_query_result_audio.py | 4 +- .../todo/inline_query_result_cached_audio.py | 4 +- .../inline_query_result_cached_document.py | 4 +- .../todo/inline_query_result_cached_gif.py | 4 +- .../inline_query_result_cached_mpeg4_gif.py | 4 +- .../todo/inline_query_result_cached_photo.py | 4 +- .../inline_query_result_cached_sticker.py | 4 +- .../todo/inline_query_result_cached_video.py | 4 +- .../todo/inline_query_result_cached_voice.py | 4 +- .../todo/inline_query_result_contact.py | 4 +- .../todo/inline_query_result_document.py | 4 +- .../todo/inline_query_result_game.py | 4 +- .../todo/inline_query_result_gif.py | 4 +- .../todo/inline_query_result_location.py | 4 +- .../todo/inline_query_result_mpeg4_gif.py | 4 +- .../todo/inline_query_result_photo.py | 4 +- .../todo/inline_query_result_venue.py | 4 +- .../todo/inline_query_result_video.py | 4 +- .../todo/inline_query_result_voice.py | 4 +- .../client/types/input_media/input_media.py | 4 +- .../types/input_media/input_phone_contact.py | 4 +- .../input_message_content.py | 4 +- .../client/types/keyboards/callback_game.py | 4 +- .../client/types/keyboards/callback_query.py | 4 +- .../client/types/keyboards/force_reply.py | 4 +- .../client/types/keyboards/game_high_score.py | 4 +- .../types/keyboards/game_high_scores.py | 4 +- .../types/keyboards/inline_keyboard_button.py | 4 +- .../types/keyboards/inline_keyboard_markup.py | 4 +- .../client/types/keyboards/keyboard_button.py | 4 +- .../types/keyboards/reply_keyboard_markup.py | 4 +- .../types/keyboards/reply_keyboard_remove.py | 4 +- .../types/{pyrogram_list.py => list.py} | 8 +-- .../types/messages_and_media/animation.py | 4 +- .../client/types/messages_and_media/audio.py | 4 +- .../types/messages_and_media/contact.py | 4 +- .../types/messages_and_media/document.py | 4 +- .../client/types/messages_and_media/game.py | 4 +- .../types/messages_and_media/location.py | 4 +- .../types/messages_and_media/message.py | 4 +- .../messages_and_media/message_entity.py | 4 +- .../types/messages_and_media/messages.py | 4 +- .../client/types/messages_and_media/photo.py | 4 +- .../client/types/messages_and_media/photos.py | 4 +- .../client/types/messages_and_media/poll.py | 4 +- .../types/messages_and_media/poll_option.py | 4 +- .../types/messages_and_media/sticker.py | 4 +- .../messages_and_media/stripped_thumbnail.py | 4 +- .../types/messages_and_media/thumbnail.py | 4 +- .../client/types/messages_and_media/venue.py | 4 +- .../client/types/messages_and_media/video.py | 4 +- .../types/messages_and_media/video_note.py | 4 +- .../client/types/messages_and_media/voice.py | 4 +- .../types/{pyrogram_type.py => object.py} | 63 +++++++++++-------- pyrogram/client/types/user_and_chats/chat.py | 4 +- .../types/user_and_chats/chat_member.py | 4 +- .../types/user_and_chats/chat_members.py | 4 +- .../types/user_and_chats/chat_permissions.py | 4 +- .../client/types/user_and_chats/chat_photo.py | 4 +- .../types/user_and_chats/chat_preview.py | 4 +- .../client/types/user_and_chats/dialog.py | 4 +- .../client/types/user_and_chats/dialogs.py | 4 +- pyrogram/client/types/user_and_chats/user.py | 4 +- .../types/user_and_chats/user_status.py | 4 +- 66 files changed, 168 insertions(+), 159 deletions(-) rename pyrogram/client/types/{pyrogram_list.py => list.py} (85%) rename pyrogram/client/types/{pyrogram_type.py => object.py} (63%) diff --git a/pyrogram/client/types/inline_mode/inline_query.py b/pyrogram/client/types/inline_mode/inline_query.py index 1985a0c0..6bfc58c3 100644 --- a/pyrogram/client/types/inline_mode/inline_query.py +++ b/pyrogram/client/types/inline_mode/inline_query.py @@ -22,12 +22,12 @@ import pyrogram from pyrogram.api import types from .inline_query_result import InlineQueryResult from ..messages_and_media import Location -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update from ..user_and_chats import User -class InlineQuery(PyrogramType, Update): +class InlineQuery(Object, Update): """An incoming inline query. When the user sends an empty query, your bot could return some default or trending results. diff --git a/pyrogram/client/types/inline_mode/inline_query_result.py b/pyrogram/client/types/inline_mode/inline_query_result.py index 4b7f7ca3..74fe77d3 100644 --- a/pyrogram/client/types/inline_mode/inline_query_result.py +++ b/pyrogram/client/types/inline_mode/inline_query_result.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_type import PyrogramType +from ..object import Object """- :obj:`InlineQueryResultCachedAudio` - :obj:`InlineQueryResultCachedDocument` @@ -39,7 +39,7 @@ from ..pyrogram_type import PyrogramType - :obj:`InlineQueryResultVoice`""" -class InlineQueryResult(PyrogramType): +class InlineQueryResult(Object): """One result of an inline query. Pyrogram currently supports results of the following 20 types: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py index 6ca0478a..dbda676d 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_audio.py +++ b/pyrogram/client/types/inline_mode/todo/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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultAudio(PyrogramType): +class InlineQueryResultAudio(Object): """Represents a link to an mp3 audio file. 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py index dc51139b..a4ac1ec8 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_audio.py @@ -23,10 +23,10 @@ from pyrogram.api import types from pyrogram.errors import FileIdInvalid from pyrogram.client.ext import utils, BaseClient from pyrogram.client.style import HTML, Markdown -from pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedAudio(PyrogramType): +class InlineQueryResultCachedAudio(Object): """Represents a link to an 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. diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py index ad6cb9af..0dfde1c4 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_document.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedDocument(PyrogramType): +class InlineQueryResultCachedDocument(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py index 1c836f20..819b383f 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_gif.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedGif(PyrogramType): +class InlineQueryResultCachedGif(Object): """Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py index 2082150d..9856af66 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_mpeg4_gif.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedMpeg4Gif(PyrogramType): +class InlineQueryResultCachedMpeg4Gif(Object): """Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 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 animation. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py index 20c1adbc..53b479f9 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_photo.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedPhoto(PyrogramType): +class InlineQueryResultCachedPhoto(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py index 4711cd72..6b2b37c9 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_sticker.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedSticker(PyrogramType): +class InlineQueryResultCachedSticker(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py index e47cae1b..3a04a766 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_video.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedVideo(PyrogramType): +class InlineQueryResultCachedVideo(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py index 3091cf65..fbdf6c19 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_cached_voice.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultCachedVoice(PyrogramType): +class InlineQueryResultCachedVoice(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py index 60512f0d..a64d6ace 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_contact.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultContact(PyrogramType): +class InlineQueryResultContact(Object): """Represents a 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py index a95dd2e9..007f237b 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_document.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_document.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultDocument(PyrogramType): +class InlineQueryResultDocument(Object): """Represents a 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. Currently, only .PDF and .ZIP files can be sent using this method. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py index 98654463..bd6f25d2 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_game.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_game.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultGame(PyrogramType): +class InlineQueryResultGame(Object): """Represents a Game. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py index d84e098b..7273b79a 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_gif.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultGif(PyrogramType): +class InlineQueryResultGif(Object): """Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py index cd05c832..a32fc93d 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_location.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_location.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultLocation(PyrogramType): +class InlineQueryResultLocation(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py index cb704eeb..04c68cf7 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_mpeg4_gif.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultMpeg4Gif(PyrogramType): +class InlineQueryResultMpeg4Gif(Object): """Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py index db6b9090..57f36fae 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_photo.py @@ -18,10 +18,10 @@ from pyrogram.api import types from pyrogram.client.style import HTML, Markdown -from pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultPhoto(PyrogramType): +class InlineQueryResultPhoto(Object): """Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py index 51ee8ae7..3343ccf9 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_venue.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultVenue(PyrogramType): +class InlineQueryResultVenue(Object): """Represents 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py index c8e27f79..ebfe2047 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_video.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_video.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultVideo(PyrogramType): +class InlineQueryResultVideo(Object): """Represents a link to a page containing an embedded video player or a video file. 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. Attributes: diff --git a/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py b/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py index 23cc741f..4e2bbb09 100644 --- a/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.py +++ b/pyrogram/client/types/inline_mode/todo/inline_query_result_voice.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 pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object -class InlineQueryResultVoice(PyrogramType): +class InlineQueryResultVoice(Object): """Represents a 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 the voice message. Attributes: diff --git a/pyrogram/client/types/input_media/input_media.py b/pyrogram/client/types/input_media/input_media.py index 8360862f..2b5d7f0f 100644 --- a/pyrogram/client/types/input_media/input_media.py +++ b/pyrogram/client/types/input_media/input_media.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 ..pyrogram_type import PyrogramType +from ..object import Object -class InputMedia(PyrogramType): +class InputMedia(Object): """Content of a media message to be sent. It should be one of: diff --git a/pyrogram/client/types/input_media/input_phone_contact.py b/pyrogram/client/types/input_media/input_phone_contact.py index c1627516..e49cee30 100644 --- a/pyrogram/client/types/input_media/input_phone_contact.py +++ b/pyrogram/client/types/input_media/input_phone_contact.py @@ -18,10 +18,10 @@ from pyrogram.api.types import InputPhoneContact as RawInputPhoneContact from pyrogram.session.internals import MsgId -from ..pyrogram_type import PyrogramType +from ..object import Object -class InputPhoneContact(PyrogramType): +class InputPhoneContact(Object): """A Phone Contact to be added in your Telegram address book. It is intended to be used with :meth:`~Client.add_contacts() ` diff --git a/pyrogram/client/types/input_message_content/input_message_content.py b/pyrogram/client/types/input_message_content/input_message_content.py index 50e068b7..1941ffb5 100644 --- a/pyrogram/client/types/input_message_content/input_message_content.py +++ b/pyrogram/client/types/input_message_content/input_message_content.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 ..pyrogram_type import PyrogramType +from ..object import Object """- :obj:`InputLocationMessageContent` - :obj:`InputVenueMessageContent` - :obj:`InputContactMessageContent`""" -class InputMessageContent(PyrogramType): +class InputMessageContent(Object): """Content of a message to be sent as a result of an inline query. Pyrogram currently supports the following 4 types: diff --git a/pyrogram/client/types/keyboards/callback_game.py b/pyrogram/client/types/keyboards/callback_game.py index 4fa43a30..acf6df60 100644 --- a/pyrogram/client/types/keyboards/callback_game.py +++ b/pyrogram/client/types/keyboards/callback_game.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 ..pyrogram_type import PyrogramType +from ..object import Object -class CallbackGame(PyrogramType): +class CallbackGame(Object): """Placeholder, currently holds no information. Use BotFather to set up your game. diff --git a/pyrogram/client/types/keyboards/callback_query.py b/pyrogram/client/types/keyboards/callback_query.py index fe6a2175..fa0d8be2 100644 --- a/pyrogram/client/types/keyboards/callback_query.py +++ b/pyrogram/client/types/keyboards/callback_query.py @@ -22,12 +22,12 @@ from typing import Union import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update from ..user_and_chats import User -class CallbackQuery(PyrogramType, Update): +class CallbackQuery(Object, Update): """An incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field *message* diff --git a/pyrogram/client/types/keyboards/force_reply.py b/pyrogram/client/types/keyboards/force_reply.py index 5b263d03..59405529 100644 --- a/pyrogram/client/types/keyboards/force_reply.py +++ b/pyrogram/client/types/keyboards/force_reply.py @@ -17,10 +17,10 @@ # along with Pyrogram. If not, see . from pyrogram.api.types import ReplyKeyboardForceReply -from ..pyrogram_type import PyrogramType +from ..object import Object -class ForceReply(PyrogramType): +class ForceReply(Object): """Object used to force clients to show a reply interface. Upon receiving a message with this object, Telegram clients will display a reply interface to the user. diff --git a/pyrogram/client/types/keyboards/game_high_score.py b/pyrogram/client/types/keyboards/game_high_score.py index 56389b17..5d576ad4 100644 --- a/pyrogram/client/types/keyboards/game_high_score.py +++ b/pyrogram/client/types/keyboards/game_high_score.py @@ -19,11 +19,11 @@ import pyrogram from pyrogram.api import types -from pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object from pyrogram.client.types.user_and_chats import User -class GameHighScore(PyrogramType): +class GameHighScore(Object): """One row of the high scores table for a game. Parameters: diff --git a/pyrogram/client/types/keyboards/game_high_scores.py b/pyrogram/client/types/keyboards/game_high_scores.py index 8183b9b0..ea557cd5 100644 --- a/pyrogram/client/types/keyboards/game_high_scores.py +++ b/pyrogram/client/types/keyboards/game_high_scores.py @@ -20,11 +20,11 @@ from typing import List import pyrogram from pyrogram.api import types -from pyrogram.client.types.pyrogram_type import PyrogramType +from pyrogram.client.types.object import Object from .game_high_score import GameHighScore -class GameHighScores(PyrogramType): +class GameHighScores(Object): """The high scores table for a game. Parameters: diff --git a/pyrogram/client/types/keyboards/inline_keyboard_button.py b/pyrogram/client/types/keyboards/inline_keyboard_button.py index 08ad0f35..54aa7802 100644 --- a/pyrogram/client/types/keyboards/inline_keyboard_button.py +++ b/pyrogram/client/types/keyboards/inline_keyboard_button.py @@ -23,10 +23,10 @@ from pyrogram.api.types import ( KeyboardButtonSwitchInline, KeyboardButtonGame ) from .callback_game import CallbackGame -from ..pyrogram_type import PyrogramType +from ..object import Object -class InlineKeyboardButton(PyrogramType): +class InlineKeyboardButton(Object): """One button of an inline keyboard. You must use exactly one of the optional fields. diff --git a/pyrogram/client/types/keyboards/inline_keyboard_markup.py b/pyrogram/client/types/keyboards/inline_keyboard_markup.py index c7230eaf..7b811f88 100644 --- a/pyrogram/client/types/keyboards/inline_keyboard_markup.py +++ b/pyrogram/client/types/keyboards/inline_keyboard_markup.py @@ -20,10 +20,10 @@ from typing import List from pyrogram.api.types import ReplyInlineMarkup, KeyboardButtonRow from . import InlineKeyboardButton -from ..pyrogram_type import PyrogramType +from ..object import Object -class InlineKeyboardMarkup(PyrogramType): +class InlineKeyboardMarkup(Object): """An inline keyboard that appears right next to the message it belongs to. Parameters: diff --git a/pyrogram/client/types/keyboards/keyboard_button.py b/pyrogram/client/types/keyboards/keyboard_button.py index 93d2e5ef..2dc09f5d 100644 --- a/pyrogram/client/types/keyboards/keyboard_button.py +++ b/pyrogram/client/types/keyboards/keyboard_button.py @@ -18,10 +18,10 @@ from pyrogram.api.types import KeyboardButton as RawKeyboardButton from pyrogram.api.types import KeyboardButtonRequestPhone, KeyboardButtonRequestGeoLocation -from ..pyrogram_type import PyrogramType +from ..object import Object -class KeyboardButton(PyrogramType): +class KeyboardButton(Object): """One button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive. diff --git a/pyrogram/client/types/keyboards/reply_keyboard_markup.py b/pyrogram/client/types/keyboards/reply_keyboard_markup.py index c4b37b7c..4e666d1f 100644 --- a/pyrogram/client/types/keyboards/reply_keyboard_markup.py +++ b/pyrogram/client/types/keyboards/reply_keyboard_markup.py @@ -21,10 +21,10 @@ from typing import List, Union from pyrogram.api.types import KeyboardButtonRow from pyrogram.api.types import ReplyKeyboardMarkup as RawReplyKeyboardMarkup from . import KeyboardButton -from ..pyrogram_type import PyrogramType +from ..object import Object -class ReplyKeyboardMarkup(PyrogramType): +class ReplyKeyboardMarkup(Object): """A custom keyboard with reply options. Parameters: diff --git a/pyrogram/client/types/keyboards/reply_keyboard_remove.py b/pyrogram/client/types/keyboards/reply_keyboard_remove.py index 9d6eb7d5..8dd84f72 100644 --- a/pyrogram/client/types/keyboards/reply_keyboard_remove.py +++ b/pyrogram/client/types/keyboards/reply_keyboard_remove.py @@ -17,10 +17,10 @@ # along with Pyrogram. If not, see . from pyrogram.api.types import ReplyKeyboardHide -from ..pyrogram_type import PyrogramType +from ..object import Object -class ReplyKeyboardRemove(PyrogramType): +class ReplyKeyboardRemove(Object): """Object used to tell clients to remove a bot keyboard. Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display diff --git a/pyrogram/client/types/pyrogram_list.py b/pyrogram/client/types/list.py similarity index 85% rename from pyrogram/client/types/pyrogram_list.py rename to pyrogram/client/types/list.py index cb802e51..cec2d8a2 100644 --- a/pyrogram/client/types/pyrogram_list.py +++ b/pyrogram/client/types/list.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 .pyrogram_type import PyrogramType +from .object import Object -class PyrogramList(list): +class List(list): __slots__ = [] def __str__(self): # noinspection PyCallByClass - return PyrogramType.__str__(self) + return Object.__str__(self) def __repr__(self): return "pyrogram.client.types.pyrogram_list.PyrogramList([{}])".format( - ",".join(PyrogramType.__repr__(i) for i in self) + ",".join(Object.__repr__(i) for i in self) ) diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py index d729c3ac..0dfbed17 100644 --- a/pyrogram/client/types/messages_and_media/animation.py +++ b/pyrogram/client/types/messages_and_media/animation.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Animation(PyrogramType): +class Animation(Object): """An animation file (GIF or H.264/MPEG-4 AVC video without sound). Parameters: diff --git a/pyrogram/client/types/messages_and_media/audio.py b/pyrogram/client/types/messages_and_media/audio.py index ccea2f3c..64e450f4 100644 --- a/pyrogram/client/types/messages_and_media/audio.py +++ b/pyrogram/client/types/messages_and_media/audio.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Audio(PyrogramType): +class Audio(Object): """An audio file to be treated as music by the Telegram clients. Parameters: diff --git a/pyrogram/client/types/messages_and_media/contact.py b/pyrogram/client/types/messages_and_media/contact.py index 9205304e..d18f5e18 100644 --- a/pyrogram/client/types/messages_and_media/contact.py +++ b/pyrogram/client/types/messages_and_media/contact.py @@ -19,10 +19,10 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object -class Contact(PyrogramType): +class Contact(Object): """A phone contact. Parameters: diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py index a8838531..ad48a847 100644 --- a/pyrogram/client/types/messages_and_media/document.py +++ b/pyrogram/client/types/messages_and_media/document.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Document(PyrogramType): +class Document(Object): """A generic file (as opposed to photos, voice messages, audio files, ...). Parameters: diff --git a/pyrogram/client/types/messages_and_media/game.py b/pyrogram/client/types/messages_and_media/game.py index 1377173a..2b400e65 100644 --- a/pyrogram/client/types/messages_and_media/game.py +++ b/pyrogram/client/types/messages_and_media/game.py @@ -20,10 +20,10 @@ import pyrogram from pyrogram.api import types from .animation import Animation from .photo import Photo -from ..pyrogram_type import PyrogramType +from ..object import Object -class Game(PyrogramType): +class Game(Object): """A game. Use BotFather to create and edit games, their short names will act as unique identifiers. diff --git a/pyrogram/client/types/messages_and_media/location.py b/pyrogram/client/types/messages_and_media/location.py index 55def7a0..5af55f0f 100644 --- a/pyrogram/client/types/messages_and_media/location.py +++ b/pyrogram/client/types/messages_and_media/location.py @@ -19,10 +19,10 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object -class Location(PyrogramType): +class Location(Object): """A point on the map. Parameters: diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index c3a12f3e..f7dff7b5 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -27,7 +27,7 @@ from .contact import Contact from .location import Location from .message_entity import MessageEntity from ..messages_and_media.photo import Photo -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update from ..user_and_chats.chat import Chat from ..user_and_chats.user import User @@ -59,7 +59,7 @@ class Str(str): return self._client.html.unparse(self, self._entities) -class Message(PyrogramType, Update): +class Message(Object, Update): """A message. Parameters: diff --git a/pyrogram/client/types/messages_and_media/message_entity.py b/pyrogram/client/types/messages_and_media/message_entity.py index e369e74e..5f3483ee 100644 --- a/pyrogram/client/types/messages_and_media/message_entity.py +++ b/pyrogram/client/types/messages_and_media/message_entity.py @@ -19,11 +19,11 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ..user_and_chats.user import User -class MessageEntity(PyrogramType): +class MessageEntity(Object): """One special entity in a text message. For example, hashtags, usernames, URLs, etc. diff --git a/pyrogram/client/types/messages_and_media/messages.py b/pyrogram/client/types/messages_and_media/messages.py index f94f1951..ee516f20 100644 --- a/pyrogram/client/types/messages_and_media/messages.py +++ b/pyrogram/client/types/messages_and_media/messages.py @@ -21,12 +21,12 @@ from typing import List, Union import pyrogram from pyrogram.api import types from .message import Message -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update from ..user_and_chats import Chat -class Messages(PyrogramType, Update): +class Messages(Object, Update): """Contains a chat's messages. Parameters: diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index ca42c3eb..b5d80b82 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Photo(PyrogramType): +class Photo(Object): """A Photo. Parameters: diff --git a/pyrogram/client/types/messages_and_media/photos.py b/pyrogram/client/types/messages_and_media/photos.py index 1d5b193e..a1803923 100644 --- a/pyrogram/client/types/messages_and_media/photos.py +++ b/pyrogram/client/types/messages_and_media/photos.py @@ -20,10 +20,10 @@ from typing import List import pyrogram from .photo import Photo -from ..pyrogram_type import PyrogramType +from ..object import Object -class Photos(PyrogramType): +class Photos(Object): """Contains a user's profile pictures. Parameters: diff --git a/pyrogram/client/types/messages_and_media/poll.py b/pyrogram/client/types/messages_and_media/poll.py index e6c97bfb..2570fdf1 100644 --- a/pyrogram/client/types/messages_and_media/poll.py +++ b/pyrogram/client/types/messages_and_media/poll.py @@ -21,11 +21,11 @@ from typing import List, Union import pyrogram from pyrogram.api import types from .poll_option import PollOption -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update -class Poll(PyrogramType, Update): +class Poll(Object, Update): """A Poll. Parameters: diff --git a/pyrogram/client/types/messages_and_media/poll_option.py b/pyrogram/client/types/messages_and_media/poll_option.py index e7eb1f5f..35f6b071 100644 --- a/pyrogram/client/types/messages_and_media/poll_option.py +++ b/pyrogram/client/types/messages_and_media/poll_option.py @@ -17,10 +17,10 @@ # along with Pyrogram. If not, see . import pyrogram -from ..pyrogram_type import PyrogramType +from ..object import Object -class PollOption(PyrogramType): +class PollOption(Object): """Contains information about one answer option in a poll. Parameters: diff --git a/pyrogram/client/types/messages_and_media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py index d133b31b..9e528dd8 100644 --- a/pyrogram/client/types/messages_and_media/sticker.py +++ b/pyrogram/client/types/messages_and_media/sticker.py @@ -24,11 +24,11 @@ import pyrogram from pyrogram.api import types, functions from pyrogram.errors import StickersetInvalid from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Sticker(PyrogramType): +class Sticker(Object): """A sticker. Parameters: diff --git a/pyrogram/client/types/messages_and_media/stripped_thumbnail.py b/pyrogram/client/types/messages_and_media/stripped_thumbnail.py index 31638fc2..4dbeb7d1 100644 --- a/pyrogram/client/types/messages_and_media/stripped_thumbnail.py +++ b/pyrogram/client/types/messages_and_media/stripped_thumbnail.py @@ -18,10 +18,10 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object -class StrippedThumbnail(PyrogramType): +class StrippedThumbnail(Object): """A stripped thumbnail Parameters: diff --git a/pyrogram/client/types/messages_and_media/thumbnail.py b/pyrogram/client/types/messages_and_media/thumbnail.py index 0ff15e66..ee173b1c 100644 --- a/pyrogram/client/types/messages_and_media/thumbnail.py +++ b/pyrogram/client/types/messages_and_media/thumbnail.py @@ -23,10 +23,10 @@ import pyrogram from pyrogram.api import types from pyrogram.client.ext.utils import encode from .stripped_thumbnail import StrippedThumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object -class Thumbnail(PyrogramType): +class Thumbnail(Object): """One size of a photo or a file/sticker thumbnail. Parameters: diff --git a/pyrogram/client/types/messages_and_media/venue.py b/pyrogram/client/types/messages_and_media/venue.py index e54a812e..45d9368f 100644 --- a/pyrogram/client/types/messages_and_media/venue.py +++ b/pyrogram/client/types/messages_and_media/venue.py @@ -19,10 +19,10 @@ import pyrogram from pyrogram.api import types from .location import Location -from ..pyrogram_type import PyrogramType +from ..object import Object -class Venue(PyrogramType): +class Venue(Object): """A venue. Parameters: diff --git a/pyrogram/client/types/messages_and_media/video.py b/pyrogram/client/types/messages_and_media/video.py index 7a20283f..feda9711 100644 --- a/pyrogram/client/types/messages_and_media/video.py +++ b/pyrogram/client/types/messages_and_media/video.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Video(PyrogramType): +class Video(Object): """A video file. Parameters: diff --git a/pyrogram/client/types/messages_and_media/video_note.py b/pyrogram/client/types/messages_and_media/video_note.py index 34f5972f..b1d9bcdb 100644 --- a/pyrogram/client/types/messages_and_media/video_note.py +++ b/pyrogram/client/types/messages_and_media/video_note.py @@ -22,11 +22,11 @@ from typing import List import pyrogram from pyrogram.api import types from .thumbnail import Thumbnail -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class VideoNote(PyrogramType): +class VideoNote(Object): """A video note. Parameters: diff --git a/pyrogram/client/types/messages_and_media/voice.py b/pyrogram/client/types/messages_and_media/voice.py index 3e08d57a..e4256197 100644 --- a/pyrogram/client/types/messages_and_media/voice.py +++ b/pyrogram/client/types/messages_and_media/voice.py @@ -20,11 +20,11 @@ from struct import pack import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class Voice(PyrogramType): +class Voice(Object): """A voice note. Parameters: diff --git a/pyrogram/client/types/pyrogram_type.py b/pyrogram/client/types/object.py similarity index 63% rename from pyrogram/client/types/pyrogram_type.py rename to pyrogram/client/types/object.py index 9a04c636..4d482e63 100644 --- a/pyrogram/client/types/pyrogram_type.py +++ b/pyrogram/client/types/object.py @@ -23,7 +23,12 @@ from json import dumps import pyrogram -class PyrogramType: +class Meta(type, metaclass=type("", (type,), {"__str__": lambda _: "~hi"})): + def __str__(self): + return "".format(self.__name__) + + +class Object(metaclass=Meta): __slots__ = ["_client"] def __init__(self, client: "pyrogram.BaseClient" = None): @@ -32,35 +37,26 @@ class PyrogramType: if self._client is None: del self._client - def __eq__(self, other: "PyrogramType") -> bool: - for attr in self.__slots__: - try: - if getattr(self, attr) != getattr(other, attr): - return False - except AttributeError: - return False + @staticmethod + def default(obj: "Object"): + if isinstance(obj, bytes): + return repr(obj) - return True + return OrderedDict( + [("_", "pyrogram." + obj.__class__.__name__)] + + [ + (attr, "*" * len(getattr(obj, attr))) + if attr == "phone_number" + else (attr, str(datetime.fromtimestamp(getattr(obj, attr)))) + if attr.endswith("date") + else (attr, getattr(obj, attr)) + for attr in obj.__slots__ + if getattr(obj, attr) is not None + ] + ) def __str__(self) -> str: - def default(obj: PyrogramType): - try: - return OrderedDict( - [("_", "pyrogram." + obj.__class__.__name__)] - + [ - (attr, "*" * len(getattr(obj, attr))) - if attr == "phone_number" - else (attr, str(datetime.fromtimestamp(getattr(obj, attr)))) - if attr.endswith("date") - else (attr, getattr(obj, attr)) - for attr in obj.__slots__ - if getattr(obj, attr) is not None - ] - ) - except AttributeError: - return repr(obj) - - return dumps(self, indent=4, default=default, ensure_ascii=False) + return dumps(self, indent=4, default=Object.default, ensure_ascii=False) def __repr__(self) -> str: return "pyrogram.{}({})".format( @@ -72,5 +68,18 @@ class PyrogramType: ) ) + def __eq__(self, other: "Object") -> bool: + for attr in self.__slots__: + try: + if getattr(self, attr) != getattr(other, attr): + return False + except AttributeError: + return False + + return True + def __getitem__(self, item): return getattr(self, item) + + def __setitem__(self, key, value): + setattr(self, key, value) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index e260d8cd..ca9acd65 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -22,10 +22,10 @@ import pyrogram from pyrogram.api import types from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto -from ..pyrogram_type import PyrogramType +from ..object import Object -class Chat(PyrogramType): +class Chat(Object): """A chat. Parameters: diff --git a/pyrogram/client/types/user_and_chats/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py index 536f9526..7451012c 100644 --- a/pyrogram/client/types/user_and_chats/chat_member.py +++ b/pyrogram/client/types/user_and_chats/chat_member.py @@ -19,10 +19,10 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object -class ChatMember(PyrogramType): +class ChatMember(Object): """Contains information about one member of a chat. Parameters: diff --git a/pyrogram/client/types/user_and_chats/chat_members.py b/pyrogram/client/types/user_and_chats/chat_members.py index f57b8b46..6abdd719 100644 --- a/pyrogram/client/types/user_and_chats/chat_members.py +++ b/pyrogram/client/types/user_and_chats/chat_members.py @@ -21,10 +21,10 @@ from typing import List import pyrogram from pyrogram.api import types from .chat_member import ChatMember -from ..pyrogram_type import PyrogramType +from ..object import Object -class ChatMembers(PyrogramType): +class ChatMembers(Object): """Contains information about the members list of a chat. Parameters: diff --git a/pyrogram/client/types/user_and_chats/chat_permissions.py b/pyrogram/client/types/user_and_chats/chat_permissions.py index 6fa1a2a8..84099955 100644 --- a/pyrogram/client/types/user_and_chats/chat_permissions.py +++ b/pyrogram/client/types/user_and_chats/chat_permissions.py @@ -19,10 +19,10 @@ from typing import Union from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object -class ChatPermissions(PyrogramType): +class ChatPermissions(Object): """A chat default permissions and a single member permissions within a chat. Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or diff --git a/pyrogram/client/types/user_and_chats/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py index 1885eff2..1584a286 100644 --- a/pyrogram/client/types/user_and_chats/chat_photo.py +++ b/pyrogram/client/types/user_and_chats/chat_photo.py @@ -20,11 +20,11 @@ from struct import pack import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ...ext.utils import encode -class ChatPhoto(PyrogramType): +class ChatPhoto(Object): """A chat photo. Parameters: diff --git a/pyrogram/client/types/user_and_chats/chat_preview.py b/pyrogram/client/types/user_and_chats/chat_preview.py index 38dda6b6..312bdfe6 100644 --- a/pyrogram/client/types/user_and_chats/chat_preview.py +++ b/pyrogram/client/types/user_and_chats/chat_preview.py @@ -21,11 +21,11 @@ from typing import List import pyrogram from pyrogram.api import types from .chat_photo import ChatPhoto -from ..pyrogram_type import PyrogramType +from ..object import Object from ..user_and_chats.user import User -class ChatPreview(PyrogramType): +class ChatPreview(Object): """A chat preview. Parameters: diff --git a/pyrogram/client/types/user_and_chats/dialog.py b/pyrogram/client/types/user_and_chats/dialog.py index 4b900012..4ea82184 100644 --- a/pyrogram/client/types/user_and_chats/dialog.py +++ b/pyrogram/client/types/user_and_chats/dialog.py @@ -19,11 +19,11 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ..user_and_chats import Chat -class Dialog(PyrogramType): +class Dialog(Object): """A user's dialog. Parameters: diff --git a/pyrogram/client/types/user_and_chats/dialogs.py b/pyrogram/client/types/user_and_chats/dialogs.py index 862fcf22..56cdfc72 100644 --- a/pyrogram/client/types/user_and_chats/dialogs.py +++ b/pyrogram/client/types/user_and_chats/dialogs.py @@ -22,10 +22,10 @@ import pyrogram from pyrogram.api import types from .dialog import Dialog from ..messages_and_media import Message -from ..pyrogram_type import PyrogramType +from ..object import Object -class Dialogs(PyrogramType): +class Dialogs(Object): """Contains a user's dialogs chunk. Parameters: diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index ae631df1..50dd8361 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -20,10 +20,10 @@ import pyrogram from pyrogram.api import types from .chat_photo import ChatPhoto from .user_status import UserStatus -from ..pyrogram_type import PyrogramType +from ..object import Object -class User(PyrogramType): +class User(Object): """A Telegram user or bot. Parameters: diff --git a/pyrogram/client/types/user_and_chats/user_status.py b/pyrogram/client/types/user_and_chats/user_status.py index e6f5b134..4d12afc1 100644 --- a/pyrogram/client/types/user_and_chats/user_status.py +++ b/pyrogram/client/types/user_and_chats/user_status.py @@ -19,11 +19,11 @@ import pyrogram from pyrogram.api import types -from ..pyrogram_type import PyrogramType +from ..object import Object from ..update import Update -class UserStatus(PyrogramType, Update): +class UserStatus(Object, Update): """A User status (Last Seen privacy). .. note:: From 1be8ca94cc2a3535b285f0c7d773e7f39a6a62a6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 4 Jun 2019 16:10:32 +0200 Subject: [PATCH 3/8] Update docs with new content --- docs/source/faq.rst | 24 +++- docs/source/glossary.rst | 4 + docs/source/index.rst | 4 +- docs/source/start/invoking.rst | 38 ++--- docs/source/start/updates.rst | 39 ++--- docs/source/topics/create-filters.rst | 92 ++++++++++++ docs/source/topics/debugging.rst | 135 ++++++++++++++++++ .../topics/{filters.rst => use-filters.rst} | 90 ------------ 8 files changed, 295 insertions(+), 131 deletions(-) create mode 100644 docs/source/topics/create-filters.rst create mode 100644 docs/source/topics/debugging.rst rename docs/source/topics/{filters.rst => use-filters.rst} (50%) diff --git a/docs/source/faq.rst b/docs/source/faq.rst index a0fe3331..6c3cc1ab 100644 --- a/docs/source/faq.rst +++ b/docs/source/faq.rst @@ -155,6 +155,14 @@ things: chats). - The chat id argument you passed is in form of a string; you have to convert it into an integer with ``int(chat_id)``. +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 one. + My verification code expires immediately! ----------------------------------------- @@ -179,8 +187,20 @@ Having said that, here's a list of what Telegram definitely doesn't like: - 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. -However, you might be right, and your account was deactivated/limited without any reason. This could happen because of -mistakes by either the automatic systems or a moderator. In such cases you can kindly email Telegram at +And here's a good explanation of how, probably, the system works: + +.. raw:: html + + + +.. centered:: Join the discussion at `@PyrogramChat `_ + +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? diff --git a/docs/source/glossary.rst b/docs/source/glossary.rst index 72d308b7..bcb1193c 100644 --- a/docs/source/glossary.rst +++ b/docs/source/glossary.rst @@ -9,7 +9,11 @@ general. Some words may as well link to dedicated articles in case the topic is If you think something interesting could be added here, feel free to propose it by opening a `Feature Request`_. +Terms +----- + .. glossary:: + :sorted: API Application Programming Interface: a set of methods, protocols and tools that make it easier to develop programs diff --git a/docs/source/index.rst b/docs/source/index.rst index b99fcf3d..12ac705b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -122,7 +122,8 @@ Meta :hidden: :caption: Topic Guides - topics/filters + topics/use-filters + topics/create-filters topics/more-on-updates topics/config-file topics/smart-plugins @@ -134,6 +135,7 @@ Meta topics/proxy topics/bots-interaction topics/mtproto-vs-botapi + topics/debugging topics/test-servers topics/advanced-usage topics/voice-calls diff --git a/docs/source/start/invoking.rst b/docs/source/start/invoking.rst index 1357cd7b..5cb6817b 100644 --- a/docs/source/start/invoking.rst +++ b/docs/source/start/invoking.rst @@ -24,40 +24,40 @@ Making API method calls with Pyrogram is very simple. Here's an example we are g app.stop() -Let's begin by importing the Client class from the Pyrogram package: +#. Let's begin by importing the Client class from the Pyrogram package: -.. code-block:: python + .. code-block:: python - from pyrogram import Client + 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 + .. code-block:: python - app = Client("my_account") + app = Client("my_account") -To actually make use of any method, the client has to be started first: +#. To actually make use of any method, the client has to be started first: -.. code-block:: python + .. code-block:: python - app.start() + app.start() -Now, you can call any method you like: +#. Now, you can call any method you like: -.. code-block:: python + .. code-block:: python - print(app.get_me()) # Print information about yourself + print(app.get_me()) # Print information about yourself - # Send messages to yourself: - app.send_message("me", "Hi!") # Text message - app.send_location("me", 51.500729, -0.124583) # Location - app.send_sticker("me", "CAADBAADyg4AAvLQYAEYD4F7vcZ43AI") # Sticker + # Send messages to yourself: + app.send_message("me", "Hi!") # Text message + app.send_location("me", 51.500729, -0.124583) # Location + app.send_sticker("me", "CAADBAADyg4AAvLQYAEYD4F7vcZ43AI") # Sticker -Finally, when done, simply stop the client: +#. Finally, when done, simply stop the client: -.. code-block:: python + .. code-block:: python - app.stop() + app.stop() Context Manager --------------- diff --git a/docs/source/start/updates.rst b/docs/source/start/updates.rst index b6838ad3..9ac428b3 100644 --- a/docs/source/start/updates.rst +++ b/docs/source/start/updates.rst @@ -45,36 +45,37 @@ arrives: app.run() -Let's examine these four new pieces. First one: a callback function we defined which accepts two arguments - -*(client, message)*. This will be the function that gets executed every time a new message arrives and Pyrogram will -call that function by passing the client instance and the new message instance as argument. +#. Let's examine these four new pieces. First one: a callback function we defined which accepts two arguments - + *(client, message)*. This will be the function that gets executed every time a new message arrives and Pyrogram will + call that function by passing the client instance and the new message instance as argument. -.. code-block:: python + .. code-block:: python - def my_function(client, message): - print(message) + def my_function(client, message): + print(message) -Second one: the :class:`~pyrogram.MessageHandler`. This object tells Pyrogram the function we defined above must only -handle updates that are in form of a :class:`~pyrogram.Message`: +#. Second one: the :class:`~pyrogram.MessageHandler`. This object tells Pyrogram the function we defined above must + only handle updates that are in form of a :class:`~pyrogram.Message`: -.. code-block:: python + .. code-block:: python - my_handler = MessageHandler(my_function) + my_handler = MessageHandler(my_function) -Third: the method :meth:`~pyrogram.Client.add_handler`. This method is used to actually register the handler and let -Pyrogram know it needs to be taken into consideration when new updates arrive and the internal dispatching phase begins. +#. Third: the method :meth:`~pyrogram.Client.add_handler`. This method is used to actually register the handler and let + Pyrogram know it needs to be taken into consideration when new updates arrive and the internal dispatching phase + begins. -.. code-block:: python + .. code-block:: python - app.add_handler(my_handler) + app.add_handler(my_handler) -Last one, the :meth:`~pyrogram.Client.run` method. What this does is simply call :meth:`~pyrogram.Client.start` and a -special method :meth:`~pyrogram.Client.idle` that keeps your main scripts alive until you press ``CTRL+C``; the client -will be automatically stopped after that. +#. Last one, the :meth:`~pyrogram.Client.run` method. What this does is simply call :meth:`~pyrogram.Client.start` and + a special method :meth:`~pyrogram.Client.idle` that keeps your main scripts alive until you press ``CTRL+C``; the + client will be automatically stopped after that. -.. code-block:: python + .. code-block:: python - app.run() + app.run() Using Decorators ---------------- diff --git a/docs/source/topics/create-filters.rst b/docs/source/topics/create-filters.rst new file mode 100644 index 00000000..0252221c --- /dev/null +++ b/docs/source/topics/create-filters.rst @@ -0,0 +1,92 @@ +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 (to be used in a different kind of handler, +for example) you can use :meth:`~pyrogram.Filters.create`. + +.. note:: + + At the moment, the built-in filters are intended to be used with the :class:`~pyrogram.MessageHandler` only. + +Custom Filters +-------------- + +An example to demonstrate how custom filters work is to show how to create and use one for the +:class:`~pyrogram.CallbackQueryHandler`. Note that callback queries updates are only received by bots; 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 import InlineKeyboardMarkup, InlineKeyboardButton + + app.send_message( + "username", # Change this to your username or id + "Pyrogram's custom filter test", + reply_markup=InlineKeyboardMarkup( + [[InlineKeyboardButton("Press me", b"pyrogram")]] + ) + ) + +Basic Filters +------------- + +For this basic filter we will be using only the first two parameters of :meth:`~pyrogram.Filters.create`. + +The code below creates a simple filter for hardcoded, static callback data. This filter will only allow callback queries +containing "Pyrogram" as data, that is, the function *func* you pass returns True in case the callback query data +equals to ``b"Pyrogram"``. + +.. code-block:: python + + static_data = Filters.create( + name="StaticdData", + func=lambda flt, callback_query: callback_query.data == b"Pyrogram" + ) + +The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same +could be achieved with a normal function, but we don't really need it as it makes sense only inside the filter's scope: + +.. code-block:: python + + def func(flt, callback_query): + return callback_query.data == b"Pyrogram" + + static_data = Filters.create( + name="StaticData", + func=func + ) + +The filter usage remains the same: + +.. code-block:: python + + @app.on_callback_query(static_data) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") + +Filters with Arguments +---------------------- + +A much cooler filter would be one that accepts "Pyrogram" or any other data as argument at usage time. +A dynamic filter like this will make use of the third parameter of :meth:`~pyrogram.Filters.create`. + +This is how a dynamic custom filter looks like: + +.. code-block:: python + + def dynamic_data(data): + return Filters.create( + name="DynamicData", + func=lambda flt, callback_query: flt.data == callback_query.data, + data=data # "data" kwarg is accessed with "filter.data" + ) + +And its usage: + +.. code-block:: python + + @app.on_callback_query(dynamic_data(b"Pyrogram")) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") \ No newline at end of file diff --git a/docs/source/topics/debugging.rst b/docs/source/topics/debugging.rst new file mode 100644 index 00000000..153c0927 --- /dev/null +++ b/docs/source/topics/debugging.rst @@ -0,0 +1,135 @@ +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. + +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 + + dan = app.get_users("haskell") + print(dan) # User + +This will show a JSON representation of the object returned by :meth:`~pyrogram.Client.get_users`, which is a +:class:`~pyrogram.User` instance, in this case. The output on your terminal will be something similar to this: + +.. code-block:: json + + { + "_": "pyrogram.User", + "id": 23122162, + "is_self": false, + "is_contact": false, + "is_mutual_contact": false, + "is_deleted": false, + "is_bot": false, + "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", + "photo": { + "_": "pyrogram.ChatPhoto", + "small_file_id": "AQADBAAD8tBgAQAEJjCxGgAEo5IBAAIC", + "big_file_id": "AQADBAAD8tBgAQAEJjCxGgAEpZIBAAEBAg" + } + } + +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 +full-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 + +.. code-block:: json + + { + "_": "pyrogram.ChatPhoto", + "small_file_id": "AQADBAAD8tBgAQAEJjCxGgAEo5IBAAIC", + "big_file_id": "AQADBAAD8tBgAQAEJjCxGgAEpZIBAAEBAg" + } + +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 +------------------------- + +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 + + dan_status = dan.status + print(type(dan_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 import UserStatus + + dan_status = dan.status + print(isinstance(dan_status, UserStatus)) + +.. code-block:: text + + True + +.. raw:: html + + \ No newline at end of file diff --git a/docs/source/topics/filters.rst b/docs/source/topics/use-filters.rst similarity index 50% rename from docs/source/topics/filters.rst rename to docs/source/topics/use-filters.rst index 7ff02ffc..c23a98df 100644 --- a/docs/source/topics/filters.rst +++ b/docs/source/topics/use-filters.rst @@ -105,93 +105,3 @@ More handlers using different filters can also live together. @app.on_message(Filters.chat("PyrogramChat")) def from_pyrogramchat(client, message): print("New message in @PyrogramChat") - -Custom 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 (to be used in a different kind of handler, -for example) you can use :meth:`~pyrogram.Filters.create`. - -.. note:: - - At the moment, the built-in filters are intended to be used with the :class:`~pyrogram.MessageHandler` only. - -An example to demonstrate how custom filters work is to show how to create and use one for the -:class:`~pyrogram.CallbackQueryHandler`. Note that callback queries updates are only received by bots; 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 import InlineKeyboardMarkup, InlineKeyboardButton - - app.send_message( - "username", # Change this to your username or id - "Pyrogram's custom filter test", - reply_markup=InlineKeyboardMarkup( - [[InlineKeyboardButton("Press me", b"pyrogram")]] - ) - ) - -Basic Filters -^^^^^^^^^^^^^ - -For this basic filter we will be using only the first two parameters of :meth:`~pyrogram.Filters.create`. - -The code below creates a simple filter for hardcoded, static callback data. This filter will only allow callback queries -containing "Pyrogram" as data, that is, the function *func* you pass returns True in case the callback query data -equals to ``b"Pyrogram"``. - -.. code-block:: python - - static_data = Filters.create( - name="StaticdData", - func=lambda flt, callback_query: callback_query.data == b"Pyrogram" - ) - -The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same -could be achieved with a normal function, but we don't really need it as it makes sense only inside the filter's scope: - -.. code-block:: python - - def func(flt, callback_query): - return callback_query.data == b"Pyrogram" - - static_data = Filters.create( - name="StaticData", - func=func - ) - -The filter usage remains the same: - -.. code-block:: python - - @app.on_callback_query(static_data) - def pyrogram_data(client, callback_query): - client.answer_callback_query(callback_query.id, "it works!") - -Filters with Arguments -^^^^^^^^^^^^^^^^^^^^^^ - -A much cooler filter would be one that accepts "Pyrogram" or any other data as argument at usage time. -A dynamic filter like this will make use of the third parameter of :meth:`~pyrogram.Filters.create`. - -This is how a dynamic custom filter looks like: - -.. code-block:: python - - def dynamic_data(data): - return Filters.create( - name="DynamicData", - func=lambda flt, callback_query: flt.data == callback_query.data, - data=data # "data" kwarg is accessed with "filter.data" - ) - -And its usage: - -.. code-block:: python - - @app.on_callback_query(dynamic_data(b"Pyrogram")) - def pyrogram_data(client, callback_query): - client.answer_callback_query(callback_query.id, "it works!") \ No newline at end of file From 896c9fa4fdd76e3897704c2b33894d8ca667ba5a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 4 Jun 2019 16:32:42 +0200 Subject: [PATCH 4/8] Add "unsave" parameter to send_animation --- .../client/methods/messages/send_animation.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 8a4ec7bd..0c4649dd 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -31,6 +31,7 @@ class SendAnimation(BaseClient): chat_id: Union[int, str], animation: str, caption: str = "", + unsave: bool = False, parse_mode: str = "", duration: int = 0, width: int = 0, @@ -64,6 +65,10 @@ class SendAnimation(BaseClient): caption (``str``, *optional*): Animation caption, 0-1024 characters. + unsave (``bool``, *optional*): + By default, the server will save into your own collection any new animation GIF you send. + Pass True to automatically unsave the sent animation. Defaults to False. + parse_mode (``str``, *optional*): Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to "markdown". @@ -171,10 +176,24 @@ class SendAnimation(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message._parse( + message = pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} ) + + if unsave: + document = message.animation or message.document + document_id = utils.get_input_media_from_file_id(document.file_id).id + + self.send( + functions.messages.SaveGif( + id=document_id, + unsave=True + ) + ) + + return message + except BaseClient.StopTransmission: return None From 806e0d79ec6459d3b6f649f20cfe221f397d5a13 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 4 Jun 2019 19:11:40 +0200 Subject: [PATCH 5/8] Tiny fixup --- docs/source/topics/advanced-usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/topics/advanced-usage.rst b/docs/source/topics/advanced-usage.rst index 41eee961..ff1afa5c 100644 --- a/docs/source/topics/advanced-usage.rst +++ b/docs/source/topics/advanced-usage.rst @@ -122,7 +122,7 @@ For example, given the ID *123456789*, here's how Pyrogram can tell entities apa - ``+ID`` User: *123456789* - ``-ID`` Chat: *-123456789* - - ``-100ID`` Channel (and Supergroup): *-100123456789* + - ``-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. From a425e00a96a9f27f7ad9218cbeab5ed7a1a8c120 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 4 Jun 2019 19:16:30 +0200 Subject: [PATCH 6/8] Add read_history method --- docs/source/api/methods.rst | 2 + pyrogram/client/methods/messages/__init__.py | 4 +- .../client/methods/messages/read_history.py | 65 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/messages/read_history.py diff --git a/docs/source/api/methods.rst b/docs/source/api/methods.rst index b9fa180c..ed150e4c 100644 --- a/docs/source/api/methods.rst +++ b/docs/source/api/methods.rst @@ -67,6 +67,7 @@ Messages - :meth:`~Client.get_messages` - :meth:`~Client.get_history` - :meth:`~Client.get_history_count` + - :meth:`~Client.read_history` - :meth:`~Client.iter_history` - :meth:`~Client.send_poll` - :meth:`~Client.vote_poll` @@ -200,6 +201,7 @@ Details .. automethod:: Client.get_messages() .. automethod:: Client.get_history() .. automethod:: Client.get_history_count() +.. automethod:: Client.read_history() .. automethod:: Client.iter_history() .. automethod:: Client.send_poll() .. automethod:: Client.vote_poll() diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 9ed6e33b..07df7a64 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -27,6 +27,7 @@ from .get_history import GetHistory from .get_history_count import GetHistoryCount from .get_messages import GetMessages from .iter_history import IterHistory +from .read_history import ReadHistory from .retract_vote import RetractVote from .send_animated_sticker import SendAnimatedSticker from .send_animation import SendAnimation @@ -80,6 +81,7 @@ class Messages( IterHistory, SendCachedMedia, GetHistoryCount, - SendAnimatedSticker + SendAnimatedSticker, + ReadHistory ): pass diff --git a/pyrogram/client/methods/messages/read_history.py b/pyrogram/client/methods/messages/read_history.py new file mode 100644 index 00000000..f0278e91 --- /dev/null +++ b/pyrogram/client/methods/messages/read_history.py @@ -0,0 +1,65 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class ReadHistory(BaseClient): + def read_history( + self, + chat_id: Union[int, str], + max_id: int = 0 + ) -> bool: + """Mark a chat's message history as read. + + 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). + + max_id (``int``, *optional*): + The id of the last message you want to mark as read; all the messages before this one will be marked as + read as well. Defaults to 0 (mark every unread message as read). + + Returns: + ``bool`` - On success, True is returned. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + + peer = self.resolve_peer(chat_id) + + if isinstance(peer, types.InputPeerChannel): + q = functions.channels.ReadHistory( + channel=peer, + max_id=max_id + ) + else: + q = functions.messages.ReadHistory( + peer=peer, + max_id=max_id + ) + + self.send(q) + + return True From a35e2620f867678935d76b65e1961caf35fc0ecf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 4 Jun 2019 23:36:10 +0200 Subject: [PATCH 7/8] Fix export_chat_invite_link for basic groups in Layer 100 --- compiler/api/source/main_api.tl | 5 ++++- pyrogram/client/methods/chats/export_chat_invite_link.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 43b02e80..16a93420 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -1356,4 +1356,7 @@ langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLangua folders.editPeerFolders#6847d0ab folder_peers:Vector = Updates; folders.deleteFolder#1c295881 folder_id:int = Updates; -// LAYER 100 \ No newline at end of file +// LAYER 100 + +// Ports +channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite; \ No newline at end of file diff --git a/pyrogram/client/methods/chats/export_chat_invite_link.py b/pyrogram/client/methods/chats/export_chat_invite_link.py index 26263d53..9266183d 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -54,7 +54,7 @@ class ExportChatInviteLink(BaseClient): if isinstance(peer, types.InputPeerChat): return self.send( functions.messages.ExportChatInvite( - peer=peer.chat_id + peer=peer ) ).link elif isinstance(peer, types.InputPeerChannel): From 0ea512bbc3f672686da3cd562013def18df344ae Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Jun 2019 11:05:01 +0200 Subject: [PATCH 8/8] Update docs: add release notes from GitHub --- docs/releases.py | 80 ++++++++++++++++++++++++++ docs/source/conf.py | 2 +- docs/source/index.rst | 4 +- docs/source/releases.rst | 13 ----- docs/source/topics/more-on-updates.rst | 2 +- 5 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 docs/releases.py delete mode 100644 docs/source/releases.rst diff --git a/docs/releases.py b/docs/releases.py new file mode 100644 index 00000000..98563ccd --- /dev/null +++ b/docs/releases.py @@ -0,0 +1,80 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import 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. + +Releases +-------- + +""".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 - %H:%M:%S (UTC)") + + body = pypandoc.convert_text( + release["body"].replace(r"\r\n", "\n"), + "rst", + format="markdown_github", + extra_args=["--wrap=none"] + ) + + 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("--- *Released on " + str(date) + "*\n\n") + 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/source/conf.py b/docs/source/conf.py index 7ddeaa94..01fbe6de 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -58,7 +58,7 @@ html_show_copyright = False html_theme_options = { "canonical_url": "https://docs.pyrogram.org/", "collapse_navigation": True, - "sticky_navigation": False, + "sticky_navigation": True, "logo_only": True, "display_version": True, "style_external_links": True diff --git a/docs/source/index.rst b/docs/source/index.rst index 12ac705b..a2e08cd0 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -83,10 +83,10 @@ Meta - :doc:`Pyrogram FAQ `: Answers to common Pyrogram questions. - :doc:`Pyrogram Glossary `: List of words with brief explanations. - - :doc:`Release Notes `: Release notes for Pyrogram releases. - :doc:`Powered by Pyrogram `: Collection of Pyrogram Projects. - :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. .. toctree:: :hidden: @@ -146,10 +146,10 @@ Meta faq glossary - releases powered-by support-pyrogram license + releases/index .. toctree:: :hidden: diff --git a/docs/source/releases.rst b/docs/source/releases.rst deleted file mode 100644 index 6c3b5b75..00000000 --- a/docs/source/releases.rst +++ /dev/null @@ -1,13 +0,0 @@ -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. - -.. note:: - - Currently, all Pyrogram release notes live inside the GitHub repository web page: - https://github.com/pyrogram/pyrogram/releases. diff --git a/docs/source/topics/more-on-updates.rst b/docs/source/topics/more-on-updates.rst index c3737b38..df0aff7d 100644 --- a/docs/source/topics/more-on-updates.rst +++ b/docs/source/topics/more-on-updates.rst @@ -2,7 +2,7 @@ More on Updates =============== Here we'll show some advanced usages when working with :doc:`update handlers <../start/updates>` and -:doc:`filters `. +:doc:`filters `. Handler Groups --------------