|
|
@ -1,15 +1,11 @@
|
|
|
|
|
|
|
|
import telebot # Telegram bot module
|
|
|
|
|
|
|
|
from re import match, compile # ANALYS WORD
|
|
|
|
|
|
|
|
from db import read_db, write_db # database functions
|
|
|
|
|
|
|
|
database = read_db()
|
|
|
|
|
|
|
|
bot = telebot.TeleBot(database['token'])
|
|
|
|
|
|
|
|
|
|
|
|
import telebot
|
|
|
|
|
|
|
|
import os
|
|
|
|
def is_bad(word, bad, excepts): # check bad words
|
|
|
|
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
|
|
|
|
# Replace spec.symbols
|
|
|
|
# Excepts
|
|
|
|
# Excepts
|
|
|
|
if word in excepts:
|
|
|
|
if word in excepts:
|
|
|
@ -22,29 +18,22 @@ def is_bad(word, bad, excepts):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
### TRANSLIT an OTHER ######
|
|
|
|
|
|
|
|
def rep(word):
|
|
|
|
def rep(word): # TRANSLIT an OTHER
|
|
|
|
rep = [['e', 'е'], ['a', 'а'], ['i', 'и'], ['t', 'т'], ['y', 'у'], ['u', 'у'], ['o', 'о'], ['d', 'д'], ['x', 'х'],
|
|
|
|
symbols = [['e', 'е'], ['a', 'а'], ['i', 'и'], ['t', 'т'], ['y', 'у'], ['u', 'у'], ['o', 'о'], ['d', 'д'], ['x', 'х'],
|
|
|
|
['t', 'т'], ['p', 'п'], ['r', 'р'], ['h', 'х'], ['b', 'б'], ['n', 'н'],
|
|
|
|
['t', 'т'], ['p', 'п'], ['r', 'р'], ['h', 'х'], ['b', 'б'], ['n', 'н'],
|
|
|
|
['🇽', 'х'], ['🇾', 'у'], ['🇹', 'т'], ['🇪', 'е'], ['❌', 'х'], ['✖', 'х'], ['❎', 'х']]
|
|
|
|
['🇽', 'х'], ['🇾', 'у'], ['🇹', 'т'], ['🇪', 'е'], ['❌', 'х'], ['✖', 'х'], ['❎', 'х']]
|
|
|
|
for i in rep:
|
|
|
|
for symbol in symbols:
|
|
|
|
word = word.replace(i[0], i[1])
|
|
|
|
word = word.replace(symbol[0], symbol[1])
|
|
|
|
return word
|
|
|
|
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):
|
|
|
|
def catch(message): # CATCH BAD WORDS
|
|
|
|
bad_list = ['ху.+й', 'х.+уй', 'xуи', 'xyи', 'хyи', 'xyй', 'xуй', 'ху.', '.+хуе', '.+хуё', 'xyu', 'xui', 'хyй',
|
|
|
|
bad_list = ['ху.+й', 'х.+уй', 'xуи', 'xyи', 'хyи', 'xyй', 'xуй', 'ху.', '.+хуе', '.+хуё', 'xyu', 'xui', 'хyй',
|
|
|
|
'поху', '.уй', 'ах.ен' , 'а.уе', '.+хуй', '.+хуй', 'хуя', '.+хуя',
|
|
|
|
'поху', '.уй', 'ах.ен', 'а.уе', '.+хуй', '.+хуй', 'хуя', '.+хуя',
|
|
|
|
'бл.+ть', 'бля', 'бл.+ть',
|
|
|
|
'бл.+ть', 'бля', 'бл.+ть', '.+бл+.дь+', '.+бл.+дь',
|
|
|
|
'.+бл+.дь+', '.+бл.+дь',
|
|
|
|
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей', 'ебу', 'ебл', 'еба',
|
|
|
|
'трах', 'еб.+ть', 'ебу', 'ебал', '..ебен', 'ёбан', 'ебть', 'eby', '..ебись', 'уеб', 'уёб', 'ебей', 'ебу', 'ебл', 'еба',
|
|
|
|
'.+ебн.+т.+', '.+еб.ть', 'ебо', '.+ебо', '.+еба', '.+ёбы', 'еби.+', 'ёба.+', 'ебля', 'ебё.+', 'заеб', 'заеб.+', 'заёб',
|
|
|
|
'.+ебн.+т.+', '.+еб.ть', 'ебо', '.+ебо', '.+еба', '.+ёбы', 'еби.+', 'ёба.+', 'ебля', 'ебё.+', 'заеб', 'заеб.+', 'заёб',
|
|
|
|
|
|
|
|
'.+заеб', '.+заёб', 'заеб.+', 'заёб.+', 'ёбск', '.+ебуч.+',
|
|
|
|
'.+заеб', '.+заёб', 'заеб.+', 'заёб.+', 'ёбск', '.+ебуч.+',
|
|
|
|
'еб.+утые', 'е.+б.+утые', 'ебан', 'еб.+н', 'ебн', 'ёбн', '.+ёбка', '.+ебка',
|
|
|
|
'еб.+утые', 'е.+б.+утые', 'ебан', 'еб.+н', 'ебн', 'ёбн', '.+ёбка', '.+ебка',
|
|
|
|
'пр..ба', '.б.л', 'у.б', '.блан',
|
|
|
|
'пр..ба', '.б.л', 'у.б', '.блан',
|
|
|
@ -65,7 +54,7 @@ def catch(message):
|
|
|
|
if bad_found:
|
|
|
|
if bad_found:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
for bad in bad_list:
|
|
|
|
for bad in bad_list:
|
|
|
|
if is_bad(check.lower(), bad, excepts) == True:
|
|
|
|
if is_bad(check.lower(), bad, excepts):
|
|
|
|
bad_found = True
|
|
|
|
bad_found = True
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if not bad_found:
|
|
|
|
if not bad_found:
|
|
|
@ -76,57 +65,71 @@ def catch(message):
|
|
|
|
if bad_found:
|
|
|
|
if bad_found:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
for bad in bad_list:
|
|
|
|
for bad in bad_list:
|
|
|
|
if is_bad(check.lower(), bad, excepts) == True:
|
|
|
|
if is_bad(check.lower(), bad, excepts):
|
|
|
|
bad_found = True
|
|
|
|
bad_found = True
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if bad_found:
|
|
|
|
if bad_found:
|
|
|
|
db = read_db()
|
|
|
|
database = read_db()
|
|
|
|
chat_id = str(message.chat.id)
|
|
|
|
chat_id = str(message.chat.id)
|
|
|
|
user_id = str(message.from_user.id)
|
|
|
|
user_id = str(message.from_user.id)
|
|
|
|
username = str(message.from_user.username)
|
|
|
|
if chat_id not in database:
|
|
|
|
if chat_id not in db:
|
|
|
|
database[chat_id] = {}
|
|
|
|
db[chat_id] = {}
|
|
|
|
if user_id not in database[chat_id]:
|
|
|
|
if user_id not in db[chat_id]:
|
|
|
|
database[chat_id][user_id] = {}
|
|
|
|
db[chat_id][user_id] = {}
|
|
|
|
database[chat_id][user_id]["lunch"] = 0
|
|
|
|
db[chat_id][user_id]["lunch"] = 0
|
|
|
|
if user_id in database[chat_id]:
|
|
|
|
if username not in db[chat_id][user_id]:
|
|
|
|
database[chat_id][user_id]["lunch"] += 1
|
|
|
|
db[chat_id][user_id]["username"] = username
|
|
|
|
bot.send_message(message.chat.id,
|
|
|
|
if user_id in db[chat_id]:
|
|
|
|
f'<a href="tg://user?id={user_id}">Пользователь</a> использовал непечатное выражение.\n'
|
|
|
|
db[chat_id][user_id]["lunch"] += 1
|
|
|
|
f'Кол-во потерянных обедов: {database[chat_id][user_id]["lunch"]}',
|
|
|
|
#bot.delete_message(message.chat.id, message.id)
|
|
|
|
parse_mode='HTML')
|
|
|
|
# bot.send_message(message.chat.id,
|
|
|
|
write_db(database)
|
|
|
|
# f'Пользователь [{telebot.util.user_link(message.from_user)}] использовал непечатное выражение.\n'\
|
|
|
|
|
|
|
|
# f'Кол-во потерянных обедов пользователя: {db[chat_id][user_id]}',
|
|
|
|
|
|
|
|
# parse_mode='HTML')
|
|
|
|
@bot.message_handler(commands=['stats']) # stats
|
|
|
|
write_db(db)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['stats'])
|
|
|
|
|
|
|
|
def send_stats(message):
|
|
|
|
def send_stats(message):
|
|
|
|
db = read_db()
|
|
|
|
database = read_db()
|
|
|
|
chat_id = str(message.chat.id)
|
|
|
|
chat_id = str(message.chat.id)
|
|
|
|
user_id = str(message.from_user.id)
|
|
|
|
user_id = str(message.from_user.id)
|
|
|
|
#if str(message.from_user.id)==db[str(message.chat.id)]:
|
|
|
|
if user_id not in database[chat_id]:
|
|
|
|
bot.send_message(chat_id, f"Количество потраченных обедов [{telebot.util.user_link(message.from_user)}]: {db[chat_id][user_id]['lunch']}{'😿' if db[chat_id][user_id]['lunch'] > 0 else '😻'}", parse_mode='HTML')
|
|
|
|
database[chat_id] = {}
|
|
|
|
|
|
|
|
database[chat_id][user_id] = {}
|
|
|
|
|
|
|
|
database[chat_id][user_id]["lunch"] = 0
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
lunch_count = database[chat_id][user_id]["lunch"]
|
|
|
|
|
|
|
|
if lunch_count > 0:
|
|
|
|
|
|
|
|
if lunch_count == 1: obed = "обеда"
|
|
|
|
|
|
|
|
else: obed = "обедов"
|
|
|
|
|
|
|
|
bot.send_message(chat_id, f'<a href="tg://user?id={user_id}">Вы</a> убили {database[chat_id][user_id]["lunch"]} {obed}! Ужас...', parse_mode='HTML')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
bot.send_message(chat_id, f'<a href="tg://user?id={user_id}">Вы</a> не убили ни одного обеда сегодня, поздравляю!', parse_mode='HTML')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler()
|
|
|
|
@bot.message_handler()
|
|
|
|
def catch_all_messages(message):
|
|
|
|
def catch_all_messages(message):
|
|
|
|
catch(message)
|
|
|
|
catch(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.edited_message_handler()
|
|
|
|
@bot.edited_message_handler()
|
|
|
|
def catch_edited_messages(message):
|
|
|
|
def catch_edited_messages(message):
|
|
|
|
catch(message)
|
|
|
|
catch(message)
|
|
|
|
|
|
|
|
|
|
|
|
mod = 1
|
|
|
|
|
|
|
|
if mod == 1:
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
bot.polling()
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
elif mod == 2:
|
|
|
|
|
|
|
|
bot.polling()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
mod = 1
|
|
|
|
|
|
|
|
if mod == 1:
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
bot.polling()
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
elif mod == 2:
|
|
|
|
|
|
|
|
bot.polling()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
main()
|
|
|
|