From 826881dd6598e1e277adecc9596b7c7681015afe Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 20 Apr 2024 14:08:03 +0300 Subject: [PATCH] Add update_personal_channel and get_personal_channels methods --- compiler/docs/compiler.py | 2 + pyrogram/methods/chats/__init__.py | 2 + .../methods/chats/get_personal_channels.py | 48 ++++++++++++++ pyrogram/methods/users/__init__.py | 2 + .../methods/users/update_personal_channel.py | 65 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 pyrogram/methods/chats/get_personal_channels.py create mode 100644 pyrogram/methods/users/update_personal_channel.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index ec80f762..024fedc6 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -261,6 +261,7 @@ def pyrogram_api(): toggle_join_to_send toggle_folder_tags set_chat_ttl + get_personal_channels """, users=""" Users @@ -280,6 +281,7 @@ def pyrogram_api(): update_status check_username update_birthday + update_personal_channel """, invite_links=""" Invite Links diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 3fc711f5..c9f11845 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -45,6 +45,7 @@ from .get_folders import GetFolders from .get_forum_topics import GetForumTopics from .get_forum_topics_by_id import GetForumTopicsByID from .get_nearby_chats import GetNearbyChats +from .get_personal_channels import GetPersonalChannels from .get_send_as_chats import GetSendAsChats from .join_chat import JoinChat from .join_folder import JoinFolder @@ -121,6 +122,7 @@ class Chats( EditForumTopic, ExportFolderLink, GetNearbyChats, + GetPersonalChannels, SetAdministratorTitle, SetSlowMode, ToggleFolderTags, diff --git a/pyrogram/methods/chats/get_personal_channels.py b/pyrogram/methods/chats/get_personal_channels.py new file mode 100644 index 00000000..1a5038cc --- /dev/null +++ b/pyrogram/methods/chats/get_personal_channels.py @@ -0,0 +1,48 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import List, Optional + +import pyrogram +from pyrogram import raw, types + + +class GetPersonalChannels: + async def get_personal_channels( + self: "pyrogram.Client" + ) -> Optional[List["types.Chat"]]: + """Get all your public channels. + + .. include:: /_includes/usable-by/users.rst + + Returns: + List of :obj:`~pyrogram.types.Chat`: On success, a list of personal channels is returned. + + Example: + .. code-block:: python + + # Get all your personal channels + await app.get_personal_channels() + """ + r = await self.invoke( + raw.functions.channels.GetAdminedPublicChannels( + for_personal=True + ) + ) + + return types.List(types.Chat._parse_chat(self, i) for i in r.chats) or None diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py index 0f81ce9d..cf34b434 100644 --- a/pyrogram/methods/users/__init__.py +++ b/pyrogram/methods/users/__init__.py @@ -30,6 +30,7 @@ from .set_profile_photo import SetProfilePhoto from .set_username import SetUsername from .unblock_user import UnblockUser from .update_birthday import UpdateBirthday +from .update_personal_channel import UpdatePersonalChannel from .update_profile import UpdateProfile from .update_status import UpdateStatus @@ -47,6 +48,7 @@ class Users( GetChatPhotosCount, UnblockUser, UpdateBirthday, + UpdatePersonalChannel, UpdateProfile, UpdateStatus, GetDefaultEmojiStatuses, diff --git a/pyrogram/methods/users/update_personal_channel.py b/pyrogram/methods/users/update_personal_channel.py new file mode 100644 index 00000000..2b26c383 --- /dev/null +++ b/pyrogram/methods/users/update_personal_channel.py @@ -0,0 +1,65 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +import pyrogram +from pyrogram import raw + + +class UpdatePersonalChannel: + async def update_personal_channel( + self: "pyrogram.Client", + chat_id: Union[int, str] = None + ) -> bool: + """Update your personal channel. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target user. + Use :meth:`~pyrogram.Client.get_personal_channels` to get available channels. + + Returns: + ``bool``: True on success. + + Example: + .. code-block:: python + + # Update your personal channel + await app.update_personal_channel(chat_id) + + # Remove personal channel from your profile + await app.update_personal_channel() + """ + if chat_id is None: + peer = raw.types.InputChannelEmpty() + else: + peer = await self.resolve_peer(chat_id) + + if not isinstance(peer, raw.types.InputChannel): + return False + + return bool( + await self.invoke( + raw.functions.account.UpdatePersonalChannel( + channel=peer + ) + ) + )