koishi-plugin-onebot-verifier 1.2.8 → 1.2.9

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 (2) hide show
  1. package/lib/index.js +26 -15
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -160,7 +160,9 @@ function apply(ctx, config) {
160
160
  if (kind !== "guild" && kind !== "removed" || session.userId && session.userId !== session.selfId) infoLines.push(`用户:${userInfo?.name || session.userId}${session.userId ? `(${session.userId})` : ""}`);
161
161
  if (adminId) infoLines.push(`管理:${adminInfo?.name ? `${adminInfo.name}(${adminId})` : adminId}`);
162
162
  if (session.guildId) infoLines.push(`群组:${groupInfo?.name ? `${groupInfo.name}(${session.guildId})` : session.guildId}`);
163
+ if (eventData.invitor_id && String(eventData.invitor_id) !== "0") infoLines.push(`邀请者:${eventData.invitor_id}`);
163
164
  if (eventData.comment) infoLines.push(`验证信息:${eventData.comment}`);
165
+ if (eventData.via) infoLines.push(`来源:${eventData.via}`);
164
166
  if (status === "waiting" && kind !== "removed") {
165
167
  if (specialMode === "vote") infoLines.push(`[投票模式]需${config.voteRatio.split(":")[0]}人同意或${config.voteRatio.split(":")[1]}人拒绝`);
166
168
  infoLines.push(`使用"y/n"回复本消息以处理该请求`);
@@ -212,25 +214,34 @@ function apply(ctx, config) {
212
214
  if (session.guildId && config.blacklist?.includes(session.guildId)) return;
213
215
  try {
214
216
  if (config.debugMode) logger.info(`[请求] 类型: ${kind} 数据: ${JSON.stringify(eventData)}`);
217
+ const verifyText = getComment(eventData.comment);
215
218
  if (kind === "friend") {
216
- const flag = eventData.flag || `${session.userId}:${eventData.time}`;
217
- const now = Date.now();
218
- const flagKey = `flag:${flag}`;
219
- if (historyMap.has(flagKey) && now - historyMap.get(flagKey) < 3e4) return;
220
- historyMap.set(flagKey, now);
221
- let updatedPending = false;
222
- for (const task of new Set(activeTasks.values())) {
223
- if (task.kind === "friend" && task.session.userId === session.userId) {
224
- task.session = session;
225
- updatedPending = true;
219
+ const existingTask = [...activeTasks.values()].find((t) => t.kind === "friend" && t.session.userId === session.userId);
220
+ if (existingTask) {
221
+ if (existingTask.timer) clearTimeout(existingTask.timer);
222
+ const oldVerifyText = getComment(existingTask.session.event?._data?.comment);
223
+ if (oldVerifyText === verifyText) {
224
+ existingTask.session = session;
225
+ const timeoutCfg = config.friendTimeout;
226
+ if (typeof timeoutCfg === "number") {
227
+ const isPass = timeoutCfg > 0;
228
+ existingTask.timer = setTimeout(async () => {
229
+ if (!activeTasks.has(existingTask.messages[0])) return;
230
+ existingTask.messages.forEach((id) => activeTasks.delete(id));
231
+ await executeAction(session, "friend", isPass, isPass ? "" : "等待超时,自动拒绝");
232
+ const [targetType, targetId] = (config.notifyTarget || "").split(":");
233
+ if (targetId && session.bot) {
234
+ const statusText = `已自动${isPass ? "通过" : "拒绝"}该请求`;
235
+ await (targetType === "private" ? session.bot.sendPrivateMessage(targetId, statusText) : session.bot.sendMessage(targetId, statusText)).catch(() => {
236
+ });
237
+ }
238
+ }, Math.abs(timeoutCfg) * 6e4);
239
+ }
240
+ return;
226
241
  }
242
+ existingTask.messages.forEach((id) => activeTasks.delete(id));
227
243
  }
228
- if (updatedPending) return;
229
- const userKey = `friend:${session.userId}`;
230
- if (historyMap.has(userKey) && now - historyMap.get(userKey) < 3e4) return;
231
- historyMap.set(userKey, now);
232
244
  }
233
- const verifyText = getComment(eventData.comment);
234
245
  if (kind === "member") {
235
246
  const rules = config.verifyRules?.filter((r) => r.guildId === session.guildId) || [];
236
247
  for (const rule of rules) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-onebot-verifier",
3
3
  "description": "[仅支持 Onebot 平台]支持好友申请/群组邀请/加群请求等的自动审核,可根据等级与正则进行筛选,并有入群验证码、投票表决、被踢清理等功能。",
4
- "version": "1.2.8",
4
+ "version": "1.2.9",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],