koishi-plugin-group-control 0.2.9 → 0.2.10

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.js CHANGED
@@ -211,8 +211,26 @@ var ADMIN_COMMANDS = /* @__PURE__ */ new Set([
211
211
  "pending-invites"
212
212
  ]);
213
213
 
214
+ // src/state.ts
215
+ var approvedGroups = /* @__PURE__ */ new Set();
216
+
214
217
  // src/modules/basic.ts
215
218
  var name2 = "group-control-basic";
219
+ async function getGroupName(bot, guildId) {
220
+ try {
221
+ const info = await bot.internal?.getGroupInfo?.(parseInt(guildId));
222
+ if (info?.group_name) return info.group_name;
223
+ } catch {
224
+ }
225
+ try {
226
+ const info = await bot.getGuild(guildId);
227
+ if (info?.name) return info.name;
228
+ if (info?.group_name) return info.group_name;
229
+ } catch {
230
+ }
231
+ return "未知";
232
+ }
233
+ __name(getGroupName, "getGroupName");
216
234
  function apply2(ctx, config) {
217
235
  const quittingGuilds = /* @__PURE__ */ new Map();
218
236
  const processedKicks = /* @__PURE__ */ new Map();
@@ -245,54 +263,65 @@ function apply2(ctx, config) {
245
263
  }
246
264
  }
