koishi-plugin-onebot-verifier 1.2.3 → 1.2.5
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 +20 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -113,6 +113,11 @@ function apply(ctx, config) {
|
|
|
113
113
|
const eventData = session.event?._data || {};
|
|
114
114
|
if (config.debugMode) logger.info(`[操作] 类型: ${kind} 结果: ${pass ? "同意" : "拒绝"} 原因: ${reason || "无"}`);
|
|
115
115
|
if (pass && kind === "guild" && session.guildId && session.userId) inviterMap.set(session.guildId, session.userId);
|
|
116
|
+
if (!pass && kind === "guild" && session.userId && session.bot) {
|
|
117
|
+
const rejectMsg = `已拒绝该群组邀请${reason ? `,原因:${reason}` : ""}`;
|
|
118
|
+
await session.bot.sendPrivateMessage(session.userId, rejectMsg).catch(() => {
|
|
119
|
+
});
|
|
120
|
+
}
|
|
116
121
|
if (!pass && kind === "guild" && session.guildId && (session.event?.type === "guild-added" || eventData.notice_type === "group_increase")) {
|
|
117
122
|
if (reason) await session.bot?.sendMessage(session.guildId, `${reason},将退出该群`).catch(() => {
|
|
118
123
|
});
|
|
@@ -143,7 +148,7 @@ function apply(ctx, config) {
|
|
|
143
148
|
const groupInfo = kind !== "friend" && session.guildId ? await session.bot.getGuild?.(session.guildId).catch(() => null) : null;
|
|
144
149
|
const adminId = String(eventData.operator_id || session.event?.operator?.id || "");
|
|
145
150
|
const adminInfo = adminId && adminId !== session.userId ? await session.bot.getUser?.(adminId).catch(() => null) : null;
|
|
146
|
-
const typeMap = { friend: "好友申请", member: "加群请求", guild: "群组邀请", removed: eventData.sub_type === "kick_me" ? "移出群组" : "退出群组" };
|
|
151
|
+
const typeMap = { friend: "好友申请", member: "加群请求", guild: eventData.post_type === "notice" ? "群组邀请 (通过)" : "群组邀请 (请求)", removed: eventData.sub_type === "kick_me" ? "移出群组" : "退出群组" };
|
|
147
152
|
const statusMap = { auto_pass: " [自动通过]", auto_reject: " [自动拒绝]", waiting: " [等待处理]" };
|
|
148
153
|
const infoLines = [];
|
|
149
154
|
if (userInfo?.avatar) infoLines.push(`<image url="${userInfo.avatar}"/>`);
|
|
@@ -202,15 +207,23 @@ function apply(ctx, config) {
|
|
|
202
207
|
if (eventData.group_id) session.guildId = String(eventData.group_id);
|
|
203
208
|
try {
|
|
204
209
|
if (config.debugMode) logger.info(`[请求] 类型: ${kind} 数据: ${JSON.stringify(eventData)}`);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
if (kind === "friend") {
|
|
211
|
+
const flag = eventData.flag || `${session.userId}:${eventData.time}`;
|
|
212
|
+
const now = Date.now();
|
|
213
|
+
const flagKey = `flag:${flag}`;
|
|
214
|
+
if (historyMap.has(flagKey) && now - historyMap.get(flagKey) < 3e4) return;
|
|
215
|
+
historyMap.set(flagKey, now);
|
|
216
|
+
let updatedPending = false;
|
|
217
|
+
for (const task of new Set(activeTasks.values())) {
|
|
218
|
+
if (task.kind === "friend" && task.session.userId === session.userId) {
|
|
210
219
|
task.session = session;
|
|
211
|
-
|
|
220
|
+
updatedPending = true;
|
|
212
221
|
}
|
|
213
222
|
}
|
|
223
|
+
if (updatedPending) return;
|
|
224
|
+
const userKey = `friend:${session.userId}`;
|
|
225
|
+
if (historyMap.has(userKey) && now - historyMap.get(userKey) < 3e4) return;
|
|
226
|
+
historyMap.set(userKey, now);
|
|
214
227
|
}
|
|
215
228
|
const verifyText = getComment(eventData.comment);
|
|
216
229
|
if (kind === "member") {
|
|
@@ -379,9 +392,6 @@ function apply(ctx, config) {
|
|
|
379
392
|
ctx.on("guild-removed", async (session) => {
|
|
380
393
|
if (session.guildId) {
|
|
381
394
|
const eventData = session.event?._data || {};
|
|
382
|
-
const curTime = eventData.time || 0;
|
|
383
|
-
if (Math.abs(curTime - (historyMap.get(session.guildId) || 0)) < 300) return;
|
|
384
|
-
historyMap.set(session.guildId, curTime);
|
|
385
395
|
if (config.debugMode) logger.info(`[事件] 退出: ${session.guildId} 数据: ${JSON.stringify(eventData)}`);
|
|
386
396
|
if (eventData.sub_type === "kick_me") {
|
|
387
397
|
const inviterId = inviterMap.get(session.guildId);
|
package/package.json
CHANGED