koishi-plugin-cat-raising 1.3.0 → 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.
Files changed (2) hide show
  1. package/lib/index.js +66 -9
  2. 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*w\+?|\b\d{3,5}\b)(?:神金|钻石|猫猫钻)?/gi;
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 amount = amountStr.includes("w") ? parseFloat(amountStr.replace("w", "")) * 1e4 : parseFloat(amountStr);
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
  }
@@ -232,11 +234,32 @@ async function fetchBilibiliInfo(ctx, roomId) {
232
234
  "Origin": "https://live.bilibili.com",
233
235
  "Referer": `https://live.bilibili.com/${roomId}`
234
236
  };
235
- const roomInfo = await ctx.http.get(
236
- `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomId}`,
237
- { headers: commonHeaders }
238
- );
239
- const uid = roomInfo?.data?.uid;
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
+ }
240
263
  if (!uid) throw new Error("无法从房间信息中获取UID");
241
264
  const statsInfo = await ctx.http.get(
242
265
  `https://api.bilibili.com/x/space/navnum?mid=${uid}`,
@@ -250,7 +273,37 @@ async function fetchBilibiliInfo(ctx, roomId) {
250
273
  );
251
274
  const videoCount = statsInfo?.data?.video;
252
275
  if (videoCount === void 0) throw new Error("无法从空间信息中获取投稿数");
253
- return { videoCount };
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 };
254
307
  } catch (error) {
255
308
  const status = error?.response?.status;
256
309
  const dataMsg = error?.response?.data?.message;
@@ -293,7 +346,9 @@ function apply(ctx, config) {
293
346
  let helperMessageId;
294
347
  if (groupConfig.sendHelperMessages) {
295
348
  try {
349
+ const displayAnchor = biliInfo.anchorName;
296
350
  [helperMessageId] = await session.send(`直播间: ${roomId}
351
+ 主播: ${displayAnchor}
297
352
  投稿数: ${biliInfo.videoCount}`);
298
353
  } catch (e) {
299
354
  ctx.logger.warn("[消息] 发送辅助信息失败:", e);
@@ -305,9 +360,11 @@ function apply(ctx, config) {
305
360
  return;
306
361
  }
307
362
  try {
363
+ const displayAnchor = biliInfo.anchorName;
308
364
  const forwardMessage = `${session.content}
309
365
 
310
366
  ---
367
+ 主播: ${displayAnchor}
311
368
  投稿数: ${biliInfo.videoCount}`;
312
369
  const [forwardedMessageId] = config.isGroup ? await session.bot.sendMessage(config.targetQQ, forwardMessage) : await session.bot.sendPrivateMessage(config.targetQQ, forwardMessage);
313
370
  forwardedHistory.push({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [