koishi-plugin-ll-schedule 1.7.10 → 1.7.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.
Files changed (2) hide show
  1. package/index.js +29 -5
  2. package/package.json +3 -1
package/index.js CHANGED
@@ -368,6 +368,16 @@ const DEFAULT_REMIND_TPL = [
368
368
  '{{/next}}',
369
369
  ].join('\n')
370
370
 
371
+ // 选取实际使用的提醒模板:
372
+ // 自定义模板必须包含 {activity} 变量,否则一律用默认模板
373
+ // (防止有人把模板写成一段固定文案,导致所有提醒发出来长得一模一样)
374
+ function resolveRemindTemplate(custom) {
375
+ const tpl = String(custom || '').trim()
376
+ if (!tpl) return DEFAULT_REMIND_TPL
377
+ if (!tpl.includes('{activity}')) return DEFAULT_REMIND_TPL
378
+ return tpl
379
+ }
380
+
371
381
  // 渲染提醒模板:{变量} 替换;含空变量的整行自动删除;{{#key}}...{{/key}} 条件块(变量为空则整块删除)
372
382
  function renderRemindTemplate(tpl, vars) {
373
383
  let out = String(tpl || DEFAULT_REMIND_TPL)
@@ -388,7 +398,7 @@ function renderRemindTemplate(tpl, vars) {
388
398
  return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim()
389
399
  }
390
400
 
391
- exports._test = { parseTimes, todayDay, parseDays, dayMatches, parseScheduleBlocks, parseScheduleRows, summarizeRows, computeFires, renderText, renderPushTemplate, hmToMin, parseActivities, expandInstances, findNextInstance, findNextFromNow, computeReminders, renderRemindTemplate, DEFAULT_REMIND_TPL, buildMd, buildTextFromMd }
401
+ exports._test = { parseTimes, todayDay, parseDays, dayMatches, parseScheduleBlocks, parseScheduleRows, summarizeRows, computeFires, renderText, renderPushTemplate, hmToMin, parseActivities, expandInstances, findNextInstance, findNextFromNow, computeReminders, renderRemindTemplate, resolveRemindTemplate, DEFAULT_REMIND_TPL, buildMd, buildTextFromMd }
392
402
 
393
403
  // ===== 配置 Schema =====
394
404
 
@@ -843,8 +853,13 @@ function apply(ctx, config) {
843
853
 
844
854
  // 渲染并发送一条活动提醒
845
855
  async function sendReminder(inst, next, now, hm) {
846
- const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
856
+ const text = renderRemindTemplate(resolveRemindTemplate(config.remindTemplate), makeRemindVars(inst, next, now, hm))
847
857
  if (!text) return
858
+ // 防串内容:渲染出来的内容必须包含该活动的名字,否则拒发并报警
859
+ if (!text.includes(inst.activity)) {
860
+ logger.error(`[schedule] 渲染内容与活动不匹配(应为「${inst.activity}」),已拒发|首行:${String(text).split('\n')[0]}`)
861
+ return
862
+ }
848
863
  logger.info(`[schedule] 活动提醒「${inst.activity}」开始于 ${inst.start}(提前 ${inst.advance} 分钟)`)
849
864
  await sendToSubscribers(text, { markdown: !!config.remindMarkdown })
850
865
  }
@@ -1002,6 +1017,10 @@ function apply(ctx, config) {
1002
1017
  }
1003
1018
  }
1004
1019
  const label = `${simulated ? '模拟' : '当前'} ${todayStr(simDate)} ${hm}(星期${WEEK_CN[day]})`
1020
+ const tplSrc = String(config.remindTemplate || '').trim()
1021
+ const tplUsed = resolveRemindTemplate(config.remindTemplate)
1022
+ lines.push(`📝 提醒模板:${!tplSrc ? '(默认)' : (tplUsed === DEFAULT_REMIND_TPL ? '⚠️ 自定义模板里没有 {activity} 变量,已被忽略、正在用默认模板' : '(自定义)')}`)
1023
+ for (const l of tplUsed.split('\n')) lines.push(` ${l}`)
1005
1024
  const hits = computeReminders(acts, simDate, hm)
1006
1025
  if (hits.length) {
1007
1026
  for (const h of hits) {
@@ -1071,7 +1090,7 @@ function apply(ctx, config) {
1071
1090
  // 下一场:按"现在"往后算,并排除自己
1072
1091
  const next = findNextFromNow(instances.filter(i => i !== inst), now, hm)
1073
1092
 
1074
- const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
1093
+ const text = renderRemindTemplate(resolveRemindTemplate(config.remindTemplate), makeRemindVars(inst, next, now, hm))
1075
1094
  const bot = (ctx.bots || []).find(b => b.sid === session.bot?.sid)
1076
1095
  if (!bot || !session.guildId) return '❌ 只能在群里测试'
1077
1096
  await sendOne(bot, String(session.guildId), text, { markdown: !!config.remindMarkdown })
@@ -1225,8 +1244,13 @@ function apply(ctx, config) {
1225
1244
  return lines.join('\n')
1226
1245
  })
1227
1246
 
1228
- logger.info('[schedule] 命令已注册: schedule / schedule.list / schedule.groups / schedule.test / ' +
1229
- `"订阅" / "取消订阅" / 订阅列表 / 我的ID`)
1247
+ logger.info('[schedule] 命令已注册: schedule / schedule.list / schedule.debug / schedule.groups / schedule.test / ' +
1248
+ `"剑灵提醒订阅" / "取消剑灵订阅" / 订阅列表 / 我的ID`)
1249
+
1250
+ // 启动检查:自定义提醒模板若不含 {activity} 变量,会被忽略(否则所有提醒内容会长得一样)
1251
+ if (config.remindTemplate && String(config.remindTemplate).trim() && !String(config.remindTemplate).includes('{activity}')) {
1252
+ logger.warn('[schedule] 自定义提醒模板里没有 {activity} 变量 → 已自动忽略它、改用默认模板')
1253
+ }
1230
1254
 
1231
1255
  Promise.all([loadKnownGroups(), loadSubs()])
1232
1256
  .then(() => migrateToAll())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.7.10",
3
+ "version": "1.7.12",
4
4
  "description": "BNS activity reminder: one activity table, one-click subscribe, auto reminders with time/place/next-up, QQ official markdown card support",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -20,3 +20,5 @@
20
20
  }
21
21
 
22
22
 
23
+
24
+