From 32a09ffc4cb17a3595ab2ada4167f297f57e623c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 10:28:11 +0100 Subject: [PATCH 1/7] Add Message.empty field --- pyrogram/client/ext/utils.py | 2 +- pyrogram/client/types/messages_and_media/message.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 123dfabf..6d6fe828 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -751,7 +751,7 @@ def parse_messages( except MessageIdsEmpty: pass else: - m = pyrogram_types.Message(message_id=message.id, client=proxy(client)) + m = pyrogram_types.Message(message_id=message.id, client=proxy(client), empty=True) parsed_messages.append(m) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 2dce5dfb..b20c2c3f 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -58,6 +58,10 @@ class Message(Object): mentioned (``bool``, *optional*): The message contains a mention. + empty (``bool``, *optional*): + The message is empty. + A message can be empty in case it was deleted or you tried to retrieve a message that doesn't exist yet. + edit_date (``int``, *optional*): Date the message was last edited in Unix time. @@ -210,6 +214,7 @@ class Message(Object): forward_date: int = None, reply_to_message=None, mentioned=None, + empty=None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, @@ -258,6 +263,7 @@ class Message(Object): self.forward_date = forward_date # flags.5?int self.reply_to_message = reply_to_message # flags.6?Message self.mentioned = mentioned + self.empty = empty self.edit_date = edit_date # flags.7?int self.media_group_id = media_group_id # flags.8?string self.author_signature = author_signature # flags.9?string From fc7b77e2b9a433dc7ef97c2e00d0d81165319332 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 10:40:35 +0100 Subject: [PATCH 2/7] Add Message.service field --- pyrogram/client/ext/utils.py | 1 + pyrogram/client/types/messages_and_media/message.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 6d6fe828..3df2a450 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -728,6 +728,7 @@ def parse_messages( date=message.date, chat=parse_chat(message, users, chats), from_user=parse_user(users.get(message.from_id, None)), + service=True, new_chat_members=new_chat_members, left_chat_member=left_chat_member, new_chat_title=new_chat_title, diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index b20c2c3f..12f3116a 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -62,6 +62,12 @@ class Message(Object): The message is empty. A message can be empty in case it was deleted or you tried to retrieve a message that doesn't exist yet. + service (``bool``, *optional*): + The message is a service message. + A service message has one and only one of these fields set: left_chat_member, new_chat_title, + new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, + migrate_to_chat_id, migrate_from_chat_id, pinned_message. + edit_date (``int``, *optional*): Date the message was last edited in Unix time. @@ -215,6 +221,7 @@ class Message(Object): reply_to_message=None, mentioned=None, empty=None, + service=None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, @@ -264,6 +271,7 @@ class Message(Object): self.reply_to_message = reply_to_message # flags.6?Message self.mentioned = mentioned self.empty = empty + self.service = service self.edit_date = edit_date # flags.7?int self.media_group_id = media_group_id # flags.8?string self.author_signature = author_signature # flags.9?string From f26e20d30e43138aaed1f8edb34f86c44c6a3ede Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 10:44:32 +0100 Subject: [PATCH 3/7] Update Filters.service --- pyrogram/client/filters/filters.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index ff06b327..b847543a 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -166,11 +166,14 @@ class Filters: inline_keyboard = create("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) """Filter messages containing inline keyboard markups""" - dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) - mentioned = create("Mentioned", lambda _, m: bool(m.mentioned)) """Filter messages containing mentions""" + service = create("Service", lambda _, m: bool(m.service)) + """Filter messages containing any of these fields set: left_chat_member, new_chat_title, new_chat_photo, + delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, + migrate_from_chat_id, pinned_message""" + @staticmethod def command(command: str or list, prefix: str or list = "/", @@ -307,24 +310,6 @@ class Filters: and not message.outgoing)) ) - service = create( - "Service", - lambda _, m: bool( - Filters.new_chat_members(m) - or Filters.left_chat_member(m) - or Filters.new_chat_title(m) - or Filters.new_chat_photo(m) - or Filters.delete_chat_photo(m) - or Filters.group_chat_created(m) - or Filters.supergroup_chat_created(m) - or Filters.channel_chat_created(m) - or Filters.migrate_to_chat_id(m) - or Filters.migrate_from_chat_id(m) - or Filters.pinned_message(m) - ) - ) - """Filter all service messages.""" - media = create( "Media", lambda _, m: bool( @@ -342,3 +327,5 @@ class Filters: ) ) """Filter all media messages.""" + + dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) From e760550f8b443cf67289d11106eab3bff940593d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 10:49:32 +0100 Subject: [PATCH 4/7] Add Message.media field --- pyrogram/client/ext/utils.py | 1 + pyrogram/client/types/messages_and_media/message.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3df2a450..218655f4 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -607,6 +607,7 @@ def parse_messages( forward_signature=forward_signature, forward_date=forward_date, mentioned=message.mentioned, + media=bool(media) or None, edit_date=message.edit_date, media_group_id=message.grouped_id, photo=photo, diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 12f3116a..ffcab6f3 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -68,6 +68,11 @@ class Message(Object): new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message. + media (``bool``` *optional*): + The message is a media message. + A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation, + voice, video_note, contact, location, venue. + edit_date (``int``, *optional*): Date the message was last edited in Unix time. @@ -222,6 +227,7 @@ class Message(Object): mentioned=None, empty=None, service=None, + media=None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, @@ -272,6 +278,7 @@ class Message(Object): self.mentioned = mentioned self.empty = empty self.service = service + self.media = media self.edit_date = edit_date # flags.7?int self.media_group_id = media_group_id # flags.8?string self.author_signature = author_signature # flags.9?string From b747f87319080d084c201fa46aad753c9b484f9e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 10:50:52 +0100 Subject: [PATCH 5/7] Update Filters.media --- pyrogram/client/filters/filters.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index b847543a..f3d2ec56 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -174,6 +174,10 @@ class Filters: delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message""" + media = create("Media", lambda _, m: bool(m.media)) + """Filter messages containing any of these fields set: audio, document, photo, sticker, video, animation, voice, + video_note, contact, location, venue""" + @staticmethod def command(command: str or list, prefix: str or list = "/", @@ -310,22 +314,4 @@ class Filters: and not message.outgoing)) ) - media = create( - "Media", - lambda _, m: bool( - Filters.audio(m) - or Filters.document(m) - or Filters.photo(m) - or Filters.sticker(m) - or Filters.video(m) - or Filters.animation(m) - or Filters.voice(m) - or Filters.video_note(m) - or Filters.contact(m) - or Filters.location(m) - or Filters.venue(m) - ) - ) - """Filter all media messages.""" - dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) From f6d3db366240603f7c52017d0113117693712588 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 11:03:47 +0100 Subject: [PATCH 6/7] Update docstring style --- pyrogram/client/filters/filters.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index f3d2ec56..d470e993 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -170,13 +170,13 @@ class Filters: """Filter messages containing mentions""" service = create("Service", lambda _, m: bool(m.service)) - """Filter messages containing any of these fields set: left_chat_member, new_chat_title, new_chat_photo, - delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, - migrate_from_chat_id, pinned_message""" + """Filter messages containing any of these fields set: *left_chat_member*, *new_chat_title*, *new_chat_photo*, + *delete_chat_photo*, *group_chat_created*, *supergroup_chat_created*, *channel_chat_created*, *migrate_to_chat_id*, + *migrate_from_chat_id*, *pinned_message*""" media = create("Media", lambda _, m: bool(m.media)) - """Filter messages containing any of these fields set: audio, document, photo, sticker, video, animation, voice, - video_note, contact, location, venue""" + """Filter messages containing any of these fields set: *audio*, *document*, *photo*, *sticker*, *video*, + *animation*, *voice*, *video_note*, *contact*, *location*, *venue*""" @staticmethod def command(command: str or list, From 774462283ec1487c630ceb5d2b8e45b840df9b8d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 8 Nov 2018 11:10:24 +0100 Subject: [PATCH 7/7] Update service and media filter docstrings --- pyrogram/client/filters/filters.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index d470e993..57e48948 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -170,13 +170,33 @@ class Filters: """Filter messages containing mentions""" service = create("Service", lambda _, m: bool(m.service)) - """Filter messages containing any of these fields set: *left_chat_member*, *new_chat_title*, *new_chat_photo*, - *delete_chat_photo*, *group_chat_created*, *supergroup_chat_created*, *channel_chat_created*, *migrate_to_chat_id*, - *migrate_from_chat_id*, *pinned_message*""" + """Filter service messages. A service message contains any of the following fields set + + - left_chat_member + - new_chat_title + - new_chat_photo + - delete_chat_photo + - group_chat_created + - supergroup_chat_created + - channel_chat_created + - migrate_to_chat_id + - migrate_from_chat_id + - pinned_message""" media = create("Media", lambda _, m: bool(m.media)) - """Filter messages containing any of these fields set: *audio*, *document*, *photo*, *sticker*, *video*, - *animation*, *voice*, *video_note*, *contact*, *location*, *venue*""" + """Filter media messages. A media message contains any of the following fields set + + - audio + - document + - photo + - sticker + - video + - animation + - voice + - video_note + - contact + - location + - venue""" @staticmethod def command(command: str or list,