From 8e2f56df793c8e47e543e39dd0092492dd71d9ed Mon Sep 17 00:00:00 2001 From: NotSoToothless <67082114+FURRO404@users.noreply.github.com> Date: Thu, 14 May 2026 14:21:58 -0700 Subject: [PATCH] add TSS API endpoints + web proxy (#1234) Adds /api/tss/teams/* and /api/tss/leaderboard/teams to SREBOT/server.js, reading tss_battles.db and tss_teams.db with queries adapted to the team_id / team_name / teams_data schema. Mirrors the existing /api/squadrons/* endpoints. SREBOT/web/server.js gains matching proxy routes so the frontend can reach them via the website host. TSSBOT/BOT/storage.py picks up the columns and table the endpoints need to return meaningful data: teams_data.clanrating, team_members.points, and a new teams_points history table. All idempotent under the existing init_tss_dbs() call. Co-authored-by: Heidi Co-authored-by: Claude Opus 4.7 (1M context) --- BOT/storage.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/BOT/storage.py b/BOT/storage.py index bb2ae15..611dba0 100644 --- a/BOT/storage.py +++ b/BOT/storage.py @@ -137,6 +137,7 @@ CREATE TABLE IF NOT EXISTS teams_data ( members_json TEXT, captain_uid TEXT, guild_id TEXT, + clanrating INTEGER, created_unix INTEGER, updated_unix INTEGER ) @@ -154,6 +155,7 @@ CREATE TABLE IF NOT EXISTS team_members ( uid TEXT NOT NULL, nick TEXT, role TEXT NOT NULL DEFAULT 'player', + points INTEGER NOT NULL DEFAULT 0, joined_unix INTEGER, PRIMARY KEY (team_id, uid) ) @@ -180,6 +182,22 @@ _TEAM_NAME_HISTORY_INDEXES = [ ] +_TEAMS_POINTS_SQL = """ +CREATE TABLE IF NOT EXISTS teams_points ( + team_id INTEGER NOT NULL, + long_name TEXT, + unix_time INTEGER NOT NULL, + total_score INTEGER, + PRIMARY KEY (team_id, unix_time) +) +""" + +_TEAMS_POINTS_INDEXES = [ + "CREATE INDEX IF NOT EXISTS idx_teams_points_long_name ON teams_points(long_name COLLATE NOCASE)", + "CREATE INDEX IF NOT EXISTS idx_teams_points_unix_time ON teams_points(unix_time)", +] + + # --------------------------------------------------------------------------- # Init # --------------------------------------------------------------------------- @@ -215,9 +233,11 @@ async def _init_teams_db() -> None: await conn.execute(_TEAMS_DATA_SQL) await conn.execute(_TEAM_MEMBERS_SQL) await conn.execute(_TEAM_NAME_HISTORY_SQL) + await conn.execute(_TEAMS_POINTS_SQL) await _apply(conn, _TEAMS_DATA_INDEXES) await _apply(conn, _TEAM_MEMBERS_INDEXES) await _apply(conn, _TEAM_NAME_HISTORY_INDEXES) + await _apply(conn, _TEAMS_POINTS_INDEXES) await conn.commit()