koishi-plugin-group-verification 1.0.21 → 1.0.22
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/index.d.ts +1 -0
- package/lib/index.js +36 -34
- package/package.json +1 -1
- package/src/index.ts +59 -60
package/lib/index.d.ts
CHANGED
|
@@ -100,4 +100,5 @@ export declare function verifyApplication(config: GroupVerificationConfig, messa
|
|
|
100
100
|
matchedCount: number;
|
|
101
101
|
requiredThreshold: string;
|
|
102
102
|
}>;
|
|
103
|
+
export declare function handleFailedVerification(ctx: Context, session: any, config: GroupVerificationConfig, matchedCount?: number, requiredThreshold?: string): Promise<void>;
|
|
103
104
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Config: () => Config,
|
|
24
24
|
apply: () => apply,
|
|
25
|
+
handleFailedVerification: () => handleFailedVerification,
|
|
25
26
|
inject: () => inject,
|
|
26
27
|
mergeReminder: () => mergeReminder,
|
|
27
28
|
name: () => name,
|
|
@@ -287,6 +288,39 @@ async function verifyApplication(config, message, session) {
|
|
|
287
288
|
return { isValid, matchedCount, requiredThreshold };
|
|
288
289
|
}
|
|
289
290
|
__name(verifyApplication, "verifyApplication");
|
|
291
|
+
async function handleFailedVerification(ctx, session, config, matchedCount, requiredThreshold) {
|
|
292
|
+
const guildId = (session.guildId || session.channelId || "").toString().trim();
|
|
293
|
+
const userId = session.userId;
|
|
294
|
+
const username = session.username || "未知用户";
|
|
295
|
+
const message = session.content || "";
|
|
296
|
+
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`);
|
|
297
|
+
if (matchedCount === void 0 || requiredThreshold === void 0) {
|
|
298
|
+
const result = await verifyApplication(config, message, session);
|
|
299
|
+
matchedCount = result.matchedCount;
|
|
300
|
+
requiredThreshold = result.requiredThreshold;
|
|
301
|
+
}
|
|
302
|
+
let groupName = "未知群组";
|
|
303
|
+
try {
|
|
304
|
+
const guild = await session.bot.getGuild(guildId);
|
|
305
|
+
groupName = guild.name || groupName;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
}
|
|
308
|
+
await ctx.database.create("group_verification_pending", {
|
|
309
|
+
groupId: guildId,
|
|
310
|
+
userId,
|
|
311
|
+
userName: username,
|
|
312
|
+
requestMessage: message,
|
|
313
|
+
applyTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
314
|
+
});
|
|
315
|
+
if (!config.reminderEnabled || !config.reminderMessage || config.reminderMessage === "") {
|
|
316
|
+
logger.info(`群 ${guildId} 的提醒消息已被禁用,跳过发送`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
let reminderMsg = config.reminderMessage;
|
|
320
|
+
reminderMsg = reminderMsg.replace(/{user}/g, username).replace(/{id}/g, userId).replace(/{group}/g, guildId).replace(/{gname}/g, groupName).replace(/{question}/g, message).replace(/{answer}/g, matchedCount.toString()).replace(/{threshold}/g, requiredThreshold);
|
|
321
|
+
await ctx.broadcast([guildId], reminderMsg);
|
|
322
|
+
}
|
|
323
|
+
__name(handleFailedVerification, "handleFailedVerification");
|
|
290
324
|
function apply(ctx, config) {
|
|
291
325
|
ctx.model.extend("group_verification_config", {
|
|
292
326
|
id: "unsigned",
|
|
@@ -367,7 +401,7 @@ function apply(ctx, config) {
|
|
|
367
401
|
}
|
|
368
402
|
}
|
|
369
403
|
} else {
|
|
370
|
-
await handleFailedVerification(ctx, session, config2);
|
|
404
|
+
await handleFailedVerification(ctx, session, config2, matchedCount, requiredThreshold);
|
|
371
405
|
}
|
|
372
406
|
});
|
|
373
407
|
ctx.on("guild-member-added", async (session) => {
|
|
@@ -393,39 +427,6 @@ function apply(ctx, config) {
|
|
|
393
427
|
logger.info(`用户 ${userId} 被手动邀请加入群 ${groupId},手动批准统计已更新`);
|
|
394
428
|
}
|
|
395
429
|
});
|
|
396
|
-
async function handleFailedVerification(ctx2, session, config2, matchedCount, requiredThreshold) {
|
|
397
|
-
const guildId = (session.guildId || session.channelId || "").toString().trim();
|
|
398
|
-
const userId = session.userId;
|
|
399
|
-
const username = session.username || "未知用户";
|
|
400
|
-
const message = session.content || "";
|
|
401
|
-
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`);
|
|
402
|
-
if (matchedCount === void 0 || requiredThreshold === void 0) {
|
|
403
|
-
const result = await verifyApplication(config2, message, session);
|
|
404
|
-
matchedCount = result.matchedCount;
|
|
405
|
-
requiredThreshold = result.requiredThreshold;
|
|
406
|
-
}
|
|
407
|
-
let groupName = "未知群组";
|
|
408
|
-
try {
|
|
409
|
-
const guild = await session.bot.getGuild(guildId);
|
|
410
|
-
groupName = guild.name || groupName;
|
|
411
|
-
} catch (error) {
|
|
412
|
-
}
|
|
413
|
-
await ctx2.database.create("group_verification_pending", {
|
|
414
|
-
groupId: guildId,
|
|
415
|
-
userId,
|
|
416
|
-
userName: username,
|
|
417
|
-
requestMessage: message,
|
|
418
|
-
applyTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
419
|
-
});
|
|
420
|
-
if (!config2.reminderEnabled || !config2.reminderMessage || config2.reminderMessage === "") {
|
|
421
|
-
logger.info(`群 ${guildId} 的提醒消息已被禁用,跳过发送`);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
let reminderMsg = config2.reminderMessage;
|
|
425
|
-
reminderMsg = reminderMsg.replace(/{user}/g, username).replace(/{id}/g, userId).replace(/{group}/g, guildId).replace(/{gname}/g, groupName).replace(/{question}/g, message).replace(/{answer}/g, matchedCount.toString()).replace(/{threshold}/g, requiredThreshold);
|
|
426
|
-
await ctx2.broadcast([guildId], reminderMsg);
|
|
427
|
-
}
|
|
428
|
-
__name(handleFailedVerification, "handleFailedVerification");
|
|
429
430
|
async function updateStats(groupId, action) {
|
|
430
431
|
const existingStats = await ctx.database.get("group_verification_stats", { groupId });
|
|
431
432
|
if (existingStats.length > 0) {
|
|
@@ -1155,6 +1156,7 @@ __name(apply, "apply");
|
|
|
1155
1156
|
0 && (module.exports = {
|
|
1156
1157
|
Config,
|
|
1157
1158
|
apply,
|
|
1159
|
+
handleFailedVerification,
|
|
1158
1160
|
inject,
|
|
1159
1161
|
mergeReminder,
|
|
1160
1162
|
name,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -405,6 +405,64 @@ export async function verifyApplication(config: GroupVerificationConfig, message
|
|
|
405
405
|
return { isValid, matchedCount, requiredThreshold }
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
// 处理验证失败的情况并发送提醒消息(可由 tests 调用)
|
|
409
|
+
export async function handleFailedVerification(
|
|
410
|
+
ctx: Context,
|
|
411
|
+
session: any,
|
|
412
|
+
config: GroupVerificationConfig,
|
|
413
|
+
matchedCount?: number,
|
|
414
|
+
requiredThreshold?: string
|
|
415
|
+
) {
|
|
416
|
+
const guildId = (session.guildId || session.channelId || '').toString().trim();
|
|
417
|
+
const userId = session.userId
|
|
418
|
+
const username = session.username || '未知用户'
|
|
419
|
+
const message = session.content || ''
|
|
420
|
+
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`)
|
|
421
|
+
// 如果未传入匹配信息,则重新计算一次(老调用)
|
|
422
|
+
if (matchedCount === undefined || requiredThreshold === undefined) {
|
|
423
|
+
const result = await verifyApplication(config, message, session)
|
|
424
|
+
matchedCount = result.matchedCount
|
|
425
|
+
requiredThreshold = result.requiredThreshold
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// 获取群信息
|
|
429
|
+
let groupName = '未知群组'
|
|
430
|
+
try {
|
|
431
|
+
const guild = await session.bot.getGuild(guildId)
|
|
432
|
+
groupName = guild.name || groupName
|
|
433
|
+
} catch (error) {
|
|
434
|
+
// 无法获取群名称时使用默认值
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// 将申请加入待审核列表
|
|
438
|
+
await ctx.database.create('group_verification_pending', {
|
|
439
|
+
groupId: guildId,
|
|
440
|
+
userId: userId,
|
|
441
|
+
userName: username,
|
|
442
|
+
requestMessage: message,
|
|
443
|
+
applyTime: new Date().toISOString()
|
|
444
|
+
})
|
|
445
|
+
// 如果提醒消息被禁用,直接返回
|
|
446
|
+
if (!config.reminderEnabled || !config.reminderMessage || config.reminderMessage === '') {
|
|
447
|
+
logger.info(`群 ${guildId} 的提醒消息已被禁用,跳过发送`)
|
|
448
|
+
return
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// 替换提醒消息中的变量
|
|
452
|
+
let reminderMsg = config.reminderMessage
|
|
453
|
+
reminderMsg = reminderMsg
|
|
454
|
+
.replace(/{user}/g, username)
|
|
455
|
+
.replace(/{id}/g, userId)
|
|
456
|
+
.replace(/{group}/g, guildId)
|
|
457
|
+
.replace(/{gname}/g, groupName)
|
|
458
|
+
.replace(/{question}/g, message)
|
|
459
|
+
.replace(/{answer}/g, matchedCount!.toString())
|
|
460
|
+
.replace(/{threshold}/g, requiredThreshold!)
|
|
461
|
+
|
|
462
|
+
// 发送提醒消息到群内
|
|
463
|
+
await ctx.broadcast([guildId], reminderMsg)
|
|
464
|
+
}
|
|
465
|
+
|
|
408
466
|
export function apply(ctx: Context, config: Config) {
|
|
409
467
|
// 创建数据库表
|
|
410
468
|
ctx.model.extend('group_verification_config', {
|
|
@@ -511,7 +569,7 @@ export function apply(ctx: Context, config: Config) {
|
|
|
511
569
|
}
|
|
512
570
|
}
|
|
513
571
|
} else {
|
|
514
|
-
await handleFailedVerification(ctx, session, config);
|
|
572
|
+
await handleFailedVerification(ctx, session, config, matchedCount, requiredThreshold);
|
|
515
573
|
}
|
|
516
574
|
});
|
|
517
575
|
|
|
@@ -548,65 +606,6 @@ export function apply(ctx: Context, config: Config) {
|
|
|
548
606
|
}
|
|
549
607
|
})
|
|
550
608
|
|
|
551
|
-
// 处理验证失败的情况
|
|
552
|
-
// 处理验证失败的情况并发送提醒消息
|
|
553
|
-
// matchedCount/requiredThreshold 可选,为空时内部重新计算(兼容旧调用)
|
|
554
|
-
async function handleFailedVerification(
|
|
555
|
-
ctx: Context,
|
|
556
|
-
session: any,
|
|
557
|
-
config: GroupVerificationConfig,
|
|
558
|
-
matchedCount?: number,
|
|
559
|
-
requiredThreshold?: string
|
|
560
|
-
) {
|
|
561
|
-
const guildId = (session.guildId || session.channelId || '').toString().trim();
|
|
562
|
-
const userId = session.userId
|
|
563
|
-
const username = session.username || '未知用户'
|
|
564
|
-
const message = session.content || ''
|
|
565
|
-
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`)
|
|
566
|
-
// 如果未传入匹配信息,则重新计算一次(老调用)
|
|
567
|
-
if (matchedCount === undefined || requiredThreshold === undefined) {
|
|
568
|
-
const result = await verifyApplication(config, message, session)
|
|
569
|
-
matchedCount = result.matchedCount
|
|
570
|
-
requiredThreshold = result.requiredThreshold
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// 获取群信息
|
|
574
|
-
let groupName = '未知群组'
|
|
575
|
-
try {
|
|
576
|
-
const guild = await session.bot.getGuild(guildId)
|
|
577
|
-
groupName = guild.name || groupName
|
|
578
|
-
} catch (error) {
|
|
579
|
-
// 无法获取群名称时使用默认值
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// 将申请加入待审核列表
|
|
583
|
-
await ctx.database.create('group_verification_pending', {
|
|
584
|
-
groupId: guildId,
|
|
585
|
-
userId: userId,
|
|
586
|
-
userName: username,
|
|
587
|
-
requestMessage: message,
|
|
588
|
-
applyTime: new Date().toISOString()
|
|
589
|
-
})
|
|
590
|
-
// 如果提醒消息被禁用,直接返回
|
|
591
|
-
if (!config.reminderEnabled || !config.reminderMessage || config.reminderMessage === '') {
|
|
592
|
-
logger.info(`群 ${guildId} 的提醒消息已被禁用,跳过发送`)
|
|
593
|
-
return
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
// 替换提醒消息中的变量
|
|
597
|
-
let reminderMsg = config.reminderMessage
|
|
598
|
-
reminderMsg = reminderMsg
|
|
599
|
-
.replace(/{user}/g, username)
|
|
600
|
-
.replace(/{id}/g, userId)
|
|
601
|
-
.replace(/{group}/g, guildId)
|
|
602
|
-
.replace(/{gname}/g, groupName)
|
|
603
|
-
.replace(/{question}/g, message)
|
|
604
|
-
.replace(/{answer}/g, matchedCount!.toString())
|
|
605
|
-
.replace(/{threshold}/g, requiredThreshold!)
|
|
606
|
-
|
|
607
|
-
// 发送提醒消息到群内
|
|
608
|
-
await ctx.broadcast([guildId], reminderMsg)
|
|
609
|
-
}
|
|
610
609
|
|
|
611
610
|
|
|
612
611
|
// 更新统计信息
|