247
265
  if (config.basic.smallGroupAutoQuit) {
248
- const delay = config.basic.smallGroupCheckDelay || 3e3;
249
- setTimeout(async () => {
250
- try {
251
- let memberCount = 0;
266
+ if (approvedGroups.has(guildId)) {
267
+ approvedGroups.delete(guildId);
268
+ } else {
269
+ const delay = config.basic.smallGroupCheckDelay || 3e3;
270
+ setTimeout(async () => {
252
271
  try {
253
- const groupInfo = await session.bot.internal?.getGroupInfo?.(parseInt(guildId));
254
- memberCount = groupInfo?.member_count || 0;
255
- } catch {
256
- }
257
- if (memberCount === 0) {
272
+ let memberCount = 0;
273
+ let groupName = "未知";
258
274
  try {
259
- const guildInfo = await session.bot.getGuild(guildId);
260
- memberCount = guildInfo?.member_count || guildInfo?.memberCount || 0;
275
+ const groupInfo = await session.bot.internal?.getGroupInfo?.(parseInt(guildId));
276
+ memberCount = groupInfo?.member_count || 0;
277
+ if (groupInfo?.group_name) groupName = groupInfo.group_name;
261
278
  } catch {
262
279
  }
263
- }
264
- if (memberCount === 0) {
265
- try {
266
- const memberList = await session.bot.getGuildMemberList(guildId);
267
- memberCount = memberList?.data?.length || 0;
268
- } catch {
280
+ if (memberCount === 0) {
281
+ try {
282
+ const guildInfo = await session.bot.getGuild(guildId);
283
+ memberCount = guildInfo?.member_count || guildInfo?.memberCount || 0;
284
+ if (guildInfo?.name) groupName = guildInfo.name;
285
+ } catch {
286
+ }
269
287
  }
270
- }
271
- if (memberCount > 0 && memberCount <= config.basic.smallGroupThreshold) {
272
- const quitMsg = config.basic.smallGroupQuitMessage.replace("{memberCount}", memberCount.toString()).replace("{threshold}", config.basic.smallGroupThreshold.toString());
273
- try {
274
- await session.bot.sendMessage(guildId, quitMsg, platform);
275
- } catch (e) {
288
+ if (memberCount === 0) {
289
+ try {
290
+ const memberList = await session.bot.getGuildMemberList(guildId);
291
+ memberCount = memberList?.data?.length || 0;
292
+ } catch {
293
+ }
294
+ }
295
+ if (groupName === "未知") {
296
+ groupName = await getGroupName(session.bot, guildId);
276
297
  }
277
- if (config.basic.smallGroupNotifyAdmin) {
278
- const adminMsg = `小群自动退群
298
+ if (memberCount > 0 && memberCount <= config.basic.smallGroupThreshold) {
299
+ const quitMsg = config.basic.smallGroupQuitMessage.replaceAll("{memberCount}", memberCount.toString()).replaceAll("{threshold}", config.basic.smallGroupThreshold.toString()).replaceAll("{groupName}", groupName).replaceAll("{groupId}", guildId);
300
+ try {
301
+ await session.bot.sendMessage(guildId, quitMsg, platform);
302
+ } catch (e) {
303
+ }
304
+ if (config.basic.smallGroupNotifyAdmin) {
305
+ const adminMsg = `小群自动退群
306
+ 群名称:${groupName}
279
307
  群号:${guildId}
280
308
  群成员数:${memberCount}人(阈值:${config.basic.smallGroupThreshold}人)
281
309
  机器人已自动退出该群。`;
282
- await notifyAdmins(session.bot, config, adminMsg);
283
- }
284
- quittingGuilds.set(`${platform}:${guildId}`, Date.now());
285
- try {
286
- await session.bot.internal.setGroupLeave(parseInt(guildId));
287
- } catch (e) {
288
- console.error(`小群自动退群失败 (群号: ${guildId}):`, e);
289
- quittingGuilds.delete(`${platform}:${guildId}`);
310
+ await notifyAdmins(session.bot, config, adminMsg);
311
+ }
312
+ quittingGuilds.set(`${platform}:${guildId}`, Date.now());
313
+ try {
314
+ await session.bot.internal.setGroupLeave(parseInt(guildId));
315
+ } catch (e) {
316
+ console.error(`小群自动退群失败 (群号: ${guildId}):`, e);
317
+ quittingGuilds.delete(`${platform}:${guildId}`);
318
+ }
290
319
  }
320
+ } catch (error) {
321
+ console.error(`小群自动退群检测失败 (群号: ${guildId}):`, error);
291
322
  }
292
- } catch (error) {
293
- console.error(`小群自动退群检测失败 (群号: ${guildId}):`, error);
294
- }
295
- }, delay);
323
+ }, delay);
324
+ }
296
325
  }
297
326
  if (config.basic.welcomeMessage) {
298
327
  try {
@@ -311,6 +340,7 @@ function apply2(ctx, config) {
311
340
  return;
312
341
  }
313
342
  processedKicks.set(quittingKey, Date.now());
343
+ const groupName = await getGroupName(session.bot, guildId);
314
344
  if (config.basic.enableBlacklist) {
315
345
  await ctx.model.upsert("blacklisted_guild", [{
316
346
  platform,
@@ -320,7 +350,7 @@ function apply2(ctx, config) {
320
350
  }]);
321
351
  }
322
352
  if (config.basic.notifyAdminOnKick) {
323
- const kickMsg = config.basic.kickNotificationMessage.replace("{groupId}", guildId);
353
+ const kickMsg = config.basic.kickNotificationMessage.replaceAll("{groupId}", guildId).replaceAll("{groupName}", groupName);
324
354
  await notifyAdmins(session.bot, config, kickMsg);
325
355
  }
326
356
  });
@@ -336,7 +366,9 @@ function apply2(ctx, config) {
336
366
  if (!hasPerm) return "权限不足,只有群管理员可以使用此指令。";
337
367
  }
338
368
  const { guildId, platform, userId } = session;
369
+ const groupName = await getGroupName(session.bot, guildId);
339
370
  const adminMsg = `收到来自 ${userId} 的退群指令
371
+ 群名称:${groupName}
340
372
  群号:${guildId}`;
341
373
  await notifyAdmins(session.bot, config, adminMsg);
342
374
  quittingGuilds.set(`${platform}:${guildId}`, Date.now());
@@ -414,6 +446,7 @@ function apply3(ctx, config) {
414
446
  if (config.invite.autoApprove) {
415
447
  try {
416
448
  await session.bot.internal.setGroupAddRequest(flag, "invite", true, "");
449
+ approvedGroups.add(rawGroupId);
417
450
  if (config.invite.showDetailedLog) {
418
451
  console.log(`自动同意群聊邀请: 群号 ${rawGroupId}, 邀请者 ${rawUserId}`);
419
452
  }
@@ -472,6 +505,7 @@ function apply3(ctx, config) {
472
505
  }
473
506
  try {
474
507
  await session.bot.internal.setGroupAddRequest(inviteData.flag, "invite", true, "");
508
+ approvedGroups.add(groupId);
475
509
  try {
476
510
  await session.bot.sendPrivateMessage(inviteData.userId, `您的群聊邀请已通过管理员审核,机器人已加入群聊。`);
477
511
  } catch (error) {
@@ -757,10 +791,10 @@ var Config = import_koishi.Schema.intersect([
757
791
  enableBlacklist: import_koishi.Schema.boolean().default(true).description('启用"被踢出自动拉黑"功能'),
758
792
  quitCommandEnabled: import_koishi.Schema.boolean().default(true).description("启用quit"),
759
793
  notifyAdminOnKick: import_koishi.Schema.boolean().default(true).description("被踢出群时通知管理员(需要在群聊邀请审核中配置管理员QQ)"),
760
- kickNotificationMessage: import_koishi.Schema.string().default("机器人已被踢出群聊\n群号:{groupId}\n该群已被自动加入黑名单。").description("被踢出群通知消息模板,支持变量{groupId}"),
794
+ kickNotificationMessage: import_koishi.Schema.string().default("机器人已被踢出群聊\n群名称:{groupName}\n群号:{groupId}\n该群已被自动加入黑名单。").description("被踢出群通知消息模板,支持变量{groupId}, {groupName}"),
761
795
  smallGroupAutoQuit: import_koishi.Schema.boolean().default(false).description("启用小群自动退群功能"),
762
796
  smallGroupThreshold: import_koishi.Schema.number().default(30).description("小群人数阈值(群成员数小于等于此值时自动退群)"),
763
- smallGroupQuitMessage: import_koishi.Schema.string().default("该群人数过少({memberCount}人),不满足最低人数要求({threshold}人),机器人将自动退出。").description("小群自动退群时在群内发送的提示,支持变量{memberCount}, {threshold}"),
797
+ smallGroupQuitMessage: import_koishi.Schema.string().default("该群人数过少({memberCount}人),不满足最低人数要求({threshold}人),机器人将自动退出。").description("小群自动退群时在群内发送的提示,支持变量{memberCount}, {threshold}, {groupName}, {groupId}"),
764
798
  smallGroupNotifyAdmin: import_koishi.Schema.boolean().default(true).description("小群自动退群时通知管理员"),
765
799
  smallGroupCheckDelay: import_koishi.Schema.number().default(3e3).description("小群检测延迟(毫秒),加入群聊后等待一段时间再获取群信息以确保数据准确")
766
800
  }).description("基础群组管理")
package/lib/state.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 跨模块共享状态
3
+ * 用于在 invite 和 basic 等模块间传递信息
4
+ */
5
+ /** 管理员已审核通过的群号集合(approve 指令通过后添加) */
6
+ export declare const approvedGroups: Set<string>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-control",
3
3
  "description": "Koishi 插件,一个多功能的群聊自管理工具。支持被踢出自动拉黑、刷屏自动屏蔽、开关控制等功能。(仅支持 OneBot 适配器)",
4
- "version": "0.2.9",
4
+ "version": "0.2.10",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [