mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Compare commits
2 commits
5413197003
...
22ccee53f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ccee53f4 | ||
|
|
989ce836d3 |
8 changed files with 249 additions and 1 deletions
|
|
@ -535,6 +535,9 @@ def pyrogram_api():
|
|||
MessageOrigin
|
||||
Photo
|
||||
Thumbnail
|
||||
TodoCompletion
|
||||
TodoList
|
||||
TodoTask
|
||||
Audio
|
||||
AvailableEffect
|
||||
Document
|
||||
|
|
|
|||
|
|
@ -84,3 +84,6 @@ class MessageMediaType(AutoName):
|
|||
|
||||
PAID_MEDIA = auto()
|
||||
"Paid media"
|
||||
|
||||
TODO = auto()
|
||||
"To-Do list media"
|
||||
|
|
|
|||
|
|
@ -135,3 +135,6 @@ class MessageServiceType(AutoName):
|
|||
|
||||
PAID_MESSAGE_PRICE_CHANGED = auto()
|
||||
"Paid message price changed"
|
||||
|
||||
TODO_COMPLETION = auto()
|
||||
"To-Do completion"
|
||||
|
|
@ -55,6 +55,9 @@ from .stickerset import StickerSet
|
|||
from .stories_privacy_rules import StoriesPrivacyRules
|
||||
from .stripped_thumbnail import StrippedThumbnail
|
||||
from .thumbnail import Thumbnail
|
||||
from .todo_completion import TodoCompletion
|
||||
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 +145,8 @@ __all__ = [
|
|||
"WallpaperSettings",
|
||||
"TranscribedAudio",
|
||||
"TranslatedText",
|
||||
"TextQuote"
|
||||
"TextQuote",
|
||||
"TodoCompletion",
|
||||
"TodoList",
|
||||
"TodoTask"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -481,6 +485,7 @@ class Message(Object, Update):
|
|||
gift: "types.Gift" = None,
|
||||
screenshot_taken: "types.ScreenshotTaken" = None,
|
||||
paid_message_price_changed: "types.PaidMessagePriceChanged" = None,
|
||||
todo_completion: "types.TodoCompletion" = None,
|
||||
invoice: "types.Invoice" = None,
|
||||
story: Union["types.MessageStory", "types.Story"] = None,
|
||||
alternative_videos: List["types.AlternativeVideo"] = None,
|
||||
|
|
@ -584,6 +589,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
|
||||
|
|
@ -598,6 +604,7 @@ class Message(Object, Update):
|
|||
self.gift = gift
|
||||
self.screenshot_taken = screenshot_taken
|
||||
self.paid_message_price_changed = paid_message_price_changed
|
||||
self.todo_completion = todo_completion
|
||||
self.invoice = invoice
|
||||
self.story = story
|
||||
self.video = video
|
||||
|
|
@ -763,6 +770,7 @@ class Message(Object, Update):
|
|||
gift = None
|
||||
screenshot_taken = None
|
||||
paid_message_price_changed = None
|
||||
todo_completion = None
|
||||
|
||||
service_type = None
|
||||
chat_join_type = None
|
||||
|
|
@ -888,6 +896,7 @@ class Message(Object, Update):
|
|||
paid_message_price_changed = types.PaidMessagePriceChanged._parse(action)
|
||||
service_type = enums.MessageServiceType.PAID_MESSAGE_PRICE_CHANGED
|
||||
|
||||
|
||||
parsed_message = Message(
|
||||
id=message.id,
|
||||
message_thread_id=message_thread_id,
|
||||
|
|
@ -967,6 +976,18 @@ class Message(Object, Update):
|
|||
parsed_message.service = enums.MessageServiceType.GAME_HIGH_SCORE
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
if isinstance(action, raw.types.MessageActionTodoCompletions):
|
||||
parsed_message.todo_completion = types.TodoCompletion._parse(action)
|
||||
parsed_message.service_type = enums.MessageServiceType.TODO_COMPLETION
|
||||
try:
|
||||
parsed_message.reply_to_message = await client.get_messages(
|
||||
parsed_message.chat.id,
|
||||
reply_to_message_ids=message.id,
|
||||
replies=0
|
||||
)
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
parsed_message.reply_to_message_id = message.reply_to.reply_to_msg_id
|
||||
|
||||
client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
|
||||
|
||||
|
|
@ -1004,6 +1025,7 @@ class Message(Object, Update):
|
|||
|
||||
photo = None
|
||||
paid_media = None
|
||||
todo = None
|
||||
location = None
|
||||
contact = None
|
||||
venue = None
|
||||
|
|
@ -1130,6 +1152,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 +1224,7 @@ class Message(Object, Update):
|
|||
invert_media=message.invert_media,
|
||||
photo=photo,
|
||||
paid_media=paid_media,
|
||||
todo=todo,
|
||||
location=location,
|
||||
contact=contact,
|
||||
venue=venue,
|
||||
|
|
|
|||
54
pyrogram/types/messages_and_media/todo_completion.py
Normal file
54
pyrogram/types/messages_and_media/todo_completion.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# 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 TodoCompletion(Object):
|
||||
"""A todo completion.
|
||||
|
||||
Parameters:
|
||||
id (``int``):
|
||||
Unique identifier of the todo tasks.
|
||||
|
||||
is_completed (``bool``):
|
||||
True, if the todo tasks is completed.
|
||||
"""
|
||||
|
||||
def __init__(self, id: int, is_completed: bool):
|
||||
super().__init__()
|
||||
|
||||
self.id = id
|
||||
self.is_completed = is_completed
|
||||
|
||||
@staticmethod
|
||||
def _parse(todo_completion: "raw.types.TodoCompletion") -> "TodoCompletion":
|
||||
if todo_completion.completed:
|
||||
return TodoCompletion(
|
||||
id=todo_completion.completed[0],
|
||||
is_completed=True
|
||||
)
|
||||
return TodoCompletion(
|
||||
id=todo_completion.incompleted[0],
|
||||
is_completed=False
|
||||
)
|
||||
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:
|
||||
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
|
||||
)
|
||||
82
pyrogram/types/messages_and_media/todo_task.py
Normal file
82
pyrogram/types/messages_and_media/todo_task.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# 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:
|
||||
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
|
||||
)
|
||||
Loading…
Reference in a new issue