This commit is contained in:
xaoyaoo 2024-04-19 18:57:09 +08:00
parent 10c051a8a1
commit 173c87ea48

View File

@ -50,12 +50,15 @@ def save_session(session_file, wxid, arg, value):
except json.JSONDecodeError as e:
logging.error(f"Error decoding JSON file: {e}")
return False
if wxid not in session:
session[wxid] = {}
if not isinstance(session[wxid], dict):
session[wxid] = {}
session[wxid][arg] = value
try:
with open(session_file, 'w') as f:
json.dump(session, f, indent=4)
json.dump(session, f, indent=4, ensure_ascii=False)
except Exception as e:
logging.error(f"Error writing to file: {e}")
return False