refactor(asf): use ASF_URL directly, poll restart

This commit is contained in:
2026-07-22 22:10:24 +05:00
parent 2fb37d1ee8
commit b1c8f6d9f8
6 changed files with 70 additions and 32 deletions
+27 -8
View File
@@ -68,50 +68,63 @@ def get_uptime(start_time_str: str) -> str:
def format_asf(data: dict) -> str:
result = data.get("Result", {})
current_version = result.get("Version")
latest_version = result.get("LatestVersion", current_version)
lines = [f"Версия ASF: {current_version}"]
lines = [f"Версия ASF: `{current_version}`"]
if current_version != latest_version:
lines.append(f"Доступно обновление: {latest_version}")
lines.append(f"Доступно обновление: `{latest_version}`")
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)
def get_bot_status_icon(bot: dict) -> str:
online = bot.get("IsConnectedAndLoggedOn", False)
farming = bot.get("CardsFarmer", {}).get("NowFarming", False)
idle_games = bot.get("BotConfig", {}).get("GamesPlayedWhileIdle", [])
loaded = bool(bot.get("BotName")) and bool(bot.get("SteamID"))
if not loaded:
return "🔄"
if farming:
return "🎴"
if idle_games and online:
return ""
if online:
return "🟢"
return "🔴"
def format_bot_ui(bot: dict) -> str:
online = get_bot_status_icon(bot)
now_farming = bot.get("CardsFarmer", {}).get("NowFarming")
status_line = (
"🎴 Идет фарм карточек"
if now_farming
else "🎴 Карточки не фармятся"
)
status_line = "🎴 Идет фарм карточек" if now_farming else "🎴 Карточки не фармятся"
time = bot.get("CardsFarmer", {}).get("TimeRemaining", "00:00:00")
games_to_farm = len(bot.get("CardsFarmer", {}).get("GamesToFarm", []))
twofa = "есть" if bot.get("HasMobileAuthenticator") else "нет"
balance = bot.get("WalletBalance", 0) / 100
currency = get_currency_name(bot.get("WalletCurrency", 0))
redeem = bot.get("GamesToRedeemInBackgroundCount", 0)
steam_id = bot.get("SteamID")
nickname = html.escape(str(bot.get("Nickname") or ""))
redeem = bot.get("GamesToRedeemInBackgroundCount", 0)
profile_url = f"https://steamcommunity.com/profiles/{steam_id}"
text = (
f"{online} {bot.get('BotName') or 'Загрузка...'}"
@@ -122,6 +135,7 @@ def format_bot_ui(bot: dict) -> str:
idle_games = bot.get("BotConfig", {}).get("GamesPlayedWhileIdle", [])
if idle_games:
names = [GAMES.get(game, str(game)) for game in idle_games]
if bot.get("IsConnectedAndLoggedOn"):
idle_text = f"⌚ Накрутка часов: включена ({', '.join(names)})"
else:
@@ -130,6 +144,7 @@ def format_bot_ui(bot: dict) -> str:
"применится после запуска"
)
text += f"{idle_text}\n"
else:
text += "⌚ Накрутка часов: выключена\n"
@@ -138,6 +153,7 @@ def format_bot_ui(bot: dict) -> str:
f"🔐 2FA: {twofa}\n\n"
f"💰 Баланс: {balance:.2f} {currency}\n"
)
if redeem > 0:
text += f"\nКлючей в очереди: {redeem}\n"
if now_farming:
@@ -149,11 +165,14 @@ def format_bot_ui(bot: dict) -> str:
def get_asf_status_text() -> str:
response = get_asf_status()
if response.status_code != 200:
return f"Ошибка API: {response.status_code}"
data = response.json()
if not data.get("Success"):
return "ASF вернул ошибку"
return f"<b>💻 Панель управления ASF</b>\n\n{format_asf(data)}"
+2 -6
View File
@@ -10,7 +10,7 @@ def main_keyboard() -> InlineKeyboardMarkup:
[InlineKeyboardButton(text="🤖 Боты", callback_data="bots")],
[
InlineKeyboardButton(
text="🔑 Активация ключей на всех аккаунтах",
text="🔑 Активация ключей",
callback_data="redeem_keys",
)
],
@@ -35,11 +35,7 @@ def back_keyboard(callback_data: str = "back") -> InlineKeyboardMarkup:
def games_keyboard(bot_name: str, is_enabled: bool) -> InlineKeyboardMarkup:
text = (
"Остановить накрутку CS2"
if is_enabled
else "⌚ Накрутить часы CS2"
)
text = "Остановить накрутку CS2" if is_enabled else "⌚ Накрутить часы CS2"
return InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text=text, callback_data=f"farm|{bot_name}|730")],