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"} js = json.dumps(db, indent=2) with open("db.json", "w") as outfile: 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: outfile.write(js) #############TOKEN INIT##### read_db() bot = telebot.TeleBot(db['token']) ########## ALANYS WORD ##### from re import search, match def is_bad(word, bad): res = search(bad, word) if res is not None: return True else: return False ####### CATCH BAD WORDS #### def catch(message): bad_list = ["бл.+ть","еб.+ть","пиз.+ец","х.+й","бл+.дь","п.+зда","бля","f.+ck","блят","s.+ck","ебу", "ебал", "трах","eby"] words = message.text.split() bad_found = False for check in words: if bad_found: break for bad in bad_list: if is_bad(check.lower(), bad) == True: print(bad) bad_found = True break 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.message_handler() def catch_all_messages(message): catch(message) @bot.edited_message_handler() def catch_edited_messages(message): catch(message) while True: try: bot.polling() except: pass