48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""会话身份从「像素哈希」换成「昵称 md5」,旧键再也匹配不上,全部作废重建。
|
|
|
|
留着不清的后果就是日志里那个循环:待回复恢复找到一堆旧任务 → 按旧指纹去开 →
|
|
「实际打开对象与目标不一致」→ 任务留在队列里,下一轮再来一遍,真正的新消息
|
|
被挤在后面。原文件都留 .bak。
|
|
"""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import time
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
STAMP = time.strftime("%Y%m%d_%H%M%S")
|
|
|
|
TARGETS = {
|
|
"pending_replies.json": {"pending": {}},
|
|
"unrepliable_sessions.json": {},
|
|
"conversations.json": {},
|
|
"false_pos_cache.json": {},
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
for name, empty in TARGETS.items():
|
|
path = os.path.join(ROOT, name)
|
|
if not os.path.exists(path):
|
|
print(f" {name:28} 不存在,跳过")
|
|
continue
|
|
size = os.path.getsize(path)
|
|
try:
|
|
with open(path, encoding="utf-8") as handle:
|
|
data = json.load(handle)
|
|
count = len(data.get("pending", data)) if isinstance(data, dict) else 0
|
|
except Exception:
|
|
count = -1
|
|
if size > 2:
|
|
shutil.copy2(path, f"{path}.{STAMP}.bak")
|
|
with open(path, "w", encoding="utf-8") as handle:
|
|
json.dump(empty, handle, ensure_ascii=False, indent=2)
|
|
print(f" {name:28} 清空(原有 {count} 条,{size} 字节,已备份)")
|
|
|
|
print()
|
|
print("旧身份数据已作废。下一轮监听会按昵称重新建立会话身份和档案。")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|