koishi-plugin-cat-raising 0.0.9 → 0.1.0

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 +23 -14
  2. 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,18 +73,20 @@ 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\+?|\b\d{3,5}\b)(?:神金|钻石|猫猫钻)?/gi;
80
77
  let match;
81
78
  while ((match = regex.exec(line)) !== null) {
82
79
  const condition = match[1] ? `${match[1]}级灯牌` : "无限制";
83
- let amountStr = match[2].toLowerCase();
80
+ let amountStr = (match[2] || "").toLowerCase();
84
81
  let amount = 0;
85
82
  if (amountStr.includes("w")) {
86
83
  amount = parseFloat(amountStr.replace("w", "")) * 1e4;
87
84
  } else {
88
- amount = parseInt(amountStr, 10);
85
+ amount = parseFloat(amountStr);
86
+ }
87
+ if (!isNaN(amount) && amount > 0) {
88
+ rewards.push({ amount, condition });
89
89
  }
90
- rewards.push({ amount, condition });
91
90
  }
92
91
  return rewards;
93
92
  }
@@ -114,27 +113,37 @@ __name(parseEvents, "parseEvents");
114
113
  function apply(ctx, config) {
115
114
  const forwardedHistory = [];
116
115
  const HISTORY_SIZE = 30;
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
+ }
127
+ const hasRejectionKeyword = REJECTION_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
128
+ if (hasRejectionKeyword) {
129
+ const hasOverrideKeyword = OVERRIDE_KEYWORDS.some((keyword) => messageForChecks.includes(keyword));
130
+ if (!hasOverrideKeyword) {
131
+ ctx.logger.info(`消息包含拒绝关键词且无覆盖词,已忽略: ${messageForChecks.substring(0, 50)}...`);
132
+ return;
133
+ }
134
+ }
122
135
  const roomIds = extractAllRoomIds(messageForChecks);
123
136
  if (roomIds.length > 1) {
137
+ session.send(`检测到多个直播间号 (${roomIds.join(", ")}),为避免信息混淆,已停止处理。`);
124
138
  return;
125
139
  }
126
- if (roomIds.length === 0) {
127
- }
128
140
  const roomId = roomIds.length === 1 ? roomIds[0] : null;
129
141
  const parsedEvents = parseEvents(messageForChecks);
130
142
  if (!parsedEvents || !roomId) {
131
- if (messageForChecks.match(/神金|w|发|掉落|\d{3,5}/)) {
132
- ctx.logger.info(`消息可能为神金信息但无法完整解析(缺少房间号或事件),已忽略: ${messageForChecks.substring(0, 50)}...`);
133
- }
134
143
  return;
135
144
  }
136
145
  if (forwardedHistory.some((entry) => entry.originalContent === originalMessageContent)) {
137
- session.send("看到啦看到啦,不要发那么多次嘛~");
146
+ session.send("这个消息刚刚已经发过啦~");
138
147
  return;
139
148
  }
140
149
  let biliInfo = "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "0.0.9",
4
+ "version": "0.1.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [