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

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
1
  import { type Awaitable, type Context, Schema, Service } from "koishi";
2
- import CacheableLookup from "cacheable-lookup";
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;
@@ -21,6 +20,7 @@ declare class BiliAPI extends Service {
21
20
  constructor(ctx: Context, config: BiliAPI.Config);
22
21
  protected start(): void | Promise<void>;
23
22
  protected stop(): Awaitable<void>;
23
+ init(): Promise<void>;
24
24
  getMixinKey: (orig: string) => string;
25
25
  encWbi(params: {
26
26
  [key: string]: string | number | object;
package/lib/biliAPI.js CHANGED
@@ -1,10 +1,43 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  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
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
8
41
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
42
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
43
  };
@@ -14,7 +47,6 @@ const md5_1 = __importDefault(require("md5"));
14
47
  const node_crypto_1 = __importDefault(require("node:crypto"));
15
48
  const node_http_1 = __importDefault(require("node:http"));
16
49
  const node_https_1 = __importDefault(require("node:https"));
17
- const cacheable_lookup_1 = __importDefault(require("cacheable-lookup"));
18
50
  const axios_1 = __importDefault(require("axios"));
19
51
  const tough_cookie_1 = require("tough-cookie");
20
52
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
@@ -56,6 +88,7 @@ class BiliAPI extends koishi_1.Service {
56
88
  static inject = ["database", "notifier"];
57
89
  jar;
58
90
  client;
91
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
59
92
  cacheable;
60
93
  apiConfig;
61
94
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -68,6 +101,8 @@ class BiliAPI extends koishi_1.Service {
68
101
  this.apiConfig = config;
69
102
  }
70
103
  start() {
104
+ // init
105
+ this.init();
71
106
  // 创建新的http客户端(axios)
72
107
  this.createNewClient();
73
108
  // 从数据库加载cookies
@@ -78,6 +113,15 @@ class BiliAPI extends koishi_1.Service {
78
113
  this.cacheable.uninstall(node_http_1.default.globalAgent);
79
114
  this.cacheable.uninstall(node_https_1.default.globalAgent);
80
115
  }
116
+ async init() {
117
+ // 导入纯ESM模块Cacheable
118
+ const { default: CacheableLookup } = await Promise.resolve().then(() => __importStar(require("cacheable-lookup")));
119
+ // 创建Cacheable
120
+ this.cacheable = new CacheableLookup();
121
+ // 安装到http和https
122
+ this.cacheable.install(node_http_1.default.globalAgent);
123
+ this.cacheable.install(node_https_1.default.globalAgent);
124
+ }
81
125
  // WBI签名
82
126
  // 对 imgKey 和 subKey 进行字符顺序打乱编码
83
127
  getMixinKey = (orig) => mixinKeyEncTab
@@ -295,11 +339,6 @@ class BiliAPI extends koishi_1.Service {
295
339
  return userAgents[index];
296
340
  }
297
341
  createNewClient() {
298
- // 创建DNS缓存
299
- this.cacheable = new cacheable_lookup_1.default();
300
- // 安装到http和https
301
- this.cacheable.install(node_http_1.default.globalAgent);
302
- this.cacheable.install(node_https_1.default.globalAgent);
303
342
  // 创建cookieJar
304
343
  this.jar = new tough_cookie_1.CookieJar();
305
344
  // 包装cookieJar
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.2.1-alpha.0",
4
+ "version": "3.2.1-alpha.2",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -256,7 +256,9 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
256
256
  - ver 3.2.0-alpha.5 修复:直播检测 `WS` 模式下,直播中推送卡片 `累计观看人数` 位置错误显示为 `粉丝数变化` 、转发动态的留言文字不显示; 优化:直播检测 `API` 模式下,直播推送语 `-watched` 固定显示为 `API模式无法获取`;
257
257
  - ver 3.2.0-alpha.6 优化:调整配置项;
258
258
  - ver 3.2.0-alpha.7 修复:自 `3.1.7` 版本 `pushImagesInDynamic` 功能失效;
259
- - ver 3.2.1-alpha.0 新增:多个相同平台bot可以选择某个群聊/频道指定机器人发送; 优化:直播检测 `WS` 模式下播后仍推送; 修复:打开 `pushImagesInDynamic` 功能时,如果发送的动态里没有图片则会报错 `TypeError: Cannot read properties of null (reading 'opus')`
259
+ - ver 3.2.1-alpha.0 新增:多个相同平台bot可以选择某个群聊/频道指定机器人发送; 优化:直播检测 `WS` 模式下播后仍推送、添加依赖 `cacheable-lookup` 优化网络; 修复:打开 `pushImagesInDynamic` 功能时,如果发送的动态里没有图片则会报错 `TypeError: Cannot read properties of null (reading 'opus')`
260
+ - ver 3.2.1-alpha.1 调整:将项目构建产物调整为 `esm`;
261
+ - ver 3.2.1-alpha.2 调整:将项目构建产物调整回 `cjs` 、将依赖 `cacheable-lookup` 导入方式更改为动态导入;
260
262
 
261
263
  ## 交流群
262
264
 
@@ -1,6 +0,0 @@
1
- interface RetryOptions {
2
- attempts: number;
3
- onFailure?: (error: Error, attempts: number) => Promise<void> | void;
4
- }
5
- declare function Retry(options?: RetryOptions): MethodDecorator;
6
- export default Retry;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function Retry(options = { attempts: 3 }) {
4
- return function (target, propertyKey, descriptor) {
5
- const originalMethod = descriptor.value;
6
- descriptor.value = async function (...args) {
7
- let lastError;
8
- for (let i = 0; i < options.attempts; i++) {
9
- try {
10
- return await originalMethod.apply(this, args);
11
- }
12
- catch (error) {
13
- lastError = error;
14
- if (options.onFailure) {
15
- await options.onFailure.call(this, lastError, i + 1);
16
- }
17
- }
18
- }
19
- throw lastError;
20
- };
21
- return descriptor;
22
- };
23
- }
24
- exports.default = Retry;
@@ -1,7 +0,0 @@
1
- /**
2
- * 高阶函数:为函数添加锁机制
3
- * @param {Function} fn - 需要包装的原始函数
4
- * @returns {Function} 带锁功能的函数
5
- */
6
- declare function withLock(fn: any): (...args: any[]) => void;
7
- export default withLock;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 高阶函数:为函数添加锁机制
5
- * @param {Function} fn - 需要包装的原始函数
6
- * @returns {Function} 带锁功能的函数
7
- */
8
- function withLock(fn) {
9
- // 判断是否是异步函数
10
- const isAsync = fn.constructor.name === 'AsyncFunction';
11
- // 定义锁标志
12
- let locked = false;
13
- // 判断是否为异步函数
14
- if (isAsync) {
15
- // 变为Promise
16
- return function (...args) {
17
- // 已加锁则跳过执行
18
- if (locked)
19
- return;
20
- // 获取锁
21
- locked = true;
22
- // 将异步函数转为Promise链
23
- Promise.resolve(fn(...args))
24
- .catch(err => {
25
- // 打印错误
26
- console.error("Execution error:", err);
27
- // 重新抛出错误
28
- throw err;
29
- })
30
- .finally(() => {
31
- // 确保释放锁
32
- locked = false;
33
- });
34
- };
35
- }
36
- // 不是异步函数
37
- return function (...args) {
38
- // 已加锁则跳过执行
39
- if (locked)
40
- return;
41
- // 获取锁
42
- locked = true;
43
- try {
44
- // 执行函数
45
- fn(...args);
46
- }
47
- catch (err) {
48
- // 打印错误
49
- console.error("Execution error:", err);
50
- // 重新抛出错误
51
- throw err;
52
- }
53
- finally {
54
- // 无论成功失败都释放锁
55
- locked = false;
56
- }
57
- };
58
- }
59
- exports.default = withLock;