koishi-plugin-onebot-verifier 1.0.4 → 1.0.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.
Files changed (2) hide show
  1. package/lib/index.js +26 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -81,6 +81,7 @@ function apply(ctx, config = {}) {
81
81
  const executeAction = /* @__PURE__ */ __name(async (session, kind, pass, reason = "", remark = "") => {
82
82
  try {
83
83
  const eventData = session.event?._data || {};
84
+ if (config.debugMode) logger.info(`[执行操作] 类型:${kind} 结果:${pass ? "同意" : "拒绝"} 原因:${reason || "无"}`);
84
85
  if (!pass && kind === "guild" && session.guildId && (session.event?.type === "guild-added" || eventData.notice_type === "group_increase")) {
85
86
  if (reason) {
86
87
  try {
@@ -133,11 +134,16 @@ function apply(ctx, config = {}) {
133
134
  const verifyText = cleanLines.length > 0 ? cleanLines.join("\n") : rawText;
134
135
  if (kind === "friend") {
135
136
  try {
136
- if (config.friendRegex && new RegExp(config.friendRegex, "i").test(verifyText)) return true;
137
+ if (config.friendRegex && new RegExp(config.friendRegex, "i").test(verifyText)) {
138
+ if (config.debugMode) logger.info(`[规则匹配] 好友检查: ${config.friendRegex}`);
139
+ return true;
140
+ }
137
141
  const limitLevel = config.friendLevel ?? -1;
138
142
  if (limitLevel >= 0 && session.onebot && session.userId) {
139
143
  const stats = await session.onebot.getStrangerInfo(session.userId, true);
140
- if ((stats.qqLevel ?? 0) < limitLevel) return `QQ 等级低于 ${limitLevel} 级`;
144
+ const isPassed = (stats.qqLevel ?? 0) >= limitLevel;
145
+ if (config.debugMode) logger.info(`[规则判定] 等级检查: ${stats.qqLevel} > ${limitLevel} = ${isPassed}`);
146
+ if (!isPassed) return `QQ 等级低于 ${limitLevel} 级`;
141
147
  return true;
142
148
  }
143
149
  } catch {
@@ -148,14 +154,23 @@ function apply(ctx, config = {}) {
148
154
  if (kind === "guild") {
149
155
  try {
150
156
  const userData = session.userId ? await ctx.database.getUser(session.platform, session.userId) : null;
151
- if (userData && userData.authority > 1) return true;
157
+ if (userData && userData.authority > 1) {
158
+ if (config.debugMode) logger.info(`[规则匹配] : ${userData.authority}`);
159
+ return true;
160
+ }
152
161
  } catch {
153
162
  }
154
163
  if (session.onebot && session.guildId && ((config.minMembers ?? -1) >= 0 || (config.maxCapacity ?? -1) >= 0)) {
155
164
  try {
156
165
  const stats = await session.onebot.getGroupInfo(session.guildId, true);
157
- if ((config.minMembers ?? -1) >= 0 && stats.member_count < (config.minMembers ?? 0)) return `群成员不足 ${config.minMembers} 人`;
158
- if ((config.maxCapacity ?? -1) >= 0 && stats.max_member_count < (config.maxCapacity ?? 0)) return `群容量不足 ${config.maxCapacity} 人`;
166
+ if ((config.minMembers ?? -1) >= 0 && stats.member_count < (config.minMembers ?? 0)) {
167
+ if (config.debugMode) logger.info(`[规则判定] 成员检查: ${stats.member_count} < ${config.minMembers}`);
168
+ return `群成员不足 ${config.minMembers} 人`;
169
+ }
170
+ if ((config.maxCapacity ?? -1) >= 0 && stats.max_member_count < (config.maxCapacity ?? 0)) {
171
+ if (config.debugMode) logger.info(`[规则判定] 容量检查: ${stats.max_member_count} < ${config.maxCapacity}`);
172
+ return `群容量不足 ${config.maxCapacity} 人`;
173
+ }
159
174
  return true;
160
175
  } catch {
161
176
  return false;
@@ -190,12 +205,16 @@ function apply(ctx, config = {}) {
190
205
  }, "setupManual");
191
206
  const handleEvent = /* @__PURE__ */ __name(async (session, kind) => {
192
207
  try {
208
+ if (config.debugMode) logger.info(`[收到请求] 类型:${kind} 数据:${JSON.stringify(session.event?._data || {})}`);
193
209
  if (kind === "member") {
194
210
  const rule = config.verifyRules?.find((r) => r.guildId === session.guildId);
195
211
  if (rule) {
196
212
  const rawText = session.event?._data?.comment || "";
197
213
  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);
214
+ const keywordMatch = !rule.keyword || new RegExp(rule.keyword, "i").test(rawText);
215
+ const levelMatch = !stats || (stats.qqLevel ?? 0) >= rule.minLevel;
216
+ const isMatch = keywordMatch && levelMatch;
217
+ if (config.debugMode) logger.info(`[规则判定] ${rule.guildId}: 关键词=${keywordMatch}, 等级=${levelMatch}, 结果=${isMatch}`);
199
218
  if (isMatch && rule.action) {
200
219
  const isApprove = rule.action === "accept";
201
220
  await executeAction(session, kind, isApprove, isApprove ? "" : "命中拒绝规则,自动拒绝");
@@ -243,6 +262,7 @@ function apply(ctx, config = {}) {
243
262
  activeTask.messages.forEach((msg) => activeTasks.delete(msg));
244
263
  const isApprove = cmdMatch[1] === "y" || cmdMatch[1] === "通过";
245
264
  const extraInfo = cmdMatch[2]?.trim() || "";
265
+ if (config.debugMode) logger.info(`[人工回复] 用户 ${session.userId} 回复: ${cmdMatch[1]} 备注: ${extraInfo}`);
246
266
  const isSuccess = await executeAction(activeTask.session, activeTask.kind, isApprove, isApprove ? "" : extraInfo, isApprove && activeTask.kind === "friend" ? extraInfo : "");
247
267
  const replyText = isSuccess ? `已${isApprove ? "通过" : "拒绝"}该请求` : `处理请求失败`;
248
268
  await (targetType === "private" ? session.bot.sendPrivateMessage(targetId, replyText) : session.bot.sendMessage(targetId, replyText));
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.4",
4
+ "version": "1.0.5",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],