ramjm 7 months ago
parent 81f29dc9f8
commit 0b2b98209e

20
db.py

@ -0,0 +1,20 @@
####### CREATE DB IF NOT EXIST
import os, json
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():
with open('db.json', 'r') as openfile:
db = json.load(openfile)
return db
def write_db(db):
js = json.dumps(db, indent=2)
with open('db.json', 'w') as outfile:
outfile.write(js)

@ -0,0 +1,128 @@
import telebot
import os
import json
from telebot import types, util
#############TOKEN INIT#####
from db import *
db = 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)
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])
return word
####### SEND MESSAGE #######
def send_message(user_id ,message):
bot.send_message(user_id,
message,
parse_mode='HTML')
####### CATCH BAD WORDS ####
def catch(message):
bad_list = ['ху.+й', 'х.+уй', 'xуи', 'xyи', 'х', 'xyй', 'xуй', 'ху.', '.+хуе', '.+хуё', 'xyu', 'xui', 'х',
'поху', '.уй', 'ах.ен' , 'а.уе', '.+хуй', '.+хуй', 'хуя', '.+хуя',
'бл.+ть', 'бля', 'бл.+ть',
'.+бл+.дь+', '.+бл.+дь',
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей', 'ебу', 'ебл', 'еба',
'.+ебн.+т.+', '.+еб.ть', 'ебо', '.+ебо', '.+еба', '.+ёбы', 'еби.+', 'ёба.+', 'ебля', 'ебё.+', 'заеб', 'заеб.+', 'заёб',
'.+заеб', '.+заёб', 'заеб.+', 'заёб.+', 'ёбск', '.+ебуч.+',
'еб.+утые', 'е.+б.+утые', 'ебан', 'еб.+н', 'ебн', 'ёбн', '.+ёбка', '.+ебка',
'пр..ба', '.б', 'у.б', '.блан',
'.+пизд', 'пизец', 'пздец', 'п.+здец', 'пизд', '.+пизж.+',
'пид.+р', 'пидр',
'д.лб.+б',
'f.+ck', 's.+ck', 'fck', 'sck']
excepts = ['хороший', 'хороший.', 'убил', 'убил.']
words = message.text.split()
bad_found = False
for check in words:
# Mat -> Мат
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:
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:
bad_found = True
break
if bad_found:
db = read_db()
chat_id = str(message.chat.id)
user_id = str(message.from_user.id)
if chat_id not in db:
db[chat_id] = {}
if user_id not in db[chat_id]:
db[chat_id][user_id] = 1
elif user_id in db[chat_id]:
db[chat_id][user_id] += 1
#bot.delete_message(message.chat.id, message.id)
bot.send_message(message.chat.id,
f'Пользователь {telebot.util.user_link(message.from_user)} использовал непечатное выражение.\n'\
f'Кол-во потерянных обедов: {db[chat_id][user_id]}',
parse_mode='HTML')
write_db(db)
@bot.message_handler(commands=['stats'])
def send_stats(message):
db = read_db()
chat_id = str(message.chat.id)
user_id = str(message.from_user.id)
#if str(message.from_user.id)==db[str(message.chat.id)]:
bot.send_message(chat_id, f"Count of lunchs of USER [{telebot.util.user_link(message.from_user)}]: {db[chat_id][user_id]}", parse_mode='HTML')
@bot.message_handler()
def catch_all_messages(message):
catch(message)
@bot.edited_message_handler()
def catch_edited_messages(message):
catch(message)
mod = 2
if mod == 1:
while True:
try:
bot.polling()
except KeyboardInterrupt:
exit()
except:
pass
elif mod == 2:
bot.polling()
else:
exit()

@ -0,0 +1,22 @@
from datetime import datetime
import time
import telebot
from db import *
db = read_db()
bot = telebot.TeleBot(db['token'])
while True:
now = datetime.now()
current_time = now.strftime("%H:%M")
if current_time == "16:10":
db = read_db()
for i in db:
if i != "token" and db[i] != 0:
text = ''
for j in i:
text += f"{db[i][j]}\n"
db[i][j] = 0
write_db(db)
bot.send_message(int(j),
text,
parse_mode='HTML')
time.sleep(61)
Loading…
Cancel
Save