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