mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-27 00:32:39 +00:00
Add update_personal_channel and get_personal_channels methods
This commit is contained in:
parent
52b473197e
commit
826881dd65
@ -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
|
||||
|
@ -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,
|
||||
|
48
pyrogram/methods/chats/get_personal_channels.py
Normal file
48
pyrogram/methods/chats/get_personal_channels.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
@ -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,
|
||||
|
65
pyrogram/methods/users/update_personal_channel.py
Normal file
65
pyrogram/methods/users/update_personal_channel.py
Normal file
@ -0,0 +1,65 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user