Add color attribute to Folder

This commit is contained in:
KurimuzonAkuma 2024-03-10 22:30:54 +03:00
parent 6b8d287b65
commit 33df30f63d
4 changed files with 105 additions and 3 deletions

View File

@ -22,6 +22,7 @@ from .chat_event_action import ChatEventAction
from .chat_member_status import ChatMemberStatus
from .chat_members_filter import ChatMembersFilter
from .chat_type import ChatType
from .folder_color import FolderColor
from .message_entity_type import MessageEntityType
from .message_media_type import MessageMediaType
from .message_service_type import MessageServiceType
@ -42,6 +43,7 @@ __all__ = [
'ChatMemberStatus',
'ChatMembersFilter',
'ChatType',
'FolderColor',
'MessageEntityType',
'MessageMediaType',
'MessageServiceType',

View File

@ -0,0 +1,47 @@
# 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 .auto_name import AutoName
class FolderColor(AutoName):
"""Folder color enumeration used in :obj:`~pyrogram.types.Folder`."""
NO_COLOR = None
"No color."
RED = 0
"Red color."
ORANGE = 1
"Orange color."
VIOLET = 2
"Violet color."
GREEN = 3
"Cyan color."
CYAN = 4
"Green color."
BLUE = 5
"Blue color."
PINK = 6
"Pink color."

View File

@ -20,6 +20,7 @@ from typing import List, Union
import pyrogram
from pyrogram import raw
from pyrogram import enums
class UpdateFolder:
@ -38,6 +39,7 @@ class UpdateFolder:
exclude_muted: bool = None,
exclude_read: bool = None,
exclude_archived: bool = None,
color: "enums.FolderColor" = None,
emoji: str = None
) -> bool:
"""Create or update a user's folder.
@ -91,6 +93,10 @@ class UpdateFolder:
Folder emoji.
Pass None to leave the folder icon as default.
color (:obj:`~pyrogram.enums.FolderColor`, *optional*):
Color type.
Pass :obj:`~pyrogram.enums.FolderColor` to set folder color.
Returns:
``bool``: True, on success.
@ -133,7 +139,8 @@ class UpdateFolder:
exclude_muted=exclude_muted,
exclude_read=exclude_read,
exclude_archived=exclude_archived,
emoticon=emoji
emoticon=emoji,
color=color.value if color else None
)
)
)

View File

@ -19,6 +19,7 @@
from typing import List, Union
import pyrogram
from pyrogram import enums
from pyrogram import raw
from pyrogram import types
from pyrogram import utils
@ -70,6 +71,9 @@ class Folder(Object):
emoji (``str``, *optional*):
Folder emoji.
color (:obj:`~pyrogram.enums.FolderColor`, *optional*)
Chat reply color.
"""
def __init__(
@ -90,6 +94,7 @@ class Folder(Object):
exclude_read: bool = None,
exclude_archived: bool = None,
emoji: str = None,
color: "enums.FolderColor" = None,
has_my_invites: bool = None
):
super().__init__(client)
@ -108,6 +113,7 @@ class Folder(Object):
self.exclude_read = exclude_read
self.exclude_archived = exclude_archived
self.emoji = emoji
self.color = color
self.has_my_invites = has_my_invites
@staticmethod
@ -150,6 +156,7 @@ class Folder(Object):
exclude_read=getattr(folder, "exclude_read", None),
exclude_archived=getattr(folder, "exclude_archived", None),
emoji=folder.emoticon or None,
color=enums.FolderColor(getattr(folder, "color", None)),
has_my_invites=getattr(folder, "has_my_invites", None),
client=client
)
@ -188,7 +195,8 @@ class Folder(Object):
exclude_muted: bool = None,
exclude_read: bool = None,
exclude_archived: bool = None,
emoji: str = None
emoji: str = None,
color: "enums.FolderColor" = None
):
"""Bound method *update_peers* of :obj:`~pyrogram.types.Folder`.
@ -251,6 +259,10 @@ class Folder(Object):
Folder emoji.
Pass None to leave the folder icon as default.
color (:obj:`~pyrogram.enums.FolderColor`, *optional*):
Color type.
Pass :obj:`~pyrogram.enums.FolderColor` to set folder color.
Returns:
True on success.
"""
@ -277,7 +289,8 @@ class Folder(Object):
exclude_muted=exclude_muted or self.exclude_muted,
exclude_read=exclude_read or self.exclude_read,
exclude_archived=exclude_archived or self.exclude_archived,
emoji=emoji or self.emoji
emoji=emoji or self.emoji,
color=color or self.color
)
async def include_chat(self, chat_id: Union[int, str]):
@ -348,6 +361,39 @@ class Folder(Object):
pinned_chats=[i.id for i in self.pinned_chats or []],
)
async def update_color(self, color: "enums.FolderColor"):
"""Bound method *update_color* of :obj:`~pyrogram.types.Folder`.
Use as a shortcut for:
.. code-block:: python
await client.update_folder(
folder_id=123456789,
included_chats=[chat_id],
excluded_chats=[chat_id],
pinned_chats=[...],
color=color
)
Example:
.. code-block:: python
await folder.update_color(enums.FolderColor.RED)
Parameters:
color (:obj:`~pyrogram.enums.FolderColor`, *optional*):
Color type.
Pass :obj:`~pyrogram.enums.FolderColor` to set folder color.
Returns:
True on success.
"""
return await self.update(
color=color
)
async def pin_chat(self, chat_id: Union[int, str]):
"""Bound method *pin_chat* of :obj:`~pyrogram.types.Folder`.