From 6ee780542fb42742d867a5831e43b0a57ee480bc Mon Sep 17 00:00:00 2001 From: J-Rios Date: Mon, 13 Jun 2022 21:20:01 +0200 Subject: [PATCH] Fix ignore URL protection for channel post discussion group messages --- sources/join_captcha_bot.py | 11 ++++++++++- sources/tlgbotutils.py | 11 +++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sources/join_captcha_bot.py b/sources/join_captcha_bot.py index 6fe5430..ee6efed 100644 --- a/sources/join_captcha_bot.py +++ b/sources/join_captcha_bot.py @@ -71,7 +71,8 @@ from tlgbotutils import ( tlg_answer_callback_query, tlg_delete_msg, tlg_edit_msg_media, tlg_ban_user, tlg_kick_user, tlg_user_is_admin, tlg_leave_chat, tlg_restrict_user, tlg_is_valid_user_id_or_alias, tlg_is_valid_group, - tlg_alias_in_string, tlg_extract_members_status_change + tlg_alias_in_string, tlg_extract_members_status_change, + tlg_is_a_channel_msg_on_discussion_group ) from constants import ( @@ -985,6 +986,10 @@ def msg_notext(update: Update, context: CallbackContext): # Ignore if message comes from a channel if chat.type == "channel": return + # Ignore if message is a channel post automatically forwarded to the + # connected discussion group + if tlg_is_a_channel_msg_on_discussion_group(update_msg): + return # Ignore if captcha protection is not enable in this chat captcha_enable = get_chat_config(chat_id, "Enabled") if not captcha_enable: @@ -1041,6 +1046,10 @@ def msg_nocmd(update: Update, context: CallbackContext): # Ignore if message comes from a channel if chat.type == "channel": return + # Ignore if message is a channel post automatically forwarded to the + # connected discussion group + if tlg_is_a_channel_msg_on_discussion_group(update_msg): + return # Ignore if captcha protection is not enable in this chat captcha_enable = get_chat_config(chat_id, "Enabled") if not captcha_enable: diff --git a/sources/tlgbotutils.py b/sources/tlgbotutils.py index be6fefb..a1a9341 100644 --- a/sources/tlgbotutils.py +++ b/sources/tlgbotutils.py @@ -10,9 +10,9 @@ Author: Creation date: 02/11/2020 Last modified date: - 06/06/2022 + 13/06/2022 Version: - 1.1.3 + 1.1.4 ''' ############################################################################### @@ -307,6 +307,13 @@ def tlg_user_is_admin(bot, user_id, chat_id, timeout=None): return False +def tlg_is_a_channel_msg_on_discussion_group(msg): + '''Check if a Telegram message is a channel publish send to linked + discussion group of that group.''' + is_automatic_forward = getattr(msg, "is_automatic_forward", None) + return is_automatic_forward + + def tlg_get_chat_type(bot, chat_id_or_alias, timeout=None): '''Telegram check if a chat exists and what type it is (user, group, ''' '''channel).'''