You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.3 KiB

1 year ago
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'):
db = {'token': 'None'}
1 year ago
js = json.dumps(db, indent=2)
with open('db.json', 'w') as outfile:
1 year ago
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)
with open('db.json', 'w') as outfile:
1 year ago
outfile.write(js)
#############TOKEN INIT#####
read_db()
bot = telebot.TeleBot(db['token'])
########## ALANYS WORD #####
from re import search, match, sub, compile
def is_bad(word, bad, excepts):
#Replace spec.symbols
# Excepts
if word in excepts:
return False
# Agressive mode, causes false positives
#res = search(bad, word)
res = match(bad, word)
1 year ago
if res is not None:
return True
else:
return False
### TRANSLIT an OTHER ######
def rep(word):
rep = [['e','е'], ['a','а'], ['i','и'], ['t','т'], ['y','у'], ['u','у'], ['o','о'], ['d','д'], ['x','х'], ['t','т'], ['p','п'],
['r','р'], ['h','х'], ['b','б'], ['n','н'],
['🇽','х'], ['🇾','у'], ['🇹','т'], ['🇪','е'],
['','х'], ['','х'], ['','х'] ]
for i in rep:
word = word.replace(i[0], i[1])
print(word)
return word
1 year ago
####### CATCH BAD WORDS ####
def catch(message):
bad_list = ['х.+й', 'xуи', 'xyи', 'х', 'xyй', 'xуй', 'ху.', '.+хуё', 'xyu', 'xui', 'х', 'поху', '.уй', 'ах.ен', 'а.уе',
'бл.+ть', 'бля', 'бл.+т',
'бл+.дь',
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ебан', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей', 'ебу', 'ебл', 'еба',
'еб.+утые', 'е.+б.+утые', 'ебан', 'еб.+н', 'ебн', 'ёбн',
'пр..ба', '.б', 'у.б', '.блан',
'п.+зда', 'пиз.+ец', 'пизд', 'пизец', 'пздец', 'п.+здец', 'пизд',
'пид.+р', 'пидр',
'д.лб.+б',
'f.+ck', 's.+ck', 'fck', 'sck']
excepts = ['хороший']
1 year ago
words = message.text.split()
bad_found = False
for check in words:
# Mat -> Мат
check = rep(check)
# -М#ат$ => Мат
regex = compile('[^a-zA-Zа-яА-ЯЁё]')
check = regex.sub('', check)
1 year ago
if bad_found:
break
for bad in bad_list:
if is_bad(check.lower(), bad, excepts) == True:
#print(bad)
1 year ago
bad_found = True
break
if not bad_found:
for check in words:
check = rep(check)
regex = compile('[^a-zA-Zа-яА-ЯЁё]')
check = regex.sub('.', check)
if bad_found:
break
for bad in bad_list:
if is_bad(check.lower(), bad, excepts) == True:
#print(bad)
bad_found = True
break
1 year ago
if bad_found:
bot.delete_message(message.chat.id, message.id)
bot.send_message(message.chat.id, f'Пользователь {telebot.util.user_link(message.from_user)} использовал непечатное выражение.', parse_mode='HTML')
1 year ago
@bot.message_handler()
def catch_all_messages(message):
catch(message)
@bot.edited_message_handler()
def catch_edited_messages(message):
catch(message)
'''
1 year ago
while True:
try:
bot.polling()
except KeyboardInterrupt:
exit()
1 year ago
except:
pass
'''
bot.polling()
#'''