Compare commits

...

3 commits

Author SHA1 Message Date
wulan17
59869c7404
pyrofork: types: Chat: _parse_dialog: Handle InputPeerUser and InputPeerChat
Some checks failed
Build-docs / build (push) Has been cancelled
Pyrofork / build (macos-latest, 3.10) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.11) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.12) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.13) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.9) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.10) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.11) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.12) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.13) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.9) (push) Has been cancelled
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-07-10 19:40:36 +07:00
wulan17
9258173570
pyrofork: Refactor folders
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-07-10 19:40:35 +07:00
wulan17
0dedc9790c
pyrofork: Adapt filters.linked_channel to latest changes
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-07-10 19:06:17 +07:00
5 changed files with 31 additions and 10 deletions

View file

@ -796,7 +796,7 @@ from_scheduled = create(from_scheduled_filter)
# region linked_channel_filter
async def linked_channel_filter(_, __, m: Message):
return bool(m.forward_from_chat and not m.from_user)
return bool((m.forward_origin and m.forward_origin.chat) and not m.from_user)
linked_channel = create(linked_channel_filter)

View file

@ -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

View file

@ -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)

View file

@ -476,9 +476,9 @@ class Chat(Object):
users: Dict[int, "raw.types.User"],
chats: Dict[int, "raw.types.Chat"]
) -> "Chat":
if isinstance(peer, raw.types.PeerUser):
if isinstance(peer, raw.types.PeerUser) or isinstance(peer, raw.types.InputPeerUser):
return Chat._parse_user_chat(client, users[peer.user_id])
elif isinstance(peer, raw.types.PeerChat):
elif isinstance(peer, raw.types.PeerChat) or isinstance(peer, raw.types.InputPeerChat):
return Chat._parse_chat_chat(client, chats[peer.chat_id])
else:
return Chat._parse_channel_chat(client, chats[peer.channel_id])

View file

@ -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,