"""Smoke test for the WeChat channel: capture, list chats, read pane, send text.""" import asyncio import logging import sys sys.path.insert(0, r"C:\Users\GuoAn\.dsh\wechat-bridge") from wechat_uia import WeChatChannel # noqa: E402 logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s") async def main() -> None: events: list[dict] = [] async def emit(event: dict) -> None: events.append(event) print("EVENT:", event["message"][0]["data"]["text"]) channel = WeChatChannel(emit, base_private=8_000_000_000_000, base_group=8_100_000_000_000, config={"self_id": 1461220927, "nickname": "小小糯"}) channel._ocr = None from winsdk.windows.globalization import Language from winsdk.windows.media.ocr import OcrEngine channel._ocr = OcrEngine.try_create_from_language(Language("zh-Hans-CN")) channel._ensure_window() img = await channel.snapshot() print("window:", channel.hwnd, "image:", None if img is None else img.size) rows = await channel.chat_rows(img) print("chats:", [(r["name"], r["y"]) for r in rows]) print("title:", await channel.chat_title(img)) print("badges:", channel.unread_rows(img)) msgs = await channel.read_pane(img) print("pane messages:", [(m["who"], m["text"][:30]) for m in msgs]) ok = await channel.open_chat("文件传输助手") print("open 文件传输助手:", ok, "current:", channel.current) result = await channel.send_text("文件传输助手", "微信桥测试 ping") print("send result:", result) asyncio.run(main())