koishi-plugin-bilibili-notify 3.0.0-alpha.8 → 3.0.0-alpha.9

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.
@@ -1398,6 +1398,9 @@ class ComRegister {
1398
1398
  // 处理target
1399
1399
  // 定义channelIdArr总长度
1400
1400
  let channelIdArrLen = 0;
1401
+ // 定义数据
1402
+ let liveRoomInfo;
1403
+ let masterInfo;
1401
1404
  // 找到频道/群组对应的
1402
1405
  const danmakuPushTargetArr = target.map(channel => {
1403
1406
  // 获取符合条件的target
@@ -1412,10 +1415,13 @@ class ComRegister {
1412
1415
  });
1413
1416
  // 定义定时推送函数
1414
1417
  const pushAtTimeFunc = async () => {
1415
- // 获取直播间信息
1416
- const liveRoomInfo = await this.useLiveRoomInfo(roomId);
1417
- // 获取主播信息
1418
- const masterInfo = await this.useMasterInfo(liveRoomInfo.uid);
1418
+ // 判断是否信息是否获取成功
1419
+ if (!(await useMasterAndLiveRoomInfo())) {
1420
+ // 未获取成功,直接返回
1421
+ return this.sendPrivateMsg('获取直播间信息失败,推送直播卡片失败!');
1422
+ }
1423
+ // 设置开播时间
1424
+ liveTime = liveRoomInfo.live_time;
1419
1425
  // 设置直播中消息
1420
1426
  const liveMsg = this.config.customLive ? this.config.customLive
1421
1427
  .replace('-name', masterInfo.username)
@@ -1439,10 +1445,44 @@ class ComRegister {
1439
1445
  temporaryLiveDanmakuArr.length = 0;
1440
1446
  }
1441
1447
  };
1442
- // 获取直播间信息
1443
- const liveRoomInfo = await this.useLiveRoomInfo(roomId);
1444
- // 获取主播信息
1445
- const masterInfo = await this.useMasterInfo(liveRoomInfo.uid);
1448
+ // 定义直播间信息获取函数
1449
+ const useMasterAndLiveRoomInfo = async () => {
1450
+ // 定义flag
1451
+ let flag = true;
1452
+ // 判断是否已存在值
1453
+ if (liveRoomInfo && masterInfo && liveTime) {
1454
+ // 所有值均已存在,不需要再获取信息
1455
+ return flag;
1456
+ }
1457
+ // 获取直播间信息
1458
+ liveRoomInfo = await this.useLiveRoomInfo(roomId).catch(() => {
1459
+ // 设置flag为false
1460
+ flag = false;
1461
+ // 返回空
1462
+ return null;
1463
+ });
1464
+ // 判断是否成功获取信息
1465
+ if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
1466
+ // 上一步未成功
1467
+ flag = false;
1468
+ // 返回flag
1469
+ return flag;
1470
+ }
1471
+ // 获取主播信息(需要满足flag为true,liveRoomInfo.uid有值)
1472
+ masterInfo = await this.useMasterInfo(liveRoomInfo.uid).catch(() => {
1473
+ // 设置flag为false
1474
+ flag = false;
1475
+ // 返回空
1476
+ return null;
1477
+ });
1478
+ // 返回信息
1479
+ return flag;
1480
+ };
1481
+ // 判断是否信息是否获取成功
1482
+ if (!(await useMasterAndLiveRoomInfo())) {
1483
+ // 未获取成功,直接返回
1484
+ return this.sendPrivateMsg('获取直播间信息失败,启动直播间弹幕检测失败!');
1485
+ }
1446
1486
  // 构建消息处理函数
1447
1487
  const handler = {
1448
1488
  onOpen: () => {
@@ -1475,10 +1515,11 @@ class ComRegister {
1475
1515
  // 判断是否已经开播
1476
1516
  if (liveStatus)
1477
1517
  return;
1478
- // 获取直播间信息
1479
- const liveRoomInfo = await this.useLiveRoomInfo(roomId);
1480
- // 获取主播信息
1481
- const masterInfo = await this.useMasterInfo(liveRoomInfo.uid);
1518
+ // 判断是否信息是否获取成功
1519
+ if (!(await useMasterAndLiveRoomInfo())) {
1520
+ // 未获取成功,直接返回
1521
+ return this.sendPrivateMsg('获取直播间信息失败,推送直播开播卡片失败!');
1522
+ }
1482
1523
  // 设置开播时间
1483
1524
  liveTime = liveRoomInfo.live_time;
1484
1525
  // 定义开播通知语
@@ -1502,10 +1543,11 @@ class ComRegister {
1502
1543
  liveStatus = true;
1503
1544
  },
1504
1545
  onLiveEnd: async () => {
1505
- // 获取直播间消息
1506
- const liveRoomInfo = await this.useLiveRoomInfo(roomId);
1507
- // 获取主播信息
1508
- const masterInfo = await this.useMasterInfo(liveRoomInfo.uid);
1546
+ // 判断是否信息是否获取成功
1547
+ if (!(await useMasterAndLiveRoomInfo())) {
1548
+ // 未获取成功,直接返回
1549
+ return this.sendPrivateMsg('获取直播间信息失败,推送直播下播卡片失败!');
1550
+ }
1509
1551
  // 更改直播时长
1510
1552
  liveRoomInfo.live_time = liveTime;
1511
1553
  // 定义下播播通知语
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.0.0-alpha.8",
4
+ "version": "3.0.0-alpha.9",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -220,6 +220,7 @@
220
220
  - ver 3.0.0-alpha.6 修复:连续发送两次直播中通知卡片; 优化:下播通知卡片
221
221
  - ver 3.0.0-alpha.7 修复:`ver 3.0.0-alpha.5` 未能解决的bug; 优化:ba代码结构
222
222
  - ver 3.0.0-alpha.8 修复:开播通知连续发送两次,登录后不会加载手动订阅中的订阅; 优化:网络请求报错
223
+ - ver 3.0.0-alpha.9 优化:加强直播推送对获取直播信息的错误处理
223
224
 
224
225
  ## 交流群
225
226