koishi-plugin-onebot-verifier 1.1.3 → 1.1.4

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 CHANGED
@@ -28,6 +28,7 @@ export interface Config {
28
28
  }[];
29
29
  captchaDiff?: 'simple' | 'medium' | 'hard';
30
30
  voteRatio?: string;
31
+ voteInSitu?: boolean;
31
32
  }
32
33
  export declare const Config: Schema<Config>;
33
34
  export declare function apply(ctx: Context, config?: Config): void;
package/lib/index.js CHANGED
@@ -84,12 +84,13 @@ var Config = import_koishi.Schema.intersect([
84
84
  ]).description("模式").default("vote"),
85
85
  enabled: import_koishi.Schema.boolean().description("前置规则").default(true)
86
86
  })).description("配置列表").role("table"),
87
- voteRatio: import_koishi.Schema.string().description("[投票]人数").default("3:2"),
87
+ voteRatio: import_koishi.Schema.string().description("[投票]支持/反对人数").default("3:2"),
88
+ voteInSitu: import_koishi.Schema.boolean().description("[投票]对应群中发起").default(true),
88
89
  captchaDiff: import_koishi.Schema.union([
89
90
  import_koishi.Schema.const("simple").description("简单"),
90
91
  import_koishi.Schema.const("medium").description("中等"),
91
92
  import_koishi.Schema.const("hard").description("困难")
92
- ]).description("[验证码]难度").default("simple")
93
+ ]).description("[验证]难度").default("simple")
93
94
  }).description("特殊验证配置")
94
95
  ]);
95
96
  function apply(ctx, config = {}) {
@@ -128,8 +129,8 @@ function apply(ctx, config = {}) {
128
129
  return false;
129
130
  }
130
131
  }, "executeAction");
