koishi-plugin-ll-schedule 1.7.1 → 1.7.3
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.
- package/index.js +85 -8
- package/package.json +3 -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
|
|
|
@@ -900,6 +918,48 @@ function apply(ctx, config) {
|
|
|
900
918
|
return formatTaskList()
|
|
901
919
|
})
|
|
902
920
|
|
|
921
|
+
// 自检:把"插件认为的当前时间 / 解析出的活动表 / 下一次提醒时刻"全打出来,便于排查
|
|
922
|
+
ctx.command('schedule.debug', '自检:查看当前时间、活动表解析结果、下一次提醒时刻')
|
|
923
|
+
.action(() => {
|
|
924
|
+
const now = new Date()
|
|
925
|
+
const day = todayDay(now)
|
|
926
|
+
const hm = nowHM(now)
|
|
927
|
+
const nowMin = hmToMin(hm)
|
|
928
|
+
const acts = parseActivities(config.activities)
|
|
929
|
+
const instances = expandInstances(acts)
|
|
930
|
+
const lines = [
|
|
931
|
+
`🕐 插件当前时间:${todayStr(now)} ${hm}:${String(now.getSeconds()).padStart(2, '0')}(星期${WEEK_CN[day]})`,
|
|
932
|
+
`📋 活动表:解析出 ${acts.length} 个活动 / ${instances.length} 个时段实例`,
|
|
933
|
+
]
|
|
934
|
+
for (const a of acts) {
|
|
935
|
+
lines.push(`【${a.name}】提前 ${a.advance} 分钟,${a.slots.length} 行`)
|
|
936
|
+
for (const s of a.slots) {
|
|
937
|
+
lines.push(` · ${s.wd} ${s.start}-${s.end}${s.place ? ' 地点:' + s.place : ''}`)
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
// 下一次提醒
|
|
941
|
+
let best = null
|
|
942
|
+
for (const inst of instances) {
|
|
943
|
+
const fireMin = inst.startMin - (inst.advance || 0)
|
|
944
|
+
let offset = (inst.day - day + 7) % 7
|
|
945
|
+
if (offset === 0 && fireMin <= nowMin) offset = 7
|
|
946
|
+
const key = offset * 1440 + fireMin
|
|
947
|
+
if (!best || key < best.key) best = { key, inst, offset, fireMin }
|
|
948
|
+
}
|
|
949
|
+
if (best) {
|
|
950
|
+
const hh = String(Math.floor(best.fireMin / 60)).padStart(2, '0')
|
|
951
|
+
const mm = String(best.fireMin % 60).padStart(2, '0')
|
|
952
|
+
const when = best.offset === 0 ? '今天' : `星期${WEEK_CN[((day - 1 + best.offset) % 7) + 1]}`
|
|
953
|
+
lines.push(`⏭ 下一次提醒:「${best.inst.activity}」${when} ${hh}:${mm}(活动 ${best.inst.start}-${best.inst.end}${best.inst.place ? ' ' + best.inst.place : ''})`)
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
lines.push('⏭ 下一次提醒:(活动表为空)')
|
|
957
|
+
}
|
|
958
|
+
lines.push(`💾 已订阅群:${(subs.get(ALL) || new Map()).size} 个`)
|
|
959
|
+
logger.info('[schedule] 命令被调用: schedule.debug')
|
|
960
|
+
return lines.join('\n')
|
|
961
|
+
})
|
|
962
|
+
|
|
903
963
|
ctx.command('schedule.groups', '查看机器人已知的群')
|
|
904
964
|
.action(async () => {
|
|
905
965
|
logger.info('[schedule] 命令被调用: schedule.groups')
|
|
@@ -907,21 +967,38 @@ function apply(ctx, config) {
|
|
|
907
967
|
})
|
|
908
968
|
|
|
909
969
|
// 活动表模式下:把某个活动的提醒测试发到当前群;返回 null 表示当前不是活动表模式
|
|
970
|
+
// 测试一律以"现在"为基准:
|
|
971
|
+
// · 指定活动名 → 取该活动从此刻起最近的一次
|
|
972
|
+
// · 不指定 → 直接取此刻之后最近的一次提醒(等于"下一条会发的提醒")
|
|
973
|
+
// · "下一时段活动"也按此刻往后算
|
|
910
974
|
async function testActivityToGroup(session, name) {
|
|
911
975
|
const acts = parseActivities(config.activities)
|
|
912
976
|
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
977
|
const instances = expandInstances(acts)
|
|
918
|
-
const inst = instances.find(i => i.activity === act.name)
|
|
919
978
|
const now = new Date()
|
|
920
|
-
const
|
|
979
|
+
const hm = nowHM(now)
|
|
980
|
+
const act = name
|
|
981
|
+
? (acts.find(a => a.name === name) || acts.find(a => a.name.includes(name)))
|
|
982
|
+
: null
|
|
983
|
+
if (name && !act) return `未找到活动 "${name}",可用 schedule.list 查看活动表`
|
|
984
|
+
|
|
985
|
+
let inst
|
|
986
|
+
if (act) {
|
|
987
|
+
const own = instances.filter(i => i.activity === act.name)
|
|
988
|
+
inst = findNextFromNow(own, now, hm) || own[0]
|
|
989
|
+
}
|
|
990
|
+
else {
|
|
991
|
+
inst = findNextFromNow(instances, now, hm) || instances[0]
|
|
992
|
+
}
|
|
993
|
+
if (!inst) return '活动表里还没有可用的时段'
|
|
994
|
+
// 下一场:按"现在"往后算,并排除自己
|
|
995
|
+
const next = findNextFromNow(instances.filter(i => i !== inst), now, hm)
|
|
996
|
+
|
|
997
|
+
const text = renderRemindTemplate(config.remindTemplate, makeRemindVars(inst, next, now, hm))
|
|
921
998
|
const bot = (ctx.bots || []).find(b => b.sid === session.bot?.sid)
|
|
922
999
|
if (!bot || !session.guildId) return '❌ 只能在群里测试'
|
|
923
1000
|
await sendOne(bot, String(session.guildId), text, { markdown: !!config.remindMarkdown })
|
|
924
|
-
return `✅ 已向本群测试发送「${
|
|
1001
|
+
return `✅ 已向本群测试发送「${inst.activity}」的提醒(星期${WEEK_CN[inst.day]} ${inst.start})`
|
|
925
1002
|
}
|
|
926
1003
|
|
|
927
1004
|
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.
|
|
3
|
+
"version": "1.7.3",
|
|
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,5 @@
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
|
|
37
|
+
|