koishi-plugin-bilibili-notify 3.0.0-alpha.5 → 3.0.0-alpha.7

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
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -14,6 +20,7 @@ const tough_cookie_1 = require("tough-cookie");
14
20
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
15
21
  const jsdom_1 = require("jsdom");
16
22
  const luxon_1 = require("luxon");
23
+ const retry_1 = __importDefault(require("./utils/retry"));
17
24
  const mixinKeyEncTab = [
18
25
  46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
19
26
  33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
@@ -108,183 +115,113 @@ class BiliAPI extends koishi_1.Service {
108
115
  }
109
116
  // BA API
110
117
  async getTheUserWhoIsLiveStreaming() {
111
- try {
112
- // 获取直播间信息流密钥
113
- const { data: { live_users } } = await this.client.get(GET_LATEST_UPDATED_UPS);
114
- // 返回data
115
- return live_users;
116
- }
117
- catch (e) {
118
- throw new Error('网络异常,本次请求失败!');
119
- }
118
+ // 获取直播间信息流密钥
119
+ const { data: { live_users } } = await this.client.get(GET_LATEST_UPDATED_UPS);
120
+ // 返回data
121
+ return live_users;
120
122
  }
121
123
  async getLiveRoomInfoStreamKey(roomId) {
122
- try {
123
- // 获取直播间信息流密钥
124
- const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
125
- // 返回data
126
- return data;
127
- }
128
- catch (e) {
129
- throw new Error('网络异常,本次请求失败!');
130
- }
124
+ // 获取直播间信息流密钥
125
+ const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
126
+ // 返回data
127
+ return data;
131
128
  }
132
129
  async getServerUTCTime() {
133
- try {
134
- const { data } = await this.client.get(GET_SERVER_UTC_TIME);
135
- const regex = /Date\.UTC\((.*?)\)/;
136
- const match = data.match(regex);
137
- if (match) {
138
- const timestamp = new Function(`return Date.UTC(${match[1]})`)();
139
- return timestamp / 1000;
140
- }
141
- else {
142
- throw new Error('解析服务器时间失败!');
143
- }
130
+ const { data } = await this.client.get(GET_SERVER_UTC_TIME);
131
+ const regex = /Date\.UTC\((.*?)\)/;
132
+ const match = data.match(regex);
133
+ if (match) {
134
+ const timestamp = new Function(`return Date.UTC(${match[1]})`)();
135
+ return timestamp / 1000;
144
136
  }
145
- catch (e) {
146
- throw new Error('网络异常,本次请求失败!');
137
+ else {
138
+ throw new Error('解析服务器时间失败!');
147
139
  }
148
140
  }
149
141
  async getTimeNow() {
150
- try {
151
- const { data } = await this.client.get(GET_TIME_NOW);
152
- return data;
153
- }
154
- catch (e) {
155
- throw new Error('网络异常,本次请求失败!');
156
- }
142
+ const { data } = await this.client.get(GET_TIME_NOW);
143
+ return data;
157
144
  }
158
145
  async getAllGroup() {
159
- try {
160
- const { data } = await this.client.get(GET_ALL_GROUP);
161
- return data;
162
- }
163
- catch (e) {
164
- throw new Error('网络异常,本次请求失败!');
165
- }
146
+ const { data } = await this.client.get(GET_ALL_GROUP);
147
+ return data;
166
148
  }
167
149
  async removeUserFromGroup(mid) {
168
150
  // 获取csrf
169
151
  const csrf = this.getCSRF();
170
- try {
171
- // 将用户mid添加到groupId
172
- const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
173
- fids: mid,
174
- tagids: 0,
175
- csrf
176
- }, {
177
- headers: {
178
- 'Content-Type': 'application/x-www-form-urlencoded',
179
- }
180
- });
181
- return data;
182
- }
183
- catch (e) {
184
- throw new Error('网络异常,本次请求失败!');
185
- }
152
+ // 将用户mid添加到groupId
153
+ const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
154
+ fids: mid,
155
+ tagids: 0,
156
+ csrf
157
+ }, {
158
+ headers: {
159
+ 'Content-Type': 'application/x-www-form-urlencoded',
160
+ }
161
+ });
162
+ return data;
186
163
  }
