koishi-plugin-group-analysis-mx 1.2.6 → 1.2.7

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.
@@ -54,6 +54,15 @@ class RendererService extends koishi_1.Service {
54
54
  return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
55
55
  }
56
56
  }
57
+ /** 往渲染 HTML 注入 emoji 字体栈,避免 puppeteer 截图时 emoji 显示为方框/问号。 */
58
+ injectEmojiFont(html) {
59
+ if (!html || typeof html !== 'string')
60
+ return html;
61
+ const style = `<style>html,body{font-family:-apple-system,'Segoe UI','Segoe UI Emoji','Noto Sans SC','Noto Color Emoji','Apple Color Emoji','Microsoft YaHei','Hiragino Sans GB',sans-serif !important;}</style>`;
62
+ if (html.includes('</head>'))
63
+ return html.replace('</head>', style + '</head>');
64
+ return html;
65
+ }
57
66
  async init() {
58
67
  const resourcesDir = __dirname + '/../../resources';
59
68
  const templateDir = this.templateDir;
@@ -184,7 +193,7 @@ class RendererService extends koishi_1.Service {
184
193
  dynamicAvatarUrl: dynamicAvatarBase64
185
194
  });
186
195
  // 写入临时 HTML 文件
187
- await fs_1.promises.writeFile(outTemplateHtmlPath, filledHtml);
196
+ await fs_1.promises.writeFile(outTemplateHtmlPath, this.injectEmojiFont(filledHtml));
188
197
  this.ctx.logger.info('HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
189
198
  const page = await this.ctx.puppeteer.page();
190
199
  // 重新加载页面并使用 goto 访问本地文件
@@ -255,7 +264,7 @@ class RendererService extends koishi_1.Service {
255
264
  const html = env.render('html_template.html', context);
256
265
  const randomId = Math.random().toString(36).substring(2, 15);
257
266
  const outTemplateHtmlPath = path_1.default.resolve(skinDir, `${randomId}.html`);
258
- await fs_1.promises.writeFile(outTemplateHtmlPath, html);
267
+ await fs_1.promises.writeFile(outTemplateHtmlPath, this.injectEmojiFont(html));
259
268
  this.ctx.logger.info(`原项目皮肤 ${skin} HTML 生成完成,正在调用 Puppeteer 渲染...`);
260
269
  const page = await this.ctx.puppeteer.page();
261
270
  await page.setViewport({ width: 1080, height: 1920, deviceScaleFactor: 2 });
@@ -471,7 +480,7 @@ class RendererService extends koishi_1.Service {
471
480
  theme,
472
481
  dynamicAvatarUrl: dynamicAvatarBase64
473
482
  });
474
- await fs_1.promises.writeFile(outTemplateHtmlPath, filledHtml);
483
+ await fs_1.promises.writeFile(outTemplateHtmlPath, this.injectEmojiFont(filledHtml));
475
484
  this.ctx.logger.info('用户画像 HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
476
485
  const page = await this.ctx.puppeteer.page();
477
486
  // 重新加载页面并使用 goto 访问本地文件
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-analysis-mx",
3
3
  "description": "群聊分析插件 - 生成精美群聊统计报告,支持 AI 话题总结(独立版,不依赖 ChatLuna)",
4
- "version": "1.2.6",
4
+ "version": "1.2.7",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",