qq-bot-roost 1.1.11 → 1.1.13
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 +12 -7
- package/package.json +3 -3
- package/src/bot.js +82 -4
- package/src/config.js +46 -23
- package/src/hashdir.js +27 -12
- package/src/main.js +32 -0
- package/src/onebot/actions.js +16 -0
- package/src/onebot/capability.js +1 -1
- package/src/onebot/ids.js +33 -0
- package/src/onebot/translate.js +226 -18
- package/src/onebot/voice.js +41 -32
- package/src/web/server.js +30 -0
- package/web/app.js +328 -28
- package/web/index.html +73 -2
- package/web/style.css +35 -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-1445%20passed-brightgreen" alt="测试 1445 项">
|
|
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.13-blueviolet" alt="版本 1.1.13">
|
|
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/roost-qq/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/roost-qq/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
|
|
16
16
|
|
|
@@ -185,8 +185,10 @@ node -v # 需要 >= 22.13
|
|
|
185
185
|
3. **关键**:「功能配置」里开通 **群聊** 能力,否则连接会被拒(关闭码 4014)
|
|
186
186
|
|
|
187
187
|
**换凭证(1.1.4+)**:AppSecret 被开放平台重置、或者整只机器人换了账号时,
|
|
188
|
-
进面板「**配置 →
|
|
189
|
-
|
|
188
|
+
进面板「**配置 → 连接凭证**」点「**扫码更新凭证**」,手机 QQ 扫一下即可——
|
|
189
|
+
拿到新凭证后会自动保存并尝试上线,不用手动点保存,也不用删机器人重建
|
|
190
|
+
(重建会带走配置、权限、群档案和插件存档)。
|
|
191
|
+
只在扫码成功那一刻旧密钥才会失效;二维码还没扫时旧凭证照常有效,不会影响在线连接。
|
|
190
192
|
|
|
191
193
|
### 3. 启动
|
|
192
194
|
|
|
@@ -194,8 +196,11 @@ node -v # 需要 >= 22.13
|
|
|
194
196
|
node src/main.js
|
|
195
197
|
```
|
|
196
198
|
|
|
197
|
-
Windows 下也可以双击 `start.bat`(它会检查 Node
|
|
198
|
-
|
|
199
|
+
Windows 下也可以双击 `start.bat`(它会检查 Node 版本并给出提示):
|
|
200
|
+
自动建好 `config/` `logs/` `data/`、启动面板并打开浏览器,**不会在命令行问 AppID / AppSecret**。
|
|
201
|
+
首次启动检测到没填凭证,面板会自动进入「首次启动引导」:扫码或手填凭证,
|
|
202
|
+
保存后自动上线;引导里还能顺手设置面板访问密钥 + 公网监听(改 host / 密钥需重启框架生效)。
|
|
203
|
+
想跳过引导点「稍后再说」,之后到「配置 → 连接凭证」补填即可。
|
|
199
204
|
|
|
200
205
|
看到这两行就成功了:
|
|
201
206
|
|
|
@@ -502,7 +507,7 @@ bot/
|
|
|
502
507
|
│ ├── web/server.js 面板服务端(REST + SSE)
|
|
503
508
|
│ └── plugin/ 插件加载、配置、依赖、子进程宿主、面板页面注册
|
|
504
509
|
├── test/
|
|
505
|
-
│ ├── selftest.mjs 框架自检(
|
|
510
|
+
│ ├── selftest.mjs 框架自检(712 项)
|
|
506
511
|
│ ├── e2e.mjs 端到端测试(253 项,起真实服务打接口)
|
|
507
512
|
│ ├── qrlogin.mjs 扫码建机器人(8 项)
|
|
508
513
|
│ └── deps.mjs 插件依赖安装(11 项)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qq-bot-roost",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"mock": "node src/main.js --mock",
|
|
31
31
|
"check": "node src/main.js --check",
|
|
32
32
|
"release:prepare": "node scripts/release-prepare.mjs",
|
|
33
|
-
"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/transport-regressions.mjs && node --test test/check-mode.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 && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs",
|
|
33
|
+
"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/transport-regressions.mjs && node --test test/check-mode.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/healthz-identity.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 && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
34
34
|
"test:e2e": "node test/e2e.mjs",
|
|
35
|
-
"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/transport-regressions.mjs && node --test test/check-mode.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 && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs",
|
|
35
|
+
"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/transport-regressions.mjs && node --test test/check-mode.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/healthz-identity.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 && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
36
36
|
"check:secrets": "node scripts/check-secrets.mjs",
|
|
37
37
|
"create": "node scripts/create-plugin.mjs",
|
|
38
38
|
"test:plugin": "node scripts/test-plugin.mjs",
|
package/src/bot.js
CHANGED
|
@@ -1165,14 +1165,24 @@ export class BotRuntime {
|
|
|
1165
1165
|
this.onMessage?.(msg);
|
|
1166
1166
|
|
|
1167
1167
|
/**
|
|
1168
|
-
* OneBot
|
|
1168
|
+
* OneBot / 宿主协议:真·空消息不推。
|
|
1169
|
+
*
|
|
1170
|
+
* 空消息转过去,客户端只会收到一条没内容的 message 事件,没有意义。
|
|
1171
|
+
* 判空口径跟 describeForLog 一致——正文、任意附件、ARK 卡片、消息元素
|
|
1172
|
+
* 有一样就不算空:纯图 / 纯语音 / 表情(other 附件)/ 卡片都不能丢,
|
|
1173
|
+
* 否则就是日志那边刚修过的误判在转发侧重演一遍。
|
|
1174
|
+
*
|
|
1175
|
+
* 只拦这两层:message-bus(面板 SSE)和后面的 logIncoming 是观测通道,
|
|
1176
|
+
* 该看到「确实收到过这条」,保持原样。
|
|
1169
1177
|
*
|
|
1170
1178
|
* 传的是**完整 msg**(含 uin / msgIdx / attachments),不走 message-bus——
|
|
1171
1179
|
* 那条通道的 payload 是对外契约,故意脱敏过,拿不到 ID 映射要的东西。
|
|
1172
1180
|
*/
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1181
|
+
if (hasMessageContent(msg)) {
|
|
1182
|
+
this.onebot?.onMessage(msg);
|
|
1183
|
+
/** 宿主协议:传完整 msg(原生结构),它自己挑字段 */
|
|
1184
|
+
this.host?.onMessage(msg);
|
|
1185
|
+
}
|
|
1176
1186
|
} catch (e) {
|
|
1177
1187
|
this.log.warn(`消息广播失败: ${e.message}`);
|
|
1178
1188
|
}
|
|
@@ -1447,6 +1457,11 @@ export class BotRuntime {
|
|
|
1447
1457
|
*
|
|
1448
1458
|
* 现在按附件类型给出人话:`[图片消息]`、`[语音消息: 转写内容]`、`[视频消息]`…
|
|
1449
1459
|
* 文本和附件都有时一起显示(图文消息很常见)。
|
|
1460
|
+
*
|
|
1461
|
+
* 另外两类「有内容但正文为空」的消息以前会被误记成「(空)」:
|
|
1462
|
+
* · `type:'other'` 附件(content_type 不属于图/音/视频/文件的表情、贴纸等);
|
|
1463
|
+
* · ARK 卡片(B 站分享、小程序、位置卡…),载荷在 `msg.ark`,不在 attachments。
|
|
1464
|
+
* 这两类都要标出来,否则排查时以为框架什么都没收到,其实是日志没认出来。
|
|
1450
1465
|
*/
|
|
1451
1466
|
export function describeForLog(msg, text = '') {
|
|
1452
1467
|
const parts = [];
|
|
@@ -1471,9 +1486,72 @@ export function describeForLog(msg, text = '') {
|
|
|
1471
1486
|
parts.push(`[文件消息: ${f?.filename || '未命名'}]`);
|
|
1472
1487
|
}
|
|
1473
1488
|
|
|
1489
|
+
/**
|
|
1490
|
+
* parseAttachments 对认不出的 content_type 统一产出 type:'other'——表情、贴纸、
|
|
1491
|
+
* 未知格式都落这里。以前没有对应分支,于是「发了东西」被记成「(空)」。
|
|
1492
|
+
* 有文件名就用文件名(最可读),否则退到 content_type,都没有就只标类型。
|
|
1493
|
+
*/
|
|
1494
|
+
for (const o of atts.filter((a) => a?.type === 'other')) {
|
|
1495
|
+
const label = String(o?.filename || o?.contentType || '').trim();
|
|
1496
|
+
parts.push(label ? `[其他消息: ${label}]` : '[其他消息]');
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* ARK 卡片走单独的 msg.ark(见 message.js::parseArk),不在 attachments 里,
|
|
1501
|
+
* 而且通常没有正文 text——不处理照样打「(空)」。
|
|
1502
|
+
* 标题最有用,其次描述/提示/名称;正文里已经出现过同样的字就不重复抄一遍。
|
|
1503
|
+
* 截断到 60 字符,别让一张长标题把整行日志撑爆。
|
|
1504
|
+
*/
|
|
1505
|
+
const ark = msg?.ark;
|
|
1506
|
+
if (ark && typeof ark === 'object') {
|
|
1507
|
+
const label = [ark.title, ark.desc, ark.prompt, ark.name]
|
|
1508
|
+
.map((s) => String(s ?? '').trim())
|
|
1509
|
+
.find(Boolean);
|
|
1510
|
+
const short = label && label.length > 60 ? `${label.slice(0, 60)}…` : label;
|
|
1511
|
+
parts.push(short && !said.includes(short) ? `[卡片消息: ${short}]` : '[卡片消息]');
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* 合并转发 / 引用:正文 content 可能是空串,内容全在 elements 里。
|
|
1516
|
+
* 跟 hasMessageContent 对齐——日志打「(空)」的消息,就是被判空不推的那批。
|
|
1517
|
+
*/
|
|
1518
|
+
const els = Array.isArray(msg?.elements) ? msg.elements : [];
|
|
1519
|
+
if (els.length) parts.push(els.length > 1 ? `[消息元素×${els.length}]` : '[消息元素]');
|
|
1520
|
+
if (String(msg?.quoted ?? '').trim()) parts.push('[引用消息]');
|
|
1521
|
+
|
|
1474
1522
|
return parts.join(' ') || '(空)';
|
|
1475
1523
|
}
|
|
1476
1524
|
|
|
1525
|
+
/**
|
|
1526
|
+
* 这条消息有没有「内容」——给协议层转发判空用。
|
|
1527
|
+
*
|
|
1528
|
+
* 口径跟 describeForLog 刻意保持一致:**日志打「(空)」的消息,就是不该推给
|
|
1529
|
+
* 协议层的消息**。两处若各写一套判定,迟早出现「日志说空却推了」或反过来。
|
|
1530
|
+
*
|
|
1531
|
+
* 正文 / attachments(任意类型)/ ARK 卡片 / elements(合并转发、引用)——
|
|
1532
|
+
* 有一样就算有内容。纯图片、纯语音、表情、贴纸、卡片都不是空消息,
|
|
1533
|
+
* 不能因为 `content` 是空串就把它们拦掉。
|
|
1534
|
+
*
|
|
1535
|
+
* @param {object} msg buildMessage() 产出的消息对象
|
|
1536
|
+
* @returns {boolean} true = 有内容,可转发;false = 真空消息
|
|
1537
|
+
*/
|
|
1538
|
+
export function hasMessageContent(msg) {
|
|
1539
|
+
const said = String(msg?.raw?.content ?? msg?.content ?? '').trim();
|
|
1540
|
+
if (said) return true;
|
|
1541
|
+
|
|
1542
|
+
const atts = Array.isArray(msg?.attachments) ? msg.attachments : [];
|
|
1543
|
+
if (atts.length) return true; // 任意附件类型都算:image/voice/video/file/other
|
|
1544
|
+
|
|
1545
|
+
if (msg?.ark && typeof msg.ark === 'object') return true;
|
|
1546
|
+
|
|
1547
|
+
const els = Array.isArray(msg?.elements) ? msg.elements : [];
|
|
1548
|
+
if (els.length) return true;
|
|
1549
|
+
|
|
1550
|
+
if (String(msg?.quoted ?? '').trim()) return true;
|
|
1551
|
+
|
|
1552
|
+
return false;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1477
1555
|
/**
|
|
1478
1556
|
* 把插件启用配置翻译成过滤函数。
|
|
1479
1557
|
* all → 全部
|
package/src/config.js
CHANGED
|
@@ -968,45 +968,68 @@ export async function migrateToMultiBot() {
|
|
|
968
968
|
/* 凭证 */
|
|
969
969
|
/* ------------------------------------------------------------------ */
|
|
970
970
|
|
|
971
|
-
/**
|
|
971
|
+
/** 首启凭证检查:缺凭证时只提示,不再在命令行拦人 */
|
|
972
972
|
export async function ensureBotCredentials(botId) {
|
|
973
973
|
const cfg = await loadBotConfig(botId);
|
|
974
974
|
if (cfg.appId && cfg.appSecret) return cfg;
|
|
975
975
|
|
|
976
976
|
/**
|
|
977
|
-
*
|
|
977
|
+
* never block waiting for input — regardless of TTY.
|
|
978
978
|
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
979
|
+
* 面板本身就是配置入口:以前双击 start.bat(有交互终端)时这里会 readline
|
|
980
|
+
* 问 AppID/AppSecret,卡住整条启动链——面板还没起来,用户却被要求在黑框里
|
|
981
|
+
* 输入密钥。而扫码建号的场景下,用户手上本来就没有这俩值(要去面板扫码拿)。
|
|
982
|
+
*
|
|
983
|
+
* 现在改成「只提示、不阻塞」:面板照常启动并打开浏览器,前端检测到没有
|
|
984
|
+
* AppID 会自动进入首次启动引导(扫码 / 手填二选一)。BotRuntime 拿空凭证
|
|
985
|
+
* 会报 state=error,引导里填完保存+上线后即恢复。
|
|
986
|
+
*/
|
|
987
|
+
/**
|
|
988
|
+
* 交互终端下不在这里提示:main 会在面板起来之后调用 promptCredentials,
|
|
989
|
+
* 那边把「命令行填 / 回车跳过 / 面板扫码」三条路一次说清,避免刷两遍。
|
|
982
990
|
*/
|
|
983
991
|
if (!stdin.isTTY) {
|
|
984
992
|
console.warn(
|
|
985
993
|
`\n[提示] 机器人 ${botId} 还没有 AppID / AppSecret。\n` +
|
|
986
|
-
`
|
|
987
|
-
` 面板地址见下面的日志。\n`,
|
|
994
|
+
` 面板会自动打开,在里面扫码或填写即可;也可编辑 ${rel(botPaths(botId).config)}。\n`,
|
|
988
995
|
);
|
|
989
|
-
return cfg;
|
|
990
996
|
}
|
|
997
|
+
return cfg;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* 命令行交互补凭证(可选路径,不阻塞面板启动)。
|
|
1002
|
+
*
|
|
1003
|
+
* 由 main 在「面板已启动 + 浏览器已打开」之后调用:有交互终端就问一句,
|
|
1004
|
+
* 用户直接回车跳过(面板引导仍能填)。和面板引导写的是同一份配置,
|
|
1005
|
+
* 面板那边刷新后就能看到新凭证。
|
|
1006
|
+
*
|
|
1007
|
+
* @returns {Promise<object|null>} 更新后的 cfg;跳过或无终端返回 null
|
|
1008
|
+
*/
|
|
1009
|
+
export async function promptCredentials(botId) {
|
|
1010
|
+
if (!stdin.isTTY) return null;
|
|
1011
|
+
const cfg = await loadBotConfig(botId);
|
|
1012
|
+
if (cfg.appId && cfg.appSecret) return null;
|
|
991
1013
|
|
|
992
|
-
console.log(`\n机器人 ${botId}
|
|
1014
|
+
console.log(`\n机器人 ${botId} 还没有凭证。可以直接在这里填,或回车跳过、去面板扫码 / 填写。\n`);
|
|
993
1015
|
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
994
1016
|
try {
|
|
995
|
-
|
|
996
|
-
if (!
|
|
1017
|
+
const appId = (await rl.question('AppID(回车跳过): ')).trim();
|
|
1018
|
+
if (!appId) {
|
|
1019
|
+
console.log('已跳过,请在面板里配置。');
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
const appSecret = (await rl.question('AppSecret: ')).trim();
|
|
1023
|
+
if (!appSecret) {
|
|
1024
|
+
console.log('AppSecret 为空,已跳过。');
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
1027
|
+
cfg.appId = appId;
|
|
1028
|
+
cfg.appSecret = appSecret;
|
|
1029
|
+
await saveBotConfig(botId, cfg);
|
|
1030
|
+
console.log(`已保存到 ${rel(botPaths(botId).config)}\n`);
|
|
1031
|
+
return cfg;
|
|
997
1032
|
} finally {
|
|
998
1033
|
rl.close();
|
|
999
1034
|
}
|
|
1000
|
-
|
|
1001
|
-
if (!cfg.appId || !cfg.appSecret) {
|
|
1002
|
-
console.warn(
|
|
1003
|
-
`\n[提示] AppID 或 AppSecret 为空,这次先不连。\n` +
|
|
1004
|
-
` 面板已启动,可以在里面填写后再连接。\n`,
|
|
1005
|
-
);
|
|
1006
|
-
return cfg;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
await saveBotConfig(botId, cfg);
|
|
1010
|
-
console.log(`\n已保存到 ${rel(botPaths(botId).config)}\n`);
|
|
1011
|
-
return cfg;
|
|
1012
1035
|
}
|
package/src/hashdir.js
CHANGED
|
@@ -29,6 +29,30 @@ import { HASH_SKIP } from './skipdirs.js';
|
|
|
29
29
|
const SKIP_DIRS = HASH_SKIP;
|
|
30
30
|
const SKIP_FILES = new Set(['.deps.json', '.DS_Store', 'Thumbs.db']);
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* 一个相对路径(`/` 分隔,含文件名)是否参与内容指纹。
|
|
34
|
+
*
|
|
35
|
+
* **这是唯一的排除规则**,目录遍历(collect)和发版脚本(build-sums.mjs)
|
|
36
|
+
* 都必须调它,不能各自复制一份判断——2026-11 就因为发版脚本漏了这里的
|
|
37
|
+
* 文档排除规则,导致 SHA256SUMS 记录的指纹含 17 个 md/LICENSE、而更新器
|
|
38
|
+
* 解包后算出的不含,v1.1.11 及之后所有版本的自更新全部校验失败。
|
|
39
|
+
*
|
|
40
|
+
* @param {string} rel 相对路径,如 `src/main.js` / `docs/架构说明.md`
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
export function isHashedFile(rel) {
|
|
44
|
+
const parts = String(rel).split('/');
|
|
45
|
+
const name = parts.pop();
|
|
46
|
+
if (!name) return false;
|
|
47
|
+
// 任一级目录在跳过表里就排除(与 collect 逐层剪枝等价)
|
|
48
|
+
if (parts.some((seg) => SKIP_DIRS.has(seg))) return false;
|
|
49
|
+
if (SKIP_FILES.has(name)) return false;
|
|
50
|
+
const lower = name.toLowerCase();
|
|
51
|
+
if (lower.endsWith('.md')) return false;
|
|
52
|
+
if (/^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower)) return false;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
32
56
|
/**
|
|
33
57
|
* 把文本文件的 CRLF 折成 LF;二进制原样返回。
|
|
34
58
|
*
|
|
@@ -65,18 +89,9 @@ async function collect(root) {
|
|
|
65
89
|
if (SKIP_DIRS.has(it.name)) continue;
|
|
66
90
|
await walk(path.join(dir, it.name), prefix ? `${prefix}/${it.name}` : it.name);
|
|
67
91
|
} else if (it.isFile()) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* 代码,不该逼维护者 bump 版本(改文档就升版纯属版本噪音)。
|
|
72
|
-
* LICENSE 由插件作者自带、可自定义协议,属于「文档声明」不是代码。
|
|
73
|
-
* 这里排除后,必须同步重建插件仓 index.json 并让插件仓的
|
|
74
|
-
* scripts/hashdir.mjs 一致排除,否则跨仓校验会全红。
|
|
75
|
-
*/
|
|
76
|
-
const lower = it.name.toLowerCase();
|
|
77
|
-
if (lower.endsWith('.md')) continue;
|
|
78
|
-
if (/^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower)) continue;
|
|
79
|
-
out.push(prefix ? `${prefix}/${it.name}` : it.name);
|
|
92
|
+
const rel = prefix ? `${prefix}/${it.name}` : it.name;
|
|
93
|
+
if (!isHashedFile(rel)) continue;
|
|
94
|
+
out.push(rel);
|
|
80
95
|
}
|
|
81
96
|
// 符号链接一律跳过:它可能指向仓库外,内容不稳定
|
|
82
97
|
}
|
package/src/main.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
saveBotConfig,
|
|
11
11
|
createBotConfig,
|
|
12
12
|
ensureBotCredentials,
|
|
13
|
+
promptCredentials,
|
|
13
14
|
migrateToMultiBot,
|
|
14
15
|
} from './config.js';
|
|
15
16
|
import { DIRS, PATHS, botPaths, listBotIds, ensureDirs, rel } from './paths.js';
|
|
@@ -1564,6 +1565,37 @@ async function main() {
|
|
|
1564
1565
|
if (!rt.online) log.error(`[${rt.id}] 未连上:${rt.lastError || '未知原因'}`);
|
|
1565
1566
|
}
|
|
1566
1567
|
|
|
1568
|
+
/**
|
|
1569
|
+
* 命令行补凭证(可选,不阻塞面板)。
|
|
1570
|
+
*
|
|
1571
|
+
* 面板和浏览器都已经起来了,这里才在终端里问一句。有 TTY 且缺凭证时提示,
|
|
1572
|
+
* 回车跳过则什么都不做(面板引导照常可用)。拿到凭证后要同步运行时:
|
|
1573
|
+
* · 把新值写进 rt.cfg(面板的 ?bot= 状态、syncBotName 都读它);
|
|
1574
|
+
* · 清 token 管理器里的旧 appId/secret,否则还拿旧凭证换 token;
|
|
1575
|
+
* · goOnline() 重新认领实例并连网关(start() 那次因无凭证置了 error)。
|
|
1576
|
+
* 用 void 启动、不 await——询问期间面板照常服务,用户输入完自行上线。
|
|
1577
|
+
*/
|
|
1578
|
+
void (async () => {
|
|
1579
|
+
for (const rt of runtimes) {
|
|
1580
|
+
if (rt.cfg.appId && rt.cfg.appSecret) continue;
|
|
1581
|
+
const fresh = await promptCredentials(rt.id);
|
|
1582
|
+
if (!fresh) continue;
|
|
1583
|
+
Object.assign(rt.cfg, { appId: fresh.appId, appSecret: fresh.appSecret });
|
|
1584
|
+
if (rt.tokens) {
|
|
1585
|
+
rt.tokens.appId = fresh.appId;
|
|
1586
|
+
rt.tokens.appSecret = fresh.appSecret;
|
|
1587
|
+
rt.tokens.token = '';
|
|
1588
|
+
rt.tokens.expiresAt = 0;
|
|
1589
|
+
}
|
|
1590
|
+
try {
|
|
1591
|
+
await rt.goOnline();
|
|
1592
|
+
log.info(`[${rt.id}] 已用命令行填入的凭证上线`);
|
|
1593
|
+
} catch (e) {
|
|
1594
|
+
log.error(`[${rt.id}] 命令行凭证已保存,但上线失败:${e.message}`);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
})().catch((e) => log.warn(`命令行凭证交互跳过:${e.message}`));
|
|
1598
|
+
|
|
1567
1599
|
// 后台服务放在最后启动,不干扰启动流程的日志
|
|
1568
1600
|
await services.start();
|
|
1569
1601
|
|
package/src/onebot/actions.js
CHANGED
|
@@ -486,6 +486,22 @@ export function createActions({
|
|
|
486
486
|
};
|
|
487
487
|
},
|
|
488
488
|
|
|
489
|
+
/**
|
|
490
|
+
* 合并转发展开。
|
|
491
|
+
*
|
|
492
|
+
* 官方没有转发内容接口,节点来自入站 `msg_elements` 里已经带来的
|
|
493
|
+
* 102 消息元素(translate.js 在收到时调 `ids.bindForward()` 存下来)。
|
|
494
|
+
* 找不到就明确 1404——返回空 `messages` 会让客户端以为转发是空的。
|
|
495
|
+
*/
|
|
496
|
+
async get_forward_msg(params) {
|
|
497
|
+
const raw = params?.id ?? params?.forward_id ?? params?.message_id;
|
|
498
|
+
const nodes = ids.getForward?.(raw);
|
|
499
|
+
if (!nodes?.length) {
|
|
500
|
+
throw obError(1404, '找不到这条合并转发(只保留本次进程收到的转发,重启或「外接」重配后就失效)');
|
|
501
|
+
}
|
|
502
|
+
return { messages: nodes };
|
|
503
|
+
},
|
|
504
|
+
|
|
489
505
|
async get_group_info(params) {
|
|
490
506
|
const openid = ids.openidOfGroup(params?.group_id);
|
|
491
507
|
if (!openid) throw obError(1404, '这个群号没有对应的 openid,先去面板「身份」页绑一下');
|
package/src/onebot/capability.js
CHANGED
|
@@ -26,7 +26,7 @@ export const CAPABILITY = [
|
|
|
26
26
|
{ name: 'get_group_member_info', level: 'degrade', why: '内邀接口;没白名单时只给号码和已知昵称' },
|
|
27
27
|
{ name: 'get_group_member_list', level: 'degrade', why: '内邀接口;否则只列「在群里说过话的人」' },
|
|
28
28
|
{ name: 'get_msg', level: 'degrade', why: '只记得最近 500 条' },
|
|
29
|
-
{ name: 'get_forward_msg', level: 'degrade', why: '
|
|
29
|
+
{ name: 'get_forward_msg', level: 'degrade', why: '只覆盖本次进程收到的合并转发节点;重启或「外接」重配后失效' },
|
|
30
30
|
{ name: 'get_stranger_info', level: 'support', note: '2026-11-16 官方新增用户资料接口;要好友关系,否则回 1404' },
|
|
31
31
|
{ name: 'get_friend_list', level: 'unsupported', why: '官方没有好友列表接口' },
|
|
32
32
|
{ name: 'get_group_msg_history', level: 'degrade', why: '用账本回放,只有本进程收到过的' },
|
package/src/onebot/ids.js
CHANGED
|
@@ -32,6 +32,15 @@ const SYNTH_MOD = 1_000_000_000_000;
|
|
|
32
32
|
/** 保留多少条消息映射。够 `get_msg` / 引用 / 撤回用即可 */
|
|
33
33
|
const MAX_MSGS = 500;
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* 合并转发只留本次进程收到的若干组,且每组最多 200 个节点。
|
|
37
|
+
*
|
|
38
|
+
* 官方没有转发内容接口,我们能给的只有入站时 `msg_elements` 已经带来的节点;
|
|
39
|
+
* 全落盘会让 ids.json 从几 KB 涨到几 MB(每次 #touch 都整份重写),不值当。
|
|
40
|
+
* id 仍从 nextId 分配,重启后不会复用旧号。
|
|
41
|
+
*/
|
|
42
|
+
const MAX_FORWARDS = 50;
|
|
43
|
+
|
|
35
44
|
/** 落盘节流:映射变化很频繁,每条都写盘不值当 */
|
|
36
45
|
const SAVE_MS = 1000;
|
|
37
46
|
|
|
@@ -69,6 +78,8 @@ export class OneBotIds {
|
|
|
69
78
|
this.byOfficial = new Map();
|
|
70
79
|
/** msgIdx → onebot message_id(引用回复用) */
|
|
71
80
|
this.byIdx = new Map();
|
|
81
|
+
/** forward id → 转发节点数组(get_forward_msg 用,只在本次进程内有效) */
|
|
82
|
+
this.forwards = new Map();
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
async load() {
|
|
@@ -243,6 +254,28 @@ export class OneBotIds {
|
|
|
243
254
|
return this.byIdx.get(i) ?? 0;
|
|
244
255
|
}
|
|
245
256
|
|
|
257
|
+
/**
|
|
258
|
+
* 给一组合并转发节点分配 id,供 `get_forward_msg` 反查。
|
|
259
|
+
*
|
|
260
|
+
* 节点内容本身不落盘(见 MAX_FORWARDS 注释),但 id 从 nextId 走,
|
|
261
|
+
* 保证重启后不会把旧 id 指到另一组转发上。
|
|
262
|
+
*/
|
|
263
|
+
bindForward(nodes) {
|
|
264
|
+
if (!this.data) throw new Error('OneBotIds 还没 load()');
|
|
265
|
+
const id = this.data.nextId++;
|
|
266
|
+
this.forwards.set(id, Array.isArray(nodes) ? nodes.slice(0, 200) : []);
|
|
267
|
+
while (this.forwards.size > MAX_FORWARDS) {
|
|
268
|
+
this.forwards.delete(this.forwards.keys().next().value);
|
|
269
|
+
}
|
|
270
|
+
this.#touch();
|
|
271
|
+
return id;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** forward id → 节点数组(找不到返回 null) */
|
|
275
|
+
getForward(id) {
|
|
276
|
+
return this.forwards.get(Number(id)) ?? null;
|
|
277
|
+
}
|
|
278
|
+
|
|
246
279
|
/* ---------------- 落盘 ---------------- */
|
|
247
280
|
|
|
248
281
|
#touch() {
|