forked from FOSS/ASF-Control-Bot
feat(bot): add async DB and FSM state handling
This commit is contained in:
+27
-14
@@ -24,46 +24,58 @@ def get_currency_name(currency_id: int) -> str:
|
||||
|
||||
def get_inventory_icon(desc: dict) -> str:
|
||||
tags = desc.get("tags", [])
|
||||
|
||||
for tag in tags:
|
||||
category = tag.get("category", "")
|
||||
name = tag.get("localized_tag_name", "")
|
||||
|
||||
if category == "item_class":
|
||||
if "Trading Card" in name:
|
||||
return "🎏"
|
||||
if "Emoticon" in name:
|
||||
elif "Emoticon" in name:
|
||||
return "😀"
|
||||
if "Profile Background" in name:
|
||||
elif "Profile Background" in name:
|
||||
return "🖼"
|
||||
if "Booster Pack" in name:
|
||||
elif "Booster Pack" in name:
|
||||
return "📦"
|
||||
if "Steam Gems" in name:
|
||||
elif "Steam Gems" in name:
|
||||
return "💎"
|
||||
|
||||
if "Gift" in name:
|
||||
return "🎁"
|
||||
|
||||
item_type = desc.get("type", "").lower()
|
||||
if "knife" in item_type:
|
||||
return "🔪"
|
||||
if "pistol" in item_type:
|
||||
elif "pistol" in item_type:
|
||||
return "🔫"
|
||||
if "rifle" in item_type:
|
||||
elif "rifle" in item_type:
|
||||
return "🎯"
|
||||
if "graffiti" in item_type:
|
||||
elif "graffiti" in item_type:
|
||||
return "🎨"
|
||||
if "music kit" in item_type:
|
||||
elif "music kit" in item_type:
|
||||
return "🎵"
|
||||
|
||||
return "📦"
|
||||
|
||||
|
||||
def get_uptime(start_time_str: str) -> str:
|
||||
start_time_str = start_time_str[:26] + "Z"
|
||||
start_time = datetime.fromisoformat(start_time_str.replace("Z", "+00:00"))
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
delta = now - start_time
|
||||
days = delta.days
|
||||
|
||||
hours, remainder = divmod(delta.seconds, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
return f"{days}д {hours}ч {minutes}м {seconds}с"
|
||||
|
||||
days_measure = f"{days}д" if days > 0 else ""
|
||||
hours_measure = f" {hours}ч" if hours > 0 else ""
|
||||
minutes_measure = f" {minutes}м" if minutes > 0 else ""
|
||||
seconds_measure = f" {seconds}с" if seconds > 0 else ""
|
||||
|
||||
return f"{days_measure}{hours_measure}{minutes_measure}{seconds_measure}"
|
||||
|
||||
|
||||
def format_asf(data: dict) -> str:
|
||||
@@ -72,9 +84,9 @@ def format_asf(data: dict) -> str:
|
||||
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
|
||||
@@ -94,13 +106,10 @@ def get_bot_status_icon(bot: dict) -> str:
|
||||
|
||||
if not loaded:
|
||||
return "🔄"
|
||||
|
||||
if farming:
|
||||
return "🎴"
|
||||
|
||||
if idle_games and online:
|
||||
return "⌚"
|
||||
|
||||
if online:
|
||||
return "🟢"
|
||||
|
||||
@@ -179,11 +188,14 @@ def get_asf_status_text() -> str:
|
||||
def get_farm_summary(bots: dict) -> str:
|
||||
total_games = 0
|
||||
total_time_seconds = 0
|
||||
|
||||
for bot in bots.values():
|
||||
farmer = bot.get("CardsFarmer", {})
|
||||
|
||||
if farmer.get("NowFarming"):
|
||||
games = farmer.get("CurrentGamesFarming", [])
|
||||
total_games += len(games)
|
||||
|
||||
time_str = farmer.get("TimeRemaining", "00:00:00")
|
||||
hours, minutes, seconds = map(int, time_str.split(":"))
|
||||
total_time_seconds += hours * 3600 + minutes * 60 + seconds
|
||||
@@ -193,6 +205,7 @@ def get_farm_summary(bots: dict) -> str:
|
||||
|
||||
hours = total_time_seconds // 3600
|
||||
minutes = (total_time_seconds % 3600) // 60
|
||||
|
||||
return (
|
||||
f"Игр фармится: {total_games}\n"
|
||||
f"Осталось времени: {hours}ч {minutes}м\n"
|
||||
|
||||
Reference in New Issue
Block a user