Add formating before check for bad word, sort bad words.

main
t 1 year ago
parent ffead28bd4
commit 09ca133722

@ -11,9 +11,9 @@ global db
####### CREATE DB IF NOT EXIST ####### CREATE DB IF NOT EXIST
if not os.path.exists('db.json'): if not os.path.exists('db.json'):
db = {"token": "None"} db = {'token': 'None'}
js = json.dumps(db, indent=2) js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile: with open('db.json', 'w') as outfile:
outfile.write(js) outfile.write(js)
print('Input token in "None" (db.json)') print('Input token in "None" (db.json)')
@ -28,7 +28,7 @@ def read_db():
def write_db(): def write_db():
global db global db
js = json.dumps(db, indent=2) js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile: with open('db.json', 'w') as outfile:
outfile.write(js) outfile.write(js)
#############TOKEN INIT##### #############TOKEN INIT#####
@ -39,10 +39,15 @@ bot = telebot.TeleBot(db['token'])
########## ALANYS WORD ##### ########## ALANYS WORD #####
from re import search, match from re import search, match, sub, compile
def is_bad(word, bad): def is_bad(word, bad):
# Agressive mode, causes false positives # Agressive mode, causes false positives
#res = search(bad, word) #res = search(bad, word)
# -М#ат$ => Мат
regex = compile('[^a-zA-Zа-яА-Я]')
word = regex.sub('', word)
res = match(bad, word) res = match(bad, word)
if res is not None: if res is not None:
return True return True
@ -53,8 +58,14 @@ def is_bad(word, bad):
def catch(message): def catch(message):
bad_list = ["бл.+ть","еб.+ть","пиз.+ец","х.+й","бл+.дь","п.+зда","бля","f.+ck","блят","s.+ck","ебу", "ебал", bad_list = ['х.+й', 'xуи', 'xyи', 'х', 'xyй', 'xуй', 'ху.', '.+хуё', 'xyu', 'xui', 'х', 'хй', 'поху',
"трах","eby"] 'бл.+ть', 'бля', 'блят',
'бл+.дь',
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ебан', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей',
'п.+зда', 'пиз.+ец', 'пизд', 'пизец', 'пздец', 'п.+здец', 'пизд',
'пид.+р', 'пидр',
'f.+ck', 's.+ck', 'fck', 'sck']
words = message.text.split() words = message.text.split()
bad_found = False bad_found = False
@ -69,7 +80,7 @@ def catch(message):
if bad_found: if bad_found:
bot.delete_message(message.chat.id, message.id) 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") bot.send_message(message.chat.id, f'Пользователь {telebot.util.user_link(message.from_user)} использовал непечатное выражение.', parse_mode='HTML')
@bot.message_handler() @bot.message_handler()
@ -80,7 +91,7 @@ def catch_edited_messages(message):
catch(message) catch(message)
''' #'''
while True: while True:
try: try:
bot.polling() bot.polling()
@ -90,3 +101,4 @@ while True:
pass pass
''' '''
bot.polling() bot.polling()
'''

Loading…
Cancel
Save