koishi-plugin-ll-schedule 1.0.2 → 1.0.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 +65 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -145,6 +145,7 @@ function apply(ctx, config) {
|
|
|
145
145
|
learnedAt: Date.now(),
|
|
146
146
|
}
|
|
147
147
|
knownGroups.set(key, entry)
|
|
148
|
+
logger.info(`[schedule] 学习到新群 ${bot.sid} (${bot.platform}) → ${session.guildId}`)
|
|
148
149
|
persistGroup(entry)
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -272,14 +273,28 @@ function apply(ctx, config) {
|
|
|
272
273
|
ctx.on('dispose', () => clearInterval(timer))
|
|
273
274
|
|
|
274
275
|
// ===== 命令 =====
|
|
276
|
+
async function listKnownGroups() {
|
|
277
|
+
if (!knownGroups.size) return '暂无已知群。机器人收到过消息的群才会被记录(官机需要先把机器人拉进群并让它收消息)'
|
|
278
|
+
const lines = []
|
|
279
|
+
for (const g of knownGroups.values()) {
|
|
280
|
+
const bot = ctx.bots.find(b => b.sid === g.botSid)
|
|
281
|
+
const name = bot ? await resolveGroupName(bot, g.guildId) : ''
|
|
282
|
+
const platformTag = g.platform === 'qq' ? '[官机]' : `[${g.platform}]`
|
|
283
|
+
lines.push(`${platformTag} ${name || '未知群名'} ${g.guildId}`)
|
|
284
|
+
}
|
|
285
|
+
return '📋 机器人已知群:\n' + lines.join('\n') + '\n(官机的群 ID 是 openid,填入任务 groups 即可)'
|
|
286
|
+
}
|
|
287
|
+
|
|
275
288
|
ctx.command('schedule', '定时发送管理')
|
|
276
|
-
.action(() =>
|
|
277
|
-
'
|
|
278
|
-
'
|
|
279
|
-
|
|
289
|
+
.action(() => {
|
|
290
|
+
logger.info('[schedule] 命令被调用: schedule')
|
|
291
|
+
return '⚙️ 管理:插件设置页 → ll-schedule → tasks 表格\n' +
|
|
292
|
+
'命令:schedule.list 查看任务 | schedule.groups 查看已知群 | schedule.test <任务名> 立即测试发送'
|
|
293
|
+
})
|
|
280
294
|
|
|
281
295
|
ctx.command('schedule.list', '查看定时任务')
|
|
282
296
|
.action(() => {
|
|
297
|
+
logger.info('[schedule] 命令被调用: schedule.list')
|
|
283
298
|
const tasks = config.tasks || {}
|
|
284
299
|
const keys = Object.keys(tasks)
|
|
285
300
|
if (!keys.length) return '暂无定时任务\n请在插件设置页的 tasks 表格中添加'
|
|
@@ -293,19 +308,13 @@ function apply(ctx, config) {
|
|
|
293
308
|
|
|
294
309
|
ctx.command('schedule.groups', '查看机器人已知的群(官机显示 openid)')
|
|
295
310
|
.action(async () => {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
for (const g of knownGroups.values()) {
|
|
299
|
-
const bot = ctx.bots.find(b => b.sid === g.botSid)
|
|
300
|
-
const name = bot ? await resolveGroupName(bot, g.guildId) : ''
|
|
301
|
-
const platformTag = g.platform === 'qq' ? '[官机]' : `[${g.platform}]`
|
|
302
|
-
lines.push(`${platformTag} ${name || '未知群名'} ${g.guildId}`)
|
|
303
|
-
}
|
|
304
|
-
return '📋 机器人已知群:\n' + lines.join('\n') + '\n(官机的群 ID 是 openid,填入任务 groups 即可)'
|
|
311
|
+
logger.info('[schedule] 命令被调用: schedule.groups')
|
|
312
|
+
return await listKnownGroups()
|
|
305
313
|
})
|
|
306
314
|
|
|
307
315
|
ctx.command('schedule.test <name>', '立即测试发送指定任务')
|
|
308
316
|
.action(async ({ session }, name) => {
|
|
317
|
+
logger.info(`[schedule] 命令被调用: schedule.test name=${name}`)
|
|
309
318
|
const tasks = config.tasks || {}
|
|
310
319
|
const task = tasks[name]
|
|
311
320
|
if (!task) return `未找到任务 "${name}",可用 schedule.list 查看任务名`
|
|
@@ -318,6 +327,49 @@ function apply(ctx, config) {
|
|
|
318
327
|
return `✅ 已发送任务 "${name}"`
|
|
319
328
|
})
|
|
320
329
|
|
|
330
|
+
// 备用命令入口(避免与其他插件的 schedule 命令冲突)
|
|
331
|
+
ctx.command('lls', 'll-schedule 管理(备用入口)')
|
|
332
|
+
.action(() => {
|
|
333
|
+
logger.info('[schedule] 命令被调用: lls')
|
|
334
|
+
return '⚙️ 备用入口:lls.list / lls.groups / lls.test <任务名>'
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
ctx.command('lls.list', '查看定时任务(备用入口)')
|
|
338
|
+
.action(() => {
|
|
339
|
+
logger.info('[schedule] 命令被调用: lls.list')
|
|
340
|
+
const tasks = config.tasks || {}
|
|
341
|
+
const keys = Object.keys(tasks)
|
|
342
|
+
if (!keys.length) return '暂无定时任务\n请在插件设置页的 tasks 表格中添加'
|
|
343
|
+
return keys.map(k => {
|
|
344
|
+
const t = tasks[k]
|
|
345
|
+
const s = t.enabled === false ? '⛔' : '✅'
|
|
346
|
+
const content = [t.text && '文字', t.image && '图片'].filter(Boolean).join('+') || '(空)'
|
|
347
|
+
return `${s} ${k} @ ${t.time} → ${content} → 群:${(t.groups || []).join(',') || '所有已知群'}`
|
|
348
|
+
}).join('\n')
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
ctx.command('lls.groups', '查看机器人已知的群(备用入口,官机显示 openid)')
|
|
352
|
+
.action(async () => {
|
|
353
|
+
logger.info('[schedule] 命令被调用: lls.groups')
|
|
354
|
+
return await listKnownGroups()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
ctx.command('lls.test <name>', '立即测试发送指定任务(备用入口)')
|
|
358
|
+
.action(async ({ session }, name) => {
|
|
359
|
+
logger.info(`[schedule] 命令被调用: lls.test name=${name}`)
|
|
360
|
+
const tasks = config.tasks || {}
|
|
361
|
+
const task = tasks[name]
|
|
362
|
+
if (!task) return `未找到任务 "${name}",可用 lls.list 查看任务名`
|
|
363
|
+
const testTask = { ...task }
|
|
364
|
+
if (!testTask.groups || !testTask.groups.length) {
|
|
365
|
+
testTask.groups = session.guildId ? [String(session.guildId)] : []
|
|
366
|
+
}
|
|
367
|
+
await sendTask(name, testTask, session.bot?.sid)
|
|
368
|
+
return `✅ 已发送任务 "${name}"`
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
logger.info('[schedule] 命令已注册: schedule / schedule.list / schedule.groups / schedule.test / lls / lls.list / lls.groups / lls.test')
|
|
372
|
+
|
|
321
373
|
// 启动时:加载已知群 + 立即检查一次
|
|
322
374
|
loadKnownGroups().then(() => checkAndSend())
|
|
323
375
|
}
|