qq-bot-roost 1.1.12 → 1.1.14
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 +56 -27
- package/src/hashdir.js +48 -16
- package/src/host/ops.js +4 -0
- 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/plugin/market.js +76 -29
- package/src/web/server.js +56 -0
- package/web/app.js +323 -25
- package/web/index.html +84 -4
- package/web/style.css +25 -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-1455%20passed-brightgreen" alt="测试 1455 项">
|
|
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.14-blueviolet" alt="版本 1.1.14">
|
|
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.14",
|
|
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 && node --test test/hashdir-sums.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/market-hash-dual.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 && node --test test/hashdir-sums.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/market-hash-dual.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
|
@@ -177,10 +177,16 @@ const GLOBAL_DEFAULTS = {
|
|
|
177
177
|
intervalHours: 6,
|
|
178
178
|
},
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
plugins: {
|
|
181
|
+
autoInstallDeps: true,
|
|
182
|
+
/**
|
|
183
|
+
* 插件市场安装 / 更新时校验目录内容哈希,默认开。
|
|
184
|
+
* 关掉等于放弃供应链完整性校验(只靠 https 和索引本身),市场页会明确提示风险;
|
|
185
|
+
* 只在索引与框架算法版本错位的过渡期临时用,修好后请打开。
|
|
186
|
+
*/
|
|
187
|
+
verifyHash: true,
|
|
188
|
+
/** Go 插件用的 go 可执行文件路径,留空则用 PATH 里的 go 或 GO_BIN 环境变量 */
|
|
189
|
+
goBin: '',
|
|
184
190
|
/**
|
|
185
191
|
* 插件市场索引地址,换成你自己的插件仓库即可。
|
|
186
192
|
*
|
|
@@ -968,45 +974,68 @@ export async function migrateToMultiBot() {
|
|
|
968
974
|
/* 凭证 */
|
|
969
975
|
/* ------------------------------------------------------------------ */
|
|
970
976
|
|
|
971
|
-
/**
|
|
977
|
+
/** 首启凭证检查:缺凭证时只提示,不再在命令行拦人 */
|
|
972
978
|
export async function ensureBotCredentials(botId) {
|
|
973
979
|
const cfg = await loadBotConfig(botId);
|
|
974
980
|
if (cfg.appId && cfg.appSecret) return cfg;
|
|
975
981
|
|
|
976
982
|
/**
|
|
977
|
-
*
|
|
983
|
+
* never block waiting for input — regardless of TTY.
|
|
984
|
+
*
|
|
985
|
+
* 面板本身就是配置入口:以前双击 start.bat(有交互终端)时这里会 readline
|
|
986
|
+
* 问 AppID/AppSecret,卡住整条启动链——面板还没起来,用户却被要求在黑框里
|
|
987
|
+
* 输入密钥。而扫码建号的场景下,用户手上本来就没有这俩值(要去面板扫码拿)。
|
|
978
988
|
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
989
|
+
* 现在改成「只提示、不阻塞」:面板照常启动并打开浏览器,前端检测到没有
|
|
990
|
+
* AppID 会自动进入首次启动引导(扫码 / 手填二选一)。BotRuntime 拿空凭证
|
|
991
|
+
* 会报 state=error,引导里填完保存+上线后即恢复。
|
|
992
|
+
*/
|
|
993
|
+
/**
|
|
994
|
+
* 交互终端下不在这里提示:main 会在面板起来之后调用 promptCredentials,
|
|
995
|
+
* 那边把「命令行填 / 回车跳过 / 面板扫码」三条路一次说清,避免刷两遍。
|
|
982
996
|
*/
|
|
983
997
|
if (!stdin.isTTY) {
|
|
984
998
|
console.warn(
|
|
985
999
|
`\n[提示] 机器人 ${botId} 还没有 AppID / AppSecret。\n` +
|
|
986
|
-
`
|
|
987
|
-
` 面板地址见下面的日志。\n`,
|
|
1000
|
+
` 面板会自动打开,在里面扫码或填写即可;也可编辑 ${rel(botPaths(botId).config)}。\n`,
|
|
988
1001
|
);
|
|
989
|
-
return cfg;
|
|
990
1002
|
}
|
|
1003
|
+
return cfg;
|
|
1004
|
+
}
|
|
991
1005
|
|
|
992
|
-
|
|
1006
|
+
/**
|
|
1007
|
+
* 命令行交互补凭证(可选路径,不阻塞面板启动)。
|
|
1008
|
+
*
|
|
1009
|
+
* 由 main 在「面板已启动 + 浏览器已打开」之后调用:有交互终端就问一句,
|
|
1010
|
+
* 用户直接回车跳过(面板引导仍能填)。和面板引导写的是同一份配置,
|
|
1011
|
+
* 面板那边刷新后就能看到新凭证。
|
|
1012
|
+
*
|
|
1013
|
+
* @returns {Promise<object|null>} 更新后的 cfg;跳过或无终端返回 null
|
|
1014
|
+
*/
|
|
1015
|
+
export async function promptCredentials(botId) {
|
|
1016
|
+
if (!stdin.isTTY) return null;
|
|
1017
|
+
const cfg = await loadBotConfig(botId);
|
|
1018
|
+
if (cfg.appId && cfg.appSecret) return null;
|
|
1019
|
+
|
|
1020
|
+
console.log(`\n机器人 ${botId} 还没有凭证。可以直接在这里填,或回车跳过、去面板扫码 / 填写。\n`);
|
|
993
1021
|
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
994
1022
|
try {
|
|
995
|
-
|
|
996
|
-
if (!
|
|
1023
|
+
const appId = (await rl.question('AppID(回车跳过): ')).trim();
|
|
1024
|
+
if (!appId) {
|
|
1025
|
+
console.log('已跳过,请在面板里配置。');
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
const appSecret = (await rl.question('AppSecret: ')).trim();
|
|
1029
|
+
if (!appSecret) {
|
|
1030
|
+
console.log('AppSecret 为空,已跳过。');
|
|
1031
|
+
return null;
|
|
1032
|
+
}
|
|
1033
|
+
cfg.appId = appId;
|
|
1034
|
+
cfg.appSecret = appSecret;
|
|
1035
|
+
await saveBotConfig(botId, cfg);
|
|
1036
|
+
console.log(`已保存到 ${rel(botPaths(botId).config)}\n`);
|
|
1037
|
+
return cfg;
|
|
997
1038
|
} finally {
|
|
998
1039
|
rl.close();
|
|
999
1040
|
}
|
|
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
1041
|
}
|
package/src/hashdir.js
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
* **换行符要归一**:Windows 上 `core.autocrlf=true` 的仓库,检出是 CRLF,
|
|
17
17
|
* 而 GitHub 打的 tarball 里是 LF。按原始字节哈希,两边永远对不上,
|
|
18
18
|
* 结果是「每个插件都校验失败」——比不校验更糟。所以文本文件统一按 LF 算。
|
|
19
|
+
*
|
|
20
|
+
* 两套算法(与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 同步):
|
|
21
|
+
* · algo1 = 老算法,纯文档 / LICENSE 计入指纹;旧索引的 `sha256` 是它算的;
|
|
22
|
+
* · algo2 = 现行算法(HASH_ALGO),排除文档与运行时状态;`sha256_v2` 是它算的。
|
|
23
|
+
* 安装 / 更新时两个都认(见 plugin/market.js 的 entryHashes);框架自更新的
|
|
24
|
+
* `hashFileList()` 仍只走下面的 `isHashedFile()`,行为不变——别把两套规则混起来。
|
|
19
25
|
*/
|
|
20
26
|
import fs from 'node:fs/promises';
|
|
21
27
|
import path from 'node:path';
|
|
@@ -23,19 +29,39 @@ import crypto from 'node:crypto';
|
|
|
23
29
|
import { HASH_SKIP } from './skipdirs.js';
|
|
24
30
|
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* algo1 的老跳过表:1.4.0 及以前就是这几项,只用来校验旧索引的 `sha256`。
|
|
33
|
+
* 来自 ./skipdirs.js 的 HASH_SKIP——改它会改变已发布插件的 sha256,必须同步重建索引。
|
|
34
|
+
*/
|
|
35
|
+
const LEGACY_SKIP_DIRS = HASH_SKIP;
|
|
36
|
+
const LEGACY_SKIP_FILES = new Set(['.deps.json', '.DS_Store', 'Thumbs.db']);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* algo2 额外排除:旧依赖位置、抽帧目录与运行时状态文件。
|
|
40
|
+
* 这些文件不入库,但用户机器上会生成——带进去会让同一份插件算出不同指纹。
|
|
28
41
|
*/
|
|
29
|
-
const
|
|
30
|
-
const
|
|
42
|
+
const SKIP_DIRS_ALGO2 = new Set([...HASH_SKIP, 'deps', 'shots']);
|
|
43
|
+
const SKIP_FILES_ALGO2 = new Set([
|
|
44
|
+
...LEGACY_SKIP_FILES,
|
|
45
|
+
'ui-data.json', 'qr.png', 'cookie.txt',
|
|
46
|
+
'replies.json', 'replied.json', 'pending.json', 'history.json', 'seen.json',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/** 纯文档不进 algo2 指纹:改 README / LICENSE 不该逼维护者重算索引。 */
|
|
50
|
+
function isDocFile(name) {
|
|
51
|
+
const lower = name.toLowerCase();
|
|
52
|
+
return lower.endsWith('.md') || /^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 算法版本。与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 保持一致。 */
|
|
56
|
+
export const HASH_ALGO = 2;
|
|
31
57
|
|
|
32
58
|
/**
|
|
33
|
-
* 一个相对路径(`/`
|
|
59
|
+
* 一个相对路径(`/` 分隔,含文件名)是否参与**框架自更新**的内容指纹。
|
|
34
60
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
61
|
+
* **只服务 hashFileList()(框架自更新 / SHA256SUMS)**,不是插件目录哈希的排除规则:
|
|
62
|
+
* 插件目录哈希走下面 collect() 的 algo1 / algo2 两套表。两处别混——2026-11 就
|
|
63
|
+
* 因为发版脚本漏了这里的文档排除规则,导致 SHA256SUMS 记录的指纹含 17 个
|
|
64
|
+
* md/LICENSE、而更新器解包后算出的不含,v1.1.11 及之后所有版本的自更新全部失败。
|
|
39
65
|
*
|
|
40
66
|
* @param {string} rel 相对路径,如 `src/main.js` / `docs/架构说明.md`
|
|
41
67
|
* @returns {boolean}
|
|
@@ -45,8 +71,8 @@ export function isHashedFile(rel) {
|
|
|
45
71
|
const name = parts.pop();
|
|
46
72
|
if (!name) return false;
|
|
47
73
|
// 任一级目录在跳过表里就排除(与 collect 逐层剪枝等价)
|
|
48
|
-
if (parts.some((seg) =>
|
|
49
|
-
if (
|
|
74
|
+
if (parts.some((seg) => LEGACY_SKIP_DIRS.has(seg))) return false;
|
|
75
|
+
if (LEGACY_SKIP_FILES.has(name)) return false;
|
|
50
76
|
const lower = name.toLowerCase();
|
|
51
77
|
if (lower.endsWith('.md')) return false;
|
|
52
78
|
if (/^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower)) return false;
|
|
@@ -74,7 +100,9 @@ function normalize(buf) {
|
|
|
74
100
|
* @param {string} root
|
|
75
101
|
* @returns {Promise<string[]>} 已排序的相对路径
|
|
76
102
|
*/
|
|
77
|
-
async function collect(root) {
|
|
103
|
+
async function collect(root, algo) {
|
|
104
|
+
const dirs = algo >= 2 ? SKIP_DIRS_ALGO2 : LEGACY_SKIP_DIRS;
|
|
105
|
+
const files = algo >= 2 ? SKIP_FILES_ALGO2 : LEGACY_SKIP_FILES;
|
|
78
106
|
const out = [];
|
|
79
107
|
|
|
80
108
|
const walk = async (dir, prefix) => {
|
|
@@ -86,11 +114,12 @@ async function collect(root) {
|
|
|
86
114
|
}
|
|
87
115
|
for (const it of items) {
|
|
88
116
|
if (it.isDirectory()) {
|
|
89
|
-
if (
|
|
117
|
+
if (dirs.has(it.name)) continue;
|
|
90
118
|
await walk(path.join(dir, it.name), prefix ? `${prefix}/${it.name}` : it.name);
|
|
91
119
|
} else if (it.isFile()) {
|
|
120
|
+
if (files.has(it.name)) continue;
|
|
121
|
+
if (algo >= 2 && isDocFile(it.name)) continue;
|
|
92
122
|
const rel = prefix ? `${prefix}/${it.name}` : it.name;
|
|
93
|
-
if (!isHashedFile(rel)) continue;
|
|
94
123
|
out.push(rel);
|
|
95
124
|
}
|
|
96
125
|
// 符号链接一律跳过:它可能指向仓库外,内容不稳定
|
|
@@ -134,7 +163,9 @@ export async function hashFileList(root, rels) {
|
|
|
134
163
|
* 算目录的内容指纹。
|
|
135
164
|
*
|
|
136
165
|
* @param {string} dir 插件目录
|
|
137
|
-
* @param {{exclude?: string[], only?: string[]}} [opts]
|
|
166
|
+
* @param {{algo?: number, exclude?: string[], only?: string[]}} [opts]
|
|
167
|
+
* - `algo`:1 = 老算法(含文档),2 = 现行算法(排除文档与运行时状态);默认 HASH_ALGO。
|
|
168
|
+
* 校验市场条目时两个都算,见 plugin/market.js 的 entryHashes。
|
|
138
169
|
* - `exclude`:精确匹配要跳过的相对路径(如 `SHA256SUMS` 这种会自引用的文件)
|
|
139
170
|
* - `only`:只算这些路径(`src` 这类目录前缀,或 `package.json` 这类文件名)。
|
|
140
171
|
* 用途:GitHub 的 tarball 是**全量**(含 .github、scripts、sdk),
|
|
@@ -143,6 +174,7 @@ export async function hashFileList(root, rels) {
|
|
|
143
174
|
* @returns {Promise<string>} 64 位十六进制
|
|
144
175
|
*/
|
|
145
176
|
export async function hashDir(dir, opts = {}) {
|
|
177
|
+
const algo = Number.isFinite(opts.algo) ? Number(opts.algo) : HASH_ALGO;
|
|
146
178
|
/**
|
|
147
179
|
* 根目录不存在时必须报错,**不能静默返回空哈希**。
|
|
148
180
|
*
|
|
@@ -156,7 +188,7 @@ export async function hashDir(dir, opts = {}) {
|
|
|
156
188
|
|
|
157
189
|
const skip = new Set(opts.exclude ?? []);
|
|
158
190
|
const only = (opts.only ?? []).map((p) => String(p));
|
|
159
|
-
let files = (await collect(dir)).filter((rel) => !skip.has(rel));
|
|
191
|
+
let files = (await collect(dir, algo)).filter((rel) => !skip.has(rel));
|
|
160
192
|
if (only.length) {
|
|
161
193
|
files = files.filter((rel) =>
|
|
162
194
|
only.some((p) => rel === p || rel.startsWith(p.endsWith('/') ? p : `${p}/`)),
|
package/src/host/ops.js
CHANGED
|
@@ -373,6 +373,8 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
373
373
|
branch: idx.branch || 'main',
|
|
374
374
|
sha256: idx?.archive?.sha256 ?? idx?.sha256 ?? null,
|
|
375
375
|
exists: (pid) => plugins().loaded.has(pid),
|
|
376
|
+
// 与面板共用同一个全局开关,老配置默认开
|
|
377
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
376
378
|
});
|
|
377
379
|
await ensurePluginInList(R, r.id, true, err);
|
|
378
380
|
const scanned = await plugins().rescan();
|
|
@@ -428,6 +430,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
428
430
|
const r = await updatePlugins({
|
|
429
431
|
tmp: repo.tmp, index: repo.index, pluginsDir: DIRS.plugins,
|
|
430
432
|
ids: [id], localVersions: localVers,
|
|
433
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
431
434
|
});
|
|
432
435
|
if (r.failed.length) throw err.bad(r.failed[0].error);
|
|
433
436
|
if (!r.updated.length) throw err.bad(`${id} 没有可用的更新`);
|
|
@@ -448,6 +451,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
448
451
|
const r = await updatePlugins({
|
|
449
452
|
tmp: repo.tmp, index: repo.index,
|
|
450
453
|
pluginsDir: DIRS.plugins, localVersions: localVers,
|
|
454
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
451
455
|
});
|
|
452
456
|
for (const u of r.updated) {
|
|
453
457
|
await plugins().reload(u.id).catch((e) => log(`插件 ${u.id} 重载失败:${e.message}`));
|
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() {
|