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()
|
||||
Reference in New Issue
Block a user