koishi-plugin-group-verification 1.0.10 → 1.0.11

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.
Files changed (3) hide show
  1. package/lib/index.js +148 -60
  2. package/package.json +1 -1
  3. package/src/index.ts +201 -86
package/lib/index.js CHANGED
@@ -373,89 +373,149 @@ ${debugInfo}`];
373
373
  return `已为群 ${targetGroupId} 创建验证配置`;
374
374
  }
375
375
  });
376
- groupVerify.subcommand(".approve <userId>", "同意用户加群申请").alias("accept", "同意", "appr", "通过").action(async ({ session }, userId) => {
377
- if (!await checkPermission(session)) {
378
- return "权限不足";
376
+ groupVerify.subcommand(".approve [userId]", "同意加群申请").alias("accept", "同意", "通过", "gva").action(async ({ session }, userId) => {
377
+ const [hasPermission, errorMsg] = await checkPermission(session);
378
+ if (!hasPermission) {
379
+ return errorMsg || "权限不足";
379
380
  }
380
- if (!session.guildId) {
381
+ const groupId = session.guildId;
382
+ if (!groupId) {
381
383
  return "请在群聊中使用此命令";
382
384
  }
383
- if (!userId) {
384
- return "请提供用户ID";
385
+ if (!userId || userId.toLowerCase() === "all") {
386
+ if (userId?.toLowerCase() === "all") {
387
+ const pendingRequests2 = await ctx.database.get("group_verification_pending", { groupId });
388
+ if (pendingRequests2.length === 0) {
389
+ return "当前无待审核的加群申请";
390
+ }
391
+ let approvedCount = 0;
392
+ for (const request2 of pendingRequests2) {
393
+ try {
394
+ await ctx.database.remove("group_verification_pending", { id: request2.id });
395
+ await updateStats(groupId, "manuallyApproved");
396
+ approvedCount++;
397
+ } catch (error) {
398
+ logger.warn(`处理申请 ${request2.id} 时出错:`, error);
399
+ }
400
+ }
401
+ return `已处理 ${approvedCount} 个加群申请`;
402
+ } else {
403
+ const recentRequest = await ctx.database.get("group_verification_pending", { groupId }, ["id", "userId", "userName"]);
404
+ if (recentRequest.length === 0) {
405
+ return "当前无待审核的加群申请";
406
+ }
407
+ const request2 = recentRequest[0];
408
+ try {
409
+ await session.bot.handleGuildMemberRequest(request2.userId, true);
410
+ await ctx.database.remove("group_verification_pending", { id: request2.id });
411
+ await updateStats(groupId, "manuallyApproved");
412
+ return `已同意用户 ${request2.userName}(${request2.userId}) 的加群申请`;
413
+ } catch (error) {
414
+ return `处理申请时出错: ${error.message}`;
415
+ }
416
+ }
385
417
  }
386
- const pendingApplications = await ctx.database.get("group_verification_pending", {
387
- groupId: session.guildId,
418
+ const pendingRequests = await ctx.database.get("group_verification_pending", {
419
+ groupId,
388
420
  userId
389
421
  });
390
- if (pendingApplications.length === 0) {
422
+ if (pendingRequests.length === 0) {
391
423
  return `未找到用户 ${userId} 的待审核申请`;
392
424
  }
393
- const application = pendingApplications[0];
394
- await ctx.database.remove("group_verification_pending", { id: application.id });
395
- await updateStats(session.guildId, "manuallyApproved");
396
- return `已同意用户 ${application.userName}(${userId}) 的加群申请`;
425
+ const request = pendingRequests[0];
426
+ try {
427
+ await session.bot.handleGuildMemberRequest(request.userId, true);
428
+ await ctx.database.remove("group_verification_pending", { id: request.id });
429
+ await updateStats(groupId, "manuallyApproved");
430
+ return `已同意用户 ${request.userName}(${userId}) 的加群申请`;
431
+ } catch (error) {
432
+ return `处理申请时出错: ${error.message}`;
433
+ }
397
434
  });
398
- groupVerify.subcommand(".reject <userId>", "拒绝用户加群申请").alias("拒绝", "rej", "拒绝").action(async ({ session }, userId) => {
399
- if (!await checkPermission(session)) {
400
- return "权限不足";
435
+ groupVerify.subcommand(".reject [userId]", "拒绝加群申请").alias("拒绝", "rej", "gvr").action(async ({ session }, userId) => {
436
+ const [hasPermission, errorMsg] = await checkPermission(session);
437
+ if (!hasPermission) {
438
+ return errorMsg || "权限不足";
401
439
  }
402
- if (!session.guildId) {
440
+ const groupId = session.guildId;
441
+ if (!groupId) {
403
442
  return "请在群聊中使用此命令";
404
443
  }
405
- if (!userId) {
406
- return "请提供用户ID";
444
+ if (!userId || userId.toLowerCase() === "all") {
445
+ if (userId?.toLowerCase() === "all") {
446
+ const pendingRequests2 = await ctx.database.get("group_verification_pending", { groupId });
447
+ if (pendingRequests2.length === 0) {
448
+ return "当前无待审核的加群申请";
449
+ }
450
+ let rejectedCount = 0;
451
+ for (const request2 of pendingRequests2) {
452
+ try {
453
+ await ctx.database.remove("group_verification_pending", { id: request2.id });
454
+ await updateStats(groupId, "rejected");
455
+ rejectedCount++;
456
+ } catch (error) {
457
+ logger.warn(`处理申请 ${request2.id} 时出错:`, error);
458
+ }
459
+ }
460
+ return `已拒绝 ${rejectedCount} 个加群申请`;
461
+ } else {
462
+ const recentRequest = await ctx.database.get("group_verification_pending", { groupId }, ["id", "userId", "userName"]);
463
+ if (recentRequest.length === 0) {
464
+ return "当前无待审核的加群申请";
465
+ }
466
+ const request2 = recentRequest[0];
467
+ try {
468
+ await ctx.database.remove("group_verification_pending", { id: request2.id });
469
+ await updateStats(groupId, "rejected");
470
+ return `已拒绝用户 ${request2.userName}(${request2.userId}) 的加群申请`;
471
+ } catch (error) {
472
+ return `处理申请时出错: ${error.message}`;
473
+ }
474
+ }
407
475
  }
408
- const pendingApplications = await ctx.database.get("group_verification_pending", {
409
- groupId: session.guildId,
476
+ const pendingRequests = await ctx.database.get("group_verification_pending", {
477
+ groupId,
410
478
  userId
411
479
  });
412
- if (pendingApplications.length === 0) {
480
+ if (pendingRequests.length === 0) {
413
481
  return `未找到用户 ${userId} 的待审核申请`;
414
482
  }
415
- const application = pendingApplications[0];
416
- await ctx.database.remove("group_verification_pending", { id: application.id });
417
- await updateStats(session.guildId, "rejected");
418
- return `已拒绝用户 ${application.userName}(${userId}) 的加群申请`;
483
+ const request = pendingRequests[0];
484
+ try {
485
+ await ctx.database.remove("group_verification_pending", { id: request.id });
486
+ await updateStats(groupId, "rejected");
487
+ return `已拒绝用户 ${request.userName}(${userId}) 的加群申请`;
488
+ } catch (error) {
489
+ return `处理申请时出错: ${error.message}`;
490
+ }
419
491
  });
420
- groupVerify.subcommand(".stats [groupId]", "查看群组验证统计信息").alias("统计", "stat", "statistics").option("total", "-t 显示总计统计").action(async ({ session, options }, groupId) => {
421
- const targetGroupId = groupId || session.guildId;
422
- if (!targetGroupId && !options.total) {
423
- return "请在群聊中使用此命令或指定群号,或使用 -t 参数查看总计统计";
424
- }
425
- let statsList = [];
426
- if (options.total) {
427
- const totalStats = await ctx.database.get("group_verification_stats", { groupId: "TOTAL" });
428
- if (totalStats.length > 0) {
429
- statsList.push(totalStats[0]);
430
- }
431
- if (targetGroupId && targetGroupId !== "TOTAL") {
432
- const groupStats = await ctx.database.get("group_verification_stats", { groupId: targetGroupId });
433
- statsList = statsList.concat(groupStats);
492
+ groupVerify.subcommand(".stats [target]", "查看群组验证统计信息").alias("统计", "stat", "statistics").action(async ({ session }, target) => {
493
+ const validTargets = ["all", "total"];
494
+ const isGroupId = target && /^\d+$/.test(target);
495
+ const isSpecialTarget = target && validTargets.includes(target.toLowerCase());
496
+ if (target && !isGroupId && !isSpecialTarget) {
497
+ return "参数错误:只能指定群号、all、total或留空";
498
+ }
499
+ if (target?.toLowerCase() === "total" || target?.toLowerCase() === "all") {
500
+ const koishiAuthority = session.author?.authority || session.user?.authority;
501
+ if (!(koishiAuthority && koishiAuthority >= 3)) {
502
+ return "查看总计统计需要koishi 3级以上权限";
434
503
  }
435
- } else {
436
- const groupStats = await ctx.database.get("group_verification_stats", { groupId: targetGroupId });
437
- statsList = groupStats;
438
504
  }
439
- if (statsList.length === 0) {
440
- if (options.total) {
441
- return "暂无统计信息";
442
- } else {
443
- return `群 ${targetGroupId} 暂无验证统计信息`;
505
+ const groupId = session.guildId;
506
+ if (!target) {
507
+ if (!groupId) {
508
+ return "请在群聊中使用此命令或指定群号";
444
509
  }
510
+ return await getGroupStats(groupId);
445
511
  }
446
- let result = "";
447
- for (const stats of statsList) {
448
- const groupName = stats.groupId === "TOTAL" ? "总计" : `群 ${stats.groupId}`;
449
- const lastUpdated = new Date(stats.lastUpdated).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
450
- result += `${groupName} 验证统计:
451
- 自动批准: ${stats.autoApproved}
452
- 手动批准: ${stats.manuallyApproved}
453
- 拒绝: ${stats.rejected}
454
- 最后更新: ${lastUpdated}
455
-
456
- `;
512
+ if (target.toLowerCase() === "all" || target.toLowerCase() === "total") {
513
+ return await getTotalStats();
514
+ }
515
+ if (isGroupId) {
516
+ return await getGroupStats(target);
457
517
  }
458
- return result.trim();
518
+ return "参数错误";
459
519
  });
460
520
  groupVerify.subcommand(".pending", "查看待审核加群申请").alias("list", "待审", "pend", "待处理").action(async ({ session }) => {
461
521
  if (!session.guildId) {
@@ -532,6 +592,34 @@ ${debugInfo}`];
532
592
  }
