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

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