koishi-plugin-bilibili-notify 3.0.0-alpha.11 → 3.0.0-alpha.12

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.
@@ -12,7 +12,6 @@ const koishi_1 = require("koishi");
12
12
  const qrcode_1 = __importDefault(require("qrcode"));
13
13
  // 弹幕词云
14
14
  const segmentit_1 = require("segmentit");
15
- const canvas_1 = require("canvas");
16
15
  const d3_cloud_1 = __importDefault(require("d3-cloud"));
17
16
  var LiveType;
18
17
  (function (LiveType) {
@@ -1462,22 +1461,22 @@ class ComRegister {
1462
1461
  // 创建画布
1463
1462
  const width = 800;
1464
1463
  const height = 600;
1465
- const canvas = (0, canvas_1.createCanvas)(width, height);
1466
- const context = canvas.getContext('2d');
1467
1464
  // 定义绘制函数
1468
- const draw = (words) => {
1469
- context.clearRect(0, 0, width, height);
1470
- context.fillStyle = '#fff';
1471
- context.fillRect(0, 0, width, height);
1472
- words.forEach(function (d) {
1473
- context.font = `${d.size}px Arial`;
1474
- context.fillStyle = '#000';
1475
- context.fillText(d.text, d.x, d.y);
1476
- });
1477
- // 保存画布为buffer
1478
- const buffer = canvas.toBuffer('image/png');
1465
+ const generateSVG = async (words) => {
1466
+ // 定义svg头部
1467
+ const svgHeader = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">`;
1468
+ // 定义svg尾部
1469
+ const svgFooter = '</svg>';
1470
+ // 定义svg身体
1471
+ const svgBody = words.map(d => {
1472
+ return `<text x="${d.x}" y="${d.y}" font-family="Arial" font-size="${d.size}" fill="black">${d.text}</text>`;
1473
+ }).join('\n');
1474
+ // 拼接svg
1475
+ const svgContent = svgHeader + svgBody + svgFooter;
1476
+ // 渲染svg
1477
+ const pic = await this.ctx.gi.generateWordCloudImg(svgContent);
1479
1478
  // 发送消息
1480
- this.sendMsg(target, koishi_1.h.image(buffer, 'image/png'));
1479
+ this.sendMsg(target, pic);
1481
1480
  };
1482
1481
  // 配置词云
1483
1482
  const layout = (0, d3_cloud_1.default)()
@@ -1486,7 +1485,7 @@ class ComRegister {
1486
1485
  .padding(5)
1487
1486
  .font('Arial')
1488
1487
  .fontSize(d => d.size)
1489
- .on('end', draw);
1488
+ .on('end', generateSVG);
1490
1489
  // 生成词云
1491
1490
  layout.start();
1492
1491
  };
@@ -24,6 +24,7 @@ declare class GenerateImg extends Service {
24
24
  link: string;
25
25
  buffer?: undefined;
26
26
  }>;
27
+ generateWordCloudImg(svgContent: string): Promise<string>;
27
28
  getLiveStatus(time: string, liveStatus: number): Promise<[string, string, boolean]>;
28
29
  getTimeDifference(dateString: string): Promise<string>;
29
30
  unixTimestampToString(timestamp: number): string;
@@ -1407,6 +1407,12 @@ class GenerateImg extends koishi_1.Service {
1407
1407
  }
1408
1408
  }
1409
1409
  }
1410
+ async generateWordCloudImg(svgContent) {
1411
+ // 渲染图片
1412
+ const pic = await this.ctx.puppeteer.render(svgContent);
1413
+ // 返回图片
1414
+ return pic;
1415
+ }
1410
1416
  async getLiveStatus(time, liveStatus) {
1411
1417
  let titleStatus;
1412
1418
  let liveTime;
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.0-alpha.11",
4
+ "version": "3.0.0-alpha.12",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -30,7 +30,6 @@
30
30
  "axios": "^1.7.9",
31
31
  "axios-cookiejar-support": "^5.0.5",
32
32
  "blive-message-listener": "^0.5.0",
33
- "canvas": "^3.1.0",
34
33
  "d3-cloud": "^1.2.7",
35
34
  "jsdom": "^24.1.3",
36
35
  "luxon": "^3.5.0",
package/readme.md CHANGED
@@ -223,6 +223,7 @@
223
223
  - ver 3.0.0-alpha.9 优化:加强直播推送对获取直播信息的错误处理
224
224
  - ver 3.0.0-alpha.10 修复:连续推送两次开播通知
225
225
  - ver 3.0.0-alpha.11 新增:直播结束后推送弹幕词云,直播推送上舰消息; 修复:直播推送都是同一张画面; 移除:直播推送弹幕消息
226
+ - ver 3.0.0-alpha.12 修复:上一版本无法安装
226
227
 
227
228
  ## 交流群
228
229