from bot.api.asf import get_bot_inventory from bot.constants import PAGE_SIZE from bot.ui.formatters import get_inventory_icon from bot.ui.keyboards import inventory_menu_keyboard, inventory_page_keyboard async def build_inventory_menu(bot_name: str) -> tuple[str, object]: cs2_inventory = await get_bot_inventory(bot_name, 730, 2) steam_inventory = await get_bot_inventory(bot_name, 753, 6) cs2_assets = [] steam_assets = [] try: cs2_assets = cs2_inventory.get(bot_name, {}).get("Assets", []) # type: ignore[union-attr] except Exception: pass try: steam_assets = steam_inventory.get(bot_name, {}).get("Assets", []) # type: ignore[union-attr] except Exception: pass if not cs2_assets and not steam_assets: return f"📦 Инвентарь {bot_name} пуст", inventory_menu_keyboard(bot_name, 0, 0) text = ( f"📦 Инвентарь {bot_name}\n\n" "🔄 — можно трейдить\n" "💰 — можно продавать\n" "🔒 — нельзя продавать\n" "❌ — нельзя трейдить" ) return text, inventory_menu_keyboard(bot_name, len(cs2_assets), len(steam_assets)) async def render_inventory_page( bot_name: str, inventory_type: str, appid: int, contextid: int, page: int ) -> tuple[str, object] | tuple[None, None]: inventory = await get_bot_inventory(bot_name, appid, contextid) if not inventory: return None, None bot_inventory = inventory.get(bot_name, {}) assets = bot_inventory.get("Assets", []) descriptions = bot_inventory.get("Descriptions", []) if not assets: return f"Инвентарь {bot_name} пуст", inventory_menu_keyboard(bot_name, 0, 0) desc_map = {} for desc in descriptions: key = (str(desc.get("classid")), str(desc.get("instanceid"))) desc_map[key] = desc total_pages = (len(assets) + PAGE_SIZE - 1) // PAGE_SIZE start = page * PAGE_SIZE end = start + PAGE_SIZE page_assets = assets[start:end] lines = [] marketable_count = 0 tradable_count = 0 cards_count = 0 emotes_count = 0 backgrounds_count = 0 gems_count = 0 for asset in page_assets: key = (str(asset.get("classid")), str(asset.get("instanceid"))) desc = desc_map.get(key, {}) name = desc.get("market_name", "Unknown") amount = asset.get("amount", 1) tradable = "🔄" if desc.get("tradable") else "❌" marketable = "💰" if desc.get("marketable") else "🔒" icon = get_inventory_icon(desc) if desc.get("marketable"): marketable_count += 1 if desc.get("tradable"): tradable_count += 1 if icon == "🃏": cards_count += amount elif icon == "😀": emotes_count += amount elif icon == "🖼": backgrounds_count += amount elif icon == "💎": gems_count += amount lines.append(f"{icon} {tradable}{marketable} {name} x{amount}") inv_name = "CS2" if appid == 730 else "Steam" stats = ( f"📦 Items: {len(assets)}\n" f"💰 Marketable: {marketable_count}\n" f"🔄 Tradable: {tradable_count}" ) if appid == 753: stats += ( f"\n🃏 Cards: {cards_count}" f"\n😀 Emotes: {emotes_count}" f"\n🖼 Backgrounds: {backgrounds_count}" f"\n💎 Gems: {gems_count}" ) text = ( f"📦 {inv_name} Inventory {bot_name}\n" f"📄 Страница {page + 1}/{total_pages}\n\n" f"{stats}\n\n" + "\n".join(lines) ) return text[:4000], inventory_page_keyboard(inventory_type, bot_name, page, total_pages)