Add formatting for spawner time and update stats display in format_stats_message
This commit is contained in:
parent
7910196397
commit
77571564c0
43
stats.py
43
stats.py
@ -180,6 +180,26 @@ def format_playtime(milliseconds):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return str(milliseconds)
|
return str(milliseconds)
|
||||||
|
|
||||||
|
def format_minutes_to_spawner(minutes):
|
||||||
|
"""Format minutes to readable format (XdYhZm)"""
|
||||||
|
try:
|
||||||
|
total_minutes = int(minutes)
|
||||||
|
days = total_minutes // 1440
|
||||||
|
hours = (total_minutes % 1440) // 60
|
||||||
|
mins = total_minutes % 60
|
||||||
|
|
||||||
|
parts = []
|
||||||
|
if days > 0:
|
||||||
|
parts.append(f"{days}d")
|
||||||
|
if hours > 0:
|
||||||
|
parts.append(f"{hours}h")
|
||||||
|
if mins > 0:
|
||||||
|
parts.append(f"{mins}m")
|
||||||
|
|
||||||
|
return " ".join(parts) if parts else "0m"
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return "N/A"
|
||||||
|
|
||||||
def format_stats_message(players_data, presence_data):
|
def format_stats_message(players_data, presence_data):
|
||||||
"""Format player stats as Discord embed fields (one field per column, inline)."""
|
"""Format player stats as Discord embed fields (one field per column, inline)."""
|
||||||
|
|
||||||
@ -189,6 +209,8 @@ def format_stats_message(players_data, presence_data):
|
|||||||
|
|
||||||
total_money = 0
|
total_money = 0
|
||||||
total_spawners = 0
|
total_spawners = 0
|
||||||
|
total_shards = 0
|
||||||
|
min_time_to_next = float('inf')
|
||||||
|
|
||||||
for username, stats in players_data.items():
|
for username, stats in players_data.items():
|
||||||
presence = presence_data.get(username, {'online': False, 'location': 'Offline'})
|
presence = presence_data.get(username, {'online': False, 'location': 'Offline'})
|
||||||
@ -197,14 +219,24 @@ def format_stats_message(players_data, presence_data):
|
|||||||
if stats:
|
if stats:
|
||||||
raw_money = stats.get('money', 0) or 0
|
raw_money = stats.get('money', 0) or 0
|
||||||
raw_shards = stats.get('shards', 0) or 0
|
raw_shards = stats.get('shards', 0) or 0
|
||||||
|
raw_shards_int = int(raw_shards) if raw_shards else 0
|
||||||
try:
|
try:
|
||||||
total_money += int(raw_money)
|
total_money += int(raw_money)
|
||||||
spawners = int(raw_shards) // 1500
|
total_shards += raw_shards_int
|
||||||
|
spawners = raw_shards_int // 1500
|
||||||
total_spawners += spawners
|
total_spawners += spawners
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
spawners = 0
|
spawners = 0
|
||||||
|
raw_shards_int = 0
|
||||||
|
|
||||||
|
# Calculate time to next spawner
|
||||||
|
shards_in_progress = raw_shards_int % 1500
|
||||||
|
shards_to_next = 1500 - shards_in_progress
|
||||||
|
min_time_to_next = min(min_time_to_next, shards_to_next)
|
||||||
|
time_to_next_str = format_minutes_to_spawner(shards_to_next)
|
||||||
|
|
||||||
money = format_number(raw_money)
|
money = format_number(raw_money)
|
||||||
shards_display = f"{format_number(raw_shards)} ({spawners} <:spawner:1411753406070263958> )"
|
shards_display = f"{format_number(raw_shards)} ({spawners} <:spawner:1411753406070263958>) {time_to_next_str}"
|
||||||
else:
|
else:
|
||||||
money = shards_display = '❌'
|
money = shards_display = '❌'
|
||||||
|
|
||||||
@ -212,10 +244,15 @@ def format_stats_message(players_data, presence_data):
|
|||||||
col_money.append(money)
|
col_money.append(money)
|
||||||
col_shards.append(shards_display)
|
col_shards.append(shards_display)
|
||||||
|
|
||||||
|
# Use minimum time to next spawner from all players
|
||||||
|
if min_time_to_next == float('inf'):
|
||||||
|
min_time_to_next = 1500
|
||||||
|
min_time_to_next_str = format_minutes_to_spawner(min_time_to_next)
|
||||||
|
|
||||||
# Append totals after a divider line
|
# Append totals after a divider line
|
||||||
col_players.append("─────")
|
col_players.append("─────")
|
||||||
col_money.append(f"**{format_number(total_money)}**")
|
col_money.append(f"**{format_number(total_money)}**")
|
||||||
col_shards.append(f"**{total_spawners} <:spawner:1411753406070263958>**")
|
col_shards.append(f"**{total_spawners} <:spawner:1411753406070263958>** {min_time_to_next_str}")
|
||||||
|
|
||||||
def field(name, values, inline=True):
|
def field(name, values, inline=True):
|
||||||
return {"name": name, "value": "\n".join(values), "inline": inline}
|
return {"name": name, "value": "\n".join(values), "inline": inline}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user