@nestim/koishi-plugin-qq-group-manager 1.2.5 → 1.2.7

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/lib/service.d.ts CHANGED
@@ -56,6 +56,14 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
56
56
  pendingJoinRequestFlags: Map<any, any>;
57
57
  violationRecords: Map<any, any>;
58
58
  _imageDataUrlCache: Map<any, any>;
59
+ /** 定时提醒:id -> reminder */
60
+ _reminders: Map<any, any>;
61
+ /** 定时提醒:id -> timer */
62
+ _reminderTimers: Map<any, any>;
63
+ /** 群空闲话题:groupId -> timer */
64
+ _idleTimers: Map<any, any>;
65
+ /** 上次主动话题时间:groupId -> ts */
66
+ _lastIdleTopicAt: Map<any, any>;
59
67
  /** 记忆库写锁:串行化「读整档→改→整写」,防止并发写互相覆盖 */
60
68
  _memoryWriteLock: Promise<void>;
61
69
  /** 待审入群申请的落盘去抖定时器 */
@@ -110,6 +118,22 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
110
118
  ai: AiEngine;
111
119
  /** 外部插件扩展点:提示词风格段 + 输出过滤(接口版本见 AiHookRegistry.version) */
112
120
  get aiHooks(): import("./ai/hooks").AiHookRegistry;
121
+ reminderFilePath(): any;
122
+ loadReminders(): void;
123
+ saveReminders(): void;
124
+ clearReminderTimer(id: any): void;
125
+ scheduleReminder(reminder: any): void;
126
+ fireReminder(id: any): Promise<void>;
127
+ addReminder(reminder: any): void;
128
+ formatReminderTime(at: any): string;
129
+ sendReminderList(session: any): Promise<void>;
130
+ cancelReminder(session: any, id: any): Promise<void>;
131
+ handleReminderCommand(session: any, rest: any): Promise<boolean>;
132
+ handleReminderRequest(session: any): Promise<boolean>;
133
+ touchIdleTopic(session: any): void;
134
+ fireIdleTopic(groupId: any): Promise<void>;
135
+ sendGroupText(groupId: any, text: any): Promise<void>;
136
+ disposeSchedulers(): void;
113
137
  isPlatformAllowed(platform: any): any;
114
138
  sessionTag(session: any): string;
115
139
  styleText(text: any): any;
@@ -291,6 +315,8 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
291
315
  getOneBotApi(session: any): any;
292
316
  /** 供 AI 引擎抽取图片结构 */
293
317
  extractImages(session: any): any[];
318
+ /** 引用消息只带 messageId 时,用 OneBot get_msg 回查图片 */
319
+ fetchQuotedImages(session: any, quote: any): Promise<any[]>;
294
320
  /** 供 AI 引擎把图片引用转成 data URL */
295
321
  resolveImage(ref: any, session: any): Promise<any>;
296
322
  /** AI 回复发送:优先引用触发消息,失败则退化为纯文本 */
@@ -577,5 +603,10 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
577
603
  message: string;
578
604
  }>;
579
605
  }
606
+ /** 解析“提醒/定时”文本;返回 { at, content } 或 null。纯函数,便于测试。 */
607
+ export function parseReminderText(rawText: any, now?: number): {
608
+ at: number;
609
+ content: string;
610
+ };
580
611
  import koishi_1 = require("koishi");
581
612
  import { AiEngine } from "./ai/engine";
package/lib/service.js CHANGED
@@ -13,6 +13,73 @@ try {
13
13
  PLUGIN_VERSION = require('../package.json').version || 'unknown';
14
14
  }
15
15
  catch { /* ignore */ }
