koishi-plugin-group-control 1.0.0 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 muyni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/config.d.ts CHANGED
@@ -26,6 +26,9 @@ export interface GroupInviteConfig {
26
26
  inviteWaitMessage: string;
27
27
  inviteRequestMessage: string;
28
28
  autoApprove: boolean;
29
+ notifyAdminOnApprove: boolean;
30
+ inviteApproveMessage: string;
31
+ inviteApproveNotificationMessage: string;
29
32
  showDetailedLog: boolean;
30
33
  inviteExpireDays: number;
31
34
  }
package/lib/index.js CHANGED
@@ -142,13 +142,20 @@ async function updateCommandFrequencyRecord(ctx, platform, guildId, data) {
142
142
  }]);
143
143
  }
144
144
  __name(updateCommandFrequencyRecord, "updateCommandFrequencyRecord");
145
+ var groupBotStatusCache = /* @__PURE__ */ new Map();
146
+ var groupBotStatusCacheKey = /* @__PURE__ */ __name((platform, guildId) => `${platform}:${guildId}`, "groupBotStatusCacheKey");
145
147
  async function getGroupBotStatus(ctx, platform, guildId) {
148
+ const key = groupBotStatusCacheKey(platform, guildId);
149
+ if (groupBotStatusCache.has(key)) return groupBotStatusCache.get(key);
146
150
  const records = await ctx.model.get("group_bot_status", { platform, guildId });
147
- return records.length > 0 ? records[0] : null;
151
+ const status = records.length > 0 ? records[0] : null;
152
+ groupBotStatusCache.set(key, status);
153
+ return status;
148
154
  }
149
155
  __name(getGroupBotStatus, "getGroupBotStatus");
150
156
  async function setGroupBotStatus(ctx, platform, guildId, botEnabled) {
151
157
  await ctx.model.upsert("group_bot_status", [{ platform, guildId, botEnabled }]);
158
+ groupBotStatusCache.set(groupBotStatusCacheKey(platform, guildId), { platform, guildId, botEnabled });
152
159
  }
153
160
  __name(setGroupBotStatus, "setGroupBotStatus");
154
161
  async function isInSmallGroupWhitelist(ctx, guildId) {
@@ -575,12 +582,6 @@ function apply3(ctx, config) {
575
582
  } catch (error) {
576
583
  console.error("获取群信息失败:", error);
577
584
  }
578
- try {
579
- const waitMessage = config.invite.inviteWaitMessage.replaceAll("{groupName}", groupName).replaceAll("{groupId}", rawGroupId).replaceAll("{userName}", userName).replaceAll("{userId}", rawUserId);
580
- await session.bot.sendPrivateMessage(rawUserId, waitMessage);
581
- } catch (error) {
582
- console.error(`发送等待审核提示给 ${rawUserId} 失败:`, error);
583
- }
584
585
  if (config.invite.autoApprove) {
585
586
  try {
586
587
  await session.bot.internal.setGroupAddRequest(flag, "invite", true, "");
@@ -590,9 +591,26 @@ function apply3(ctx, config) {
590
591
  }
591
592
  } catch (error) {
592
593
  console.error("自动同意群聊邀请失败:", error);
594
+ return;
595
+ }
596
+ try {
597
+ const approveMessage = config.invite.inviteApproveMessage.replaceAll("{groupName}", groupName).replaceAll("{groupId}", rawGroupId).replaceAll("{userName}", userName).replaceAll("{userId}", rawUserId);
598
+ await session.bot.sendPrivateMessage(rawUserId, approveMessage);
599
+ } catch (error) {
600
+ console.error(`发送自动通过提示给 ${rawUserId} 失败:`, error);
601
+ }
602
+ if (config.invite.notifyAdminOnApprove) {
603
+ const notifyMessage = config.invite.inviteApproveNotificationMessage.replaceAll("{groupName}", groupName).replaceAll("{groupId}", rawGroupId).replaceAll("{userName}", userName).replaceAll("{userId}", rawUserId);
604
+ await notifyAdmins(session.bot, config, notifyMessage);
593
605
  }
594
606
  return;
595
607
  }
608
+ try {
609
+ const waitMessage = config.invite.inviteWaitMessage.replaceAll("{groupName}", groupName).replaceAll("{groupId}", rawGroupId).replaceAll("{userName}", userName).replaceAll("{userId}", rawUserId);
610
+ await session.bot.sendPrivateMessage(rawUserId, waitMessage);
611
+ } catch (error) {
612
+ console.error(`发送等待审核提示给 ${rawUserId} 失败:`, error);
613
+ }
596
614
  if (!config.admin.adminQQs || config.admin.adminQQs.length === 0) {
597
615
  return;
598
616
  }
@@ -1039,7 +1057,9 @@ function apply6(ctx, config) {
1039
1057
  if (isBotEnabled) {
1040
1058
  return next();
1041
1059
  }
1042
- if (ADMIN_COMMANDS.has(session["event"]["_data"]["message"])) {
1060
+ const content = session.stripped?.content ?? session.content ?? "";
1061
+ const firstWord = content.match(/^\s*[/.!!。]*(\S+)/)?.[1];
1062
+ if (firstWord && ADMIN_COMMANDS.has(firstWord)) {
1043
1063
  return next();
1044
1064
  }
1045
1065
  const isMentioned = session.elements?.some((e) => e.type === "at" && e.attrs.id === session.bot.userId);
@@ -1184,8 +1204,11 @@ var Config = import_koishi.Schema.intersect([
1184
1204
  invite: import_koishi.Schema.object({
1185
1205
  enabled: import_koishi.Schema.boolean().default(false).description("启用群聊邀请审核"),
1186
1206
  autoApprove: import_koishi.Schema.boolean().default(false).description("自动同意邀请"),
1207
+ notifyAdminOnApprove: import_koishi.Schema.boolean().default(true).description("自动同意时是否仍通知管理员"),
1187
1208
  inviteWaitMessage: import_koishi.Schema.string().default("已收到您的群聊邀请,正在等待管理员审核,请耐心等待。").description("发给邀请者的等待提示"),
1209
+ inviteApproveMessage: import_koishi.Schema.string().default("已自动通过您的群聊邀请,机器人正在加入群聊。").description("自动同意时发给邀请者的提示,支持变量 {groupName}, {groupId}, {userName}, {userId}"),
1188
1210
  inviteRequestMessage: import_koishi.Schema.string().default("收到新的群聊邀请请求:\n群名称:{groupName}\n群号:{groupId}\n邀请者:{userName} (QQ: {userId})\n\n请使用指令 gc.approve {groupId} 同意或 gc.reject {groupId} 拒绝。").description("发给管理员的请求消息模板,支持变量 {groupName}, {groupId}, {userName}, {userId}"),
1211
+ inviteApproveNotificationMessage: import_koishi.Schema.string().default("已自动通过群聊邀请\n群名称:{groupName}\n群号:{groupId}\n邀请者:{userName} (QQ: {userId})").description("自动同意时发给管理员的通知模板,支持变量 {groupName}, {groupId}, {userName}, {userId}"),
1189
1212
  inviteExpireDays: import_koishi.Schema.number().default(3).description("邀请记录过期天数"),
1190
1213
  showDetailedLog: import_koishi.Schema.boolean().default(false).description("显示详细日志")
1191
1214
  }).description("群聊邀请审核")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-control",
3
3
  "description": "Koishi 插件,一个多功能的群聊自管理工具。支持被踢出自动拉黑、刷屏自动屏蔽、开关控制等功能。(仅支持 OneBot 适配器)",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [