koishi-plugin-bilibili-notify 3.2.1-alpha.8 → 3.2.1-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.
package/lib/biliAPI.d.ts CHANGED
@@ -11,6 +11,7 @@ declare class BiliAPI extends Service {
11
11
  static inject: string[];
12
12
  jar: CookieJar;
13
13
  client: AxiosInstance;
14
+ cacheable: any;
14
15
  apiConfig: BiliAPI.Config;
15
16
  loginData: any;
16
17
  loginNotifier: Notifier;
@@ -62,7 +63,7 @@ declare class BiliAPI extends Service {
62
63
  cookies: any;
63
64
  refresh_token: string;
64
65
  }>;
65
- getCSRF(): string;
66
+ getCSRF(): any;
66
67
  loadCookiesFromDatabase(): Promise<void>;
67
68
  enableRefreshCookiesDetect(): void;
68
69
  checkIfTokenNeedRefresh(refreshToken: string, csrf: string, times?: number): Promise<void>;
package/lib/biliAPI.js CHANGED
@@ -1,17 +1,22 @@
1
+ "use strict";
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
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;
5
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
7
  };
7
- import { Schema, Service } from "koishi";
8
- import md5 from "md5";
9
- import crypto from "node:crypto";
10
- import axios from "axios";
11
- import { CookieJar, Cookie } from "tough-cookie";
12
- import { wrapper } from "axios-cookiejar-support";
13
- import { JSDOM } from "jsdom";
14
- import { Retry } from "./utils";
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const koishi_1 = require("koishi");
13
+ const md5_1 = __importDefault(require("md5"));
14
+ const node_crypto_1 = __importDefault(require("node:crypto"));
15
+ const axios_1 = __importDefault(require("axios"));
16
+ const tough_cookie_1 = require("tough-cookie");
17
+ const axios_cookiejar_support_1 = require("axios-cookiejar-support");
18
+ const jsdom_1 = require("jsdom");
19
+ const utils_1 = require("./utils");
15
20
  const mixinKeyEncTab = [
16
21
  46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
17
22
  33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61,
@@ -44,10 +49,12 @@ const GET_RELATION_GROUP_DETAIL = "https://api.bilibili.com/x/relation/tag";
44
49
  // 直播
45
50
  const GET_LIVE_ROOM_INFO_STREAM_KEY = "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo";
46
51
  const GET_LIVE_ROOMS_INFO = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids";
47
- class BiliAPI extends Service {
52
+ class BiliAPI extends koishi_1.Service {
48
53
  static inject = ["database", "notifier"];
49
54
  jar;
50
55
  client;
56
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
57
+ cacheable;
51
58
  apiConfig;
52
59
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
53
60
  loginData;
@@ -85,7 +92,7 @@ class BiliAPI extends Service {
85
92
  return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
86
93
  })
87
94
  .join("&");
88
- const wbi_sign = md5(query + mixin_key); // 计算 w_rid
95
+ const wbi_sign = (0, md5_1.default)(query + mixin_key); // 计算 w_rid
89
96
  return `${query}&w_rid=${wbi_sign}`;
90
97
  }
91
98
  async getWbi(params) {
@@ -96,8 +103,8 @@ class BiliAPI extends Service {
96
103
  return query;
97
104
  }
98
105
  encrypt(text) {
99
- const iv = crypto.randomBytes(16);
100
- const cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
106
+ const iv = node_crypto_1.default.randomBytes(16);
107
+ const cipher = node_crypto_1.default.createCipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
101
108
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
102
109
  return `${iv.toString("hex")}:${encrypted.toString("hex")}`;
103
110
  }
@@ -105,7 +112,7 @@ class BiliAPI extends Service {
105
112
  const textParts = text.split(":");
106
113
  const iv = Buffer.from(textParts.shift(), "hex");
107
114
  const encryptedText = Buffer.from(textParts.join(":"), "hex");
108
- const decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
115
+ const decipher = node_crypto_1.default.createDecipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
109
116
  const decrypted = Buffer.concat([
110
117
  decipher.update(encryptedText),
111
118
  decipher.final(),
@@ -282,9 +289,9 @@ class BiliAPI extends Service {
282
289
  }
283
290
  createNewClient() {
284
291
  // 创建cookieJar
285
- this.jar = new CookieJar();
292
+ this.jar = new tough_cookie_1.CookieJar();
286
293
  // 包装cookieJar
287
- this.client = wrapper(axios.create({
294
+ this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
288
295
  jar: this.jar,
289
296
  headers: {
290
297
  "Content-Type": "application/json",
@@ -400,7 +407,7 @@ class BiliAPI extends Service {
400
407
  sameSite = cookieData.sameSite;
401
408
  }
402
409
  // 创建一个完整的 Cookie 实例
403
- const cookie = new Cookie({
410
+ const cookie = new tough_cookie_1.Cookie({
404
411
  key: cookieData.key,
405
412
  value: cookieData.value,
406
413
  expires: new Date(cookieData.expires),
@@ -413,7 +420,7 @@ class BiliAPI extends Service {
413
420
  this.jar.setCookieSync(cookie, `http${cookie.secure ? "s" : ""}://${cookie.domain}${cookie.path}`, {});
414
421
  }
415
422
  // 对于某些 IP 地址,需要在 Cookie 中提供任意非空的 buvid3 字段
416
- const buvid3Cookie = new Cookie({
423
+ const buvid3Cookie = new tough_cookie_1.Cookie({
417
424
  key: "buvid3",
418
425
  value: "some_non_empty_value", // 设置任意非空值
419
426
  expires, // 设置过期时间
@@ -486,7 +493,7 @@ class BiliAPI extends Service {
486
493
  // 如果请求失败,有可能是404,直接刷新cookie
487
494
  }
488
495
  // 定义Key
489
- const publicKey = await crypto.subtle.importKey("jwk", {
496
+ const publicKey = await node_crypto_1.default.subtle.importKey("jwk", {
490
497
  kty: "RSA",
491
498
  n: "y4HdjgJHBlbaBN04VERG4qNBIFHP6a3GozCl75AihQloSWCXC5HDNgyinEnhaQ_4-gaMud_GF50elYXLlCToR9se9Z8z433U3KjM-3Yx7ptKkmQNAMggQwAVKgq3zYAoidNEWuxpkY_mAitTSRLnsJW-NCTa0bqBFF6Wm1MxgfE",
492
499
  e: "AQAB",
@@ -494,7 +501,7 @@ class BiliAPI extends Service {
494
501
  // 定义获取CorrespondPath方法
495
502
  async function getCorrespondPath(timestamp) {
496
503
  const data = new TextEncoder().encode(`refresh_${timestamp}`);
497
- const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
504
+ const encrypted = new Uint8Array(await node_crypto_1.default.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
498
505
  return encrypted.reduce((str, c) => str + c.toString(16).padStart(2, "0"), "");
499
506
  }
500
507
  // 获取CorrespondPath
@@ -503,7 +510,7 @@ class BiliAPI extends Service {
503
510
  // 获取refresh_csrf
504
511
  const { data: refreshCsrfHtml } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
505
512
  // 创建一个虚拟的DOM元素
506
- const { document } = new JSDOM(refreshCsrfHtml).window;
513
+ const { document } = new jsdom_1.JSDOM(refreshCsrfHtml).window;
507
514
  // 提取标签name为1-name的内容
508
515
  const targetElement = document.getElementById("1-name");
509
516
  const refresh_csrf = targetElement ? targetElement.textContent : null;
@@ -571,7 +578,7 @@ class BiliAPI extends Service {
571
578
  }
572
579
  }
573
580
  __decorate([
574
- Retry({
581
+ (0, utils_1.Retry)({
575
582
  attempts: 3,
576
583
  onFailure(error, attempts) {
577
584
  this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
@@ -579,7 +586,7 @@ __decorate([
579
586
  })
580
587
  ], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
581
588
  __decorate([
582
- Retry({
589
+ (0, utils_1.Retry)({
583
590
  attempts: 3,
584
591
  onFailure(error, attempts) {
585
592
  this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
@@ -587,7 +594,7 @@ __decorate([
587
594
  })
588
595
  ], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
589
596
  __decorate([
590
- Retry({
597
+ (0, utils_1.Retry)({
591
598
  attempts: 3,
592
599
  onFailure(error, attempts) {
593
600
  this.logger.error(`getLiveRoomInfoByUids() 第${attempts}次失败: ${error.message}`);
@@ -595,7 +602,7 @@ __decorate([
595
602
  })
596
603
  ], BiliAPI.prototype, "getLiveRoomInfoByUids", null);
597
604
  __decorate([
598
- Retry({
605
+ (0, utils_1.Retry)({
599
606
  attempts: 3,
600
607
  onFailure(error, attempts) {
601
608
  this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
@@ -603,7 +610,7 @@ __decorate([
603
610
  })
604
611
  ], BiliAPI.prototype, "getServerUTCTime", null);
605
612
  __decorate([
606
- Retry({
613
+ (0, utils_1.Retry)({
607
614
  attempts: 3,
608
615
  onFailure(error, attempts) {
609
616
  this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
@@ -611,7 +618,7 @@ __decorate([
611
618
  })
612
619
  ], BiliAPI.prototype, "getTimeNow", null);
613
620
  __decorate([
614
- Retry({
621
+ (0, utils_1.Retry)({
615
622
  attempts: 3,
616
623
  onFailure(error, attempts) {
617
624
  this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
@@ -619,7 +626,7 @@ __decorate([
619
626
  })
620
627
  ], BiliAPI.prototype, "getAllGroup", null);
621
628
  __decorate([
622
- Retry({
629
+ (0, utils_1.Retry)({
623
630
  attempts: 3,
624
631
  onFailure(error, attempts) {
625
632
  this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
@@ -627,7 +634,7 @@ __decorate([
627
634
  })
628
635
  ], BiliAPI.prototype, "removeUserFromGroup", null);
629
636
  __decorate([
630
- Retry({
637
+ (0, utils_1.Retry)({
631
638
  attempts: 3,
632
639
  onFailure(error, attempts) {
633
640
  this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
@@ -635,7 +642,7 @@ __decorate([
635
642
  })
636
643
  ], BiliAPI.prototype, "copyUserToGroup", null);
637
644
  __decorate([
638
- Retry({
645
+ (0, utils_1.Retry)({
639
646
  attempts: 3,
640
647
  onFailure(error, attempts) {
641
648
  this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
@@ -643,7 +650,7 @@ __decorate([
643
650
  })
644
651
  ], BiliAPI.prototype, "getUserSpaceDynamic", null);
645
652
  __decorate([
646
- Retry({
653
+ (0, utils_1.Retry)({
647
654
  attempts: 3,
648
655
  onFailure(error, attempts) {
649
656
  this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
@@ -651,7 +658,7 @@ __decorate([
651
658
  })
652
659
  ], BiliAPI.prototype, "createGroup", null);
653
660
  __decorate([
654
- Retry({
661
+ (0, utils_1.Retry)({
655
662
  attempts: 3,
656
663
  onFailure(error, attempts) {
657
664
  this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
@@ -659,7 +666,7 @@ __decorate([
659
666
  })
660
667
  ], BiliAPI.prototype, "getAllDynamic", null);
661
668
  __decorate([
662
- Retry({
669
+ (0, utils_1.Retry)({
663
670
  attempts: 3,
664
671
  onFailure(error, attempts) {
665
672
  this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
@@ -667,7 +674,7 @@ __decorate([
667
674
  })
668
675
  ], BiliAPI.prototype, "hasNewDynamic", null);
669
676
  __decorate([
670
- Retry({
677
+ (0, utils_1.Retry)({
671
678
  attempts: 3,
672
679
  onFailure(error, attempts) {
673
680
  this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
@@ -675,7 +682,7 @@ __decorate([
675
682
  })
676
683
  ], BiliAPI.prototype, "follow", null);
677
684
  __decorate([
678
- Retry({
685
+ (0, utils_1.Retry)({
679
686
  attempts: 3,
680
687
  onFailure(error, attempts) {
681
688
  this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
@@ -683,7 +690,7 @@ __decorate([
683
690
  })
684
691
  ], BiliAPI.prototype, "getRelationGroupDetail", null);
685
692
  __decorate([
686
- Retry({
693
+ (0, utils_1.Retry)({
687
694
  attempts: 3,
688
695
  onFailure(error, attempts) {
689
696
  this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
@@ -691,7 +698,7 @@ __decorate([
691
698
  })
692
699
  ], BiliAPI.prototype, "getCookieInfo", null);
693
700
  __decorate([
694
- Retry({
701
+ (0, utils_1.Retry)({
695
702
  attempts: 3,
696
703
  onFailure(error, attempts) {
697
704
  this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
@@ -699,7 +706,7 @@ __decorate([
699
706
  })
700
707
  ], BiliAPI.prototype, "getUserInfo", null);
701
708
  __decorate([
702
- Retry({
709
+ (0, utils_1.Retry)({
703
710
  attempts: 3,
704
711
  onFailure(error, attempts) {
705
712
  this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
@@ -707,7 +714,7 @@ __decorate([
707
714
  })
708
715
  ], BiliAPI.prototype, "getWbiKeys", null);
709
716
  __decorate([
710
- Retry({
717
+ (0, utils_1.Retry)({
711
718
  attempts: 3,
712
719
  onFailure(error, attempts) {
713
720
  this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
@@ -715,7 +722,7 @@ __decorate([
715
722
  })
716
723
  ], BiliAPI.prototype, "getMyselfInfo", null);
717
724
  __decorate([
718
- Retry({
725
+ (0, utils_1.Retry)({
719
726
  attempts: 3,
720
727
  onFailure(error, attempts) {
721
728
  this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
@@ -723,7 +730,7 @@ __decorate([
723
730
  })
724
731
  ], BiliAPI.prototype, "getLoginQRCode", null);
725
732
  __decorate([
726
- Retry({
733
+ (0, utils_1.Retry)({
727
734
  attempts: 3,
728
735
  onFailure(error, attempts) {
729
736
  this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
@@ -731,7 +738,7 @@ __decorate([
731
738
  })
732
739
  ], BiliAPI.prototype, "getLoginStatus", null);
733
740
  __decorate([
734
- Retry({
741
+ (0, utils_1.Retry)({
735
742
  attempts: 3,
736
743
  onFailure(error, attempts) {
737
744
  this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
@@ -739,7 +746,7 @@ __decorate([
739
746
  })
740
747
  ], BiliAPI.prototype, "getLiveRoomInfo", null);
741
748
  __decorate([
742
- Retry({
749
+ (0, utils_1.Retry)({
743
750
  attempts: 3,
744
751
  onFailure(error, attempts) {
745
752
  this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
@@ -747,11 +754,11 @@ __decorate([
747
754
  })
748
755
  ], BiliAPI.prototype, "getMasterInfo", null);
749
756
  (function (BiliAPI) {
750
- BiliAPI.Config = Schema.object({
751
- userAgent: Schema.string(),
752
- key: Schema.string()
757
+ BiliAPI.Config = koishi_1.Schema.object({
758
+ userAgent: koishi_1.Schema.string(),
759
+ key: koishi_1.Schema.string()
753
760
  .pattern(/^[0-9a-f]{32}$/)
754
761
  .required(),
755
762
  });
756
763
  })(BiliAPI || (BiliAPI = {}));
757
- export default BiliAPI;
764
+ exports.default = BiliAPI;
package/lib/blive.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Awaitable, type Context, Service } from "koishi";
2
- import { type MsgHandler } from "@akokko/blive-message-listener";
2
+ import { type MsgHandler } from "blive-message-listener";
3
3
  declare module "koishi" {
4
4
  interface Context {
5
5
  bl: BLive;
package/lib/blive.js CHANGED
@@ -1,6 +1,8 @@
1
- import { Service } from "koishi";
2
- import { startListen, } from "@akokko/blive-message-listener";
3
- class BLive extends Service {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const koishi_1 = require("koishi");
4
+ const blive_message_listener_1 = require("blive-message-listener");
5
+ class BLive extends koishi_1.Service {
4
6
  // 必要服务
5
7
  static inject = ["ba"];
6
8
  // 定义类属性
@@ -17,29 +19,26 @@ class BLive extends Service {
17
19
  }
18
20
  }
19
21
  async startLiveRoomListener(roomId, handler) {
20
- try {
21
- // 获取cookieStr
22
- const cookiesStr = await this.ctx.ba.getCookiesForHeader();
23
- // 获取自身信息
24
- const mySelfInfo = await this.ctx.ba.getMyselfInfo();
25
- // 创建实例并保存到Record中
26
- this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, {
27
- ws: {
28
- headers: {
29
- Cookie: cookiesStr,
30
- },
31
- uid: mySelfInfo.data.mid,
22
+ // 获取cookieStr
23
+ const cookiesStr = await this.ctx.ba.getCookiesForHeader();
24
+ // 获取自身信息
25
+ const mySelfInfo = await this.ctx.ba.getMyselfInfo();
26
+ // 创建实例并保存到Record中
27
+ this.listenerRecord[roomId] = (0, blive_message_listener_1.startListen)(Number.parseInt(roomId), handler, {
28
+ ws: {
29
+ headers: {
30
+ Cookie: cookiesStr,
32
31
  },
33
- });
34
- }
35
- catch (e) {
36
- // logger
37
- this.logger.info(`[${roomId}]监听直播间消息失败!错误:${e.message}`);
38
- }
32
+ uid: mySelfInfo.data.mid,
33
+ },
34
+ });
35
+ // logger
36
+ this.logger.info(`[${roomId}]开始监听直播间消息!`);
39
37
  }
40
38
  closeListener(roomId) {
41
39
  // 判断直播间监听器是否关闭
42
- if (!this.listenerRecord || !this.listenerRecord[roomId]?.closed) {
40
+ if (!this.listenerRecord ||
41
+ !this.listenerRecord[roomId]?.closed) {
43
42
  // 输出logger
44
43
  this.logger.info(`${roomId}直播间弹幕监听器无需关闭`);
45
44
  }
@@ -58,4 +57,4 @@ class BLive extends Service {
58
57
  this.logger.warn(`${roomId}直播间弹幕监听未成功关闭`);
59
58
  }
60
59
  }
61
- export default BLive;
60
+ exports.default = BLive;