131
- const sendNotice = /* @__PURE__ */ __name(async (session, kind, status = "waiting") => {
132
- const notifyConfig = config.notifyTarget || "";
132
+ const sendNotice = /* @__PURE__ */ __name(async (session, kind, status = "waiting", overrideTarget) => {
133
+ const notifyConfig = overrideTarget || config.notifyTarget || "";
133
134
  const [targetType, targetId] = notifyConfig.split(":");
134
135
  if (!targetId || !session.bot) return [];
135
136
  try {
@@ -156,12 +157,14 @@ function apply(ctx, config = {}) {
156
157
  return [];
157
158
  }
158
159
  }, "sendNotice");
159
- const setupManual = /* @__PURE__ */ __name(async (session, kind, specialMode) => {
160
+ const setupManual = /* @__PURE__ */ __name(async (session, kind, specialMode, useInSitu) => {
160
161
  const waitMinutes = config.timeout ?? 0;
161
162
  const action = kind === "member" ? config.verifyMode : config.timeoutAction;
162
- const msgIds = await sendNotice(session, kind, "waiting");
163
+ let targetStr = config.notifyTarget || "";
164
+ if (useInSitu && kind === "member" && session.guildId) targetStr = `guild:${session.guildId}`;
165
+ const msgIds = await sendNotice(session, kind, "waiting", targetStr);
163
166
  if (!msgIds?.length) return;
164
- const task = { session, kind, messages: msgIds, specialMode };
167
+ const task = { session, kind, messages: msgIds, specialMode, inSitu: useInSitu };
165
168
  if (specialMode === "vote") {
166
169
  const [yesStr, noStr] = config.voteRatio.split(":");
167
170
  task.voteTarget = { yes: parseInt(yesStr) || 0, no: parseInt(noStr) || 0 };
@@ -177,7 +180,7 @@ function apply(ctx, config = {}) {
177
180
  if (finalAction === "manual") return;
178
181
  const isPass = finalAction === "accept";
179
182
  await executeAction(session, kind, isPass, isPass ? "" : "等待超时,自动拒绝");
180
- const [targetType, targetId] = (config.notifyTarget || "").split(":");
183
+ const [targetType, targetId] = targetStr.split(":");
181
184
  if (targetId && session.bot) {
182
185
  const statusText = `已自动${isPass ? "通过" : "拒绝"}该请求`;
183
186
  await (targetType === "private" ? session.bot.sendPrivateMessage(targetId, statusText) : session.bot.sendMessage(targetId, statusText)).catch(() => {
@@ -214,7 +217,7 @@ function apply(ctx, config = {}) {
214
217
  }
215
218
  const specialRule = config.specialRules?.find((r) => String(r.guildId) === String(session.guildId) && r.enabled);
216
219
  if (specialRule) {
217
- if (specialRule.mode === "vote") return await setupManual(session, kind, "vote");
220
+ if (specialRule.mode === "vote") return await setupManual(session, kind, "vote", config.voteInSitu);
218
221
  if (specialRule.mode === "captcha") {
219
222
  await executeAction(session, kind, true, "验证码验证,自动通过");
220
223
  await sendNotice(session, kind, "auto_pass");
@@ -270,7 +273,7 @@ function apply(ctx, config = {}) {
270
273
  logger.error(`处理失败: ${error}`);
271
274
  }
272
275
  }, "hookEvent");
273
- const handleSpecialVote = /* @__PURE__ */ __name(async (session, task, isApprove, extraInfo, targetType, targetId) => {
276
+ const handleSpecialVote = /* @__PURE__ */ __name(async (session, task, isApprove, extraInfo) => {
274
277
  if (!task.voteTarget || !task.votes) return;
275
278
  const voterId = session.userId;
276
279
  if (!voterId) return;
@@ -296,7 +299,7 @@ function apply(ctx, config = {}) {
296
299
  task.messages.forEach((msg) => activeTasks.delete(msg));
297
300
  const isSuccess = await executeAction(task.session, task.kind, finalVerdict, finalVerdict ? "" : extraInfo);
298
301
  const replyText = isSuccess ? `已${finalVerdict ? "通过" : "拒绝"}该投票` : `处理投票失败`;
299
- if (session.bot) await (targetType === "private" ? session.bot.sendPrivateMessage(targetId, replyText) : session.bot.sendMessage(targetId, replyText)).catch(() => {
302
+ await session.send(replyText).catch(() => {
300
303
  });
301
304
  }, "handleSpecialVote");
302
305
  ctx.on("friend-request", hookEvent("friend"));
@@ -377,9 +380,10 @@ function apply(ctx, config = {}) {
377
380
  if (!session.quote?.id) return next();
378
381
  const task = activeTasks.get(session.quote.id);
379
382
  if (!task) return next();
380
- const [targetType, targetId] = (config.notifyTarget || "").split(":");
381
- const isMatched = targetType === "private" ? session.userId === targetId : session.guildId === targetId;
382
- if (!isMatched) return next();
383
+ const [ntType, ntId] = (config.notifyTarget || "").split(":");
384
+ const isGlobalNotifyTarget = ntType === "private" ? session.userId === ntId : session.guildId === ntId;
385
+ const isInSituGuild = task.inSitu && session.guildId && session.guildId === task.session.guildId;
386
+ if (!isGlobalNotifyTarget && !isInSituGuild) return next();
383
387
  const input = session.content.replace(/<(quote|at)\s+[^>]*\/>/gi, "").trim();
384
388
  const cmdMatch = input.match(/^(y|n|通过|拒绝)(?:\s+(.*))?$/i);
385
389
  if (!cmdMatch) return next();
@@ -387,14 +391,14 @@ function apply(ctx, config = {}) {
387
391
  const extraInfo = cmdMatch[2]?.trim() || "";
388
392
  if (config.debugMode) logger.info(`[操作] 收到指令: ${isApprove ? "同意" : "拒绝"}`);
389
393
  if (task.specialMode === "vote") {
390
- await handleSpecialVote(session, task, isApprove, extraInfo, targetType, targetId);
394
+ await handleSpecialVote(session, task, isApprove, extraInfo);
391
395
  return;
392
396
  }
393
397
  if (task.timer) clearTimeout(task.timer);
394
398
  task.messages.forEach((msg) => activeTasks.delete(msg));
395
399
  const isSuccess = await executeAction(task.session, task.kind, isApprove, isApprove ? "" : extraInfo, isApprove && task.kind === "friend" ? extraInfo : "");
396
400
  const replyText = isSuccess ? `已${isApprove ? "通过" : "拒绝"}该请求` : `处理请求失败`;
397
- if (session.bot) await (targetType === "private" ? session.bot.sendPrivateMessage(targetId, replyText) : session.bot.sendMessage(targetId, replyText)).catch(() => {
401
+ await session.send(replyText).catch(() => {
398
402
  });
399
403
  });
400
404
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-onebot-verifier",
3
3
  "description": "适用于 Onebot 的审核插件,支持自动审核好友/加群/邀请请求",
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],