koishi-plugin-bilibili-notify 3.0.0-alpha.7 → 3.0.0-alpha.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.
package/lib/biliAPI.js CHANGED
@@ -551,67 +551,172 @@ class BiliAPI extends koishi_1.Service {
551
551
  }
552
552
  }
553
553
  __decorate([
554
- (0, retry_1.default)()
554
+ (0, retry_1.default)({
555
+ attempts: 3,
556
+ onFailure(error, attempts) {
557
+ this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
558
+ },
559
+ })
555
560
  ], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
556
561
  __decorate([
557
- (0, retry_1.default)()
562
+ (0, retry_1.default)({
563
+ attempts: 3,
564
+ onFailure(error, attempts) {
565
+ this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
566
+ },
567
+ })
558
568
  ], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
559
569
  __decorate([
560
- (0, retry_1.default)()
570
+ (0, retry_1.default)({
571
+ attempts: 3,
572
+ onFailure(error, attempts) {
573
+ this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
574
+ },
575
+ })
561
576
  ], BiliAPI.prototype, "getServerUTCTime", null);
562
577
  __decorate([
563
- (0, retry_1.default)()
578
+ (0, retry_1.default)({
579
+ attempts: 3,
580
+ onFailure(error, attempts) {
581
+ this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
582
+ },
583
+ })
564
584
  ], BiliAPI.prototype, "getTimeNow", null);
565
585
  __decorate([
566
- (0, retry_1.default)()
586
+ (0, retry_1.default)({
587
+ attempts: 3,
588
+ onFailure(error, attempts) {
589
+ this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
590
+ },
591
+ })
567
592
  ], BiliAPI.prototype, "getAllGroup", null);
568
593
  __decorate([
569
- (0, retry_1.default)()
594
+ (0, retry_1.default)({
595
+ attempts: 3,
596
+ onFailure(error, attempts) {
597
+ this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
598
+ },
599
+ })
570
600
  ], BiliAPI.prototype, "removeUserFromGroup", null);
571
601
  __decorate([
572
- (0, retry_1.default)()
602
+ (0, retry_1.default)({
603
+ attempts: 3,
604
+ onFailure(error, attempts) {
605
+ this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
606
+ },
607
+ })
573
608
  ], BiliAPI.prototype, "copyUserToGroup", null);
574
609
  __decorate([
575
- (0, retry_1.default)()
610
+ (0, retry_1.default)({
611
+ attempts: 3,
612
+ onFailure(error, attempts) {
613
+ this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
614
+ },
615
+ })
576
616
  ], BiliAPI.prototype, "getUserSpaceDynamic", null);
577
617
  __decorate([
578
- (0, retry_1.default)()
618
+ (0, retry_1.default)({
619
+ attempts: 3,
620
+ onFailure(error, attempts) {
621
+ this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
622
+ },
623
+ })
579
624
  ], BiliAPI.prototype, "createGroup", null);
580
625
  __decorate([
581
- (0, retry_1.default)()
626
+ (0, retry_1.default)({
627
+ attempts: 3,
628
+ onFailure(error, attempts) {
629
+ this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
630
+ },
631
+ })
582
632
  ], BiliAPI.prototype, "getAllDynamic", null);
583
633
  __decorate([
584
- (0, retry_1.default)()
634
+ (0, retry_1.default)({
635
+ attempts: 3,
636
+ onFailure(error, attempts) {
637
+ this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
638
+ },
639
+ })
585
640
  ], BiliAPI.prototype, "hasNewDynamic", null);
586
641
  __decorate([
587
- (0, retry_1.default)()
642
+ (0, retry_1.default)({
643
+ attempts: 3,
644
+ onFailure(error, attempts) {
645
+ this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
646
+ },
647
+ })
588
648
  ], BiliAPI.prototype, "follow", null);
589
649
  __decorate([
590
- (0, retry_1.default)()
650
+ (0, retry_1.default)({
651
+ attempts: 3,
652
+ onFailure(error, attempts) {
653
+ this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
654
+ },
655
+ })
591
656
  ], BiliAPI.prototype, "getRelationGroupDetail", null);
592
657
  __decorate([
593
- (0, retry_1.default)()
658
+ (0, retry_1.default)({
659
+ attempts: 3,
660
+ onFailure(error, attempts) {
661
+ this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
662
+ },
663
+ })
594
664
  ], BiliAPI.prototype, "getCookieInfo", null);
595
665
  __decorate([
596
- (0, retry_1.default)()
666
+ (0, retry_1.default)({
667
+ attempts: 3,
668
+ onFailure(error, attempts) {
669
+ this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
670
+ },
671
+ })
597
672
  ], BiliAPI.prototype, "getUserInfo", null);
598
673
  __decorate([
599
- (0, retry_1.default)()
674
+ (0, retry_1.default)({
675
+ attempts: 3,
676
+ onFailure(error, attempts) {
677
+ this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
678
+ },
679
+ })
600
680
  ], BiliAPI.prototype, "getWbiKeys", null);
601
681
  __decorate([
602
- (0, retry_1.default)()
682
+ (0, retry_1.default)({
683
+ attempts: 3,
684
+ onFailure(error, attempts) {
685
+ this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
686
+ },
687
+ })
603
688
  ], BiliAPI.prototype, "getMyselfInfo", null);
604
689
  __decorate([
605
- (0, retry_1.default)()
690
+ (0, retry_1.default)({
691
+ attempts: 3,
692
+ onFailure(error, attempts) {
693
+ this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
694
+ },
695
+ })
606
696
  ], BiliAPI.prototype, "getLoginQRCode", null);
607
697
  __decorate([
608
- (0, retry_1.default)()
698
+ (0, retry_1.default)({
699
+ attempts: 3,
700
+ onFailure(error, attempts) {
701
+ this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
702
+ },
703
+ })
609
704
  ], BiliAPI.prototype, "getLoginStatus", null);
610
705
  __decorate([
611
- (0, retry_1.default)()
706
+ (0, retry_1.default)({
707
+ attempts: 3,
708
+ onFailure(error, attempts) {
709
+ this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
710
+ },
711
+ })
612
712
  ], BiliAPI.prototype, "getLiveRoomInfo", null);
613
713
  __decorate([
614
- (0, retry_1.default)()
714
+ (0, retry_1.default)({
715
+ attempts: 3,
716
+ onFailure(error, attempts) {
717
+ this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
718
+ },
719
+ })
615
720
  ], BiliAPI.prototype, "getMasterInfo", null);
616
721
  (function (BiliAPI) {
617
722
  BiliAPI.Config = koishi_1.Schema.object({
@@ -165,6 +165,8 @@ class ComRegister {
165
165
  }]);
166
166
  // 销毁定时器
167
167
  this.loginTimer();
168
+ // 订阅手动订阅中的订阅
169
+ await this.loadSubFromConfig(config.sub);
168
170
  // 订阅之前的订阅
169
171
  await this.loadSubFromDatabase();
170
172
  // 清除控制台通知
@@ -175,7 +177,6 @@ class ComRegister {
175
177
  await session.execute('bili show');
176
178
  // 开启cookies刷新检测
177
179
  ctx.ba.enableRefreshCookiesDetect();
178
- return;
179
180
  }
180
181
  }
181
182
  finally {
@@ -1392,6 +1393,8 @@ class ComRegister {
1392
1393
  // 定义弹幕存放数组
1393
1394
  const currentLiveDanmakuArr = [];
1394
1395
  const temporaryLiveDanmakuArr = [];
1396
+ // 定义开播状态
1397
+ let liveStatus = false;
1395
1398
  // 处理target
1396
1399
  // 定义channelIdArr总长度
1397
1400
  let channelIdArrLen = 0;
@@ -1469,6 +1472,9 @@ class ComRegister {
1469
1472
  temporaryLiveDanmakuArr.push(content);
1470
1473
  },
1471
1474
  onLiveStart: async () => {
1475
+ // 判断是否已经开播
1476
+ if (liveStatus)
1477
+ return;
1472
1478
  // 获取直播间信息
1473
1479
  const liveRoomInfo = await this.useLiveRoomInfo(roomId);
1474
1480
  // 获取主播信息
@@ -1480,7 +1486,7 @@ class ComRegister {
1480
1486
  .replace('-name', masterInfo.username)
1481
1487
  .replace('-time', await this.ctx.gi.getTimeDifference(liveTime))
1482
1488
  .replace('-link', `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
1483
- // 推送下播通知
1489
+ // 推送开播通知
1484
1490
  await this.sendLiveNotifyCard({
1485
1491
  username: masterInfo.username,
1486
1492
  userface: masterInfo.userface,
@@ -1492,6 +1498,8 @@ class ComRegister {
1492
1498
  // 开始直播,开启定时器
1493
1499
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1494
1500
  }
1501
+ // 设置开播状态为true
1502
+ liveStatus = true;
1495
1503
  },
1496
1504
  onLiveEnd: async () => {
1497
1505
  // 获取直播间消息
@@ -1515,6 +1523,8 @@ class ComRegister {
1515
1523
  pushAtTimeTimer();
1516
1524
  // 将推送定时器变量置空
1517
1525
  pushAtTimeTimer = null;
1526
+ // 将直播状态设置为false
1527
+ liveStatus = false;
1518
1528
  }
1519
1529
  };
1520
1530
  // 启动直播间弹幕监测
@@ -1543,6 +1553,8 @@ class ComRegister {
1543
1553
  // 开始直播,开启定时器
1544
1554
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1545
1555
  }
1556
+ // 设置直播状态为true
1557
+ liveStatus = true;
1546
1558
  }
1547
1559
  }
1548
1560
  subShow() {
@@ -1,2 +1,6 @@
1
- declare function Retry(attempts?: number, onFailure?: (error: Error, attempts: number) => Promise<void> | void): MethodDecorator;
1
+ interface RetryOptions {
2
+ attempts: number;
3
+ onFailure?: (error: Error, attempts: number) => Promise<void> | void;
4
+ }
5
+ declare function Retry(options?: RetryOptions): MethodDecorator;
2
6
  export default Retry;
@@ -1,20 +1,18 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- /* eslint-disable @typescript-eslint/ban-types */
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
- function Retry(attempts = 3, onFailure) {
3
+ function Retry(options = { attempts: 3 }) {
6
4
  return function (target, propertyKey, descriptor) {
7
5
  const originalMethod = descriptor.value;
8
6
  descriptor.value = async function (...args) {
9
7
  let lastError;
10
- for (let i = 0; i < attempts; i++) {
8
+ for (let i = 0; i < options.attempts; i++) {
11
9
  try {
12
10
  return await originalMethod.apply(this, args);
13
11
  }
14
12
  catch (error) {
15
13
  lastError = error;
16
- if (onFailure) {
17
- await onFailure.call(this, lastError, i + 1);
14
+ if (options.onFailure) {
15
+ await options.onFailure.call(this, lastError, i + 1);
18
16
  }
19
17
  }
20
18
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 高阶函数:为函数添加锁机制
3
+ * @param {Function} fn - 需要包装的原始函数
4
+ * @returns {Function} 带锁功能的函数
5
+ */
6
+ declare function withLock(fn: any): (...args: any[]) => void;
7
+ export default withLock;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 高阶函数:为函数添加锁机制
5
+ * @param {Function} fn - 需要包装的原始函数
6
+ * @returns {Function} 带锁功能的函数
7
+ */
8
+ function withLock(fn) {
9
+ // 判断是否是异步函数
10
+ const isAsync = fn.constructor.name === 'AsyncFunction';
11
+ // 定义锁标志
12
+ let locked = false;
13
+ // 判断是否为异步函数
14
+ if (isAsync) {
15
+ // 变为Promise
16
+ return function (...args) {
17
+ // 已加锁则跳过执行
18
+ if (locked)
19
+ return;
20
+ // 获取锁
21
+ locked = true;
22
+ // 将异步函数转为Promise链
23
+ Promise.resolve(fn(...args))
24
+ .catch(err => {
25
+ // 打印错误
26
+ console.error("Execution error:", err);
27
+ // 重新抛出错误
28
+ throw err;
29
+ })
30
+ .finally(() => {
31
+ // 确保释放锁
32
+ locked = false;
33
+ });
34
+ };
35
+ }
36
+ // 不是异步函数
37
+ return function (...args) {
38
+ // 已加锁则跳过执行
39
+ if (locked)
40
+ return;
41
+ // 获取锁
42
+ locked = true;
43
+ try {
44
+ // 执行函数
45
+ fn(...args);
46
+ }
47
+ catch (err) {
48
+ // 打印错误
49
+ console.error("Execution error:", err);
50
+ // 重新抛出错误
51
+ throw err;
52
+ }
53
+ finally {
54
+ // 无论成功失败都释放锁
55
+ locked = false;
56
+ }
57
+ };
58
+ }
59
+ exports.default = withLock;
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.7",
4
+ "version": "3.0.0-alpha.8",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -219,6 +219,7 @@
219
219
  - ver 3.0.0-alpha.5 修复:订阅的直播开播后,未开启弹幕推送会一直报错、主播开播推送下播卡片,直播时长显示NaN; 新增:直播检测模式选项; 优化:下播卡片内容
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
+ - ver 3.0.0-alpha.8 修复:开播通知连续发送两次,登录后不会加载手动订阅中的订阅; 优化:网络请求报错
222
223
 
223
224
  ## 交流群
224
225