koishi-plugin-bilibili-notify 3.0.4 → 3.0.5-alpha.0

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.
@@ -253,6 +253,24 @@ class ComRegister {
253
253
  }
254
254
  return table;
255
255
  });
256
+ biliCom
257
+ .subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", {
258
+ hidden: true,
259
+ })
260
+ .usage("手动推送一条动态信息")
261
+ .example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息")
262
+ .action(async ({ session }, uid, index) => {
263
+ // 获取index
264
+ const i = (index && index - 1) || 0;
265
+ // 获取动态
266
+ const content = await this.ctx.ba.getUserSpaceDynamic(uid);
267
+ // 获取动态内容
268
+ const item = content.data.items[i];
269
+ // 生成图片
270
+ const buffer = await this.ctx.gi.generateDynamicImg(item);
271
+ // 发送图片
272
+ await session.send(koishi_1.h.image(buffer, "image/png"));
273
+ });
256
274
  }
257
275
  async init(config) {
258
276
  // 设置logger
@@ -509,7 +527,9 @@ class ComRegister {
509
527
  // 设置第一条动态的动态ID
510
528
  dynamicIdStr1st = content.data?.items[0]?.id_str || "0";
511
529
  // 设置时间线
512
- timeline = content.data?.items[0]?.modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
530
+ timeline =
531
+ content.data?.items[0]?.modules.module_author.pub_ts ||
532
+ luxon_1.DateTime.now().toSeconds();
513
533
  // 设置初始化为false
514
534
  detectSetup = false;
515
535
  // logger
@@ -650,7 +670,8 @@ class ComRegister {
650
670
  // 更新本次请求第一条动态的动态ID
651
671
  dynamicIdStr1st = items[0].id_str;
652
672
  // 更新时间线
653
- timeline = items[0].modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
673
+ timeline =
674
+ items[0].modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
654
675
  };
655
676
  // 返回一个闭包函数
656
677
  return (0, utils_1.withLock)(handler);
@@ -695,7 +716,9 @@ class ComRegister {
695
716
  // logger
696
717
  this.logger.info(`获取到第一条动态ID:${dynamicIdStr1st}`);
697
718
  // 设置时间线
698
- timeline = content.data?.items[0]?.modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
719
+ timeline =
720
+ content.data?.items[0]?.modules.module_author.pub_ts ||
721
+ luxon_1.DateTime.now().toSeconds();
699
722
  // logger
700
723
  this.logger.info(`获取到时间线信息:${timeline}`);
701
724
  // 设置初始化为false
@@ -882,7 +905,8 @@ class ComRegister {
882
905
  // logger
883
906
  this.logger.info(`更新本次请求第一条动态的动态ID:${dynamicIdStr1st}`);
884
907
  // 更新时间线
885
- timeline = items[0].modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
908
+ timeline =
909
+ items[0].modules.module_author.pub_ts || luxon_1.DateTime.now().toSeconds();
886
910
  // logger
887
911
  this.logger.info(`更新时间线:${timeline}`);
888
912
  };
@@ -8,6 +8,7 @@ declare class GenerateImg extends Service {
8
8
  static inject: string[];
9
9
  giConfig: GenerateImg.Config;
10
10
  constructor(ctx: Context, config: GenerateImg.Config);
11
+ compressImage(buffer: Buffer): Promise<Buffer>;
11
12
  imgHandler(html: string): Promise<Buffer<ArrayBufferLike>>;
12
13
  generateLiveImg(data: any, username: string, userface: string, followerDisplay: string, liveStatus: number, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }: {
13
14
  cardColorStart?: string;
@@ -15,7 +16,7 @@ declare class GenerateImg extends Service {
15
16
  cardBasePlateColor?: string;
16
17
  cardBasePlateBorder?: string;
17
18
  }): Promise<Buffer<ArrayBufferLike>>;
18
- generateDynamicImg(data: any, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }: {
19
+ generateDynamicImg(data: any, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }?: {
19
20
  cardColorStart?: string;
20
21
  cardColorEnd?: string;
21
22
  cardBasePlateColor?: string;
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const koishi_1 = require("koishi");
4
7
  const luxon_1 = require("luxon");
8
+ const imagemin_1 = __importDefault(require("imagemin"));
9
+ const imagemin_pngquant_1 = __importDefault(require("imagemin-pngquant"));
5
10
  const node_path_1 = require("node:path");
6
11
  const node_url_1 = require("node:url");
7
12
  const utils_1 = require("./utils");
@@ -29,6 +34,25 @@ class GenerateImg extends koishi_1.Service {
29
34
  super(ctx, "gi");
30
35
  this.giConfig = config;
31
36
  }
37
+ async compressImage(buffer) {
38
+ return await (0, utils_1.withRetry)(async () => {
39
+ const compressedBuffer = await imagemin_1.default.buffer(buffer, {
40
+ plugins: [
41
+ (0, imagemin_pngquant_1.default)({
42
+ quality: [0.6, 0.8],
43
+ speed: 4,
44
+ }),
45
+ ],
46
+ });
47
+ if (compressedBuffer.length >= buffer.length) {
48
+ return buffer;
49
+ }
50
+ return Buffer.from(compressedBuffer);
51
+ }, 1).catch((e) => {
52
+ this.ctx.logger.error(`压缩图片失败: ${e.message}`);
53
+ return buffer;
54
+ });
55
+ }
32
56
  async imgHandler(html) {
33
57
  const htmlPath = `file://${__dirname.replaceAll("\\", "/")}/page/0.html`;
34
58
  const page = await this.ctx.puppeteer.page();
@@ -47,7 +71,7 @@ class GenerateImg extends koishi_1.Service {
47
71
  });
48
72
  await elementHandle.dispose();
49
73
  await page.close();
50
- return buffer;
74
+ return this.compressImage(buffer);
51
75
  }
52
76
  async generateLiveImg(
53
77
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -216,7 +240,7 @@ class GenerateImg extends koishi_1.Service {
216
240
  }
217
241
  async generateDynamicImg(
218
242
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
219
- data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, }) {
243
+ data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, } = {}) {
220
244
  // module_author
221
245
  const module_author = data.modules.module_author;
222
246
  const avatarUrl = module_author.face;
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.0.4",
4
+ "version": "3.0.5-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -30,6 +30,8 @@
30
30
  "axios": "^1.7.9",
31
31
  "axios-cookiejar-support": "^5.0.5",
32
32
  "blive-message-listener": "^0.5.0",
33
+ "imagemin": "^9.0.1",
34
+ "imagemin-pngquant": "^10.0.0",
33
35
  "jsdom": "^24.1.3",
34
36
  "luxon": "^3.5.0",
35
37
  "md5": "^2.3.0",
@@ -39,6 +41,7 @@
39
41
  },
40
42
  "devDependencies": {
41
43
  "@biomejs/biome": "1.9.4",
44
+ "@types/imagemin": "^9",
42
45
  "@types/luxon": "^3.4.2",
43
46
  "@types/md5": "^2.3.5",
44
47
  "@types/qrcode": "^1.5.5",
package/readme.md CHANGED
@@ -64,6 +64,12 @@
64
64
 
65
65
  - 使用指令 `bili ll`
66
66
 
67
+ 推送指定UP主指定动态:
68
+
69
+ - 使用指令 `bili dyn <uid> [index]`
70
+
71
+ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要推送的动态排序,不应超过15,不填默认第一条。例如要推送UID为 `233` 的UP主的第九条动态 `bili dyn 233 9`
72
+
67
73
  插件的启动、停止和重启
68
74
 
69
75
  - 使用指令 `sys`
@@ -221,6 +227,7 @@
221
227
  - ver 3.0.2 优化:动态监测,新增依赖服务 `cron`
222
228
  - ver 3.0.3 移除:配置项 `dynamicLoopTime` ,动态循环时间将不再可选,默认为两分钟
223
229
  - ver 3.0.4 优化:动态监测,增加时间判断,防止出现重复推送问题; 由于 `3.0.2` 动态监测定时器更换为cron定时任务,如果需要测试动态监测功能是否正常,可以通过控制台日志输出观察,打印 `动态监测初始化完毕!` 后,可进行测试
230
+ - ver 3.0.5-alpha.0 优化:推送卡片渲染,压缩图片; 新增:指令 `bili dyn` 可用于推送指定UP主指定动态
224
231
 
225
232
  ## 交流群
226
233