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 <clippii@protonmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
NotSoToothless
2026-05-14 14:21:58 -07:00
committed by GitHub
parent e56951fcb2
commit 8e2f56df79
+20
View File
@@ -137,6 +137,7 @@ CREATE TABLE IF NOT EXISTS teams_data (
members_json TEXT, members_json TEXT,
captain_uid TEXT, captain_uid TEXT,
guild_id TEXT, guild_id TEXT,
clanrating INTEGER,
created_unix INTEGER, created_unix INTEGER,
updated_unix INTEGER updated_unix INTEGER
) )
@@ -154,6 +155,7 @@ CREATE TABLE IF NOT EXISTS team_members (
uid TEXT NOT NULL, uid TEXT NOT NULL,
nick TEXT, nick TEXT,
role TEXT NOT NULL DEFAULT 'player', role TEXT NOT NULL DEFAULT 'player',
points INTEGER NOT NULL DEFAULT 0,
joined_unix INTEGER, joined_unix INTEGER,
PRIMARY KEY (team_id, uid) 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 # Init
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -215,9 +233,11 @@ async def _init_teams_db() -> None:
await conn.execute(_TEAMS_DATA_SQL) await conn.execute(_TEAMS_DATA_SQL)
await conn.execute(_TEAM_MEMBERS_SQL) await conn.execute(_TEAM_MEMBERS_SQL)
await conn.execute(_TEAM_NAME_HISTORY_SQL) await conn.execute(_TEAM_NAME_HISTORY_SQL)
await conn.execute(_TEAMS_POINTS_SQL)
await _apply(conn, _TEAMS_DATA_INDEXES) await _apply(conn, _TEAMS_DATA_INDEXES)
await _apply(conn, _TEAM_MEMBERS_INDEXES) await _apply(conn, _TEAM_MEMBERS_INDEXES)
await _apply(conn, _TEAM_NAME_HISTORY_INDEXES) await _apply(conn, _TEAM_NAME_HISTORY_INDEXES)
await _apply(conn, _TEAMS_POINTS_INDEXES)
await conn.commit() await conn.commit()