koishi-plugin-dwrgbwiki 2.0.4 → 2.0.5

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.
Files changed (2) hide show
  1. package/index.js +28 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -8,6 +8,7 @@ const codex = require('./codex')
8
8
  const wiki = require('./wiki')
9
9
  const cangtou = require('./cangtou')
10
10
  const match = require('./match')
11
+ const notice = require('./notice')
11
12
 
12
13
  const HELP = lib.buildHelp()
13
14
 
@@ -1338,11 +1339,27 @@ async function sendNoticeMessage(ctx, config, content, logger) {
1338
1339
  }
1339
1340
  }
1340
1341
 
1342
+ // 公告渲染为图片推送;失败(无 puppeteer / 渲染出错)返回 false,由调用方回退文本
1343
+ // changed 为 diffNotice 结果(非空时仅渲染变化部分),为 null 时渲染完整公告
1344
+ async function sendNoticeImage(ctx, config, parsed, header, logger, sourceName, changed) {
1345
+ if (!ctx.puppeteer) return false
1346
+ try {
1347
+ const width = config.width || 1300
1348
+ const html = notice.buildNoticeHtml(parsed, { ...config, width, sourceName }, changed)
1349
+ const image = await capture(ctx, html, { ...config, width })
1350
+ return await sendNoticeMessage(ctx, config, [header, h.image(image, 'image/png')], logger)
1351
+ } catch (e) {
1352
+ logger.warn('公告图片渲染失败: ' + (e && e.message ? e.message : e))
1353
+ return false
1354
+ }
1355
+ }
1356
+
1341
1357
  function startNoticeMonitor(ctx, config) {
1342
1358
  const logger = ctx.logger('dwrgbwiki')
1343
1359
  const timeout = Math.max(config.timeout || 15000, 20000)
1344
- // 上次内容哈希:key -> hash
1360
+ // 上次内容哈希:key -> hash;上次解析结果:key -> parsed(用于增量 diff)
1345
1361
  let lastHash = {}
1362
+ let lastParsed = {}
1346
1363
  let running = false
1347
1364
 
1348
1365
  const check = async () => {
@@ -1355,12 +1372,20 @@ function startNoticeMonitor(ctx, config) {
1355
1372
  const hash = require('crypto').createHash('sha256').update(text).digest('hex')
1356
1373
  const prev = lastHash[item.key]
1357
1374
  lastHash[item.key] = hash
1375
+ const parsed = notice.parseNoticeCached(text)
1376
+ const prevParsed = lastParsed[item.key] || null
1377
+ lastParsed[item.key] = parsed
1358
1378
  // 首次运行只记录,不推送;之后变动才推送
1359
1379
  if (prev !== undefined && prev !== hash) {
1360
1380
  const { title, body } = parseNotice(text)
1361
1381
  const header = '【' + item.name + '公告更新】' + (title ? '「' + title + '」' : '')
1362
- const content = [header, '', body].join('\n')
1363
- await sendNoticeMessage(ctx, config, content, logger)
1382
+ // 优先渲染为图片推送(仅变化部分),失败时回退纯文本摘要
1383
+ const changed = prevParsed ? notice.diffNotice(prevParsed, parsed) : null
1384
+ const sent = await sendNoticeImage(ctx, config, parsed, header, logger, item.name, changed && changed.hasChange ? changed : null)
1385
+ if (!sent) {
1386
+ const content = [header, '', body].join('\n')
1387
+ await sendNoticeMessage(ctx, config, content, logger)
1388
+ }
1364
1389
  }
1365
1390
  } catch (e) {
1366
1391
  logger.warn('公告检查失败(' + item.key + '): ' + (e && e.message ? e.message : e))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-dwrgbwiki",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "第五人格BWIKI编辑组开发,所有代码由DeepSeek V4 Flash 0731编写。支持胜率/地图/模仿者/勋章/基础数据查询、图鉴查询、wiki页面截图、藏头诗、抽卡模拟、加页手记探索、赛事数据(选手/对决)、公告变动推送、反馈系统等功能。",
5
5
  "main": "index.js",
6
6
  "files": [