Archived
refactor(bot): modularize bot code
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from bot.ui.formatters import get_bot_status_icon
|
||||
|
||||
|
||||
def main_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text="🆙 Обновить", callback_data="refresh")],
|
||||
[InlineKeyboardButton(text="🤖 Боты", callback_data="bots")],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🔑 Активация ключей на всех аккаунтах",
|
||||
callback_data="redeem_keys",
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="📁 Плагины", callback_data="plugins")],
|
||||
[InlineKeyboardButton(text="💻 Консоль", callback_data="console")],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="♻ Перезапустить ASF",
|
||||
callback_data="restart_asf_confirm",
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def back_keyboard(callback_data: str = "back") -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=callback_data)]
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def games_keyboard(bot_name: str, is_enabled: bool) -> InlineKeyboardMarkup:
|
||||
text = "Остановить накрутку CS2" if is_enabled else "⌚ Накрутить часы CS2"
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text=text, callback_data=f"farm|{bot_name}|730")],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{bot_name}")],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def bots_keyboard(bots: dict) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
for name, bot in bots.items():
|
||||
status = get_bot_status_icon(bot)
|
||||
loaded = bool(bot.get("BotName")) and bool(bot.get("SteamID"))
|
||||
callback_data = f"bot_{name}" if loaded else "bot_loading"
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text=f"{status} {name}", callback_data=callback_data)]
|
||||
)
|
||||
keyboard.append([InlineKeyboardButton(text="🔙 Назад", callback_data="back")])
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def bot_details_keyboard(
|
||||
bot_name: str, has_mobile_authenticator: bool
|
||||
) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
if has_mobile_authenticator:
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔐 2FA", callback_data=f"2fa_{bot_name}")]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="⌚ Накрутка часов", callback_data=f"games_{bot_name}")]
|
||||
)
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🔑 Активировать ключ",
|
||||
callback_data=f"redeem_bot_{bot_name}",
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="📦 Инвентарь", callback_data=f"inventory_{bot_name}")]
|
||||
)
|
||||
keyboard.append([InlineKeyboardButton(text="🔙 Назад", callback_data="bots")])
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def twofa_keyboard(bot_name: str, has_confirmations: bool) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
if has_confirmations:
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Подтверждения",
|
||||
callback_data=f"confirm_list_{bot_name}",
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{bot_name}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def confirmations_keyboard(bot_name: str) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Подтвердить всё",
|
||||
callback_data=f"confirm_all_{bot_name}",
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"2fa_{bot_name}")],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def confirm_action_keyboard(confirm_data: str, cancel_data: str) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text="Да", callback_data=confirm_data)],
|
||||
[InlineKeyboardButton(text="Нет", callback_data=cancel_data)],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def inventory_menu_keyboard(
|
||||
bot_name: str, cs2_count: int, steam_count: int
|
||||
) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
if cs2_count:
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=f"CS2 ({cs2_count})",
|
||||
callback_data=f"inv_cs2_{bot_name}",
|
||||
)
|
||||
]
|
||||
)
|
||||
if steam_count:
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=f"Steam ({steam_count})",
|
||||
callback_data=f"inv_steam_{bot_name}",
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{bot_name}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def inventory_page_keyboard(
|
||||
inventory_type: str, bot_name: str, page: int, total_pages: int
|
||||
) -> InlineKeyboardMarkup:
|
||||
nav_buttons = []
|
||||
if page > 0:
|
||||
nav_buttons.append(
|
||||
InlineKeyboardButton(
|
||||
text="◀",
|
||||
callback_data=f"invpage|{inventory_type}|{bot_name}|{page - 1}",
|
||||
)
|
||||
)
|
||||
if page < total_pages - 1:
|
||||
nav_buttons.append(
|
||||
InlineKeyboardButton(
|
||||
text="▶",
|
||||
callback_data=f"invpage|{inventory_type}|{bot_name}|{page + 1}",
|
||||
)
|
||||
)
|
||||
keyboard = []
|
||||
if nav_buttons:
|
||||
keyboard.append(nav_buttons)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"inventory_{bot_name}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def console_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="console_exit")]
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def delete_message_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[[InlineKeyboardButton(text="Удалить", callback_data="delete_msg")]]
|
||||
)
|
||||
Reference in New Issue
Block a user