@nestim/koishi-plugin-qq-group-manager 1.1.4 → 1.2.0

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
@@ -1,158 +1,579 @@
1
- import { Context, Service, Session } from 'koishi';
2
- import type { Config } from './index';
3
- import type { ActionResult, AuthorizationResult, MuteParseResult } from './types';
4
- declare module 'koishi' {
5
- interface Context {
6
- nestimQqGroupManager: QQGroupManagerService;
7
- }
8
- }
9
- export declare class QQGroupManagerService extends Service {
10
- ctx: Context;
11
- config: Config;
12
- private _logger;
13
- private unauthorizedMuteAttempts;
14
- private aiBuffers;
15
- private aiCounters;
16
- private aiLastReplyAt;
17
- private aiInFlight;
18
- private aiHandledEvents;
19
- private aiFollowups;
20
- private aiUserMemory;
21
- private repeatStates;
22
- private aiTopicMemory;
23
- private pendingJoinRequests;
24
- private pendingJoinRequestFlags;
25
- private violationRecords;
26
- constructor(ctx: Context, config: Config);
27
- isPlatformAllowed(platform?: string): boolean;
28
- private sessionTag;
29
- private styleText;
30
- private getMessageText;
31
- private aiGroupKey;
32
- private resolveAiEnabled;
33
- private extractAiMessageText;
34
- private getDisplayName;
35
- private isHomeUser;
36
- private rememberUser;
37
- private getFollowupSession;
38
- private tokenizeTopic;
39
- private scoreTopicRelevance;
40
- private startFollowupSession;
41
- private bumpFollowupSession;
42
- private shouldContinueFollowup;
43
- private getActivePersona;
44
- private getActiveAgentName;
45
- private getActiveSystemPrompt;
46
- private containsAgentName;
47
- private isMentionBot;
48
- private isCommandLikeMessage;
49
- private isDuplicateAiEvent;
50
- private pushAiRecord;
51
- private appendAiContextNote;
52
- private shouldTriggerAiReply;
53
- private parseInterestDecision;
54
- private buildInterestContextPrompt;
55
- private decideInterestByOpenAI;
56
- private decideInterestByGemini;
57
- private shouldReplyByInterest;
58
- private buildAiUserPrompt;
59
- private normalizeAiOutput;
60
- private sanitizeAiOutputForSend;
61
- private splitAiReplyParts;
62
- private waitHumanLikeDelay;
63
- private isAddressingOtherThanBot;
64
- private extractAiImageUrls;
65
- private callOpenAiCompatible;
66
- private callGemini;
67
- private extractImageUrls;
68
- private extractMessageImageUrls;
69
- private extractImageFingerprintKeys;
70
- private normalizeRepeatText;
71
- private buildRepeatPayload;
72
- private parseCqImageParams;
73
- private extractImageRefsFromRawMessage;
74
- private extractImageSegmentsFromRawMessage;
75
- private extractImageSendRefs;
76
- private fetchMessageImagePayload;
77
- private sendImageRef;
78
- private handleRepeater;
79
- private callOpenAiCompatibleWithImages;
80
- private generateAiReply;
81
- private maybeReplyWithAi;
82
- private isBotOwnerInGroup;
83
- private logAuth;
84
- logCommandResult(command: string, result: ActionResult, session?: Session, extra?: Record<string, unknown>): void;
85
- authorizeCommand(command: string, session?: Session): Promise<AuthorizationResult>;
86
- authorize(session?: Session): Promise<AuthorizationResult>;
87
- canUseAdminCommand(session?: Session): Promise<AuthorizationResult>;
88
- private resolveMemberRole;
89
- private normalizeRole;
90
- private parseTargetId;
91
- private randomMinutes;
92
- private extractAtIds;
93
- private parseDurationToken;
94
- private extractMuteTokens;
95
- private looksLikeMemberInGroup;
96
- parseMuteArguments(session?: Session): Promise<MuteParseResult>;
97
- private getMemoryFilePath;
98
- private readMemoryFile;
99
- private writeMemoryFile;
100
- private extractMemoryBlocks;
101
- private saveMemoryToFile;
102
- private searchMemory;
103
- private decoratePromptWithMemory;
104
- private handleMemoryCommand;
105
- private isImageSendableUrl;
106
- describeImageMessage(session?: Session): {
107
- hasCqImage: boolean;
108
- rawCq: string[];
109
- elementImages: any[];
110
- extractableUrls: string[];
1
+ export const __esModule: boolean;
2
+ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Context> {
3
+ /**
4
+ * 违禁词分档默认分值(可通过配置用 "关键词|分值" 或 {keyword,score} 覆盖)
5
+ * 设计原则:单独出现时属于强广告特征的词给高分(可独立触发),
6
+ * 需要组合才能确认的弱特征词给低分(需多条累计)。
7
+ */
8
+ static DEFAULT_BANNED_WORD_SCORES: {
9
+ 加群: number;
10
+ 拉人: number;
11
+ 拉群: number;
12
+ 互推: number;
13
+ 引流: number;
14
+ 加微信: number;
15
+ 加v: number;
16
+ 加V: number;
17
+ 加qq: number;
18
+ 加QQ: number;
19
+ 扫码进群: number;
20
+ 进群领: number;
21
+ 加我好友: number;
22
+ 私信我: number;
23
+ 点击链接: number;
24
+ 刷单: number;
25
+ 躺赚: number;
26
+ 日结: number;
27
+ 邀请你: number;
28
+ 问卷: number;
29
+ 兼职: number;
30
+ 赚钱: number;
31
+ 赚米: number;
32
+ 返利: number;
33
+ 代理: number;
34
+ 招人: number;
35
+ 零成本: number;
36
+ 速来: number;
37
+ 福利群: number;
38
+ 红包群: number;
39
+ 活动群: number;
40
+ 转发群: number;
41
+ 免费领: number;
42
+ 免费送: number;
43
+ 领红包: number;
44
+ 抢红包: number;
45
+ 领福利: number;
46
+ 点击查看: number;
47
+ 名额有限: number;
48
+ };
49
+ static DEFAULT_BANNED_WORD_SCORE: number;
50
+ constructor(ctx: any, config: any);
51
+ ctx: any;
52
+ _logger: any;
53
+ unauthorizedMuteAttempts: Map<any, any>;
54
+ repeatStates: Map<any, any>;
55
+ pendingJoinRequests: Map<any, any>;
56
+ pendingJoinRequestFlags: Map<any, any>;
57
+ violationRecords: Map<any, any>;
58
+ _imageDataUrlCache: Map<any, any>;
59
+ /** 记忆库写锁:串行化「读整档→改→整写」,防止并发写互相覆盖 */
60
+ _memoryWriteLock: Promise<void>;
61
+ /** 待审入群申请的落盘去抖定时器 */
62
+ _pendingJoinSaveTimer: any;
63
+ /** 待审单落盘串行化(防止 dispose 与去抖写同时进行) */
64
+ _pendingJoinWriteChain: Promise<void>;
65
+ /** 待审单落盘 helper */
66
+ runPendingJoinWriteLocked(task: any): Promise<any>;
67
+ /** 安全读取布尔配置(字段缺失/未定义时返回默认值) */
68
+ cfgBool(key: any, def: any): any;
69
+ /** 事件里的操作者 QQ(踢人事件用) */
70
+ eventOperatorId(session: any): string;
71
+ /**
72
+ * 把任意形态的 ID 归一成纯数字 QQ 号,便于比较。
73
+ * 兼容 'onebot:12345'、12345(number)、'12345'。
74
+ * selfId 取自 session.bot.selfId(session.selfId 在 Koishi 里通常不存在)。
75
+ */
76
+ normalizeQqForCompare(value: any): string;
77
+ /** bot 自身 QQ */
78
+ selfQqForCompare(session: any): string;
79
+ /**
80
+ * 求「被移出群聊的人」的 QQ,并标记身份是否可确证。
81
+ *
82
+ * 字段语义(Koishi onebot):
83
+ * - `session.targetId` 存在时,就是被移出的人,最可信;
84
+ * - `session.userId` 在移出事件里通常是**操作者**(bot 自己踢人时就是 bot),
85
+ * 只有没有 targetId 时才退而用它,且仅当它与操作者不同(=当时是被踢者)才可采信;
86
+ * - 永远排除 bot 自己。
87
+ *
88
+ * 返回 `{ id, certain }`。`certain=false` 表示只是猜测,宁可漏记也不误拉黑。
89
+ */
90
+ resolveRemovedMemberId(session: any): {
91
+ id: string;
92
+ certain: boolean;
93
+ };
94
+ /** 踢人后记入黑名单(供自动踢人/手动踢人复用) */
95
+ recordKickToBlacklist(session: any, qq: any): Promise<void>;
96
+ /**
97
+ * 群成员被移出 → 记入本群黑名单。
98
+ *
99
+ * 只在「明确判定为被踢」时记录。历史 bug:原先写的是
100
+ * `if (session.subtype && session.subtype !== 'passive') return;`,
101
+ * subtype 缺失(undefined)时会继续往下走,把**主动退群**的人也当被踢记进黑名单,
102
+ * 并且会误用 session.userId(可能是踢人者/事件消费者)。
103
+ * 现在改为白名单式判定:只有 subtype === 'passive' 才处理。
104
+ */
105
+ handleMemberRemoved(session: any): Promise<void>;
106
+ /**
107
+ * 有人入群 → 比对黑名单,命中则踢出并提示。
108
+ */
109
+ handleMemberAdded(session: any): Promise<void>;
110
+ ai: AiEngine;
111
+ isPlatformAllowed(platform: any): any;
112
+ sessionTag(session: any): string;
113
+ styleText(text: any): any;
114
+ getMessageText(session: any): any;
115
+ aiGroupKey(session: any): string;
116
+ /**
117
+ * 统一的三态开关解析:单个群设置优先,未设置时跟随全局。
118
+ *
119
+ * 规则(这是本插件的核心约定):
120
+ * 1) 单个群**显式设置**了该值 → 无条件以它为准,**不受全局开关影响**
121
+ * (所以全局关着,某个群单独打开也能生效)
122
+ * 2) 单个群**未设置**(undefined)→ 跟随全局
123
+ *
124
+ * 注意:用 `!== undefined` 判断,这样 `false` 也算"已设置",
125
+ * 不会被 `??` 或 `||` 误判为"未设置"。
126
+ */
127
+ resolveSwitch(rule: any, ruleKey: any, globalKey: any): any;
128
+ extractAiMessageText(session: any): any;
129
+ /**
130
+ * 解析本群黑名单文件路径。
131
+ * 文件名由模板推导:banMember.md -> banMember_<群号>.md
132
+ * 这样每个群一份独立文件,可在 Explorer 中分别查看/编辑。
133
+ */
134
+ getBlacklistFilePath(session: any): any;
135
+ readBlacklistFile(session: any): Promise<any>;
136
+ writeBlacklistFile(session: any, content: any): Promise<void>;
137
+ /** 解析 banMember.md -> [{qq, name, at}],按 QQ 去重 */
138
+ parseBlacklist(content: any): any[];
139
+ /** 序列化(保持人类可读,便于在 Explorer 里直接改) */
140
+ serializeBlacklist(entries: any, groupId: any): string;
141
+ getBlacklist(session: any): Promise<any[]>;
142
+ isBlacklisted(session: any, qq: any): Promise<boolean>;
143
+ /** 加入本群黑名单。返回 { ok, message } */
144
+ addToBlacklist(session: any, qq: any, name: any): Promise<{
145
+ ok: boolean;
146
+ message: string;
147
+ }>;
148
+ /** 从本群黑名单移除。返回 { ok, message } */
149
+ removeFromBlacklist(session: any, qq: any): Promise<{
150
+ ok: boolean;
151
+ message: string;
152
+ }>;
153
+ /** 该群是否启用黑名单(单群设置优先,未设置跟随全局) */
154
+ resolveBlacklistEnabled(session: any): any;
155
+ /** 取群成员信息(用于校验"必须是群内人员"并拿到昵称) */
156
+ /**
157
+ * 提取本条消息中 @ 到的目标 QQ 号(@ 可代替 QQ 号作为指令目标)。
158
+ * 支持三种来源:CQ 码 [CQ:at,qq=xxx]、Koishi 的 at 元素、content 里的 <at id="xxx"/>。
159
+ * 排除 @全体成员 与 @机器人自身。
160
+ */
161
+ extractMentionedTargets(session: any): any[];
162
+ fetchGroupMember(session: any, qq: any): Promise<{
163
+ qq: string;
164
+ name: string;
165
+ }>;
166
+ getMemoryFilePath(): any;
167
+ readMemoryFile(): Promise<any>;
168
+ writeMemoryFile(content: any): Promise<void>;
169
+ extractMemoryBlocks(content: any): string[];
170
+ /**
171
+ * 记忆库写互斥:把「读整档 → 改 → 整写」串行化。
172
+ * 并发保存时后一次读到的才是前一次写完的内容,不会互相覆盖丢条目。
173
+ * 记忆属于低频写,一把 promise 队列足够,无需文件锁。
174
+ */
175
+ runMemoryWriteLocked(task: any): Promise<any>;
176
+ saveMemoryToFile(userId: any, content: any): Promise<any>;
177
+ searchMemory(keyword: any, limit?: number): Promise<string[]>;
178
+ /** 按关键词删除记忆条目(含该关键词的整条记忆块)。返回 { ok, removed, message } */
179
+ deleteMemoryByKeyword(keyword: any): Promise<any>;
180
+ getDisplayName(session: any): any;
181
+ splitAiReplyParts(text: any): any;
182
+ waitHumanLikeDelay(minMs?: number, maxMs?: number): Promise<void>;
183
+ extractImageUrls(session: any): any[];
184
+ isImageReference(value: any): boolean;
185
+ extractImageCandidates(session: any, maxCount?: number): any[];
186
+ detectImageMime(buffer: any, fallback?: string): string;
187
+ resolveImageReferenceToDataUrl(ref: any, session: any): Promise<any>;
188
+ fetchImageAsDataUrl(url: any, extraHeaders?: {}): Promise<any>;
189
+ rememberImageDataUrl(url: any, dataUrl: any): void;
190
+ resolveImagesForModel(refs: any, session: any, maxCount: any): Promise<any[]>;
191
+ /**
192
+ * 把 extractImageElements 的结构化条目解析为可直接喂给模型的 data URL。
193
+ * 每个条目会依次尝试:原始 URL -> 本地文件名(走 OneBot get_image)。
194
+ */
195
+ resolveVisualItemsForModel(items: any, session: any, maxCount: any): Promise<any[]>;
196
+ isImageSendableUrl(value: any): boolean;
197
+ decodeHtmlEntities(value: any): string;
198
+ parseHtmlTagParams(tag: any): {};
199
+ extractImageElements(session: any): any[];
200
+ extractImageUrlsFromSession(session: any, maxCount?: number): any[];
201
+ hasAnyImageElement(session: any): any;
202
+ hasStickerContent(session: any): boolean;
203
+ extractMessageImageUrls(session: any, maxCount?: number): any[];
204
+ extractImageFingerprintKeys(session: any, maxCount?: number): any[];
205
+ normalizeRepeatText(text: any): any;
206
+ buildRepeatPayload(session: any): {
207
+ signature: string;
208
+ text: any;
209
+ images: any[];
210
+ imageKeys: any[];
211
+ rawImageSegments: any;
212
+ sendRefs: any[];
213
+ };
214
+ parseCqImageParams(chunk: any): {};
215
+ extractImageRefsFromRawMessage(raw: any, maxCount?: number): any[];
216
+ extractImageSegmentsFromRawMessage(raw: any, maxCount?: number): any[];
217
+ extractImageSendRefs(session: any, maxCount?: number): any[];
218
+ fetchMessageImagePayload(session: any, maxCount?: number): Promise<{
219
+ segments: any[];
220
+ refs: any[];
221
+ }>;
222
+ sendImageRef(session: any, ref: any): Promise<boolean>;
223
+ handleRepeater(session: any): Promise<void>;
224
+ logAuth(stage: any, result: any, session: any): void;
225
+ logCommandResult(command: any, result: any, session: any, extra: any): void;
226
+ authorizeCommand(command: any, session: any): Promise<{
227
+ ok: boolean;
228
+ message: string;
229
+ userMessage: string;
230
+ } | {
231
+ ok: boolean;
232
+ message: string;
233
+ userMessage?: undefined;
234
+ }>;
235
+ authorize(session: any): Promise<{
236
+ ok: boolean;
237
+ message: string;
238
+ userMessage: string;
239
+ } | {
240
+ ok: boolean;
241
+ message: string;
242
+ userMessage?: undefined;
243
+ }>;
244
+ canUseAdminCommand(session: any): Promise<{
245
+ ok: boolean;
246
+ message: string;
247
+ }>;
248
+ isBotOwnerInGroup(session: any): Promise<boolean>;
249
+ resolveMemberRole(session: any): Promise<any>;
250
+ normalizeRole(input: any): any;
251
+ parseTargetId(input: any): any;
252
+ randomMinutes(min?: number, max?: number): number;
253
+ parseDurationToken(token: any): {
254
+ raw: string;
255
+ value: number;
256
+ hasUnit: boolean;
257
+ minutes: number;
258
+ };
259
+ looksLikeMemberInGroup(session: any, targetIdRaw: any): Promise<boolean>;
260
+ isPrivilegedUser(session: any, role: any): boolean;
261
+ recordUnauthorizedMuteAttempt(session: any): boolean;
262
+ isRegularMember(session: any): Promise<boolean>;
263
+ shouldSelfGag(session: any, target: any): Promise<boolean>;
264
+ selfGag(session: any, reason: any): Promise<{
265
+ ok: boolean;
266
+ message: string;
267
+ plan?: undefined;
268
+ } | {
269
+ ok: boolean;
270
+ message: string;
271
+ plan: {
272
+ action: string;
273
+ groupId: string;
274
+ targetId: any;
275
+ reason: string;
276
+ };
277
+ }>;
278
+ punishUnauthorizedMuteAttempt(session: any, target: any): Promise<{
279
+ ok: boolean;
280
+ message: string;
281
+ plan: {
282
+ action: string;
283
+ groupId: string;
284
+ targetId: any;
285
+ reason: string;
286
+ };
287
+ }>;
288
+ toGroupId(session: any): number;
289
+ getOneBotApi(session: any): any;
290
+ /** 供 AI 引擎抽取图片结构 */
291
+ extractImages(session: any): any[];
292
+ /** 供 AI 引擎把图片引用转成 data URL */
293
+ resolveImage(ref: any, session: any): Promise<any>;
294
+ /** AI 回复发送:优先引用触发消息,失败则退化为纯文本 */
295
+ sendReply(session: any, text: any): Promise<void>;
296
+ extractTextForFilter(session: any): any;
297
+ hasTextContent(session: any): boolean;
298
+ hasImageOrFace(session: any): any;
299
+ hasCardMessage(session: any): any;
300
+ hasForwardMessage(session: any): any;
301
+ normalizeGuildId(guildId: any): any;
302
+ resolveModerationPolicy(session: any): {
303
+ bannedWords: any;
304
+ strongKeywords: any;
305
+ whitelistKeywords: any;
306
+ whitelistOnlyOwners: boolean;
307
+ blockCardMessage: any;
308
+ blockForwardMessage: any;
309
+ autoDeleteViolation: any;
310
+ sendViolationNotice: any;
311
+ enableAutoMute: any;
312
+ autoMuteThreshold: any;
313
+ autoMuteMinutes: any;
314
+ enableAutoKick: any;
315
+ autoKickThreshold: any;
316
+ violationWindowMinutes: any;
111
317
  };
112
- private logImageDebug;
113
- private isPrivilegedUser;
114
- private recordUnauthorizedMuteAttempt;
115
- private isRegularMember;
116
- shouldSelfGag(session?: Session, target?: string): Promise<boolean>;
117
- selfGag(session: Session, reason?: string): Promise<ActionResult>;
118
- punishUnauthorizedMuteAttempt(session?: Session, target?: string): Promise<ActionResult | null>;
119
- private toGroupId;
120
- private getOneBotApi;
121
- private extractTextForFilter;
122
- private hasTextContent;
123
- private hasImageOrFace;
124
- private hasCardMessage;
125
- private hasForwardMessage;
126
- private normalizeGuildId;
127
- private resolveModerationPolicy;
128
- private detectViolation;
129
- private deleteMessage;
130
- private shouldExemptViolationPunish;
131
- private recordViolation;
132
- private clearViolationRecord;
133
- private autoModerationPunish;
134
- private handleGroupModeration;
135
- private getPendingJoinFilePath;
136
- private buildPendingJoinFileContent;
318
+ normalizeBannedWordEntry(entry: any): {
319
+ keyword: string;
320
+ score: any;
321
+ };
322
+ normalizeBannedWordList(list: any): {
323
+ keyword: string;
324
+ score: any;
325
+ }[];
326
+ /**
327
+ * 顺序子序列匹配:关键词的字符按顺序出现在文本中即命中,允许中间隔词。
328
+ * 返回匹配跨度与紧凑度(跨度越接近词长,置信度越高)。
329
+ */
330
+ /**
331
+ * 模糊命中的最低置信度门槛。
332
+ * 短关键词(2~4 字)极易被无关文本凑齐(如「领导说…红色包装袋」凑出「领红包」),
333
+ * 因此对短词要求更高的置信度;长词本身信息量足,门槛可放宽。
334
+ */
335
+ minBannedWordConfidence(keywordLength: any): 1 | 0.6 | 0.65 | 0.55 | 0.45;
336
+ subsequenceMatch(text: any, keyword: any): {
337
+ start: any;
338
+ end: any;
339
+ span: any;
340
+ ratio: number;
341
+ exact: boolean;
342
+ overflow?: undefined;
343
+ confidence?: undefined;
344
+ } | {
345
+ start: number;
346
+ end: number;
347
+ span: number;
348
+ overflow: number;
349
+ ratio: number;
350
+ confidence: number;
351
+ exact: boolean;
352
+ };
353
+ evaluateBannedWords(text: any, policy: any): {
354
+ total: number;
355
+ evaluations: {
356
+ keyword: string;
357
+ score: any;
358
+ confidence: number;
359
+ gained: number;
360
+ span: any;
361
+ exact: boolean;
362
+ }[];
363
+ };
364
+ /**
365
+ * 违禁词白名单豁免检查。
366
+ *
367
+ * 用于「校学生会招新」这类特殊场景:招新文案本身会包含“加群”“群号”等
368
+ * 违禁词,但只要命中白名单关键词(如“宣传部”“纪检部”),就整条跳过违禁词评分。
369
+ *
370
+ * 返回 { keyword, reason } 表示命中并豁免;返回 null 表示未命中。
371
+ */
372
+ checkWhitelistBypass(session: any, policy: any, text: any): Promise<{
373
+ keyword: any;
374
+ reason: string;
375
+ }>;
376
+ detectViolation(session: any, policy: any, type?: string): Promise<{
377
+ type: string;
378
+ detail: string;
379
+ assessment?: undefined;
380
+ strong?: undefined;
381
+ } | {
382
+ type: string;
383
+ detail: string;
384
+ assessment: {
385
+ total: number;
386
+ evaluations: {
387
+ keyword: string;
388
+ score: any;
389
+ confidence: number;
390
+ gained: number;
391
+ span: any;
392
+ exact: boolean;
393
+ }[];
394
+ };
395
+ strong: boolean;
396
+ } | {
397
+ type: string;
398
+ detail: string;
399
+ assessment: {
400
+ total: number;
401
+ evaluations: {
402
+ keyword: string;
403
+ score: any;
404
+ confidence: number;
405
+ gained: number;
406
+ span: any;
407
+ exact: boolean;
408
+ }[];
409
+ };
410
+ strong?: undefined;
411
+ }>;
412
+ deleteMessage(session: any): Promise<boolean>;
413
+ shouldExemptViolationPunish(session: any): Promise<boolean>;
414
+ recordViolation(session: any, policy: any): number;
415
+ clearViolationRecord(session: any): void;
416
+ autoModerationPunish(session: any, policy: any): Promise<{
417
+ ok: boolean;
418
+ action: string;
419
+ count: number;
420
+ message: string;
421
+ minutes?: undefined;
422
+ } | {
423
+ ok: boolean;
424
+ action: string;
425
+ count: number;
426
+ minutes: number;
427
+ message: string;
428
+ }>;
429
+ /**
430
+ * 自定义命令处理器:整条消息与触发词完全一致(忽略首尾空白)即回复预设内容。
431
+ * 触发词约定用方括号包裹(如 [签到])。命中后返回 true,调用方据此跳过后续
432
+ * 违禁词管控与 AI 回复(自定义命令完全不走 AI)。
433
+ */
434
+ handleCustomCommand(session: any): Promise<boolean>;
435
+ _customCmdAt: Map<any, any>;
436
+ _customCmdIdx: Map<any, any>;
437
+ /**
438
+ * 读取指令前缀配置(带默认值)。
439
+ */
440
+ cmdPrefix(key: any, def: any): any;
441
+ /**
442
+ * 统一指令路由器:所有指令均为「方括号直连」语法,如 [mute] 12345 10 广告。
443
+ * 命中并处理返回 true(不再走后续管控与 AI)。
444
+ */
445
+ routeBracketCommand(session: any): Promise<boolean>;
446
+ /**
447
+ * 指令菜单:行首用中文介绍功能名称,指令本身保持英文([记忆] 新规)。
448
+ * 记忆查询紧跟在记忆保存之后;冒号后留一个空行,避免标题与条目挤在一起。
449
+ */
450
+ sendCommandMenu(session: any): Promise<void>;
451
+ /** 自定义指令集:列出当前生效的自定义命令;没有配置时明确提示暂无指令 */
452
+ sendCustomCommandList(session: any): Promise<void>;
453
+ /**
454
+ * [Version]:查看插件信息(当前版本、作者、仓库与 npm 地址)。
455
+ * 版本号与仓库地址从 package.json 读取,避免发版时忘记同步。
456
+ */
457
+ sendVersionInfo(session: any): Promise<void>;
458
+ /** 权限不足提示 */
459
+ denyAdmin(session: any, message: any): Promise<boolean>;
460
+ /**
461
+ * 群管指令的统一鉴权(两步):
462
+ * ① authorizeCommand —— 判定「谁在操作」:账号白名单 / 群主 / 群管理员;
463
+ * ② canUseAdminCommand —— 确认「bot 在该群是否具备管理能力」。
464
+ *
465
+ * 此前方括号指令只做了第②步,导致 allowedUserIds / allowGroupOwner /
466
+ * allowGroupAdmin 对 mute/unmute/kick/ban/unban 完全失效:配置里允许群主操作,
467
+ * 但只要 bot 不是群主就会被拒;反过来当 bot 是群主时,任何群成员都能踢人。
468
+ */
469
+ authorizeModerationAction(command: any, session: any): Promise<{
470
+ ok: boolean;
471
+ message: any;
472
+ }>;
473
+ /** [mute] qq号|@某人 时长 [原因] */
474
+ execMute(session: any, rest: any, mentions?: any[]): Promise<boolean>;
475
+ /** [unmute] qq号|@某人 [原因] */
476
+ execUnmute(session: any, rest: any, mentions?: any[]): Promise<boolean>;
477
+ /** [kick] qq号|@某人 [原因] */
478
+ execKick(session: any, rest: any, mentions?: any[]): Promise<boolean>;
479
+ /** [memory] content / [memory] list / [memory] search keyword / [memory] delete keyword */
480
+ execMemory(session: any, rest: any): Promise<boolean>;
481
+ /** [ban] qq号|@某人 [原因](兼容旧的 [ban] add qq号) */
482
+ execBanAdd(session: any, rest: any, mentions?: any[]): Promise<boolean>;
483
+ /** [unban] qq号|@某人 [原因] */
484
+ execUnban(session: any, rest: any, mentions?: any[]): Promise<boolean>;
485
+ /** [banlist] */
486
+ execBanList(session: any): Promise<void>;
487
+ /**
488
+ * 黑名单指令(旧式 [ban] list / add / delete 兼容入口)。
489
+ */
490
+ handleBanCommand(session: any): Promise<boolean>;
491
+ handleGroupModeration(session: any): Promise<void>;
492
+ /**
493
+ * 待审入群申请的落盘文件路径。
494
+ * 与 Memory.md 同目录(ctx.baseDir),可用 Koishi 控制台「探索器 Explorer」直接查看。
495
+ */
496
+ getPendingJoinFilePath(): any;
497
+ buildPendingJoinFileContent(): string;
498
+ /** 立即把待审单写入 MD(供 dispose / 去抖到期调用) */
137
499
  persistPendingJoinRequestsNow(): Promise<void>;
138
- private schedulePendingJoinPersist;
500
+ /** 去抖落盘:入群申请是低频事件,合并多次写入避免频繁 I/O */
501
+ schedulePendingJoinPersist(delayMs?: number): void;
502
+ /** 卸载/重启前的同步兜底:写失败只记日志,不阻塞退出 */
139
503
  flushPendingJoinRequests(): void;
504
+ /**
505
+ * 启动时从 MD 恢复待审单,并顺手清掉已过期的编号。
506
+ * 这样重启不再丢审核单;超过 TTL 的自然失效。
507
+ */
140
508
  loadPendingJoinRequests(): void;
141
- private cleanupPendingJoinRequests;
142
- private generateJoinRequestCode;
143
- private parseJoinRequestReviewText;
144
- private handleJoinRequestReviewMessage;
145
- private resolveJoinReviewEnabled;
146
- private fetchStrangerInfo;
147
- private buildJoinRequestPrompt;
148
- private handleGuildMemberRequest;
149
- reviewJoinRequestDecision(session: Session, code: string, approve: boolean, reason?: string): Promise<ActionResult>;
150
- formatTargetDisplay(session: Session | undefined, targetId?: string, rawTarget?: string): Promise<string>;
151
- private getTargetRole;
152
- private createDryRunResult;
153
- planDemoAction(groupId: string, reason?: string): Promise<ActionResult>;
154
- kick(session: Session, target: string, rejectAddRequest?: boolean, reason?: string): Promise<ActionResult>;
155
- mute(session: Session, target: string, minutes: number, reason?: string): Promise<ActionResult>;
156
- unmute(session: Session, target: string, reason?: string): Promise<ActionResult>;
157
- setAdmin(session: Session, target: string, enable: boolean, reason?: string): Promise<ActionResult>;
509
+ cleanupPendingJoinRequests(): void;
510
+ generateJoinRequestCode(): string;
511
+ parseJoinRequestReviewText(text: any): {
512
+ approve: boolean;
513
+ code: string;
514
+ reason: string;
515
+ };
516
+ handleJoinRequestReviewMessage(session: any): Promise<boolean>;
517
+ resolveJoinReviewEnabled(session: any): any;
518
+ fetchStrangerInfo(bot: any, userId: any): Promise<any>;
519
+ buildJoinRequestPrompt(applicant: any, extra: any): string;
520
+ handleGuildMemberRequest(session: any): Promise<void>;
521
+ reviewJoinRequestDecision(session: any, code: any, approve: any, reason: any): Promise<{
522
+ ok: boolean;
523
+ message: string;
524
+ plan: any;
525
+ } | {
526
+ ok: boolean;
527
+ message: string;
528
+ }>;
529
+ formatTargetDisplay(session: any, targetId: any, rawTarget: any): Promise<any>;
530
+ getTargetRole(session: any, targetId: any): Promise<any>;
531
+ createDryRunResult(plan: any): {
532
+ ok: boolean;
533
+ message: string;
534
+ plan: any;
535
+ };
536
+ planDemoAction(groupId: any, reason: any): Promise<{
537
+ ok: boolean;
538
+ message: string;
539
+ plan: {
540
+ action: string;
541
+ groupId: any;
542
+ reason: any;
543
+ };
544
+ }>;
545
+ kick(session: any, target: any, rejectAddRequest: boolean, reason: any): Promise<{
546
+ ok: boolean;
547
+ message: string;
548
+ plan: any;
549
+ } | {
550
+ ok: boolean;
551
+ message: string;
552
+ }>;
553
+ mute(session: any, target: any, minutes: any, reason: any): Promise<{
554
+ ok: boolean;
555
+ message: string;
556
+ plan: any;
557
+ } | {
558
+ ok: boolean;
559
+ message: string;
560
+ }>;
561
+ unmute(session: any, target: any, reason: any): Promise<{
562
+ ok: boolean;
563
+ message: string;
564
+ plan: any;
565
+ } | {
566
+ ok: boolean;
567
+ message: string;
568
+ }>;
569
+ setAdmin(session: any, target: any, enable: any, reason: any): Promise<{
570
+ ok: boolean;
571
+ message: string;
572
+ plan: any;
573
+ } | {
574
+ ok: boolean;
575
+ message: string;
576
+ }>;
158
577
  }
578
+ import koishi_1 = require("koishi");
579
+ import { AiEngine } from "./ai/engine";