diff --git a/call2api.py b/call2api.py index 15c3ef1..1bfba0f 100644 --- a/call2api.py +++ b/call2api.py @@ -108,4 +108,9 @@ def get_passwd(token, id): data = {'token': token, 'id': id} return call('api/get_passwd/', data) +def transfer_callbak(addr, token, src_id, amount): + amount = str(amount) + data = {'token': token, 'src_id': src_id, 'amount': amount} + return call(addr + 'api/get_passwd/', data) + #print( user_in_db('ee77b9d8-44f3-4e01-a702-69d5524ee50b', '1234') ) diff --git a/tg.py b/tg.py index 38521a3..a30cbe9 100644 --- a/tg.py +++ b/tg.py @@ -3,6 +3,15 @@ from telebot.formatting import hcode from telebot.types import ReplyKeyboardMarkup, KeyboardButton from datetime import datetime +# API для отправки сообщения о переводе +# TG -> DS / DS -> Mine / ... +from fastapi import FastAPI, HTTPException +from pydantic import BaseModel +import uvicorn +app = FastAPI() +# Для запуска API в потоке +from threading import Thread + from call2api import * from db import * @@ -174,4 +183,34 @@ def checks(message): help(message) +# API для переводов TG->DS / ... +class Transfer_callback(BaseModel): + token: str + src_nick: str + dst_nick: str + amount: str +@app.post('/api/transfer_callback/') +def transfer_callback(it: Transfer_callback): + token, src_nick, dst_nick, amount = it.token, it.src_nick, it.dst_nick, it.amount + db = read() + if token in db['tokens']: + dst_id = user_in_db(API_TOKEN, nick=dst_nick) + tg_dst = int(get_tg(API_TOKEN, id=dst_id)) + print(tg_dst) + bot.send_message(tg_dst, f'''Вам перевели {hcode(amount)} CDM. + +Отправитель: {hcode(src_nick)}''', parse_mode='HTML') + return 200 + else: + return 'Error' + +def run_api(): + uvicorn.run(app, host='127.0.0.1', port=2222) + +# Запускаем API для переводов +api = Thread(target=run_api) +api.Daemon = True +api.start() + +# Запускаем бота bot.infinity_polling()