From 80c7a6e98891d23d0215a8cefe4dc98571def4ed Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:28:05 +0200 Subject: [PATCH 1/5] Rename set_custom_title to set_administrator_title and clarify --- compiler/docs/compiler.py | 1 + pyrogram/client/methods/chats/__init__.py | 4 ++-- ...et_custom_title.py => set_administrator_title.py} | 12 +++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) rename pyrogram/client/methods/chats/{set_custom_title.py => set_administrator_title.py} (86%) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 93e71da6..6d940448 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -184,6 +184,7 @@ def pyrogram_api(): unban_chat_member restrict_chat_member promote_chat_member + set_administrator_title export_chat_invite_link set_chat_photo delete_chat_photo diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index b47385c4..67ade88a 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -40,11 +40,11 @@ from .leave_chat import LeaveChat from .pin_chat_message import PinChatMessage from .promote_chat_member import PromoteChatMember from .restrict_chat_member import RestrictChatMember +from .set_administrator_title import SetAdministratorTitle from .set_chat_description import SetChatDescription from .set_chat_permissions import SetChatPermissions from .set_chat_photo import SetChatPhoto from .set_chat_title import SetChatTitle -from .set_custom_title import SetCustomTitle from .unarchive_chats import UnarchiveChats from .unban_chat_member import UnbanChatMember from .unpin_chat_message import UnpinChatMessage @@ -84,6 +84,6 @@ class Chats( DeleteChannel, DeleteSupergroup, GetNearbyChats, - SetCustomTitle + SetAdministratorTitle ): pass diff --git a/pyrogram/client/methods/chats/set_custom_title.py b/pyrogram/client/methods/chats/set_administrator_title.py similarity index 86% rename from pyrogram/client/methods/chats/set_custom_title.py rename to pyrogram/client/methods/chats/set_administrator_title.py index f13e667a..9de1754f 100644 --- a/pyrogram/client/methods/chats/set_custom_title.py +++ b/pyrogram/client/methods/chats/set_administrator_title.py @@ -22,14 +22,17 @@ from pyrogram.api import functions, types from ...ext import BaseClient -class SetCustomTitle(BaseClient): - def set_custom_title( +class SetAdministratorTitle(BaseClient): + def set_administrator_title( self, chat_id: Union[int, str], user_id: Union[int, str], title: str, ) -> bool: - """Set a custom title to administrators or owners of a supergroup. + """Set a custom title (rank) to an administrator of a supergroup. + + If you are an administrator of a supergroup (i.e. not the owner), you can only set the title of other + administrators who have been promoted by you. If you are the owner, you can change every administrator's title. Parameters: chat_id (``int`` | ``str``): @@ -49,8 +52,7 @@ class SetCustomTitle(BaseClient): Example: .. code-block:: python - # Set custom titles to owners or administrators of supergroups - app.set_custom_title(chat_id, user_id, "Custom Title") + app.set_administrator_title(chat_id, user_id, "ฅ^•ﻌ•^ฅ") """ chat_id = self.resolve_peer(chat_id) user_id = self.resolve_peer(user_id) From aaf0e82cdf4292634de3ef4f9b9b6e05973907eb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:28:27 +0200 Subject: [PATCH 2/5] Optimize join_chat code --- pyrogram/client/methods/chats/join_chat.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pyrogram/client/methods/chats/join_chat.py b/pyrogram/client/methods/chats/join_chat.py index c1dd923a..45d35b48 100644 --- a/pyrogram/client/methods/chats/join_chat.py +++ b/pyrogram/client/methods/chats/join_chat.py @@ -58,20 +58,9 @@ class JoinChat(BaseClient): elif isinstance(chat.chats[0], types.Channel): return pyrogram.Chat._parse_channel_chat(self, chat.chats[0]) else: - resolved_peer = self.send( - functions.contacts.ResolveUsername( - username=chat_id.lower().strip("@") - ) - ) - - channel = types.InputPeerChannel( - channel_id=resolved_peer.chats[0].id, - access_hash=resolved_peer.chats[0].access_hash - ) - chat = self.send( functions.channels.JoinChannel( - channel=channel + channel=self.resolve_peer(chat_id) ) ) From 71148758c9326be6cfb946d8682d0797a9033111 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:42:38 +0200 Subject: [PATCH 3/5] Tiny documentation fixes --- pyrogram/client/methods/chats/create_channel.py | 2 +- pyrogram/client/methods/chats/create_group.py | 2 +- pyrogram/client/methods/chats/create_supergroup.py | 2 +- pyrogram/client/methods/chats/iter_dialogs.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/methods/chats/create_channel.py b/pyrogram/client/methods/chats/create_channel.py index 9520ceef..9dde8781 100644 --- a/pyrogram/client/methods/chats/create_channel.py +++ b/pyrogram/client/methods/chats/create_channel.py @@ -30,7 +30,7 @@ class CreateChannel(BaseClient): """Create a new broadcast channel. Parameters: - title (``title``): + title (``str``): The channel title. description (``str``, *optional*): diff --git a/pyrogram/client/methods/chats/create_group.py b/pyrogram/client/methods/chats/create_group.py index 4e1d63bd..a9013d81 100644 --- a/pyrogram/client/methods/chats/create_group.py +++ b/pyrogram/client/methods/chats/create_group.py @@ -36,7 +36,7 @@ class CreateGroup(BaseClient): If you want to create a new supergroup, use :meth:`~pyrogram.Client.create_supergroup` instead. Parameters: - title (``title``): + title (``str``): The group title. users (``int`` | ``str`` | List of ``int`` or ``str``): diff --git a/pyrogram/client/methods/chats/create_supergroup.py b/pyrogram/client/methods/chats/create_supergroup.py index 0ad14d06..28b3fd1b 100644 --- a/pyrogram/client/methods/chats/create_supergroup.py +++ b/pyrogram/client/methods/chats/create_supergroup.py @@ -34,7 +34,7 @@ class CreateSupergroup(BaseClient): If you want to create a new basic group, use :meth:`~pyrogram.Client.create_group` instead. Parameters: - title (``title``): + title (``str``): The supergroup title. description (``str``, *optional*): diff --git a/pyrogram/client/methods/chats/iter_dialogs.py b/pyrogram/client/methods/chats/iter_dialogs.py index 55de2a74..f0082096 100644 --- a/pyrogram/client/methods/chats/iter_dialogs.py +++ b/pyrogram/client/methods/chats/iter_dialogs.py @@ -39,7 +39,7 @@ class IterDialogs(BaseClient): The offset date in Unix time taken from the top message of a :obj:`Dialog`. Defaults to 0 (most recent dialog). - limit (``str``, *optional*): + limit (``int``, *optional*): Limits the number of dialogs to be retrieved. By default, no limit is applied and all dialogs are returned. From 011375d0b2fb8caeae7931f2451b9fd98a6ce794 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:44:45 +0200 Subject: [PATCH 4/5] Update docs link --- pyrogram/client/client.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 993af2f0..d6676662 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1429,10 +1429,7 @@ class Client(Methods, BaseClient): self.api_id = parser.getint("pyrogram", "api_id") self.api_hash = parser.get("pyrogram", "api_hash") else: - raise AttributeError( - "No API Key found. " - "More info: https://docs.pyrogram.org/intro/setup#configuration" - ) + raise AttributeError("No API Key found. More info: https://docs.pyrogram.org/intro/setup") for option in ["app_version", "device_model", "system_version", "lang_code"]: if getattr(self, option): From 2983a3b87aa938605a6307092d259905885af8a5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:45:19 +0200 Subject: [PATCH 5/5] Workaround for SQLite VACUUM on Python 3.6.0 --- pyrogram/client/storage/file_storage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/storage/file_storage.py b/pyrogram/client/storage/file_storage.py index e367b447..b9529504 100644 --- a/pyrogram/client/storage/file_storage.py +++ b/pyrogram/client/storage/file_storage.py @@ -108,7 +108,10 @@ class FileStorage(MemoryStorage): self.create() with self.conn: - self.conn.execute("VACUUM") + try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum + self.conn.execute("VACUUM") + except sqlite3.OperationalError: + pass def destroy(self): os.remove(self.database)