koishi-plugin-onebot-verifier 1.1.4 → 1.1.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.d.ts +9 -4
- package/lib/index.js +26 -17
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -8,13 +8,18 @@ export interface Config {
|
|
|
8
8
|
notifyTarget?: string;
|
|
9
9
|
debugMode?: boolean;
|
|
10
10
|
kickBan?: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
friendTimeout: 'manual' | {
|
|
12
|
+
action: 'accept' | 'reject';
|
|
13
|
+
timeout: number;
|
|
14
|
+
};
|
|
13
15
|
friendLevel?: number;
|
|
14
16
|
friendRegex?: string;
|
|
15
17
|
minMembers?: number;
|
|
16
18
|
maxCapacity?: number;
|
|
17
|
-
|
|
19
|
+
memberTimeout: 'manual' | {
|
|
20
|
+
action: 'accept' | 'reject';
|
|
21
|
+
timeout: number;
|
|
22
|
+
};
|
|
18
23
|
verifyRules?: {
|
|
19
24
|
guildId: string;
|
|
20
25
|
keyword?: string;
|
|
@@ -31,4 +36,4 @@ export interface Config {
|
|
|
31
36
|
voteInSitu?: boolean;
|
|
32
37
|
}
|
|
33
38
|
export declare const Config: Schema<Config>;
|
|
34
|
-
export declare function apply(ctx: Context, config
|
|
39
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -49,22 +49,32 @@ var Config = import_koishi.Schema.intersect([
|
|
|
49
49
|
kickBan: import_koishi.Schema.boolean().description("被踢自动处理").default(false)
|
|
50
50
|
}).description("基础配置"),
|
|
51
51
|
import_koishi.Schema.object({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
import_koishi.Schema.
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
friendTimeout: import_koishi.Schema.union([
|
|
53
|
+
import_koishi.Schema.const("manual").description("手动"),
|
|
54
|
+
import_koishi.Schema.object({
|
|
55
|
+
action: import_koishi.Schema.union([
|
|
56
|
+
import_koishi.Schema.const("accept").description("同意"),
|
|
57
|
+
import_koishi.Schema.const("reject").description("拒绝")
|
|
58
|
+
]).description("操作").required(),
|
|
59
|
+
timeout: import_koishi.Schema.number().description("时长").default(360).min(1)
|
|
60
|
+
}).description("自动")
|
|
61
|
+
]).description("模式").default("manual"),
|
|
57
62
|
friendLevel: import_koishi.Schema.number().description("最低好友等级").default(0).min(0).max(256),
|
|
58
63
|
friendRegex: import_koishi.Schema.string().description("好友验证正则"),
|
|
59
64
|
minMembers: import_koishi.Schema.number().description("最低群成员数").default(0).min(0).max(3e3),
|
|
60
65
|
maxCapacity: import_koishi.Schema.number().description("最低受邀容量").default(0).min(0).max(3e3)
|
|
61
66
|
}).description("好友邀群配置"),
|
|
62
67
|
import_koishi.Schema.object({
|
|
63
|
-
|
|
64
|
-
import_koishi.Schema.const("
|
|
65
|
-
import_koishi.Schema.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
memberTimeout: import_koishi.Schema.union([
|
|
69
|
+
import_koishi.Schema.const("manual").description("手动"),
|
|
70
|
+
import_koishi.Schema.object({
|
|
71
|
+
action: import_koishi.Schema.union([
|
|
72
|
+
import_koishi.Schema.const("accept").description("同意"),
|
|
73
|
+
import_koishi.Schema.const("reject").description("拒绝")
|
|
74
|
+
]).description("操作").required(),
|
|
75
|
+
timeout: import_koishi.Schema.number().description("超时").default(360).min(1)
|
|
76
|
+
}).description("自动")
|
|
77
|
+
]).description("模式").default("manual"),
|
|
68
78
|
verifyRules: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
69
79
|
guildId: import_koishi.Schema.string().description("群号").required(),
|
|
70
80
|
keyword: import_koishi.Schema.string().description("正则"),
|
|
@@ -93,7 +103,7 @@ var Config = import_koishi.Schema.intersect([
|
|
|
93
103
|
]).description("[验证]难度").default("simple")
|
|
94
104
|
}).description("特殊验证配置")
|
|
95
105
|
]);
|
|
96
|
-
function apply(ctx, config
|
|
106
|
+
function apply(ctx, config) {
|
|
97
107
|
const logger = new import_koishi.Logger("onebot-verifier");
|
|
98
108
|
const activeTasks = /* @__PURE__ */ new Map();
|
|
99
109
|
const activeCaptchas = /* @__PURE__ */ new Map();
|
|
@@ -158,8 +168,7 @@ function apply(ctx, config = {}) {
|
|
|
158
168
|
}
|
|
159
169
|
}, "sendNotice");
|
|
160
170
|
const setupManual = /* @__PURE__ */ __name(async (session, kind, specialMode, useInSitu) => {
|
|
161
|
-
const
|
|
162
|
-
const action = kind === "member" ? config.verifyMode : config.timeoutAction;
|
|
171
|
+
const mode = kind === "member" ? config.memberTimeout : config.friendTimeout;
|
|
163
172
|
let targetStr = config.notifyTarget || "";
|
|
164
173
|
if (useInSitu && kind === "member" && session.guildId) targetStr = `guild:${session.guildId}`;
|
|
165
174
|
const msgIds = await sendNotice(session, kind, "waiting", targetStr);
|
|
@@ -171,13 +180,13 @@ function apply(ctx, config = {}) {
|
|
|
171
180
|
task.votes = { yes: /* @__PURE__ */ new Set(), no: /* @__PURE__ */ new Set() };
|
|
172
181
|
}
|
|
173
182
|
msgIds.forEach((id) => activeTasks.set(id, task));
|
|
174
|
-
if (
|
|
183
|
+
if (mode !== "manual" && typeof mode === "object") {
|
|
184
|
+
const { action, timeout } = mode;
|
|
175
185
|
task.timer = setTimeout(async () => {
|
|
176
186
|
if (!activeTasks.has(msgIds[0])) return;
|
|
177
187
|
msgIds.forEach((id) => activeTasks.delete(id));
|
|
178
188
|
let finalAction = action;
|
|
179
|
-
if (specialMode === "vote"
|
|
180
|
-
if (finalAction === "manual") return;
|
|
189
|
+
if (specialMode === "vote") finalAction = "reject";
|
|
181
190
|
const isPass = finalAction === "accept";
|
|
182
191
|
await executeAction(session, kind, isPass, isPass ? "" : "等待超时,自动拒绝");
|
|
183
192
|
const [targetType, targetId] = targetStr.split(":");
|
|
@@ -187,7 +196,7 @@ function apply(ctx, config = {}) {
|
|
|
187
196
|
});
|
|
188
197
|
}
|
|
189
198
|
if (config.debugMode) logger.info(`[操作] 等待超时,默认${isPass ? "通过" : "拒绝"}`);
|
|
190
|
-
},
|
|
199
|
+
}, timeout * 6e4);
|
|
191
200
|
}
|
|
192
201
|
}, "setupManual");
|
|
193
202
|
const hookEvent = /* @__PURE__ */ __name((kind) => async (session) => {
|