koishi-plugin-onebot-verifier 1.0.5 → 1.0.6
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 +7 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -130,7 +130,7 @@ function apply(ctx, config = {}) {
|
|
|
130
130
|
}, "sendNotice");
|
|
131
131
|
const checkCriteria = /* @__PURE__ */ __name(async (session, kind) => {
|
|
132
132
|
const rawText = session.event?._data?.comment || "";
|
|
133
|
-
const cleanLines = rawText.split(/[\r\n]+/).map((s) => s.trim()).filter((s) => /^(
|
|
133
|
+
const cleanLines = rawText.split(/[\r\n]+/).map((s) => s.trim()).filter((s) => /^(回答|答案)[::]/i.test(s)).map((s) => s.replace(/^(回答|答案)[::]\s*/i, ""));
|
|
134
134
|
const verifyText = cleanLines.length > 0 ? cleanLines.join("\n") : rawText;
|
|
135
135
|
if (kind === "friend") {
|
|
136
136
|
try {
|
|
@@ -155,7 +155,7 @@ function apply(ctx, config = {}) {
|
|
|
155
155
|
try {
|
|
156
156
|
const userData = session.userId ? await ctx.database.getUser(session.platform, session.userId) : null;
|
|
157
157
|
if (userData && userData.authority > 1) {
|
|
158
|
-
if (config.debugMode) logger.info(`[规则匹配]
|
|
158
|
+
if (config.debugMode) logger.info(`[规则匹配] 白名单: ${userData.authority}`);
|
|
159
159
|
return true;
|
|
160
160
|
}
|
|
161
161
|
} catch {
|
|
@@ -205,13 +205,15 @@ function apply(ctx, config = {}) {
|
|
|
205
205
|
}, "setupManual");
|
|
206
206
|
const handleEvent = /* @__PURE__ */ __name(async (session, kind) => {
|
|
207
207
|
try {
|
|
208
|
-
if (config.debugMode) logger.info(`[收到请求]
|
|
208
|
+
if (config.debugMode) logger.info(`[收到请求] 类型: ${kind} 数据:${JSON.stringify(session.event?._data || {})}`);
|
|
209
209
|
if (kind === "member") {
|
|
210
|
-
const rule = config.verifyRules?.find((r) => r.guildId === session.guildId);
|
|
210
|
+
const rule = config.verifyRules?.find((r) => String(r.guildId) === String(session.guildId));
|
|
211
211
|
if (rule) {
|
|
212
212
|
const rawText = session.event?._data?.comment || "";
|
|
213
|
+
const cleanLines = rawText.split(/[\r\n]+/).map((s) => s.trim()).filter((s) => /^(回答|答案)[::]/i.test(s)).map((s) => s.replace(/^(回答|答案)[::]\s*/i, ""));
|
|
214
|
+
const verifyText = cleanLines.length > 0 ? cleanLines.join("\n") : rawText;
|
|
213
215
|
const stats = (rule.minLevel ?? -1) >= 0 && session.onebot && session.userId ? await session.onebot.getStrangerInfo(session.userId, true).catch(() => ({})) : null;
|
|
214
|
-
const keywordMatch = !rule.keyword || new RegExp(rule.keyword, "i").test(
|
|
216
|
+
const keywordMatch = !rule.keyword || new RegExp(rule.keyword, "i").test(verifyText);
|
|
215
217
|
const levelMatch = !stats || (stats.qqLevel ?? 0) >= rule.minLevel;
|
|
216
218
|
const isMatch = keywordMatch && levelMatch;
|
|
217
219
|
if (config.debugMode) logger.info(`[规则判定] ${rule.guildId}: 关键词=${keywordMatch}, 等级=${levelMatch}, 结果=${isMatch}`);
|