koishi-plugin-cat-raising 0.0.9 → 0.0.10
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 +17 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -36,15 +36,12 @@ function extractAllRoomIds(text) {
|
|
|
36
36
|
const patterns = [
|
|
37
37
|
/(?:播间号|房间号|直播间)[::\s]*(\d{6,15})/g,
|
|
38
38
|
/\b(\d{8,15})\b/g
|
|
39
|
-
// 独立的8位以上数字
|
|
40
39
|
];
|
|
41
40
|
const foundIds = /* @__PURE__ */ new Set();
|
|
42
41
|
for (const pattern of patterns) {
|
|
43
42
|
const matches = text.matchAll(pattern);
|
|
44
43
|
for (const match of matches) {
|
|
45
|
-
if (match[1])
|
|
46
|
-
foundIds.add(match[1]);
|
|
47
|
-
}
|
|
44
|
+
if (match[1]) foundIds.add(match[1]);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
return Array.from(foundIds);
|
|
@@ -76,16 +73,17 @@ function extractDateTime(line) {
|
|
|
76
73
|
__name(extractDateTime, "extractDateTime");
|
|
77
74
|
function extractRewards(line) {
|
|
78
75
|
const rewards = [];
|
|
79
|
-
const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(\d+\.?\d*w?\+?)(?:神金|钻石|猫猫钻)?/gi;
|
|
76
|
+
const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(?:发\s*)?(\d+\.?\d*w?\+?)(?:神金|钻石|猫猫钻)?/gi;
|
|
80
77
|
let match;
|
|
81
78
|
while ((match = regex.exec(line)) !== null) {
|
|
79
|
+
if (line.includes("签到") && !line.match(/发|神金|猫猫钻/)) continue;
|
|
82
80
|
const condition = match[1] ? `${match[1]}级灯牌` : "无限制";
|
|
83
81
|
let amountStr = match[2].toLowerCase();
|
|
84
82
|
let amount = 0;
|
|
85
83
|
if (amountStr.includes("w")) {
|
|
86
84
|
amount = parseFloat(amountStr.replace("w", "")) * 1e4;
|
|
87
85
|
} else {
|
|
88
|
-
amount =
|
|
86
|
+
amount = parseFloat(amountStr);
|
|
89
87
|
}
|
|
90
88
|
rewards.push({ amount, condition });
|
|
91
89
|
}
|
|
@@ -114,27 +112,36 @@ __name(parseEvents, "parseEvents");
|
|
|
114
112
|
function apply(ctx, config) {
|
|
115
113
|
const forwardedHistory = [];
|
|
116
114
|
const HISTORY_SIZE = 30;
|
|
115
|
+
const REJECTION_KEYWORDS = ["签到"];
|
|
116
|
+
const OVERRIDE_KEYWORDS = ["神金", "发"];
|
|
117
117
|
ctx.on("message", async (session) => {
|
|
118
118
|
if (session.channelId !== config.monitorGroup) return;
|
|
119
119
|
const originalMessageContent = session.content;
|
|
120
120
|
const messageForChecks = session.stripped.content;
|
|
121
121
|
const messageId = session.messageId;
|
|
122
|
+
const hasRejectionKeyword = REJECTION_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
|
|
123
|
+
if (hasRejectionKeyword) {
|
|
124
|
+
const hasOverrideKeyword = OVERRIDE_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
|
|
125
|
+
if (!hasOverrideKeyword) {
|
|
126
|
+
ctx.logger.info(`消息包含拒绝关键词且无覆盖词,已忽略: ${messageForChecks.substring(0, 50)}...`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
122
130
|
const roomIds = extractAllRoomIds(messageForChecks);
|
|
123
131
|
if (roomIds.length > 1) {
|
|
132
|
+
session.send(`检测到多个直播间号 (${roomIds.join(", ")}),为避免信息混淆,已停止处理。`);
|
|
124
133
|
return;
|
|
125
134
|
}
|
|
126
|
-
if (roomIds.length === 0) {
|
|
127
|
-
}
|
|
128
135
|
const roomId = roomIds.length === 1 ? roomIds[0] : null;
|
|
129
136
|
const parsedEvents = parseEvents(messageForChecks);
|
|
130
137
|
if (!parsedEvents || !roomId) {
|
|
131
|
-
if (messageForChecks.match(/神金|w|发|掉落|\d{
|
|
138
|
+
if (messageForChecks.match(/神金|w|发|掉落|\d{4,}/)) {
|
|
132
139
|
ctx.logger.info(`消息可能为神金信息但无法完整解析(缺少房间号或事件),已忽略: ${messageForChecks.substring(0, 50)}...`);
|
|
133
140
|
}
|
|
134
141
|
return;
|
|
135
142
|
}
|
|
136
143
|
if (forwardedHistory.some((entry) => entry.originalContent === originalMessageContent)) {
|
|
137
|
-
session.send("
|
|
144
|
+
session.send("这个消息刚刚已经发过啦~");
|
|
138
145
|
return;
|
|
139
146
|
}
|
|
140
147
|
let biliInfo = "";
|