big update
This commit is contained in:
1 parent
7d05a3f2c0
commit
f45d593a84
32 files changed
+726
-320
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from aiogram import types, Router
|
||||
|
||||
from app.client_bot.routers.home import router as home_router
|
||||
from app.client_bot.routers.tonconnect import router as tonconnect_router
|
||||
|
||||
from app.core.logger import logger
|
||||
|
||||
router = Router()
|
||||
|
||||
# router.message.register(t_, Command('dev_tonconnect'))
|
||||
# router.callback_query.register(t_callback_init_tonconnect, F.data.startswith('initTonconnect_'))
|
||||
# router.callback_query.register(t_callback_disconnect_wallet, F.data == 'disconnectWallet')
|
||||
@@ -6,6 +6,7 @@ from app.core._blockchain.ton.connect import TonConnect
|
||||
from app.core._keyboards import get_inline_keyboard
|
||||
from app.core._utils.tg_process_template import tg_process_template
|
||||
from app.core.models.wallet_connection import WalletConnection
|
||||
from app.core.models.node_storage import StoredContent
|
||||
|
||||
main_router = Router()
|
||||
|
||||
@@ -71,6 +72,14 @@ async def t_home_menu(__msg, **extra):
|
||||
if not wallet_connection:
|
||||
return await send_connect_wallets_list(db_session, chat_wrap, user, message_id=message_id)
|
||||
|
||||
args = []
|
||||
if isinstance(__msg, types.Message):
|
||||
args = __msg.text.split(' ')[1:]
|
||||
|
||||
if args[0].startswith('C'):
|
||||
content = StoredContent.from_cid(db_session, args[0][1:])
|
||||
return await chat_wrap.send_content(content, message_id=message_id)
|
||||
|
||||
return await send_home_menu(chat_wrap, user, wallet_connection, message_id=message_id)
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,15 @@ import traceback
|
||||
from aiogram import types, Router
|
||||
|
||||
from app.client_bot.routers.home import router as home_router
|
||||
from app.client_bot.routers.tonconnect import router as tonconnect_router
|
||||
from app.client_bot.routers.content import router as content_router
|
||||
|
||||
from app.core.logger import logger
|
||||
|
||||
main_router = Router()
|
||||
main_router.include_routers(home_router)
|
||||
main_router.include_routers(tonconnect_router)
|
||||
main_router.include_routers(content_router)
|
||||
|
||||
closing_router = Router()
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from aiogram import types, Router, F
|
||||
from aiogram.filters import Command
|
||||
|
||||
from app.client_bot.routers.home import send_connect_wallets_list, send_home_menu
|
||||
from app.core._blockchain.ton.connect import TonConnect, unpack_wallet_info
|
||||
from app.core._keyboards import get_inline_keyboard
|
||||
from app.core._utils.tg_process_template import tg_process_template
|
||||
from app.core.logger import make_log
|
||||
from app.core.models.wallet_connection import WalletConnection
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
async def pause_ton_connection(ton_connect: TonConnect):
|
||||
if ton_connect.connected:
|
||||
ton_connect._sdk_client.pause_connection()
|
||||
|
||||
|
||||
async def t_tonconnect_dev_menu(message: types.Message, memory=None, user=None, db_session=None, chat_wrap=None,
|
||||
**extra):
|
||||
try:
|
||||
command_args = message.text.split(" ")[1:]
|
||||
except BaseException as e:
|
||||
command_args = []
|
||||
|
||||
make_log("TonConnect_DevMenu", f"Command args: {command_args}", level='info')
|
||||
wallet_app_name = 'tonkeeper'
|
||||
if len(command_args) > 0:
|
||||
wallet_app_name = command_args[0].lower()
|
||||
|
||||
keyboard = []
|
||||
|
||||
ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=())
|
||||
make_log("TonConnect_DevMenu", f"Available wallets: {ton_connect._sdk_client.get_wallets()}", level='debug')
|
||||
await ton_connect.restore_connection()
|
||||
make_log("TonConnect_DevMenu", f"SDK connected?: {ton_connect.connected}", level='info')
|
||||
if not ton_connect.connected:
|
||||
if ton_connection:
|
||||
make_log("TonConnect_DevMenu", f"Invalidating old connection", level='debug')
|
||||
ton_connection.invalidated = True
|
||||
db_session.commit()
|
||||
|
||||
message_text = f"""<b>Wallet is not connected</b>
|
||||
|
||||
Use /dev_tonconnect <code>{wallet_app_name}</code> for connect to wallet."""
|
||||
connection_link = await ton_connect.new_connection(wallet_app_name)
|
||||
ton_connect.connected
|
||||
make_log("TonConnect_DevMenu", f"New connection link for {wallet_app_name}: {connection_link}", level='debug')
|
||||
keyboard.append([
|
||||
{
|
||||
'text': 'Connect',
|
||||
'url': connection_link
|
||||
}
|
||||
])
|
||||
else:
|
||||
wallet_info_text = json.dumps(unpack_wallet_info(ton_connect._sdk_client._wallet), indent=4, ensure_ascii=False)
|
||||
message_text = f"""<b>Wallet is connected</b>
|
||||
|
||||
<pre>{wallet_info_text}</pre>"""
|
||||
|
||||
memory.add_task(pause_ton_connection, ton_connect, delay_s=60 * 3)
|
||||
|
||||
return await tg_process_template(
|
||||
chat_wrap, message_text,
|
||||
keyboard=get_inline_keyboard(keyboard) if keyboard else None
|
||||
)
|
||||
|
||||
|
||||
async def t_callback_init_tonconnect(query: types.CallbackQuery, memory=None, user=None, db_session=None,
|
||||
chat_wrap=None, **extra):
|
||||
wallet_app_name = query.data.split("_")[1]
|
||||
ton_connect, ton_connection = TonConnect.by_user(db_session, user)
|
||||
await ton_connect.restore_connection()
|
||||
connection_link = await ton_connect.new_connection(wallet_app_name)
|
||||
ton_connect.connected
|
||||
memory.add_task(pause_ton_connection, ton_connect, delay_s=60 * 3)
|
||||
make_log("TonConnect_Init", f"New connection link for {wallet_app_name}: {connection_link}", level='debug')
|
||||
message_text = user.translated("tonconnectInit_menu")
|
||||
r = await tg_process_template(
|
||||
chat_wrap, message_text,
|
||||
keyboard=get_inline_keyboard([
|
||||
[
|
||||
{
|
||||
'text': user.translated('tonconnectOpenWallet_button'),
|
||||
'url': connection_link
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'text': user.translated('home_button'),
|
||||
'callback_data': 'home'
|
||||
}
|
||||
]
|
||||
]), message_id=query.message.message_id
|
||||
)
|
||||
|
||||
start_ts = datetime.now()
|
||||
while datetime.now() - start_ts < timedelta(seconds=180):
|
||||
new_connection = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).first()
|
||||
if new_connection:
|
||||
await tg_process_template(
|
||||
chat_wrap, user.translated('p_successConnectWallet')
|
||||
)
|
||||
await send_home_menu(chat_wrap, user, new_connection)
|
||||
break
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
return r
|
||||
|
||||
|
||||
async def t_callback_disconnect_wallet(query: types.CallbackQuery, memory=None, user=None, db_session=None,
|
||||
chat_wrap=None, **extra):
|
||||
wallet_connections = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).all()
|
||||
for wallet_connection in wallet_connections:
|
||||
wallet_connection.invalidated = True
|
||||
|
||||
db_session.commit()
|
||||
return await send_connect_wallets_list(db_session, chat_wrap, user, message_id=query.message.message_id)
|
||||
|
||||
|
||||
router.message.register(t_tonconnect_dev_menu, Command('dev_tonconnect'))
|
||||
router.callback_query.register(t_callback_init_tonconnect, F.data.startswith('initTonconnect_'))
|
||||
router.callback_query.register(t_callback_disconnect_wallet, F.data == 'disconnectWallet')
|
||||
Reference in new issue
Block a user