forked from FOSS/ASF-Control-Bot
62 lines
2.9 KiB
Python
62 lines
2.9 KiB
Python
from aiogram import Router
|
|
from aiogram.types import CallbackQuery
|
|
|
|
from bot.services.bot_accounts import get_owned_bot
|
|
from bot.services.inventory import build_inventory_menu, render_inventory_page
|
|
from bot.ui.keyboards import back_keyboard
|
|
|
|
router = Router()
|
|
|
|
|
|
async def account_from_data(callback: CallbackQuery, prefix: str):
|
|
try:
|
|
return await get_owned_bot(callback.from_user.id, int((callback.data or "").removeprefix(prefix)))
|
|
except ValueError:
|
|
return None
|
|
|
|
|
|
@router.callback_query(lambda c: c.data and c.data.startswith("inventory_"))
|
|
async def inventory_menu(callback: CallbackQuery) -> None:
|
|
account = await account_from_data(callback, "inventory_")
|
|
if account is None:
|
|
await callback.answer("Бот не найден или вам не принадлежит", show_alert=True); return
|
|
await callback.answer()
|
|
text, keyboard = await build_inventory_menu(account.bot_name, account.id)
|
|
await callback.message.edit_text(text, reply_markup=keyboard)
|
|
|
|
|
|
@router.callback_query(lambda c: c.data and c.data.startswith("inv_cs2_"))
|
|
async def inventory_cs2(callback: CallbackQuery) -> None:
|
|
account = await account_from_data(callback, "inv_cs2_")
|
|
if account is None:
|
|
await callback.answer("Бот не найден или вам не принадлежит", show_alert=True); return
|
|
await callback.answer()
|
|
text, keyboard = await render_inventory_page(account.bot_name, "cs2", 730, 2, 0, account.id)
|
|
await callback.message.edit_text(text, reply_markup=keyboard)
|
|
|
|
|
|
@router.callback_query(lambda c: c.data and c.data.startswith("inv_steam_"))
|
|
async def inventory_steam(callback: CallbackQuery) -> None:
|
|
account = await account_from_data(callback, "inv_steam_")
|
|
if account is None:
|
|
await callback.answer("Бот не найден или вам не принадлежит", show_alert=True); return
|
|
await callback.answer()
|
|
text, keyboard = await render_inventory_page(account.bot_name, "steam", 753, 6, 0, account.id)
|
|
await callback.message.edit_text(text, reply_markup=keyboard)
|
|
|
|
|
|
@router.callback_query(lambda c: c.data and c.data.startswith("invpage|"))
|
|
async def inventory_page(callback: CallbackQuery) -> None:
|
|
try:
|
|
_, inv_type, account_id, page = (callback.data or "").split("|")
|
|
account = await get_owned_bot(callback.from_user.id, int(account_id))
|
|
page = int(page)
|
|
except (ValueError, TypeError):
|
|
account = None
|
|
if account is None or inv_type not in {"cs2", "steam"}:
|
|
await callback.answer("Бот не найден или вам не принадлежит", show_alert=True); return
|
|
appid, contextid = (730, 2) if inv_type == "cs2" else (753, 6)
|
|
await callback.answer()
|
|
text, keyboard = await render_inventory_page(account.bot_name, inv_type, appid, contextid, page, account.id)
|
|
await callback.message.edit_text(text, reply_markup=keyboard)
|