koishi-plugin-ll-schedule 1.7.1 → 1.7.2

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 -8
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -310,6 +310,24 @@ function findNextInstance(instances, current) {
310
310
  return best
311
311
  }
312
312
 
313
+ // 从某一时刻(date+hm)往后找最近的一场(用于测试:按"现在"算下一场)
314
+ function findNextFromNow(instances, date, hm) {
315
+ const day = todayDay(date)
316
+ const nowMin = hmToMin(hm)
317
+ let best = null
318
+ let bestKey = Infinity
319
+ for (const inst of instances) {
320
+ let offset = (inst.day - day + 7) % 7
321
+ if (offset === 0 && inst.startMin < nowMin) offset = 7
322
+ const key = offset * 1440 + inst.startMin
323
+ if (key < bestKey) {
324
+ bestKey = key
325
+ best = inst
326
+ }
327
+ }
328
+ return best
329
+ }
330
+
313
331
  // 计算"现在这一分钟该发哪些提前提醒"
314
332
  function computeReminders(activities, date, hm) {
315
333
  const day = todayDay(date)
@@ -360,7 +378,7 @@ function renderRemindTemplate(tpl, vars) {
360
378
  return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim()
361
379
  }
362
380
 
363
- exports._test = { parseTimes, todayDay, parseDays, dayMatches, parseScheduleBlocks, parseScheduleRows, summarizeRows, computeFires, renderText, renderPushTemplate, hmToMin, parseActivities, expandInstances, findNextInstance, computeReminders, renderRemindTemplate, DEFAULT_REMIND_TPL, buildMd, buildTextFromMd }
381
+ exports._test = { parseTimes, todayDay, parseDays, dayMatches, parseScheduleBlocks, parseScheduleRows, summarizeRows, computeFires, renderText, renderPushTemplate, hmToMin, parseActivities, expandInstances, findNextInstance, findNextFromNow, computeReminders, renderRemindTemplate, DEFAULT_REMIND_TPL, buildMd, buildTextFromMd }
364
382
 
365
383
  // ===== 配置 Schema =====
366
384
 
@@ -907,21 +925,38 @@ function apply(ctx, config) {
907
925
  })
908
926
 
909
927
  // 活动表模式下:把某个活动的提醒测试发到当前群;返回 null 表示当前不是活动表模式
928
+ // 测试一律以"现在"为基准:
929
+ // · 指定活动名 → 取该活动从此刻起最近的一次
930
+ // · 不指定 → 直接取此刻之后最近的一次提醒(等于"下一条会发的提醒")
931
+ // · "下一时段活动"也按此刻往后算
910
932
  async function testActivityToGroup(session, name) {
911
933
  const acts = parseActivities(config.activities)
912
934
  if (!acts.length) return null
913
- const act = name
914
- ? (acts.find(a => a.name === name) || acts.find(a => a.name.includes(name)))
915
- : acts[0]
916
- if (!act) return `未找到活动 "${name}",可用 schedule.list 查看活动表`
917
935
  const instances = expandInstances(acts)
918
- const inst = instances.find(i => i.activity === act.name)
919
936
  const now = new Date()
920
- const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, findNextInstance(instances, inst), now, nowHM(now)))
937
+ const hm = nowHM(now)
938
+ const act = name
939
+ ? (acts.find(a => a.name === name) || acts.find(a => a.name.includes(name)))
940
+ : null
941
+ if (name && !act) return `未找到活动 "${name}",可用 schedule.list 查看活动表`
942
+
943
+ let inst
944
+ if (act) {
945
+ const own = instances.filter(i => i.activity === act.name)
946
+ inst = findNextFromNow(own, now, hm) || own[0]
947
+ }
948
+ else {
949
+ inst = findNextFromNow(instances, now, hm) || instances[0]
950
+ }
951
+ if (!inst) return '活动表里还没有可用的时段'
952
+ // 下一场:按"现在"往后算,并排除自己
953
+ const next = findNextFromNow(instances.filter(i => i !== inst), now, hm)
954
+
955
+ const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
921
956
  const bot = (ctx.bots || []).find(b => b.sid === session.bot?.sid)
922
957
  if (!bot || !session.guildId) return '❌ 只能在群里测试'
923
958
  await sendOne(bot, String(session.guildId), text, { markdown: !!config.remindMarkdown })
924
- return `✅ 已向本群测试发送「${act.name}」的提醒`
959
+ return `✅ 已向本群测试发送「${inst.activity}」的提醒(星期${WEEK_CN[inst.day]} ${inst.start})`
925
960
  }
926
961
 
927
962
  ctx.command('schedule.test [name:text]', '测试发送提醒(发到当前群)')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
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": [
@@ -33,3 +33,4 @@
33
33
 
34
34
 
35
35
 
36
+