dsh-qqbot-muu 0.1.20 → 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.
Files changed (92) hide show
  1. package/CHANGELOG.md +168 -154
  2. package/client/qqbot-settings.js +13401 -13380
  3. package/dist/config.js +573 -581
  4. package/dist/features/contextless-store.js +247 -247
  5. package/dist/features/four-source.js +338 -336
  6. package/dist/features/group-join-request.js +289 -287
  7. package/dist/features/local-models.js +1494 -1467
  8. package/dist/features/style-layer.js +501 -498
  9. package/dist/features/thinking-log.js +71 -69
  10. package/dist/gateway/bootstrap.js +1704 -1652
  11. package/dist/model/settings-reader.js +193 -102
  12. package/dist/shared/paths.js +128 -0
  13. package/dist/shared/settings-io.js +79 -83
  14. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  15. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -794
  16. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  17. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  18. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -444
  19. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  20. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  21. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  22. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  23. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  24. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  25. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  26. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  27. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  28. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  29. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  30. package/package.json +119 -118
  31. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  32. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  33. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  34. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  35. package/scripts/ai-toolkit.py +607 -478
  36. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  37. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  38. package/scripts/chat-archive/build-sft-v4.py +566 -0
  39. package/scripts/chat-archive/build-sft.py +390 -0
  40. package/scripts/chat-archive/eval-sft.py +155 -0
  41. package/scripts/chat-archive/extract-memory.py +143 -0
  42. package/scripts/chat-archive/inventory.py +182 -0
  43. package/scripts/chat-archive/merge-sft.py +114 -0
  44. package/scripts/chat-archive/qce-pull.py +217 -0
  45. package/scripts/chat-archive/qqheader.py +110 -0
  46. package/scripts/chat-archive/qqkey2.py +113 -0
  47. package/scripts/chat-archive/qqprobe.py +153 -0
  48. package/scripts/chat-archive/screen-collect.py +163 -0
  49. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  50. package/scripts/episode.py +529 -0
  51. package/scripts/fan-curve.py +218 -0
  52. package/scripts/fan-guard.cmd +8 -0
  53. package/scripts/fan-mode.py +380 -263
  54. package/scripts/gen-image.py +420 -413
  55. package/scripts/gen-video.py +186 -178
  56. package/scripts/hw-profile.py +175 -0
  57. package/scripts/media-enhance.py +402 -0
  58. package/scripts/memory-audit.py +581 -0
  59. package/scripts/migrate-scope.mjs +140 -139
  60. package/scripts/qq-connect-login.py +133 -0
  61. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  62. package/scripts/qq-ip-sync.py +300 -0
  63. package/scripts/qq-whitelist.py +71 -0
  64. package/scripts/release-all.mjs +636 -509
  65. package/scripts/release-check.mjs +244 -226
  66. package/scripts/secure-room/index.html +334 -0
  67. package/scripts/secure-room/server.py +582 -0
  68. package/scripts/stickers/auto-tag.mjs +161 -0
  69. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  70. package/scripts/train/gguf-quantize.py +92 -0
  71. package/scripts/train/gguf-to-hf.py +112 -0
  72. package/scripts/train/merge-lora.py +51 -0
  73. package/scripts/train/probe-mirrors.sh +12 -0
  74. package/scripts/train/probe-mirrors2.sh +20 -0
  75. package/scripts/train/setup-wsl.sh +23 -0
  76. package/scripts/train/setup-wsl2.sh +25 -0
  77. package/scripts/train/setup-wsl3.sh +22 -0
  78. package/scripts/train/setup-wsl4.sh +22 -0
  79. package/scripts/train/train-lora.py +319 -0
  80. package/dist/_backup_ctx_20261125_183653/dist/config.d.ts +0 -473
  81. package/dist/_backup_ctx_20261125_183653/dist/config.js +0 -450
  82. package/dist/_backup_ctx_20261125_183653/dist/features/contextless-trim.js +0 -304
  83. package/dist/_backup_ctx_20261125_183653/dist/session/session-manager.js +0 -1588
  84. package/dist/_backup_ctx_20261125_183653/dist/transport/inbound.js +0 -1567
  85. package/dist/_backup_ctx_20261125_183653/dist/transport/outbound.js +0 -647
  86. package/scripts/__pycache__/ai-mode.cpython-311.pyc +0 -0
  87. package/scripts/__pycache__/ai-toolkit.cpython-311.pyc +0 -0
  88. package/scripts/__pycache__/comfy_gen.cpython-311.pyc +0 -0
  89. package/scripts/__pycache__/gen-image.cpython-311.pyc +0 -0
  90. package/scripts/__pycache__/gen-video.cpython-311.pyc +0 -0
  91. package/scripts/__pycache__/model-registry.cpython-311.pyc +0 -0
  92. package/scripts/__pycache__/purge-standby.cpython-311.pyc +0 -0
