From 1b6a6d2d842704b1abdb60d1fa569e71a57d6947 Mon Sep 17 00:00:00 2001 From: Rykov7 Date: Wed, 2 Nov 2022 09:27:18 +0300 Subject: [PATCH] add checking url entities in message --- app/bot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/bot.py b/app/bot.py index 005626f..603a6c6 100644 --- a/app/bot.py +++ b/app/bot.py @@ -40,7 +40,7 @@ def wait_for_readers(action, chat_id, msg_id): def check_spam_list(type_message: types.Message) -> bool: """ Check for mentioning unwanted persons in text. """ - unwanted_phrases = ['https://tg.sv/', 'https://goo.by/', '🍀GREEN ROOM🍀'] + unwanted_phrases = ['tg.sv', 'goo.by', '🍀GREEN ROOM🍀'] for phrase in unwanted_phrases: if phrase in type_message.text.casefold(): return True @@ -59,10 +59,13 @@ def moderate_messages(message: types.Message): def check_delete_list(type_message: types.Message) -> bool: """ Check for unwanted text in message and delete. """ - unwanted_phrases = ['https://t.me/'] + unwanted_phrases = ['t.me'] for phrase in unwanted_phrases: if phrase in type_message.text.casefold(): return True + for entity in type_message.entities: + if phrase in entity.url: + return True @bot.message_handler(func=check_delete_list, content_types=['text'])