add deleting links excluding allowed
This commit is contained in:
+17
-11
@@ -10,7 +10,7 @@ import shelve
|
|||||||
from . import report
|
from . import report
|
||||||
from .query_log import logging
|
from .query_log import logging
|
||||||
from .me import get_me
|
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
|
from . import reminder
|
||||||
|
|
||||||
# https://core.telegram.org/bots/api Telegram Bot API
|
# 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:
|
def check_spam_list(type_message: types.Message) -> bool:
|
||||||
""" Check for mentioning unwanted persons in text. """
|
""" 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:
|
for phrase in unwanted_phrases:
|
||||||
if phrase in type_message.text.casefold():
|
if phrase in type_message.text.casefold():
|
||||||
return True
|
return True
|
||||||
@@ -83,16 +84,21 @@ def catch_videos(message: types.Message):
|
|||||||
chat_stats['Banned'] += 1
|
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:
|
def check_delete_list(type_message: types.Message) -> bool:
|
||||||
""" Check for unwanted text in message and delete. """
|
""" Check for URLs in message and delete. """
|
||||||
unwanted_phrases = ['t.me/']
|
if URL_RX.search(type_message.text) and check_no_allowed(ALLOWED_WORDS, type_message.text):
|
||||||
for phrase in unwanted_phrases:
|
return True
|
||||||
if phrase in type_message.text.casefold():
|
if type_message.entities:
|
||||||
return True
|
for entity in type_message.entities:
|
||||||
if type_message.entities:
|
if entity.url and check_no_allowed(ALLOWED_WORDS, entity.url):
|
||||||
for entity in type_message.entities:
|
return True
|
||||||
if entity.url and phrase in entity.url:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=check_delete_list)
|
@bot.message_handler(func=check_delete_list)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from telebot import TeleBot
|
from telebot import TeleBot
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
@@ -10,3 +11,7 @@ bot = TeleBot(TOKEN)
|
|||||||
ADMIN_ID = 280887861 # Rykov7
|
ADMIN_ID = 280887861 # Rykov7
|
||||||
PYTHONCHATRU = -1001338616632 # pythonchatru
|
PYTHONCHATRU = -1001338616632 # pythonchatru
|
||||||
TEST_CHAT = -1001622893830
|
TEST_CHAT = -1001622893830
|
||||||
|
|
||||||
|
URL_RX = re.compile(r'\w+\.\w+/\w+')
|
||||||
|
ALLOWED_WORDS = ['pastebin', 'github', 'google', 'nometa', 'python',
|
||||||
|
'stackoverflow', 'habr', 'medium']
|
||||||
|
|||||||
Reference in New Issue
Block a user