koishi-plugin-onebot-verifier 1.0.7 → 1.0.8
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.js +14 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -222,21 +222,23 @@ function apply(ctx, config = {}) {
|
|
|
222
222
|
try {
|
|
223
223
|
if (config.debugMode) logger.info(`[收到请求] 类型: ${kind} 数据:${JSON.stringify(session.event?._data || {})}`);
|
|
224
224
|
if (kind === "member") {
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
225
|
+
const rules = config.verifyRules?.filter((r) => String(r.guildId) === String(session.guildId)) || [];
|
|
226
|
+
if (rules.length > 0) {
|
|
227
227
|
const rawText = session.event?._data?.comment || "";
|
|
228
228
|
const cleanLines = rawText.split(/[\r\n]+/).map((s) => s.trim()).filter((s) => /^(回答|答案)[::]/i.test(s)).map((s) => s.replace(/^(回答|答案)[::]\s*/i, ""));
|
|
229
229
|
const verifyText = cleanLines.length > 0 ? cleanLines.join("\n") : rawText;
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
230
|
+
for (const rule of rules) {
|
|
231
|
+
const stats = (rule.minLevel ?? -1) >= 0 && session.onebot && session.userId ? await session.onebot.getStrangerInfo(session.userId, true).catch(() => ({})) : null;
|
|
232
|
+
const keywordMatch = !rule.keyword || new RegExp(rule.keyword, "i").test(verifyText);
|
|
233
|
+
const levelMatch = !stats || (stats.qqLevel ?? 0) >= rule.minLevel;
|
|
234
|
+
const isMatch = keywordMatch && levelMatch;
|
|
235
|
+
if (config.debugMode) logger.info(`[规则判定] ${rule.guildId}: 关键词="${rule.keyword}"=${keywordMatch}; 等级="${rule.minLevel}"=${levelMatch}`);
|
|
236
|
+
if (isMatch && rule.action) {
|
|
237
|
+
const isApprove = rule.action === "accept";
|
|
238
|
+
await executeAction(session, kind, isApprove, isApprove ? "" : "命中拒绝规则,自动拒绝");
|
|
239
|
+
await sendNotice(session, kind, isApprove ? "auto_pass" : "auto_reject");
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
244
|
return await setupManual(session, kind);
|