mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Refactor folders
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
4a109b3dc2
commit
413556a3f2
3 changed files with 28 additions and 7 deletions
|
|
@ -81,7 +81,7 @@ class GetFolders:
|
|||
users.update({i.id: i for i in r.users})
|
||||
chats.update({i.id: i for i in r.chats})
|
||||
|
||||
folders = types.List(types.Folder._parse(self, folder, users, chats) for folder in raw_folders)
|
||||
folders = types.List([types.Folder._parse(self, folder, users, chats) for folder in raw_folders])
|
||||
|
||||
if not folders:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@
|
|||
from typing import List, Union
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import enums
|
||||
from pyrogram import enums, raw, types, utils
|
||||
|
||||
|
||||
class UpdateFolder:
|
||||
|
|
@ -29,6 +28,7 @@ class UpdateFolder:
|
|||
self: "pyrogram.Client",
|
||||
folder_id: int,
|
||||
title: str,
|
||||
title_entities: List["types.MessageEntity"] = None,
|
||||
included_chats: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
excluded_chats: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
pinned_chats: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
|
|
@ -41,7 +41,8 @@ class UpdateFolder:
|
|||
exclude_read: bool = None,
|
||||
exclude_archived: bool = None,
|
||||
color: "enums.FolderColor" = None,
|
||||
emoji: str = None
|
||||
emoji: str = None,
|
||||
parse_mode: "pyrogram.enums.ParseMode" = pyrogram.enums.ParseMode.DEFAULT
|
||||
) -> bool:
|
||||
"""Create or update a user's folder.
|
||||
|
||||
|
|
@ -54,6 +55,9 @@ class UpdateFolder:
|
|||
title (``str``):
|
||||
Folder title.
|
||||
|
||||
title_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
|
||||
Entities for the folder title.
|
||||
|
||||
included_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*):
|
||||
Users or chats that should added in the folder
|
||||
You can pass an ID (int), username (str) or phone number (str).
|
||||
|
|
@ -98,6 +102,9 @@ class UpdateFolder:
|
|||
Color type.
|
||||
Pass :obj:`~pyrogram.enums.FolderColor` to set folder color.
|
||||
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
The parse mode to use for the title.
|
||||
|
||||
Returns:
|
||||
``bool``: True, on success.
|
||||
|
||||
|
|
@ -107,6 +114,8 @@ class UpdateFolder:
|
|||
# Create or update folder
|
||||
app.update_folder(folder_id, title="New folder", included_chats="me")
|
||||
"""
|
||||
title_text, title_entities = (await utils.parse_text_entities(self, title, parse_mode, title_entities)).values()
|
||||
|
||||
if not isinstance(included_chats, list):
|
||||
included_chats = [included_chats] if included_chats else []
|
||||
if not isinstance(excluded_chats, list):
|
||||
|
|
@ -119,7 +128,10 @@ class UpdateFolder:
|
|||
id=folder_id,
|
||||
filter=raw.types.DialogFilter(
|
||||
id=folder_id,
|
||||
title=title,
|
||||
title=raw.types.TextWithEntities(
|
||||
text=title_text,
|
||||
entities=title_entities or []
|
||||
),
|
||||
pinned_peers=[
|
||||
await self.resolve_peer(user_id)
|
||||
for user_id in pinned_chats
|
||||
|
|
@ -146,4 +158,4 @@ class UpdateFolder:
|
|||
)
|
||||
)
|
||||
|
||||
return r
|
||||
return bool(r)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ class Folder(Object):
|
|||
title (``str``):
|
||||
The folder title.
|
||||
|
||||
title_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
|
||||
A list of entities in the folder title.
|
||||
|
||||
included_chats (List of :obj:`~pyrogram.types.Chat`, *optional*):
|
||||
A list of included chats in folder.
|
||||
|
||||
|
|
@ -83,6 +86,7 @@ class Folder(Object):
|
|||
client: "pyrogram.Client" = None,
|
||||
id: int,
|
||||
title: str,
|
||||
title_entities: List["types.MessageEntity"] = None,
|
||||
included_chats: List["types.Chat"] = None,
|
||||
excluded_chats: List["types.Chat"] = None,
|
||||
pinned_chats: List["types.Chat"] = None,
|
||||
|
|
@ -102,6 +106,7 @@ class Folder(Object):
|
|||
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.title_entities = title_entities
|
||||
self.included_chats = included_chats
|
||||
self.excluded_chats = excluded_chats
|
||||
self.pinned_chats = pinned_chats
|
||||
|
|
@ -122,6 +127,9 @@ class Folder(Object):
|
|||
included_chats = []
|
||||
excluded_chats = []
|
||||
pinned_chats = []
|
||||
title = folder.title
|
||||
title_text = title.text
|
||||
title_entities = [types.MessageEntity._parse(client, entity) for entity in title.entities] if title.entities else None
|
||||
|
||||
for peer in folder.include_peers:
|
||||
try:
|
||||
|
|
@ -144,7 +152,8 @@ class Folder(Object):
|
|||
|
||||
return Folder(
|
||||
id=folder.id,
|
||||
title=folder.title,
|
||||
title=title_text,
|
||||
title_entities=title_entities,
|
||||
included_chats=types.List(included_chats) or None,
|
||||
excluded_chats=types.List(excluded_chats) or None,
|
||||
pinned_chats=types.List(pinned_chats) or None,
|
||||
|
|
|
|||
Loading…
Reference in a new issue