From 989ce836d3358980458c46c343bc6c9c85202d7e Mon Sep 17 00:00:00 2001 From: wulan17 Date: Mon, 7 Jul 2025 19:30:03 +0700 Subject: [PATCH] pyrofork: Add todolist Signed-off-by: wulan17 --- compiler/docs/compiler.py | 2 + pyrogram/enums/message_media_type.py | 3 + pyrogram/types/messages_and_media/__init__.py | 6 +- pyrogram/types/messages_and_media/message.py | 10 +++ .../types/messages_and_media/todo_list.py | 71 ++++++++++++++++ .../types/messages_and_media/todo_task.py | 82 +++++++++++++++++++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/messages_and_media/todo_list.py create mode 100644 pyrogram/types/messages_and_media/todo_task.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 24eeb19f..7eb8b792 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -535,6 +535,8 @@ def pyrogram_api(): MessageOrigin Photo Thumbnail + TodoList + TodoTask Audio AvailableEffect Document diff --git a/pyrogram/enums/message_media_type.py b/pyrogram/enums/message_media_type.py index c9e3fa44..067c2f96 100644 --- a/pyrogram/enums/message_media_type.py +++ b/pyrogram/enums/message_media_type.py @@ -84,3 +84,6 @@ class MessageMediaType(AutoName): PAID_MEDIA = auto() "Paid media" + + TODO = auto() + "To-Do list media" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 7cb8837f..3bc969d0 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -55,6 +55,8 @@ from .stickerset import StickerSet from .stories_privacy_rules import StoriesPrivacyRules from .stripped_thumbnail import StrippedThumbnail from .thumbnail import Thumbnail +from .todo_list import TodoList +from .todo_task import TodoTask from .venue import Venue from .video import Video from .video_note import VideoNote @@ -142,5 +144,7 @@ __all__ = [ "WallpaperSettings", "TranscribedAudio", "TranslatedText", - "TextQuote" + "TextQuote", + "TodoList", + "TodoTask" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index bb6007c2..2f5bf8e5 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -194,6 +194,9 @@ class Message(Object, Update): paid_media (:obj:`~pyrogram.types.PaidMedia`, *optional*): Message is a paid media, information about the paid media. + todo (:obj:`~pyrogram.types.Todo`, *optional*): + Message is a todo list, information about the todo list. + sticker (:obj:`~pyrogram.types.Sticker`, *optional*): Message is a sticker, information about the sticker. @@ -468,6 +471,7 @@ class Message(Object, Update): document: "types.Document" = None, photo: "types.Photo" = None, paid_media: "types.PaidMedia" = None, + todo: "types.Todo" = None, sticker: "types.Sticker" = None, animation: "types.Animation" = None, game: "types.Game" = None, @@ -584,6 +588,7 @@ class Message(Object, Update): self.document = document self.photo = photo self.paid_media = paid_media + self.todo = todo self.sticker = sticker self.animation = animation self.game = game @@ -1004,6 +1009,7 @@ class Message(Object, Update): photo = None paid_media = None + todo = None location = None contact = None venue = None @@ -1130,6 +1136,9 @@ class Message(Object, Update): elif isinstance(media, raw.types.MessageMediaPaidMedia): paid_media = types.PaidMedia._parse(client, media) media_type = enums.MessageMediaType.PAID_MEDIA + elif isinstance(media, raw.types.MessageMediaToDo): + todo = types.TodoList._parse(client, media, users) + media_type = enums.MessageMediaType.TODO else: media = None @@ -1199,6 +1208,7 @@ class Message(Object, Update): invert_media=message.invert_media, photo=photo, paid_media=paid_media, + todo=todo, location=location, contact=contact, venue=venue, diff --git a/pyrogram/types/messages_and_media/todo_list.py b/pyrogram/types/messages_and_media/todo_list.py new file mode 100644 index 00000000..717c8b21 --- /dev/null +++ b/pyrogram/types/messages_and_media/todo_list.py @@ -0,0 +1,71 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + + +from typing import List, Dict + +import pyrogram +from pyrogram import raw, types +from ..object import Object + + +class TodoList(Object): + """A list of tasks. + + Parameters: + name (``str``): + Title of the todo list. + + entities (List of :obj:`~pyrogram.types.MessageEntity`): + Entities in the name of the todo list. + + tasks (List of :obj:`~pyrogram.types.TodoTask`): + List of tasks in the todo list. + """ + + def __init__( + self, + name: str, + entities: List["types.MessageEntity"], + tasks: List["types.TodoTask"] = None + ): + super().__init__() + + self.name = name + self.entities = entities + self.tasks = tasks + + @staticmethod + def _parse( + client: "pyrogram.Client", + todo: "raw.types.TodoList", + users: Dict + ) -> "TodoList": + todo_list = todo.todo + completions = todo.completions + entities = [types.MessageEntity._parse(client, entity, None) for entity in todo_list.title.entities] + entities = types.List(filter(lambda x: x is not None, entities)) + tasks = [ + types.TodoTask._parse(client, task, users, completions) + for task in todo_list.list + ] if todo_list.list else [] + return TodoList( + name=todo_list.title.text, + entities=entities, + tasks=tasks + ) diff --git a/pyrogram/types/messages_and_media/todo_task.py b/pyrogram/types/messages_and_media/todo_task.py new file mode 100644 index 00000000..ec8f79ba --- /dev/null +++ b/pyrogram/types/messages_and_media/todo_task.py @@ -0,0 +1,82 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + + +from typing import List, Dict + +import pyrogram +from pyrogram import raw, types, utils +from ..object import Object + + +class TodoTask(Object): + """A task in a todo list. + + Parameters: + name (``str``): + Title of the task. + + entities (List of :obj:`~pyrogram.types.MessageEntity`): + Entities in the name of the task. + + is_completed (``bool``): + True, if the task is completed. + + completed_by (:obj:`~pyrogram.types.User`, *optional*): + User who completed the task. + + complete_date (:obj:`~datetime.datetime`, *optional*): + Date when the task was completed. + """ + + def __init__( + self, + name: str, + entities: List["types.MessageEntity"], + is_completed: bool, + completed_by: "types.User" = None, + complete_date: "pyrogram.types.datetime" = None + ): + super().__init__() + + self.name = name + self.entities = entities + self.is_completed = is_completed + self.completed_by = completed_by + self.complete_date = complete_date + + @staticmethod + def _parse( + client: "pyrogram.Client", + todo_task: "raw.types.TodoTask", + users: Dict, + completions: List["raw.types.TodoTaskCompletion"] = None + ) -> "TodoTask": + entities = [types.MessageEntity._parse(client, entity, None) for entity in todo_task.title.entities] + entities = types.List(filter(lambda x: x is not None, entities)) + complete = {i.id: i for i in completions} if completions else {} + todo_completion = complete.get(todo_task.id) + completed_by = types.User._parse(client, users.get(todo_completion.completed_by, None)) if todo_completion else None + complete_date = utils.timestamp_to_datetime(todo_completion.date) if todo_completion else None + return TodoTask( + name=todo_task.title.text, + entities=entities, + is_completed=True if todo_completion else False, + completed_by=completed_by, + complete_date=complete_date + )