koishi-plugin-cat-raising 0.0.10 → 0.1.1

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 +20 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -73,19 +73,20 @@ function extractDateTime(line) {
73
73
  __name(extractDateTime, "extractDateTime");
74
74
  function extractRewards(line) {
75
75
  const rewards = [];
76
- const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(?:发\s*)?(\d+\.?\d*w?\+?)(?:神金|钻石|猫猫钻)?/gi;
76
+ const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(?:发\s*)?(\d+\.?\d*w\+?|\b\d{3,5}\b)(?:神金|钻石|猫猫钻)?/gi;
77
77
  let match;
78
78
  while ((match = regex.exec(line)) !== null) {
79
- if (line.includes("签到") && !line.match(/发|神金|猫猫钻/)) continue;
80
79
  const condition = match[1] ? `${match[1]}级灯牌` : "无限制";
81
- let amountStr = match[2].toLowerCase();
80
+ let amountStr = (match[2] || "").toLowerCase();
82
81
  let amount = 0;
83
82
  if (amountStr.includes("w")) {
84
83
  amount = parseFloat(amountStr.replace("w", "")) * 1e4;
85
84
  } else {
86
85
  amount = parseFloat(amountStr);
87
86
  }
88
- rewards.push({ amount, condition });
87
+ if (!isNaN(amount) && amount > 0) {
88
+ rewards.push({ amount, condition });
89
+ }
89
90
  }
90
91
  return rewards;
91
92
  }
@@ -112,13 +113,17 @@ __name(parseEvents, "parseEvents");
112
113
  function apply(ctx, config) {
113
114
  const forwardedHistory = [];
114
115
  const HISTORY_SIZE = 30;
115
- const REJECTION_KEYWORDS = ["签到"];
116
- const OVERRIDE_KEYWORDS = ["神金", "发"];
116
+ const REJECTION_KEYWORDS = ["签到", "打卡"];
117
+ const OVERRIDE_KEYWORDS = ["神金", "发", "掉落", "猫猫钻"];
117
118
  ctx.on("message", async (session) => {
118
119
  if (session.channelId !== config.monitorGroup) return;
119
120
  const originalMessageContent = session.content;
120
121
  const messageForChecks = session.stripped.content;
121
122
  const messageId = session.messageId;
123
+ const triggerRegex = /神金|发|掉落|猫猫钻|w|\b\d{3,5}\b/i;
124
+ if (!triggerRegex.test(messageForChecks)) {
125
+ return;
126
+ }
122
127
  const hasRejectionKeyword = REJECTION_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
123
128
  if (hasRejectionKeyword) {
124
129
  const hasOverrideKeyword = OVERRIDE_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
@@ -129,19 +134,22 @@ function apply(ctx, config) {
129
134
  }
130
135
  const roomIds = extractAllRoomIds(messageForChecks);
131
136
  if (roomIds.length > 1) {
132
- session.send(`检测到多个直播间号 (${roomIds.join(", ")}),为避免信息混淆,已停止处理。`);
133
137
  return;
134
138
  }
135
139
  const roomId = roomIds.length === 1 ? roomIds[0] : null;
136
140
  const parsedEvents = parseEvents(messageForChecks);
137
141
  if (!parsedEvents || !roomId) {
138
- if (messageForChecks.match(/神金|w|发|掉落|\d{4,}/)) {
139
- ctx.logger.info(`消息可能为神金信息但无法完整解析(缺少房间号或事件),已忽略: ${messageForChecks.substring(0, 50)}...`);
140
- }
142
+ return;
143
+ }
144
+ const strongContextRegex = /神金|发|掉落|猫猫钻|w/i;
145
+ const hasStrongContext = strongContextRegex.test(messageForChecks);
146
+ const hasTime = parsedEvents.some((event) => event.dateTime !== "时间未知");
147
+ if (!hasStrongContext && !hasTime) {
148
+ ctx.logger.info(`纯数字信息缺少时间,已忽略: ${messageForChecks.replace(/\s+/g, " ").substring(0, 50)}...`);
141
149
  return;
142
150
  }
143
151
  if (forwardedHistory.some((entry) => entry.originalContent === originalMessageContent)) {
144
- session.send("这个消息刚刚已经发过啦~");
152
+ session.send("看到啦看到啦,不要发那么多次嘛~");
145
153
  return;
146
154
  }
147
155
  let biliInfo = "";
@@ -166,6 +174,7 @@ function apply(ctx, config) {
166
174
  }
167
175
  } catch (error) {
168
176
  ctx.logger.warn(`获取直播间 ${roomId} 的B站信息失败: ${error.message}`);
177
+ return;
169
178
  }
170
179
  const forwardMessage = originalMessageContent + biliInfo;
171
180
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "0.0.10",
4
+ "version": "0.1.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [