docs: restructure markdown docs and publish the bridge
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Probe obmux: connect like DSH does, print events, optionally send a WeChat text."""
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
from websockets.asyncio.client import connect
|
||||
|
||||
CONFIG = json.load(open(r"C:\Users\GuoAn\.dsh\wechat-bridge\config.json", encoding="utf-8"))
|
||||
|
||||
|
||||
def uid_of(name: str) -> int:
|
||||
return 8_000_000_000_000 + (zlib.crc32(name.encode("utf-8")) % 1_000_000)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
target = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
text = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||
headers = {"Authorization": f"Bearer {CONFIG['token']}"}
|
||||
async with connect(f"ws://127.0.0.1:{CONFIG['listen_port']}", additional_headers=headers) as ws:
|
||||
print("connected")
|
||||
if target and text:
|
||||
payload = {
|
||||
"action": "send_private_msg",
|
||||
"params": {"user_id": uid_of(target), "message": [{"type": "text", "data": {"text": text}}]},
|
||||
"echo": "probe-1",
|
||||
}
|
||||
await ws.send(json.dumps(payload, ensure_ascii=False))
|
||||
deadline = asyncio.get_running_loop().time() + 12
|
||||
while asyncio.get_running_loop().time() < deadline:
|
||||
try:
|
||||
raw = await asyncio.wait_for(ws.recv(), timeout=deadline - asyncio.get_running_loop().time())
|
||||
except asyncio.TimeoutError:
|
||||
break
|
||||
msg = json.loads(raw)
|
||||
print("<-", json.dumps(msg, ensure_ascii=False)[:300])
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user