@@ -1,139 +1,140 @@
1
- import { existsSync as __existsSync } from 'node:fs'
2
- const __repoRoot = (() => {
3
- let cached = ''
4
- const norm = (p) => String(p || '').split(String.fromCharCode(92)).join('/')
5
- return () => {
6
- if (cached) return cached
7
- const cands = []
8
- const env = String(process.env.QQBOT_ROOT || process.env.QQBOT_REPO_ROOT || '').trim()
9
- if (env) cands.push(norm(env))
10
- try {
11
- let here = decodeURIComponent(new URL('.', import.meta.url).pathname)
12
- if (here[0] === '/' && here[2] === ':') here = here.slice(1)
13
- here = norm(here).replace(/\/+$/, '')
14
- let d = here
15
- for (let i = 0; i < 6; i += 1) {
16
- if (!d) break
17
- cands.push(d)
18
- const k = d.lastIndexOf('/')
19
- d = k > 0 ? d.slice(0, k) : ''
20
- }
21
- } catch { /* noop */ }
22
- try { cands.push(norm(process.cwd())) } catch { /* noop */ }
23
- for (const c of cands) {
24
- try {
25
- if (c && (__existsSync(c + '/qqbot-mod/muu-shared.mjs') || __existsSync(c + '/dshqqbot'))) { cached = c; return cached }
26
- } catch { /* noop */ }
27
- }
28
- cached = norm(cands.find(Boolean) || '.')
29
- return cached
30
- }
31
- })()
32
- // 旧 scope 迁移:把历史上「按渠道形状」写的记忆并到「按人」的规范 scope。
33
- //
34
- // 背景(2026-11-13):写侧已经从 person-link 归一(wechat:<wxid> / c2c:<腕表id> → c2c:<personId>),
35
- // 但库里还留着旧 scope(例如把昵称当 id 的脏数据、wechat:<wxid> 私聊)。
36
- // 读侧 aliasesFor 已经能兜住一部分,这个脚本把存量真正改过来,避免同一件事记两遍。
37
- //
38
- // 默认 dry-run,只打印会改什么;确认后加 --apply 才写,写前自动备份 memory.db。
39
- //
40
- // 用法:
41
- // node F:\qqbot\scripts\migrate-scope.mjs
42
- // node F:\qqbot\scripts\migrate-scope.mjs --apply
43
- // 可选 --db <memory.db 路径>(默认 F:/qqbot/dshqqbot/.qqbot/memory.db)
44
- // 可选 --data-root <机器人数据根>(默认 F:/qqbot/dshqqbot)
45
-
46
- import { existsSync, copyFileSync, statSync } from 'node:fs'
47
- import { join } from 'node:path'
48
- import { createRequire } from 'node:module'
49
-
50
- const require = createRequire(import.meta.url)
51
- const { DatabaseSync } = require('node:sqlite')
52
-
53
- const argv = process.argv.slice(2)
54
- const APPLY = argv.includes('--apply')
55
- const argOf = (k, d) => {
56
- const i = argv.indexOf(k)
57
- return i >= 0 && argv[i + 1] ? argv[i + 1] : d
58
- }
59
- const DATA_ROOT = argOf('--data-root', __repoRoot() + "/dshqqbot")
60
- const DB = argOf('--db', join(DATA_ROOT, '.qqbot', 'memory.db'))
61
-
62
- const { loadPeople } = await import(pathToFileURL(join(__repoRoot(), "dshqqbot/.qqbot-extensions/lib/person-link.mjs")).href)
63
-
64
- if (!existsSync(DB)) {
65
- console.error(`找不到库:${DB}`)
66
- process.exit(1)
67
- }
68
-
69
- const reg = loadPeople(DATA_ROOT)
70
- /** 老 scope → 新 scope(只改 c2c:/wechat: 私聊;群和 __global__ 不动) */
71
- function targetOf(scope) {
72
- const s = String(scope || '')
73
- if (!/^(c2c|wechat):/.test(s)) return ''
74
- if (s.includes('@chatroom') || s.includes('@gid')) return ''
75
- const p = reg.byAlias.get(s) || reg.byAlias.get(`c2c:${s.replace(/^[a-z]+:/, '')}`)
76
- if (!p || !p.scope || p.scope === s) return ''
77
- return p.scope
78
- }
79
-
80
- const db = new DatabaseSync(DB, { readOnly: !APPLY })
81
- // 只动「带 scope 列」的表,动态发现,避免漏掉以后新加的表
82
- const tables = db.prepare("select name, sql from sqlite_master where type = ?").all('table')
83
- .map((t) => String(t.name))
84
- .filter((n) => {
85
- if (n.startsWith('sqlite_')) return false
86
- try {
87
- return db.prepare(`pragma table_info("${n}")`).all().some((c) => c.name === 'scope')
88
- } catch { return false }
89
- })
90
-
91
- console.log(`库:${DB}`)
92
- console.log(`表:${tables.join(', ')}`)
93
- console.log(APPLY ? '模式:APPLY(会写库)' : '模式:dry-run(只看不改,加 --apply 才写)')
94
-
95
- const plan = []
96
- for (const t of tables) {
97
- const rows = db.prepare(`select scope, count(*) n from "${t}" group by scope`).all()
98
- for (const r of rows) {
99
- const to = targetOf(r.scope)
100
- if (!to) continue
101
- plan.push({ table: t, from: String(r.scope), to, n: Number(r.n) || 0 })
102
- }
103
- }
104
-
105
- if (!plan.length) {
106
- console.log('没有需要迁移的 scope。')
107
- db.close()
108
- process.exit(0)
109
- }
110
- for (const p of plan) console.log(` ${p.table}: ${p.from} → ${p.to}(${p.n} 行)`)
111
-
112
- if (!APPLY) {
113
- console.log(`\n共 ${plan.length} 组。确认后加 --apply 执行(会先备份)。`)
114
- db.close()
115
- process.exit(0)
116
- }
117
-
118
- // 备份:同一秒内多次跑也不覆盖
119
- const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)
120
- const bak = `${DB}.bak-${stamp}`
121
- copyFileSync(DB, bak)
122
- console.log(`已备份 → ${bak}(${Math.round(statSync(bak).size / 1024)} KB)`)
123
-
124
- db.exec('begin')
125
- try {
126
- for (const p of plan) {
127
- // 同表同组只跑一次(scope 分布已按组聚合)
128
- const r = db.prepare(`update "${p.table}" set scope = ? where scope = ?`).run(p.to, p.from)
129
- console.log(` ✓ ${p.table}: ${p.from} → ${p.to}(${Number(r.changes) || 0} 行)`)
130
- }
131
- db.exec('commit')
132
- console.log('\n迁移完成。重启 DSH 后生效。')
133
- } catch (e) {
134
- try { db.exec('rollback') } catch { /* ignore */ }
135
- console.error(`迁移失败,已回滚:${e?.message ?? e}`)
136
- process.exitCode = 1
137
- } finally {
138
- db.close()
139
- }
1
+ import { existsSync as __existsSync } from 'node:fs'
2
+ const __repoRoot = (() => {
3
+ let cached = ''
4
+ const norm = (p) => String(p || '').split(String.fromCharCode(92)).join('/')
5
+ return () => {
6
+ if (cached) return cached
7
+ const cands = []
8
+ const env = String(process.env.QQBOT_ROOT || process.env.QQBOT_REPO_ROOT || '').trim()
9
+ if (env) cands.push(norm(env))
10
+ try {
11
+ let here = decodeURIComponent(new URL('.', import.meta.url).pathname)
12
+ if (here[0] === '/' && here[2] === ':') here = here.slice(1)
13
+ here = norm(here).replace(/\/+$/, '')
14
+ let d = here
15
+ for (let i = 0; i < 6; i += 1) {
16
+ if (!d) break
17
+ cands.push(d)
18
+ const k = d.lastIndexOf('/')
19
+ d = k > 0 ? d.slice(0, k) : ''
20
+ }
21
+ } catch { /* noop */ }
22
+ try { cands.push(norm(process.cwd())) } catch { /* noop */ }
23
+ for (const c of cands) {
24
+ try {
25
+ if (c && (__existsSync(c + '/qqbot-mod/muu-shared.mjs') || __existsSync(c + '/dshqqbot'))) { cached = c; return cached }
26
+ } catch { /* noop */ }
27
+ }
28
+ cached = norm(cands.find(Boolean) || '.')
29
+ return cached
30
+ }
31
+ })()
32
+ // 旧 scope 迁移:把历史上「按渠道形状」写的记忆并到「按人」的规范 scope。
33
+ //
34
+ // 背景(2026-11-13):写侧已经从 person-link 归一(wechat:<wxid> / c2c:<腕表id> → c2c:<personId>),
35
+ // 但库里还留着旧 scope(例如把昵称当 id 的脏数据、wechat:<wxid> 私聊)。
36
+ // 读侧 aliasesFor 已经能兜住一部分,这个脚本把存量真正改过来,避免同一件事记两遍。
37
+ //
38
+ // 默认 dry-run,只打印会改什么;确认后加 --apply 才写,写前自动备份 memory.db。
39
+ //
40
+ // 用法:
41
+ // node F:\qqbot\scripts\migrate-scope.mjs
42
+ // node F:\qqbot\scripts\migrate-scope.mjs --apply
43
+ // 可选 --db <memory.db 路径>(默认 F:/qqbot/dshqqbot/.qqbot/memory.db)
44
+ // 可选 --data-root <机器人数据根>(默认 F:/qqbot/dshqqbot)
45
+
46
+ import { existsSync, copyFileSync, statSync } from 'node:fs'
47
+ import { join } from 'node:path'
48
+ import { pathToFileURL } from 'node:url'
49
+ import { createRequire } from 'node:module'
50
+
51
+ const require = createRequire(import.meta.url)
52
+ const { DatabaseSync } = require('node:sqlite')
53
+
54
+ const argv = process.argv.slice(2)
55
+ const APPLY = argv.includes('--apply')
56
+ const argOf = (k, d) => {
57
+ const i = argv.indexOf(k)
58
+ return i >= 0 && argv[i + 1] ? argv[i + 1] : d
59
+ }
60
+ const DATA_ROOT = argOf('--data-root', __repoRoot() + "/dshqqbot")
61
+ const DB = argOf('--db', join(DATA_ROOT, '.qqbot', 'memory.db'))
62
+
63
+ const { loadPeople } = await import(pathToFileURL(join(__repoRoot(), "dshqqbot/.qqbot-extensions/lib/person-link.mjs")).href)
64
+
65
+ if (!existsSync(DB)) {
66
+ console.error(`找不到库:${DB}`)
67
+ process.exit(1)
68
+ }
69
+
70
+ const reg = loadPeople(DATA_ROOT)
71
+ /** 老 scope → 新 scope(只改 c2c:/wechat: 私聊;群和 __global__ 不动) */
72
+ function targetOf(scope) {
73
+ const s = String(scope || '')
74
+ if (!/^(c2c|wechat):/.test(s)) return ''
75
+ if (s.includes('@chatroom') || s.includes('@gid')) return ''
76
+ const p = reg.byAlias.get(s) || reg.byAlias.get(`c2c:${s.replace(/^[a-z]+:/, '')}`)
77
+ if (!p || !p.scope || p.scope === s) return ''
78
+ return p.scope
79
+ }
80
+
81
+ const db = new DatabaseSync(DB, { readOnly: !APPLY })
82
+ // 只动「带 scope 列」的表,动态发现,避免漏掉以后新加的表
83
+ const tables = db.prepare("select name, sql from sqlite_master where type = ?").all('table')
84
+ .map((t) => String(t.name))
85
+ .filter((n) => {
86
+ if (n.startsWith('sqlite_')) return false
87
+ try {
88
+ return db.prepare(`pragma table_info("${n}")`).all().some((c) => c.name === 'scope')
89
+ } catch { return false }
90
+ })
91
+
92
+ console.log(`库:${DB}`)
93
+ console.log(`表:${tables.join(', ')}`)
94
+ console.log(APPLY ? '模式:APPLY(会写库)' : '模式:dry-run(只看不改,加 --apply 才写)')
95
+
96
+ const plan = []
97
+ for (const t of tables) {
98
+ const rows = db.prepare(`select scope, count(*) n from "${t}" group by scope`).all()
99
+ for (const r of rows) {
100
+ const to = targetOf(r.scope)
101
+ if (!to) continue
102
+ plan.push({ table: t, from: String(r.scope), to, n: Number(r.n) || 0 })
103
+ }
104
+ }
105
+
106
+ if (!plan.length) {
107
+ console.log('没有需要迁移的 scope。')
108
+ db.close()
109
+ process.exit(0)
110
+ }
111
+ for (const p of plan) console.log(` ${p.table}: ${p.from} → ${p.to}(${p.n} 行)`)
112
+
113
+ if (!APPLY) {
114
+ console.log(`\n共 ${plan.length} 组。确认后加 --apply 执行(会先备份)。`)
115
+ db.close()
116
+ process.exit(0)
117
+ }
118
+
119
+ // 备份:同一秒内多次跑也不覆盖
120
+ const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)
121
+ const bak = `${DB}.bak-${stamp}`
122
+ copyFileSync(DB, bak)
123
+ console.log(`已备份 → ${bak}(${Math.round(statSync(bak).size / 1024)} KB)`)
124
+
125
+ db.exec('begin')
126
+ try {
127
+ for (const p of plan) {
128
+ // 同表同组只跑一次(scope 分布已按组聚合)
129
+ const r = db.prepare(`update "${p.table}" set scope = ? where scope = ?`).run(p.to, p.from)
130
+ console.log(` ✓ ${p.table}: ${p.from} → ${p.to}(${Number(r.changes) || 0} 行)`)
131
+ }
132
+ db.exec('commit')
133
+ console.log('\n迁移完成。重启 DSH 后生效。')
134
+ } catch (e) {
135
+ try { db.exec('rollback') } catch { /* ignore */ }
136
+ console.error(`迁移失败,已回滚:${e?.message ?? e}`)
137
+ process.exitCode = 1
138
+ } finally {
139
+ db.close()
140
+ }
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """qq-connect-login.py — 打开机器人的新控制台(connect.qq.com/open-platform)并等待登录
4
+
5
+ 背景(2026-12-03):旧控制台 https://q.qq.com/qqbot/dashboard/ 已经全部 302 回首页,
6
+ 脚本里"找机器人列表"的逻辑永远失败(rc=20)。机器人管理迁到了 connect.qq.com 的
7
+ 「AI 开发者管理平台」,而且这个域要单独登录一次。
8
+
9
+ 这个脚本只做两件事:
10
+ 1. 用专用 profile 打开新控制台,若未登录就点「立即登录」(扫码由本人完成,无法代劳);
11
+ 2. 登录成功后把控制台结构和截图 dump 到 logs,供下一步自动改 IP 白名单用。
12
+
13
+ 用法:python scripts/qq-connect-login.py [--wait 600]
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import json
19
+ import os
20
+ import time
21
+ from pathlib import Path
22
+
23
+ BASE = Path(os.environ.get("QQBOT_REPO_ROOT") or Path(__file__).resolve().parent.parent)
24
+ PROFILE = BASE / "data" / "edge-profile"
25
+ LOGS = BASE / "logs"
26
+ SHOTS = LOGS / "qq-connect-shots"
27
+ HOME = "https://connect.qq.com/open-platform/home"
28
+
29
+
30
+ def log(tag: str, msg: str) -> None:
31
+ line = f"{time.strftime('%Y-%m-%d %H:%M:%S')} [{tag}] {msg}"
32
+ print(line, flush=True)
33
+ try:
34
+ LOGS.mkdir(parents=True, exist_ok=True)
35
+ with open(LOGS / "qq-connect.log", "a", encoding="utf-8") as f:
36
+ f.write(line + "\n")
37
+ except Exception:
38
+ pass
39
+
40
+
41
+ def shot(page, tag: str) -> str:
42
+ SHOTS.mkdir(parents=True, exist_ok=True)
43
+ p = SHOTS / f"{time.strftime('%Y%m%d-%H%M%S')}-{tag}.png"
44
+ try:
45
+ page.screenshot(path=str(p))
46
+ except Exception:
47
+ pass
48
+ return str(p)
49
+
50
+
51
+ def main() -> int:
52
+ ap = argparse.ArgumentParser()
53
+ ap.add_argument("--wait", type=int, default=600)
54
+ a = ap.parse_args()
55
+
56
+ from playwright.sync_api import sync_playwright
57
+
58
+ with sync_playwright() as p:
59
+ ctx = p.chromium.launch_persistent_context(
60
+ str(PROFILE), channel="msedge", headless=False,
61
+ viewport={"width": 1440, "height": 900}, locale="zh-CN", timezone_id="Asia/Shanghai",
62
+ args=["--disable-blink-features=AutomationControlled", "--no-first-run", "--start-maximized"],
63
+ )
64
+ page = ctx.pages[0] if ctx.pages else ctx.new_page()
65
+ page.set_default_timeout(15000)
66
+ try:
67
+ page.goto(HOME, wait_until="domcontentloaded", timeout=45000)
68
+ page.wait_for_timeout(3000)
69
+ body = page.inner_text("body")
70
+ if "请先登录" in body or "登录后即可" in body:
71
+ log("login", "未登录,点击「立即登录」——请用手机 QQ 扫码(只需这一次)")
72
+ try:
73
+ page.locator("text=立即登录").first.click(timeout=6000)
74
+ except Exception as e:
75
+ log("login", f"点登录失败: {e}")
76
+ page.wait_for_timeout(4000)
77
+ try:
78
+ page.evaluate("window.focus()")
79
+ except Exception:
80
+ pass
81
+ shot(page, "need-scan")
82
+ deadline = time.time() + a.wait
83
+ nxt = time.time() + 20
84
+ while time.time() < deadline:
85
+ try:
86
+ if len(ctx.pages) > 1:
87
+ page = ctx.pages[-1]
88
+ txt = page.inner_text("body")
89
+ if "请先登录" not in txt and "登录后即可" not in txt and "扫码" not in txt:
90
+ log("login", f"LOGIN_OK url={page.url}")
91
+ break
92
+ except Exception:
93
+ pass
94
+ if time.time() >= nxt:
95
+ shot(page, "wait")
96
+ log("login", f"等待扫码… 还剩 {int(deadline - time.time())}s")
97
+ nxt = time.time() + 25
98
+ page.wait_for_timeout(1500)
99
+ else:
100
+ log("login", "等待超时,未登录")
101
+ return 10
102
+ else:
103
+ log("login", "已经是登录状态")
104
+
105
+ # 登录后:把控制台结构摸出来(下一步据此自动改 IP 白名单)
106
+ try:
107
+ pages = [x.url for x in ctx.pages]
108
+ log("page", "当前标签页: " + json.dumps(pages, ensure_ascii=False))
109
+ page.goto("https://connect.qq.com/open-platform/home", wait_until="domcontentloaded", timeout=40000)
110
+ page.wait_for_timeout(5000)
111
+ txt = page.inner_text("body")
112
+ log("page", f"url={page.url}")
113
+ log("page", "TEXT=" + txt[:600].replace("\n", " | "))
114
+ hrefs = page.eval_on_selector_all("a", "els => els.map(e => (e.getAttribute('href')||'') + ' :: ' + (e.innerText||'').trim().slice(0,24))")
115
+ seen, uniq = set(), []
116
+ for h in hrefs:
117
+ if h and h not in seen:
118
+ seen.add(h)
119
+ uniq.append(h)
120
+ log("page", "LINKS=" + json.dumps(uniq[:30], ensure_ascii=False))
121
+ log("shot", shot(page, "console"))
122
+ except Exception as e:
123
+ log("page", f"dump 控制台失败: {e}")
124
+ return 0
125
+ finally:
126
+ try:
127
+ ctx.close()
128
+ except Exception:
129
+ pass
130
+
131
+
132
+ if __name__ == "__main__":
133
+ raise SystemExit(main())
@@ -0,0 +1,5 @@
1
+ ' 开机静默自检:出口 IP 变了就自动改机器人白名单(不弹窗、不扫码)
2
+ ' 由 Startup 文件夹的快捷方式在登录时调用;失败只写 logs\qq-ip-sync.log
3
+ Set sh = CreateObject("WScript.Shell")
4
+ sh.CurrentDirectory = "F:\qqbot"
5
+ sh.Run """E:\Anaconda\envs\ai25\python.exe"" -u ""F:\qqbot\scripts\qq-ip-sync.py"" --sync", 0, False