dsh-qqbot-muu 0.1.15 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +168 -85
- package/client/qqbot-settings.js +13401 -12024
- package/config/modules.json +212 -0
- package/dist/channel-tools.js +21 -10
- package/dist/config.d.ts +14 -0
- package/dist/config.js +573 -449
- package/dist/features/contextless-store.js +247 -247
- package/dist/features/contextless-trim.js +455 -34
- package/dist/features/four-source.js +338 -336
- package/dist/features/group-join-request.js +289 -287
- package/dist/features/local-models.js +1494 -0
- package/dist/features/rotate-summarizer.js +438 -0
- package/dist/features/scenario-detect.js +321 -0
- package/dist/features/scheduler.js +8 -1
- package/dist/features/session-rotate.js +499 -0
- package/dist/features/session-title.js +199 -0
- package/dist/features/style-layer.js +501 -0
- package/dist/features/thinking-log.js +71 -69
- package/dist/gateway/bootstrap.js +1704 -1388
- package/dist/gateway/data-root.js +77 -3
- package/dist/gateway/middleware-setup.js +6 -3
- package/dist/index.js +4 -2
- package/dist/model/settings-reader.js +193 -102
- package/dist/session/session-manager.js +1730 -1587
- package/dist/shared/paths.js +128 -0
- package/dist/shared/settings-io.js +79 -0
- package/dist/transport/inbound.js +20 -1
- package/dist/transport/outbound.js +56 -4
- package/docs/RELEASE_CHECKLIST.md +24 -2
- package/dshqqbot/.qqbot-extensions/hooks/interview-panel.mjs +41 -1
- package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
- package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -689
- package/dshqqbot/.qqbot-extensions/inbound/ac-image-see.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
- package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
- package/dshqqbot/.qqbot-extensions/lib/.pet-form.json +1 -1
- package/dshqqbot/.qqbot-extensions/lib/draw-core.mjs +238 -7
- package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -394
- package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
- package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
- package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
- package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
- package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
- package/dshqqbot/.qqbot-extensions/lib/plugin-dir.mjs +14 -4
- package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
- package/dshqqbot/.qqbot-extensions/lib/vision.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
- package/dshqqbot/.qqbot-extensions/outbound/ac-media-fix.mjs +5 -1
- package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
- package/dshqqbot/.qqbot-extensions/outbound/split-reply.mjs +18 -2
- package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
- package/dshqqbot/.qqbot-extensions/tools/draw.mjs +22 -1
- package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
- package/dshqqbot/.qqbot-extensions/tools/pet_card.mjs +3 -2
- package/dshqqbot/.qqbot-extensions/tools/storyboard.mjs +3 -1
- package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
- package/package.json +119 -111
- package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
- package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
- package/scripts/_add_maintenance_cfg.py +20 -0
- package/scripts/_bench_keeplease.sh +10 -0
- package/scripts/_dbg_purge.py +15 -0
- package/scripts/_elev.sh +6 -0
- package/scripts/_fix_all_admin.cmd +16 -0
- package/scripts/_livecheck-image.mjs +33 -0
- package/scripts/_livecheck-llm.mjs +34 -0
- package/scripts/_livecheck-tts.mjs +37 -0
- package/scripts/_patch_curve.py +88 -0
- package/scripts/_patch_fan_thermal.py +24 -0
- package/scripts/_tag_tmp.py +13 -0
- package/scripts/adb-broker-client.mjs +87 -0
- package/scripts/adb-broker.mjs +205 -0
- package/scripts/ai-mode.cmd +6 -0
- package/scripts/ai-mode.py +387 -0
- package/scripts/ai-toolkit.py +607 -0
- package/scripts/apply-fan-gpu45.py +51 -0
- package/scripts/bench-fans.py +515 -0
- package/scripts/bench-load-direct.py +63 -0
- package/scripts/boot-tasks-hidden.vbs +20 -0
- package/scripts/boot-tasks.cmd +277 -0
- package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
- package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
- package/scripts/chat-archive/build-sft-v4.py +566 -0
- package/scripts/chat-archive/build-sft.py +390 -0
- package/scripts/chat-archive/eval-sft.py +155 -0
- package/scripts/chat-archive/extract-memory.py +143 -0
- package/scripts/chat-archive/inventory.py +182 -0
- package/scripts/chat-archive/merge-sft.py +114 -0
- package/scripts/chat-archive/qce-pull.py +217 -0
- package/scripts/chat-archive/qqheader.py +110 -0
- package/scripts/chat-archive/qqkey2.py +113 -0
- package/scripts/chat-archive/qqprobe.py +153 -0
- package/scripts/chat-archive/screen-collect.py +163 -0
- package/scripts/chat-archive/sqlcipher_probe.py +444 -0
- package/scripts/comfy_gen.py +209 -0
- package/scripts/compose-video.py +168 -0
- package/scripts/dl_models.py +45 -0
- package/scripts/draw-now.cmd +18 -0
- package/scripts/dsh-instance-guard.mjs +20 -2
- package/scripts/elev-extra.cmd +25 -0
- package/scripts/episode.py +529 -0
- package/scripts/fan-curve.py +218 -0
- package/scripts/fan-guard.cmd +8 -0
- package/scripts/fan-mode.py +380 -0
- package/scripts/fan_manual_safe.py +33 -0
- package/scripts/fan_restore_manual.py +46 -0
- package/scripts/fc_curves.py +359 -0
- package/scripts/fix-fan-and-timers.cmd +39 -0
- package/scripts/fix_admin_all.py +94 -0
- package/scripts/flows.mjs +224 -0
- package/scripts/gateway.cmd +126 -0
- package/scripts/gen-image.py +420 -0
- package/scripts/gen-video.py +186 -0
- package/scripts/git-askpass.cmd +2 -2
- package/scripts/gpu-mode.py +195 -0
- package/scripts/hw-profile.py +175 -0
- package/scripts/install-schedule.cmd +37 -0
- package/scripts/install-watch.cmd +29 -0
- package/scripts/matte-cutout.py +106 -0
- package/scripts/media-enhance.py +402 -0
- package/scripts/memory-audit.py +581 -0
- package/scripts/migrate-scope.mjs +140 -139
- package/scripts/model-registry.py +519 -0
- package/scripts/openid-audit.mjs +219 -0
- package/scripts/pull-gguf.py +127 -0
- package/scripts/purge-standby.py +151 -0
- package/scripts/qq-connect-login.py +133 -0
- package/scripts/qq-ip-sync-hidden.vbs +5 -0
- package/scripts/qq-ip-sync.py +300 -0
- package/scripts/qq-login-once.cmd +20 -0
- package/scripts/qq-login-qr.py +72 -0
- package/scripts/qq-whitelist-fix.cmd +27 -0
- package/scripts/qq-whitelist-login.cmd +26 -0
- package/scripts/qq-whitelist.cmd +12 -0
- package/scripts/qq-whitelist.py +1452 -0
- package/scripts/quality-compare.py +134 -0
- package/scripts/release-all.mjs +636 -430
- package/scripts/release-check.mjs +244 -226
- package/scripts/resume-coder.cmd +38 -0
- package/scripts/secure-room/index.html +334 -0
- package/scripts/secure-room/server.py +582 -0
- package/scripts/security-check.mjs +164 -0
- package/scripts/selftest-local-llm.mjs +20 -0
- package/scripts/selftest-local-models.mjs +754 -0
- package/scripts/selftest-rotate-style.mjs +308 -0
- package/scripts/shutdown-s5-optional.cmd +21 -0
- package/scripts/sleep-2325.cmd +75 -0
- package/scripts/start-comfyui.cmd +5 -0
- package/scripts/start-strata.cmd +17 -0
- package/scripts/start-strata.vbs +11 -0
- package/scripts/start-watch-hidden.vbs +3 -0
- package/scripts/stickers/auto-tag.mjs +161 -0
- package/scripts/storage.mjs +236 -0
- package/scripts/sync-plugin-copies.mjs +98 -23
- package/scripts/tests/test-qq-whitelist.py +192 -0
- package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
- package/scripts/train/gguf-quantize.py +92 -0
- package/scripts/train/gguf-to-hf.py +112 -0
- package/scripts/train/merge-lora.py +51 -0
- package/scripts/train/probe-mirrors.sh +12 -0
- package/scripts/train/probe-mirrors2.sh +20 -0
- package/scripts/train/setup-wsl.sh +23 -0
- package/scripts/train/setup-wsl2.sh +25 -0
- package/scripts/train/setup-wsl3.sh +22 -0
- package/scripts/train/setup-wsl4.sh +22 -0
- package/scripts/train/train-lora.py +319 -0
- package/scripts/vram-free.py +104 -0
- package/scripts/wechat-full-pull.mjs +1 -1
- package/settings-host.js +1047 -12
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""qq-ip-sync.py — 机器人 IP 白名单自愈(流程化,不再人工扫码/点控制台)
|
|
4
|
+
|
|
5
|
+
背景(2026-12-03):
|
|
6
|
+
· 家用宽带重播后出口 IP 变了(113.200.174.4 -> .15),机器人开始报
|
|
7
|
+
「接口访问源IP不在白名单」,DSH 里那套 `qq-whitelist.py --headless`
|
|
8
|
+
还在用旧控制台地址(/qqbot/dashboard/ 已 302 回首页),永远 rc=20。
|
|
9
|
+
· 现在改成「先探针、再开浏览器」:gateway 能调通就什么都不做(秒级);
|
|
10
|
+
调不通才打开新控制台(q.qq.com/qqbot/dashboard/manage/<appId>?sec=dev-settings),
|
|
11
|
+
把当前 IPv4 加进白名单,最后再用 gateway 复核。
|
|
12
|
+
|
|
13
|
+
子命令:
|
|
14
|
+
--print-ip 只打印当前 IPv4(给 bootstrap 的漂移检测用)
|
|
15
|
+
--sync 完整自愈(默认行为)
|
|
16
|
+
--check 只探 gateway,通=0 不通=3
|
|
17
|
+
|
|
18
|
+
退出码:0 正常 / 3 需要人工(控制台要登录)/ 4 浏览器或控制台失败 / 5 无 IPv4
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import time
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
BASE = Path(os.environ.get("QQBOT_REPO_ROOT") or Path(__file__).resolve().parent.parent)
|
|
31
|
+
LOGS = BASE / "logs"
|
|
32
|
+
NET = BASE / "data" / "net"
|
|
33
|
+
PROFILE = BASE / "data" / "edge-profile"
|
|
34
|
+
LOCK = BASE / "data" / "whitelist-run.lock"
|
|
35
|
+
APPLIED = NET / "whitelist-applied.txt"
|
|
36
|
+
SETTINGS = BASE / "data" / "harness" / "qqbot-settings" / "desktop" / "im-qqbot.json"
|
|
37
|
+
IP_APIS = ["http://ipv4.icanhazip.com", "http://ip.3322.net", "https://ipv4.ip.sb/ip"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def log(tag: str, msg: str) -> None:
|
|
41
|
+
line = f"{time.strftime('%Y-%m-%d %H:%M:%S')} [{tag}] {msg}"
|
|
42
|
+
print(line, flush=True)
|
|
43
|
+
try:
|
|
44
|
+
LOGS.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
with open(LOGS / "qq-ip-sync.log", "a", encoding="utf-8") as f:
|
|
46
|
+
f.write(line + "\n")
|
|
47
|
+
except Exception:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def creds() -> tuple[str, str]:
|
|
52
|
+
try:
|
|
53
|
+
raw = json.loads(SETTINGS.read_text("utf-8"))
|
|
54
|
+
except Exception:
|
|
55
|
+
return "", ""
|
|
56
|
+
found: dict = {}
|
|
57
|
+
|
|
58
|
+
def walk(o):
|
|
59
|
+
if isinstance(o, dict):
|
|
60
|
+
if "appId" in o and "appSecret" in o:
|
|
61
|
+
found.update(o)
|
|
62
|
+
for v in o.values():
|
|
63
|
+
walk(v)
|
|
64
|
+
elif isinstance(o, list):
|
|
65
|
+
for v in o:
|
|
66
|
+
walk(v)
|
|
67
|
+
|
|
68
|
+
walk(raw)
|
|
69
|
+
return str(found.get("appId") or ""), str(found.get("appSecret") or "")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def current_ipv4() -> str:
|
|
73
|
+
import requests
|
|
74
|
+
for u in IP_APIS:
|
|
75
|
+
try:
|
|
76
|
+
t = requests.get(u, timeout=8).text.strip().splitlines()[0].strip()
|
|
77
|
+
if t.count(".") == 3 and all(x.isdigit() for x in t.split(".")):
|
|
78
|
+
return t
|
|
79
|
+
except Exception:
|
|
80
|
+
continue
|
|
81
|
+
return ""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def token_of(app_id: str, secret: str) -> str:
|
|
85
|
+
import requests
|
|
86
|
+
r = requests.post("https://bots.qq.com/app/getAppAccessToken",
|
|
87
|
+
json={"appId": app_id, "clientSecret": secret}, timeout=15)
|
|
88
|
+
try:
|
|
89
|
+
return str(r.json().get("access_token") or "")
|
|
90
|
+
except Exception:
|
|
91
|
+
return ""
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def gateway_ok(app_id: str, token: str) -> tuple[bool, str]:
|
|
95
|
+
"""真正的判据:能调通 /gateway 就说明源 IP 已放行(401 只是 header 写法问题)"""
|
|
96
|
+
import requests
|
|
97
|
+
h = {"Authorization": "QQBot " + token, "X-Union-Appid": app_id}
|
|
98
|
+
try:
|
|
99
|
+
r = requests.get("https://api.sgroup.qq.com/gateway", headers=h, timeout=15)
|
|
100
|
+
if r.status_code == 200:
|
|
101
|
+
return True, "200"
|
|
102
|
+
if "白名单" in r.text or r.status_code == 401 and "源IP" in r.text:
|
|
103
|
+
return False, f"{r.status_code} {r.text[:120]}"
|
|
104
|
+
return False, f"{r.status_code} {r.text[:120]}"
|
|
105
|
+
except Exception as e:
|
|
106
|
+
return False, f"ERR {e}"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def kill_stale_edge() -> None:
|
|
110
|
+
ps = ("Get-CimInstance Win32_Process -Filter \"Name='msedge.exe'\" | "
|
|
111
|
+
"Where-Object { $_.CommandLine -like '*edge-profile*' } | "
|
|
112
|
+
"ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }")
|
|
113
|
+
subprocess.run(["powershell", "-NoProfile", "-Command", ps], capture_output=True)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def acquire_lock() -> bool:
|
|
117
|
+
try:
|
|
118
|
+
LOCK.parent.mkdir(parents=True, exist_ok=True)
|
|
119
|
+
if LOCK.exists():
|
|
120
|
+
try:
|
|
121
|
+
info = json.loads(LOCK.read_text("utf-8"))
|
|
122
|
+
except Exception:
|
|
123
|
+
info = {}
|
|
124
|
+
pid = int(info.get("pid") or 0)
|
|
125
|
+
if pid and pid != os.getpid():
|
|
126
|
+
try:
|
|
127
|
+
os.kill(pid, 0)
|
|
128
|
+
log("lock", f"已有白名单任务在跑(PID {pid}),本次退出")
|
|
129
|
+
return False
|
|
130
|
+
except OSError:
|
|
131
|
+
pass
|
|
132
|
+
LOCK.write_text(json.dumps({"pid": os.getpid(), "at": time.time()}), "utf-8")
|
|
133
|
+
return True
|
|
134
|
+
except Exception:
|
|
135
|
+
return True
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def release_lock() -> None:
|
|
139
|
+
try:
|
|
140
|
+
info = json.loads(LOCK.read_text("utf-8"))
|
|
141
|
+
if int(info.get("pid") or 0) == os.getpid():
|
|
142
|
+
LOCK.unlink()
|
|
143
|
+
except Exception:
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def add_ip_via_console(app_id: str, ip: str, timeout_manual: int = 180) -> tuple[bool, str]:
|
|
148
|
+
"""打开控制台把 IP 加进白名单。返回 (成功, 说明)"""
|
|
149
|
+
# 2026-12-04:playwright 不是插件的必装依赖。别的用户机器上没装时,旧代码
|
|
150
|
+
# 会抛 ModuleNotFoundError → rc 非 0 → 插件每隔一段时间重试一次自愈,
|
|
151
|
+
# 日志里只有一堆 traceback。这里直接给可执行的手工方案(IP 已经算好了)。
|
|
152
|
+
try:
|
|
153
|
+
from playwright.sync_api import sync_playwright
|
|
154
|
+
except Exception:
|
|
155
|
+
return (False,
|
|
156
|
+
"未安装 playwright(pip install playwright && playwright install msedge),"
|
|
157
|
+
"白名单自愈不可用;请手动把 %s 加入后台白名单:"
|
|
158
|
+
"https://q.qq.com/qqbot/dashboard/manage/%s?sec=dev-settings" % (ip, app_id))
|
|
159
|
+
|
|
160
|
+
url = f"https://q.qq.com/qqbot/dashboard/manage/{app_id}?sec=dev-settings"
|
|
161
|
+
for attempt, headless in enumerate((True, False)):
|
|
162
|
+
kill_stale_edge()
|
|
163
|
+
time.sleep(4)
|
|
164
|
+
ctx = None
|
|
165
|
+
try:
|
|
166
|
+
with sync_playwright() as p:
|
|
167
|
+
ctx = p.chromium.launch_persistent_context(
|
|
168
|
+
str(PROFILE), channel="msedge", headless=headless,
|
|
169
|
+
viewport={"width": 1440, "height": 900}, locale="zh-CN", timezone_id="Asia/Shanghai",
|
|
170
|
+
args=["--disable-blink-features=AutomationControlled", "--no-first-run"],
|
|
171
|
+
)
|
|
172
|
+
pg = ctx.pages[0] if ctx.pages else ctx.new_page()
|
|
173
|
+
pg.goto(url, wait_until="domcontentloaded", timeout=45000)
|
|
174
|
+
time.sleep(6 if headless else 9)
|
|
175
|
+
body = pg.inner_text("body")
|
|
176
|
+
if "我的机器人" not in body and "开发设置" not in body:
|
|
177
|
+
if headless:
|
|
178
|
+
log("console", "未登录(headless),改用有窗口模式再试一次")
|
|
179
|
+
ctx.close()
|
|
180
|
+
continue
|
|
181
|
+
log("console", f"仍未登录,需要人工在窗口里点一次头像授权(最多等 {timeout_manual}s)")
|
|
182
|
+
try:
|
|
183
|
+
pg.locator("text=QQ登录").first.click(timeout=5000)
|
|
184
|
+
except Exception:
|
|
185
|
+
pass
|
|
186
|
+
deadline = time.time() + timeout_manual
|
|
187
|
+
while time.time() < deadline:
|
|
188
|
+
time.sleep(4)
|
|
189
|
+
try:
|
|
190
|
+
if "我的机器人" in pg.inner_text("body") or "开发设置" in pg.inner_text("body"):
|
|
191
|
+
break
|
|
192
|
+
except Exception:
|
|
193
|
+
pass
|
|
194
|
+
else:
|
|
195
|
+
ctx.close()
|
|
196
|
+
return False, "需要人工登录控制台"
|
|
197
|
+
pg.goto(url, wait_until="domcontentloaded", timeout=45000)
|
|
198
|
+
time.sleep(7)
|
|
199
|
+
# 已经在白名单里就不用重复添加
|
|
200
|
+
if ip in pg.inner_text("body"):
|
|
201
|
+
log("console", f"{ip} 已在白名单中")
|
|
202
|
+
ctx.close()
|
|
203
|
+
return True, "already"
|
|
204
|
+
pg.locator("text=添加 IP").first.click(timeout=8000)
|
|
205
|
+
time.sleep(2)
|
|
206
|
+
pg.locator("input[placeholder='请输入 IPv4']").first.fill(ip)
|
|
207
|
+
time.sleep(1)
|
|
208
|
+
btns = pg.locator("button", has_text="添加")
|
|
209
|
+
clicked = False
|
|
210
|
+
for i in range(btns.count() - 1, -1, -1):
|
|
211
|
+
try:
|
|
212
|
+
b = btns.nth(i)
|
|
213
|
+
if b.is_visible():
|
|
214
|
+
b.click(timeout=4000)
|
|
215
|
+
clicked = True
|
|
216
|
+
break
|
|
217
|
+
except Exception:
|
|
218
|
+
continue
|
|
219
|
+
if not clicked:
|
|
220
|
+
ctx.close()
|
|
221
|
+
return False, "找不到「添加」按钮"
|
|
222
|
+
time.sleep(5)
|
|
223
|
+
body = pg.inner_text("body")
|
|
224
|
+
ok = ip in body
|
|
225
|
+
try:
|
|
226
|
+
pg.screenshot(path=str(LOGS / f"ip-sync-{time.strftime('%H%M%S')}.png"))
|
|
227
|
+
except Exception:
|
|
228
|
+
pass
|
|
229
|
+
ctx.close()
|
|
230
|
+
return ok, "added" if ok else "提交后未在页面看到该 IP"
|
|
231
|
+
except Exception as e:
|
|
232
|
+
try:
|
|
233
|
+
ctx and ctx.close()
|
|
234
|
+
except Exception:
|
|
235
|
+
pass
|
|
236
|
+
log("console", f"第 {attempt + 1} 次失败: {str(e)[:140]}")
|
|
237
|
+
return False, "浏览器两次都失败"
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def write_applied(ip: str) -> None:
|
|
241
|
+
try:
|
|
242
|
+
NET.mkdir(parents=True, exist_ok=True)
|
|
243
|
+
APPLIED.write_text(ip + "\n", "utf-8")
|
|
244
|
+
except Exception:
|
|
245
|
+
pass
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def main() -> int:
|
|
249
|
+
ap = argparse.ArgumentParser()
|
|
250
|
+
ap.add_argument("--print-ip", action="store_true")
|
|
251
|
+
ap.add_argument("--check", action="store_true")
|
|
252
|
+
ap.add_argument("--sync", action="store_true")
|
|
253
|
+
ap.add_argument("--manual-wait", type=int, default=180)
|
|
254
|
+
a = ap.parse_args()
|
|
255
|
+
|
|
256
|
+
ip = current_ipv4()
|
|
257
|
+
if a.print_ip:
|
|
258
|
+
print(ip)
|
|
259
|
+
return 0 if ip else 5
|
|
260
|
+
if not ip:
|
|
261
|
+
log("ip", "取不到 IPv4(网络异常)")
|
|
262
|
+
return 5
|
|
263
|
+
|
|
264
|
+
app_id, secret = creds()
|
|
265
|
+
if not app_id or not secret:
|
|
266
|
+
log("cred", "读不到 appId/appSecret,跳过")
|
|
267
|
+
return 4
|
|
268
|
+
|
|
269
|
+
if not acquire_lock():
|
|
270
|
+
return 0
|
|
271
|
+
try:
|
|
272
|
+
token = token_of(app_id, secret)
|
|
273
|
+
if not token:
|
|
274
|
+
log("token", "getAppAccessToken 失败(凭据或网络问题)")
|
|
275
|
+
return 4
|
|
276
|
+
ok, detail = gateway_ok(app_id, token)
|
|
277
|
+
log("probe", f"ip={ip} gateway={'OK' if ok else 'FAIL'} {detail}")
|
|
278
|
+
if ok:
|
|
279
|
+
write_applied(ip)
|
|
280
|
+
return 0
|
|
281
|
+
if a.check:
|
|
282
|
+
return 3
|
|
283
|
+
log("sync", f"{ip} 不在白名单 -> 打开控制台添加")
|
|
284
|
+
done, why = add_ip_via_console(app_id, ip, a.manual_wait)
|
|
285
|
+
log("console", f"{'成功' if done else '失败'}:{why}")
|
|
286
|
+
if not done:
|
|
287
|
+
return 3 if "人工" in why else 4
|
|
288
|
+
token = token_of(app_id, secret)
|
|
289
|
+
ok2, detail2 = gateway_ok(app_id, token)
|
|
290
|
+
log("verify", f"gateway={'OK' if ok2 else 'FAIL'} {detail2}")
|
|
291
|
+
if ok2:
|
|
292
|
+
write_applied(ip)
|
|
293
|
+
return 0
|
|
294
|
+
return 4
|
|
295
|
+
finally:
|
|
296
|
+
release_lock()
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
if __name__ == "__main__":
|
|
300
|
+
sys.exit(main())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM ============================================================================
|
|
3
|
+
REM QQ open-platform login helper (2026-12-01)
|
|
4
|
+
REM Opens the Edge window; scan the QR code with your phone once.
|
|
5
|
+
REM After login it automatically writes the current public IP into the bot
|
|
6
|
+
REM IP whitelist. Waits up to 10 minutes for the scan.
|
|
7
|
+
REM
|
|
8
|
+
REM Portable: repo root is derived from this script's location.
|
|
9
|
+
REM Python: QQBOT_PYTHON env > conda env if present > python on PATH.
|
|
10
|
+
REM ============================================================================
|
|
11
|
+
chcp 65001 >nul
|
|
12
|
+
setlocal
|
|
13
|
+
set "ROOT=%~dp0.."
|
|
14
|
+
if not defined QQBOT_PYTHON (
|
|
15
|
+
if exist "E:\Anaconda\envs\ai25\python.exe" (set "QQBOT_PYTHON=E:\Anaconda\envs\ai25\python.exe") else (set "QQBOT_PYTHON=python")
|
|
16
|
+
)
|
|
17
|
+
"%QQBOT_PYTHON%" -u "%ROOT%\scripts\qq-whitelist.py" --login
|
|
18
|
+
echo.
|
|
19
|
+
echo exit code: %ERRORLEVEL% (0=ok 10=not logged in 20=element missing 30=verify fail 40=network)
|
|
20
|
+
pause
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""qq-login-qr.py — 无人值守扫码登录:headless 打开 q.qq.com,截二维码图,等扫码,成功后跑白名单。
|
|
3
|
+
用法: python qq-login-qr.py [--wait 300] [--shot-dir F:\qqbot\logs\qq-whitelist-shots]
|
|
4
|
+
输出: 二维码截图路径(最后一行 "QR <path>"),扫码成功 "LOGIN ok",超时 "LOGIN timeout"
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
import argparse, sys, time
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
|
|
11
|
+
PROFILE = Path(r"F:\qqbot\data\edge-profile")
|
|
12
|
+
URL = "https://q.qq.com/#/"
|
|
13
|
+
|
|
14
|
+
def shot_dir_default() -> Path:
|
|
15
|
+
return Path(r"F:\qqbot\logs\qq-whitelist-shots")
|
|
16
|
+
|
|
17
|
+
def now_tag() -> str:
|
|
18
|
+
return datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
19
|
+
|
|
20
|
+
def logged_in(page) -> bool:
|
|
21
|
+
try:
|
|
22
|
+
html = page.content()
|
|
23
|
+
except Exception:
|
|
24
|
+
return False
|
|
25
|
+
marks = ["我的机器人", "开发设置", "服务器 IP 白名单", "机器人管理"]
|
|
26
|
+
hits = sum(1 for m in marks if m in html)
|
|
27
|
+
# 登录卡特征
|
|
28
|
+
not_login = ("QQ登录" in html) or ("扫码登录" in html) or ("密码登录" in html)
|
|
29
|
+
return hits >= 2 and not (not_login and hits < 3)
|
|
30
|
+
|
|
31
|
+
def main() -> int:
|
|
32
|
+
ap = argparse.ArgumentParser()
|
|
33
|
+
ap.add_argument("--wait", type=int, default=300)
|
|
34
|
+
ap.add_argument("--shot-dir", default=str(shot_dir_default()))
|
|
35
|
+
a = ap.parse_args()
|
|
36
|
+
sd = Path(a.shot_dir); sd.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
|
|
38
|
+
from playwright.sync_api import sync_playwright
|
|
39
|
+
with sync_playwright() as p:
|
|
40
|
+
ctx = p.chromium.launch_persistent_context(
|
|
41
|
+
str(PROFILE), headless=True, channel="msedge",
|
|
42
|
+
viewport={"width": 1440, "height": 900}, args=["--disable-blink-features=AutomationControlled"],
|
|
43
|
+
)
|
|
44
|
+
page = ctx.pages[0] if ctx.pages else ctx.new_page()
|
|
45
|
+
page.goto(URL, wait_until="domcontentloaded", timeout=60000)
|
|
46
|
+
try:
|
|
47
|
+
page.wait_for_selector("text=QQ登录", timeout=20000)
|
|
48
|
+
except Exception:
|
|
49
|
+
pass
|
|
50
|
+
time.sleep(1.5)
|
|
51
|
+
qr = sd / f"{now_tag()}-qr.png"
|
|
52
|
+
page.screenshot(path=str(qr), full_page=False)
|
|
53
|
+
print(f"QR {qr}", flush=True)
|
|
54
|
+
|
|
55
|
+
deadline = time.time() + a.wait
|
|
56
|
+
ok = False
|
|
57
|
+
while time.time() < deadline:
|
|
58
|
+
if logged_in(page):
|
|
59
|
+
ok = True; break
|
|
60
|
+
time.sleep(5)
|
|
61
|
+
if not ok:
|
|
62
|
+
print("LOGIN timeout", flush=True)
|
|
63
|
+
ctx.close(); return 10
|
|
64
|
+
print("LOGIN ok", flush=True)
|
|
65
|
+
final = sd / f"{now_tag()}-logged-in.png"
|
|
66
|
+
try: page.screenshot(path=str(final), full_page=False)
|
|
67
|
+
except Exception: pass
|
|
68
|
+
ctx.close()
|
|
69
|
+
return 0
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
sys.exit(main())
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM QQ whitelist: one-time login + update, in your normal desktop session.
|
|
3
|
+
REM step 1 (only when cookies expired): headful Edge opens, scan the QR once
|
|
4
|
+
REM step 2: headless run updates the server IP whitelist
|
|
5
|
+
REM Keep ASCII-only, and keep it location-independent (repo root = %~dp0..).
|
|
6
|
+
chcp 936 >nul
|
|
7
|
+
setlocal
|
|
8
|
+
set "ROOT=%~dp0.."
|
|
9
|
+
if not defined QQBOT_PYTHON (
|
|
10
|
+
if exist "E:\Anaconda\envs\ai25\python.exe" (set "QQBOT_PYTHON=E:\Anaconda\envs\ai25\python.exe") else (set "QQBOT_PYTHON=python")
|
|
11
|
+
)
|
|
12
|
+
set "S=%ROOT%\scripts\qq-whitelist.py"
|
|
13
|
+
echo ============================================================
|
|
14
|
+
echo QQ bot server-IP whitelist
|
|
15
|
+
echo 1) if you see a login page, scan the QR with the bot's QQ
|
|
16
|
+
echo 2) then it writes the current IPv4 into the whitelist
|
|
17
|
+
echo ============================================================
|
|
18
|
+
"%QQBOT_PYTHON%" -u "%S%" --login
|
|
19
|
+
set "RC1=%ERRORLEVEL%"
|
|
20
|
+
echo.
|
|
21
|
+
echo login step rc=%RC1% (0 ok / 10 still need login / 40 network)
|
|
22
|
+
"%QQBOT_PYTHON%" -u "%S%"
|
|
23
|
+
set "RC2=%ERRORLEVEL%"
|
|
24
|
+
echo.
|
|
25
|
+
echo update step rc=%RC2%
|
|
26
|
+
echo log: %ROOT%\logs\qq-whitelist.log
|
|
27
|
+
pause
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM qq-whitelist-login.cmd - one-click manual login for q.qq.com (then update IP whitelist)
|
|
3
|
+
REM Needs a real desktop session: an Edge window pops up, scan the QR with phone QQ.
|
|
4
|
+
REM Exit codes: 0 ok 10 need manual login 20 element missing 30 readback fail 40 network
|
|
5
|
+
chcp 936 >nul
|
|
6
|
+
setlocal
|
|
7
|
+
set "PY=E:\Anaconda\envsi25\python.exe"
|
|
8
|
+
set "SCRIPT=F:\qqbot\scripts\qq-whitelist.py"
|
|
9
|
+
set "PYTHONUTF8=1"
|
|
10
|
+
set "PYTHONIOENCODING=utf-8"
|
|
11
|
+
echo ============================================================
|
|
12
|
+
echo QQ whitelist - manual login helper
|
|
13
|
+
echo 1) an Edge window opens on https://q.qq.com/#/
|
|
14
|
+
echo 2) scan the QR with phone QQ (account MuU / ľ��)
|
|
15
|
+
echo 3) window is kept in front, screenshot every 20s, QR auto-refresh
|
|
16
|
+
echo 4) after login it continues to update the IP whitelist
|
|
17
|
+
echo ============================================================
|
|
18
|
+
"%PY%" -u "%SCRIPT%" --login --login-wait 300
|
|
19
|
+
set "RC=%ERRORLEVEL%"
|
|
20
|
+
echo.
|
|
21
|
+
echo exit code = %RC% (0 ok / 10 need login / 20 element missing / 30 readback / 40 network)
|
|
22
|
+
if "%RC%"=="10" echo still not logged in: run this file again, or check phone QQ can scan (account MuU)
|
|
23
|
+
if "%RC%"=="0" echo login + whitelist update finished, see F:\qqbot\logs\qq-whitelist.log
|
|
24
|
+
echo.
|
|
25
|
+
pause
|
|
26
|
+
endlocal & exit /b %RC%
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM qq-whitelist.cmd - wrapper for F:\qqbot\scripts\qq-whitelist.py
|
|
3
|
+
REM Exit codes: 0 ok/up-to-date 10 need manual login 20 element missing 30 verify failed 40 network/page failed
|
|
4
|
+
chcp 65001 >nul
|
|
5
|
+
setlocal
|
|
6
|
+
set "PY=E:\Anaconda\envs\ai25\python.exe"
|
|
7
|
+
set "SCRIPT=F:\qqbot\scripts\qq-whitelist.py"
|
|
8
|
+
set "PYTHONUTF8=1"
|
|
9
|
+
set "PYTHONIOENCODING=utf-8"
|
|
10
|
+
"%PY%" -u "%SCRIPT%" %*
|
|
11
|
+
set "RC=%ERRORLEVEL%"
|
|
12
|
+
endlocal & exit /b %RC%
|