koishi-plugin-ll-schedule 1.5.1 → 1.6.0

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 +65 -0
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -24,6 +24,7 @@ exports.usage = `定时提醒:每个任务一个大文本框(schedule)。每
24
24
  内容支持 Markdown 卡片、模板变量 {date} {time} {week} {task}
25
25
 
26
26
  群命令:订阅 任务名 / 取消订阅 任务名 / 订阅列表 / schedule.list / schedule.groups / schedule.test 任务名 / schedule.testcur 任务名(只发当前群) / 我的ID
27
+ 管理员:schedule.unsuball 任务名(取消该任务全部群订阅并通知各群;填 all 清空全部)
27
28
 
28
29
  推送接口:POST /ll-schedule/push {"secret":"密钥","task":"任务名","place1":"xxx","delay":0}
29
30
 
@@ -248,6 +249,9 @@ const Config = Schema.object({
248
249
  pushSecret: Schema.string()
249
250
  .default('')
250
251
  .description('🔑 HTTP 推送接口密钥:外部系统调用 POST /ll-schedule/push 时须携带相同 secret(留空则接口拒绝所有推送)'),
252
+ unsubAllNotice: Schema.string()
253
+ .default('本群已取消「{task}」的推送')
254
+ .description('管理员用 schedule.unsuball 取消全部订阅时,发到每个被取消群的提示语({task}=任务名;留空则不发送提示)'),
251
255
  subscribeAuthority: Schema.number()
252
256
  .min(1).max(4).default(1)
253
257
  .description('执行订阅命令所需的最低权限等级(Koishi 用户权限等级,与QQ群主/管理员身份无关;默认 1=所有人都能订阅。如需限制,先在控制台"用户管理"给指定账号提权,再调高此值)'),
@@ -809,6 +813,67 @@ function apply(ctx, config) {
809
813
  return '📋 订阅列表:\n' + lines.join('\n')
810
814
  })
811
815
 
816
+ // 管理员:取消指定任务的全部群订阅(并通知每个被取消的群)
817
+ // 任务名可填 all / * 表示清空所有任务的全部订阅
818
+ ctx.command('schedule.unsuball <name>', '取消某任务的全部群订阅(管理员;填 all 清空全部)', { authority: 3 })
819
+ .action(async ({ session }, name) => {
820
+ logger.info(`[schedule] 命令被调用: schedule.unsuball name=${name}`)
821
+ const tasks = config.tasks || {}
822
+ const all = name === 'all' || name === '*'
823
+ if (!all && (!name || !tasks[name])) {
824
+ return `未找到任务 "${name}",可用 schedule.list 查看任务名(也可以填 all 清空全部任务的订阅)`
825
+ }
826
+ // 收集要取消的订阅
827
+ const targets = []
828
+ if (all) {
829
+ for (const [tn, m] of subs) {
830
+ for (const e of m.values()) targets.push({ taskName: tn, botSid: e.botSid, guildId: e.guildId })
831
+ }
832
+ }
833
+ else {
834
+ const m = subs.get(name)
835
+ if (m) for (const e of m.values()) targets.push({ taskName: name, botSid: e.botSid, guildId: e.guildId })
836
+ }
837
+ if (!targets.length) return all ? 'ℹ️ 当前没有任何群订阅' : `ℹ️ 任务 "${name}" 当前没有任何群订阅`
838
+
839
+ // 逐群发送"已取消"提示
840
+ let notified = 0
841
+ if (config.unsubAllNotice) {
842
+ for (const t of targets) {
843
+ const bot = (ctx.bots || []).find(b => b.sid === t.botSid)
844
+ if (!bot || !bot.online) continue
845
+ const text = String(config.unsubAllNotice).split('{task}').join(t.taskName)
846
+ try {
847
+ await bot.sendMessage(t.guildId, [text])
848
+ notified++
849
+ }
850
+ catch (e) {
851
+ logger.warn(`[schedule] 取消提示发送失败 ${t.botSid}:${t.guildId}: ${e.message}`)
852
+ }
853
+ }
854
+ }
855
+
856
+ // 清空订阅(内存 + 数据库)
857
+ if (all) {
858
+ for (const m of subs.values()) m.clear()
859
+ if (ctx.database) {
860
+ try {
861
+ await ctx.database.remove('ll_schedule_subs', {})
862
+ }
863
+ catch (e) {
864
+ logger.warn('[schedule] 清空订阅表失败:', e)
865
+ }
866
+ }
867
+ }
868
+ else {
869
+ const m = subs.get(name)
870
+ if (m) m.clear()
871
+ for (const t of targets) await removeSub(t.taskName, t.botSid, t.guildId)
872
+ }
873
+ logger.info(`[schedule] 已取消 ${targets.length} 个群订阅(通知 ${notified} 个群)${all ? '(全部任务)' : `任务 "${name}"`}`)
874
+ return `✅ 已取消 ${targets.length} 个群订阅${all ? '(全部任务)' : `(任务「${name}」)`}\n已向 ${notified} 个群发送取消提示`
875
+ })
876
+
812
877
  ctx.command('我的ID', '查看自己的账号信息(openid/群ID/角色)')
813
878
  .action(({ session }) => {
814
879
  logger.info('[schedule] 命令被调用: 我的ID')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-schedule",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
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": [
@@ -27,3 +27,4 @@
27
27
 
28
28
 
29
29
 
30
+