Auto merge dev → main (#1332)
* 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
This commit is contained in:
@@ -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()
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user