qq-bot-roost 1.1.3 → 1.1.5
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/README.md +9 -5
- package/package.json +3 -3
- package/src/bot.js +13 -7
- package/src/main.js +5 -1
- package/src/onebot/keep.js +33 -0
- package/web/app.js +81 -25
- package/web/index.html +11 -0
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
<img src="https://img.shields.io/badge/Node.js-22.13%2B-339933?logo=node.js&logoColor=white" alt="Node.js 22.13+">
|
|
10
10
|
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="零依赖">
|
|
11
|
-
<img src="https://img.shields.io/badge/tests-
|
|
11
|
+
<img src="https://img.shields.io/badge/tests-1289%20passed-brightgreen" alt="测试 1289 项">
|
|
12
12
|
<img src="https://img.shields.io/badge/plugins-JS%20%7C%20Python%20%7C%20Go%20%7C%20any-blue" alt="多语言插件">
|
|
13
|
-
<img src="https://img.shields.io/badge/version-1.1.
|
|
13
|
+
<img src="https://img.shields.io/badge/version-1.1.5-blueviolet" alt="版本 1.1.5">
|
|
14
14
|
<img src="https://img.shields.io/badge/license-AGPL--3.0--only-blue" alt="AGPL-3.0-only">
|
|
15
15
|
<a href="https://github.com/tdcq9594/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/tdcq9594/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
|
|
16
16
|
|
|
@@ -185,6 +185,10 @@ node -v # 需要 >= 22.13
|
|
|
185
185
|
2. 「开发设置」里拿到 **AppID** 和 **AppSecret**
|
|
186
186
|
3. **关键**:「功能配置」里开通 **群聊** 能力,否则连接会被拒(关闭码 4014)
|
|
187
187
|
|
|
188
|
+
**换凭证(1.1.4+)**:AppSecret 被开放平台重置、或者整只机器人换了账号时,
|
|
189
|
+
进面板「**配置 → 连接凭证**」点「**扫码更新凭证**」,扫完 AppID / AppSecret 填进输入框,
|
|
190
|
+
再点「保存设置」生效——不用删机器人重建(重建会带走配置、权限、群档案和插件存档)。
|
|
191
|
+
|
|
188
192
|
### 3. 启动
|
|
189
193
|
|
|
190
194
|
```bash
|
|
@@ -502,9 +506,9 @@ openid 完全不同。共享 `roles.json` 等于所有权限记录全部对不
|
|
|
502
506
|
## 开发
|
|
503
507
|
|
|
504
508
|
```bash
|
|
505
|
-
npm test # 自检
|
|
506
|
-
npm run test:e2e # 端到端
|
|
507
|
-
npm run test:all # 全量约
|
|
509
|
+
npm test # 自检 686 + qrlogin 8 + deps 11 + npm-registry 12 + deps-external 4,另跑 53 个 node:test 文件(共 568 项)
|
|
510
|
+
npm run test:e2e # 端到端 253 项(起 mock 服务打全部接口,跑在临时目录)
|
|
511
|
+
npm run test:all # 全量约 1542 项:自检 + 扫码 + 依赖 + e2e(真机驱动要真机,没配就跳过)
|
|
508
512
|
npm run check:secrets # 扫硬编码凭据(CI 也跑这个,提交前建议过一遍)
|
|
509
513
|
node src/main.js --mock # 不连 QQ,命令行发假消息调插件
|
|
510
514
|
node src/main.js --mock --serve # 只开面板,调界面
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qq-bot-roost",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"start": "node src/main.js",
|
|
30
30
|
"mock": "node src/main.js --mock",
|
|
31
31
|
"check": "node src/main.js --check",
|
|
32
|
-
"test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs",
|
|
32
|
+
"test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs",
|
|
33
33
|
"test:e2e": "node test/e2e.mjs",
|
|
34
|
-
"test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs",
|
|
34
|
+
"test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs",
|
|
35
35
|
"check:secrets": "node scripts/check-secrets.mjs",
|
|
36
36
|
"create": "node scripts/create-plugin.mjs",
|
|
37
37
|
"test:plugin": "node scripts/test-plugin.mjs",
|
package/src/bot.js
CHANGED
|
@@ -22,6 +22,7 @@ import { createGate } from './gate.js';
|
|
|
22
22
|
import { createDeliveryLedger } from './delivery.js';
|
|
23
23
|
import { sharedIdentity } from './identity.js';
|
|
24
24
|
import { OneBotBridge } from './onebot/index.js';
|
|
25
|
+
import { onebotAllowsCore } from './onebot/keep.js';
|
|
25
26
|
import { HostBridge } from './host/index.js';
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -1161,7 +1162,7 @@ export class BotRuntime {
|
|
|
1161
1162
|
if (msg.mentioned || msg.isCommand) session.markAddressed(msg.chatId);
|
|
1162
1163
|
|
|
1163
1164
|
/**
|
|
1164
|
-
*
|
|
1165
|
+
* 兼容模式「独占」:**插件**不再回话,内核命令也只留绑定那四条。
|
|
1165
1166
|
*
|
|
1166
1167
|
* 为什么不能直接 `return`(第一版就是这么写的,被主人指出来):
|
|
1167
1168
|
* `绑定qq` / `绑定群号` / `绑定成员` 这些是**内核命令**(pluginId `__core`),
|
|
@@ -1171,7 +1172,7 @@ export class BotRuntime {
|
|
|
1171
1172
|
*
|
|
1172
1173
|
* 所以这里**不提前 return**,只打一个标记:
|
|
1173
1174
|
* - 管线照跑(去重 / 白名单 / 限流 / 暂停闸都还在,别的地方也别想绕过)
|
|
1174
|
-
* - 命令只放 `
|
|
1175
|
+
* - 命令只放 `onebot/keep.js` 里那四条绑定,其余(含 `/help`)静默忽略
|
|
1175
1176
|
* - 插件监听器整段跳过
|
|
1176
1177
|
*/
|
|
1177
1178
|
const coreOnly = Boolean(this.onebot?.exclusive);
|
|
@@ -1203,12 +1204,17 @@ export class BotRuntime {
|
|
|
1203
1204
|
|
|
1204
1205
|
if (msg.isCommand && commandEntry) {
|
|
1205
1206
|
/**
|
|
1206
|
-
*
|
|
1207
|
-
*
|
|
1208
|
-
* `__core`
|
|
1209
|
-
*
|
|
1207
|
+
* 独占模式只放行「绑定四件套」,其余内核命令一律静默。
|
|
1208
|
+
*
|
|
1209
|
+
* 以前是把整个 `__core` 都放行:绑定命令挂在 `__core` 上,而 OneBot 的
|
|
1210
|
+
* ID 映射又离不开绑定表,为了不挡住那四条,把 help / ping / status /
|
|
1211
|
+
* admin 这些一起放了出去。副作用是群里任何人发一句 `/help`,机器人都回
|
|
1212
|
+
* 一大段菜单——而独占的语义恰恰是「对话交给客户端」,这条回复纯属噪音。
|
|
1213
|
+
*
|
|
1214
|
+
* 现在收窄成白名单(见 `onebot/keep.js`):绑定必须留,其余全静默,包括
|
|
1215
|
+
* `/help`。要查命令或改配置去面板、或去客户端,那里有完整上下文。
|
|
1210
1216
|
*/
|
|
1211
|
-
if (coreOnly && commandEntry.
|
|
1217
|
+
if (coreOnly && !onebotAllowsCore(commandEntry.name)) {
|
|
1212
1218
|
this.metrics.bump('ignored');
|
|
1213
1219
|
return;
|
|
1214
1220
|
}
|
package/src/main.js
CHANGED
|
@@ -199,7 +199,11 @@ function registerCoreCommands(rt) {
|
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
201
|
* 独占模式(OneBot 兼容)下插件不回话,菜单里也就别再列它们——
|
|
202
|
-
*
|
|
202
|
+
* 列出来点了没反应,比不显示更让人困惑。
|
|
203
|
+
*
|
|
204
|
+
* 注意:1.1.5 起独占模式只放行绑定四件套,`/help` 在 `bot.js` 就被拦掉了,
|
|
205
|
+
* 这段正常走不到。留着是兜底——哪天放开 `help`(比如只对管理员回),
|
|
206
|
+
* `msg.coreOnly` 标记还在,这条过滤依然生效,不用回来重写一遍。
|
|
203
207
|
*/
|
|
204
208
|
const pluginMenus = msg.coreOnly ? [] : [...registry.menus.values()].filter((m) => m.id !== '__core');
|
|
205
209
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OneBot 独占模式下还放行的内核命令。
|
|
3
|
+
*
|
|
4
|
+
* 为什么只留这四条:OneBot 客户端里每个 QQ 号是**合成号**,要还原成真 QQ 号,
|
|
5
|
+
* 只能靠 `identity` 里的绑定表;而用户在客户端里发消息绑不了号,只能回 QQ 里发命令。
|
|
6
|
+
* 一刀切掉所有命令 = ID 映射永远对不上,主人权限、群号全是错的(第一版就这么踩过)。
|
|
7
|
+
*
|
|
8
|
+
* 其余内核命令(help / menu / ping / status / stats / admin / claim / whoami /
|
|
9
|
+
* plugins / enable / disable / 群插件 / reload)**一律静默**:独占的语义是
|
|
10
|
+
* 「对话交给客户端」,群里再多一条内核菜单就是噪音;要管理去面板或客户端,
|
|
11
|
+
* 那边有完整上下文,也不打扰群里的人。
|
|
12
|
+
*
|
|
13
|
+
* 单独一个文件是为了能脱离 bot.js 的重依赖单测——这条规则很容易被顺手改宽,
|
|
14
|
+
* 而改宽的后果(群里冒菜单)在测试里看不出来,只能靠用例钉住。
|
|
15
|
+
*/
|
|
16
|
+
export const ONEBOT_KEEP_COMMANDS = Object.freeze([
|
|
17
|
+
'绑定qq',
|
|
18
|
+
'qq验证码',
|
|
19
|
+
'绑定群号',
|
|
20
|
+
'绑定成员',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const KEEP = new Set(ONEBOT_KEEP_COMMANDS);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 这条内核命令在独占模式下该不该执行。
|
|
27
|
+
*
|
|
28
|
+
* 入参给注册名(`commandEntry.name`)或消息里解析出的命令名都行:
|
|
29
|
+
* 统一 trim + 小写再比,`绑定QQ` 和 `绑定qq` 是同一个命令。
|
|
30
|
+
*/
|
|
31
|
+
export function onebotAllowsCore(name) {
|
|
32
|
+
return KEEP.has(String(name ?? '').trim().toLowerCase());
|
|
33
|
+
}
|
package/web/app.js
CHANGED
|
@@ -275,6 +275,8 @@ async function selectBot(id) {
|
|
|
275
275
|
CURRENT_BOT = id;
|
|
276
276
|
localStorage.setItem('qqbot_bot', id);
|
|
277
277
|
closeBotMenu();
|
|
278
|
+
// 扫出来的是「当前这只鸟」的新凭证:换了机器人就不能再往新表单里灌
|
|
279
|
+
if (qrSlot === 'cfg') resetQr();
|
|
278
280
|
updateBotTrigger();
|
|
279
281
|
// SSE 在连接建立时就绑死了机器人,切换后必须重建,否则状态还是旧的
|
|
280
282
|
connectStream();
|
|
@@ -330,7 +332,7 @@ async function deleteBot(id) {
|
|
|
330
332
|
if (CURRENT_BOT) await selectBot(CURRENT_BOT);
|
|
331
333
|
}
|
|
332
334
|
|
|
333
|
-
/* ----------------
|
|
335
|
+
/* ---------------- 扫码(新建机器人 / 更新凭证) ---------------- */
|
|
334
336
|
|
|
335
337
|
/**
|
|
336
338
|
* 官方有「绑定」接口,手机 QQ 扫一下就能拿到 AppID / AppSecret,
|
|
@@ -338,9 +340,56 @@ async function deleteBot(id) {
|
|
|
338
340
|
*
|
|
339
341
|
* 二维码内容是官方给的一个 URL,我们本地画成二维码(web/vendor/qrcode.js)。
|
|
340
342
|
* 密钥(bindKey)留在服务端,前端只拿到 taskId。
|
|
343
|
+
*
|
|
344
|
+
* 两个入口共用这套逻辑,区别只在「扫完之后把值填哪」:
|
|
345
|
+
* · `new` —— 新建机器人弹窗:填进 #nbAppId / #nbSecret,等用户补个 ID 再创建;
|
|
346
|
+
* · `cfg` —— 配置页的连接凭证:填进 cfgForm,AppSecret 被重置、或者整只机器人
|
|
347
|
+
* 换账号时用,点「保存设置」才生效(自动保存会在用户没反应过来时重连一次,
|
|
348
|
+
* 扫码本来就可能是误点,不该顺带把在线连接掐掉)。
|
|
349
|
+
*
|
|
350
|
+
* 同一时刻只允许一个扫码任务:换位置扫会先把上一个收掉,免得两个 interval
|
|
351
|
+
* 抢同一个 taskId、或者把结果填到已经关掉的弹窗里。
|
|
341
352
|
*/
|
|
342
353
|
let qrTaskId = '';
|
|
343
354
|
let qrTimer = null;
|
|
355
|
+
let qrSlot = '';
|
|
356
|
+
|
|
357
|
+
const QR_SLOTS = {
|
|
358
|
+
new: {
|
|
359
|
+
box: '#nbQr', code: '#nbQrCode', tip: '#nbQrTip', btn: '#nbQrStart',
|
|
360
|
+
hint: '用手机 QQ 扫码,确认后会自动填好 AppID / AppSecret',
|
|
361
|
+
onDone(r) {
|
|
362
|
+
$('#nbAppId').value = r.appId || '';
|
|
363
|
+
$('#nbSecret').value = r.appSecret || '';
|
|
364
|
+
$('#nbQrTip').textContent = `✓ 已拿到 AppID ${r.appId},填个 ID 就能创建`;
|
|
365
|
+
$('#nbId').focus();
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
cfg: {
|
|
369
|
+
box: '#cfgQr', code: '#cfgQrCode', tip: '#cfgQrTip', btn: '#cfgQrStart',
|
|
370
|
+
hint: '用手机 QQ 扫码,确认后自动填到上面,再点「保存设置」生效',
|
|
371
|
+
onDone(r) {
|
|
372
|
+
const f = $('#cfgForm');
|
|
373
|
+
f.appId.value = r.appId || '';
|
|
374
|
+
// 扫码给的是完整的一对,直接覆盖输入框;留空会被后端当成「不修改」
|
|
375
|
+
f.appSecret.value = r.appSecret || '';
|
|
376
|
+
/**
|
|
377
|
+
* 二维码已经用完了,留着只是一块黑白方块:清掉图纸,让提示单独留着,
|
|
378
|
+
* 这样用户视线落在「点保存设置」上,而不是再扫一次。
|
|
379
|
+
*/
|
|
380
|
+
const code = $('#cfgQrCode');
|
|
381
|
+
if (code) code.innerHTML = '';
|
|
382
|
+
$('#cfgQrTip').textContent = `✓ 已换成 AppID ${r.appId},点「保存设置」生效`;
|
|
383
|
+
$('#cfgSaveTop')?.focus();
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
function qrEls(name) {
|
|
389
|
+
const s = QR_SLOTS[name];
|
|
390
|
+
if (!s) return null;
|
|
391
|
+
return { s, box: $(s.box), code: $(s.code), tip: $(s.tip), btn: $(s.btn) };
|
|
392
|
+
}
|
|
344
393
|
|
|
345
394
|
function stopQrPoll() {
|
|
346
395
|
if (qrTimer) {
|
|
@@ -349,19 +398,21 @@ function stopQrPoll() {
|
|
|
349
398
|
}
|
|
350
399
|
}
|
|
351
400
|
|
|
401
|
+
/** 收掉两个位置的二维码,顺带清空任务——打开/关闭弹窗、重扫都走这里 */
|
|
352
402
|
function resetQr() {
|
|
353
403
|
stopQrPoll();
|
|
354
404
|
qrTaskId = '';
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
405
|
+
qrSlot = '';
|
|
406
|
+
for (const name of Object.keys(QR_SLOTS)) {
|
|
407
|
+
const els = qrEls(name);
|
|
408
|
+
if (!els) continue;
|
|
409
|
+
if (els.box) els.box.hidden = true;
|
|
410
|
+
if (els.code) els.code.innerHTML = '';
|
|
411
|
+
if (els.tip) els.tip.textContent = '';
|
|
412
|
+
}
|
|
361
413
|
}
|
|
362
414
|
|
|
363
|
-
function drawQr(url) {
|
|
364
|
-
const code = $('#nbQrCode');
|
|
415
|
+
function drawQr(url, code) {
|
|
365
416
|
if (!code || typeof qrcode !== 'function') return false;
|
|
366
417
|
const qr = qrcode(0, 'M'); // 0 = 自动选版本
|
|
367
418
|
qr.addData(url);
|
|
@@ -370,21 +421,25 @@ function drawQr(url) {
|
|
|
370
421
|
return true;
|
|
371
422
|
}
|
|
372
423
|
|
|
373
|
-
async function startQr() {
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
const tip =
|
|
424
|
+
async function startQr(name = 'new') {
|
|
425
|
+
const els = qrEls(name);
|
|
426
|
+
if (!els) return;
|
|
427
|
+
const { box, tip, btn } = els;
|
|
428
|
+
if (!box || !tip || !btn) return;
|
|
429
|
+
|
|
430
|
+
if (qrSlot && qrSlot !== name) resetQr();
|
|
431
|
+
qrSlot = name;
|
|
377
432
|
box.hidden = false;
|
|
378
433
|
tip.textContent = '正在生成二维码…';
|
|
379
434
|
btn.disabled = true;
|
|
380
435
|
try {
|
|
381
436
|
const r = await api('/api/bots/qr/start', { method: 'POST', body: '{}' });
|
|
382
437
|
qrTaskId = r.taskId;
|
|
383
|
-
if (!drawQr(r.qrUrl)) {
|
|
438
|
+
if (!drawQr(r.qrUrl, els.code)) {
|
|
384
439
|
tip.textContent = '二维码库没加载上,刷新页面再试一次';
|
|
385
440
|
return;
|
|
386
441
|
}
|
|
387
|
-
tip.textContent =
|
|
442
|
+
tip.textContent = els.s.hint;
|
|
388
443
|
stopQrPoll();
|
|
389
444
|
qrTimer = setInterval(pollQr, 2000);
|
|
390
445
|
} catch (e) {
|
|
@@ -396,7 +451,9 @@ async function startQr() {
|
|
|
396
451
|
|
|
397
452
|
async function pollQr() {
|
|
398
453
|
if (!qrTaskId) return stopQrPoll();
|
|
399
|
-
const
|
|
454
|
+
const els = qrEls(qrSlot);
|
|
455
|
+
if (!els || !els.tip) return stopQrPoll();
|
|
456
|
+
const { tip } = els;
|
|
400
457
|
try {
|
|
401
458
|
const r = await api('/api/bots/qr/poll', {
|
|
402
459
|
method: 'POST',
|
|
@@ -404,14 +461,9 @@ async function pollQr() {
|
|
|
404
461
|
});
|
|
405
462
|
if (r.status === 'pending') return;
|
|
406
463
|
stopQrPoll();
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
tip.textContent = `✓ 已拿到 AppID ${r.appId},填个 ID 就能创建`;
|
|
411
|
-
$('#nbId').focus();
|
|
412
|
-
} else {
|
|
413
|
-
tip.textContent = r.message || '二维码失效了,重新生成一个';
|
|
414
|
-
}
|
|
464
|
+
qrTaskId = '';
|
|
465
|
+
if (r.status === 'done') els.s.onDone(r);
|
|
466
|
+
else tip.textContent = r.message || '二维码失效了,重新生成一个';
|
|
415
467
|
} catch (e) {
|
|
416
468
|
stopQrPoll();
|
|
417
469
|
if (tip) tip.textContent = e.message;
|
|
@@ -473,7 +525,9 @@ async function submitNewBot() {
|
|
|
473
525
|
}
|
|
474
526
|
}
|
|
475
527
|
|
|
476
|
-
|
|
528
|
+
// 传箭头函数:直接把 startQr 挂上去会把 click 事件当成位置名传进去
|
|
529
|
+
$('#nbQrStart')?.addEventListener('click', () => startQr('new'));
|
|
530
|
+
$('#cfgQrStart')?.addEventListener('click', () => startQr('cfg'));
|
|
477
531
|
|
|
478
532
|
$('#botTrigger')?.addEventListener('click', () => {
|
|
479
533
|
if ($('#botMenu').hidden) openBotMenu();
|
|
@@ -1715,6 +1769,8 @@ $('#cfgForm').addEventListener('submit', async (e) => {
|
|
|
1715
1769
|
: (renamed ? `已保存,机器人昵称同步为「${r.name}」` : '已保存') +
|
|
1716
1770
|
(payload.appId ? '' : '(AppID 为空)');
|
|
1717
1771
|
f.appSecret.value = '';
|
|
1772
|
+
// 扫码换凭证的那条提示到此为止:凭证已落盘,再挂着「点保存设置」就是误导
|
|
1773
|
+
resetQr();
|
|
1718
1774
|
clearCfgDirty();
|
|
1719
1775
|
setTimeout(() => ($('#cfgMsg').textContent = ''), 4000);
|
|
1720
1776
|
await loadBots();
|
package/web/index.html
CHANGED
|
@@ -741,8 +741,19 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
|
|
|
741
741
|
</select>
|
|
742
742
|
</label>
|
|
743
743
|
</div>
|
|
744
|
+
<!--
|
|
745
|
+
扫码换凭证:AppSecret 会被重置、或者整只机器人换了账号时,
|
|
746
|
+
与其去 q.qq.com 后台翻两个值再复制,不如扫一下。
|
|
747
|
+
和「新建机器人」用的是同一个官方绑定接口,区别只是扫完**不建新机器人**,
|
|
748
|
+
把 AppID / AppSecret 填进当前这张表单里——仍然要点「保存设置」才生效。
|
|
749
|
+
-->
|
|
750
|
+
<div class="nb-qr" id="cfgQr" hidden>
|
|
751
|
+
<div class="nb-qr-code" id="cfgQrCode"></div>
|
|
752
|
+
<div class="nb-qr-tip" id="cfgQrTip"></div>
|
|
753
|
+
</div>
|
|
744
754
|
<div class="cred-actions">
|
|
745
755
|
<span class="hint" id="cfgMsgTop"></span>
|
|
756
|
+
<button type="button" class="btn" id="cfgQrStart">扫码更新凭证</button>
|
|
746
757
|
<button type="submit" class="btn" id="cfgSaveTop">保存设置</button>
|
|
747
758
|
</div>
|
|
748
759
|
<div class="full intents-block">
|