diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index aa4fdae7..464a228e 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -174,6 +174,7 @@ def pyrogram_api(): send_audio send_document send_sticker + send_todo send_video send_animation send_voice @@ -739,6 +740,7 @@ def pyrogram_api(): InputVenueMessageContent InputContactMessageContent InputInvoiceMessageContent + InputTodoTask """, authorization=""" Authorization diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index d239cb49..2f75dc23 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -66,6 +66,7 @@ from .send_photo import SendPhoto from .send_poll import SendPoll from .send_reaction import SendReaction from .send_sticker import SendSticker +from .send_todo import SendTodo from .send_venue import SendVenue from .send_video import SendVideo from .send_video_note import SendVideoNote @@ -103,6 +104,7 @@ class Messages( SendMessage, SendPhoto, SendSticker, + SendTodo, SendVenue, SendVideo, SendVideoNote, diff --git a/pyrogram/methods/messages/send_todo.py b/pyrogram/methods/messages/send_todo.py new file mode 100644 index 00000000..8e671085 --- /dev/null +++ b/pyrogram/methods/messages/send_todo.py @@ -0,0 +1,99 @@ +# 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 . + +import pyrogram + +from pyrogram import raw, types, utils +from typing import Union, List + + +class SendTodo: + async def send_todo( + self: "pyrogram.Client", + chat_id: Union[int, str], + title: str, + tasks: List["types.InputTodoTask"], + entities: List["types.MessageEntity"] = None, + can_append: bool = False, + can_complete: bool = False, + parse_mode: Union[str, None] = None + ): + """Send a todo list to a chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target channel. + + title (``str``): + Title of the todo list. + + tasks (List of :obj:`~pyrogram.types.TodoTask`): + List of tasks in the todo list. + + entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*): + Entities in the title of the todo list. + + can_append (``bool``, *optional*): + True, if other users can append tasks to this todo list. + + can_complete (``bool``, *optional*): + True, if other users can complete tasks in this todo list. + """ + title, entities = (await utils.parse_text_entities(self, title, parse_mode, entities)).values() + tasks_list = [] + for i, task in enumerate(tasks): + task_title, task_entities = (await utils.parse_text_entities(self, task.title, parse_mode, task.entities)).values() + tasks_list.append( + raw.types.TodoItem( + id=i + 1, + title=raw.types.TextWithEntities( + text=task_title, + entities=task_entities or [] + ) + ) + ) + + r = await self.invoke( + raw.functions.messages.SendMedia( + peer=await self.resolve_peer(chat_id), + message="", + random_id=self.rnd_id(), + media=raw.types.InputMediaTodo( + todo=raw.types.TodoList( + title=raw.types.TextWithEntities( + text=title, + entities=entities or [] + ), + list=tasks_list, + others_can_append=can_append, + others_can_complete=can_complete + ) + ) + ) + ) + for i in r.updates: + if isinstance(i, (raw.types.UpdateNewMessage, + raw.types.UpdateNewChannelMessage, + raw.types.UpdateNewScheduledMessage, + raw.types.UpdateBotNewBusinessMessage)): + return await types.Message._parse( + self, i.message, + {i.id: i for i in r.users}, + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage) + ) diff --git a/pyrogram/types/input_message_content/__init__.py b/pyrogram/types/input_message_content/__init__.py index ae897b0d..5b2b15a0 100644 --- a/pyrogram/types/input_message_content/__init__.py +++ b/pyrogram/types/input_message_content/__init__.py @@ -26,6 +26,7 @@ from .input_location_message_content import InputLocationMessageContent from .input_venue_message_content import InputVenueMessageContent from .input_contact_message_content import InputContactMessageContent from .input_invoice_message_content import InputInvoiceMessageContent +from .input_todo_task import InputTodoTask __all__ = [ "InputMessageContent", @@ -36,5 +37,6 @@ __all__ = [ "InputLocationMessageContent", "InputVenueMessageContent", "InputContactMessageContent", - "InputInvoiceMessageContent" + "InputInvoiceMessageContent", + "InputTodoTask" ] diff --git a/pyrogram/types/input_message_content/input_todo_task.py b/pyrogram/types/input_message_content/input_todo_task.py new file mode 100644 index 00000000..2e4d6ab0 --- /dev/null +++ b/pyrogram/types/input_message_content/input_todo_task.py @@ -0,0 +1,37 @@ +# 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 ..object import Object + + +class InputTodoTask(Object): + """Contains information about a todo task. + + Parameters: + title (``str``): + Title of the task. + + entities (List of :obj:`~pyrogram.types.MessageEntity`): + Entities in the title of the task. + """ + + def __init__(self, *, title: str, entities: list = None): + super().__init__() + + self.title = title + self.entities = entities