Auto merge dev → main (#1258)

* meow

* updated it

* meow

* add avg TTL footer to /comp + extend freshness window to 90m when servers slow

---------

Co-authored-by: Clippii <clippii@protonmail.com>
This commit is contained in:
NotSoToothless
2026-05-17 12:58:48 -07:00
committed by GitHub
parent 5148a0c7bb
commit 47ae8b92f7
139 changed files with 44 additions and 49025 deletions
+41 -2
View File
@@ -493,6 +493,32 @@ async def comp(interaction: discord.Interaction, squadron_short: str):
)
squadron_short = squadron_short.upper()
# ── Avg TTL across the last 20 games globally ─────────────────────
# TTL = received_unix - endtime_unix: how long after a match ended
# the result was ingested. Not squadron-scoped — this is a server-wide
# signal, so when Gaijin is slow we can explain why no "recent" comps
# show up: the games we have are simply older than the freshness cap.
avg_ttl_seconds: Optional[int] = None
ttl_sample_size = 0
try:
ttl_stats = await get_recent_ttl_stats(limit=20)
avg_ttl_seconds = ttl_stats["avg_delay"]
ttl_sample_size = ttl_stats["sample_size"]
except Exception:
logging.exception("(COMP-CMD) Failed to compute TTL stats")
if avg_ttl_seconds is not None:
a_min, a_sec = divmod(avg_ttl_seconds, 60)
if avg_ttl_seconds > 3600:
ttl_icon = " 🚨"
elif avg_ttl_seconds > 600:
ttl_icon = " ⚠️"
else:
ttl_icon = ""
ttl_footer = f"Avg TTL (last {ttl_sample_size}): {a_min}m {a_sec:02d}s{ttl_icon}"
comp_footer = f"{comp_footer}\n{ttl_footer}" if comp_footer else ttl_footer
comp_dir = STORAGE_DIR / "COMPS"
squad_file = comp_dir / f"{squadron_short}.json"
if not squad_file.exists():
@@ -520,7 +546,14 @@ async def comp(interaction: discord.Interaction, squadron_short: str):
)
# Thresholds
threshold_seconds = 3600 # 1 hour
# Normal freshness window is 1h. When the server-wide avg TTL is high
# (>50m), recently played comps may not have been ingested yet — extend
# to 90m so users still see something, and flag any field past 60m with
# an alarm icon on the age line.
base_threshold_seconds = 3600 # 1 hour
extended_threshold_seconds = 5400 # 90 minutes
ttl_extended = avg_ttl_seconds is not None and avg_ttl_seconds > 3000
threshold_seconds = extended_threshold_seconds if ttl_extended else base_threshold_seconds
now_ts = int(time_module.time())
embed = discord.Embed(
@@ -610,11 +643,17 @@ async def comp(interaction: discord.Interaction, squadron_short: str):
comp_title = t(lang, "comp.comp_title", index=comp_index)
comp_index += 1
if age > base_threshold_seconds:
age_icon = ' 🚨'
elif age > 1200:
age_icon = ' ⚠️'
else:
age_icon = ''
embed.add_field(
name=comp_title,
value=(
#f"SQ Number {squad_key}\n"
t(lang, "comp.last_seen_label", timestamp=last_str, warning=' ⚠️' if age > 1200 else '') + "\n"
t(lang, "comp.last_seen_label", timestamp=last_str, warning=age_icon) + "\n"
+ t(lang, "comp.comp_label", notation=comp_notation) + "\n"
+ f"{block}"
),
+2 -1
View File
@@ -8,9 +8,9 @@ on configured intervals.
# Standard Library Imports
import asyncio
import os
import json
import logging
import os
import shutil
import time
from datetime import datetime, timezone
@@ -370,6 +370,7 @@ async def before_points_alarm_task():
await get_bot().wait_until_ready()
# ============================================================================
# REPLAY CLEANUP TASK
# ============================================================================