From c9462911cfced5c5640ac005a64e498604ec0626 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 25 Oct 2018 14:47:18 +0200 Subject: [PATCH 01/10] Fix Filters.command ignoring commands with empty prefixes --- pyrogram/client/filters/filters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index e80e230e..173b211c 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -183,6 +183,7 @@ class Filters: prefix (``str`` | ``list``, *optional*): A prefix or a list of prefixes as string the filter should look for. Defaults to "/" (slash). Examples: ".", "!", ["/", "!", "."]. + Can be None or "" (empty string) to allow commands with no prefix at all. separator (``str``, *optional*): The command arguments separator. Defaults to " " (white space). @@ -214,7 +215,7 @@ class Filters: else {c if case_sensitive else c.lower() for c in command}, - p=set(prefix), + p=set(prefix) if prefix else {""}, s=separator, cs=case_sensitive ) From 11b7c3b52a5dce678b7762fab4c8939e7a6db221 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 15:26:46 +0100 Subject: [PATCH 02/10] Remove unused game field from Message --- pyrogram/client/types/messages_and_media/message.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index ac8721e8..e86e4300 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -83,9 +83,6 @@ class Message(Object): document (:obj:`Document `, *optional*): Message is a general file, information about the file. - game (:obj:`Game `, *optional*): - Message is a game, information about the game. More about games. - photo (:obj:`Photo `, *optional*): Message is a photo, information about the photo. @@ -225,7 +222,6 @@ class Message(Object): caption_entities: list = None, audio=None, document=None, - game=None, photo=None, sticker=None, animation=None, @@ -276,7 +272,6 @@ class Message(Object): self.caption_entities = caption_entities # flags.12?Vector self.audio = audio # flags.13?Audio self.document = document # flags.14?Document - self.game = game # flags.15?Game self.photo = photo # flags.16?Vector self.sticker = sticker # flags.17?Sticker self.animation = animation From 0a946033c3d10d19d9069b42995fd483600f6445 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 15:27:20 +0100 Subject: [PATCH 03/10] Move optional field down after required fields --- pyrogram/client/types/user_and_chats/user.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index fc267b07..06045b00 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -41,12 +41,12 @@ class User(Object): is_bot (``bool``): True, if this user is a bot. - status (:obj:`UserStatus `): - User's Last Seen status. Empty for bots. - first_name (``str``): User's or bot's first name. + status (:obj:`UserStatus `, *optional*): + User's Last Seen status. Empty for bots. + last_name (``str``, *optional*): User's or bot's last name. @@ -76,8 +76,8 @@ class User(Object): is_mutual_contact: bool, is_deleted: bool, is_bot: bool, - status, first_name: str, + status=None, last_name: str = None, username: str = None, language_code: str = None, @@ -91,8 +91,8 @@ class User(Object): self.is_mutual_contact = is_mutual_contact self.is_deleted = is_deleted self.is_bot = is_bot - self.status = status self.first_name = first_name + self.status = status self.last_name = last_name self.username = username self.language_code = language_code From 4fd93a790fdd667189e294a1ad950acff852016f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 15:27:49 +0100 Subject: [PATCH 04/10] Small fixes and rewords --- .../types/user_and_chats/user_status.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/user_status.py b/pyrogram/client/types/user_and_chats/user_status.py index 17b73ea1..b2974dbe 100644 --- a/pyrogram/client/types/user_and_chats/user_status.py +++ b/pyrogram/client/types/user_and_chats/user_status.py @@ -28,35 +28,35 @@ class UserStatus(Object): "recently", "within_week", "within_month" or "long_time_ago" fields set. Args: - user_id (``int``): - User's id. Only available for UserStatus updates. + user_id (``int``, *optional*): + User's id. Only available for incoming UserStatus updates. - online (``bool``): - True if the user is online in this moment, None otherwise. + online (``bool``, *optional*): + True if the user is online in this very moment, None otherwise. If True, the "date" field will be also set containing the online expiration date (i.e.: the date when a user will automatically go offline in case of no action by his client). - offline (``bool``): - True if the user is offline and has the Last Seen privacy setting visible for everybody, None otherwise. + offline (``bool``, *optional*): + True if the user is offline in this moment and has the Last Seen privacy setting public, None otherwise. If True, the "date" field will be also set containing the last seen date (i.e.: the date when a user was online the last time). - date (``int``): + date (``int``, *optional*): Exact date in unix time. Available only in case "online" or "offline" equals to True. - recently (``bool``): + recently (``bool``, *optional*): True for users with hidden Last Seen privacy that have been online between 1 second and 2-3 days ago, None otherwise. - within_week (``bool``): + within_week (``bool``, *optional*): True for users with hidden Last Seen privacy that have been online between 2-3 and seven days ago, None otherwise. - within_month (``bool``): + within_month (``bool``, *optional*): True for users with hidden Last Seen privacy that have been online between 6-7 days and a month ago, None otherwise. - long_time_ago (``bool``): + long_time_ago (``bool``, *optional*): True for users with hidden Last Seen privacy that have been online more than a month ago (this is also always shown to blocked users), None otherwise. """ From 39636f2843ff699eba4c112dc305e348e5e87383 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 17:18:00 +0100 Subject: [PATCH 05/10] Update get_messages signature --- pyrogram/client/ext/base_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index c18c4050..32046115 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -119,7 +119,8 @@ class BaseClient: def get_messages( self, chat_id: int or str, - message_ids, + message_ids: int or list = None, + reply_to_message_ids: int or list = None, replies: int = 1 ): pass From daee188fa55b68a5b75be758bc066dab9991021f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 17:23:30 +0100 Subject: [PATCH 06/10] Update get_messages to accept the new reply_to_message_ids argument --- .../client/methods/messages/get_messages.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index c2751d74..29cce695 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -23,9 +23,10 @@ from ...ext import BaseClient, utils class GetMessages(BaseClient): def get_messages(self, chat_id: int or str, - message_ids, + message_ids: int or list = None, + reply_to_message_ids: int or list = None, replies: int = 1): - """Use this method to get messages that belong to a specific chat. + """Use this method to get one or more messages that belong to a specific chat. You can retrieve up to 200 messages at once. Args: @@ -50,20 +51,25 @@ class GetMessages(BaseClient): Raises: :class:`Error ` """ + ids, ids_type = ( + (message_ids, types.InputMessageID) if message_ids + else (reply_to_message_ids, types.InputMessageReplyTo) if reply_to_message_ids + else (None, None) + ) + + if ids is None: + raise ValueError("No argument supplied") + peer = self.resolve_peer(chat_id) - is_iterable = not isinstance(message_ids, int) - message_ids = list(message_ids) if is_iterable else [message_ids] - message_ids = [types.InputMessageID(i) for i in message_ids] + + is_iterable = not isinstance(ids, int) + ids = list(ids) if is_iterable else [ids] + ids = [types.InputMessageID(i) for i in ids] if isinstance(peer, types.InputPeerChannel): - rpc = functions.channels.GetMessages( - channel=peer, - id=message_ids - ) + rpc = functions.channels.GetMessages(channel=peer, id=ids) else: - rpc = functions.messages.GetMessages( - id=message_ids - ) + rpc = functions.messages.GetMessages(id=ids) r = self.send(rpc) From 6cf6d496342e636f0d65e5835e1d6ed6cfc180fd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 17:24:05 +0100 Subject: [PATCH 07/10] Update utils to accommodate changes on get_messages --- pyrogram/client/ext/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 94be83f5..492fbeb0 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -638,7 +638,8 @@ def parse_messages( while True: try: m.reply_to_message = client.get_messages( - m.chat.id, message.reply_to_msg_id, + m.chat.id, + reply_to_message_ids=message.id, replies=replies - 1 ) except FloodWait as e: @@ -750,8 +751,8 @@ def parse_messages( while True: try: m.pinned_message = client.get_messages( - m.chat.id, message.reply_to_msg_id, - replies=0 + m.chat.id, + message_ids=message.reply_to_msg_id ) except FloodWait as e: log.warning("get_messages flood: waiting {} seconds".format(e.x)) @@ -948,7 +949,7 @@ def parse_chat_full( if full_chat.pinned_msg_id: parsed_chat.pinned_message = client.get_messages( parsed_chat.id, - full_chat.pinned_msg_id + message_ids=full_chat.pinned_msg_id ) if isinstance(full_chat.exported_invite, types.ChatInviteExported): From 005c24e4bd711d4bd8005cb76bfe65e969ce7407 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 17:24:37 +0100 Subject: [PATCH 08/10] Update get_messages docstrings --- .../client/methods/messages/get_messages.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 29cce695..25fd0da1 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -35,18 +35,23 @@ class GetMessages(BaseClient): For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - message_ids (``iterable``): - A list of Message identifiers in the chat specified in *chat_id* or a single message id, as integer. - Iterators and Generators are also accepted. + message_ids (``iterable``, *optional*): + Pass a single message identifier or a list of message ids (as integers) to get the content of the + message themselves. Iterators and Generators are also accepted. + + reply_to_message_ids (``iterable``, *optional*): + Pass a single message identifier or a list of message ids (as integers) to get the content of + the previous message you replied to using this message. Iterators and Generators are also accepted. + If *message_ids* is set, this argument will be ignored. replies (``int``, *optional*): The number of subsequent replies to get for each message. Defaults to 1. Returns: - On success and in case *message_ids* was a list, the returned value will be a list of the requested - :obj:`Messages ` even if a list contains just one element, otherwise if - *message_ids* was an integer, the single requested :obj:`Message ` - is returned. + On success and in case *message_ids* or *reply_to_message_ids* was a list, the returned value will be a + list of the requested :obj:`Messages ` even if a list contains just one element, + otherwise if *message_ids* or *reply_to_message_ids* was an integer, the single requested + :obj:`Message ` is returned. Raises: :class:`Error ` From 229b8df9cd98d816844503028053777c21c05652 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 17:44:24 +0100 Subject: [PATCH 09/10] Fix bad behaviours of get_messages --- pyrogram/client/ext/utils.py | 3 ++- pyrogram/client/methods/messages/get_messages.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 492fbeb0..a2f1c3db 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -752,7 +752,8 @@ def parse_messages( try: m.pinned_message = client.get_messages( m.chat.id, - message_ids=message.reply_to_msg_id + reply_to_message_ids=message.id, + replies=0 ) except FloodWait as e: log.warning("get_messages flood: waiting {} seconds".format(e.x)) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 25fd0da1..e65ce128 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -69,7 +69,7 @@ class GetMessages(BaseClient): is_iterable = not isinstance(ids, int) ids = list(ids) if is_iterable else [ids] - ids = [types.InputMessageID(i) for i in ids] + ids = [ids_type(i) for i in ids] if isinstance(peer, types.InputPeerChannel): rpc = functions.channels.GetMessages(channel=peer, id=ids) From 529ef143f0de7fcc3d35b0735612f10f83c18962 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 28 Oct 2018 19:52:54 +0100 Subject: [PATCH 10/10] Remove debugging piece of code --- pyrogram/client/ext/emoji.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pyrogram/client/ext/emoji.py b/pyrogram/client/ext/emoji.py index bcd98854..b2dd99fd 100644 --- a/pyrogram/client/ext/emoji.py +++ b/pyrogram/client/ext/emoji.py @@ -7849,8 +7849,3 @@ class Emoji: REVERSED_THUMBS_UP_SIGN_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f592\U0001f3ff" LEFT_WRITING_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f58e\U0001f3ff" REVERSED_VICTORY_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f594\U0001f3ff" - -with open("suca.txt", "w") as f: - for k, v in Emoji.__dict__.items(): - if not k.startswith("__"): - f.write("{},{}\n".format(k, v)) \ No newline at end of file