2023-10-14 22:54:06 +00:00
|
|
|
import telebot
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
from telebot import types,util
|
|
|
|
|
|
|
|
global db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####### CREATE DB IF NOT EXIST
|
|
|
|
|
|
|
|
if not os.path.exists('db.json'):
|
2023-10-19 21:03:14 +00:00
|
|
|
db = {'token': 'None'}
|
2023-10-14 22:54:06 +00:00
|
|
|
js = json.dumps(db, indent=2)
|
2023-10-19 21:03:14 +00:00
|
|
|
with open('db.json', 'w') as outfile:
|
2023-10-14 22:54:06 +00:00
|
|
|
outfile.write(js)
|
|
|
|
|
|
|
|
print('Input token in "None" (db.json)')
|
|
|
|
exit()
|
|
|
|
|
|
|
|
############WORK WITH DBs##########
|
|
|
|
|
|
|
|
def read_db():
|
|
|
|
global db
|
|
|
|
with open('db.json', 'r') as openfile:
|
|
|
|
db = json.load(openfile)
|
|
|
|
def write_db():
|
|
|
|
global db
|
|
|
|
js = json.dumps(db, indent=2)
|
2023-10-19 21:03:14 +00:00
|
|
|
with open('db.json', 'w') as outfile:
|
2023-10-14 22:54:06 +00:00
|
|
|
outfile.write(js)
|
|
|
|
|
|
|
|
#############TOKEN INIT#####
|
|
|
|
|
|
|
|
read_db()
|
|
|
|
bot = telebot.TeleBot(db['token'])
|
|
|
|
|
|
|
|
|
|
|
|
########## ALANYS WORD #####
|
|
|
|
|
2023-10-19 21:03:14 +00:00
|
|
|
from re import search, match, sub, compile
|
2023-11-09 20:15:22 +00:00
|
|
|
def is_bad(word, bad, excepts):
|
|
|
|
# Excepts
|
|
|
|
if word in excepts:
|
|
|
|
return False
|
|
|
|
|
2023-10-15 17:51:00 +00:00
|
|
|
# Agressive mode, causes false positives
|
|
|
|
#res = search(bad, word)
|
|
|
|
res = match(bad, word)
|
2023-10-14 22:54:06 +00:00
|
|
|
if res is not None:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
####### CATCH BAD WORDS ####
|
|
|
|
|
|
|
|
|
|
|
|
def catch(message):
|
2023-10-19 21:03:14 +00:00
|
|
|
bad_list = ['х.+й', 'xуи', 'xyи', 'хyи', 'xyй', 'xуй', 'ху.', '.+хуё', 'xyu', 'xui', 'хyй', 'хй', 'поху',
|
|
|
|
'бл.+ть', 'бля', 'блят',
|
|
|
|
'бл+.дь',
|
|
|
|
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ебан', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей',
|
|
|
|
'п.+зда', 'пиз.+ец', 'пизд', 'пизец', 'пздец', 'п.+здец', 'пизд',
|
|
|
|
'пид.+р', 'пидр',
|
2023-11-09 20:15:22 +00:00
|
|
|
'д.лб.+б',
|
2023-10-19 21:03:14 +00:00
|
|
|
'f.+ck', 's.+ck', 'fck', 'sck']
|
|
|
|
|
2023-11-09 20:15:22 +00:00
|
|
|
excepts = ['хороший']
|
|
|
|
|
2023-10-14 22:54:06 +00:00
|
|
|
words = message.text.split()
|
|
|
|
|
|
|
|
bad_found = False
|
|
|
|
for check in words:
|
2023-11-09 20:15:22 +00:00
|
|
|
# -М#ат$ => Мат
|
|
|
|
regex = compile('[^a-zA-Zа-яА-ЯЁё]')
|
|
|
|
check = regex.sub('', check)
|
2023-10-14 22:54:06 +00:00
|
|
|
if bad_found:
|
|
|
|
break
|
|
|
|
for bad in bad_list:
|
2023-11-09 20:15:22 +00:00
|
|
|
if is_bad(check.lower(), bad, excepts) == True:
|
2023-10-14 22:54:06 +00:00
|
|
|
print(bad)
|
|
|
|
bad_found = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if bad_found:
|
|
|
|
bot.delete_message(message.chat.id, message.id)
|
2023-10-19 21:03:14 +00:00
|
|
|
bot.send_message(message.chat.id, f'Пользователь {telebot.util.user_link(message.from_user)} использовал непечатное выражение.', parse_mode='HTML')
|
2023-10-14 22:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler()
|
|
|
|
def catch_all_messages(message):
|
|
|
|
catch(message)
|
|
|
|
@bot.edited_message_handler()
|
|
|
|
def catch_edited_messages(message):
|
|
|
|
catch(message)
|
|
|
|
|
|
|
|
|
2023-10-19 21:03:14 +00:00
|
|
|
#'''
|
2023-10-14 22:54:06 +00:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
bot.polling()
|
2023-10-15 17:51:00 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
exit()
|
2023-10-14 22:54:06 +00:00
|
|
|
except:
|
|
|
|
pass
|
2023-10-15 17:51:00 +00:00
|
|
|
'''
|
|
|
|
bot.polling()
|
2023-10-19 21:03:14 +00:00
|
|
|
'''
|