Archived
feat(bot): add bot account ownership and balance
This commit is contained in:
+12
-9
@@ -3,6 +3,7 @@ import json
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from bot.api.asf import get_asf_status
|
||||
from bot.config import ADMIN_ID
|
||||
from bot.constants import GAMES
|
||||
|
||||
|
||||
@@ -78,21 +79,23 @@ def get_uptime(start_time_str: str) -> str:
|
||||
return f"{days_measure}{hours_measure}{minutes_measure}{seconds_measure}"
|
||||
|
||||
|
||||
def format_asf(data: dict) -> str:
|
||||
def format_asf(data: dict, user_id: int) -> str:
|
||||
result = data.get("Result", {})
|
||||
|
||||
current_version = result.get("Version")
|
||||
latest_version = result.get("LatestVersion", current_version)
|
||||
|
||||
lines = [f"Версия ASF: {current_version}"]
|
||||
if current_version != latest_version:
|
||||
lines.append(f"Доступно обновление: {latest_version}")
|
||||
|
||||
memory_kb = result.get("MemoryUsage", 0)
|
||||
memory_mb = memory_kb / 1024
|
||||
if user_id == ADMIN_ID:
|
||||
if current_version != latest_version:
|
||||
lines.append(f"Доступно обновление: {latest_version}")
|
||||
|
||||
lines.append(f"Используется памяти: {memory_mb:.2f} MB")
|
||||
lines.append(f"Работает: {get_uptime(result.get('ProcessStartTime'))}")
|
||||
memory_kb = result.get("MemoryUsage", 0)
|
||||
memory_mb = memory_kb / 1024
|
||||
|
||||
lines.append(f"Используется памяти: {memory_mb:.2f} MB")
|
||||
lines.append(f"Работает: {get_uptime(result.get('ProcessStartTime'))}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -172,7 +175,7 @@ def format_bot_ui(bot: dict) -> str:
|
||||
return text
|
||||
|
||||
|
||||
def get_asf_status_text() -> str:
|
||||
def get_asf_status_text(user_id: int) -> str:
|
||||
response = get_asf_status()
|
||||
|
||||
if response.status_code != 200:
|
||||
@@ -182,7 +185,7 @@ def get_asf_status_text() -> str:
|
||||
if not data.get("Success"):
|
||||
return "ASF вернул ошибку"
|
||||
|
||||
return f"<b>💻 Панель управления ASF</b>\n\n{format_asf(data)}"
|
||||
return f"<b>💻 Панель управления ASF</b>\n\n{format_asf(data, user_id)}"
|
||||
|
||||
|
||||
def get_farm_summary(bots: dict) -> str:
|
||||
|
||||
+98
-55
@@ -1,30 +1,40 @@
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from bot.ui.formatters import get_bot_status_icon
|
||||
from bot.config import ADMIN_ID
|
||||
|
||||
|
||||
def main_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
def main_keyboard(user_id: int | None = None) -> InlineKeyboardMarkup:
|
||||
keyboard = [
|
||||
[InlineKeyboardButton(text="🤖 Боты", callback_data="bots")],
|
||||
[InlineKeyboardButton(text="🔑 Активация ключей", callback_data="redeem_keys")],
|
||||
]
|
||||
|
||||
profile_index = -1 if user_id == ADMIN_ID else 0
|
||||
|
||||
if user_id == ADMIN_ID:
|
||||
keyboard.insert(
|
||||
0,
|
||||
[InlineKeyboardButton(text="🆙 Обновить", callback_data="refresh")],
|
||||
[InlineKeyboardButton(text="🤖 Боты", callback_data="bots")],
|
||||
)
|
||||
|
||||
keyboard.extend(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🔑 Активация ключей",
|
||||
callback_data="redeem_keys",
|
||||
)
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🤵 Админ-панель", callback_data="admin_panel"
|
||||
)
|
||||
],
|
||||
],
|
||||
[InlineKeyboardButton(text="📁 Плагины", callback_data="plugins")],
|
||||
[InlineKeyboardButton(text="💻 Консоль", callback_data="console")],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="♻ Перезапустить ASF",
|
||||
callback_data="restart_asf_confirm",
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
keyboard.insert(
|
||||
profile_index,
|
||||
[InlineKeyboardButton(text="👤 Профиль", callback_data="profile")],
|
||||
)
|
||||
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def back_keyboard(callback_data: str = "back") -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
@@ -34,57 +44,96 @@ def back_keyboard(callback_data: str = "back") -> InlineKeyboardMarkup:
|
||||
)
|
||||
|
||||
|
||||
def games_keyboard(bot_name: str, is_enabled: bool) -> InlineKeyboardMarkup:
|
||||
def admin_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🔍 Найти пользователя", callback_data="admin_lookup"
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="💲 Цена слота", callback_data="admin_price")],
|
||||
[InlineKeyboardButton(text="📁 Плагины", callback_data="plugins")],
|
||||
[InlineKeyboardButton(text="💻 Консоль", callback_data="console")],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="♻ Перезапустить ASF", callback_data="restart_asf_confirm"
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="back")],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def admin_profile_keyboard(user_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="💲 Изменить баланс", callback_data=f"admin_balance:{user_id}"
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="admin_panel")],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def games_keyboard(account_id: int, 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}")],
|
||||
[InlineKeyboardButton(text=text, callback_data=f"farm|{account_id}|730")],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{account_id}")],
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def bots_keyboard(bots: dict) -> InlineKeyboardMarkup:
|
||||
def bots_keyboard(bots: list[tuple[int, str, dict]]) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
for name, bot in bots.items():
|
||||
for account_id, name, bot in bots:
|
||||
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"
|
||||
callback_data = f"bot_{account_id}" if loaded else "bot_loading"
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text=f"{status} {name}", callback_data=callback_data)]
|
||||
)
|
||||
keyboard.append([InlineKeyboardButton(text="🔙 Назад", callback_data="back")])
|
||||
|
||||
keyboard.extend(
|
||||
[
|
||||
[InlineKeyboardButton(text="⬆️ Загрузить конфиг", callback_data="upload")],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="admin_panel")],
|
||||
]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def bot_details_keyboard(
|
||||
bot_name: str, has_mobile_authenticator: bool
|
||||
account_id: int, has_mobile_authenticator: bool
|
||||
) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
if has_mobile_authenticator:
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔐 2FA", callback_data=f"2fa_{bot_name}")]
|
||||
[InlineKeyboardButton(text="🔐 2FA", callback_data=f"2fa_{account_id}")]
|
||||
)
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="⌚ Накрутка часов", callback_data=f"games_{bot_name}"
|
||||
text="⌚ Накрутка часов", callback_data=f"games_{account_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🔑 Активировать ключ",
|
||||
callback_data=f"redeem_bot_{bot_name}",
|
||||
text="🔑 Активировать ключ", callback_data=f"redeem_bot_{account_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="📦 Инвентарь", callback_data=f"inventory_{bot_name}"
|
||||
text="📦 Инвентарь", callback_data=f"inventory_{account_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -92,33 +141,31 @@ def bot_details_keyboard(
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def twofa_keyboard(bot_name: str, has_confirmations: bool) -> InlineKeyboardMarkup:
|
||||
def twofa_keyboard(account_id: int, has_confirmations: bool) -> InlineKeyboardMarkup:
|
||||
keyboard = []
|
||||
if has_confirmations:
|
||||
keyboard.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Подтверждения",
|
||||
callback_data=f"confirm_list_{bot_name}",
|
||||
text="Подтверждения", callback_data=f"confirm_list_{account_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{bot_name}")]
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{account_id}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def confirmations_keyboard(bot_name: str) -> InlineKeyboardMarkup:
|
||||
def confirmations_keyboard(account_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Подтвердить всё",
|
||||
callback_data=f"confirm_all_{bot_name}",
|
||||
text="Подтвердить всё", callback_data=f"confirm_all_{account_id}"
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"2fa_{bot_name}")],
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"2fa_{account_id}")],
|
||||
]
|
||||
)
|
||||
|
||||
@@ -135,15 +182,14 @@ def confirm_action_keyboard(
|
||||
|
||||
|
||||
def inventory_menu_keyboard(
|
||||
bot_name: str, cs2_count: int, steam_count: int
|
||||
account_id: int, 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}",
|
||||
text=f"CS2 ({cs2_count})", callback_data=f"inv_cs2_{account_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -152,40 +198,37 @@ def inventory_menu_keyboard(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=f"Steam ({steam_count})",
|
||||
callback_data=f"inv_steam_{bot_name}",
|
||||
callback_data=f"inv_steam_{account_id}",
|
||||
)
|
||||
]
|
||||
)
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{bot_name}")]
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"bot_{account_id}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
|
||||
def inventory_page_keyboard(
|
||||
inventory_type: str, bot_name: str, page: int, total_pages: int
|
||||
inventory_type: str, account_id: int, page: int, total_pages: int
|
||||
) -> InlineKeyboardMarkup:
|
||||
nav_buttons = []
|
||||
nav = []
|
||||
if page > 0:
|
||||
nav_buttons.append(
|
||||
nav.append(
|
||||
InlineKeyboardButton(
|
||||
text="◀",
|
||||
callback_data=f"invpage|{inventory_type}|{bot_name}|{page - 1}",
|
||||
callback_data=f"invpage|{inventory_type}|{account_id}|{page - 1}",
|
||||
)
|
||||
)
|
||||
if page < total_pages - 1:
|
||||
nav_buttons.append(
|
||||
nav.append(
|
||||
InlineKeyboardButton(
|
||||
text="▶",
|
||||
callback_data=f"invpage|{inventory_type}|{bot_name}|{page + 1}",
|
||||
callback_data=f"invpage|{inventory_type}|{account_id}|{page + 1}",
|
||||
)
|
||||
)
|
||||
|
||||
keyboard = []
|
||||
if nav_buttons:
|
||||
keyboard.append(nav_buttons)
|
||||
keyboard = [nav] if nav else []
|
||||
keyboard.append(
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"inventory_{bot_name}")]
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data=f"inventory_{account_id}")]
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=keyboard)
|
||||
|
||||
@@ -193,7 +236,7 @@ def inventory_page_keyboard(
|
||||
def console_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="console_exit")]
|
||||
[InlineKeyboardButton(text="🔙 Назад", callback_data="admin_panel")]
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user