koishi-plugin-group-verification 1.0.31 → 1.0.32

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 +12 -2
  2. package/package.json +50 -51
  3. package/src/index.ts +15 -2
package/lib/index.js CHANGED
@@ -348,7 +348,7 @@ async function checkPermission(session, targetGroupId) {
348
348
  });
349
349
  }
350
350
  if (koishiAuthority && koishiAuthority >= 3) {
351
- logger.info(`权限检查 - 通过koishi权限检查: ${koishiAuthority}`);
351
+ logger.debug(`权限检查 - 通过koishi权限检查: ${koishiAuthority}`);
352
352
  return [true];
353
353
  }
354
354
  try {
@@ -661,7 +661,9 @@ async function processBlacklistCommand(ctx, session, rawArgs, config) {
661
661
  targetUser = parts[1];
662
662
  if (!targetUser) return "请提供用户ID";
663
663
  const rest = parts.slice(2);
664
- if (rest.length > 0) {
664
+ if (rest.length === 1) {
665
+ reason = rest[0];
666
+ } else if (rest.length > 1) {
665
667
  const last = rest[rest.length - 1];
666
668
  if (/^\d+$/.test(last) || last.toLowerCase() === "all") {
667
669
  group = last;
@@ -700,6 +702,14 @@ async function processBlacklistCommand(ctx, session, rawArgs, config) {
700
702
  entries[targetUser] = storedReason;
701
703
  await ctx.database.create("group_verification_blacklist", { groupId: group, entries });
702
704
  }
705
+ if (session.bot && typeof session.bot.kickGuildMember === "function") {
706
+ try {
707
+ await session.bot.kickGuildMember(group, targetUser);
708
+ logger.info(`已将黑名单用户 ${targetUser} 从群 ${group} 踢出`);
709
+ } catch (e) {
710
+ logger.warn(`踢出用户 ${targetUser} 失败`, e);
711
+ }
712
+ }
703
713
  const tmpl = config && config.blacklistAddSuccess || "已将用户 {user} 加入群 {group} 黑名单{reason}";
704
714
  return tmpl.replace("{user}", targetUser).replace("{group}", group).replace("{reason}", reason ? `,原因:${reason}` : "");
705
715
  }
package/package.json CHANGED
@@ -1,51 +1,50 @@
1
- {
2
- "name": "koishi-plugin-group-verification",
3
- "description": "Koishi 群组加群验证插件,支持多关键词匹配审核、多种审核方式和详细统计功能",
4
-
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/LHDyx/koishi-plugin-group-verification.git"
8
- },
9
- "bugs": {
10
- "url": "https://github.com/LHDyx/koishi-plugin-group-verification/issues"
11
- },
12
- "version": "1.0.31",
13
- "main": "lib/index.js",
14
- "typings": "lib/index.d.ts",
15
- "files": [
16
- "lib",
17
- "dist",
18
- "src",
19
- "README.md",
20
- "USAGE_EXAMPLE.md"
21
- ],
22
- "scripts": {
23
- "build": "tsc",
24
- "dev": "tsc -w",
25
- "test": "ts-node test/basic-test.ts"
26
- },
27
- "license": "MIT",
28
- "keywords": [
29
- "chatbot",
30
- "koishi",
31
- "plugin",
32
- "group-verification",
33
- "guild-management",
34
- "join-request",
35
- "moderation"
36
- ],
37
- "koishi": {
38
- "service": {
39
- "required": [
40
- "database"
41
- ]
42
- }
43
- },
44
- "peerDependencies": {
45
- "koishi": "^4.15.0"
46
- },
47
- "devDependencies": {
48
- "typescript": "^4.9.0",
49
- "@types/node": "^16.0.0"
50
- }
51
- }
1
+ {
2
+ "name": "koishi-plugin-group-verification",
3
+ "description": "Koishi 群组加群验证插件,支持多关键词匹配审核、多种审核方式和详细统计功能",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/LHDyx/koishi-plugin-group-verification.git"
7
+ },
8
+ "bugs": {
9
+ "url": "https://github.com/LHDyx/koishi-plugin-group-verification/issues"
10
+ },
11
+ "version": "1.0.32",
12
+ "main": "lib/index.js",
13
+ "typings": "lib/index.d.ts",
14
+ "files": [
15
+ "lib",
16
+ "dist",
17
+ "src",
18
+ "README.md",
19
+ "USAGE_EXAMPLE.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "dev": "tsc -w",
24
+ "test": "ts-node test/basic-test.ts"
25
+ },
26
+ "license": "MIT",
27
+ "keywords": [
28
+ "chatbot",
29
+ "koishi",
30
+ "plugin",
31
+ "group-verification",
32
+ "guild-management",
33
+ "join-request",
34
+ "moderation"
35
+ ],
36
+ "koishi": {
37
+ "service": {
38
+ "required": [
39
+ "database"
40
+ ]
41
+ }
42
+ },
43
+ "peerDependencies": {
44
+ "koishi": "^4.15.0"
45
+ },
46
+ "devDependencies": {
47
+ "typescript": "^4.9.0",
48
+ "@types/node": "^16.0.0"
49
+ }
50
+ }
package/src/index.ts CHANGED
@@ -498,7 +498,7 @@ export async function checkPermission(session: any, targetGroupId?: string): Pro
498
498
  }
499
499
 
500
500
  if (koishiAuthority && koishiAuthority >= 3) {
501
- logger.info(`权限检查 - 通过koishi权限检查: ${koishiAuthority}`)
501
+ logger.debug(`权限检查 - 通过koishi权限检查: ${koishiAuthority}`)
502
502
  return [true]
503
503
  }
504
504
 
@@ -886,13 +886,17 @@ export async function processBlacklistCommand(ctx: Context, session: any, rawArg
886
886
  targetUser = parts[1]
887
887
  if (!targetUser) return '请提供用户ID'
888
888
  // handle optional reason and group at end
889
+ // 规则:如果只有一个附加参数,则作为 reason;两个及以上时最后一个为群号,其余拼成 reason
889
890
  const rest = parts.slice(2)
890
- if (rest.length > 0) {
891
+ if (rest.length === 1) {
892
+ reason = rest[0]
893
+ } else if (rest.length > 1) {
891
894
  const last = rest[rest.length - 1]
892
895
  if (/^\d+$/.test(last) || last.toLowerCase() === 'all') {
893
896
  group = last
894
897
  reason = rest.slice(0, -1).join(' ')
895
898
  } else {
899
+ // 虽然数量>=2,但最后一个不是数字,全部作为reason
896
900
  reason = rest.join(' ')
897
901
  }
898
902
  }
@@ -930,6 +934,15 @@ export async function processBlacklistCommand(ctx: Context, session: any, rawArg
930
934
  entries[targetUser] = storedReason
931
935
  await ctx.database.create('group_verification_blacklist', { groupId: group, entries })
932
936
  }
937
+ // 添加成功后尝试踢人
938
+ if (session.bot && typeof session.bot.kickGuildMember === 'function') {
939
+ try {
940
+ await session.bot.kickGuildMember(group, targetUser)
941
+ logger.info(`已将黑名单用户 ${targetUser} 从群 ${group} 踢出`)
942
+ } catch (e) {
943
+ logger.warn(`踢出用户 ${targetUser} 失败`, e)
944
+ }
945
+ }
933
946
  const tmpl = (config && config.blacklistAddSuccess) || '已将用户 {user} 加入群 {group} 黑名单{reason}'
934
947
  return tmpl.replace('{user}', targetUser).replace('{group}', group).replace('{reason}', reason ? `,原因:${reason}` : '')
935
948
  }