From 580c684cb3a60d73a3c0a1aa90012a47f9dcc466 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 16:13:10 +0200 Subject: [PATCH 01/13] Fix export_chat_invite_link not working correctly (channels/supergroups) --- .../client/methods/chats/export_chat_invite_link.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/methods/chats/export_chat_invite_link.py b/pyrogram/client/methods/chats/export_chat_invite_link.py index 9266183d..6e39dd84 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -48,18 +48,15 @@ class ExportChatInviteLink(BaseClient): Raises: RPCError: In case of a Telegram RPC error. + ValueError: In case the chat_id belongs to a user. """ peer = self.resolve_peer(chat_id) - if isinstance(peer, types.InputPeerChat): + if isinstance(peer, (types.InputPeerChannel, types.InputPeerChat)): return self.send( functions.messages.ExportChatInvite( peer=peer ) ).link - elif isinstance(peer, types.InputPeerChannel): - return self.send( - functions.channels.ExportInvite( - channel=peer - ) - ).link + else: + raise ValueError('The chat_id "{}" belongs to a user'.format(chat_id)) From c76a62964f166801286d435f5b8db8b67e317d95 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 18:51:04 +0200 Subject: [PATCH 02/13] Update: consistent examples --- docs/source/topics/text-formatting.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index 03b50a8e..fc8b952c 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -78,7 +78,7 @@ To strictly use this mode, pass "markdown" to the *parse_mode* parameter when us "**bold**, " "__italic__, " "--underline--, " - "~~strikethrough~~, " + "~~strike~~, " "[mention](tg://user?id=23122162), " "[URL](https://pyrogram.org), " "`code`, " @@ -128,7 +128,7 @@ The following tags are currently supported: "bold, " "italic, " "underline, " - "strikethrough, " + "strike, " "mention, " "URL, " "code\n\n" @@ -210,13 +210,13 @@ Here there are some example texts you can try sending: **Markdown**: - ``**bold, --underline--**`` -- ``**bold __italic --underline ~~striked~~--__**`` +- ``**bold __italic --underline ~~strike~~--__**`` - ``**bold __and** italic__`` **HTML**: - ``bold, underline`` -- ``bold italic underline striked`` +- ``bold italic underline strike`` - ``bold and italic`` **Combined**: From a05ac9d8a3993595c3a28719f02dd7c1b1951178 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 19:22:19 +0200 Subject: [PATCH 03/13] Update errors prune path --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 79c547f6..9f4d328c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,7 +4,7 @@ recursive-include compiler *.py *.tl *.tsv *.txt recursive-include pyrogram mime.types schema.sql ## Exclude -prune pyrogram/api/errors/exceptions +prune pyrogram/errors/exceptions prune pyrogram/api/functions prune pyrogram/api/types exclude pyrogram/api/all.py \ No newline at end of file From 83c386cbecfc57884560623063deb8483d99371c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 20:53:05 +0200 Subject: [PATCH 04/13] Use consistent naming --- pyrogram/client/storage/memory_storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/storage/memory_storage.py b/pyrogram/client/storage/memory_storage.py index bf000f35..1c32b3f3 100644 --- a/pyrogram/client/storage/memory_storage.py +++ b/pyrogram/client/storage/memory_storage.py @@ -59,8 +59,8 @@ class MemoryStorage(Storage): (1, None, None, 0, None, None) ) - def _import_session_string(self, string_session: str): - decoded = base64.urlsafe_b64decode(string_session + "=" * (-len(string_session) % 4)) + def _import_session_string(self, session_string: str): + decoded = base64.urlsafe_b64decode(session_string + "=" * (-len(session_string) % 4)) return struct.unpack(self.SESSION_STRING_FMT, decoded) def export_session_string(self): From 40b0c57b54d634eb0a83f172100e184d5ab20e14 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 20:53:35 +0200 Subject: [PATCH 05/13] Don't rename the in-memory sessions --- pyrogram/client/storage/memory_storage.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyrogram/client/storage/memory_storage.py b/pyrogram/client/storage/memory_storage.py index 1c32b3f3..ff4cb540 100644 --- a/pyrogram/client/storage/memory_storage.py +++ b/pyrogram/client/storage/memory_storage.py @@ -86,8 +86,6 @@ class MemoryStorage(Storage): self.dc_id, self.test_mode, self.auth_key, self.user_id, self.is_bot = imported_session_string self.date = 0 - self.name = ":memory:" + str(self.user_id or "") - # noinspection PyAttributeOutsideInit def save(self): self.date = int(time.time()) From a790431274f65a19392fa905a726c5b0a302c063 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 21:08:50 +0200 Subject: [PATCH 06/13] Do string conversion and striping in the Parser --- pyrogram/client/parser/html.py | 2 +- pyrogram/client/parser/parser.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/parser/html.py b/pyrogram/client/parser/html.py index 16c5922a..04f4ad30 100644 --- a/pyrogram/client/parser/html.py +++ b/pyrogram/client/parser/html.py @@ -108,7 +108,7 @@ class HTML: self.client = client def parse(self, text: str): - text = utils.add_surrogates(str(text or "").strip()) + text = utils.add_surrogates(text) parser = Parser(self.client) parser.feed(text) diff --git a/pyrogram/client/parser/parser.py b/pyrogram/client/parser/parser.py index f685c942..cde26f0b 100644 --- a/pyrogram/client/parser/parser.py +++ b/pyrogram/client/parser/parser.py @@ -31,6 +31,8 @@ class Parser: self.markdown = Markdown(client) def parse(self, text: str, mode: str = ""): + text = str(text or "").strip() + if mode is None: return OrderedDict([ ("message", text), From 6c80064f2c239309c50b9e44db0ee1d6fa08be51 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Jun 2019 21:10:28 +0200 Subject: [PATCH 07/13] Enable custom format for User mentions Examples: - format(user, "mention") - "{:mention}".format(user) - f"{user:mention}" --- pyrogram/client/types/user_and_chats/user.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index f47e8c42..248c4c0a 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import html + import pyrogram from pyrogram.api import types from .chat_photo import ChatPhoto @@ -134,6 +136,12 @@ class User(Object): self.photo = photo self.restriction_reason = restriction_reason + def __format__(self, format_spec): + if format_spec == "mention": + return '{1}'.format(self.id, html.escape(self.first_name)) + + return html.escape(str(self)) + @staticmethod def _parse(client, user: types.User) -> "User" or None: if user is None: From 46a03a20009f625fa5b2ebbb4f05caf6b3b6f114 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 13:17:16 +0200 Subject: [PATCH 08/13] Log the invalid values when raising errors --- pyrogram/client/storage/memory_storage.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/storage/memory_storage.py b/pyrogram/client/storage/memory_storage.py index ff4cb540..e69d247f 100644 --- a/pyrogram/client/storage/memory_storage.py +++ b/pyrogram/client/storage/memory_storage.py @@ -130,7 +130,7 @@ class MemoryStorage(Storage): access_hash=access_hash ) - raise ValueError("Invalid peer type") + raise ValueError("Invalid peer type: {}".format(peer_type)) def get_peer_by_id(self, peer_id: int): r = self.conn.execute( @@ -139,7 +139,7 @@ class MemoryStorage(Storage): ).fetchone() if r is None: - raise KeyError("ID not found") + raise KeyError("ID not found: {}".format(peer_id)) return self._get_input_peer(*r) @@ -150,10 +150,10 @@ class MemoryStorage(Storage): ).fetchone() if r is None: - raise KeyError("Username not found") + raise KeyError("Username not found: {}".format(username)) if abs(time.time() - r[3]) > self.USERNAME_TTL: - raise KeyError("Username expired") + raise KeyError("Username expired: {}".format(username)) return self._get_input_peer(*r[:3]) @@ -164,7 +164,7 @@ class MemoryStorage(Storage): ).fetchone() if r is None: - raise KeyError("Phone number not found") + raise KeyError("Phone number not found: {}".format(phone_number)) return self._get_input_peer(*r) From 414e42a3cca544c5e4628e319465743289b8881e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 13:32:14 +0200 Subject: [PATCH 09/13] Update README.md example Use .reply_text() instead of .reply() --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e758b5a..a4294175 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ app = Client("my_account") @app.on_message(Filters.private) def hello(client, message): - message.reply("Hello {}".format(message.from_user.first_name)) + message.reply_text("Hello {}".format(message.from_user.first_name)) app.run() From 992ef7bf527d59011593526dfec894c6ec21eaa5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 13:37:12 +0200 Subject: [PATCH 10/13] Fix sphinx warnings --- docs/source/api/bound-methods.rst | 2 +- docs/source/topics/text-formatting.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/api/bound-methods.rst b/docs/source/api/bound-methods.rst index 6a1cf1c3..679e1f8a 100644 --- a/docs/source/api/bound-methods.rst +++ b/docs/source/api/bound-methods.rst @@ -142,7 +142,7 @@ Details .. automethod:: Chat.archive() .. automethod:: Chat.unarchive() .. automethod:: Chat.set_title() -.. automethod:: Chat.set_description) +.. automethod:: Chat.set_description() .. automethod:: Chat.set_photo() .. automethod:: Chat.kick_member() .. automethod:: Chat.unban_member() diff --git a/docs/source/topics/text-formatting.rst b/docs/source/topics/text-formatting.rst index fc8b952c..0194dc58 100644 --- a/docs/source/topics/text-formatting.rst +++ b/docs/source/topics/text-formatting.rst @@ -202,7 +202,7 @@ Nested and Overlapping Entities ------------------------------- You can also style texts with more than one decoration at once by nesting entities together. For example, you can send -a text message with both :bold-underline:`bold and underline` styles, or a text that has both :italic-strike:`italic and +a text message with both :bold-underline:`bold and underline` styles, or a text that has both :strike-italic:`italic and strike` styles, and you can still combine both Markdown and HTML together. Here there are some example texts you can try sending: From 544cddfd1c0b03f1b19d07c074e5ac3d80d58990 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 13:44:16 +0200 Subject: [PATCH 11/13] Update Pyrogram to v0.15.0 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index ac184844..3e5940a8 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -24,7 +24,7 @@ if sys.version_info[:3] in [(3, 5, 0), (3, 5, 1), (3, 5, 2)]: # Monkey patch the standard "typing" module because Python versions from 3.5.0 to 3.5.2 have a broken one. sys.modules["typing"] = typing -__version__ = "0.15.0-develop" +__version__ = "0.15.0" __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" __copyright__ = "Copyright (C) 2017-2019 Dan " From 7a1d6002a9b63157f1cb541424cc3cb2f42ed0c8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 14:29:02 +0200 Subject: [PATCH 12/13] Update robots.txt --- docs/robots.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/robots.txt b/docs/robots.txt index 1b9e8da6..e7799fdd 100644 --- a/docs/robots.txt +++ b/docs/robots.txt @@ -2,7 +2,7 @@ User-agent: * Allow: / -Disallow: /dev/* -Disallow: /old/* +Disallow: /dev* +Disallow: /v0* Sitemap: https://docs.pyrogram.org/sitemap.xml \ No newline at end of file From 3f2f40af02346ef7d646bb4a3d2235bb54903185 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 1 Jul 2019 14:46:33 +0200 Subject: [PATCH 13/13] Update docs index example --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 682c883c..b37bf2dc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -106,7 +106,7 @@ Welcome to Pyrogram @app.on_message(Filters.private) def hello(client, message): - message.reply("Hello {}".format(message.from_user.first_name)) + message.reply_text("Hello {}".format(message.from_user.first_name)) app.run()