|
|
@ -2,44 +2,85 @@ import telebot
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
global db
|
|
|
|
########### Работа с БД ##########
|
|
|
|
|
|
|
|
|
|
|
|
########### CREATE DB IF NOT EXIST
|
|
|
|
from db import *
|
|
|
|
|
|
|
|
raw_db = read_db()
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# db = {
|
|
|
|
# raw_db = {
|
|
|
|
# "Anon": {"id": 2045634, channel: "AnotherUser", blocks: [5375652, 436432], avatar: "♿️", pkey: "fuD2d", keys: {AnotherUser: "dDH73s"}},
|
|
|
|
# "Anon": {"id": 2045634, pkey: "fuD2d", channel: "AnotherUser", avatar: "♿️", blocks: [5375652, 436432], keys: {AnotherUser: "dDH73s"}},
|
|
|
|
# 2045634: "Anon"
|
|
|
|
# "2045634": "Anon"
|
|
|
|
#}
|
|
|
|
# }
|
|
|
|
# Невозможно хешировать айди - это всё ломает
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Первая строка - информация о пользователе (айди, канал, блокнутые пользователи)
|
|
|
|
# Первая строка - информация о пользователе (айди, канал, блокнутые пользователи)
|
|
|
|
# Вторая строчка - для отправки сообщения и блокировки
|
|
|
|
# Вторая строчка - для отправки сообщения и блокировки
|
|
|
|
# keys - ключи , pkey - личный ключ
|
|
|
|
# keys - ключи , pkey - личный ключ
|
|
|
|
|
|
|
|
|
|
|
|
############WORK WITH DBs##########
|
|
|
|
def is_num(str):
|
|
|
|
|
|
|
|
try:
|
|
|
|
from db import *
|
|
|
|
int(str)
|
|
|
|
db = read_db()
|
|
|
|
return True
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Класс пользователя
|
|
|
|
|
|
|
|
class user_:
|
|
|
|
|
|
|
|
def __init__(self, id, pkey, channel = None, avatar = "♿️", blocks = [], keys = {}):
|
|
|
|
|
|
|
|
self.id = id
|
|
|
|
|
|
|
|
self.channel = channel
|
|
|
|
|
|
|
|
self.avatar = avatar
|
|
|
|
|
|
|
|
self.blocks = blocks
|
|
|
|
|
|
|
|
self.pkey = pkey
|
|
|
|
|
|
|
|
self.keys = keys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Загружаем в формат
|
|
|
|
|
|
|
|
# db = {
|
|
|
|
|
|
|
|
# "Anon": user.*,
|
|
|
|
|
|
|
|
# "2045634": "Anon"
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Загружаем
|
|
|
|
|
|
|
|
def load():
|
|
|
|
|
|
|
|
raw_db = read_db()
|
|
|
|
|
|
|
|
db = {}
|
|
|
|
|
|
|
|
for i in raw_db:
|
|
|
|
|
|
|
|
if is_num(i) == True:
|
|
|
|
|
|
|
|
db[i] = raw_db[i]
|
|
|
|
|
|
|
|
elif "token" == i:
|
|
|
|
|
|
|
|
db["token"] = raw_db["token"]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
id, pkey, channel, avatar, blocks, keys = raw_db[i]["id"], raw_db[i]["pkey"], raw_db[i]["channel"], raw_db[i]["avatar"], raw_db[i]["blocks"], raw_db[i]["keys"],
|
|
|
|
|
|
|
|
user = user_(id, pkey, channel, avatar, blocks, keys)
|
|
|
|
|
|
|
|
db[i] = user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db = load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Сохраняем
|
|
|
|
|
|
|
|
def save(db):
|
|
|
|
|
|
|
|
raw_db = {}
|
|
|
|
|
|
|
|
for i in db:
|
|
|
|
|
|
|
|
if is_num(i) == True:
|
|
|
|
|
|
|
|
raw_db[i] = db[i]
|
|
|
|
|
|
|
|
elif "token" == i:
|
|
|
|
|
|
|
|
raw_db["token"] = db["token"]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raw_db[i] = {"id": db[i].id, "pkey": db[i].pkey, "channel": db[i].channel, "avatar": db[i].avatar, "blocks": db[i].blocks, "keys": db[i].keys}
|
|
|
|
|
|
|
|
write_db(raw_db)
|
|
|
|
|
|
|
|
|
|
|
|
###### WORK WITH HASHES ##########
|
|
|
|
####### Работа с хэшем ###########
|
|
|
|
|
|
|
|
|
|
|
|
from hash import hash
|
|
|
|
from hash import hash
|
|
|
|
from random import randint
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
|
|
|
|
################ TOKEN INIT ######
|
|
|
|
##### Инициализация токена #######
|
|
|
|
|
|
|
|
|
|
|
|
bot = telebot.TeleBot(db['token'])
|
|
|
|
bot = telebot.TeleBot(raw_db['token'])
|
|
|
|
|
|
|
|
|
|
|
|
##################CATCH ERRORS####
|
|
|
|
########## Ловим ошибки ##########
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
@ -66,20 +107,52 @@ def catch_error(message, err_type = None):
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Небольшие функции ####
|
|
|
|
|
|
|
|
|
|
|
|
def is_auth(message):
|
|
|
|
def is_auth(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
if str(message.chat.id) in db:
|
|
|
|
if str(message.chat.id) in db:
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message,"Извините, но Вы не авторизованы.")
|
|
|
|
bot.reply_to(message,"Извините, но Вы не авторизованы.\n\n/reg ник")
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
catch_error(message)
|
|
|
|
catch_error(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Регулярные выражения
|
|
|
|
|
|
|
|
from re import search, match, sub, compile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def nick_ok(message, nick):
|
|
|
|
|
|
|
|
if len(nick) > 30:
|
|
|
|
|
|
|
|
bot.reply_to(message,"Слишком длинный ник, попробуйте короче.")
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
if is_num(nick):
|
|
|
|
|
|
|
|
bot.reply_to(message,"Ник должен содержать хоть 1 букву, попробуйте ещё раз.")
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
en = True
|
|
|
|
|
|
|
|
ru = True
|
|
|
|
|
|
|
|
# Если только английский
|
|
|
|
|
|
|
|
regex = compile('[^a-zA-Z0-9]')
|
|
|
|
|
|
|
|
check = regex.sub('', nick)
|
|
|
|
|
|
|
|
if check != nick:
|
|
|
|
|
|
|
|
en = False
|
|
|
|
|
|
|
|
# Если только русский
|
|
|
|
|
|
|
|
regex = compile('[^а-яА-ЯЁё0-9]')
|
|
|
|
|
|
|
|
check = regex.sub('', nick)
|
|
|
|
|
|
|
|
if check != nick:
|
|
|
|
|
|
|
|
ru = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if en == False and ru == False:
|
|
|
|
|
|
|
|
bot.reply_to(message,"Нельзя смешивать алфавиты и ставить спец.-символы, попробуйте ещё раз")
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
############## MAIN
|
|
|
|
############## MAIN
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['start'])
|
|
|
|
@bot.message_handler(commands=['start', 'help'])
|
|
|
|
def start(message):
|
|
|
|
def start(message):
|
|
|
|
bot.reply_to(message, f"""Приветствую, это бот для анонимного общения.
|
|
|
|
bot.reply_to(message, f"""Приветствую, это бот для анонимного общения.
|
|
|
|
Главное - выполняет свою функцию без рекламы, без платы и без слежки.
|
|
|
|
Главное - выполняет свою функцию без рекламы, без платы и без слежки.
|
|
|
@ -88,7 +161,7 @@ def start(message):
|
|
|
|
/reg ЛюбойНикнейм
|
|
|
|
/reg ЛюбойНикнейм
|
|
|
|
Установка адресата - { telebot.formatting.hcode(":НикАдресата") }
|
|
|
|
Установка адресата - { telebot.formatting.hcode(":НикАдресата") }
|
|
|
|
|
|
|
|
|
|
|
|
Исходный код: https://gitea.gulyaipole.fun/justuser/just_anonchat
|
|
|
|
Исходный код: https://gitea.404.mn/justuser/just_anonchat
|
|
|
|
Связь с админом: { telebot.formatting.hcode(":justuser") }
|
|
|
|
Связь с админом: { telebot.formatting.hcode(":justuser") }
|
|
|
|
|
|
|
|
|
|
|
|
Ещё проекты: @just_openbots""", parse_mode="HTML")
|
|
|
|
Ещё проекты: @just_openbots""", parse_mode="HTML")
|
|
|
@ -96,18 +169,22 @@ def start(message):
|
|
|
|
@bot.message_handler(commands=['reg'])
|
|
|
|
@bot.message_handler(commands=['reg'])
|
|
|
|
def reg(message):
|
|
|
|
def reg(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
if len(message.text.split()) == 2:
|
|
|
|
if len(message.text.split()) == 2:
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
|
|
|
|
# Проверка ника
|
|
|
|
|
|
|
|
if not nick_ok(message, nick):
|
|
|
|
|
|
|
|
return 0
|
|
|
|
if nick in db:
|
|
|
|
if nick in db:
|
|
|
|
bot.reply_to(message, "Данный пользователь уже зарегистрирован.")
|
|
|
|
bot.reply_to(message, "Данный пользователь уже зарегистрирован.")
|
|
|
|
elif str(message.chat.id) in db:
|
|
|
|
elif str(message.chat.id) in db:
|
|
|
|
bot.reply_to(message, "Вы уже зарегистрированы.")
|
|
|
|
bot.reply_to(message, "Вы уже зарегистрированы.")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
db[nick] = {"id": message.chat.id, "channel": None, "blocks": [], "avatar": "♿️", "pkey": hash(randint(74287, 5747962)), "keys": {}}
|
|
|
|
user = user_(message.chat.id, hash(randint(74287, 5747962)))
|
|
|
|
|
|
|
|
db[nick] = user
|
|
|
|
db[message.chat.id] = nick
|
|
|
|
db[message.chat.id] = nick
|
|
|
|
|
|
|
|
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
bot.reply_to(message, "Вы зарегистрировались!\nПриятного использования.")
|
|
|
|
bot.reply_to(message, "Вы зарегистрировались!\nПриятного использования.")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message, "Вы ввели не 2 аргумента, нужно: /reg ЛюбойНикнейм")
|
|
|
|
bot.reply_to(message, "Вы ввели не 2 аргумента, нужно: /reg ЛюбойНикнейм")
|
|
|
@ -118,8 +195,9 @@ def reg(message):
|
|
|
|
def b(message):
|
|
|
|
def b(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if is_auth(message):
|
|
|
|
if is_auth(message):
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
|
|
|
|
user = db[nick]
|
|
|
|
block = message.text.split()[1]
|
|
|
|
block = message.text.split()[1]
|
|
|
|
|
|
|
|
|
|
|
|
# Block by ":user"
|
|
|
|
# Block by ":user"
|
|
|
@ -127,9 +205,9 @@ def b(message):
|
|
|
|
block = block[1:]
|
|
|
|
block = block[1:]
|
|
|
|
|
|
|
|
|
|
|
|
if block in db:
|
|
|
|
if block in db:
|
|
|
|
if db[block]["id"] not in db[nick]["blocks"]:
|
|
|
|
if db[block].id not in user.blocks:
|
|
|
|
db[nick]["blocks"].append(db[block]["id"])
|
|
|
|
user.blocks.append(db[block].id)
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
bot.reply_to(message, f"Пользователь {telebot.formatting.hcode(block)} был заблокирован.",parse_mode="HTML")
|
|
|
|
bot.reply_to(message, f"Пользователь {telebot.formatting.hcode(block)} был заблокирован.",parse_mode="HTML")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message, "Данного пользователя не существует.")
|
|
|
|
bot.reply_to(message, "Данного пользователя не существует.")
|
|
|
@ -140,17 +218,18 @@ def b(message):
|
|
|
|
def u(message):
|
|
|
|
def u(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if is_auth(message):
|
|
|
|
if is_auth(message):
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
|
|
|
|
user = db[nick]
|
|
|
|
block = message.text.split()[1]
|
|
|
|
block = message.text.split()[1]
|
|
|
|
|
|
|
|
|
|
|
|
# Unblock by ":user"
|
|
|
|
# Unblock by ":user"
|
|
|
|
if block[0] == ":":
|
|
|
|
if block[0] == ":":
|
|
|
|
block = block[1:]
|
|
|
|
block = block[1:]
|
|
|
|
|
|
|
|
|
|
|
|
if db[block]["id"] in db[nick]["blocks"]:
|
|
|
|
if db[block].id in user.blocks:
|
|
|
|
db[nick]["blocks"].remove(db[block]["id"])
|
|
|
|
user.blocks.remove(db[block].id)
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
bot.reply_to(message, f"Была снята блокировка с пользователя {telebot.formatting.hcode(block)}",parse_mode="HTML")
|
|
|
|
bot.reply_to(message, f"Была снята блокировка с пользователя {telebot.formatting.hcode(block)}",parse_mode="HTML")
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
catch_error(message)
|
|
|
|
catch_error(message)
|
|
|
@ -159,16 +238,19 @@ def u(message):
|
|
|
|
def nick(message):
|
|
|
|
def nick(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if is_auth(message):
|
|
|
|
if is_auth(message):
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
new_nick = message.text.split()[1]
|
|
|
|
new_nick = message.text.split()[1]
|
|
|
|
|
|
|
|
# Проверка ника
|
|
|
|
|
|
|
|
if not nick_ok(message, new_nick):
|
|
|
|
|
|
|
|
return 0
|
|
|
|
old_nick = db[str(message.chat.id)]
|
|
|
|
old_nick = db[str(message.chat.id)]
|
|
|
|
|
|
|
|
|
|
|
|
if new_nick not in db:
|
|
|
|
if new_nick not in db:
|
|
|
|
db[new_nick] = db[old_nick]
|
|
|
|
db[new_nick] = db[old_nick]
|
|
|
|
db[new_nick]["avatar"] = "♿️"
|
|
|
|
db[new_nick].avatar = "♿️"
|
|
|
|
db[str(message.chat.id)] = new_nick
|
|
|
|
db[str(message.chat.id)] = new_nick
|
|
|
|
del db[old_nick]
|
|
|
|
del db[old_nick]
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
bot.reply_to(message,f"Вы успешно сменили ник с {telebot.formatting.hcode(old_nick)} на {telebot.formatting.hcode(new_nick)}",parse_mode="HTML")
|
|
|
|
bot.reply_to(message,f"Вы успешно сменили ник с {telebot.formatting.hcode(old_nick)} на {telebot.formatting.hcode(new_nick)}",parse_mode="HTML")
|
|
|
|
bot.reply_to(message, """Ваша аватарка сброшена до стандартной: ♿️
|
|
|
|
bot.reply_to(message, """Ваша аватарка сброшена до стандартной: ♿️
|
|
|
|
Также вы можете сбросить публичный ключ: /key_res""")
|
|
|
|
Также вы можете сбросить публичный ключ: /key_res""")
|
|
|
@ -181,7 +263,7 @@ def nick(message):
|
|
|
|
def av(message):
|
|
|
|
def av(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if is_auth(message):
|
|
|
|
if is_auth(message):
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
if not len(message.text.split()) > 1:
|
|
|
|
if not len(message.text.split()) > 1:
|
|
|
|
bot.reply_to(message,"Укажите аватарку")
|
|
|
|
bot.reply_to(message,"Укажите аватарку")
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
@ -190,8 +272,8 @@ def av(message):
|
|
|
|
bot.reply_to(message,"Слишком большое количество символов для аватарки")
|
|
|
|
bot.reply_to(message,"Слишком большое количество символов для аватарки")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
db[nick]["avatar"] = new_avatar
|
|
|
|
db[nick].avatar = new_avatar
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
bot.reply_to(message,"Новая аватарка успешно установлена")
|
|
|
|
bot.reply_to(message,"Новая аватарка успешно установлена")
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
catch_error(message)
|
|
|
|
catch_error(message)
|
|
|
@ -203,11 +285,11 @@ def av(message):
|
|
|
|
def key(message):
|
|
|
|
def key(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if len(message.text.split()) == 2:
|
|
|
|
if len(message.text.split()) == 2:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
if nick[0] == ':':
|
|
|
|
if nick[0] == ':':
|
|
|
|
nick = nick[1:]
|
|
|
|
nick = nick[1:]
|
|
|
|
key = db[nick]["pkey"]
|
|
|
|
key = db[nick].pkey
|
|
|
|
bot.reply_to(message,f"Ключ пользователя: {telebot.formatting.hcode(key)}", parse_mode="HTML")
|
|
|
|
bot.reply_to(message,f"Ключ пользователя: {telebot.formatting.hcode(key)}", parse_mode="HTML")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message,"/key ник")
|
|
|
|
bot.reply_to(message,"/key ник")
|
|
|
@ -218,7 +300,7 @@ def key(message):
|
|
|
|
def ver(message):
|
|
|
|
def ver(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if len(message.text.split()) == 3:
|
|
|
|
if len(message.text.split()) == 3:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
nick = message.text.split()[1]
|
|
|
|
if nick[0] == ':':
|
|
|
|
if nick[0] == ':':
|
|
|
|
nick = nick[1:]
|
|
|
|
nick = nick[1:]
|
|
|
@ -227,7 +309,7 @@ def ver(message):
|
|
|
|
bot.reply_to(message,"Не существует такого пользователя")
|
|
|
|
bot.reply_to(message,"Не существует такого пользователя")
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if key == db[nick]["pkey"]:
|
|
|
|
if key == db[nick].pkey:
|
|
|
|
bot.reply_to(message,"✅ Ключи совпадают")
|
|
|
|
bot.reply_to(message,"✅ Ключи совпадают")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message,"❌ Ключи не совпадают")
|
|
|
|
bot.reply_to(message,"❌ Ключи не совпадают")
|
|
|
@ -240,14 +322,14 @@ def ver(message):
|
|
|
|
def key_res(message):
|
|
|
|
def key_res(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if is_auth(message):
|
|
|
|
if is_auth(message):
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
|
|
|
|
|
|
|
|
key = hash(randint(74287, 5747962))
|
|
|
|
key = hash(randint(74287, 5747962))
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
old_key = db[nick]["pkey"]
|
|
|
|
old_key = db[nick].pkey
|
|
|
|
|
|
|
|
|
|
|
|
db[nick]["pkey"] = key
|
|
|
|
db[nick].pkey = key
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message,f"""🔑 Ключ успешно сброшен.
|
|
|
|
bot.reply_to(message,f"""🔑 Ключ успешно сброшен.
|
|
|
|
|
|
|
|
|
|
|
@ -259,24 +341,26 @@ def key_res(message):
|
|
|
|
# Проверяем совпадение ключей при отправке сообщений
|
|
|
|
# Проверяем совпадение ключей при отправке сообщений
|
|
|
|
def key_valid(message, channel):
|
|
|
|
def key_valid(message, channel):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
our_nick = db[str(message.chat.id)]
|
|
|
|
our_nick = db[str(message.chat.id)]
|
|
|
|
|
|
|
|
user = db[our_nick]
|
|
|
|
# Добавляем ключ если его нету в нашей БД
|
|
|
|
# Добавляем ключ если его нету в нашей БД
|
|
|
|
if channel not in db[our_nick]["keys"]:
|
|
|
|
if channel not in user.keys:
|
|
|
|
db[our_nick]["keys"][channel] = db[channel]["pkey"]
|
|
|
|
user.keys[channel] = db[channel].pkey
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
|
|
|
|
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
our_key = db[our_nick]["keys"][channel]
|
|
|
|
our_key = user.keys[channel]
|
|
|
|
dest_key = db[channel]["pkey"]
|
|
|
|
print(channel)
|
|
|
|
|
|
|
|
dest_key = db[channel].pkey
|
|
|
|
|
|
|
|
|
|
|
|
if our_key == dest_key:
|
|
|
|
if our_key == dest_key:
|
|
|
|
print("Valid: ", channel)
|
|
|
|
print("Valid: ", channel)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Not valid: ", channel)
|
|
|
|
print("Not valid: ", channel)
|
|
|
|
db[our_nick]["keys"][channel] = dest_key
|
|
|
|
use.keys[channel] = dest_key
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""⚠️ Публичные ключи не совпадают ⚠️
|
|
|
|
bot.reply_to(message, f"""⚠️ Публичные ключи не совпадают ⚠️
|
|
|
|
Ожидаемый ключ: {telebot.formatting.hcode(our_key)}
|
|
|
|
Ожидаемый ключ: {telebot.formatting.hcode(our_key)}
|
|
|
@ -295,51 +379,51 @@ def key_valid(message, channel):
|
|
|
|
@bot.message_handler(commands=['me'])
|
|
|
|
@bot.message_handler(commands=['me'])
|
|
|
|
def me(message):
|
|
|
|
def me(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = read_db()
|
|
|
|
if is_auth(message):
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
db = load()
|
|
|
|
channel = db[nick]["channel"]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
avatar = db[nick]["avatar"]
|
|
|
|
user = db[nick]
|
|
|
|
pkey = db[nick]["pkey"]
|
|
|
|
ch = user.channel
|
|
|
|
if not channel:
|
|
|
|
if not user.channel:
|
|
|
|
channel = "Не задан."
|
|
|
|
ch = "Не задан."
|
|
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Заданный канал: {telebot.formatting.hcode(channel)}
|
|
|
|
bot.reply_to(message, f"""Заданный канал: {telebot.formatting.hcode(ch)}
|
|
|
|
|
|
|
|
|
|
|
|
Ваш ник: {telebot.formatting.hcode(nick)}
|
|
|
|
Ваш ник: {telebot.formatting.hcode(nick)}
|
|
|
|
Ваша аватарка: {telebot.formatting.hcode(avatar)}
|
|
|
|
Ваша аватарка: {telebot.formatting.hcode(user.avatar)}
|
|
|
|
Ваш публичный ключ: {telebot.formatting.hcode(pkey)}""",parse_mode="HTML")
|
|
|
|
Ваш публичный ключ: {telebot.formatting.hcode(user.pkey)}""",parse_mode="HTML")
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
catch_error(message)
|
|
|
|
catch_error(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(func=lambda message: True, content_types=['photo','text', 'document', 'voice'])
|
|
|
|
@bot.message_handler(func=lambda message: True, content_types=['photo','text', 'document', 'voice', 'video'])
|
|
|
|
def catch_all_messages(message):
|
|
|
|
def catch_all_messages(message):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
nick = db[str(message.chat.id)]
|
|
|
|
avatar = ' ' + db[nick]["avatar"]
|
|
|
|
user = db[nick]
|
|
|
|
|
|
|
|
avatar = ' ' + user.avatar
|
|
|
|
if message.content_type == "text" and message.text[:1].lower() == ":":
|
|
|
|
if message.content_type == "text" and message.text[:1].lower() == ":":
|
|
|
|
channel = message.text[1:]
|
|
|
|
channel = message.text[1:]
|
|
|
|
if channel in db:
|
|
|
|
if channel in db:
|
|
|
|
# Проверяем ключи
|
|
|
|
# Проверяем ключи
|
|
|
|
if not key_valid(message, channel):
|
|
|
|
if not key_valid(message, channel):
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
db = read_db()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db[nick]["channel"] = channel
|
|
|
|
user.channel = channel
|
|
|
|
bot.reply_to(message, "Установлен адресат: " + telebot.formatting.hcode(channel), parse_mode="HTML")
|
|
|
|
bot.reply_to(message, "Установлен адресат: " + telebot.formatting.hcode(channel), parse_mode="HTML")
|
|
|
|
write_db(db)
|
|
|
|
save(db)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message, "Не существует данного пользователя.")
|
|
|
|
bot.reply_to(message, "Не существует данного пользователя.")
|
|
|
|
elif db[nick]["channel"] != None:
|
|
|
|
elif user.channel != None:
|
|
|
|
channel = db[nick]["channel"]
|
|
|
|
channel = user.channel
|
|
|
|
# Проверяем ключи
|
|
|
|
# Проверяем ключи
|
|
|
|
if not key_valid(message, channel):
|
|
|
|
if not key_valid(message, channel):
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
db = read_db()
|
|
|
|
db = load()
|
|
|
|
|
|
|
|
|
|
|
|
if message.chat.id not in db[channel]["blocks"]:
|
|
|
|
if message.chat.id not in db[channel].blocks:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Check if image
|
|
|
|
# Check if image
|
|
|
|
if "photo" in message.json:
|
|
|
|
if "photo" in message.json:
|
|
|
@ -350,7 +434,7 @@ def catch_all_messages(message):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
caption = ""
|
|
|
|
caption = ""
|
|
|
|
|
|
|
|
|
|
|
|
bot.send_photo(db[channel]["id"], img_id, f"{telebot.formatting.hcode(':'+nick) + avatar}" + caption, parse_mode="HTML")
|
|
|
|
bot.send_photo(db[channel].id, img_id, f"{telebot.formatting.hcode(':'+nick) + avatar}" + caption, parse_mode="HTML")
|
|
|
|
|
|
|
|
|
|
|
|
elif "document" in message.json:
|
|
|
|
elif "document" in message.json:
|
|
|
|
doc_id = message.json['document']['file_id']
|
|
|
|
doc_id = message.json['document']['file_id']
|
|
|
@ -358,14 +442,22 @@ def catch_all_messages(message):
|
|
|
|
caption = "\n" + message.json['caption']
|
|
|
|
caption = "\n" + message.json['caption']
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
caption = ""
|
|
|
|
caption = ""
|
|
|
|
bot.send_document(db[channel]["id"], doc_id, caption = f"{telebot.formatting.hcode(':'+nick) + avatar}" + caption, parse_mode="HTML")
|
|
|
|
bot.send_document(db[channel].id, doc_id, caption = f"{telebot.formatting.hcode(':'+nick) + avatar}" + caption, parse_mode="HTML")
|
|
|
|
elif "voice" in message.json:
|
|
|
|
elif "voice" in message.json:
|
|
|
|
voice_id = message.json['voice']['file_id']
|
|
|
|
voice_id = message.json['voice']['file_id']
|
|
|
|
bot.send_document(db[channel]["id"], voice_id, caption = f"{telebot.formatting.hcode(':'+nick) + avatar}", parse_mode="HTML")
|
|
|
|
bot.send_document(db[channel].id, voice_id, caption = f"{telebot.formatting.hcode(':'+nick) + avatar}", parse_mode="HTML")
|
|
|
|
|
|
|
|
elif "video" in message.json:
|
|
|
|
|
|
|
|
vid_id = message.json['video']['file_id']
|
|
|
|
|
|
|
|
if "caption" in message.json:
|
|
|
|
|
|
|
|
caption = "\n" + message.json['caption']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
caption = ""
|
|
|
|
|
|
|
|
bot.send_video(db[channel].id, vid_id, caption = f"{telebot.formatting.hcode(':'+nick) + avatar}", parse_mode="HTML")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.send_message(db[channel]["id"], f"{telebot.formatting.hcode(':'+nick) + avatar}\n" + message.text, parse_mode="HTML")
|
|
|
|
bot.send_message(db[channel].id, f"{telebot.formatting.hcode(':'+nick) + avatar}\n" + message.text, parse_mode="HTML")
|
|
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
|
|
|
|
catch_error(message)
|
|
|
|
bot.reply_to(message, "Сообщение не было доставлено.\nВероятно пользователь заблокировал бота.")
|
|
|
|
bot.reply_to(message, "Сообщение не было доставлено.\nВероятно пользователь заблокировал бота.")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bot.reply_to(message, "Увы, но вас заблокировал данный пользователь.")
|
|
|
|
bot.reply_to(message, "Увы, но вас заблокировал данный пользователь.")
|
|
|
@ -375,7 +467,7 @@ def catch_all_messages(message):
|
|
|
|
catch_error(message)
|
|
|
|
catch_error(message)
|
|
|
|
|
|
|
|
|
|
|
|
#### POLLING ####
|
|
|
|
#### POLLING ####
|
|
|
|
mode = 0
|
|
|
|
mode = 1
|
|
|
|
# Normal - 0, debug - 1
|
|
|
|
# Normal - 0, debug - 1
|
|
|
|
|
|
|
|
|
|
|
|
if mode == 0:
|
|
|
|
if mode == 0:
|
|
|
|