187
164
  async copyUserToGroup(mid, groupId) {
188
165
  // 获取csrf
189
166
  const csrf = this.getCSRF();
190
- try {
191
- // 将用户mid添加到groupId
192
- const { data } = await this.client.post(COPY_USER_TO_GROUP, {
193
- fids: mid,
194
- tagids: groupId,
195
- csrf
196
- }, {
197
- headers: {
198
- 'Content-Type': 'application/x-www-form-urlencoded',
199
- }
200
- });
201
- return data;
202
- }
203
- catch (e) {
204
- throw new Error('网络异常,本次请求失败!');
205
- }
167
+ // 将用户mid添加到groupId
168
+ const { data } = await this.client.post(COPY_USER_TO_GROUP, {
169
+ fids: mid,
170
+ tagids: groupId,
171
+ csrf
172
+ }, {
173
+ headers: {
174
+ 'Content-Type': 'application/x-www-form-urlencoded',
175
+ }
176
+ });
177
+ return data;
206
178
  }
207
179
  async getUserSpaceDynamic(mid) {
208
- try {
209
- const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}?host_mid=${mid}`);
210
- return data;
211
- }
212
- catch (e) {
213
- throw new Error('网络异常,本次请求失败!');
214
- }
180
+ const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}?host_mid=${mid}`);
181
+ return data;
215
182
  }
216
183
  async createGroup(tag) {
217
- try {
218
- const { data } = await this.client.post(CREATE_GROUP, {
219
- tag,
220
- csrf: this.getCSRF()
221
- }, {
222
- headers: {
223
- 'Content-Type': 'application/x-www-form-urlencoded',
224
- }
225
- });
226
- return data;
227
- }
228
- catch (e) {
229
- throw new Error('网络异常,本次请求失败!');
230
- }
184
+ const { data } = await this.client.post(CREATE_GROUP, {
185
+ tag,
186
+ csrf: this.getCSRF()
187
+ }, {
188
+ headers: {
189
+ 'Content-Type': 'application/x-www-form-urlencoded',
190
+ }
191
+ });
192
+ return data;
231
193
  }
232
194
  async getAllDynamic(updateBaseline) {
233
195
  let url = GET_ALL_DYNAMIC_LIST;
234
196
  updateBaseline && (url += `?update_baseline=${updateBaseline}`);
235
- try {
236
- const { data } = await this.client.get(url);
237
- return data;
238
- }
239
- catch (e) {
240
- throw new Error('网络异常,本次请求失败!');
241
- }
197
+ const { data } = await this.client.get(url);
198
+ return data;
242
199
  }
243
200
  async hasNewDynamic(updateBaseline) {
244
- try {
245
- const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
246
- return data;
247
- }
248
- catch (e) {
249
- throw new Error('网络异常,本次请求失败!');
250
- }
201
+ const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
202
+ return data;
251
203
  }
252
204
  async follow(fid) {
253
- try {
254
- const { data } = await this.client.post(MODIFY_RELATION, {
255
- fid,
256
- act: 1,
257
- re_src: 11,
258
- csrf: this.getCSRF()
259
- }, {
260
- headers: {
261
- 'Content-Type': 'application/x-www-form-urlencoded',
262
- }
263
- });
264
- return data;
265
- }
266
- catch (e) {
267
- throw new Error('网络异常,本次请求失败!');
268
- }
205
+ const { data } = await this.client.post(MODIFY_RELATION, {
206
+ fid,
207
+ act: 1,
208
+ re_src: 11,
209
+ csrf: this.getCSRF()
210
+ }, {
211
+ headers: {
212
+ 'Content-Type': 'application/x-www-form-urlencoded',
213
+ }
214
+ });
215
+ return data;
269
216
  }
270
217
  async getRelationGroupDetail(tagid) {
271
- try {
272
- const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
273
- return data;
274
- }
275
- catch (e) {
276
- throw new Error('网络异常,本次请求失败!');
277
- }
218
+ const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
219
+ return data;
278
220
  }
279
221
  // Check if Token need refresh
280
222
  async getCookieInfo(refreshToken) {
281
- try {
282
- const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
283
- return data;
284
- }
285
- catch (e) {
286
- throw new Error('网络异常,本次请求失败!');
287
- }
223
+ const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
224
+ return data;
288
225
  }
