koishi-plugin-cat-raising 0.1.3 → 0.1.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.d.ts +1 -0
- package/lib/index.js +34 -17
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -30,7 +30,9 @@ var name = "cat-raising";
|
|
|
30
30
|
var Config = import_koishi.Schema.object({
|
|
31
31
|
targetQQ: import_koishi.Schema.string().description("目标QQ号或QQ群号").required(),
|
|
32
32
|
isGroup: import_koishi.Schema.boolean().description("是否为QQ群").default(false),
|
|
33
|
-
monitorGroup: import_koishi.Schema.string().description("监听的群号(只检测此群的消息)").required()
|
|
33
|
+
monitorGroup: import_koishi.Schema.string().description("监听的群号(只检测此群的消息)").required(),
|
|
34
|
+
// [核心改动 2] 添加配置项的UI描述
|
|
35
|
+
historySize: import_koishi.Schema.number().description("防复读历史记录大小 (记录最近N条转发信息,防止短期内对同一直播间的同一活动重复转发)").default(30).min(5).max(100)
|
|
34
36
|
});
|
|
35
37
|
function extractAllRoomIds(text) {
|
|
36
38
|
const patterns = [
|
|
@@ -55,9 +57,18 @@ function extractDateTime(line) {
|
|
|
55
57
|
match = line.match(/(\d{1,2}\s*月\s*(?:上|中|下)旬)/);
|
|
56
58
|
if (match) return match[1];
|
|
57
59
|
match = line.match(/(\d{1,2})[::.点时]\s*(\d{1,2})/);
|
|
58
|
-
if (match
|
|
60
|
+
if (match && match[2]) {
|
|
61
|
+
const hour = match[1].padStart(2, "0");
|
|
62
|
+
const minute = match[2].padStart(2, "0");
|
|
63
|
+
return `${hour}:${minute}`;
|
|
64
|
+
}
|
|
59
65
|
match = line.match(/(\d{1,2})\s*点\s*半/);
|
|
60
66
|
if (match) return `${match[1].padStart(2, "0")}:30`;
|
|
67
|
+
match = line.match(/\b(\d{1,2})\s*[.点时](?!\d)/);
|
|
68
|
+
if (match && match[1]) {
|
|
69
|
+
const hour = match[1].padStart(2, "0");
|
|
70
|
+
return `${hour}:00`;
|
|
71
|
+
}
|
|
61
72
|
match = line.match(/(\d{1,2})\s*分/);
|
|
62
73
|
if (match) {
|
|
63
74
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -94,25 +105,30 @@ __name(extractRewards, "extractRewards");
|
|
|
94
105
|
function parseEvents(text) {
|
|
95
106
|
const lines = text.split("\n").filter((line) => line.trim() !== "");
|
|
96
107
|
const events = [];
|
|
97
|
-
let
|
|
108
|
+
let globalDateTime = null;
|
|
98
109
|
for (const line of lines) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
if (foundRewards.length > 0) {
|
|
105
|
-
const eventTime = currentDateTime || "时间未知";
|
|
106
|
-
events.push({ dateTime: eventTime, rewards: foundRewards });
|
|
107
|
-
if (foundDateTime) currentDateTime = null;
|
|
110
|
+
const timeInLine = extractDateTime(line);
|
|
111
|
+
if (timeInLine) {
|
|
112
|
+
globalDateTime = timeInLine;
|
|
113
|
+
break;
|
|
108
114
|
}
|
|
109
115
|
}
|
|
116
|
+
const allRewards = [];
|
|
117
|
+
for (const line of lines) {
|
|
118
|
+
const rewardsInLine = extractRewards(line);
|
|
119
|
+
allRewards.push(...rewardsInLine);
|
|
120
|
+
}
|
|
121
|
+
if (allRewards.length > 0) {
|
|
122
|
+
events.push({
|
|
123
|
+
dateTime: globalDateTime || "时间未知",
|
|
124
|
+
rewards: allRewards
|
|
125
|
+
});
|
|
126
|
+
}
|
|
110
127
|
return events.length > 0 ? events : null;
|
|
111
128
|
}
|
|
112
129
|
__name(parseEvents, "parseEvents");
|
|
113
130
|
function apply(ctx, config) {
|
|
114
131
|
const forwardedHistory = [];
|
|
115
|
-
const HISTORY_SIZE = 10;
|
|
116
132
|
const REJECTION_KEYWORDS = ["签到", "打卡"];
|
|
117
133
|
const OVERRIDE_KEYWORDS = ["神金", "发"];
|
|
118
134
|
ctx.on("message", async (session) => {
|
|
@@ -148,7 +164,8 @@ function apply(ctx, config) {
|
|
|
148
164
|
ctx.logger.info(`纯数字信息缺少时间,已忽略: ${messageForChecks.replace(/\s+/g, " ").substring(0, 50)}...`);
|
|
149
165
|
return;
|
|
150
166
|
}
|
|
151
|
-
|
|
167
|
+
const currentDateTime = parsedEvents[0].dateTime;
|
|
168
|
+
if (forwardedHistory.some((entry) => entry.roomId === roomId && entry.dateTime === currentDateTime)) {
|
|
152
169
|
session.send(`看到啦看到啦,不要发那么多次嘛~`);
|
|
153
170
|
return;
|
|
154
171
|
}
|
|
@@ -190,11 +207,11 @@ function apply(ctx, config) {
|
|
|
190
207
|
originalMessageId: messageId,
|
|
191
208
|
forwardedMessageId,
|
|
192
209
|
originalContent: originalMessageContent,
|
|
193
|
-
roomId
|
|
194
|
-
|
|
210
|
+
roomId,
|
|
211
|
+
dateTime: currentDateTime
|
|
195
212
|
};
|
|
196
213
|
forwardedHistory.push(newEntry);
|
|
197
|
-
if (forwardedHistory.length >
|
|
214
|
+
if (forwardedHistory.length > config.historySize) {
|
|
198
215
|
forwardedHistory.shift();
|
|
199
216
|
}
|
|
200
217
|
} catch (error) {
|