diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index 2b825520..e6ddc505 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -118,7 +118,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 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 diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 4177ca56..23396472 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -650,7 +650,8 @@ async def parse_messages( while True: try: m.reply_to_message = await 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: @@ -762,7 +763,8 @@ async def parse_messages( while True: try: m.pinned_message = await client.get_messages( - m.chat.id, message.reply_to_msg_id, + m.chat.id, + reply_to_message_ids=message.id, replies=0 ) except FloodWait as e: @@ -960,7 +962,7 @@ async def parse_chat_full( if full_chat.pinned_msg_id: parsed_chat.pinned_message = await 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): 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 ) diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 906aa7ce..bb96f329 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): async 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: @@ -34,36 +35,46 @@ 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 ` """ + 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 = await 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 = [ids_type(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 = await self.send(rpc) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index e149f669..cd5b9cd8 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 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 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. """