diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 5b6bccd2..e9cd912e 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -23,7 +23,13 @@ from queue import Queue from threading import Thread, Lock import pyrogram -from pyrogram.api import types +from pyrogram.api.types import ( + UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage, + UpdateEditMessage, UpdateEditChannelMessage, + UpdateDeleteMessages, UpdateDeleteChannelMessages, + UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, + UpdateUserStatus, UpdateBotInlineQuery, UpdateMessagePoll +) from . import utils from ..handlers import ( CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, @@ -35,23 +41,24 @@ log = logging.getLogger(__name__) class Dispatcher: NEW_MESSAGE_UPDATES = ( - types.UpdateNewMessage, - types.UpdateNewChannelMessage + UpdateNewMessage, + UpdateNewChannelMessage, + UpdateNewScheduledMessage ) EDIT_MESSAGE_UPDATES = ( - types.UpdateEditMessage, - types.UpdateEditChannelMessage + UpdateEditMessage, + UpdateEditChannelMessage, ) DELETE_MESSAGES_UPDATES = ( - types.UpdateDeleteMessages, - types.UpdateDeleteChannelMessages + UpdateDeleteMessages, + UpdateDeleteChannelMessages ) CALLBACK_QUERY_UPDATES = ( - types.UpdateBotCallbackQuery, - types.UpdateInlineBotCallbackQuery + UpdateBotCallbackQuery, + UpdateInlineBotCallbackQuery ) MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES @@ -68,7 +75,16 @@ class Dispatcher: self.update_parsers = { Dispatcher.MESSAGE_UPDATES: - lambda upd, usr, cht: (pyrogram.Message._parse(self.client, upd.message, usr, cht), MessageHandler), + lambda upd, usr, cht: ( + pyrogram.Message._parse( + self.client, + upd.message, + usr, + cht, + isinstance(upd, UpdateNewScheduledMessage) + ), + MessageHandler + ), Dispatcher.DELETE_MESSAGES_UPDATES: lambda upd, usr, cht: (utils.parse_deleted_messages(self.client, upd), DeletedMessagesHandler), @@ -76,13 +92,13 @@ class Dispatcher: Dispatcher.CALLBACK_QUERY_UPDATES: lambda upd, usr, cht: (pyrogram.CallbackQuery._parse(self.client, upd, usr), CallbackQueryHandler), - (types.UpdateUserStatus,): + (UpdateUserStatus,): lambda upd, usr, cht: (pyrogram.User._parse_user_status(self.client, upd), UserStatusHandler), - (types.UpdateBotInlineQuery,): + (UpdateBotInlineQuery,): lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler), - (types.UpdateMessagePoll,): + (UpdateMessagePoll,): lambda upd, usr, cht: (pyrogram.Poll._parse_update(self.client, upd), PollHandler) } diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 5d345010..b4ca4e43 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -39,6 +39,7 @@ class SendAnimation(BaseClient): thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -98,6 +99,9 @@ class SendAnimation(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -183,6 +187,7 @@ class SendAnimation(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -191,11 +196,15 @@ class SendAnimation(BaseClient): self.save_file(animation, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): message = pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) if unsave: diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 7395718b..63478c63 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -38,6 +38,7 @@ class SendAudio(BaseClient): thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -95,6 +96,9 @@ class SendAudio(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -181,6 +185,7 @@ class SendAudio(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -189,11 +194,15 @@ class SendAudio(BaseClient): self.save_file(audio, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_cached_media.py b/pyrogram/client/methods/messages/send_cached_media.py index 9b4fbafa..874b0507 100644 --- a/pyrogram/client/methods/messages/send_cached_media.py +++ b/pyrogram/client/methods/messages/send_cached_media.py @@ -32,6 +32,7 @@ class SendCachedMedia(BaseClient): parse_mode: Union[str, None] = object, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -72,6 +73,9 @@ class SendCachedMedia(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -92,15 +96,17 @@ class SendCachedMedia(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index c32ca25d..84174433 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -33,6 +33,7 @@ class SendContact(BaseClient): vcard: str = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -67,6 +68,9 @@ class SendContact(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -92,14 +96,16 @@ class SendContact(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 567bc561..4064fc2a 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -35,6 +35,7 @@ class SendDocument(BaseClient): parse_mode: Union[str, None] = object, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -81,6 +82,9 @@ class SendDocument(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -156,6 +160,7 @@ class SendDocument(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -164,11 +169,15 @@ class SendDocument(BaseClient): self.save_file(document, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index 245f61f2..23204d80 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -31,6 +31,7 @@ class SendLocation(BaseClient): longitude: float, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -59,6 +60,9 @@ class SendLocation(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -84,14 +88,16 @@ class SendLocation(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index c15b3a84..1389ff21 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -32,6 +32,7 @@ class SendMessage(BaseClient): disable_web_page_preview: bool = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -67,6 +68,9 @@ class SendMessage(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -121,6 +125,7 @@ class SendMessage(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, message=message, entities=entities @@ -151,9 +156,10 @@ class SendMessage(BaseClient): ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index 0c82ebfc..95fdeef8 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -35,6 +35,7 @@ class SendPhoto(BaseClient): ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -80,6 +81,9 @@ class SendPhoto(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -151,6 +155,7 @@ class SendPhoto(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -159,11 +164,15 @@ class SendPhoto(BaseClient): self.save_file(photo, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_poll.py b/pyrogram/client/methods/messages/send_poll.py index 2fa008ab..a684dda9 100644 --- a/pyrogram/client/methods/messages/send_poll.py +++ b/pyrogram/client/methods/messages/send_poll.py @@ -31,6 +31,7 @@ class SendPoll(BaseClient): options: List[str], disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -59,6 +60,9 @@ class SendPoll(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -88,14 +92,16 @@ class SendPoll(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index ae5e8551..9c6e042c 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -32,6 +32,7 @@ class SendSticker(BaseClient): sticker: str, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -62,6 +63,9 @@ class SendSticker(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -129,6 +133,7 @@ class SendSticker(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, message="" ) @@ -137,11 +142,15 @@ class SendSticker(BaseClient): self.save_file(sticker, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index ab630936..5d95b1c2 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -35,6 +35,7 @@ class SendVenue(BaseClient): foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -76,6 +77,9 @@ class SendVenue(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -108,14 +112,16 @@ class SendVenue(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index ca6f0519..26a70ac1 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -39,6 +39,7 @@ class SendVideo(BaseClient): supports_streaming: bool = True, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -98,6 +99,9 @@ class SendVideo(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -179,6 +183,7 @@ class SendVideo(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -187,11 +192,15 @@ class SendVideo(BaseClient): self.save_file(video, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index 65988b36..3f309fa3 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -35,6 +35,7 @@ class SendVideoNote(BaseClient): thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -77,6 +78,9 @@ class SendVideoNote(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -147,6 +151,7 @@ class SendVideoNote(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, message="" ) @@ -155,11 +160,15 @@ class SendVideoNote(BaseClient): self.save_file(video_note, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index 8d9f6c5f..5db42cd2 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -35,6 +35,7 @@ class SendVoice(BaseClient): duration: int = 0, disable_notification: bool = None, reply_to_message_id: int = None, + schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", @@ -78,6 +79,9 @@ class SendVoice(BaseClient): reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message + schedule_date (``int``, *optional*): + Date when the message will be automatically sent. Unix time. + reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -151,6 +155,7 @@ class SendVoice(BaseClient): silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), + schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None, **self.parser.parse(caption, parse_mode) ) @@ -159,11 +164,15 @@ class SendVoice(BaseClient): self.save_file(voice, file_id=file.id, file_part=e.x) else: for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): + if isinstance( + i, + (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage) + ): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, - {i.id: i for i in r.chats} + {i.id: i for i in r.chats}, + is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) ) except BaseClient.StopTransmission: return None diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 0052e86d..54aabdfc 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -282,6 +282,8 @@ class Message(Object, Update): mentioned: bool = None, empty: bool = None, service: bool = None, + scheduled: bool = None, + from_scheduled: bool = None, media: bool = None, edit_date: int = None, media_group_id: str = None, @@ -344,6 +346,8 @@ class Message(Object, Update): self.mentioned = mentioned self.empty = empty self.service = service + self.scheduled = scheduled + self.from_scheduled = from_scheduled self.media = media self.edit_date = edit_date self.media_group_id = media_group_id @@ -387,7 +391,7 @@ class Message(Object, Update): @staticmethod def _parse(client, message: types.Message or types.MessageService or types.MessageEmpty, users: dict, chats: dict, - replies: int = 1): + is_scheduled: bool = False, replies: int = 1): if isinstance(message, types.MessageEmpty): return Message(message_id=message.id, empty=True, client=client) @@ -620,6 +624,8 @@ class Message(Object, Update): forward_signature=forward_signature, forward_date=forward_date, mentioned=message.mentioned, + scheduled=is_scheduled, + from_scheduled=message.from_scheduled, media=bool(media) or None, edit_date=message.edit_date, media_group_id=message.grouped_id,