add deleting links excluding allowed

This commit is contained in:
Rykov7
2022-11-12 15:37:48 +03:00
parent abb787d6ef
commit 7fa7400be3
2 changed files with 23 additions and 12 deletions
+13 -7
View File
@@ -10,7 +10,7 @@ import shelve
from . import report
from .query_log import logging
from .me import get_me
from .config import bot, ADMIN_ID, TOKEN, PYTHONCHATRU
from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU
from . import reminder
# https://core.telegram.org/bots/api Telegram Bot API
@@ -42,7 +42,8 @@ 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 = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/']
unwanted_phrases = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/',
'uclck.ru/']
for phrase in unwanted_phrases:
if phrase in type_message.text.casefold():
return True
@@ -83,15 +84,20 @@ def catch_videos(message: types.Message):
chat_stats['Banned'] += 1
def check_no_allowed(word_list, msg):
for word in word_list:
if word in msg.casefold():
return False
return True
def check_delete_list(type_message: types.Message) -> bool:
""" Check for unwanted text in message and delete. """
unwanted_phrases = ['t.me/']
for phrase in unwanted_phrases:
if phrase in type_message.text.casefold():
""" Check for URLs in message and delete. """
if URL_RX.search(type_message.text) and check_no_allowed(ALLOWED_WORDS, type_message.text):
return True
if type_message.entities:
for entity in type_message.entities:
if entity.url and phrase in entity.url:
if entity.url and check_no_allowed(ALLOWED_WORDS, entity.url):
return True
+5
View File
@@ -1,4 +1,5 @@
import os
import re
from telebot import TeleBot
from dotenv import load_dotenv
@@ -10,3 +11,7 @@ bot = TeleBot(TOKEN)
ADMIN_ID = 280887861 # Rykov7
PYTHONCHATRU = -1001338616632 # pythonchatru
TEST_CHAT = -1001622893830
URL_RX = re.compile(r'\w+\.\w+/\w+')
ALLOWED_WORDS = ['pastebin', 'github', 'google', 'nometa', 'python',
'stackoverflow', 'habr', 'medium']