koishi-plugin-group-analysis-mx 1.3.4 → 1.3.6

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.
@@ -8,7 +8,6 @@ const koishi_1 = require("koishi");
8
8
  const fs_1 = require("fs");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const nunjucks = require("nunjucks");
11
- const twemoji = require("twemoji");
12
11
  const utils_1 = require("../utils");
13
12
  const skins_1 = require("../skins");
14
13
  /** 来自原项目 astrbot_plugin_qq_group_daily_analysis 的皮肤(Jinja2 模板,用 nunjucks 渲染) */
@@ -73,32 +72,14 @@ class RendererService extends koishi_1.Service {
73
72
  return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
74
73
  }
75
74
  }
76
- /** HTML 中的 emoji 字符替换成 <img>(Twemoji 在线 CDN 图片),避免 Chromium emoji 字体时渲染成方框。 */
75
+ /** 不做 emoji 处理(与 ChatLuna 原版一致)。Chromium 能正常渲染 emoji,之前的处理反而制造问题。 */
77
76
  async injectEmojiFont(html) {
78
- if (!html || typeof html !== 'string')
79
- return html;
80
- try {
81
- const base = 'https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/';
82
- let out = twemoji.parse(html, { base, folder: 'svg', ext: '.svg', className: 'twemoji' });
83
- const sizeCss = '<style>.twemoji{height:1em;width:1em;vertical-align:middle;display:inline-block;}</style>';
84
- return out.includes('</head>')
85
- ? out.replace('</head>', sizeCss + '</head>')
86
- : out;
87
- }
88
- catch (e) {
89
- this.ctx.logger.warn('emoji 图片替换失败:', e);
90
- return html;
91
- }
77
+ return html;
92
78
  }
93
79
  async init() {
94
80
  const resourcesDir = __dirname + '/../../resources';
95
81
  const templateDir = this.templateDir;
96
82
  const skin = this.config.skin || 'md3';
97
- // 拷贝内嵌的 Twemoji 图片到 data 目录(emoji 用 <img> 渲染,不走 Chromium 字体系统,跨环境可靠)
98
- const twemojiSrcDir = path_1.default.resolve(resourcesDir, 'twemoji');
99
- const twemojiDestDir = path_1.default.resolve(templateDir, 'twemoji');
100
- await fs_1.promises.mkdir(twemojiDestDir, { recursive: true });
101
- await fs_1.promises.cp(twemojiSrcDir, twemojiDestDir, { recursive: true });
102
83
  // 创建空 HTML 占位:渲染时先 goto 它(建立 file:// base),再 setContent 注入内容,@font-face 相对字体才能被加载
103
84
  const emptyHtmlPath = ORIGINAL_SKINS.includes(skin)
104
85
  ? path_1.default.resolve(templateDir, 'original', skin, 'emptyHtml.html')
@@ -251,12 +232,8 @@ class RendererService extends koishi_1.Service {
251
232
  await fs_1.promises.writeFile(outTemplateHtmlPath, await this.injectEmojiFont(filledHtml));
252
233
  this.ctx.logger.info('HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
253
234
  const page = await this.ctx.puppeteer.page();
254
- // goto HTML 建立 file:// base,再 setContent 注入内容(@font-face 相对字体才能被加载)
255
- await this.ensureEmptyHtml();
256
- await page.goto('file://' + this.emptyHtmlPath(), {
257
- waitUntil: 'domcontentloaded'
258
- });
259
- await page.setContent(await this.injectEmojiFont(filledHtml), {
235
+ // ChatLuna 原版一致:直接 goto 临时 HTML(不 handle emoji,由 Chromium 正常渲染)
236
+ await page.goto('file://' + outTemplateHtmlPath, {
260
237
  waitUntil: 'domcontentloaded'
261
238
  });
262
239
  this.ctx.logger.info('网页加载完成,开始等待字体加载。');
@@ -328,14 +305,10 @@ class RendererService extends koishi_1.Service {
328
305
  this.ctx.logger.info(`原项目皮肤 ${skin} HTML 生成完成,正在调用 Puppeteer 渲染...`);
329
306
  const page = await this.ctx.puppeteer.page();
330
307
  await page.setViewport({ width: 1080, height: 1920, deviceScaleFactor: 2 });
331
- await this.ensureEmptyHtml();
332
- await page.goto('file://' + this.emptyHtmlPath(), {
333
- waitUntil: 'domcontentloaded'
334
- });
335
- await page.setContent(emojiHtmlOriginal, {
308
+ await page.goto('file://' + outTemplateHtmlPath, {
336
309
  waitUntil: 'networkidle0',
337
310
  timeout: 60000
338
- }).catch(() => page.setContent(emojiHtmlOriginal, {
311
+ }).catch(() => page.goto('file://' + outTemplateHtmlPath, {
339
312
  waitUntil: 'domcontentloaded',
340
313
  timeout: 60000
341
314
  }));
@@ -547,12 +520,8 @@ class RendererService extends koishi_1.Service {
547
520
  await fs_1.promises.writeFile(outTemplateHtmlPath, await this.injectEmojiFont(filledHtml));
548
521
  this.ctx.logger.info('用户画像 HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
549
522
  const page = await this.ctx.puppeteer.page();
550
- // goto HTML 建立 file:// base,再 setContent 注入内容(@font-face 相对字体才能被加载)
551
- await this.ensureEmptyHtml();
552
- await page.goto('file://' + this.emptyHtmlPath(), {
553
- waitUntil: 'domcontentloaded'
554
- });
555
- await page.setContent(await this.injectEmojiFont(filledHtml), {
523
+ // ChatLuna 原版一致:直接 goto 临时 HTML(不 handle emoji,由 Chromium 正常渲染)
524
+ await page.goto('file://' + outTemplateHtmlPath, {
556
525
  waitUntil: 'domcontentloaded'
557
526
  });
558
527
  this.ctx.logger.info('网页加载完成,开始等待字体加载。');
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.3.4",
4
+ "version": "1.3.6",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -26,8 +26,7 @@
26
26
  "js-yaml": "^4.1.0",
27
27
  "zod": "^3.25.0",
28
28
  "cron-parser": "^5.5.0",
29
- "nunjucks": "^3.2.4",
30
- "twemoji": "^14.0.2"
29
+ "nunjucks": "^3.2.4"
31
30
  },
32
31
  "devDependencies": {
33
32
  "koishi": "^4.18.0",