koishi-plugin-onebot-verifier 1.0.2 → 1.0.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
@@ -6,7 +6,6 @@ export declare const inject: {
6
6
  export declare const usage = "\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #4a6ee0;\">\uD83D\uDCCC \u63D2\u4EF6\u8BF4\u660E</h2>\n <p>\uD83D\uDCD6 <strong>\u4F7F\u7528\u6587\u6863</strong>\uFF1A\u8BF7\u70B9\u51FB\u5DE6\u4E0A\u89D2\u7684 <strong>\u63D2\u4EF6\u4E3B\u9875</strong> \u67E5\u770B\u63D2\u4EF6\u4F7F\u7528\u6587\u6863</p>\n <p>\uD83D\uDD0D <strong>\u66F4\u591A\u63D2\u4EF6</strong>\uFF1A\u53EF\u8BBF\u95EE <a href=\"https://github.com/YisRime\" style=\"color:#4a6ee0;text-decoration:none;\">\u82E1\u6DDE\u7684 GitHub</a> \u67E5\u770B\u672C\u4EBA\u7684\u6240\u6709\u63D2\u4EF6</p>\n</div>\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #e0574a;\">\u2764\uFE0F \u652F\u6301\u4E0E\u53CD\u9988</h2>\n <p>\uD83C\uDF1F \u559C\u6B22\u8FD9\u4E2A\u63D2\u4EF6\uFF1F\u8BF7\u5728 <a href=\"https://github.com/YisRime\" style=\"color:#e0574a;text-decoration:none;\">GitHub</a> \u4E0A\u7ED9\u6211\u4E00\u4E2A Star\uFF01</p>\n <p>\uD83D\uDC1B \u9047\u5230\u95EE\u9898\uFF1F\u8BF7\u901A\u8FC7 <strong>Issues</strong> \u63D0\u4EA4\u53CD\u9988\uFF0C\u6216\u52A0\u5165 QQ \u7FA4 <a href=\"https://qm.qq.com/q/PdLMx9Jowq\" style=\"color:#e0574a;text-decoration:none;\"><strong>855571375</strong></a> \u8FDB\u884C\u4EA4\u6D41</p>\n</div>\n";
7
7
  export interface Config {
8
8
  notifyTarget?: string;
9
- notifyAuto?: boolean;
10
9
  debugMode?: boolean;
11
10
  timeout?: number;
12
11
  timeoutAction?: 'accept' | 'reject';
@@ -14,12 +13,12 @@ export interface Config {
14
13
  friendRegex?: string;
15
14
  minMembers?: number;
16
15
  maxCapacity?: number;
17
- verifyMode?: 'strict' | 'assist' | 'manual';
16
+ verifyMode?: 'accept' | 'reject' | 'manual';
18
17
  verifyRules?: {
19
18
  guildId: string;
20
19
  keyword?: string;
21
20
  minLevel?: number;
22
- groupAction?: 'accept' | 'reject';
21
+ action?: 'accept' | 'reject';
23
22
  }[];
24
23
  }
25
24
  export declare const Config: Schema<Config>;
package/lib/index.js CHANGED
@@ -45,7 +45,6 @@ var usage = `
45
45
  var Config = import_koishi.Schema.intersect([
46
46
  import_koishi.Schema.object({
47
47
  notifyTarget: import_koishi.Schema.string().description("通知目标(guild/private:number)").required(),
48
- notifyAuto: import_koishi.Schema.boolean().description("发送全部通知").default(true),
49
48
  debugMode: import_koishi.Schema.boolean().description("输出调试日志").default(false)
50
49
  }).description("基础配置"),
51
50
  import_koishi.Schema.object({
@@ -61,15 +60,15 @@ var Config = import_koishi.Schema.intersect([
61
60
  }).description("好友邀群配置"),
62
61
  import_koishi.Schema.object({
63
62
  verifyMode: import_koishi.Schema.union([
64
- import_koishi.Schema.const("strict").description("规则"),
65
- import_koishi.Schema.const("assist").description("超时"),
63
+ import_koishi.Schema.const("accept").description("同意"),
64
+ import_koishi.Schema.const("reject").description("拒绝"),
66
65
  import_koishi.Schema.const("manual").description("手动")
67
- ]).description("处理模式").default("assist"),
66
+ ]).description("处理模式").default("manual"),
68
67
  verifyRules: import_koishi.Schema.array(import_koishi.Schema.object({
69
68
  guildId: import_koishi.Schema.string().description("群号").required(),
70
69
  keyword: import_koishi.Schema.string().description("正则"),
71
70
  minLevel: import_koishi.Schema.number().description("等级").default(-1),
72
- groupAction: import_koishi.Schema.union([
71
+ action: import_koishi.Schema.union([
73
72
  import_koishi.Schema.const("accept").description("同意"),
74
73
  import_koishi.Schema.const("reject").description("拒绝")
75
74
  ]).description("操作")
@@ -107,7 +106,6 @@ function apply(ctx, config = {}) {
107
106
  if (!notifyConfig) return [];
108
107
  const [targetType, targetId] = notifyConfig.split(":");
109
108
  if (!targetId || targetType !== "guild" && targetType !== "private") return [];
110
- if (status !== "waiting" && !config.notifyAuto) return [];
111
109
  try {
112
110
  const eventData = session.event?._data || {};
113
111
  const userInfo = session.userId ? await session.bot.getUser?.(session.userId)?.catch(() => null) : null;
@@ -133,28 +131,9 @@ function apply(ctx, config = {}) {
133
131
  const rawText = session.event?._data?.comment || "";
134
132
  const cleanLines = rawText.split(/[\r\n]+/).map((s) => s.trim()).filter((s) => /^(回答)[::]/i.test(s)).map((s) => s.replace(/^(回答)[::]\s*/i, ""));
135
133
  const verifyText = cleanLines.length > 0 ? cleanLines.join("\n") : rawText;
136
- const toRegex = /* @__PURE__ */ __name((text) => {
137
- const match = text.match(/^\/(.+)\/([a-z]*)$/);
138
- return match ? new RegExp(match[1], match[2]) : new RegExp(text, "i");
139
- }, "toRegex");
140
- if (kind === "member") {
141
- const groupRule = config.verifyRules?.find((r) => r.guildId === session.guildId);
142
- if (!groupRule) return false;
143
- try {
144
- if (groupRule.keyword && !toRegex(groupRule.keyword).test(verifyText)) return false;
145
- const limitLevel = groupRule.minLevel ?? -1;
146
- if (limitLevel >= 0 && session.onebot && session.userId) {
147
- const stats = await session.onebot.getStrangerInfo(session.userId, true);
148
- if ((stats.qqLevel ?? 0) < limitLevel) return `QQ 等级低于 ${limitLevel} 级`;
149
- }
150
- } catch {
151
- return false;
152
- }
153
- return true;
154
- }
155
134
  if (kind === "friend") {
156
135
  try {
157
- if (config.friendRegex && toRegex(config.friendRegex).test(verifyText)) return true;
136
+ if (config.friendRegex && new RegExp(config.friendRegex, "i").test(verifyText)) return true;
158
137
  const limitLevel = config.friendLevel ?? -1;
159
138
  if (limitLevel >= 0 && session.onebot && session.userId) {
160
139
  const stats = await session.onebot.getStrangerInfo(session.userId, true);
@@ -196,12 +175,9 @@ function apply(ctx, config = {}) {
196
175
  task.timer = setTimeout(async () => {
197
176
  if (!activeTasks.has(msgIds[0])) return;
198
177
  msgIds.forEach((id) => activeTasks.delete(id));
199
- let finalAction = config.timeoutAction;
200
- if (kind === "member") {
201
- const groupRule = config.verifyRules?.find((r) => r.guildId === session.guildId);
202
- if (groupRule?.groupAction) finalAction = groupRule.groupAction;
203
- }
204
- const isPass = finalAction === "accept";
178
+ const action = kind === "member" ? config.verifyMode : config.timeoutAction;
179
+ if (action === "manual" || !action) return;
180
+ const isPass = action === "accept";
205
181
  await executeAction(session, kind, isPass, isPass ? "" : "等待人工超时,自动拒绝");
206
182
  const notifyConfig = config.notifyTarget || "";
207
183
  const [targetType, targetId] = notifyConfig.split(":");
@@ -215,14 +191,19 @@ function apply(ctx, config = {}) {
215
191
  const handleEvent = /* @__PURE__ */ __name(async (session, kind) => {
216
192
  try {
217
193
  if (kind === "member") {
218
- if (config.verifyMode === "manual") {
219
- await setupManual(session, kind);
220
- return;
221
- }
222
- if (config.verifyMode === "strict") {
223
- const matched = config.verifyRules?.some((r) => r.guildId === session.guildId);
224
- if (!matched) return;
194
+ const rule = config.verifyRules?.find((r) => r.guildId === session.guildId);
195
+ if (rule) {
196
+ const rawText = session.event?._data?.comment || "";
197
+ const stats = (rule.minLevel ?? -1) >= 0 && session.onebot && session.userId ? await session.onebot.getStrangerInfo(session.userId, true).catch(() => ({})) : null;
198
+ const isMatch = (!rule.keyword || new RegExp(rule.keyword, "i").test(rawText)) && (!stats || (stats.qqLevel ?? 0) >= rule.minLevel);
199
+ if (isMatch && rule.action) {
200
+ const isApprove = rule.action === "accept";
201
+ await executeAction(session, kind, isApprove, isApprove ? "" : "命中拒绝规则,自动拒绝");
202
+ await sendNotice(session, kind, isApprove ? "auto_pass" : "auto_reject");
203
+ return;
204
+ }
225
205
  }
206
+ return await setupManual(session, kind);
226
207
  }
227
208
  const verdict = await checkCriteria(session, kind);
228
209
  if (verdict === true) {
@@ -232,7 +213,6 @@ function apply(ctx, config = {}) {
232
213
  await executeAction(session, kind, false, verdict);
233
214
  await sendNotice(session, kind, "auto_reject");
234
215
  } else {
235
- if (kind === "member" && config.verifyMode === "strict") return;
236
216
  await setupManual(session, kind);
237
217
  }
238
218
  } catch (error) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-onebot-verifier",
3
3
  "description": "适用于 Onebot 的审核插件,支持自动审核好友/加群/邀请请求",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],