2024-12-24 18:08:03 +00:00
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
from aiogram.types import CallbackQuery
|
2024-12-25 01:30:33 +00:00
|
|
|
|
from aiogram_dialog import DialogManager
|
2024-12-24 18:08:03 +00:00
|
|
|
|
from sqlalchemy import select
|
|
|
|
|
from sqlalchemy.exc import SQLAlchemyError
|
|
|
|
|
|
2024-12-25 01:30:33 +00:00
|
|
|
|
from shopbot.bot.database.db import async_session
|
|
|
|
|
from shopbot.bot.database.models import Account
|
|
|
|
|
from shopbot.bot.states import PurchaseHistorySG
|
2024-12-24 18:08:03 +00:00
|
|
|
|
|
|
|
|
|
ACCOUNT_INFO_TEMPLATE = (
|
|
|
|
|
"<b>Подробная информация об аккаунте:</b>\n\n"
|
|
|
|
|
"<b>💰 Цена:</b> {price:.2f}₽\n\n"
|
|
|
|
|
"<b>🔑 Логин:</b> {login}\n"
|
|
|
|
|
"<b>🔒 Пароль:</b> {password}\n\n"
|
|
|
|
|
"<b>🌍 Регион:</b> {region}\n"
|
|
|
|
|
"<b>🎮 Ранг:</b> {current_rank}\n"
|
|
|
|
|
"<b>🔪 Количество ножей:</b> {knife_count}\n"
|
|
|
|
|
"<b>🛡️ Количество агентов:</b> {agent_count}\n"
|
|
|
|
|
"<b>🖌️ Скины:</b> {skin_count}\n"
|
|
|
|
|
"<b>🗡️ Стоимость инвентаря:</b> {inventory_value}VP\n"
|
|
|
|
|
"<b>📈 Последний ранг:</b> {last_rank}\n"
|
|
|
|
|
"<b>🏅 Уровень:</b> {level}\n"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _format_account_info(account: Account) -> str:
|
|
|
|
|
"""Формирует строку с информацией об аккаунте."""
|
|
|
|
|
return ACCOUNT_INFO_TEMPLATE.format(
|
|
|
|
|
price=account.price,
|
|
|
|
|
login=account.login,
|
|
|
|
|
password=account.password,
|
|
|
|
|
region=account.region,
|
|
|
|
|
current_rank=account.current_rank,
|
|
|
|
|
knife_count=account.knife_count,
|
|
|
|
|
agent_count=account.agent_count,
|
|
|
|
|
skin_count=account.skin_count,
|
|
|
|
|
inventory_value=account.inventory_value,
|
|
|
|
|
last_rank=account.last_rank,
|
|
|
|
|
level=account.level,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2024-12-25 01:30:33 +00:00
|
|
|
|
async def on_history_account_selected(
|
|
|
|
|
callback: CallbackQuery, selecte, manager: DialogManager, item_id: int
|
|
|
|
|
):
|
2024-12-24 18:08:03 +00:00
|
|
|
|
try:
|
|
|
|
|
if not isinstance(item_id, int):
|
|
|
|
|
item_id = int(item_id)
|
|
|
|
|
|
|
|
|
|
manager.current_context().dialog_data["selected_account_id"] = item_id
|
|
|
|
|
|
|
|
|
|
async with async_session() as session:
|
|
|
|
|
async with session.begin():
|
2024-12-25 01:30:33 +00:00
|
|
|
|
account = await session.scalar(
|
|
|
|
|
select(Account).where(Account.id == item_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if account:
|
|
|
|
|
manager.current_context().dialog_data[
|
|
|
|
|
"account_info"
|
|
|
|
|
] = await _format_account_info(account)
|
|
|
|
|
else:
|
|
|
|
|
logging.warning(f"Account with id {item_id} not found")
|
|
|
|
|
manager.current_context().dialog_data["account_info"] = (
|
|
|
|
|
"Аккаунт не найден!"
|
|
|
|
|
)
|
2024-12-24 18:08:03 +00:00
|
|
|
|
|
|
|
|
|
await manager.switch_to(PurchaseHistorySG.details)
|
|
|
|
|
|
|
|
|
|
except SQLAlchemyError as e:
|
|
|
|
|
logging.error(f"Database error: {e}", exc_info=True)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
2024-12-25 01:30:33 +00:00
|
|
|
|
logging.error(f"An unexpected error occurred: {e}", exc_info=True)
|