koishi-plugin-bilibili-notify 3.2.1-alpha.0 → 3.2.1-alpha.1

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,25 +1,20 @@
1
- "use strict";
2
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
4
  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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
6
  };
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 node_http_1 = __importDefault(require("node:http"));
16
- const node_https_1 = __importDefault(require("node:https"));
17
- const cacheable_lookup_1 = __importDefault(require("cacheable-lookup"));
18
- const axios_1 = __importDefault(require("axios"));
19
- const tough_cookie_1 = require("tough-cookie");
20
- const axios_cookiejar_support_1 = require("axios-cookiejar-support");
21
- const jsdom_1 = require("jsdom");
22
- const utils_1 = require("./utils");
7
+ import { Schema, Service } from "koishi";
8
+ import md5 from "md5";
9
+ import crypto from "node:crypto";
10
+ import http from "node:http";
11
+ import https from "node:https";
12
+ import CacheableLookup from "cacheable-lookup";
13
+ import axios from "axios";
14
+ import { CookieJar, Cookie } from "tough-cookie";
15
+ import { wrapper } from "axios-cookiejar-support";
16
+ import { JSDOM } from "jsdom";
17
+ import { Retry } from "./utils";
23
18
  const mixinKeyEncTab = [
24
19
  46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
25
20
  33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61,
@@ -52,7 +47,7 @@ const GET_RELATION_GROUP_DETAIL = "https://api.bilibili.com/x/relation/tag";
52
47
  // 直播
53
48
  const GET_LIVE_ROOM_INFO_STREAM_KEY = "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo";
54
49
  const GET_LIVE_ROOMS_INFO = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids";
55
- class BiliAPI extends koishi_1.Service {
50
+ class BiliAPI extends Service {
56
51
  static inject = ["database", "notifier"];
57
52
  jar;
58
53
  client;
@@ -75,8 +70,8 @@ class BiliAPI extends koishi_1.Service {
75
70
  }
76
71
  stop() {
77
72
  // 将DNS缓存卸载
78
- this.cacheable.uninstall(node_http_1.default.globalAgent);
79
- this.cacheable.uninstall(node_https_1.default.globalAgent);
73
+ this.cacheable.uninstall(http.globalAgent);
74
+ this.cacheable.uninstall(https.globalAgent);
80
75
  }
81
76
  // WBI签名
82
77
  // 对 imgKey 和 subKey 进行字符顺序打乱编码
@@ -99,7 +94,7 @@ class BiliAPI extends koishi_1.Service {
99
94
  return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
100
95
  })
101
96
  .join("&");
102
- const wbi_sign = (0, md5_1.default)(query + mixin_key); // 计算 w_rid
97
+ const wbi_sign = md5(query + mixin_key); // 计算 w_rid
103
98
  return `${query}&w_rid=${wbi_sign}`;
104
99
  }
105
100
  async getWbi(params) {
@@ -110,8 +105,8 @@ class BiliAPI extends koishi_1.Service {
110
105
  return query;
111
106
  }
112
107
  encrypt(text) {
113
- const iv = node_crypto_1.default.randomBytes(16);
114
- const cipher = node_crypto_1.default.createCipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
108
+ const iv = crypto.randomBytes(16);
109
+ const cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
115
110
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
116
111
  return `${iv.toString("hex")}:${encrypted.toString("hex")}`;
117
112
  }
@@ -119,7 +114,7 @@ class BiliAPI extends koishi_1.Service {
119
114
  const textParts = text.split(":");
120
115
  const iv = Buffer.from(textParts.shift(), "hex");
121
116
  const encryptedText = Buffer.from(textParts.join(":"), "hex");
122
- const decipher = node_crypto_1.default.createDecipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
117
+ const decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
123
118
  const decrypted = Buffer.concat([
124
119
  decipher.update(encryptedText),
125
120
  decipher.final(),
@@ -296,14 +291,14 @@ class BiliAPI extends koishi_1.Service {
296
291
  }
297
292
  createNewClient() {
298
293
  // 创建DNS缓存
299
- this.cacheable = new cacheable_lookup_1.default();
294
+ this.cacheable = new CacheableLookup();
300
295
  // 安装到http和https
301
- this.cacheable.install(node_http_1.default.globalAgent);
302
- this.cacheable.install(node_https_1.default.globalAgent);
296
+ this.cacheable.install(http.globalAgent);
297
+ this.cacheable.install(https.globalAgent);
303
298
  // 创建cookieJar
304
- this.jar = new tough_cookie_1.CookieJar();
299
+ this.jar = new CookieJar();
305
300
  // 包装cookieJar
306
- this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
301
+ this.client = wrapper(axios.create({
307
302
  jar: this.jar,
308
303
  headers: {
309
304
  "Content-Type": "application/json",
@@ -419,7 +414,7 @@ class BiliAPI extends koishi_1.Service {
419
414
  sameSite = cookieData.sameSite;
420
415
  }
421
416
  // 创建一个完整的 Cookie 实例
422
- const cookie = new tough_cookie_1.Cookie({
417
+ const cookie = new Cookie({
423
418
  key: cookieData.key,
424
419
  value: cookieData.value,
425
420
  expires: new Date(cookieData.expires),
@@ -432,7 +427,7 @@ class BiliAPI extends koishi_1.Service {
432
427
  this.jar.setCookieSync(cookie, `http${cookie.secure ? "s" : ""}://${cookie.domain}${cookie.path}`, {});
433
428
  }
434
429
  // 对于某些 IP 地址,需要在 Cookie 中提供任意非空的 buvid3 字段
435
- const buvid3Cookie = new tough_cookie_1.Cookie({
430
+ const buvid3Cookie = new Cookie({
436
431
  key: "buvid3",
437
432
  value: "some_non_empty_value", // 设置任意非空值
438
433
  expires, // 设置过期时间
@@ -505,7 +500,7 @@ class BiliAPI extends koishi_1.Service {
505
500
  // 如果请求失败,有可能是404,直接刷新cookie
506
501
  }
507
502
  // 定义Key
508
- const publicKey = await node_crypto_1.default.subtle.importKey("jwk", {
503
+ const publicKey = await crypto.subtle.importKey("jwk", {
509
504
  kty: "RSA",
510
505
  n: "y4HdjgJHBlbaBN04VERG4qNBIFHP6a3GozCl75AihQloSWCXC5HDNgyinEnhaQ_4-gaMud_GF50elYXLlCToR9se9Z8z433U3KjM-3Yx7ptKkmQNAMggQwAVKgq3zYAoidNEWuxpkY_mAitTSRLnsJW-NCTa0bqBFF6Wm1MxgfE",
511
506
  e: "AQAB",
@@ -513,7 +508,7 @@ class BiliAPI extends koishi_1.Service {
513
508
  // 定义获取CorrespondPath方法
514
509
  async function getCorrespondPath(timestamp) {
515
510
  const data = new TextEncoder().encode(`refresh_${timestamp}`);
516
- const encrypted = new Uint8Array(await node_crypto_1.default.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
511
+ const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
517
512
  return encrypted.reduce((str, c) => str + c.toString(16).padStart(2, "0"), "");
518
513
  }
519
514
  // 获取CorrespondPath
@@ -522,7 +517,7 @@ class BiliAPI extends koishi_1.Service {
522
517
  // 获取refresh_csrf
523
518
  const { data: refreshCsrfHtml } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
524
519
  // 创建一个虚拟的DOM元素
525
- const { document } = new jsdom_1.JSDOM(refreshCsrfHtml).window;
520
+ const { document } = new JSDOM(refreshCsrfHtml).window;
526
521
  // 提取标签name为1-name的内容
527
522
  const targetElement = document.getElementById("1-name");
528
523
  const refresh_csrf = targetElement ? targetElement.textContent : null;
@@ -590,7 +585,7 @@ class BiliAPI extends koishi_1.Service {
590
585
  }
591
586
  }
592
587
  __decorate([
593
- (0, utils_1.Retry)({
588
+ Retry({
594
589
  attempts: 3,
595
590
  onFailure(error, attempts) {
596
591
  this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
@@ -598,7 +593,7 @@ __decorate([
598
593
  })
599
594
  ], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
600
595
  __decorate([
601
- (0, utils_1.Retry)({
596
+ Retry({
602
597
  attempts: 3,
603
598
  onFailure(error, attempts) {
604
599
  this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
@@ -606,7 +601,7 @@ __decorate([
606
601
  })
607
602
  ], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
608
603
  __decorate([
609
- (0, utils_1.Retry)({
604
+ Retry({
610
605
  attempts: 3,
611
606
  onFailure(error, attempts) {
612
607
  this.logger.error(`getLiveRoomInfoByUids() 第${attempts}次失败: ${error.message}`);
@@ -614,7 +609,7 @@ __decorate([
614
609
  })
615
610
  ], BiliAPI.prototype, "getLiveRoomInfoByUids", null);
616
611
  __decorate([
617
- (0, utils_1.Retry)({
612
+ Retry({
618
613
  attempts: 3,
619
614
  onFailure(error, attempts) {
620
615
  this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
@@ -622,7 +617,7 @@ __decorate([
622
617
  })
623
618
  ], BiliAPI.prototype, "getServerUTCTime", null);
624
619
  __decorate([
625
- (0, utils_1.Retry)({
620
+ Retry({
626
621
  attempts: 3,
627
622
  onFailure(error, attempts) {
628
623
  this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
@@ -630,7 +625,7 @@ __decorate([
630
625
  })
631
626
  ], BiliAPI.prototype, "getTimeNow", null);
632
627
  __decorate([
633
- (0, utils_1.Retry)({
628
+ Retry({
634
629
  attempts: 3,
635
630
  onFailure(error, attempts) {
636
631
  this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
@@ -638,7 +633,7 @@ __decorate([
638
633
  })
639
634
  ], BiliAPI.prototype, "getAllGroup", null);
640
635
  __decorate([
641
- (0, utils_1.Retry)({
636
+ Retry({
642
637
  attempts: 3,
643
638
  onFailure(error, attempts) {
644
639
  this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
@@ -646,7 +641,7 @@ __decorate([
646
641
  })
647
642
  ], BiliAPI.prototype, "removeUserFromGroup", null);
648
643
  __decorate([
649
- (0, utils_1.Retry)({
644
+ Retry({
650
645
  attempts: 3,
651
646
  onFailure(error, attempts) {
652
647
  this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
@@ -654,7 +649,7 @@ __decorate([
654
649
  })
655
650
  ], BiliAPI.prototype, "copyUserToGroup", null);
656
651
  __decorate([
657
- (0, utils_1.Retry)({
652
+ Retry({
658
653
  attempts: 3,
659
654
  onFailure(error, attempts) {
660
655
  this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
@@ -662,7 +657,7 @@ __decorate([
662
657
  })
663
658
  ], BiliAPI.prototype, "getUserSpaceDynamic", null);
664
659
  __decorate([
665
- (0, utils_1.Retry)({
660
+ Retry({
666
661
  attempts: 3,
667
662
  onFailure(error, attempts) {
668
663
  this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
@@ -670,7 +665,7 @@ __decorate([
670
665
  })
671
666
  ], BiliAPI.prototype, "createGroup", null);
672
667
  __decorate([
673
- (0, utils_1.Retry)({
668
+ Retry({
674
669
  attempts: 3,
675
670
  onFailure(error, attempts) {
676
671
  this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
@@ -678,7 +673,7 @@ __decorate([
678
673
  })
679
674
  ], BiliAPI.prototype, "getAllDynamic", null);
680
675
  __decorate([
681
- (0, utils_1.Retry)({
676
+ Retry({
682
677
  attempts: 3,
683
678
  onFailure(error, attempts) {
684
679
  this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
@@ -686,7 +681,7 @@ __decorate([
686
681
  })
687
682
  ], BiliAPI.prototype, "hasNewDynamic", null);
688
683
  __decorate([
689
- (0, utils_1.Retry)({
684
+ Retry({
690
685
  attempts: 3,
691
686
  onFailure(error, attempts) {
692
687
  this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
@@ -694,7 +689,7 @@ __decorate([
694
689
  })
695
690
  ], BiliAPI.prototype, "follow", null);
696
691
  __decorate([
697
- (0, utils_1.Retry)({
692
+ Retry({
698
693
  attempts: 3,
699
694
  onFailure(error, attempts) {
700
695
  this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
@@ -702,7 +697,7 @@ __decorate([
702
697
  })
703
698
  ], BiliAPI.prototype, "getRelationGroupDetail", null);
704
699
  __decorate([
705
- (0, utils_1.Retry)({
700
+ Retry({
706
701
  attempts: 3,
707
702
  onFailure(error, attempts) {
708
703
  this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
@@ -710,7 +705,7 @@ __decorate([
710
705
  })
711
706
  ], BiliAPI.prototype, "getCookieInfo", null);
712
707
  __decorate([
713
- (0, utils_1.Retry)({
708
+ Retry({
714
709
  attempts: 3,
715
710
  onFailure(error, attempts) {
716
711
  this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
@@ -718,7 +713,7 @@ __decorate([
718
713
  })
719
714
  ], BiliAPI.prototype, "getUserInfo", null);
720
715
  __decorate([
721
- (0, utils_1.Retry)({
716
+ Retry({
722
717
  attempts: 3,
723
718
  onFailure(error, attempts) {
724
719
  this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
@@ -726,7 +721,7 @@ __decorate([
726
721
  })
727
722
  ], BiliAPI.prototype, "getWbiKeys", null);
728
723
  __decorate([
729
- (0, utils_1.Retry)({
724
+ Retry({
730
725
  attempts: 3,
731
726
  onFailure(error, attempts) {
732
727
  this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
@@ -734,7 +729,7 @@ __decorate([
734
729
  })
735
730
  ], BiliAPI.prototype, "getMyselfInfo", null);
736
731
  __decorate([
737
- (0, utils_1.Retry)({
732
+ Retry({
738
733
  attempts: 3,
739
734
  onFailure(error, attempts) {
740
735
  this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
@@ -742,7 +737,7 @@ __decorate([
742
737
  })
743
738
  ], BiliAPI.prototype, "getLoginQRCode", null);
744
739
  __decorate([
745
- (0, utils_1.Retry)({
740
+ Retry({
746
741
  attempts: 3,
747
742
  onFailure(error, attempts) {
748
743
  this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
@@ -750,7 +745,7 @@ __decorate([
750
745
  })
751
746
  ], BiliAPI.prototype, "getLoginStatus", null);
752
747
  __decorate([
753
- (0, utils_1.Retry)({
748
+ Retry({
754
749
  attempts: 3,
755
750
  onFailure(error, attempts) {
756
751
  this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
@@ -758,7 +753,7 @@ __decorate([
758
753
  })
759
754
  ], BiliAPI.prototype, "getLiveRoomInfo", null);
760
755
  __decorate([
761
- (0, utils_1.Retry)({
756
+ Retry({
762
757
  attempts: 3,
763
758
  onFailure(error, attempts) {
764
759
  this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
@@ -766,11 +761,11 @@ __decorate([
766
761
  })
767
762
  ], BiliAPI.prototype, "getMasterInfo", null);
768
763
  (function (BiliAPI) {
769
- BiliAPI.Config = koishi_1.Schema.object({
770
- userAgent: koishi_1.Schema.string(),
771
- key: koishi_1.Schema.string()
764
+ BiliAPI.Config = Schema.object({
765
+ userAgent: Schema.string(),
766
+ key: Schema.string()
772
767
  .pattern(/^[0-9a-f]{32}$/)
773
768
  .required(),
774
769
  });
775
770
  })(BiliAPI || (BiliAPI = {}));
776
- exports.default = BiliAPI;
771
+ export default BiliAPI;
package/lib/blive.js CHANGED
@@ -1,8 +1,6 @@
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 {
1
+ import { Service } from "koishi";
2
+ import { startListen, } from "blive-message-listener";
3
+ class BLive extends Service {
6
4
  // 必要服务
7
5
  static inject = ["ba"];
8
6
  // 定义类属性
@@ -24,7 +22,7 @@ class BLive extends koishi_1.Service {
24
22
  // 获取自身信息
25
23
  const mySelfInfo = await this.ctx.ba.getMyselfInfo();
26
24
  // 创建实例并保存到Record中
27
- this.listenerRecord[roomId] = (0, blive_message_listener_1.startListen)(Number.parseInt(roomId), handler, {
25
+ this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, {
28
26
  ws: {
29
27
  headers: {
30
28
  Cookie: cookiesStr,
@@ -55,4 +53,4 @@ class BLive extends koishi_1.Service {
55
53
  this.logger.warn(`${roomId}直播间弹幕监听未成功关闭`);
56
54
  }
57
55
  }
58
- exports.default = BLive;
56
+ export default BLive;