From 91beb214e9cd3ff4cf71425f245b3fd327536bbb Mon Sep 17 00:00:00 2001 From: Furoin Date: Tue, 6 Nov 2018 17:11:35 +0300 Subject: [PATCH 1/7] added message.mentioned --- pyrogram/client/ext/utils.py | 3 +++ pyrogram/client/types/messages_and_media/message.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index bc908165..0d0c5abf 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -591,6 +591,8 @@ def parse_messages( else: reply_markup = None + mentioned = message.mentioned + m = pyrogram_types.Message( message_id=message.id, date=message.date, @@ -606,6 +608,7 @@ def parse_messages( forward_from_message_id=forward_from_message_id, forward_signature=forward_signature, forward_date=forward_date, + mentioned=mentioned, 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 86bb57bc..59776859 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -206,6 +206,7 @@ class Message(Object): forward_signature: str = None, forward_date: int = None, reply_to_message=None, + mentioned=None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, @@ -253,6 +254,7 @@ class Message(Object): self.forward_signature = forward_signature # flags.4?string self.forward_date = forward_date # flags.5?int self.reply_to_message = reply_to_message # flags.6?Message + self.mentioned = mentioned 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 2d0ffcb0f48117af882213da8f056056f2cfa59b Mon Sep 17 00:00:00 2001 From: Furoin Date: Tue, 6 Nov 2018 17:13:37 +0300 Subject: [PATCH 2/7] added Filters.mentioned --- pyrogram/client/filters/filters.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index aeb730a7..6b9e9fd2 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -168,6 +168,8 @@ class Filters: dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) + mentioned = create("Mentioned", lambda _, m: bool(m.mentioned)) + @staticmethod def command(command: str or list, prefix: str or list = "/", From 1adc8121080ff71f247cee6afac52647cf9c42d9 Mon Sep 17 00:00:00 2001 From: Furoin Date: Tue, 6 Nov 2018 18:36:40 +0300 Subject: [PATCH 3/7] added Filters.chat("me") --- pyrogram/client/filters/filters.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index aeb730a7..037e6bb9 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -287,9 +287,9 @@ class Filters: def __init__(self, chats: int or str or list = None): chats = [] if chats is None else chats if type(chats) is list else [chats] super().__init__( - {i.lower().strip("@") if type(i) is str else i for i in chats} + {"me" if i in ["me", "self"] else i.lower().strip("@") if type(i) is str else i for i in chats} if type(chats) is list else - {chats.lower().strip("@") if type(chats) is str else chats} + {"me" if chats in ["me", "self"] else chats.lower().strip("@") if type(chats) is str else chats} ) def __call__(self, message): @@ -297,7 +297,10 @@ class Filters: message.chat and (message.chat.id in self or (message.chat.username - and message.chat.username.lower() in self)) + and message.chat.username.lower() in self) + or ("me" in self and message.from_user + and message.from_user.is_self + and not message.outgoing)) ) service = create( From 5da5cabf4ca708f5aeb067f76f9528ff6acc3131 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Nov 2018 17:31:04 +0100 Subject: [PATCH 4/7] Remove useless variable --- pyrogram/client/ext/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 0d0c5abf..6fc2552a 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -591,8 +591,6 @@ def parse_messages( else: reply_markup = None - mentioned = message.mentioned - m = pyrogram_types.Message( message_id=message.id, date=message.date, @@ -608,7 +606,7 @@ def parse_messages( forward_from_message_id=forward_from_message_id, forward_signature=forward_signature, forward_date=forward_date, - mentioned=mentioned, + mentioned=message.mentioned, edit_date=message.edit_date, media_group_id=message.grouped_id, photo=photo, From 0943761a911ae2a0f29127f1b29860ff8b308ddd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Nov 2018 17:32:46 +0100 Subject: [PATCH 5/7] Update filters.py --- pyrogram/client/filters/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 6b9e9fd2..48f0965d 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -169,6 +169,7 @@ class Filters: 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""" @staticmethod def command(command: str or list, From 5571888143dc310168b3383a8718209510f103e0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Nov 2018 17:37:32 +0100 Subject: [PATCH 6/7] Add mentioned docstrings --- pyrogram/client/types/messages_and_media/message.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 59776859..d224a9c6 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -55,6 +55,9 @@ class Message(Object): For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + mentioned (``bool``, *optional*): + The message contains a mention. + edit_date (``int``, *optional*): Date the message was last edited in Unix time. From 5efd608487f454efaf7a6939355eefd3f49acc10 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Nov 2018 17:40:37 +0100 Subject: [PATCH 7/7] Update Filters.chat docstrings --- pyrogram/client/filters/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 037e6bb9..77ebb771 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -281,6 +281,7 @@ class Filters: Args: chats (``int`` | ``str`` | ``list``): Pass one or more chat ids/usernames to filter chats. + For your personal cloud (Saved Messages) you can simply use “me” or “self”. Defaults to None (no chats). """