533
593
  await syncTotalStats(ctx);
534
594
  });
595
+ async function getGroupStats(groupId) {
596
+ const stats = await ctx.database.get("group_verification_stats", { groupId });
597
+ if (stats.length === 0) {
598
+ return `群 ${groupId} 暂无验证统计信息`;
599
+ }
600
+ const stat = stats[0];
601
+ const lastUpdated = new Date(stat.lastUpdated).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
602
+ return `群 ${groupId} 验证统计:
603
+ 自动批准: ${stat.autoApproved}
604
+ 手动批准: ${stat.manuallyApproved}
605
+ 拒绝: ${stat.rejected}
606
+ 最后更新: ${lastUpdated}`;
607
+ }
608
+ __name(getGroupStats, "getGroupStats");
609
+ async function getTotalStats() {
610
+ const stats = await ctx.database.get("group_verification_stats", { groupId: "TOTAL" });
611
+ if (stats.length === 0) {
612
+ return "暂无统计信息";
613
+ }
614
+ const stat = stats[0];
615
+ const lastUpdated = new Date(stat.lastUpdated).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
616
+ return `总计验证统计:
617
+ 自动批准: ${stat.autoApproved}
618
+ 手动批准: ${stat.manuallyApproved}
619
+ 拒绝: ${stat.rejected}
620
+ 最后更新: ${lastUpdated}`;
621
+ }
622
+ __name(getTotalStats, "getTotalStats");
535
623
  async function syncTotalStats(ctx2) {
536
624
  try {
537
625
  const allStats = await ctx2.database.get("group_verification_stats", {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-verification",
3
3
  "description": "Koishi 群组加群验证插件,支持多关键词匹配审核、多种审核方式和详细统计功能",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/src/index.ts CHANGED
@@ -536,132 +536,211 @@ export function apply(ctx: Context, config: Config) {
536
536
 
537
537
  // Subcommand: approve join request
538
538
  groupVerify
539
- .subcommand('.approve <userId>', '同意用户加群申请')
540
- .alias('accept', '同意', 'appr', '通过')
539
+ .subcommand('.approve [userId]', '同意加群申请')
540
+ .alias('accept', '同意', '通过', 'gva')
541
541
  .action(async ({ session }, userId) => {
542
542
  // 权限检查
543
- if (!(await checkPermission(session))) {
544
- return '权限不足'
543
+ const [hasPermission, errorMsg] = await checkPermission(session)
544
+ if (!hasPermission) {
545
+ return errorMsg || '权限不足'
545
546
  }
546
547
 
547
- if (!session.guildId) {
548
+ const groupId = session.guildId
549
+ if (!groupId) {
548
550
  return '请在群聊中使用此命令'
549
551
  }
550
-
551
- if (!userId) {
552
- return '请提供用户ID'
552
+
553
+ // 处理默认情况和all情况
554
+ if (!userId || userId.toLowerCase() === 'all') {
555
+ if (userId?.toLowerCase() === 'all') {
556
+ // 处理所有待审核申请
557
+ const pendingRequests = await ctx.database.get('group_verification_pending', { groupId })
558
+ if (pendingRequests.length === 0) {
559
+ return '当前无待审核的加群申请'
560
+ }
561
+
562
+ let approvedCount = 0
563
+ for (const request of pendingRequests) {
564
+ try {
565
+ // TODO: 需要获取实际的requestId来进行审批
566
+ // await session.bot.handleGuildMemberRequest(request.requestId, true)
567
+ await ctx.database.remove('group_verification_pending', { id: request.id })
568
+ await updateStats(groupId, 'manuallyApproved')
569
+ approvedCount++
570
+ } catch (error) {
571
+ logger.warn(`处理申请 ${request.id} 时出错:`, error)
572
+ }
573
+ }
574
+
575
+ return `已处理 ${approvedCount} 个加群申请`
576
+ } else {
577
+ // 处理最近的一个申请
578
+ const recentRequest = await ctx.database.get('group_verification_pending', { groupId }, ['id', 'userId', 'userName'])
579
+ if (recentRequest.length === 0) {
580
+ return '当前无待审核的加群申请'
581
+ }
582
+
583
+ const request = recentRequest[0]
584
+ try {
585
+ // 这里需要获取实际的requestId,暂时用userId作为示例
586
+ await session.bot.handleGuildMemberRequest(request.userId, true)
587
+ await ctx.database.remove('group_verification_pending', { id: request.id })
588
+ await updateStats(groupId, 'manuallyApproved')
589
+ return `已同意用户 ${request.userName}(${request.userId}) 的加群申请`
590
+ } catch (error) {
591
+ return `处理申请时出错: ${error.message}`
592
+ }
593
+ }
553
594
  }
554
-
555
- // Find pending applications
556
- const pendingApplications = await ctx.database.get('group_verification_pending', {
557
- groupId: session.guildId,
558
- userId: userId
595
+
596
+ // 处理指定用户ID的情况
597
+ const pendingRequests = await ctx.database.get('group_verification_pending', {
598
+ groupId,
599
+ userId: userId
559
600
  })
560
-
561
- if (pendingApplications.length === 0) {
601
+
602
+ if (pendingRequests.length === 0) {
562
603
  return `未找到用户 ${userId} 的待审核申请`
563
604
  }
564
-
565
- const application = pendingApplications[0]
566
-
567
- // Remove pending record
568
- await ctx.database.remove('group_verification_pending', { id: application.id })
569
- await updateStats(session.guildId, 'manuallyApproved')
570
-
571
- return `已同意用户 ${application.userName}(${userId}) 的加群申请`
605
+
606
+ const request = pendingRequests[0]
607
+ try {
608
+ // 这里需要获取实际的requestId来进行审批
609
+ await session.bot.handleGuildMemberRequest(request.userId, true)
610
+ await ctx.database.remove('group_verification_pending', { id: request.id })
611
+ await updateStats(groupId, 'manuallyApproved')
612
+ return `已同意用户 ${request.userName}(${userId}) 的加群申请`
613
+ } catch (error) {
614
+ return `处理申请时出错: ${error.message}`
615
+ }
572
616
  })
573
617
 
574
618
  // Subcommand: reject join request
575
619
  groupVerify
576
- .subcommand('.reject <userId>', '拒绝用户加群申请')
577
- .alias('拒绝', 'rej', '拒绝')
620
+ .subcommand('.reject [userId]', '拒绝加群申请')
621
+ .alias('拒绝', 'rej', 'gvr')
578
622
  .action(async ({ session }, userId) => {
579
623
  // 权限检查
580
- if (!(await checkPermission(session))) {
581
- return '权限不足'
624
+ const [hasPermission, errorMsg] = await checkPermission(session)
625
+ if (!hasPermission) {
626
+ return errorMsg || '权限不足'
582
627
  }
583
628
 
584
- if (!session.guildId) {
629
+ const groupId = session.guildId
630
+ if (!groupId) {
585
631
  return '请在群聊中使用此命令'
586
632
  }
587
-
588
- if (!userId) {
589
- return '请提供用户ID'
633
+
634
+ // 处理默认情况和all情况
635
+ if (!userId || userId.toLowerCase() === 'all') {
636
+ if (userId?.toLowerCase() === 'all') {
637
+ // 拒绝所有待审核申请
638
+ const pendingRequests = await ctx.database.get('group_verification_pending', { groupId })
639
+ if (pendingRequests.length === 0) {
640
+ return '当前无待审核的加群申请'
641
+ }
642
+
643
+ let rejectedCount = 0
644
+ for (const request of pendingRequests) {
645
+ try {
646
+ // TODO: 需要获取实际的requestId来进行拒绝
647
+ // await session.bot.handleGuildMemberRequest(request.requestId, false)
648
+ await ctx.database.remove('group_verification_pending', { id: request.id })
649
+ await updateStats(groupId, 'rejected')
650
+ rejectedCount++
651
+ } catch (error) {
652
+ logger.warn(`处理申请 ${request.id} 时出错:`, error)
653
+ }
654
+ }
655
+
656
+ return `已拒绝 ${rejectedCount} 个加群申请`
657
+ } else {
658
+ // 拒绝最近的一个申请
659
+ const recentRequest = await ctx.database.get('group_verification_pending', { groupId }, ['id', 'userId', 'userName'])
660
+ if (recentRequest.length === 0) {
661
+ return '当前无待审核的加群申请'
662
+ }
663
+
664
+ const request = recentRequest[0]
665
+ try {
666
+ // TODO: 需要获取实际的requestId来进行拒绝
667
+ // await session.bot.handleGuildMemberRequest(request.requestId, false)
668
+ await ctx.database.remove('group_verification_pending', { id: request.id })
669
+ await updateStats(groupId, 'rejected')
670
+ return `已拒绝用户 ${request.userName}(${request.userId}) 的加群申请`
671
+ } catch (error) {
672
+ return `处理申请时出错: ${error.message}`
673
+ }
674
+ }
590
675
  }
591
-
592
- // Find pending applications
593
- const pendingApplications = await ctx.database.get('group_verification_pending', {
594
- groupId: session.guildId,
595
- userId: userId
676
+
677
+ // 处理指定用户ID的情况
678
+ const pendingRequests = await ctx.database.get('group_verification_pending', {
679
+ groupId,
680
+ userId: userId
596
681
  })
597
-
598
- if (pendingApplications.length === 0) {
682
+
683
+ if (pendingRequests.length === 0) {
599
684
  return `未找到用户 ${userId} 的待审核申请`
600
685
  }
601
-
602
- const application = pendingApplications[0]
603
-
604
- // Remove pending record
605
- await ctx.database.remove('group_verification_pending', { id: application.id })
606
- await updateStats(session.guildId, 'rejected')
607
-
608
- return `已拒绝用户 ${application.userName}(${userId}) 的加群申请`
686
+
687
+ const request = pendingRequests[0]
688
+ try {
689
+ // TODO: 需要获取实际的requestId来进行拒绝
690
+ // await session.bot.handleGuildMemberRequest(request.requestId, false)
691
+ await ctx.database.remove('group_verification_pending', { id: request.id })
692
+ await updateStats(groupId, 'rejected')
693
+ return `已拒绝用户 ${request.userName}(${userId}) 的加群申请`
694
+ } catch (error) {
695
+ return `处理申请时出错: ${error.message}`
696
+ }
609
697
  })
610
698
 
611
699
  // Subcommand: view statistics
612
700
  groupVerify
613
- .subcommand('.stats [groupId]', '查看群组验证统计信息')
701
+ .subcommand('.stats [target]', '查看群组验证统计信息')
614
702
  .alias('统计', 'stat', 'statistics')
615
- .option('total', '-t 显示总计统计')
616
- .action(async ({ session, options }, groupId) => {
617
- // 权限检查(统计命令相对宽松,任意用户可查看)
618
- const targetGroupId = groupId || session.guildId
703
+ .action(async ({ session }, target) => {
704
+ // 参数验证:只能是群号、all、total或空
705
+ const validTargets = ['all', 'total']
706
+ const isGroupId = target && /^\d+$/.test(target)
707
+ const isSpecialTarget = target && validTargets.includes(target.toLowerCase())
708
+
709
+ if (target && !isGroupId && !isSpecialTarget) {
710
+ return '参数错误:只能指定群号、all、total或留空'
711
+ }
619
712
 
620
- if (!targetGroupId && !options.total) {
621
- return '请在群聊中使用此命令或指定群号,或使用 -t 参数查看总计统计'
713
+ // 权限检查:总计统计需要3级以上权限
714
+ if (target?.toLowerCase() === 'total' || target?.toLowerCase() === 'all') {
715
+ // 检查是否为koishi 3级以上权限
716
+ const koishiAuthority = (session as any).author?.authority || (session as any).user?.authority
717
+ if (!(koishiAuthority && koishiAuthority >= 3)) {
718
+ return '查看总计统计需要koishi 3级以上权限'
719
+ }
622
720
  }
623
721
 
624
- let statsList: GroupVerificationStats[] = []
722
+ const groupId = session.guildId
625
723
 
626
- if (options.total) {
627
- // 显示总计统计
628
- const totalStats = await ctx.database.get('group_verification_stats', { groupId: 'TOTAL' })
629
- if (totalStats.length > 0) {
630
- statsList.push(totalStats[0])
631
- }
632
-
633
- // 如果同时指定了具体群号,也显示该群统计
634
- if (targetGroupId && targetGroupId !== 'TOTAL') {
635
- const groupStats = await ctx.database.get('group_verification_stats', { groupId: targetGroupId })
636
- statsList = statsList.concat(groupStats)
724
+ // 处理不同参数情况
725
+ if (!target) {
726
+ // 无参数:显示当前群统计
727
+ if (!groupId) {
728
+ return '请在群聊中使用此命令或指定群号'
637
729
  }
638
- } else {
639
- // 显示指定群统计
640
- const groupStats = await ctx.database.get('group_verification_stats', { groupId: targetGroupId })
641
- statsList = groupStats
730
+ return await getGroupStats(groupId)
642
731
  }
643
732
 
644
- if (statsList.length === 0) {
645
- if (options.total) {
646
- return '暂无统计信息'
647
- } else {
648
- return `群 ${targetGroupId} 暂无验证统计信息`
649
- }
733
+ if (target.toLowerCase() === 'all' || target.toLowerCase() === 'total') {
734
+ // 显示总计统计
735
+ return await getTotalStats()
650
736
  }
651
737
 
652
- let result = ''
653
- for (const stats of statsList) {
654
- const groupName = stats.groupId === 'TOTAL' ? '总计' : `群 ${stats.groupId}`
655
- const lastUpdated = new Date(stats.lastUpdated).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })
656
-
657
- result += `${groupName} 验证统计:
658
- 自动批准: ${stats.autoApproved}
659
- 手动批准: ${stats.manuallyApproved}
660
- 拒绝: ${stats.rejected}
661
- 最后更新: ${lastUpdated}\n\n`
738
+ if (isGroupId) {
739
+ // 显示指定群统计
740
+ return await getGroupStats(target)
662
741
  }
663
742
 
664
- return result.trim()
743
+ return '参数错误'
665
744
  })
666
745
 
667
746
  // Subcommand: view pending requests
@@ -760,6 +839,42 @@ export function apply(ctx: Context, config: Config) {
760
839
  await syncTotalStats(ctx)
761
840
  })
762
841
 
842
+ // 辅助函数:获取群组统计
843
+ async function getGroupStats(groupId: string): Promise<string> {
844
+ const stats = await ctx.database.get('group_verification_stats', { groupId })
845
+
846
+ if (stats.length === 0) {
847
+ return `群 ${groupId} 暂无验证统计信息`
848
+ }
849
+
850
+ const stat = stats[0]
851
+ const lastUpdated = new Date(stat.lastUpdated).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })
852
+
853
+ return `群 ${groupId} 验证统计:
854
+ 自动批准: ${stat.autoApproved}
855
+ 手动批准: ${stat.manuallyApproved}
856
+ 拒绝: ${stat.rejected}
857
+ 最后更新: ${lastUpdated}`
858
+ }
859
+
860
+ // 辅助函数:获取总计统计
861
+ async function getTotalStats(): Promise<string> {
862
+ const stats = await ctx.database.get('group_verification_stats', { groupId: 'TOTAL' })
863
+
864
+ if (stats.length === 0) {
865
+ return '暂无统计信息'
866
+ }
867
+
868
+ const stat = stats[0]
869
+ const lastUpdated = new Date(stat.lastUpdated).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })
870
+
871
+ return `总计验证统计:
872
+ 自动批准: ${stat.autoApproved}
873
+ 手动批准: ${stat.manuallyApproved}
874
+ 拒绝: ${stat.rejected}
875
+ 最后更新: ${lastUpdated}`
876
+ }
877
+
763
878
  // 同步统计数据到总计行的函数
764
879
  async function syncTotalStats(ctx: Context) {
765
880
  try {