koishi-plugin-cat-raising 0.0.7 → 0.0.8

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 +34 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -43,12 +43,41 @@ function apply(ctx, config) {
43
43
  if (session.channelId !== config.monitorGroup) return;
44
44
  if (!messageForChecks.includes("神金")) return;
45
45
  const numberRegex = /\d{6,15}/;
46
- if (!numberRegex.test(messageForChecks)) return;
46
+ const match = messageForChecks.match(numberRegex);
47
+ if (!match) return;
48
+ const roomId = match[0];
47
49
  if (forwardedMessageHistory.includes(originalMessageContent)) {
48
- session.send("🐱 - 检测到复读机行为,停止转发");
50
+ session.send("看到啦看到啦,不要发那么多次嘛~");
49
51
  return;
50
52
  }
51
- const forwardMessage = originalMessageContent;
53
+ let biliInfo = "";
54
+ try {
55
+ const roomInfoUrl = `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomId}`;
56
+ const roomInfo = await ctx.http.get(roomInfoUrl);
57
+ if (roomInfo.code !== 0 || !roomInfo.data || !roomInfo.data.uid) {
58
+ throw new Error("无法通过直播间号获取UID");
59
+ }
60
+ const uid = roomInfo.data.uid;
61
+ const statsUrl = `https://api.bilibili.com/x/space/navnum?mid=${uid}`;
62
+ const statsInfo = await ctx.http.get(statsUrl);
63
+ if (statsInfo.code !== 0 || !statsInfo.data || statsInfo.data.video === void 0) {
64
+ throw new Error("无法获取用户投稿数");
65
+ }
66
+ const videoCount = statsInfo.data.video;
67
+ biliInfo = `
68
+
69
+ ---
70
+ 用户投稿数: ${videoCount}`;
71
+ try {
72
+ await session.send(`直播间: ${roomId}
73
+ 用户投稿数: ${videoCount}`);
74
+ } catch (e) {
75
+ ctx.logger.warn(`向监听群 ${config.monitorGroup} 发送B站信息时失败:`, e);
76
+ }
77
+ } catch (error) {
78
+ ctx.logger.warn(`获取直播间 ${roomId} 的B站信息失败: ${error.message}`);
79
+ }
80
+ const forwardMessage = originalMessageContent + biliInfo;
52
81
  try {
53
82
  let forwardedMessageId;
54
83
  if (config.isGroup) {
@@ -65,7 +94,7 @@ function apply(ctx, config) {
65
94
  }
66
95
  } catch (error) {
67
96
  session.send("🐱 - 转发失败,请检查配置");
68
- console.error("转发失败:", error);
97
+ ctx.logger.error("转发失败:", error);
69
98
  }
70
99
  });
71
100
  ctx.on("message-deleted", async (session) => {
@@ -80,7 +109,7 @@ function apply(ctx, config) {
80
109
  }
81
110
  messageMap.delete(originalMessageId);
82
111
  } catch (error) {
83
- console.error("撤回转发消息失败:", error);
112
+ ctx.logger.error("撤回转发消息失败:", error);
84
113
  }
85
114
  }
86
115
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [