qq-bot-roost 1.1.4 → 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 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-1284%20passed-brightgreen" alt="测试 1284 项">
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.4-blueviolet" alt="版本 1.1.4">
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
 
@@ -506,9 +506,9 @@ openid 完全不同。共享 `roles.json` 等于所有权限记录全部对不
506
506
  ## 开发
507
507
 
508
508
  ```bash
509
- npm test # 自检 686 + qrlogin 8 + deps 11 + npm-registry 12 + deps-external 4,另跑 52 个 node:test 文件(共 563 项)
509
+ npm test # 自检 686 + qrlogin 8 + deps 11 + npm-registry 12 + deps-external 4,另跑 53 个 node:test 文件(共 568 项)
510
510
  npm run test:e2e # 端到端 253 项(起 mock 服务打全部接口,跑在临时目录)
511
- npm run test:all # 全量约 1537 项:自检 + 扫码 + 依赖 + e2e(真机驱动要真机,没配就跳过)
511
+ npm run test:all # 全量约 1542 项:自检 + 扫码 + 依赖 + e2e(真机驱动要真机,没配就跳过)
512
512
  npm run check:secrets # 扫硬编码凭据(CI 也跑这个,提交前建议过一遍)
513
513
  node src/main.js --mock # 不连 QQ,命令行发假消息调插件
514
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.4",
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
- * - 命令只放 `__core`,插件命令静默忽略
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` 是内核命令(绑定 / 管理 / help),必须留着——
1209
- * 否则 OneBot 的 ID 映射永远拿不到真 QQ 号。
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.pluginId !== '__core') {
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
+ }