koishi-plugin-cat-raising 1.2.1 → 1.3.2
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 +86 -14
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -122,12 +122,14 @@ function extractDateTime(line) {
|
|
|
122
122
|
__name(extractDateTime, "extractDateTime");
|
|
123
123
|
function extractRewards(line) {
|
|
124
124
|
const rewards = [];
|
|
125
|
-
const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(?:发\s*)?(\d+\.?\d*
|
|
125
|
+
const regex = /(?:(\d{1,2})\s*级(?:灯牌)?\s*)?(?:发\s*)?(?:神金\s*)?(\d+\.?\d*\s*[wWkK万千]\+?|\b\d{3,5}\b)(?:\s*神金|\s*钻石|\s*猫猫钻)?/gi;
|
|
126
126
|
let match;
|
|
127
127
|
while ((match = regex.exec(line)) !== null) {
|
|
128
128
|
const condition = match[1] ? `${match[1]}级灯牌` : "无限制";
|
|
129
|
-
const amountStr = (match[2] || "").toLowerCase();
|
|
130
|
-
const
|
|
129
|
+
const amountStr = (match[2] || "").toLowerCase().replace(/\s+/g, "");
|
|
130
|
+
const base = parseFloat(amountStr.replace(/[^\d.]/g, ""));
|
|
131
|
+
const multiplier = /[w万]/i.test(amountStr) ? 1e4 : /[k千]/i.test(amountStr) ? 1e3 : 1;
|
|
132
|
+
const amount = base * multiplier;
|
|
131
133
|
if (!isNaN(amount) && amount > 0) {
|
|
132
134
|
rewards.push({ amount, condition });
|
|
133
135
|
}
|
|
@@ -226,20 +228,87 @@ async function sendBilibiliDanmaku(ctx, keyConfig, roomId, message) {
|
|
|
226
228
|
__name(sendBilibiliDanmaku, "sendBilibiliDanmaku");
|
|
227
229
|
async function fetchBilibiliInfo(ctx, roomId) {
|
|
228
230
|
try {
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
+
const commonHeaders = {
|
|
232
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
233
|
+
"Accept": "application/json, text/plain, */*",
|
|
234
|
+
"Origin": "https://live.bilibili.com",
|
|
235
|
+
"Referer": `https://live.bilibili.com/${roomId}`
|
|
236
|
+
};
|
|
237
|
+
let uid;
|
|
238
|
+
let anchorName = "未知";
|
|
239
|
+
try {
|
|
240
|
+
const infoByRoom = await ctx.http.get(
|
|
241
|
+
`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${roomId}`,
|
|
242
|
+
{ headers: commonHeaders }
|
|
243
|
+
);
|
|
244
|
+
uid = infoByRoom?.data?.room_info?.uid || uid;
|
|
245
|
+
anchorName = infoByRoom?.data?.anchor_info?.base_info?.uname || infoByRoom?.data?.anchor_info?.uname || anchorName;
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
if (!uid || anchorName === "未知") {
|
|
249
|
+
try {
|
|
250
|
+
const initInfo = await ctx.http.get(
|
|
251
|
+
`https://api.live.bilibili.com/room/v1/Room/room_init?id=${roomId}`,
|
|
252
|
+
{ headers: commonHeaders }
|
|
253
|
+
);
|
|
254
|
+
uid = initInfo?.data?.uid || uid;
|
|
255
|
+
const roomInfo2 = await ctx.http.get(
|
|
256
|
+
`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${initInfo?.data?.room_id || roomId}`,
|
|
257
|
+
{ headers: commonHeaders }
|
|
258
|
+
);
|
|
259
|
+
anchorName = roomInfo2?.data?.uname || anchorName;
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
231
263
|
if (!uid) throw new Error("无法从房间信息中获取UID");
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
264
|
+
const statsInfo = await ctx.http.get(
|
|
265
|
+
`https://api.bilibili.com/x/space/navnum?mid=${uid}`,
|
|
266
|
+
{
|
|
267
|
+
headers: {
|
|
268
|
+
...commonHeaders,
|
|
269
|
+
Origin: "https://space.bilibili.com",
|
|
270
|
+
Referer: `https://space.bilibili.com/${uid}`
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
);
|
|
236
274
|
const videoCount = statsInfo?.data?.video;
|
|
237
275
|
if (videoCount === void 0) throw new Error("无法从空间信息中获取投稿数");
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
276
|
+
try {
|
|
277
|
+
const anchorInfo = await ctx.http.get(
|
|
278
|
+
`https://api.bilibili.com/x/space/acc/info?mid=${uid}`,
|
|
279
|
+
{
|
|
280
|
+
headers: {
|
|
281
|
+
...commonHeaders,
|
|
282
|
+
Origin: "https://space.bilibili.com",
|
|
283
|
+
Referer: `https://space.bilibili.com/${uid}`
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
anchorName = anchorInfo?.data?.name || anchorName;
|
|
288
|
+
} catch {
|
|
289
|
+
}
|
|
290
|
+
if (anchorName === "未知") {
|
|
291
|
+
try {
|
|
292
|
+
const liveUser = await ctx.http.get(
|
|
293
|
+
`https://api.live.bilibili.com/live_user/v3/UserInfo/get_info?uid=${uid}`,
|
|
294
|
+
{
|
|
295
|
+
headers: {
|
|
296
|
+
...commonHeaders,
|
|
297
|
+
Origin: "https://live.bilibili.com",
|
|
298
|
+
Referer: `https://live.bilibili.com/${roomId}`
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
anchorName = liveUser?.data?.info?.uname || anchorName;
|
|
303
|
+
} catch {
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { videoCount, anchorName };
|
|
241
307
|
} catch (error) {
|
|
242
|
-
|
|
308
|
+
const status = error?.response?.status;
|
|
309
|
+
const dataMsg = error?.response?.data?.message;
|
|
310
|
+
const msg = dataMsg || error?.message || "未知错误";
|
|
311
|
+
ctx.logger.warn(`[API] 获取直播间 ${roomId} 的B站信息失败: ${msg}${status ? ` (HTTP ${status})` : ""}`);
|
|
243
312
|
return null;
|
|
244
313
|
}
|
|
245
314
|
}
|
|
@@ -277,7 +346,9 @@ function apply(ctx, config) {
|
|
|
277
346
|
let helperMessageId;
|
|
278
347
|
if (groupConfig.sendHelperMessages) {
|
|
279
348
|
try {
|
|
349
|
+
const displayAnchor = biliInfo.anchorName;
|
|
280
350
|
[helperMessageId] = await session.send(`直播间: ${roomId}
|
|
351
|
+
主播: ${displayAnchor}
|
|
281
352
|
投稿数: ${biliInfo.videoCount}`);
|
|
282
353
|
} catch (e) {
|
|
283
354
|
ctx.logger.warn("[消息] 发送辅助信息失败:", e);
|
|
@@ -289,10 +360,11 @@ function apply(ctx, config) {
|
|
|
289
360
|
return;
|
|
290
361
|
}
|
|
291
362
|
try {
|
|
363
|
+
const displayAnchor = biliInfo.anchorName;
|
|
292
364
|
const forwardMessage = `${session.content}
|
|
293
365
|
|
|
294
366
|
---
|
|
295
|
-
主播: ${
|
|
367
|
+
主播: ${displayAnchor}
|
|
296
368
|
投稿数: ${biliInfo.videoCount}`;
|
|
297
369
|
const [forwardedMessageId] = config.isGroup ? await session.bot.sendMessage(config.targetQQ, forwardMessage) : await session.bot.sendPrivateMessage(config.targetQQ, forwardMessage);
|
|
298
370
|
forwardedHistory.push({
|