koishi-plugin-group-control 0.2.2 → 0.2.3
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 +35 -11
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -54,9 +54,10 @@ var Config = import_koishi.Schema.intersect([
|
|
|
54
54
|
import_koishi.Schema.object({
|
|
55
55
|
invite: import_koishi.Schema.object({
|
|
56
56
|
enabled: import_koishi.Schema.boolean().default(false).description("启用群聊邀请审核功能"),
|
|
57
|
-
adminQQs: import_koishi.Schema.array(String).default([]).description("管理员QQ
|
|
57
|
+
adminQQs: import_koishi.Schema.array(String).default([]).description("管理员QQ号列表(用于权限验证)"),
|
|
58
|
+
notificationGroupId: import_koishi.Schema.string().description("通知群号(可选:若填写,邀请请求将发送到此群;若不填,则发送私聊给管理员)"),
|
|
58
59
|
inviteWaitMessage: import_koishi.Schema.string().default("已收到您的群聊邀请,正在等待管理员审核,请耐心等待。").description("发送给邀请者的等待审核提示消息"),
|
|
59
|
-
inviteRequestMessage: import_koishi.Schema.string().default('收到新的群聊邀请请求:\n群名称:{groupName}\n群号:{groupId}\n邀请者:{userName} (QQ: {userId})\n\n
|
|
60
|
+
inviteRequestMessage: import_koishi.Schema.string().default('收到新的群聊邀请请求:\n群名称:{groupName}\n群号:{groupId}\n邀请者:{userName} (QQ: {userId})\n\n请管理员引用此消息回复"同意"或"拒绝"。').description("发送给管理员的邀请请求消息模板,支持变量{groupName}, {groupId}, {userName}, {userId}"),
|
|
60
61
|
autoApprove: import_koishi.Schema.boolean().default(false).description("是否自动同意邀请(仅在没有指定管理员时)"),
|
|
61
62
|
showDetailedLog: import_koishi.Schema.boolean().default(false).description("是否显示详细日志")
|
|
62
63
|
}).description("群聊邀请审核")
|
|
@@ -198,22 +199,45 @@ function apply(ctx, config) {
|
|
|
198
199
|
// 保存flag用于后续处理请求
|
|
199
200
|
});
|
|
200
201
|
const requestMessage = config.invite.inviteRequestMessage.replace("{groupName}", groupName).replace("{groupId}", guildId).replace("{userName}", userName).replace("{userId}", userId);
|
|
201
|
-
|
|
202
|
+
let requestSent = false;
|
|
203
|
+
if (config.invite.notificationGroupId) {
|
|
202
204
|
try {
|
|
203
|
-
|
|
205
|
+
await session.bot.sendMessage(config.invite.notificationGroupId, requestMessage, platform);
|
|
206
|
+
requestSent = true;
|
|
204
207
|
if (config.invite.showDetailedLog) {
|
|
205
|
-
console.log(
|
|
208
|
+
console.log(`发送群聊邀请请求到通知群 ${config.invite.notificationGroupId}`);
|
|
206
209
|
}
|
|
207
210
|
} catch (error) {
|
|
208
|
-
console.error(
|
|
211
|
+
console.error(`发送邀请请求到通知群 ${config.invite.notificationGroupId} 失败:`, error);
|
|
209
212
|
}
|
|
210
213
|
}
|
|
214
|
+
if (!config.invite.notificationGroupId) {
|
|
215
|
+
for (const adminQQ of config.invite.adminQQs) {
|
|
216
|
+
try {
|
|
217
|
+
await session.bot.sendMessage(adminQQ, requestMessage, platform);
|
|
218
|
+
requestSent = true;
|
|
219
|
+
if (config.invite.showDetailedLog) {
|
|
220
|
+
console.log(`发送群聊邀请请求给管理员 ${adminQQ}: 群号 ${guildId}, 邀请者 ${userId}`);
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error(`发送邀请请求给管理员 ${adminQQ} 失败:`, error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!requestSent && config.invite.showDetailedLog) {
|
|
228
|
+
console.warn("群邀请请求未发送给任何目标(未配置通知群且私聊发送失败或未配置管理员)");
|
|
229
|
+
}
|
|
211
230
|
});
|
|
212
231
|
ctx.on("message", async (session) => {
|
|
213
|
-
const { userId, content, platform } = session;
|
|
232
|
+
const { userId, content, platform, guildId } = session;
|
|
214
233
|
if (!config.invite.adminQQs.includes(userId)) {
|
|
215
234
|
return;
|
|
216
235
|
}
|
|
236
|
+
const isNotificationGroup = config.invite.notificationGroupId && guildId === config.invite.notificationGroupId;
|
|
237
|
+
const isPrivate = !guildId;
|
|
238
|
+
if (!isNotificationGroup && !isPrivate && config.invite.notificationGroupId) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
217
241
|
const hasQuote = session.elements.some((element) => element.type === "quote");
|
|
218
242
|
if (!hasQuote) {
|
|
219
243
|
return;
|
|
@@ -253,7 +277,7 @@ function apply(ctx, config) {
|
|
|
253
277
|
if (config.invite.showDetailedLog) {
|
|
254
278
|
console.log(`管理员 ${userId} 同意群聊邀请: 群号 ${inviteData.groupId}, 邀请者 ${inviteData.userId}`);
|
|
255
279
|
}
|
|
256
|
-
await session.
|
|
280
|
+
await session.send(`已同意加入群 ${inviteData.groupId}`);
|
|
257
281
|
try {
|
|
258
282
|
await session.bot.sendMessage(inviteData.userId, `您的群聊邀请已通过管理员审核,机器人已加入群聊。`, platform);
|
|
259
283
|
} catch (error) {
|
|
@@ -261,7 +285,7 @@ function apply(ctx, config) {
|
|
|
261
285
|
}
|
|
262
286
|
} catch (error) {
|
|
263
287
|
console.error("处理同意邀请失败:", error);
|
|
264
|
-
await session.
|
|
288
|
+
await session.send(`处理同意邀请失败: ${error.message}`);
|
|
265
289
|
}
|
|
266
290
|
} else if (trimmedContent === "拒绝" || trimmedContent === "reject") {
|
|
267
291
|
try {
|
|
@@ -274,7 +298,7 @@ function apply(ctx, config) {
|
|
|
274
298
|
if (config.invite.showDetailedLog) {
|
|
275
299
|
console.log(`管理员 ${userId} 拒绝群聊邀请: 群号 ${inviteData.groupId}, 邀请者 ${inviteData.userId}`);
|
|
276
300
|
}
|
|
277
|
-
await session.
|
|
301
|
+
await session.send(`已拒绝加入群 ${inviteData.groupId}`);
|
|
278
302
|
try {
|
|
279
303
|
await session.bot.sendMessage(inviteData.userId, `您的群聊邀请未通过管理员审核,机器人将不会加入该群聊。`, platform);
|
|
280
304
|
} catch (error) {
|
|
@@ -282,7 +306,7 @@ function apply(ctx, config) {
|
|
|
282
306
|
}
|
|
283
307
|
} catch (error) {
|
|
284
308
|
console.error("处理拒绝邀请失败:", error);
|
|
285
|
-
await session.
|
|
309
|
+
await session.send(`处理拒绝邀请失败: ${error.message}`);
|
|
286
310
|
}
|
|
287
311
|
}
|
|
288
312
|
pendingInvites.delete(targetInviteId);
|
package/package.json
CHANGED