koishi-plugin-ll-schedule 1.7.4 → 1.7.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.
Files changed (2) hide show
  1. package/index.js +37 -2
  2. package/package.json +3 -1
package/index.js CHANGED
@@ -243,6 +243,7 @@ function hmToMin(hm) {
243
243
  function parseActivities(text) {
244
244
  const lines = String(text || '').split(/\r?\n/)
245
245
  const acts = []
246
+ const errors = []
246
247
  let cur = null
247
248
  const pad = (s) => (String(s).length === 4 ? '0' + s : String(s))
248
249
  for (const raw of lines) {
@@ -262,12 +263,22 @@ function parseActivities(text) {
262
263
  if (/^[#/]/.test(line)) continue // 注释行
263
264
  // 时段行:星期 开始-结束 [地点:xxx]
264
265
  const m = line.match(/^(\S+)\s+(\d{1,2}:\d{2})\s*[-~—至]\s*(\d{1,2}:\d{2})\s*(.*)$/)
265
- if (!m) continue
266
+ if (!m) {
267
+ errors.push(line)
268
+ continue
269
+ }
266
270
  const rest = (m[4] || '').trim()
267
271
  const pm = rest.match(/地点\s*[::]\s*(.+)$/)
268
272
  cur.slots.push({ wd: m[1], start: pad(m[2]), end: pad(m[3]), place: pm ? pm[1].trim() : rest })
269
273
  }
270
- return acts.filter(a => a.slots.length > 0)
274
+ const out = acts.filter(a => {
275
+ if (a.slots.length) return true
276
+ errors.push(`【${a.name}】下面没有任何可识别的时段行`)
277
+ return false
278
+ })
279
+ // 把"看不懂的行"挂到数组上,供 list/debug 提示(不影响正常调用)
280
+ out.errors = errors
281
+ return out
271
282
  }
272
283
 
273
284
  // 展开成"周内实例"(星期 × 时段)
@@ -627,6 +638,11 @@ function apply(ctx, config) {
627
638
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
628
639
  }
629
640
 
641
+ // 分钟数 → "HH:MM"
642
+ function minToHM(min) {
643
+ return `${String(Math.floor(min / 60) % 24).padStart(2, '0')}:${String(min % 60).padStart(2, '0')}`
644
+ }
645
+
630
646
  // ===== 发送 =====
631
647
  const KNOWN_IGNORE_CODES = new Set([11293, 40034101, 40034105, 304101, 304102])
632
648
 
@@ -829,10 +845,19 @@ function apply(ctx, config) {
829
845
  // ① 活动表模式(有新活动表就只跑它,避免和旧任务重复发)
830
846
  const activities = parseActivities(config.activities)
831
847
  if (activities.length) {
848
+ const nowMin = hmToMin(hm)
832
849
  const reminds = computeReminders(activities, now, hm)
833
850
  for (const r of reminds) {
851
+ // 发送前复核:独立再算一次"这条提醒该在几点发",对不上就拒发(防任何上游错位)
852
+ const fireMin = r.inst.startMin - (r.inst.advance || 0)
853
+ if (fireMin !== nowMin) {
854
+ logger.warn(`[schedule] 触发复核未通过,已拒发:「${r.inst.activity}」提醒点 ${minToHM(fireMin)},当前 ${hm}`)
855
+ continue
856
+ }
834
857
  if (firedToday[r.key]) continue
835
858
  firedToday[r.key] = true
859
+ logger.info(`[schedule] 触发提醒:「${r.inst.activity}」星期${WEEK_CN[r.inst.day]} ${r.inst.start}-${r.inst.end}` +
860
+ `${r.inst.place ? '|' + r.inst.place : ''}|提醒点 ${minToHM(fireMin)}|当前 ${hm}`)
836
861
  await sendReminder(r.inst, r.next, now, hm)
837
862
  }
838
863
  return
@@ -882,6 +907,10 @@ function apply(ctx, config) {
882
907
  }
883
908
  const subCount = (subs.get(ALL) || new Map()).size
884
909
  lines.push('', `已订阅的群:${subCount} 个(发送"订阅列表"查看)`)
910
+ if (acts.errors && acts.errors.length) {
911
+ lines.push(`⚠️ 有 ${acts.errors.length} 行看不懂、已忽略(检查写法:星期 开始-结束,时间要 HH:MM):`)
912
+ for (const e of acts.errors.slice(0, 5)) lines.push(` ✗ ${e}`)
913
+ }
885
914
  return lines.join('\n')
886
915
  }
887
916
  // 旧任务模式
@@ -983,6 +1012,12 @@ function apply(ctx, config) {
983
1012
  lines.push(`⏭ 下一次提醒:「${best.inst.activity}」${when} ${hh}:${mm}(活动 ${best.inst.start}-${best.inst.end}${best.inst.place ? ' ' + best.inst.place : ''})`)
984
1013
  }
985
1014
  lines.push(`💾 已订阅群:${(subs.get(ALL) || new Map()).size} 个`)
1015
+ if (acts.errors && acts.errors.length) {
1016
+ lines.push(`⚠️ 有 ${acts.errors.length} 行看不懂、已忽略(检查写法:星期 开始-结束,时间要 HH:MM):`)
1017
+ for (const e of acts.errors.slice(0, 5)) lines.push(` ✗ ${e}`)
1018
+ }
1019
+ const fired = Object.keys(firedToday).filter(k => k !== 'date')
1020
+ lines.push(`📤 今天已发过的提醒(${firedToday.date || todayStr(now)}):${fired.length ? fired.join('、') : '无'}`)
986
1021
  return lines.join('\n')
987
1022
  })
988
1023
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "Scheduled message sender with weekly slots (per-day time & content), QQ official markdown card support",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -36,3 +36,5 @@
36
36
 
37
37
 
38
38
 
39
+
40
+