From 22eb42e1f362be05a2c9acb5aed3b01722f26145 Mon Sep 17 00:00:00 2001 From: Eric Solinas Date: Sat, 16 May 2020 12:24:14 +0200 Subject: [PATCH 1/3] Add Filter.linked_channel * filter messages coming from the channel connected to the chat * Update filters.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/client/filters/filters.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 83493965..d740d3c7 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -214,6 +214,10 @@ class Filters: from_scheduled = create(lambda _, m: bool(m.from_scheduled), "FromScheduledFilter") """Filter new automatically sent messages that were previously scheduled.""" + + # Messages from linked channels are forwarded automatically by Telegram and have no sender (from_user is None). + linked_channel = create(lambda _, m: bool(m.forward_from_chat and not m.from_user), "LinkedChannelFilter") + """Filter messages that are automatically forwarded from the linked channel to the group chat.""" @staticmethod def command( From 0c83fa09a6a6f2f8ea9d34ba461e7bc15f26b8fb Mon Sep 17 00:00:00 2001 From: demget <30910794+demget@users.noreply.github.com> Date: Sat, 16 May 2020 13:33:21 +0300 Subject: [PATCH 2/3] Add file_name param to file-related functions (#308) --- pyrogram/client/methods/messages/send_animation.py | 7 ++++++- pyrogram/client/methods/messages/send_audio.py | 7 ++++++- pyrogram/client/methods/messages/send_document.py | 7 ++++++- pyrogram/client/methods/messages/send_video.py | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 99e86fba..288ed04e 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -38,6 +38,7 @@ class SendAnimation(BaseClient): width: int = 0, height: int = 0, thumb: str = None, + file_name: str = None, disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, @@ -97,6 +98,10 @@ class SendAnimation(BaseClient): A thumbnail's width and height should not exceed 320 pixels. Thumbnails can't be reused and can be only uploaded as a new file. + file_name (``str``, *optional*): + File name of the animation sent. + Defaults to file's path basename. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -172,7 +177,7 @@ class SendAnimation(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(file_name=os.path.basename(animation)), + types.DocumentAttributeFilename(file_name=file_name or os.path.basename(animation)), types.DocumentAttributeAnimated() ] ) diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 2d34f861..e271d96c 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -37,6 +37,7 @@ class SendAudio(BaseClient): performer: str = None, title: str = None, thumb: str = None, + file_name: str = None, disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, @@ -94,6 +95,10 @@ class SendAudio(BaseClient): A thumbnail's width and height should not exceed 320 pixels. Thumbnails can't be reused and can be only uploaded as a new file. + file_name (``str``, *optional*): + File name of the audio sent. + Defaults to file's path basename. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -171,7 +176,7 @@ class SendAudio(BaseClient): performer=performer, title=title ), - types.DocumentAttributeFilename(file_name=os.path.basename(audio)) + types.DocumentAttributeFilename(file_name=file_name or os.path.basename(audio)) ] ) elif audio.startswith("http"): diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 182d2985..24a754f0 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -34,6 +34,7 @@ class SendDocument(BaseClient): thumb: str = None, caption: str = "", parse_mode: Union[str, None] = object, + file_name: str = None, disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, @@ -80,6 +81,10 @@ class SendDocument(BaseClient): Pass "html" to enable HTML-style parsing only. Pass None to completely disable style parsing. + file_name (``str``, *optional*): + File name of the document sent. + Defaults to file's path basename. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -146,7 +151,7 @@ class SendDocument(BaseClient): file=file, thumb=thumb, attributes=[ - types.DocumentAttributeFilename(file_name=os.path.basename(document)) + types.DocumentAttributeFilename(file_name=file_name or os.path.basename(document)) ] ) elif document.startswith("http"): diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index 8335b902..fc58aa98 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -37,6 +37,7 @@ class SendVideo(BaseClient): width: int = 0, height: int = 0, thumb: str = None, + file_name: str = None, supports_streaming: bool = True, disable_notification: bool = None, reply_to_message_id: int = None, @@ -93,6 +94,10 @@ class SendVideo(BaseClient): A thumbnail's width and height should not exceed 320 pixels. Thumbnails can't be reused and can be only uploaded as a new file. + file_name (``str``, *optional*): + File name of the video sent. + Defaults to file's path basename. + supports_streaming (``bool``, *optional*): Pass True, if the uploaded video is suitable for streaming. Defaults to True. @@ -169,7 +174,7 @@ class SendVideo(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(file_name=os.path.basename(video)) + types.DocumentAttributeFilename(file_name=file_name or os.path.basename(video)) ] ) elif video.startswith("http"): From 5b94c340c072382b686c1f90fdcc6bac4ce9d503 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 16 May 2020 14:40:22 +0200 Subject: [PATCH 3/3] Fix Filters.regex failing in case the value is None --- 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 d740d3c7..19218813 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -323,7 +323,8 @@ class Filters: else: raise ValueError("Regex filter doesn't work with {}".format(type(update))) - update.matches = list(flt.p.finditer(value)) or None + if value: + update.matches = list(flt.p.finditer(value)) or None return bool(update.matches)