From 2219fa89792eafecd1bf27a05bed5b8cc1498f26 Mon Sep 17 00:00:00 2001 From: J-Rios Date: Thu, 30 Jun 2022 21:14:35 +0200 Subject: [PATCH] Deny and remove forwarded msgs from doing captcha users --- sources/constants.py | 6 +++--- sources/join_captcha_bot.py | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sources/constants.py b/sources/constants.py index 7d3881a..486db38 100644 --- a/sources/constants.py +++ b/sources/constants.py @@ -10,9 +10,9 @@ Author: Creation date: 09/09/2018 Last modified date: - 07/06/2022 + 30/06/2022 Version: - 1.26.3 + 1.26.4 ''' ############################################################################### @@ -290,7 +290,7 @@ CONST = { "DEV_DONATION_ADDR": "https://www.buymeacoffee.com/joincaptchabot", # Bot version - "VERSION": "1.26.3 (07/06/2022)" + "VERSION": "1.26.4 (30/06/2022)" } # Supported languages list diff --git a/sources/join_captcha_bot.py b/sources/join_captcha_bot.py index 0d58202..90d68c6 100644 --- a/sources/join_captcha_bot.py +++ b/sources/join_captcha_bot.py @@ -12,9 +12,9 @@ Author: Creation date: 09/09/2018 Last modified date: - 07/06/2022 + 30/06/2022 Version: - 1.26.3 + 1.26.4 ''' ############################################################################### @@ -1117,6 +1117,20 @@ def msg_nocmd(update: Update, context: CallbackContext): lang = get_chat_config(chat_id, "Language") rm_result_msg = get_chat_config(chat_id, "Rm_Result_Msg") captcha_mode = new_users[chat_id][user_id]["join_data"]["captcha_mode"] + # Check for forwarded messages and delete it + forward_from = getattr(update_msg, "forward_from", None) + forward_from_chat = getattr(update_msg, "forward_from_chat", None) + if (forward_from is not None) or (forward_from_chat is not None): + printts("[{}] Spammer detected: {}.".format(chat_id, user_name)) + printts("[{}] Removing forwarded msg: {}.".format(chat_id, msg_text)) + delete_result = tlg_delete_msg(bot, chat_id, msg_id) + if delete_result["error"] == "": + printts("Message removed.") + elif delete_result["error"] == "Message can't be deleted": + printts("No rights to remove msg.") + else: + printts("Message can't be deleted.") + return # Check for Spam (check if the message contains any URL or alias) has_url = re.findall(CONST["REGEX_URLS"], msg_text) has_alias = tlg_alias_in_string(msg_text)