From 2e1539825914f927605c503a41f8c787d8b76f9c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 30 Nov 2024 08:45:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B8=D0=BA=D1=83=20=D0=BD=D0=B0=20=D1=82=D0=BE?= =?UTF-8?q?=D0=BA=D0=B5=D0=BD=20=D0=BF=D0=BE=20=D0=B0=D0=B9=D0=B4=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 33 +++++++++++++++------------------ call2api.py | 5 ++++- tg.py | 9 +++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/api.py b/api.py index 73d0f89..993ae01 100644 --- a/api.py +++ b/api.py @@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException from pydantic import BaseModel from datetime import datetime, timedelta from statistics import median +from uuid import uuid4 # Fix 3.3 + 0.15 = 3.4499999999999997 from decimal import Decimal as d @@ -322,23 +323,6 @@ def update_passwd(it: Update_passwd): else: return 'Error' -# DEPRECATED -# class Update_time(BaseModel): - # token: str - # id: str - # time: str -# @app.post('/api/update_time/') -# def update_time(it: Update_time): - # token, id, time = it.token, it.id, int(it.time) - # if token_check(token): - # db = read() - # db['id'][id]['time'] = time - # write(db) - # return 'OK' - # else: - # return 'Error' - - class Add_time(BaseModel): token: str id: str @@ -478,7 +462,20 @@ def get_stat(it: Get_stat): else: return 'Error' -# TODO: unauth from account +class Token_gen(BaseModel): + token: str + id: str +@app.post('/api/token_gen/') +def token_gen(it: Token_gen): + token, id = it.token, it.id + if token_check(token): + user_token = str(uuid4()) + user_api = read('user_api.json') + user_api['tokens'][id] = user_token + write(user_api, 'user_api.json') + return user_token + else: + return 'Error' if __name__ == '__main__': import uvicorn diff --git a/call2api.py b/call2api.py index 531cfbd..d571696 100644 --- a/call2api.py +++ b/call2api.py @@ -132,7 +132,10 @@ def get_stat(token): def transfer_callback(addr, token, src_nick, dst_nick, amount): amount = str(amount) data = {'token': token, 'src_nick': src_nick, 'dst_nick': dst_nick, 'amount': amount} - print(addr + 'api/transfer_callback/') return call(addr + 'api/transfer_callback/', data, pre=False) +def token_gen(token, id): + data = {'token': token, 'id': id} + return call('api/token_gen/', data) + #print( user_in_db('ee77b9d8-44f3-4e01-a702-69d5524ee50b', '1234') ) diff --git a/tg.py b/tg.py index 838ea6b..d294da0 100644 --- a/tg.py +++ b/tg.py @@ -236,6 +236,15 @@ def set_course(message): CDM в час: `{conf['time2cdm']*3600}`''', parse_mode = 'Markdown') +@bot.message_handler(commands=['token_gen']) +def token_gen_tg(message): + if checkauth(message): + id = user_in_db(API_TOKEN, tg=message.chat.id) + token = token_gen(API_TOKEN, id) + bot.reply_to(message, f'''Ваш новый токен: {hcode(f"{token}")} + +⚠️ВНИМАНИЕ, не передавайте никому токен. Администрация не спрашивает токены.⚠️''', parse_mode='HTML') + @bot.message_handler(func=lambda message: True) def checks(message): if message.text == 'Баланс':