From 48f96ca8ff1bf922e07fa2f00b204f6ac77e06ca Mon Sep 17 00:00:00 2001 From: NotSoToothless <67082114+FURRO404@users.noreply.github.com> Date: Thu, 18 Jun 2026 01:02:59 -0700 Subject: [PATCH] =?UTF-8?q?Auto=20merge=20dev=20=E2=86=92=20main=20(#1332)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(tssbot): build_match_logs + match_logs persistence * feat(tssbot): create match_logs table and write logs at ingest * feat(tssbot): one-time match_logs backfill script * feat(srebot): persist chat/battle logs to match_logs (parity, no backfill) * feat(tssbot): Battle/Chat Log buttons on Discord scoreboards --- BOT/match_logs_store.py | 36 ++++++++++++++++++++++++++++++++++++ BOT/utils.py | 10 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 BOT/match_logs_store.py diff --git a/BOT/match_logs_store.py b/BOT/match_logs_store.py new file mode 100644 index 0000000..494d974 --- /dev/null +++ b/BOT/match_logs_store.py @@ -0,0 +1,36 @@ +"""match_logs table for sq_battles.db (SREBOT parity with TSSBOT). + +Stores pre-formatted chat/battle log string arrays keyed by hex session id, +matching how the rest of sq_battles.db keys match data. +""" +import json +import sqlite3 +import time + +MATCH_LOGS_SQL = """ +CREATE TABLE IF NOT EXISTS match_logs ( + session_id TEXT PRIMARY KEY, + chat_log_json TEXT, + battle_log_json TEXT, + built_unix INTEGER +) +""" + + +def upsert_match_logs_sync(db_path, session_id, chat_log, battle_log) -> None: + conn = sqlite3.connect(db_path) + try: + conn.execute(MATCH_LOGS_SQL) + conn.execute( + """INSERT INTO match_logs (session_id, chat_log_json, battle_log_json, built_unix) + VALUES (?, ?, ?, ?) + ON CONFLICT(session_id) DO UPDATE SET + chat_log_json=excluded.chat_log_json, + battle_log_json=excluded.battle_log_json, + built_unix=excluded.built_unix""", + (str(session_id), json.dumps(chat_log, ensure_ascii=False), + json.dumps(battle_log, ensure_ascii=False), int(time.time())), + ) + conn.commit() + finally: + conn.close() diff --git a/BOT/utils.py b/BOT/utils.py index 23cb5ad..a4ae738 100644 --- a/BOT/utils.py +++ b/BOT/utils.py @@ -1497,6 +1497,16 @@ def transform_to_local_format(api_data: Dict[str, Any]) -> Optional[Dict[str, An if loser_team_slot: team_slot_names[loser_team_slot] = loser_squadron + try: + from BOT.match_logs_store import upsert_match_logs_sync + from pathlib import Path as _Path + import os as _os + _sq = _Path(_os.environ["STORAGE_VOL_PATH"]) / "sq_battles.db" + if session_id_hex: + upsert_match_logs_sync(_sq, session_id_hex, chat_log, battle_log) + except Exception as _e: + logging.error(f"match_logs upsert failed for {session_id_hex}: {_e}") + return { "winning_team_squadron": winner_squadron, "losing_team_squadron": loser_squadron,