koishi-plugin-cat-raising 1.2.1 → 1.3.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 +25 -10
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -226,20 +226,36 @@ async function sendBilibiliDanmaku(ctx, keyConfig, roomId, message) {
226
226
  __name(sendBilibiliDanmaku, "sendBilibiliDanmaku");
227
227
  async function fetchBilibiliInfo(ctx, roomId) {
228
228
  try {
229
- const roomInfo = await ctx.http.get(`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomId}`);
229
+ const commonHeaders = {
230
+ "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",
231
+ "Accept": "application/json, text/plain, */*",
232
+ "Origin": "https://live.bilibili.com",
233
+ "Referer": `https://live.bilibili.com/${roomId}`
234
+ };
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
+ );
230
239
  const uid = roomInfo?.data?.uid;
231
240
  if (!uid) throw new Error("无法从房间信息中获取UID");
232
- const [statsInfo, cardInfo] = await Promise.all([
233
- ctx.http.get(`https://api.bilibili.com/x/space/navnum?mid=${uid}`),
234
- ctx.http.get(`https://api.bilibili.com/x/web-interface/card?mid=${uid}`)
235
- ]);
241
+ const statsInfo = await ctx.http.get(
242
+ `https://api.bilibili.com/x/space/navnum?mid=${uid}`,
243
+ {
244
+ headers: {
245
+ ...commonHeaders,
246
+ Origin: "https://space.bilibili.com",
247
+ Referer: `https://space.bilibili.com/${uid}`
248
+ }
249
+ }
250
+ );
236
251
  const videoCount = statsInfo?.data?.video;
237
252
  if (videoCount === void 0) throw new Error("无法从空间信息中获取投稿数");
238
- const streamerName = cardInfo?.data?.card?.name;
239
- if (!streamerName) throw new Error("无法从账号信息中获取主播昵称");
240
- return { videoCount, streamerName };
253
+ return { videoCount };
241
254
  } catch (error) {
242
- ctx.logger.warn(`[API] 获取直播间 ${roomId} 的B站信息失败: ${error.message}`);
255
+ const status = error?.response?.status;
256
+ const dataMsg = error?.response?.data?.message;
257
+ const msg = dataMsg || error?.message || "未知错误";
258
+ ctx.logger.warn(`[API] 获取直播间 ${roomId} 的B站信息失败: ${msg}${status ? ` (HTTP ${status})` : ""}`);
243
259
  return null;
244
260
  }
245
261
  }
@@ -292,7 +308,6 @@ function apply(ctx, config) {
292
308
  const forwardMessage = `${session.content}
293
309
 
294
310
  ---
295
- 主播: ${biliInfo.streamerName}
296
311
  投稿数: ${biliInfo.videoCount}`;
297
312
  const [forwardedMessageId] = config.isGroup ? await session.bot.sendMessage(config.targetQQ, forwardMessage) : await session.bot.sendPrivateMessage(config.targetQQ, forwardMessage);
298
313
  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.2.1",
4
+ "version": "1.3.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [