koishi-plugin-bilibili-notify 3.2.1-alpha.0 → 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
@@ -12,9 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const koishi_1 = require("koishi");
13
13
  const md5_1 = __importDefault(require("md5"));
14
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
15
  const axios_1 = __importDefault(require("axios"));
19
16
  const tough_cookie_1 = require("tough-cookie");
20
17
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
@@ -56,6 +53,7 @@ class BiliAPI extends koishi_1.Service {
56
53
  static inject = ["database", "notifier"];
57
54
  jar;
58
55
  client;
56
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
59
57
  cacheable;
60
58
  apiConfig;
61
59
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -73,11 +71,6 @@ class BiliAPI extends koishi_1.Service {
73
71
  // 从数据库加载cookies
74
72
  this.loadCookiesFromDatabase();
75
73
  }
76
- stop() {
77
- // 将DNS缓存卸载
78
- this.cacheable.uninstall(node_http_1.default.globalAgent);
79
- this.cacheable.uninstall(node_https_1.default.globalAgent);
80
- }
81
74
  // WBI签名
82
75
  // 对 imgKey 和 subKey 进行字符顺序打乱编码
83
76
  getMixinKey = (orig) => mixinKeyEncTab
@@ -295,11 +288,6 @@ class BiliAPI extends koishi_1.Service {
295
288
  return userAgents[index];
296
289
  }
297
290
  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
291
  // 创建cookieJar
304
292
  this.jar = new tough_cookie_1.CookieJar();
305
293
  // 包装cookieJar
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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const koishi_1 = require("koishi");
4
- const blive_message_listener_1 = require("blive-message-listener");
4
+ const blive_message_listener_1 = require("@akokko/blive-message-listener");
5
5
  class BLive extends koishi_1.Service {
6
6
  // 必要服务
7
7
  static inject = ["ba"];
@@ -1100,7 +1100,7 @@ class ComRegister {
1100
1100
  // connFlag设置为false
1101
1101
  connFlag = false;
1102
1102
  // logger
1103
- this.logger.info(`${roomId}直播间连接已建立!`);
1103
+ this.logger.info(`[${roomId}]直播间连接已建立!`);
1104
1104
  }
1105
1105
  },
1106
1106
  onClose: async () => {
@@ -1114,10 +1114,21 @@ class ComRegister {
1114
1114
  // 更改connFlag
1115
1115
  connFlag = true;
1116
1116
  // 发送消息
1117
- await this.sendPrivateMsg(`${roomId}直播间连接已中断!`);
1118
- this.logger.error(`${roomId}直播间连接已中断!`);
1117
+ await this.sendPrivateMsg(`[${roomId}]直播间连接已中断!`);
1118
+ this.logger.error(`[${roomId}]直播间连接已中断!`);
1119
1119
  }
1120
1120
  },
1121
+ onError: async () => {
1122
+ // 更直播状态
1123
+ liveStatus = false;
1124
+ // 关闭定时推送
1125
+ pushAtTimeTimer?.();
1126
+ // 停止服务
1127
+ this.ctx.bl.closeListener(roomId);
1128
+ // 发送消息
1129
+ await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
1130
+ this.logger.error(`[${roomId}]直播间连接发生错误!`);
1131
+ },
1121
1132
  onIncomeDanmu: ({ body }) => {
1122
1133
  // 保存消息到数组
1123
1134
  currentLiveDanmakuArr.push(body.content);
@@ -1563,17 +1574,17 @@ class ComRegister {
1563
1574
  // 判断是否有数据
1564
1575
  if (!this.loginDBData?.dynamic_group_id) {
1565
1576
  // 没有数据,没有创建分组,尝试创建分组
1566
- const createGroupData = await this.ctx.ba.createGroup("订阅");
1577
+ const createGroupData = (await this.ctx.ba.createGroup("订阅"));
1567
1578
  // 如果分组已创建,则获取分组id
1568
1579
  if (createGroupData.code === 22106) {
1569
1580
  // 分组已存在,拿到之前的分组id
1570
- const allGroupData = await this.ctx.ba.getAllGroup();
1581
+ const allGroupData = (await this.ctx.ba.getAllGroup());
1571
1582
  // 遍历所有分组
1572
1583
  for (const group of allGroupData.data) {
1573
1584
  // 找到订阅分组
1574
1585
  if (group.name === "订阅") {
1575
1586
  // 拿到分组id
1576
- this.loginDBData.dynamic_group_id = group.tagid;
1587
+ this.loginDBData.dynamic_group_id = group.tagid.toString();
1577
1588
  // 保存到数据库
1578
1589
  this.ctx.database.set("loginBili", 1, {
1579
1590
  dynamic_group_id: this.loginDBData.dynamic_group_id,
@@ -1589,7 +1600,7 @@ class ComRegister {
1589
1600
  }
1590
1601
  // 创建成功,保存到数据库
1591
1602
  this.ctx.database.set("loginBili", 1, {
1592
- dynamic_group_id: this.loginDBData.dynamic_group_id,
1603
+ dynamic_group_id: createGroupData.data.tagid.toString(),
1593
1604
  });
1594
1605
  // 创建成功
1595
1606
  return { code: createGroupData.code, msg: createGroupData.message };
@@ -241,3 +241,22 @@ export type Result = {
241
241
  msg?: string;
242
242
  data?: any;
243
243
  };
244
+ export type CreateGroup = {
245
+ code: number;
246
+ message: string;
247
+ ttl: number;
248
+ data: {
249
+ tagid: number;
250
+ };
251
+ };
252
+ export type GroupList = {
253
+ code: number;
254
+ message: string;
255
+ ttl: number;
256
+ data: Array<{
257
+ tagid: number;
258
+ name: string;
259
+ count: number;
260
+ tip: string;
261
+ }>;
262
+ };
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.10",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -27,10 +27,9 @@
27
27
  "koishi": "^4.18.7"
28
28
  },
29
29
  "dependencies": {
30
+ "@akokko/blive-message-listener": "^0.5.1",
30
31
  "axios": "^1.7.9",
31
32
  "axios-cookiejar-support": "^5.0.5",
32
- "blive-message-listener": "^0.5.0",
33
- "cacheable-lookup": "^7.0.0",
34
33
  "cron": "^4.3.0",
35
34
  "jsdom": "^24.1.3",
36
35
  "luxon": "^3.5.0",
package/readme.md CHANGED
@@ -256,7 +256,14 @@ 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` 导入方式更改为动态导入;
262
+ - ver 3.2.1-alpha.3 修复:直播检测 `WS` 初始化后自动断开连接;
263
+ - ver 3.2.1-alpha.4 优化:直播监听初始化没有提示;
264
+ - ver 3.2.1-alpha.4 - ver 3.2.1-alpha.8 `deprecate`
265
+ - ver 3.2.1-alpha.9 修复:`bugs`
266
+ - ver 3.2.1-alpha.10 修复:临时切换依赖 `blive-message-listener` 为 `@akokko/blive-message-listener` 以解决直播检测模式 `WS` 掉线问题、第一次使用插件报错 `TypeError: Cannot set properties of undefined (setting 'dynamic_group_id')`;
260
267
 
261
268
  ## 交流群
262
269
 
@@ -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;