qq-bot-roost 1.1.14 → 1.1.15

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-1455%20passed-brightgreen" alt="测试 1455 项">
11
+ <img src="https://img.shields.io/badge/tests-1481%20passed-brightgreen" alt="测试 1481 项">
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.14-blueviolet" alt="版本 1.1.14">
13
+ <img src="https://img.shields.io/badge/version-1.1.15-blueviolet" alt="版本 1.1.15">
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
 
@@ -508,7 +508,7 @@ bot/
508
508
  │ └── plugin/ 插件加载、配置、依赖、子进程宿主、面板页面注册
509
509
  ├── test/
510
510
  │ ├── selftest.mjs 框架自检(712 项)
511
- │ ├── e2e.mjs 端到端测试(253 项,起真实服务打接口)
511
+ │ ├── e2e.mjs 端到端测试(244 项,起真实服务打接口)
512
512
  │ ├── qrlogin.mjs 扫码建机器人(8 项)
513
513
  │ └── deps.mjs 插件依赖安装(11 项)
514
514
  ├── web/ 面板前端(原生 JS/CSS,无构建)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qq-bot-roost",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
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/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",
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/mention-routing.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/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",
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/mention-routing.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
@@ -1178,7 +1178,17 @@ export class BotRuntime {
1178
1178
  * 传的是**完整 msg**(含 uin / msgIdx / attachments),不走 message-bus——
1179
1179
  * 那条通道的 payload 是对外契约,故意脱敏过,拿不到 ID 映射要的东西。
1180
1180
  */
1181
- if (hasMessageContent(msg)) {
1181
+ /**
1182
+ * 「静默消息是否交给协议层」开关(plugins.forwardSilentToProtocol,默认 true):
1183
+ * silent 消息(@ 别的机器人 / 只回@模式的闲聊 / 命令必须@模式的裸命令)
1184
+ * 在框架内部一律不响应,但要不要让 DSH 宿主 / OneBot 客户端也看到它,
1185
+ * 交给用户决定——默认照旧全交(`!== false` 让没写过这个字段的老配置保持原样)。
1186
+ * 关掉后这些消息不进协议层:DSH 的 ai 模式就不会再「补一句」(issue #38 的另一半)。
1187
+ * 注意转发在下面的静默闸之前,所以必须在这一层拦;观测通道(message-bus /
1188
+ * 日志)仍看得到,面板能查「确实收到过这条」。
1189
+ */
1190
+ const forwardSilent = cfg?.plugins?.forwardSilentToProtocol !== false;
1191
+ if (hasMessageContent(msg) && (!msg.silent || forwardSilent)) {
1182
1192
  this.onebot?.onMessage(msg);
1183
1193
  /** 宿主协议:传完整 msg(原生结构),它自己挑字段 */
1184
1194
  this.host?.onMessage(msg);
@@ -1208,7 +1218,8 @@ export class BotRuntime {
1208
1218
 
1209
1219
  this.logIncoming(msg);
1210
1220
 
1211
- if (msg.mentioned || msg.isCommand) session.markAddressed(msg.chatId);
1221
+ // @ 别的机器人 / 只回@模式下的裸命令:不写免@窗口,免得后续闲聊被当 addressed(issue #38)
1222
+ if (!msg.silent && (msg.mentioned || msg.isCommand)) session.markAddressed(msg.chatId);
1212
1223
 
1213
1224
  /**
1214
1225
  * 兼容模式「独占」:**插件**不再回话,内核命令也只留绑定那四条。
@@ -1251,6 +1262,14 @@ export class BotRuntime {
1251
1262
 
1252
1263
  this.#rememberPerson(msg);
1253
1264
 
1265
+ /**
1266
+ * 静默消息(issue #38):明确 @ 了别的机器人,或「只回@ / 命令必须@」模式下的裸命令。
1267
+ * 放在 pipeline 之后:去重 / 白名单 / 限流 / 暂停闸照跑(别的地方也别想绕过),
1268
+ * 但到这里整条掐断——不执行命令、不 session.deliver、不进插件与 AI 模型。
1269
+ * 观测(metrics / stats / 记人)在上面已经做完,面板仍看得到「收到过这条」。
1270
+ */
1271
+ if (msg.silent) return;
1272
+
1254
1273
  if (msg.isCommand && commandEntry) {
1255
1274
  /**
1256
1275
  * 独占模式只放行「绑定四件套」,其余内核命令一律静默。
package/src/config.js CHANGED
@@ -185,6 +185,33 @@ const GLOBAL_DEFAULTS = {
185
185
  * 只在索引与框架算法版本错位的过渡期临时用,修好后请打开。
186
186
  */
187
187
  verifyHash: true,
188
+ /**
189
+ * 只回 @ 消息(全局,默认关;只作用于群聊)。
190
+ * 开后群聊里只有明确 @ 本机器人的消息才算 addressed——裸 `/命令`、
191
+ * 普通闲聊、免@窗口一律静默。单聊天生一对一,不受影响。
192
+ * 与 commandRequiresMention 可叠加:前者管所有消息,后者只管命令。
193
+ */
194
+ groupOnlyMentioned: false,
195
+ /**
196
+ * @ 了别的机器人就静默(默认开;issue #38)。
197
+ * 群里同时有好几个机器人时,@ 别的机器人不该把本机器人吵起来。
198
+ * 默认开、行为与修复前一致地「只理 @ 我的」;关掉则恢复旧行为
199
+ * (官方 mentions 里 bot=true 也算 @ 我,容易误触发)。同时 @ 我仍照常回复。
200
+ */
201
+ ignoreOtherBotMention: true,
202
+ /**
203
+ * 命令必须 @ 才回复(全局,默认关;只作用于群聊,issue #38)。
204
+ * 开后群聊里裸 `/命令` 静默(不解析、不回「没有这个命令」),
205
+ * 但普通闲聊照旧进插件 / 模型。只要明确了 @ 别的机器人,无论本开关如何都静默。
206
+ */
207
+ commandRequiresMention: false,
208
+ /**
209
+ * 静默消息是否交给协议层(默认 true;issue #38)。
210
+ * silent 消息(@ 别的机器人 / 上面两个开关静默掉的消息)在框架内部一律不响应;
211
+ * 这个开关只决定要不要把它们推给 DSH 宿主与 OneBot 客户端。默认全交、行为不变;
212
+ * 关掉后协议层看不到这些消息,DSH 的 ai 模式也就不会「补一句」。
213
+ */
214
+ forwardSilentToProtocol: true,
188
215
  /** Go 插件用的 go 可执行文件路径,留空则用 PATH 里的 go 或 GO_BIN 环境变量 */
189
216
  goBin: '',
190
217
  /**
package/src/message.js CHANGED
@@ -152,6 +152,33 @@ function detectMention(d) {
152
152
  return MENTION_TEST.test(String(d?.content ?? ''));
153
153
  }
154
154
 
155
+ /**
156
+ * 这条消息是否**明确只 @ 了别的机器人**(issue #38)。
157
+ *
158
+ * 官方 `GroupMentionsUser` 里 `is_you` 才是「@ 的是当前这个 bot」,`bot`
159
+ * 只表示「被 @ 的是个机器人」。`detectMention()` 历史用 `is_you || bot`
160
+ * 做「有没有 @ 我」的宽松判断,于是多机器人群里 @B 也被算成 @ 我。
161
+ *
162
+ * 这里不推翻那个宽松口径(正文正则 fallback 还要靠它),而是单独识别
163
+ * 「官方字段明确说 @ 了机器人、但明确不是我」的情况:
164
+ * · `m.bot === true && m.is_you === false` —— 明确是别的机器人
165
+ * · 只要有一个 `m.is_you === true` 就不算(同时 @ 了我,该响应)
166
+ * · `scope === 'all'` 是 @全体,不是 @机器人,不算
167
+ * · 没有官方 mentions 字段(如 GROUP_AT_MESSAGE_CREATE)时返回 false——
168
+ * 那种事件 content 已去掉 @ 前缀,无从判断,不能瞎静默
169
+ *
170
+ * 保守取向:宁可漏静默(多回一句),不可误静默(该回的没回)。
171
+ */
172
+ function detectOtherBotMention(d) {
173
+ const list = Array.isArray(d?.mentions) ? d.mentions : [];
174
+ if (!list.length) return false;
175
+ // 同时 @ 了我 → 按「@ 我」处理,不静默
176
+ if (list.some((m) => m && m.is_you === true)) return false;
177
+ return list.some(
178
+ (m) => m && m.bot === true && m.is_you === false && m.scope !== 'all',
179
+ );
180
+ }
181
+
155
182
  /**
156
183
  * 附件归一化。
157
184
  *
@@ -355,6 +382,16 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
355
382
  const prefix = cfg.commandPrefix || '/';
356
383
  const isCommand = content.startsWith(prefix);
357
384
  const mentioned = detectMention(d);
385
+ /**
386
+ * @ 了别的机器人(issue #38)。只在官方字段**明确**时生效——正文正则
387
+ * fallback 那条不动,避免误静默。是否因此静默由开关决定(默认静默):
388
+ * `ignoreOtherBotMention=false` 时恢复旧行为(@ 任意机器人都算 @ 我)。
389
+ * `mentionedOtherBot` 始终报告「检测到」这个事实,与开关无关。
390
+ */
391
+ const mentionedOtherBot = detectOtherBotMention(d);
392
+ const ignoreOtherBot =
393
+ mentionedOtherBot && cfg?.plugins?.ignoreOtherBotMention !== false;
394
+ const effectiveMentioned = ignoreOtherBot ? false : mentioned;
358
395
  const chatId = groupId || userId;
359
396
  const receivedAt = Date.now();
360
397
 
@@ -381,7 +418,24 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
381
418
 
382
419
  // 没 @ 也不算命令,但可能处在免@窗口内 —— 此时同样算「在跟机器人说话」
383
420
  const sticky = Boolean(session?.isSticky(chatId));
384
- const addressed = mentioned || isCommand || sticky;
421
+ /**
422
+ * 「只回复 @ 我」开关(plugins.groupOnlyMentioned,默认关):
423
+ * 开后群聊里只有明确 @ 本机器人的消息才算 addressed,裸 `/命令` 与
424
+ * 免@窗口都不算。单聊天生是一对一,不受影响。
425
+ *
426
+ * 与 issue #38 的 @ 别的机器人静默叠加:后者默认开,可用
427
+ * `ignoreOtherBotMention=false` 关掉,关掉后 @ 别的机器人恢复旧行为。
428
+ */
429
+ const onlyMentioned = cfg?.plugins?.groupOnlyMentioned === true && kind === 'group';
430
+ /** 「命令必须 @ 我」开关(plugins.commandRequiresMention,默认关):只管命令,闲聊不受影响 */
431
+ const cmdRequiresMention =
432
+ cfg?.plugins?.commandRequiresMention === true &&
433
+ kind === 'group' &&
434
+ isCommand &&
435
+ !effectiveMentioned;
436
+ const addressed =
437
+ !ignoreOtherBot &&
438
+ (effectiveMentioned || (onlyMentioned || cmdRequiresMention ? false : isCommand || sticky));
385
439
 
386
440
  /**
387
441
  * 官方事件里以前被整个丢掉的载荷。
@@ -462,7 +516,10 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
462
516
 
463
517
  content,
464
518
  raw: d,
465
- mentioned,
519
+ /** 修正后的「@ 我」:@ 了别的机器人时这里是 false(issue #38) */
520
+ mentioned: effectiveMentioned,
521
+ /** 明确 @ 了别的机器人(客观检测结果,与 ignoreOtherBotMention 开关无关) */
522
+ mentionedOtherBot,
466
523
  /**
467
524
  * 本条消息 @ 了谁(不含机器人自己)。
468
525
  *
@@ -547,7 +604,10 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
547
604
  quoted: elements.find((e) => e.type === 'quote')?.content ?? '',
548
605
 
549
606
  sticky,
607
+ /** 是否「在跟我说话」:@ 别的机器人 / 只回@模式下的裸命令都为 false */
550
608
  addressed,
609
+ /** 是否该整条静默(命令闸与会话投递统一读它) */
610
+ silent: ignoreOtherBot || (onlyMentioned && !effectiveMentioned) || cmdRequiresMention,
551
611
  isCommand,
552
612
  receivedAt, // 被动回复窗口从这里开始算,出站调度器要用
553
613
  replied: false, // 任何发送动作都会置为 true,供内核判断「有没有插件回应」
package/src/pipeline.js CHANGED
@@ -182,7 +182,8 @@ export function ratelimitMiddleware(cfg, { isSticky = () => false, metrics = nul
182
182
  return async (ctx, next) => {
183
183
  const rl = cfg.rateLimit ?? {};
184
184
  const msg = ctx.msg;
185
- const addressed = msg.mentioned || msg.isCommand || isSticky(msg.chatId);
185
+ // 静默消息(@ 别的机器人 / 只回@模式下的裸命令)不占额度,也不该被限流回复打岔
186
+ const addressed = !msg.silent && (msg.mentioned || msg.isCommand || isSticky(msg.chatId));
186
187
  if (!rl.enabled || !msg.chatId || !addressed) return next();
187
188
 
188
189
  const limit = Math.max(1, rl.perChatPerMinute ?? 30);
@@ -55,6 +55,9 @@ export function serializeMessage(msg, extra = {}) {
55
55
  command: msg.command || '',
56
56
  args: msg.args ?? [],
57
57
  mentioned: Boolean(msg.mentioned),
58
+ addressed: Boolean(msg.addressed),
59
+ /** 静默消息(@ 别的机器人 / 只回@模式下裸命令):插件应直接跳过,不要搭话 */
60
+ silent: Boolean(msg.silent),
58
61
  isCommand: Boolean(msg.isCommand),
59
62
  at: msg.at ?? Date.now(),
60
63
  /**
@@ -237,6 +237,7 @@ export function makeMsg({
237
237
  sticky = false,
238
238
  mentions = null,
239
239
  raw = null,
240
+ silent,
240
241
  } = {}) {
241
242
  const replies = [];
242
243
  /** markdown 消息单独记一份,好断言「走的是富文本还是纯文本」 */
@@ -261,8 +262,10 @@ export function makeMsg({
261
262
  args: isCommand ? parts.slice(1) : parts,
262
263
  isCommand,
263
264
  mentioned,
264
- // 和 message.js 保持一致:@ 了、是命令、或还在免 @ 窗口里,都算「在跟我说话」
265
- addressed: mentioned || isCommand || sticky,
265
+ // 和 message.js 保持一致:@ 了、是命令、或还在免 @ 窗口里,都算「在跟我说话」;
266
+ // silent 由调用方显式给(@ 别的机器人 / 只回@模式),默认按没有静默处理
267
+ silent: Boolean(silent),
268
+ addressed: silent ? false : mentioned || isCommand || sticky,
266
269
  sticky,
267
270
  mentions: mentions ?? [],
268
271
  raw: raw ?? (kind === 'group' ? { author: { member_role: 'member' } } : {}),
@@ -374,6 +377,7 @@ export async function runCommand(plugin, command, opts = {}) {
374
377
  mentioned: opts.mentioned,
375
378
  mentions: opts.mentions,
376
379
  raw: opts.raw,
380
+ silent: opts.silent,
377
381
  });
378
382
 
379
383
  await handler(msg, { args: msg.args, raw: msg.content });
package/src/web/server.js CHANGED
@@ -2079,6 +2079,20 @@ async function startWebServerInstance({
2079
2079
  if (body.dedupWindowSec !== undefined) {
2080
2080
  cfg.dedupWindowSec = Math.max(0, Number(body.dedupWindowSec) || 0);
2081
2081
  }
2082
+ /**
2083
+ * @ 回复策略(bot 级;message.js 每条消息现读 cfg.plugins,立即生效)。
2084
+ * 严格只认布尔,漏给的不动——面板和旧脚本可能只提交其中一个。
2085
+ * 用 merge 而不是替换,避免冲掉 autoInstallDeps / verifyHash 等其它 plugins 字段。
2086
+ */
2087
+ if (body.plugins && typeof body.plugins === 'object') {
2088
+ const patch = {};
2089
+ for (const key of ['groupOnlyMentioned', 'ignoreOtherBotMention', 'commandRequiresMention', 'forwardSilentToProtocol']) {
2090
+ if (typeof body.plugins[key] === 'boolean') patch[key] = body.plugins[key];
2091
+ }
2092
+ if (Object.keys(patch).length) {
2093
+ cfg.plugins = { ...(cfg.plugins ?? {}), ...patch };
2094
+ }
2095
+ }
2082
2096
  /**
2083
2097
  * 连接方式:面板一直在提交这个字段,但服务端从来没读过——
2084
2098
  * 用户选「Webhook」保存后毫无变化、也没有任何提示,以为已经切了。
package/web/app.js CHANGED
@@ -1961,6 +1961,13 @@ function fillForm(c) {
1961
1961
  f.rateLimitEnabled.checked = c.rateLimit?.enabled !== false;
1962
1962
  f.perChatPerMinute.value = c.rateLimit?.perChatPerMinute ?? 30;
1963
1963
  f.dedupWindowSec.value = c.dedupWindowSec ?? 120;
1964
+ // @ 回复策略(bot 级;与 message.js 的 plugins.* 对应)
1965
+ // @ 别的机器人静默:默认开,所以用 !== false(老配置没这个字段也算开)
1966
+ f.ignoreOtherBotMention.checked = c.plugins?.ignoreOtherBotMention !== false;
1967
+ f.groupOnlyMentioned.checked = c.plugins?.groupOnlyMentioned === true;
1968
+ f.commandRequiresMention.checked = c.plugins?.commandRequiresMention === true;
1969
+ // 静默消息交给协议层:默认开,所以用 !== false(老配置没这个字段也算开)
1970
+ f.forwardSilentToProtocol.checked = c.plugins?.forwardSilentToProtocol !== false;
1964
1971
 
1965
1972
  const ml = c.messageLog ?? {};
1966
1973
  f.messageLogEnabled.checked = ml.enabled !== false;
@@ -2430,6 +2437,12 @@ function collectAutoPayload(f) {
2430
2437
  perChatPerMinute: Number(f.perChatPerMinute.value) || 30,
2431
2438
  },
2432
2439
  dedupWindowSec: Number(f.dedupWindowSec.value) || 0,
2440
+ plugins: {
2441
+ ignoreOtherBotMention: f.ignoreOtherBotMention.checked,
2442
+ groupOnlyMentioned: f.groupOnlyMentioned.checked,
2443
+ commandRequiresMention: f.commandRequiresMention.checked,
2444
+ forwardSilentToProtocol: f.forwardSilentToProtocol.checked,
2445
+ },
2433
2446
  messageLog: {
2434
2447
  enabled: f.messageLogEnabled.checked,
2435
2448
  muteKinds: [
@@ -2525,6 +2538,12 @@ async function saveCfgForm({ fromQr = false } = {}) {
2525
2538
  perChatPerMinute: Number(f.perChatPerMinute.value) || 30,
2526
2539
  },
2527
2540
  dedupWindowSec: Number(f.dedupWindowSec.value) || 0,
2541
+ plugins: {
2542
+ ignoreOtherBotMention: f.ignoreOtherBotMention.checked,
2543
+ groupOnlyMentioned: f.groupOnlyMentioned.checked,
2544
+ commandRequiresMention: f.commandRequiresMention.checked,
2545
+ forwardSilentToProtocol: f.forwardSilentToProtocol.checked,
2546
+ },
2528
2547
  messageLog: {
2529
2548
  enabled: f.messageLogEnabled.checked,
2530
2549
  muteKinds: [
package/web/index.html CHANGED
@@ -961,6 +961,32 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
961
961
  <label>去重窗口(秒)<input name="dedupWindowSec" type="number" min="0"></label>
962
962
  </div>
963
963
  <div class="divider"></div>
964
+ <div class="intent-group-title">@ 回复策略</div>
965
+ <div class="hint" style="margin-bottom:6px">
966
+ 默认只有第一项开、后两项关:群里 @ 别的机器人不理会,裸 <code>/命令</code> 与免@窗口照旧算「在跟我说话」。
967
+ 后两项只作用于群聊,私聊一对一不受影响。
968
+ </div>
969
+ <label class="switch">
970
+ <input type="checkbox" name="ignoreOtherBotMention" checked>
971
+ @ 别的机器人时静默(默认开;同时 @ 我仍照常回复)
972
+ </label>
973
+ <label class="switch">
974
+ <input type="checkbox" name="groupOnlyMentioned">
975
+ 只回复 @ 我的消息(群聊里裸 <code>/命令</code> 和普通闲聊都不回应)
976
+ </label>
977
+ <label class="switch">
978
+ <input type="checkbox" name="commandRequiresMention">
979
+ /命令 必须 @ 我才回复(普通闲聊照旧进插件 / 模型)
980
+ </label>
981
+ <label class="switch">
982
+ <input type="checkbox" name="forwardSilentToProtocol" checked>
983
+ 静默消息仍交给协议层(默认开;关掉后 DSH 宿主 / OneBot 客户端也看不到这些消息)
984
+ </label>
985
+ <div class="hint" style="margin-top:4px">
986
+ 上面几种静默消息在框架内部一律不回复。本开关只管<b>要不要把它们推给外部协议层</b>:
987
+ 默认全交(和以前一样);关掉后连 DSH 的 AI 模式也看不到,就不会「补一句」。不影响本框架收到消息的记录。
988
+ </div>
989
+ <div class="divider"></div>
964
990
  <div class="intent-group-title">消息日志</div>
965
991
  <label class="switch">
966
992
  <input type="checkbox" name="messageLogEnabled">