koishi-plugin-ll-schedule 1.7.3 → 1.7.4

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 +43 -17
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -918,30 +918,60 @@ function apply(ctx, config) {
918
918
  return formatTaskList()
919
919
  })
920
920
 
921
- // 自检:把"插件认为的当前时间 / 解析出的活动表 / 下一次提醒时刻"全打出来,便于排查
922
- ctx.command('schedule.debug', '自检:查看当前时间、活动表解析结果、下一次提醒时刻')
923
- .action(() => {
921
+ // 自检:看当前时间 / 活动表解析结果 / 某时刻会触发什么
922
+ // 可加参数模拟,如:schedule.debug 18:58 或 schedule.debug 周四18:58
923
+ ctx.command('schedule.debug [arg:text]', '自检:可加时间模拟(例:schedule.debug 18:58)')
924
+ .action((_, arg) => {
925
+ logger.info(`[schedule] 命令被调用: schedule.debug arg=${arg || ''}`)
924
926
  const now = new Date()
925
- const day = todayDay(now)
926
- const hm = nowHM(now)
927
- const nowMin = hmToMin(hm)
927
+ const nowDay = todayDay(now)
928
928
  const acts = parseActivities(config.activities)
929
929
  const instances = expandInstances(acts)
930
+ let day = nowDay
931
+ let hm = nowHM(now)
932
+ let simulated = false
933
+ if (arg) {
934
+ const tm = String(arg).match(/(\d{1,2}):(\d{2})/)
935
+ if (tm) {
936
+ hm = `${String(tm[1]).padStart(2, '0')}:${tm[2]}`
937
+ simulated = true
938
+ }
939
+ const dm = String(arg).match(/(?:周|星期|礼拜)([一二三四五六日天1-7])/)
940
+ if (dm) {
941
+ const map = { '一': 1, '二': 2, '三': 3, '四': 4, '五': 5, '六': 6, '日': 7, '天': 7 }
942
+ day = map[dm[1]] || parseInt(dm[1], 10) || day
943
+ simulated = true
944
+ }
945
+ }
946
+ const simDate = new Date(now)
947
+ simDate.setDate(now.getDate() + ((day - nowDay + 7) % 7))
948
+
930
949
  const lines = [
931
- `🕐 插件当前时间:${todayStr(now)} ${hm}:${String(now.getSeconds()).padStart(2, '0')}(星期${WEEK_CN[day]})`,
932
- `📋 活动表:解析出 ${acts.length} 个活动 / ${instances.length} 个时段实例`,
950
+ `🕐 插件当前时间:${todayStr(now)} ${nowHM(now)}:${String(now.getSeconds()).padStart(2, '0')}(星期${WEEK_CN[nowDay]})`,
951
+ `📋 活动表:${acts.length} 个活动 / ${instances.length} 个时段实例`,
933
952
  ]
934
953
  for (const a of acts) {
935
- lines.push(`【${a.name}】提前 ${a.advance} 分钟,${a.slots.length} 行`)
954
+ lines.push(`【${a.name}】提前 ${a.advance} 分钟`)
936
955
  for (const s of a.slots) {
937
- lines.push(` · ${s.wd} ${s.start}-${s.end}${s.place ? ' 地点:' + s.place : ''}`)
956
+ lines.push(` · ${s.wd} ${s.start}-${s.end}${s.place ? ' ' + s.place : ''}`)
938
957
  }
939
958
  }
940
- // 下一次提醒
959
+ const label = `${simulated ? '模拟' : '当前'} ${todayStr(simDate)} ${hm}(星期${WEEK_CN[day]})`
960
+ const hits = computeReminders(acts, simDate, hm)
961
+ if (hits.length) {
962
+ for (const h of hits) {
963
+ lines.push(`🔔 ${label} 会触发:「${h.inst.activity}」${h.inst.start}-${h.inst.end}${h.inst.place ? ' ' + h.inst.place : ''}(提前 ${h.inst.advance} 分钟)`)
964
+ }
965
+ }
966
+ else {
967
+ lines.push(`🔔 ${label} 不会触发任何提醒`)
968
+ }
969
+ // 下一次提醒(按当前时刻往后算)
970
+ const nowMin = hmToMin(nowHM(now))
941
971
  let best = null
942
972
  for (const inst of instances) {
943
973
  const fireMin = inst.startMin - (inst.advance || 0)
944
- let offset = (inst.day - day + 7) % 7
974
+ let offset = (inst.day - nowDay + 7) % 7
945
975
  if (offset === 0 && fireMin <= nowMin) offset = 7
946
976
  const key = offset * 1440 + fireMin
947
977
  if (!best || key < best.key) best = { key, inst, offset, fireMin }
@@ -949,14 +979,10 @@ function apply(ctx, config) {
949
979
  if (best) {
950
980
  const hh = String(Math.floor(best.fireMin / 60)).padStart(2, '0')
951
981
  const mm = String(best.fireMin % 60).padStart(2, '0')
952
- const when = best.offset === 0 ? '今天' : `星期${WEEK_CN[((day - 1 + best.offset) % 7) + 1]}`
982
+ const when = best.offset === 0 ? '今天' : `星期${WEEK_CN[((nowDay - 1 + best.offset) % 7) + 1]}`
953
983
  lines.push(`⏭ 下一次提醒:「${best.inst.activity}」${when} ${hh}:${mm}(活动 ${best.inst.start}-${best.inst.end}${best.inst.place ? ' ' + best.inst.place : ''})`)
954
984
  }
955
- else {
956
- lines.push('⏭ 下一次提醒:(活动表为空)')
957
- }
958
985
  lines.push(`💾 已订阅群:${(subs.get(ALL) || new Map()).size} 个`)
959
- logger.info('[schedule] 命令被调用: schedule.debug')
960
986
  return lines.join('\n')
961
987
  })
962
988
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
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": [
@@ -35,3 +35,4 @@
35
35
 
36
36
 
37
37
 
38
+