koishi-plugin-ll-schedule 1.7.9 → 1.7.11

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 +26 -6
  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
 
@@ -812,7 +822,8 @@ function apply(ctx, config) {
812
822
  try {
813
823
  await sendOne(bot, target, text, { markdown, image })
814
824
  sent++
815
- if (config.verbose) logger.info(`[schedule] 提醒已发 ${bot.sid}:${target}`)
825
+ // 记录"实际发出的内容首行 + 目标群",便于事后核对发错/漏发
826
+ logger.info(`[schedule] 已发出 → ${bot.sid}:${target}|${String(text).split('\n')[0].slice(0, 60)}`)
816
827
  }
817
828
  catch (e) {
818
829
  logger.error(`[schedule] 提醒发送失败 ${bot.sid}:${target}: ${errDetail(e)}`)
@@ -842,7 +853,7 @@ function apply(ctx, config) {
842
853
 
843
854
  // 渲染并发送一条活动提醒
844
855
  async function sendReminder(inst, next, now, hm) {
845
- const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
856
+ const text = renderRemindTemplate(resolveRemindTemplate(config.remindTemplate), makeRemindVars(inst, next, now, hm))
846
857
  if (!text) return
847
858
  logger.info(`[schedule] 活动提醒「${inst.activity}」开始于 ${inst.start}(提前 ${inst.advance} 分钟)`)
848
859
  await sendToSubscribers(text, { markdown: !!config.remindMarkdown })
@@ -1001,6 +1012,10 @@ function apply(ctx, config) {
1001
1012
  }
1002
1013
  }
1003
1014
  const label = `${simulated ? '模拟' : '当前'} ${todayStr(simDate)} ${hm}(星期${WEEK_CN[day]})`
1015
+ const tplSrc = String(config.remindTemplate || '').trim()
1016
+ const tplUsed = resolveRemindTemplate(config.remindTemplate)
1017
+ lines.push(`📝 提醒模板:${!tplSrc ? '(默认)' : (tplUsed === DEFAULT_REMIND_TPL ? '⚠️ 自定义模板里没有 {activity} 变量,已被忽略、正在用默认模板' : '(自定义)')}`)
1018
+ for (const l of tplUsed.split('\n')) lines.push(` ${l}`)
1004
1019
  const hits = computeReminders(acts, simDate, hm)
1005
1020
  if (hits.length) {
1006
1021
  for (const h of hits) {
@@ -1070,7 +1085,7 @@ function apply(ctx, config) {
1070
1085
  // 下一场:按"现在"往后算,并排除自己
1071
1086
  const next = findNextFromNow(instances.filter(i => i !== inst), now, hm)
1072
1087
 
1073
- const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
1088
+ const text = renderRemindTemplate(resolveRemindTemplate(config.remindTemplate), makeRemindVars(inst, next, now, hm))
1074
1089
  const bot = (ctx.bots || []).find(b => b.sid === session.bot?.sid)
1075
1090
  if (!bot || !session.guildId) return '❌ 只能在群里测试'
1076
1091
  await sendOne(bot, String(session.guildId), text, { markdown: !!config.remindMarkdown })
@@ -1224,8 +1239,13 @@ function apply(ctx, config) {
1224
1239
  return lines.join('\n')
1225
1240
  })
1226
1241
 
1227
- logger.info('[schedule] 命令已注册: schedule / schedule.list / schedule.groups / schedule.test / ' +
1228
- `"订阅" / "取消订阅" / 订阅列表 / 我的ID`)
1242
+ logger.info('[schedule] 命令已注册: schedule / schedule.list / schedule.debug / schedule.groups / schedule.test / ' +
1243
+ `"剑灵提醒订阅" / "取消剑灵订阅" / 订阅列表 / 我的ID`)
1244
+
1245
+ // 启动检查:自定义提醒模板若不含 {activity} 变量,会被忽略(否则所有提醒内容会长得一样)
1246
+ if (config.remindTemplate && String(config.remindTemplate).trim() && !String(config.remindTemplate).includes('{activity}')) {
1247
+ logger.warn('[schedule] 自定义提醒模板里没有 {activity} 变量 → 已自动忽略它、改用默认模板')
1248
+ }
1229
1249
 
1230
1250
  Promise.all([loadKnownGroups(), loadSubs()])
1231
1251
  .then(() => migrateToAll())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
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": [
@@ -19,3 +19,5 @@
19
19
  }
20
20
  }
21
21
 
22
+
23
+