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