add whitelist users and whitelist ids
This commit is contained in:
+7
-5
@@ -8,7 +8,7 @@ from . import reminder
|
||||
from . import trolling
|
||||
from . import admin
|
||||
from . import report
|
||||
from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU
|
||||
from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU, WHITEUN, WHITEIDS
|
||||
from .me import get_me
|
||||
|
||||
# https://core.telegram.org/bots/api Telegram Bot API
|
||||
@@ -37,6 +37,7 @@ if trolling:
|
||||
|
||||
def check_spam_list(type_message: types.Message) -> bool:
|
||||
""" Check for mentioning unwanted persons in text. """
|
||||
if type_message.from_user.username not in WHITEUN and type_message.from_user.id not in WHITEIDS:
|
||||
unwanted_phrases = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/',
|
||||
'uclck.ru/']
|
||||
for phrase in unwanted_phrases:
|
||||
@@ -48,7 +49,7 @@ def check_spam_list(type_message: types.Message) -> bool:
|
||||
@bot.message_handler(func=check_spam_list)
|
||||
def moderate_messages(message: types.Message):
|
||||
""" Ban user and delete their message. """
|
||||
logging.warning(f'[BAN] {message.from_user.first_name} - {message.text}')
|
||||
logging.warning(f'[BAN] {message.from_user.id} {message.from_user.username} - {message.text}')
|
||||
bot.delete_message(message.chat.id, message.id)
|
||||
bot.ban_chat_member(message.chat.id, message.from_user.id)
|
||||
if message.chat.id == PYTHONCHATRU:
|
||||
@@ -67,7 +68,7 @@ def check_caption_spam_list(type_message: types.Message) -> bool:
|
||||
@bot.message_handler(func=check_caption_spam_list, content_types=['video'])
|
||||
def catch_videos(message: types.Message):
|
||||
"""Catch offensive videos"""
|
||||
logging.warning(f'[BAN] {message.from_user.first_name} - {message.video.file_name}')
|
||||
logging.warning(f'[BAN] {message.from_user.id} {message.from_user.first_name} - {message.video.file_name}')
|
||||
bot.delete_message(message.chat.id, message.id)
|
||||
bot.ban_chat_member(message.chat.id, message.from_user.id)
|
||||
with shelve.open('chat_stats') as chat_stats:
|
||||
@@ -83,13 +84,14 @@ def check_no_allowed(word_list, msg):
|
||||
|
||||
def check_delete_list(type_message: types.Message) -> bool:
|
||||
""" Check for URLs in message and delete. """
|
||||
if type_message.from_user.username not in WHITEUN and type_message.from_user.id not in WHITEIDS:
|
||||
if URL_RX.search(type_message.text) and check_no_allowed(ALLOWED_WORDS, type_message.text):
|
||||
logging.info(f'[DEL] {type_message.from_user.first_name} - {type_message.text}')
|
||||
logging.info(f'[DEL] {type_message.from_user.id} {type_message.from_user.first_name} - {type_message.text}')
|
||||
return True
|
||||
if type_message.entities:
|
||||
for entity in type_message.entities:
|
||||
if entity.url and check_no_allowed(ALLOWED_WORDS, entity.url):
|
||||
logging.info(f'[DEL] {type_message.from_user.first_name} - Entity ({entity.url})')
|
||||
logging.info(f'[DEL] {type_message.from_user.id} {type_message.from_user.first_name} - Entity ({entity.url})')
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ import os
|
||||
import re
|
||||
from telebot import TeleBot
|
||||
from dotenv import load_dotenv
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -14,3 +18,9 @@ PYTHONCHATRU = -1001338616632 # pythonchatru
|
||||
URL_RX = re.compile(r'\w+\.\w+/\w+')
|
||||
ALLOWED_WORDS = ['pastebin', 'github', 'google', 'nometa', 'python', 'django', 'flask', 'fastapi',
|
||||
'stackoverflow', 'habr', 'medium', 'youtube', 'stepik', 'telegraph']
|
||||
|
||||
WHITEUN = set(os.environ.get('whitelist', '<<<ERR_USRS').split(','))
|
||||
logging.warning(f'White users {WHITEUN}')
|
||||
|
||||
WHITEIDS = {int(i) for i in os.environ.get('whiteids', '<<<ERR_IDS').split(',')}
|
||||
logging.warning(f'White IDs {WHITEIDS}')
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ def create_report_text():
|
||||
top_users += f'\n {i + 1}. <a href="tg://user?id={user.id}">{name}</a> ({flooder["Count"]})'
|
||||
report = f"<code>Hello, World!</code> 🌍\n"
|
||||
if s['Banned'] or s['Deleted']:
|
||||
report += f"""<b>Заблокировано</b> ⛔
|
||||
report += f"""
|
||||
<b>Заблокировано</b> ⛔
|
||||
├ <b>Пользователей: </b>{s['Banned']}
|
||||
└ <b>Сообщений: </b>{s['Deleted']}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user