koishi-plugin-ll-schedule 1.0.1 → 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.
Files changed (2) hide show
  1. package/index.js +68 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -70,8 +70,9 @@ const Config = Schema.object({
70
70
 
71
71
  exports.Config = Config
72
72
 
73
- // 可选数据库:持久化学习到的群(重启不丢)
74
- exports.inject = { optional: ['database'] }
73
+ // 需要数据库:持久化学习到的群(重启不丢)
74
+ // 必须声明 required:确保插件在数据库就绪后才启动,模型表能正常注册建表
75
+ exports.inject = { required: ['database'] }
75
76
 
76
77
  function apply(ctx, config) {
77
78
  const logger = ctx.logger('ll-schedule')
@@ -144,6 +145,7 @@ function apply(ctx, config) {
144
145
  learnedAt: Date.now(),
145
146
  }
146
147
  knownGroups.set(key, entry)
148
+ logger.info(`[schedule] 学习到新群 ${bot.sid} (${bot.platform}) → ${session.guildId}`)
147
149
  persistGroup(entry)
148
150
  }
149
151
 
@@ -271,14 +273,28 @@ function apply(ctx, config) {
271
273
  ctx.on('dispose', () => clearInterval(timer))
272
274
 
273
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
+
274
288
  ctx.command('schedule', '定时发送管理')
275
- .action(() =>
276
- '⚙️ 管理:插件设置页 → ll-schedule → tasks 表格\n' +
277
- '命令:schedule.list 查看任务 | schedule.groups 查看已知群 | schedule.test <任务名> 立即测试发送'
278
- )
289
+ .action(() => {
290
+ logger.info('[schedule] 命令被调用: schedule')
291
+ return '⚙️ 管理:插件设置页 → ll-schedule → tasks 表格\n' +
292
+ '命令:schedule.list 查看任务 | schedule.groups 查看已知群 | schedule.test <任务名> 立即测试发送'
293
+ })
279
294
 
280
295
  ctx.command('schedule.list', '查看定时任务')
281
296
  .action(() => {
297
+ logger.info('[schedule] 命令被调用: schedule.list')
282
298
  const tasks = config.tasks || {}
283
299
  const keys = Object.keys(tasks)
284
300
  if (!keys.length) return '暂无定时任务\n请在插件设置页的 tasks 表格中添加'
@@ -292,19 +308,13 @@ function apply(ctx, config) {
292
308
 
293
309
  ctx.command('schedule.groups', '查看机器人已知的群(官机显示 openid)')
294
310
  .action(async () => {
295
- if (!knownGroups.size) return '暂无已知群。机器人收到过消息的群才会被记录(官机需要先把机器人拉进群并让它收消息)'
296
- const lines = []
297
- for (const g of knownGroups.values()) {
298
- const bot = ctx.bots.find(b => b.sid === g.botSid)
299
- const name = bot ? await resolveGroupName(bot, g.guildId) : ''
300
- const platformTag = g.platform === 'qq' ? '[官机]' : `[${g.platform}]`
301
- lines.push(`${platformTag} ${name || '未知群名'} ${g.guildId}`)
302
- }
303
- return '📋 机器人已知群:\n' + lines.join('\n') + '\n(官机的群 ID 是 openid,填入任务 groups 即可)'
311
+ logger.info('[schedule] 命令被调用: schedule.groups')
312
+ return await listKnownGroups()
304
313
  })
305
314
 
306
315
  ctx.command('schedule.test <name>', '立即测试发送指定任务')
307
316
  .action(async ({ session }, name) => {
317
+ logger.info(`[schedule] 命令被调用: schedule.test name=${name}`)
308
318
  const tasks = config.tasks || {}
309
319
  const task = tasks[name]
310
320
  if (!task) return `未找到任务 "${name}",可用 schedule.list 查看任务名`
@@ -317,6 +327,49 @@ function apply(ctx, config) {
317
327
  return `✅ 已发送任务 "${name}"`
318
328
  })
319
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
+
320
373
  // 启动时:加载已知群 + 立即检查一次
321
374
  loadKnownGroups().then(() => checkAndSend())
322
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Scheduled message sender with text/image support, works with official QQ bot",
5
5
  "main": "index.js",
6
6
  "files": [