289
226
  async getUserInfo(mid) {
290
227
  //如果为番剧出差的UID,则不从远程接口拉取数据,直接传回一段精简过的有效数据
@@ -292,15 +229,9 @@ class BiliAPI extends koishi_1.Service {
292
229
  console.log("检测到番剧出差UID,跳过远程用户接口访问");
293
230
  return bangumiTripData;
294
231
  }
295
- try {
296
- const wbi = await this.getWbi({ mid });
297
- const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
298
- return data;
299
- }
300
- catch (e) {
301
- console.warn(e);
302
- throw new Error('网络异常,本次请求失败!');
303
- }
232
+ const wbi = await this.getWbi({ mid });
233
+ const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
234
+ return data;
304
235
  }
305
236
  // 获取最新的 img_key 和 sub_key
306
237
  async getWbiKeys() {
@@ -312,49 +243,24 @@ class BiliAPI extends koishi_1.Service {
312
243
  };
313
244
  }
314
245
  async getMyselfInfo() {
315
- try {
316
- const { data } = await this.client.get(GET_MYSELF_INFO);
317
- return data;
318
- }
319
- catch (e) {
320
- throw new Error('网络异常,本次请求失败!');
321
- }
246
+ const { data } = await this.client.get(GET_MYSELF_INFO);
247
+ return data;
322
248
  }
323
249
  async getLoginQRCode() {
324
- try {
325
- const { data } = await this.client.get(GET_LOGIN_QRCODE);
326
- return data;
327
- }
328
- catch (e) {
329
- throw new Error('网络异常,本次请求失败!');
330
- }
250
+ const { data } = await this.client.get(GET_LOGIN_QRCODE);
251
+ return data;
331
252
  }
332
253
  async getLoginStatus(qrcodeKey) {
333
- try {
334
- const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
335
- return data;
336
- }
337
- catch (e) {
338
- throw new Error('网络异常,本次请求失败!');
339
- }
254
+ const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
255
+ return data;
340
256
  }
341
257
  async getLiveRoomInfo(roomId) {
342
- try {
343
- const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
344
- return data;
345
- }
346
- catch (e) {
347
- throw new Error('网络异常,本次请求失败!');
348
- }
258
+ const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
259
+ return data;
349
260
  }
350
261
  async getMasterInfo(mid) {
351
- try {
352
- const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
353
- return data;
354
- }
355
- catch (e) {
356
- throw new Error('网络异常,本次请求失败!');
357
- }
262
+ const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
263
+ return data;
358
264
  }
359
265
  disposeNotifier() { if (this.loginNotifier)
360
266
  this.loginNotifier.dispose(); }
@@ -644,6 +550,69 @@ class BiliAPI extends koishi_1.Service {
644
550
  // 没有问题,cookies已更新完成
645
551
  }
646
552
  }
