42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""诊断:自己的 wxid、会话类型、最近消息 sender_id 结构"""
|
|
import sys, os, time
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
try:
|
|
os.system("chcp 65001 >nul 2>&1")
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
except Exception:
|
|
pass
|
|
|
|
from wechatauto.db import WeChatDB
|
|
|
|
db = WeChatDB()
|
|
info = db.get_self_info()
|
|
print("=== 自己 ===")
|
|
print("username:", info.get("username"))
|
|
print("nick_name:", info.get("nick_name"))
|
|
|
|
print("\n=== 会话列表(前 40 个,标注类型)===")
|
|
sessions = db.get_sessions(limit=40)
|
|
for s in sessions:
|
|
u = s["username"]
|
|
kind = "群聊" if u.endswith("@chatroom") else ("文件助手" if u == "filehelper" else "好友/其他")
|
|
print(f"[{kind}] {u} 未读={s['unread']} 摘要={ (s['summary'] or '')[:20]}")
|
|
|
|
print("\n=== 找 1 个好友会话,看最近 5 条消息的 sender_id 结构 ===")
|
|
for s in sessions:
|
|
u = s["username"]
|
|
if u.endswith("@chatroom") or u == "filehelper":
|
|
continue
|
|
msgs = db.get_messages(u, limit=5)
|
|
if not msgs:
|
|
continue
|
|
nick = db.get_nickname(u)
|
|
print(f"\n好友会话: {u} (昵称/备注={nick})")
|
|
for m in reversed(msgs):
|
|
sid = m["sender_id"]
|
|
me = "★自己" if (str(sid) == "2" or str(sid) == str(info.get("username"))) else "对方"
|
|
print(f" sender_id={sid!r} {me} | {m['type']} | {str(m['content'])[:30]}")
|
|
break
|