mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add todolist
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
6c7de705ce
commit
e54b991cea
6 changed files with 176 additions and 1 deletions
|
|
@ -535,6 +535,8 @@ def pyrogram_api():
|
||||||
MessageOrigin
|
MessageOrigin
|
||||||
Photo
|
Photo
|
||||||
Thumbnail
|
Thumbnail
|
||||||
|
TodoList
|
||||||
|
TodoTask
|
||||||
Audio
|
Audio
|
||||||
AvailableEffect
|
AvailableEffect
|
||||||
Document
|
Document
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,6 @@ class MessageMediaType(AutoName):
|
||||||
|
|
||||||
PAID_MEDIA = auto()
|
PAID_MEDIA = auto()
|
||||||
"Paid media"
|
"Paid media"
|
||||||
|
|
||||||
|
TODO = auto()
|
||||||
|
"To-Do list media"
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ from .stickerset import StickerSet
|
||||||
from .stories_privacy_rules import StoriesPrivacyRules
|
from .stories_privacy_rules import StoriesPrivacyRules
|
||||||
from .stripped_thumbnail import StrippedThumbnail
|
from .stripped_thumbnail import StrippedThumbnail
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
|
from .todo_list import TodoList
|
||||||
|
from .todo_task import TodoTask
|
||||||
from .venue import Venue
|
from .venue import Venue
|
||||||
from .video import Video
|
from .video import Video
|
||||||
from .video_note import VideoNote
|
from .video_note import VideoNote
|
||||||
|
|
@ -142,5 +144,7 @@ __all__ = [
|
||||||
"WallpaperSettings",
|
"WallpaperSettings",
|
||||||
"TranscribedAudio",
|
"TranscribedAudio",
|
||||||
"TranslatedText",
|
"TranslatedText",
|
||||||
"TextQuote"
|
"TextQuote",
|
||||||
|
"TodoList",
|
||||||
|
"TodoTask"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,9 @@ class Message(Object, Update):
|
||||||
paid_media (:obj:`~pyrogram.types.PaidMedia`, *optional*):
|
paid_media (:obj:`~pyrogram.types.PaidMedia`, *optional*):
|
||||||
Message is a paid media, information about the paid media.
|
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*):
|
sticker (:obj:`~pyrogram.types.Sticker`, *optional*):
|
||||||
Message is a sticker, information about the sticker.
|
Message is a sticker, information about the sticker.
|
||||||
|
|
||||||
|
|
@ -468,6 +471,7 @@ class Message(Object, Update):
|
||||||
document: "types.Document" = None,
|
document: "types.Document" = None,
|
||||||
photo: "types.Photo" = None,
|
photo: "types.Photo" = None,
|
||||||
paid_media: "types.PaidMedia" = None,
|
paid_media: "types.PaidMedia" = None,
|
||||||
|
todo: "types.Todo" = None,
|
||||||
sticker: "types.Sticker" = None,
|
sticker: "types.Sticker" = None,
|
||||||
animation: "types.Animation" = None,
|
animation: "types.Animation" = None,
|
||||||
game: "types.Game" = None,
|
game: "types.Game" = None,
|
||||||
|
|
@ -584,6 +588,7 @@ class Message(Object, Update):
|
||||||
self.document = document
|
self.document = document
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.paid_media = paid_media
|
self.paid_media = paid_media
|
||||||
|
self.todo = todo
|
||||||
self.sticker = sticker
|
self.sticker = sticker
|
||||||
self.animation = animation
|
self.animation = animation
|
||||||
self.game = game
|
self.game = game
|
||||||
|
|
@ -1004,6 +1009,7 @@ class Message(Object, Update):
|
||||||
|
|
||||||
photo = None
|
photo = None
|
||||||
paid_media = None
|
paid_media = None
|
||||||
|
todo = None
|
||||||
location = None
|
location = None
|
||||||
contact = None
|
contact = None
|
||||||
venue = None
|
venue = None
|
||||||
|
|
@ -1130,6 +1136,9 @@ class Message(Object, Update):
|
||||||
elif isinstance(media, raw.types.MessageMediaPaidMedia):
|
elif isinstance(media, raw.types.MessageMediaPaidMedia):
|
||||||
paid_media = types.PaidMedia._parse(client, media)
|
paid_media = types.PaidMedia._parse(client, media)
|
||||||
media_type = enums.MessageMediaType.PAID_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:
|
else:
|
||||||
media = None
|
media = None
|
||||||
|
|
||||||
|
|
@ -1199,6 +1208,7 @@ class Message(Object, Update):
|
||||||
invert_media=message.invert_media,
|
invert_media=message.invert_media,
|
||||||
photo=photo,
|
photo=photo,
|
||||||
paid_media=paid_media,
|
paid_media=paid_media,
|
||||||
|
todo=todo,
|
||||||
location=location,
|
location=location,
|
||||||
contact=contact,
|
contact=contact,
|
||||||
venue=venue,
|
venue=venue,
|
||||||
|
|
|
||||||
71
pyrogram/types/messages_and_media/todo_list.py
Normal file
71
pyrogram/types/messages_and_media/todo_list.py
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, types
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class TodoList(Object):
|
||||||
|
"""A list of tasks.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
title (``str``):
|
||||||
|
Title of the todo list.
|
||||||
|
|
||||||
|
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||||
|
Entities in the title of the todo list.
|
||||||
|
|
||||||
|
tasks (List of :obj:`~pyrogram.types.TodoTask`):
|
||||||
|
List of tasks in the todo list.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
title: str,
|
||||||
|
entities: List["types.MessageEntity"],
|
||||||
|
tasks: List["types.TodoTask"] = None
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.title = title
|
||||||
|
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(
|
||||||
|
title=todo_list.title.text,
|
||||||
|
entities=entities,
|
||||||
|
tasks=tasks
|
||||||
|
)
|
||||||
85
pyrogram/types/messages_and_media/todo_task.py
Normal file
85
pyrogram/types/messages_and_media/todo_task.py
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
title (``str``):
|
||||||
|
Title of the task.
|
||||||
|
|
||||||
|
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||||
|
Entities in the title 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,
|
||||||
|
id: int,
|
||||||
|
title: str,
|
||||||
|
entities: List["types.MessageEntity"],
|
||||||
|
is_completed: bool,
|
||||||
|
completed_by: "types.User" = None,
|
||||||
|
complete_date: "pyrogram.types.datetime" = None
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.id = id
|
||||||
|
self.title = title
|
||||||
|
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(
|
||||||
|
id=todo_task.id,
|
||||||
|
title=todo_task.title.text,
|
||||||
|
entities=entities,
|
||||||
|
is_completed=True if todo_completion else False,
|
||||||
|
completed_by=completed_by,
|
||||||
|
complete_date=complete_date
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue