dev@locazia: add client_bot & try fix background funcs
This commit is contained in:
1 parent
27b093bc07
commit
f4b77f38e4
10 files changed
+228
-17
No files matched your search
@@ -0,0 +1,81 @@
|
||||
from app.core._utils.tg_process_template import tg_process_template
|
||||
from app.core._keyboards import get_inline_keyboard
|
||||
from app.core.logger import logger
|
||||
from app.core.models.wallet_connection import WalletConnection
|
||||
from app.core._blockchain.ton.connect import TonConnect, unpack_wallet_info
|
||||
from app.core._config import WEB_APP_URLS
|
||||
from aiogram import types, Router, F
|
||||
from aiogram.filters import Command
|
||||
from tonsdk.utils import Address
|
||||
|
||||
|
||||
main_router = Router()
|
||||
|
||||
|
||||
async def send_home_menu(chat_wrap, user, wallet_connection, **kwargs):
|
||||
return await tg_process_template(
|
||||
chat_wrap, user.translated('home_menu').format(
|
||||
wallet_address=Address(wallet_connection.wallet_address).to_string(1, 1, 1),
|
||||
name=user.front_format(plain_text=True),
|
||||
), keyboard=get_inline_keyboard([
|
||||
[{
|
||||
'text': user.translated('ownedContent_button'),
|
||||
'callback_data': 'ownedContent'
|
||||
}],
|
||||
[{
|
||||
'text': user.translated('disconnectWallet_button'),
|
||||
'callback_data': 'disconnectWallet'
|
||||
}]
|
||||
]), **kwargs
|
||||
)
|
||||
|
||||
|
||||
async def send_connect_wallets_list(db_session, chat_wrap, user, **kwargs):
|
||||
ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=())
|
||||
await ton_connect.restore_connection()
|
||||
wallets = ton_connect._sdk_client.get_wallets()
|
||||
message_text = user.translated("connectWalletsList_menu")
|
||||
return await tg_process_template(
|
||||
chat_wrap, message_text,
|
||||
keyboard=get_inline_keyboard([
|
||||
[
|
||||
{
|
||||
'text': f"{wallets[i]['name']}",
|
||||
'callback_data': f"initTonconnect_{wallets[i]['app_name']}"
|
||||
} if i < len(wallets) else None,
|
||||
{
|
||||
'text': f"{wallets[i + 1]['name']}",
|
||||
'callback_data': f"initTonconnect_{wallets[i + 1]['app_name']}"
|
||||
} if i + 1 < len(wallets) else None,
|
||||
]
|
||||
for i in range(0, len(wallets), 2)
|
||||
]), **kwargs
|
||||
)
|
||||
|
||||
|
||||
async def t_home_menu(__msg, **extra):
|
||||
memory, user, db_session, chat_wrap = extra['memory'], extra['user'], extra['db_session'], extra['chat_wrap']
|
||||
if extra.get('state'):
|
||||
await extra['state'].clear()
|
||||
|
||||
if isinstance(__msg, types.CallbackQuery):
|
||||
message_id = __msg.message.message_id
|
||||
elif isinstance(__msg, types.Message):
|
||||
message_id = __msg.message_id
|
||||
else:
|
||||
message_id = None
|
||||
|
||||
wallet_connection = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).first()
|
||||
|
||||
if not wallet_connection:
|
||||
return await send_connect_wallets_list(db_session, chat_wrap, user, message_id=message_id)
|
||||
|
||||
return await send_home_menu(chat_wrap, user, wallet_connection, message_id=message_id)
|
||||
|
||||
|
||||
main_router.message.register(t_home_menu, Command('start'))
|
||||
main_router.callback_query.register(t_home_menu, F.data == 'home')
|
||||
router = main_router
|
||||
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from aiogram import types, Router, F
|
||||
from aiogram.filters import Command
|
||||
|
||||
from app.client_bot.routers.home import router as home_router
|
||||
from app.core.logger import logger
|
||||
|
||||
main_router = Router()
|
||||
main_router.include_routers(home_router)
|
||||
|
||||
closing_router = Router()
|
||||
|
||||
|
||||
@closing_router.message()
|
||||
async def t_index(message: types.Message, **extra):
|
||||
return await message.answer(extra['user'].translated('error_unknownCommand'), parse_mode='html')
|
||||
|
||||
main_router.include_routers(closing_router)
|
||||
|
||||
|
||||
@main_router.error()
|
||||
async def t_index_error(err_event: types.ErrorEvent, **extra):
|
||||
try:
|
||||
raise err_event.exception
|
||||
except BaseException as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
|
||||
try:
|
||||
filename = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
except:
|
||||
filename = None
|
||||
|
||||
logger.error(f"""Error: {e}
|
||||
-/ {exc_type} {exc_obj} {filename} {exc_tb.tb_frame.f_lineno}""")
|
||||
traceback.print_tb(exc_tb)
|
||||
Reference in new issue
Block a user