You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.0 KiB

2 years ago
import var
import telebot
#FUNC import
from func import *
API_TOKEN = var.API_MAIN
bot = telebot.TeleBot(API_TOKEN)
1 year ago
#Get home dir
#from subprocess import getoutput
#global home
#home = getoutput("echo $HOME")
#Work with OS
from os import system as sys
2 years ago
#Work with JSON
import json
def read():
with open('db.json', 'r') as openfile:
var.db = json.load(openfile)
def write():
js = json.dumps(var.db, indent=4)
with open("db.json", "w") as outfile:
outfile.write(js)
1 year ago
def readfp():
with open('fp.json', 'r') as openfile:
var.fp = json.load(openfile)
def writefp():
js = json.dumps(var.fp, indent=4)
with open("fp.json", "w") as outfile:
outfile.write(js)
def readtime():
global home
with open(f'../db.json', 'r') as openfile:
var.dbtime = json.load(openfile)
def writetime():
js = json.dumps(var.dbtime, indent=4)
with open(f"../db.json", "w") as outfile:
outfile.write(js)
# sys(f'cp time_db.json {home}/db.json')
2 years ago
#SHA256 for sign
import hashlib
#Date&Time
from datetime import date
import time
def err(message):
bot.reply_to(message,"Что-то пошло не так, отмена операции.")
var.steps[message.chat.id] = None
def err_reg(message):
bot.reply_to(message,"""
Пожалуйста, авторизуйстесь.
Для этого введите свой ник (желательно игровой).""")
var.steps[message.chat.id]="reg"
def checkauth(message):
read()
id=str(message.chat.id)
if id in var.db:
return True
elif not id in var.db:
err_reg(message)
return False
def reg(message):
read()
id=(message.chat.id)
nick=message.text
try:
getid = list(db.keys())[list(db.values()).index(nick)]
except:
getid=None
if not getid in var.db:
bot.reply_to(message,"Пожалуйста, введите пароль для аккаунта банка.")
var.steps[message.chat.id]="pass"
var.anick[message.chat.id]=nick
elif getid in var.db:
bot.reply_to(message,"""Вы пытаетесь зайти под именем другого игрока или с нового аккаунта?
Поддержка больше чем 1 аккаунта не реализована, напишите администратору - @kirill638355""")
var.steps[message.chat.id]=None
2 years ago
def passs(message):
2 years ago
read()
id=str(message.chat.id)
pas = hashlib.sha256(str.encode(message.text)).hexdigest()
try:
deb=var.db[var.anick[message.chat.id]+"_pas"]
except:
deb=None
try:
mon=var.db[var.anick[message.chat.id]]
except:
mon=None
if pas == deb:
bot.reply_to(message,"Поздравляю, Вы успешно авторизовались.")
var.steps[message.chat.id]=None
var.db[id]=var.anick[message.chat.id]
if var.anick[message.chat.id] in var.db:
pass
else:
var.db[var.anick[message.chat.id]]=0
write()
elif deb == None:
var.steps[message.chat.id]=None
var.db[id]=var.anick[message.chat.id]
if mon == None:
var.db[var.anick[message.chat.id]]=0
2 years ago
today = date.today()
dttm = today.strftime("%d.%m.%Y_"+time.strftime("%H:%M", time.localtime()))
2 years ago
2 years ago
signstr=message.text+dttm
sign=str(hashlib.sha256(str.encode(signstr)).hexdigest())
2 years ago
2 years ago
f=open('reg.sha256','a')
f.write(sign+"-"+dttm+"\n")
f.close()
bot.reply_to(message,"Поздравляю, Вы успешно зарегистрировались.")
bot.reply_to(message,f"""
2 years ago
Ваш ключ восстановления пароля - {sign}
#REG
НИКОМУ НЕ ПЕРЕСЫЛАЙТЕ ЕГО, КРОМЕ - @kirill638355
ИНАЧЕ ВАШУ ЗАПИСЬ МОГУТ УКРАСТЬ.
""")
2 years ago
var.db[var.anick[message.chat.id]+"_pas"]=pas
2 years ago
2 years ago
write()
2 years ago
else:
err(message)
def unreg(message):
read()
print(var.db)
id=str(message.chat.id)
print(id)
var.db.pop(id)
write()
print(var.db)
bot.reply_to(message,"""
Вы успешно вышли из своего аккаунта.
ВНИМАНИЕ: ВАШ НИК БОЛЬШЕ НЕ ПРИВЯЗАН НИ К ОДНОМУ ТЕЛЕГРАМ АККАУНТУ.
""")