koishi-plugin-onebot-verifier 1.1.0 → 1.1.1
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 +30 -5
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -85,7 +85,12 @@ var Config = import_koishi.Schema.intersect([
|
|
|
85
85
|
]).description("模式").default("vote"),
|
|
86
86
|
enabled: import_koishi.Schema.boolean().description("前置规则").default(true)
|
|
87
87
|
})).description("配置列表").role("table"),
|
|
88
|
-
voteRatio: import_koishi.Schema.string().description("
|
|
88
|
+
voteRatio: import_koishi.Schema.string().description("[投票]人数").default("3:2"),
|
|
89
|
+
captchaDiff: import_koishi.Schema.union([
|
|
90
|
+
import_koishi.Schema.const("simple").description("简单"),
|
|
91
|
+
import_koishi.Schema.const("medium").description("中等"),
|
|
92
|
+
import_koishi.Schema.const("hard").description("困难")
|
|
93
|
+
]).description("[验证码]难度").default("simple")
|
|
89
94
|
}).description("特殊验证配置")
|
|
90
95
|
]);
|
|
91
96
|
function apply(ctx, config = {}) {
|
|
@@ -325,11 +330,31 @@ function apply(ctx, config = {}) {
|
|
|
325
330
|
if (!config.specialRules || !session.guildId || !session.userId) return;
|
|
326
331
|
const rule = config.specialRules.find((r) => String(r.guildId) === String(session.guildId) && r.enabled);
|
|
327
332
|
if (rule?.mode === "captcha") {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
333
|
+
let a, b, op = "+", answer;
|
|
334
|
+
if (config.captchaDiff === "simple") {
|
|
335
|
+
a = Math.floor(Math.random() * 80) + 10;
|
|
336
|
+
b = Math.floor(Math.random() * 80) + 10;
|
|
337
|
+
if (Math.random() > 0.5) {
|
|
338
|
+
op = "+";
|
|
339
|
+
answer = (a + b).toString();
|
|
340
|
+
} else {
|
|
341
|
+
op = "-";
|
|
342
|
+
if (a < b) [a, b] = [b, a];
|
|
343
|
+
answer = (a - b).toString();
|
|
344
|
+
}
|
|
345
|
+
} else if (config.captchaDiff === "medium") {
|
|
346
|
+
a = Math.floor(Math.random() * 89) + 11;
|
|
347
|
+
b = Math.floor(Math.random() * 8) + 2;
|
|
348
|
+
op = "×";
|
|
349
|
+
answer = (a * b).toString();
|
|
350
|
+
} else {
|
|
351
|
+
a = Math.floor(Math.random() * 40) + 11;
|
|
352
|
+
b = Math.floor(Math.random() * 10) + 11;
|
|
353
|
+
op = "×";
|
|
354
|
+
answer = (a * b).toString();
|
|
355
|
+
}
|
|
331
356
|
const captchaKey = `${session.guildId}:${session.userId}`;
|
|
332
|
-
await session.send(`<at id="${session.userId}"/> 请在 60 秒内回复计算结果,以进行验证:${a}
|
|
357
|
+
await session.send(`<at id="${session.userId}"/> 请在 60 秒内回复计算结果,以进行验证:${a} ${op} ${b} =`);
|
|
333
358
|
const timer = setTimeout(async () => {
|
|
334
359
|
if (activeCaptchas.has(captchaKey)) {
|
|
335
360
|
activeCaptchas.delete(captchaKey);
|