From 9b992d6dbecad6d5d350756d2013089b1586272c Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 12 Sep 2026 22:12:21 -0500 Subject: [PATCH] fix: persist user guild map when login token is registered user_guild_map was only written when a login token was consumed on the webui login page. Users on stale session cookies never re-login, so their jobs carried empty guild_id and TTS was posted to whatever global channel happened to match instead of the server they logged in from. Persist the guild as soon as the bot registers the token so _resolve_guild_id() falls back to the correct login guild. --- ttstoy/webui/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ttstoy/webui/app.py b/ttstoy/webui/app.py index f0b4b9b..b515a90 100644 --- a/ttstoy/webui/app.py +++ b/ttstoy/webui/app.py @@ -1248,6 +1248,17 @@ def api_register_token(): data.get("guild_id", ""), data.get("guild_name", ""), ) + guild_id = data.get("guild_id", "") + if guild_id: + try: + state = _read_json(SHARED_STATE_FILE) if SHARED_STATE_FILE.exists() else {} + ugm = state.setdefault("user_guild_map", {}) + ugm[str(data["user_id"])] = guild_id + with open(SHARED_STATE_FILE, "w") as f: + json.dump(state, f) + log.debug(f"api_register_token: persisted user_guild_map[{data['user_id']}]={guild_id}") + except Exception as e: + log.warning(f"api_register_token: could not persist user_guild_map: {e}") return jsonify({"token": token})