Archived
refactor(bot): modularize bot code
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from aiogram import Router
|
||||
from aiogram.types import CallbackQuery
|
||||
|
||||
from bot.filters import AdminCallbackFilter
|
||||
from bot.services.inventory import build_inventory_menu, render_inventory_page
|
||||
from bot.ui.keyboards import back_keyboard
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.callback_query(lambda c: c.data and c.data.startswith("inventory_"), AdminCallbackFilter())
|
||||
async def inventory_menu(callback: CallbackQuery) -> None:
|
||||
await callback.answer()
|
||||
bot_name = callback.data.replace("inventory_", "") # type: ignore[union-attr]
|
||||
await callback.message.edit_text("Проверка inventory...") # type: ignore[union-attr]
|
||||
text, keyboard = await build_inventory_menu(bot_name)
|
||||
if "пуст" in text:
|
||||
keyboard = back_keyboard(f"bot_{bot_name}")
|
||||
await callback.message.edit_text(text, reply_markup=keyboard) # type: ignore[union-attr]
|
||||
|
||||
|
||||
@router.callback_query(lambda c: c.data and c.data.startswith("inv_cs2_"), AdminCallbackFilter())
|
||||
async def cs2_inventory(callback: CallbackQuery) -> None:
|
||||
await callback.answer()
|
||||
bot_name = callback.data.replace("inv_cs2_", "") # type: ignore[union-attr]
|
||||
await callback.message.edit_text("Загрузка inventory...") # type: ignore[union-attr]
|
||||
text, keyboard = await render_inventory_page(bot_name, "cs2", 730, 2, 0)
|
||||
if text is None:
|
||||
await callback.message.edit_text("Не удалось загрузить inventory") # type: ignore[union-attr]
|
||||
return
|
||||
await callback.message.edit_text(text, reply_markup=keyboard) # type: ignore[union-attr]
|
||||
|
||||
|
||||
@router.callback_query(lambda c: c.data and c.data.startswith("inv_steam_"), AdminCallbackFilter())
|
||||
async def steam_inventory(callback: CallbackQuery) -> None:
|
||||
await callback.answer()
|
||||
bot_name = callback.data.replace("inv_steam_", "") # type: ignore[union-attr]
|
||||
await callback.message.edit_text("Загрузка inventory...") # type: ignore[union-attr]
|
||||
text, keyboard = await render_inventory_page(bot_name, "steam", 753, 6, 0)
|
||||
if text is None:
|
||||
await callback.message.edit_text("Не удалось загрузить inventory") # type: ignore[union-attr]
|
||||
return
|
||||
await callback.message.edit_text(text, reply_markup=keyboard) # type: ignore[union-attr]
|
||||
|
||||
|
||||
@router.callback_query(lambda c: c.data and c.data.startswith("invpage|"), AdminCallbackFilter())
|
||||
async def inventory_page(callback: CallbackQuery) -> None:
|
||||
await callback.answer()
|
||||
_, inv_type, bot_name, page_value = callback.data.split("|") # type: ignore[union-attr]
|
||||
app_id, context_id = (730, 2) if inv_type == "cs2" else (753, 6)
|
||||
text, keyboard = await render_inventory_page(bot_name, inv_type, app_id, context_id, int(page_value))
|
||||
if text is None:
|
||||
await callback.message.edit_text("Не удалось загрузить inventory") # type: ignore[union-attr]
|
||||
return
|
||||
await callback.message.edit_text(text, reply_markup=keyboard) # type: ignore[union-attr]
|
||||
Reference in New Issue
Block a user