16
+ /** 解析“提醒/定时”文本;返回 { at, content } 或 null。纯函数,便于测试。 */
17
+ function parseReminderText(rawText, now = Date.now()) {
18
+ let text = String(rawText || '')
19
+ .replace(/<at\b[^>]*\/?>/gi, ' ')
20
+ .replace(/\[CQ:at,[^\]]+\]/gi, ' ')
21
+ .replace(/^\s*\[bot\]\s*/i, ' ')
22
+ .replace(/\s+/g, ' ')
23
+ .trim();
24
+ if (!text || !/(提醒|定时|叫我)/.test(text))
25
+ return null;
26
+ let at = null;
27
+ let timeMatch = '';
28
+ const rel = text.match(/(半|一|两|二|\d+)\s*(秒钟?|分钟?|小时|钟头)\s*(?:之后|以后|后)/);
29
+ if (rel) {
30
+ const raw = rel[1];
31
+ const num = raw === '半' ? 0.5 : raw === '一' ? 1 : (raw === '两' || raw === '二' ? 2 : Number(raw));
32
+ if (!Number.isFinite(num) || num <= 0)
33
+ return null;
34
+ const ms = /秒/.test(rel[2]) ? num * 1000 : (/小时|钟头/.test(rel[2]) ? num * 3600000 : num * 60000);
35
+ at = now + ms;
36
+ timeMatch = rel[0];
37
+ }
38
+ else {
39
+ const abs = text.match(/(今天|明天|后天)?\s*(早上|上午|中午|下午|晚上|夜里)?\s*(\d{1,2})\s*[::点时]\s*(\d{1,2})?\s*分?/);
40
+ if (!abs)
41
+ return null;
42
+ const dayWord = abs[1] || '';
43
+ const period = abs[2] || '';
44
+ let hour = Number(abs[3]);
45
+ const minute = abs[4] === undefined ? 0 : Number(abs[4]);
46
+ if (!Number.isFinite(hour) || hour > 23 || minute > 59)
47
+ return null;
48
+ if (period === '下午' || period === '晚上' || period === '夜里') {
49
+ if (hour < 12)
50
+ hour += 12;
51
+ }
52
+ else if (period === '中午') {
53
+ if (hour < 11)
54
+ hour += 12;
55
+ }
56
+ else if (period === '早上' || period === '上午') {
57
+ if (hour === 12)
58
+ hour = 0;
59
+ }
60
+ const date = new Date(now);
61
+ date.setSeconds(0, 0);
62
+ date.setHours(hour, minute, 0, 0);
63
+ const offset = dayWord === '明天' ? 1 : (dayWord === '后天' ? 2 : 0);
64
+ if (offset)
65
+ date.setDate(date.getDate() + offset);
66
+ else if (date.getTime() <= now + 30000) {
67
+ if (dayWord === '今天')
68
+ return null;
69
+ date.setDate(date.getDate() + 1);
70
+ }
71
+ at = date.getTime();
72
+ timeMatch = abs[0];
73
+ }
74
+ let content = text.replace(timeMatch, ' ')
75
+ .replace(/^(?:请|麻烦|帮我|帮忙)?\s*(?:提醒我?|定个?时(?:提醒)?|叫我|记得)\s*/, ' ')
76
+ .replace(/\s+/g, ' ')
77
+ .trim();
78
+ content = content.replace(/^[,,。::\s]+/, '').trim();
79
+ if (!content)
80
+ content = '该做你之前说的事了';
81
+ return { at, content };
82
+ }
16
83
  class QQGroupManagerService extends koishi_1.Service {
17
84
  ctx;
18
85
  config;
@@ -23,6 +90,14 @@ class QQGroupManagerService extends koishi_1.Service {
23
90
  pendingJoinRequestFlags = new Map();
24
91
  violationRecords = new Map();
25
92
  _imageDataUrlCache = new Map();
93
+ /** 定时提醒:id -> reminder */
94
+ _reminders = new Map();
95
+ /** 定时提醒:id -> timer */
96
+ _reminderTimers = new Map();
97
+ /** 群空闲话题:groupId -> timer */
98
+ _idleTimers = new Map();
99
+ /** 上次主动话题时间:groupId -> ts */
100
+ _lastIdleTopicAt = new Map();
26
101
  /** 记忆库写锁:串行化「读整档→改→整写」,防止并发写互相覆盖 */
27
102
  _memoryWriteLock = Promise.resolve();
28
103
  /** 待审入群申请的落盘去抖定时器 */
@@ -226,11 +301,249 @@ class QQGroupManagerService extends koishi_1.Service {
226
301
  catch (error) {
227
302
  this._logger.warn(`[join-review] 恢复待审单失败: ${String(error)}`);
228
303
  }
304
+ try {
305
+ this.loadReminders();
306
+ }
307
+ catch (error) {
308
+ this._logger.warn(`[reminder] 恢复待审提醒失败: ${String(error)}`);
309
+ }
310
+ ctx.on('dispose', () => this.disposeSchedulers());
229
311
  }
230
312
  /** 外部插件扩展点:提示词风格段 + 输出过滤(接口版本见 AiHookRegistry.version) */
231
313
  get aiHooks() {
232
314
  return this.ai ? this.ai.hooks : null;
233
315
  }
316
+ reminderFilePath() {
317
+ const base = (this.ctx && this.ctx.baseDir) || process.cwd();
318
+ return node_path_1.default.join(base, 'data', 'qqgm-reminders.json');
319
+ }
320
+ loadReminders() {
321
+ const file = this.reminderFilePath();
322
+ if (!node_fs_1.default.existsSync(file))
323
+ return;
324
+ const list = JSON.parse(node_fs_1.default.readFileSync(file, 'utf8'));
325
+ if (!Array.isArray(list))
326
+ return;
327
+ for (const item of list) {
328
+ if (!item || !item.id || !item.groupId || !item.userId || !Number.isFinite(Number(item.at)))
329
+ continue;
330
+ this._reminders.set(item.id, item);
331
+ this.scheduleReminder(item);
332
+ }
333
+ this._logger.info(`[reminder] 恢复 ${this._reminders.size} 条待提醒`);
334
+ }
335
+ saveReminders() {
336
+ try {
337
+ const file = this.reminderFilePath();
338
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
339
+ node_fs_1.default.writeFileSync(file, JSON.stringify([...this._reminders.values()], null, 2));
340
+ }
341
+ catch (error) {
342
+ this._logger.warn(`[reminder] 保存失败: ${String(error)}`);
343
+ }
344
+ }
345
+ clearReminderTimer(id) {
346
+ const timer = this._reminderTimers.get(id);
347
+ if (timer)
348
+ clearTimeout(timer);
349
+ this._reminderTimers.delete(id);
350
+ }
351
+ scheduleReminder(reminder) {
352
+ this.clearReminderTimer(reminder.id);
353
+ const delay = Math.max(0, Number(reminder.at) - Date.now());
354
+ const max = 2147483647;
355
+ const timer = setTimeout(() => {
356
+ if (delay > max) {
357
+ this.scheduleReminder(reminder);
358
+ return;
359
+ }
360
+ this.fireReminder(reminder.id).catch((error) => this._logger.warn(`[reminder] 触发失败 ${reminder.id}: ${String(error)}`));
361
+ }, Math.min(delay, max));
362
+ timer.unref?.();
363
+ this._reminderTimers.set(reminder.id, timer);
364
+ }
365
+ async fireReminder(id) {
366
+ const reminder = this._reminders.get(id);
367
+ if (!reminder)
368
+ return;
369
+ this._reminders.delete(id);
370
+ this.clearReminderTimer(id);
371
+ this.saveReminders();
372
+ const bots = this.ctx?.bots || [];
373
+ const bot = bots.find((b) => b.platform === 'onebot' && b.status !== 'offline')
374
+ || bots.find((b) => b.platform === 'onebot')
375
+ || bots[0];
376
+ if (!bot) {
377
+ this._logger.warn(`[reminder] 没有可用 bot,跳过 ${id}`);
378
+ return;
379
+ }
380
+ try {
381
+ await bot.sendMessage(reminder.groupId, [koishi_1.h.at(reminder.userId), koishi_1.h.text(` ${reminder.text}`)], reminder.groupId);
382
+ this._logger.info(`[reminder] sent ${id} group=${reminder.groupId} user=${reminder.userId}`);
383
+ }
384
+ catch (error) {
385
+ this._logger.warn(`[reminder] 发送失败 ${id}: ${String(error)}`);
386
+ }
387
+ }
388
+ addReminder(reminder) {
389
+ this._reminders.set(reminder.id, reminder);
390
+ this.saveReminders();
391
+ this.scheduleReminder(reminder);
392
+ }
393
+ formatReminderTime(at) {
394
+ const date = new Date(at);
395
+ const now = new Date();
396
+ const pad = (n) => String(n).padStart(2, '0');
397
+ const day = date.toDateString() === now.toDateString()
398
+ ? '今天'
399
+ : (new Date(now.getTime() + 86400000).toDateString() === date.toDateString()
400
+ ? '明天'
401
+ : `${date.getMonth() + 1}月${date.getDate()}日`);
402
+ return `${day} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
403
+ }
404
+ async sendReminderList(session) {
405
+ const userId = String(session.userId || '');
406
+ const items = [...this._reminders.values()]
407
+ .filter((item) => item.userId === userId)
408
+ .sort((a, b) => a.at - b.at);
409
+ if (!items.length) {
410
+ await this.sendReply(session, '你还没有定时提醒');
411
+ return;
412
+ }
413
+ const lines = items.slice(0, 10).map((item, index) => `${index + 1}. [${item.id}] ${this.formatReminderTime(item.at)} ${item.text}`);
414
+ await this.sendReply(session, lines.join('\n'));
415
+ }
416
+ async cancelReminder(session, id) {
417
+ const key = String(id || '').trim();
418
+ const reminder = this._reminders.get(key);
419
+ if (!reminder || reminder.userId !== String(session.userId || '')) {
420
+ await this.sendReply(session, '没找到这条提醒');
421
+ return;
422
+ }
423
+ this._reminders.delete(key);
424
+ this.clearReminderTimer(key);
425
+ this.saveReminders();
426
+ await this.sendReply(session, `已取消:${reminder.text}`);
427
+ }
428
+ async handleReminderCommand(session, rest) {
429
+ const cmd = String(rest || '').trim();
430
+ if (!cmd)
431
+ return false;
432
+ if (/^(提醒|定时)列表$/.test(cmd)) {
433
+ await this.sendReminderList(session);
434
+ return true;
435
+ }
436
+ const cancel = cmd.match(/^(?:取消提醒|取消定时)\s+(\S+)$/);
437
+ if (cancel) {
438
+ await this.cancelReminder(session, cancel[1]);
439
+ return true;
440
+ }
441
+ if (!/^(提醒|定时)\s+/.test(cmd))
442
+ return false;
443
+ const parsed = parseReminderText(cmd, Date.now());
444
+ if (!parsed)
445
+ return false;
446
+ const reminder = {
447
+ id: `r${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`,
448
+ groupId: String(session.guildId || session.channelId || ''),
449
+ userId: String(session.userId || ''),
450
+ at: parsed.at,
451
+ text: parsed.content,
452
+ createdAt: Date.now(),
453
+ };
454
+ this.addReminder(reminder);
455
+ const confirmation = `好,${this.formatReminderTime(parsed.at)} 提醒你:${parsed.content}`;
456
+ await this.sendReply(session, confirmation);
457
+ try {
458
+ this.ai.recordSelf(session, confirmation);
459
+ }
460
+ catch { /* ignore */ }
461
+ return true;
462
+ }
463
+ async handleReminderRequest(session) {
464
+ if (!session.guildId)
465
+ return false;
466
+ const text = this.extractTextForFilter(session);
467
+ if (!/(提醒|定时|叫我)/.test(text))
468
+ return false;
469
+ const selfId = String(session.bot?.selfId || '');
470
+ const rawContent = String(session.content || '');
471
+ const atBot = !!selfId && new RegExp(`<at\\b[^>]*(?:id|qq)=["']?${selfId}`).test(rawContent);
472
+ if (!atBot && !/^\s*(?:提醒|定时|叫我)/.test(text) && !/^\s*\[bot\]/i.test(rawContent))
473
+ return false;
474
+ const parsed = parseReminderText(text, Date.now());
475
+ if (!parsed)
476
+ return false;
477
+ const reminder = {
478
+ id: `r${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`,
479
+ groupId: String(session.guildId),
480
+ userId: String(session.userId || ''),
481
+ at: parsed.at,
482
+ text: parsed.content,
483
+ createdAt: Date.now(),
484
+ };
485
+ this.addReminder(reminder);
486
+ const confirmation = `好,${this.formatReminderTime(parsed.at)} 提醒你:${parsed.content}`;
487
+ await this.sendReply(session, confirmation);
488
+ try {
489
+ this.ai.recordSelf(session, confirmation);
490
+ }
491
+ catch { /* ignore */ }
492
+ return true;
493
+ }
494
+ touchIdleTopic(session) {
495
+ const groupId = String(session?.guildId || '');
496
+ const minutes = Number(this.config?.aiIdleTopicMinutes ?? 0);
497
+ if (!groupId || !minutes)
498
+ return;
499
+ try {
500
+ if (!this.ai.resolveEnabled(session))
501
+ return;
502
+ }
503
+ catch { /* ignore */ }
504
+ const old = this._idleTimers.get(groupId);
505
+ if (old)
506
+ clearTimeout(old);
507
+ const timer = setTimeout(() => {
508
+ this.fireIdleTopic(groupId).catch((error) => this._logger.warn(`[idle] ${String(error)}`));
509
+ }, minutes * 60000);
510
+ timer.unref?.();
511
+ this._idleTimers.set(groupId, timer);
512
+ }
513
+ async fireIdleTopic(groupId) {
514
+ this._idleTimers.delete(groupId);
515
+ const hour = new Date().getHours();
516
+ const min = Number(this.config?.aiIdleTopicMinHour ?? 9);
517
+ const max = Number(this.config?.aiIdleTopicMaxHour ?? 23);
518
+ if (hour < min || hour >= max)
519
+ return;
520
+ const cooldown = Math.max(1, Number(this.config?.aiIdleTopicCooldownMinutes ?? 60)) * 60000;
521
+ if (Date.now() - (this._lastIdleTopicAt.get(groupId) || 0) < cooldown)
522
+ return;
523
+ const text = await this.ai.idleTopic(groupId);
524
+ if (!text)
525
+ return;
526
+ await this.sendGroupText(groupId, text);
527
+ this._lastIdleTopicAt.set(groupId, Date.now());
528
+ this._logger.info(`[idle] topic sent group=${groupId} chars=${text.length}`);
529
+ }
530
+ async sendGroupText(groupId, text) {
531
+ const bots = this.ctx?.bots || [];
532
+ const bot = bots.find((b) => b.platform === 'onebot' && b.status !== 'offline')
533
+ || bots.find((b) => b.platform === 'onebot')
534
+ || bots[0];
535
+ if (!bot)
536
+ return;
537
+ await bot.sendMessage(groupId, koishi_1.h.text(text), groupId);
538
+ }
539
+ disposeSchedulers() {
540
+ for (const timer of this._reminderTimers.values())
541
+ clearTimeout(timer);
542
+ for (const timer of this._idleTimers.values())
543
+ clearTimeout(timer);
544
+ this._reminderTimers.clear();
545
+ this._idleTimers.clear();
546
+ }
234
547
  isPlatformAllowed(platform) {
235
548
  if (!platform)
236
549
  return false;
@@ -1704,6 +2017,42 @@ class QQGroupManagerService extends koishi_1.Service {
1704
2017
  extractImages(session) {
1705
2018
  return this.extractImageElements(session);
1706
2019
  }
2020
+ /** 引用消息只带 messageId 时,用 OneBot get_msg 回查图片 */
2021
+ async fetchQuotedImages(session, quote) {
2022
+ const id = String(quote?.id || '');
2023
+ if (!id)
2024
+ return [];
2025
+ const onebot = this.getOneBotApi(session);
2026
+ if (!onebot?.getMsg)
2027
+ return [];
2028
+ try {
2029
+ const msg = await onebot.getMsg(id);
2030
+ const message = msg?.message ?? msg?.data?.message;
2031
+ const elements = [];
2032
+ let content = '';
2033
+ if (Array.isArray(message)) {
2034
+ for (const seg of message) {
2035
+ if (seg?.type === 'image') {
2036
+ elements.push({
2037
+ type: 'image',
2038
+ attrs: {
2039
+ src: seg.data?.url || seg.data?.file || '',
2040
+ file: seg.data?.file || '',
2041
+ },
2042
+ });
2043
+ }
2044
+ }
2045
+ }
2046
+ else if (typeof message === 'string') {
2047
+ content = message;
2048
+ }
2049
+ return this.extractImageElements({ content, elements });
2050
+ }
2051
+ catch (error) {
2052
+ this._logger.warn(`[ai] 引用消息取图失败: ${String(error)}`);
2053
+ return [];
2054
+ }
2055
+ }
1707
2056
  /** 供 AI 引擎把图片引用转成 data URL */
1708
2057
  resolveImage(ref, session) {
1709
2058
  return this.resolveImageReferenceToDataUrl(ref, session);
@@ -2267,6 +2616,8 @@ class QQGroupManagerService extends koishi_1.Service {
2267
2616
  await this.sendCommandMenu(session);
2268
2617
  return true;
2269
2618
  }
2619
+ if (await this.handleReminderCommand(session, rest))
2620
+ return true;
2270
2621
  return false;
2271
2622
  }
2272
2623
  if (name === this.cmdPrefix('cmdMute', '[mute]'))
@@ -2698,6 +3049,8 @@ class QQGroupManagerService extends koishi_1.Service {
2698
3049
  async handleGroupModeration(session) {
2699
3050
  if (!this.isPlatformAllowed(session.platform))
2700
3051
  return;
3052
+ if (session.guildId)
3053
+ this.touchIdleTopic(session);
2701
3054
  // AI 上下文先记录:被管控/被指令拦截的消息也要进上下文(指令类由引擎自行忽略)
2702
3055
  try {
2703
3056
  await this.ai.record(session);
@@ -2780,6 +3133,8 @@ class QQGroupManagerService extends koishi_1.Service {
2780
3133
  catch (error) {
2781
3134
  this._logger.warn(`[repeater] failed: ${String(error)} | ${this.sessionTag(session)}`);
2782
3135
  }
3136
+ if (await this.handleReminderRequest(session))
3137
+ return;
2783
3138
  await this.ai.handle(session);
2784
3139
  }
2785
3140
  /**
@@ -3336,3 +3691,4 @@ class QQGroupManagerService extends koishi_1.Service {
3336
3691
  }
3337
3692
  }
3338
3693
  exports.QQGroupManagerService = QQGroupManagerService;
3694
+ exports.parseReminderText = parseReminderText;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qq-group-manager",
3
3
  "description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、图片菜单、状态卡片、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -31,6 +31,7 @@ Koishi 控制台「探索器 Explorer」里查看和手改。
31
31
  | **记忆库** | `[memory]` 保存 / 列出 / 查询 / 删除,落盘 `Memory.md`;开启后 AI 回复会检索并引用相关记忆 |
32
32
  | **AI 群聊回复** | 三道闸门(阈值 / 概率 / 冷却)+ 模型自行 `<pass/>` 决定是否接话;群名片、引用、@ 目标、自己历史发言都进上下文;记忆按相关度注入;图片并发解析并限时。多人格、点名后话题跟随、温度与输出上限 |
33
33
  | **AI 识图** | 图片下载转 data URL 后送入模型,兼容 CQ 码 / HTML `<img>` / 元素三种形态与表情包 |
34
+ | **AI 联网搜索** | 按问题自动判断是否联网,调用 DeepSeek 原生 Search API(复用现有 API Key),结果注入提示词;API 不支持 / 超时 / 无结果时自动回退普通回复 |
34
35
  | **复读** | 连续相同消息达阈值复读,支持图片引用回查;复读事件会进入 AI 上下文 |
35
36
  | **娱乐** | 自我约束(口球)与违规禁言惩罚,可开关与调节参数 |
36
37
 
@@ -101,6 +102,12 @@ npm i @nestim/koishi-plugin-qq-group-manager
101
102
  | `aiReplyDecision` | `single` | `single` 一次调用(推荐)/ `two-stage` 两次调用 |
102
103
  | `aiMaxReplyChars` | `120` | 单条回复最大字符数 |
103
104
  | `aiImageBudgetMs` | `6000` | 图片解析总预算(毫秒),超时跳过 |
105
+ | `aiWebSearchEnabled` | `true` | 启用联网搜索(DeepSeek Search API,复用 `aiApiKey`) |
106
+ | `aiWebSearchMode` | `auto` | `auto` 自动判断 / `always` 每次都搜 / `off` 关闭 |
107
+ | `aiWebSearchMaxResults` | `5` | 每次搜索取几条结果 |
108
+ | `aiWebSearchTimeoutMs` | `4000` | 搜索请求超时(毫秒) |
109
+ | `aiWebSearchMaxPerHour` | `10` | 每个群每小时最多搜索次数;0=不限 |
110
+ | `aiWebSearchCacheMinutes` | `10` | 相同 query 的结果缓存分钟数 |
104
111
  | `aiDebugPrompt` | `false` | 把最终提示词写入日志,排查"答非所问" |
105
112
  | `dryRun` | `false` | 演练模式:只输出计划动作,不真正执行 |
106
113
 
@@ -127,6 +134,11 @@ npm i @nestim/koishi-plugin-qq-group-manager
127
134
  - **识图**:开启 `aiEnableImageRecognition` 后,图片并发下载并转为 data URL 再送入模型;
128
135
  总预算由 `aiImageBudgetMs` 控制(默认 6 秒),超时直接跳过,不再把回复拖到几十秒。
129
136
  模型不支持图片时会自动降级为纯文本并记住该结论,后续不再重复尝试。
137
+ - **联网搜索**:`aiWebSearchMode: auto` 时,只有明确的问题/时效性内容才会触发。
138
+ 调用当前 `aiBaseUrl` 的 DeepSeek Search API(`/v1/tools/search`),复用现有 `aiApiKey`,
139
+ 不需要第三方搜索 Key;结果以 `【联网搜索结果】` 注入,模型一次回答。
140
+ API 不支持(400/401/403/404)、超时、没结果时会**自动放弃搜索**,继续普通模型调用。
141
+ 默认每群每小时最多 10 次,相同 query 缓存 10 分钟。
130
142
  - **输出**:单条消息,`aiMaxReplyChars`(默认 120)限制长度;推荐 `aiTemperature` 0.7~0.9。
131
143
  - **调试**:`aiDebugPrompt` 打开后会把最终提示词写进日志,便于排查"到底看到了什么"。
132
144
  - **扩展点**:`ctx.nestimQqGroupManager.aiHooks`(接口版本 1)。外部插件可