553
+ __decorate([
554
+ (0, retry_1.default)()
555
+ ], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
556
+ __decorate([
557
+ (0, retry_1.default)()
558
+ ], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
559
+ __decorate([
560
+ (0, retry_1.default)()
561
+ ], BiliAPI.prototype, "getServerUTCTime", null);
562
+ __decorate([
563
+ (0, retry_1.default)()
564
+ ], BiliAPI.prototype, "getTimeNow", null);
565
+ __decorate([
566
+ (0, retry_1.default)()
567
+ ], BiliAPI.prototype, "getAllGroup", null);
568
+ __decorate([
569
+ (0, retry_1.default)()
570
+ ], BiliAPI.prototype, "removeUserFromGroup", null);
571
+ __decorate([
572
+ (0, retry_1.default)()
573
+ ], BiliAPI.prototype, "copyUserToGroup", null);
574
+ __decorate([
575
+ (0, retry_1.default)()
576
+ ], BiliAPI.prototype, "getUserSpaceDynamic", null);
577
+ __decorate([
578
+ (0, retry_1.default)()
579
+ ], BiliAPI.prototype, "createGroup", null);
580
+ __decorate([
581
+ (0, retry_1.default)()
582
+ ], BiliAPI.prototype, "getAllDynamic", null);
583
+ __decorate([
584
+ (0, retry_1.default)()
585
+ ], BiliAPI.prototype, "hasNewDynamic", null);
586
+ __decorate([
587
+ (0, retry_1.default)()
588
+ ], BiliAPI.prototype, "follow", null);
589
+ __decorate([
590
+ (0, retry_1.default)()
591
+ ], BiliAPI.prototype, "getRelationGroupDetail", null);
592
+ __decorate([
593
+ (0, retry_1.default)()
594
+ ], BiliAPI.prototype, "getCookieInfo", null);
595
+ __decorate([
596
+ (0, retry_1.default)()
597
+ ], BiliAPI.prototype, "getUserInfo", null);
598
+ __decorate([
599
+ (0, retry_1.default)()
600
+ ], BiliAPI.prototype, "getWbiKeys", null);
601
+ __decorate([
602
+ (0, retry_1.default)()
603
+ ], BiliAPI.prototype, "getMyselfInfo", null);
604
+ __decorate([
605
+ (0, retry_1.default)()
606
+ ], BiliAPI.prototype, "getLoginQRCode", null);
607
+ __decorate([
608
+ (0, retry_1.default)()
609
+ ], BiliAPI.prototype, "getLoginStatus", null);
610
+ __decorate([
611
+ (0, retry_1.default)()
612
+ ], BiliAPI.prototype, "getLiveRoomInfo", null);
613
+ __decorate([
614
+ (0, retry_1.default)()
615
+ ], BiliAPI.prototype, "getMasterInfo", null);
647
616
  (function (BiliAPI) {
648
617
  BiliAPI.Config = koishi_1.Schema.object({
649
618
  userAgent: koishi_1.Schema.string(),
@@ -439,23 +439,23 @@ class ComRegister {
439
439
  this.logger.error('bili sub指令 getMasterInfo() 发生了错误,错误为:' + e.message);
440
440
  return '订阅出错啦,请重试';
441
441
  }
442
+ const liveDetectModeSelector = {
443
+ API: async () => {
444
+ // 判断是否已开启直播检测
445
+ if (!this.liveDispose) { // 未开启直播检测
446
+ // 开启直播检测并保存销毁函数
447
+ this.liveDispose = await this.liveDetectWithAPI();
448
+ }
449
+ },
450
+ WS: async () => {
451
+ // 连接到服务器
452
+ await this.liveDetectWithListener(roomId, target);
453
+ }
454
+ };
442
455
  // 订阅直播
443
456
  if (liveMsg) {
444
457
  // 判断直播订阅方式
445
- switch (this.config.liveDetectMode) {
446
- case "API": {
447
- // 判断是否已开启直播检测
448
- if (!this.liveDispose) { // 未开启直播检测
449
- // 开启直播检测并保存销毁函数
450
- this.liveDispose = await this.liveDetectWithAPI();
451
- }
452
- break;
453
- }
454
- case "WS": {
455
- // 连接到服务器
456
- await this.liveDetectWithListener(roomId, target);
457
- }
458
- }
458
+ await liveDetectModeSelector[this.config.liveDetectMode]();
459
459
  // 发送订阅消息通知
460
460
  await session.send(`订阅${userData.info.uname}直播通知`);
461
461
  }
@@ -463,6 +463,7 @@ class ComRegister {
463
463
  if (dynamicMsg) {
464
464
  // 判断是否开启动态监测
465
465
  if (!this.dynamicDispose) {
466
+ // 开启动态监测
466
467
  this.enableDynamicDetect();
467
468
  }
468
469
  // 发送订阅消息通知
@@ -1392,9 +1393,15 @@ class ComRegister {
1392
1393
  const currentLiveDanmakuArr = [];
1393
1394
  const temporaryLiveDanmakuArr = [];
1394
1395
  // 处理target
1396
+ // 定义channelIdArr总长度
1397
+ let channelIdArrLen = 0;
1395
1398
  // 找到频道/群组对应的
1396
1399
  const danmakuPushTargetArr = target.map(channel => {
1400
+ // 获取符合条件的target
1397
1401
  const liveDanmakuArr = channel.channelIdArr.filter(channelId => channelId.liveDanmaku);
1402
+ // 将当前liveDanmakuArr的长度+到channelIdArrLen中
1403
+ channelIdArrLen += liveDanmakuArr.length;
1404
+ // 返回符合的target
1398
1405
  return {
1399
1406
  channelIdArr: liveDanmakuArr,
1400
1407
  platform: channel.platform
@@ -1422,7 +1429,7 @@ class ComRegister {
1422
1429
  // 定义弹幕推送函数
1423
1430
  const danmakuPushFunc = () => {
1424
1431
  // 判断数组是否有内容
1425
- if (danmakuPushTargetArr.length > 0 && temporaryLiveDanmakuArr.length > 0) {
1432
+ if (channelIdArrLen > 0 && temporaryLiveDanmakuArr.length > 0) {
1426
1433
  // 发送消息
1427
1434
  this.sendMsg(danmakuPushTargetArr, temporaryLiveDanmakuArr.join('\n'));
1428
1435
  // 将临时消息数组清空
@@ -1480,8 +1487,11 @@ class ComRegister {
1480
1487
  target,
1481
1488
  data: liveRoomInfo
1482
1489
  }, LiveType.StartBroadcasting, liveStartMsg);
1483
- // 开始直播,开启定时器
1484
- pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1490
+ // 判断定时器是否已开启
1491
+ if (!pushAtTimeTimer) {
1492
+ // 开始直播,开启定时器
1493
+ pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1494
+ }
1485
1495
  },
1486
1496
  onLiveEnd: async () => {
1487
1497
  // 获取直播间消息
@@ -1528,7 +1538,11 @@ class ComRegister {
1528
1538
  }, LiveType.LiveBroadcast, liveMsg);
1529
1539
  }
1530
1540
  // 正在直播,开启定时器
1531
- pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1541
+ // 判断定时器是否已开启
1542
+ if (!pushAtTimeTimer) {
1543
+ // 开始直播,开启定时器
1544
+ pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1000 * 60 * 60);
1545
+ }
1532
1546
  }
1533
1547
  }
1534
1548
  subShow() {
@@ -1728,23 +1742,24 @@ class ComRegister {
1728
1742
  // 发送提示
1729
1743
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1730
1744
  }
1731
- // 判断是否订阅直播
1732
- if (sub.live) {
1733
- // 判断直播订阅方式
1734
- switch (this.config.liveDetectMode) {
1735
- case "API": {
1736
- // 判断是否已开启直播检测
1737
- if (!this.liveDispose) { // 未开启直播检测
1738
- // 开启直播检测并保存销毁函数
1739
- this.liveDispose = await this.liveDetectWithAPI();
1740
- }
1741
- break;
1742
- }
1743
- case "WS": {
1744
- // 连接到服务器
1745
- await this.liveDetectWithListener(data.live_room.roomid, sub.target);
1745
+ //
1746
+ const liveDetectModeSelector = {
1747
+ API: async () => {
1748
+ // 判断是否已开启直播检测
1749
+ if (!this.liveDispose) { // 未开启直播检测
1750
+ // 开启直播检测并保存销毁函数
1751
+ this.liveDispose = await this.liveDetectWithAPI();
1746
1752
  }
1753
+ },
1754
+ WS: async () => {
1755
+ // 连接到服务器
1756
+ await this.liveDetectWithListener(data.live_room.roomid, sub.target);
1747
1757
  }
1758
+ };
1759
+ // 判断是否订阅直播
1760
+ if (sub.live) {
1761
+ // 启动直播监测
1762
+ await liveDetectModeSelector[this.config.liveDetectMode]();
1748
1763
  }
1749
1764
  }
1750
1765
  // 在B站中订阅该对象
@@ -1865,36 +1880,37 @@ class ComRegister {
1865
1880
  dynamic: sub.dynamic === 1 ? true : false,
1866
1881
  liveDispose: null
1867
1882
  };
1868
- // 判断是否订阅直播
1869
- if (sub.live) {
1870
- // 判断直播检测方式
1871
- switch (this.config.liveDetectMode) {
1872
- case "API": {
1873
- // 判断是否已开启直播检测
1874
- if (!this.liveDispose) { // 未开启直播检测
1875
- // 开启直播检测并保存销毁函数
1876
- this.liveDispose = await this.liveDetectWithAPI();
1877
- }
1878
- break;
1883
+ // 定义直播模式监测器
1884
+ const liveDetectModeSelector = {
1885
+ API: async () => {
1886
+ // 判断是否已开启直播检测
1887
+ if (!this.liveDispose) { // 未开启直播检测
1888
+ // 开启直播检测并保存销毁函数
1889
+ this.liveDispose = await this.liveDetectWithAPI();
1879
1890
  }
1880
- case "WS": {
1881
- // 判断订阅直播数是否超过限制
1882
- if (!this.config.unlockSubLimits && liveSubNum >= 3) {
1883
- // 将live改为false
1884
- subManagerItem.live = false;
1885
- // log
1886
- this.logger.warn(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
1887
- // 发送错误消息
1888
- await this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
1889
- }
1890
- else {
1891
- // 直播订阅数+1
1892
- liveSubNum++;
1893
- // 订阅直播,开始循环检测
1894
- this.liveDetectWithListener(sub.room_id, target);
1895
- }
1891
+ },
1892
+ WS: async () => {
1893
+ // 判断订阅直播数是否超过限制
1894
+ if (!this.config.unlockSubLimits && liveSubNum >= 3) {
1895
+ // 将live改为false
1896
+ subManagerItem.live = false;
1897
+ // log
1898
+ this.logger.warn(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
1899
+ // 发送错误消息
1900
+ await this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
1901
+ }
1902
+ else {
1903
+ // 直播订阅数+1
1904
+ liveSubNum++;
1905
+ // 订阅直播,开始循环检测
1906
+ await this.liveDetectWithListener(sub.room_id, target);
1896
1907
  }
1897
1908
  }
1909
+ };
1910
+ // 判断是否订阅直播
1911
+ if (sub.live) {
1912
+ // 启动直播监测
1913
+ await liveDetectModeSelector[this.config.liveDetectMode]();
1898
1914
  }
1899
1915
  // 保存新订阅对象
1900
1916
  this.subManager.push(subManagerItem);
@@ -176,7 +176,7 @@ class GenerateImg extends koishi_1.Service {
176
176
  </div>
177
177
  ${this.giConfig.hideDesc ? '' : `<p class="card-text">${data.description ? data.description : '这个主播很懒,什么都简介都没写'}</p>`}
178
178
  <p class="card-link">
179
- ${liveStatus !== 3 ? `<span>人气:${data.online > 10000 ? `${(data.online / 10000).toFixed(1)}万` : data.online}</span>` : ''}
179
+ <span>人气:${data.online > 10000 ? `${(data.online / 10000).toFixed(1)}万` : data.online}</span>
180
180
  <span>分区名称:${data.area_name}</span>
181
181
  </p>
182
182
  <p class="card-link">
@@ -1455,7 +1455,7 @@ class GenerateImg extends koishi_1.Service {
1455
1455
  const seconds = differenceInSeconds % 60;
1456
1456
  // 返回格式化的字符串
1457
1457
  return days ?
1458
- `${days} 天 ${hours}小时${minutes.toString().padStart(2, '0')}分${seconds.toString().padStart(2, '0')}秒` :
1458
+ `${days}天${hours}小时${minutes.toString().padStart(2, '0')}分${seconds.toString().padStart(2, '0')}秒` :
1459
1459
  `${hours}小时${minutes.toString().padStart(2, '0')}分${seconds.toString().padStart(2, '0')}秒`;
1460
1460
  }
1461
1461
  unixTimestampToString(timestamp) {
@@ -0,0 +1,2 @@
1
+ declare function Retry(attempts?: number, onFailure?: (error: Error, attempts: number) => Promise<void> | void): MethodDecorator;
2
+ export default Retry;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /* eslint-disable @typescript-eslint/ban-types */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ function Retry(attempts = 3, onFailure) {
6
+ return function (target, propertyKey, descriptor) {
7
+ const originalMethod = descriptor.value;
8
+ descriptor.value = async function (...args) {
9
+ let lastError;
10
+ for (let i = 0; i < attempts; i++) {
11
+ try {
12
+ return await originalMethod.apply(this, args);
13
+ }
14
+ catch (error) {
15
+ lastError = error;
16
+ if (onFailure) {
17
+ await onFailure.call(this, lastError, i + 1);
18
+ }
19
+ }
20
+ }
21
+ throw lastError;
22
+ };
23
+ return descriptor;
24
+ };
25
+ }
26
+ exports.default = Retry;
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.5",
4
+ "version": "3.0.0-alpha.7",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -217,6 +217,8 @@
217
217
  - ver 3.0.0-alpha.3 修复:未开启弹幕推送也不会推送直播通知卡片
218
218
  - ver 3.0.0-alpha.4 修复:使用了手动订阅,数据库中的订阅不会加载
219
219
  - ver 3.0.0-alpha.5 修复:订阅的直播开播后,未开启弹幕推送会一直报错、主播开播推送下播卡片,直播时长显示NaN; 新增:直播检测模式选项; 优化:下播卡片内容
220
+ - ver 3.0.0-alpha.6 修复:连续发送两次直播中通知卡片; 优化:下播通知卡片
221
+ - ver 3.0.0-alpha.7 修复:`ver 3.0.0-alpha.5` 未能解决的bug; 优化:ba代码结构
220
222
 
221
223
  ## 交流群
222
224