| 84 | save(partial: Partial<CheckInConfig>): void { |
| 85 | this.data = { ...this.data, ...partial }; |
| 86 | try { |
| 87 | fs.writeFileSync(this.configPath, JSON.stringify(this.data, null, 2), "utf-8"); |
| 88 | } catch (e) { |
| 89 | console.error("[CheckIn] Config save error:", e); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | class CheckInPlugin extends Plugin { |
| 95 | description = this.helpText(); |
| 96 | private readonly cfg = new ConfigManager(); |
| 97 | private timer: NodeJS.Timeout | null = null; |
| 98 | private running = false; |
| 99 | private todayRunTime: string | null = null; |
| 100 | private pendingAdds = new Map<string, PendingAdd>(); |
| 101 | |
| 102 | constructor() { |
| 103 | super(); |
| 104 | this.timer = setInterval(() => void this.checkAndRun(), 60_000); |
| 105 | } |
| 106 | |
| 107 | cleanup(): void { |
| 108 | if (this.timer) clearInterval(this.timer); |
| 109 | this.timer = null; |
| 110 | } |
| 111 | |
| 112 | cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = { |
| 113 | checkin: async (msg: Api.Message) => { |
| 114 | try { |
| 115 | const parts = (msg.message || msg.text || "").trim().split(/\s+/); |
| 116 | const args = parts.slice(1); |
| 117 | const action = (args[0] || "").toLowerCase(); |
| 118 | |
| 119 | if (!action || action === "help" || action === "h") { |
| 120 | if (!action && this.cfg.get().targets.length > 0) { |
| 121 | await this.edit(msg, "🚀 开始执行所有签到任务..."); |
| 122 | void this.runAllSigns("手动触发", msg.chatId, msg); |
| 123 | return; |
| 124 | } |
| 125 | await this.edit(msg, this.helpText()); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | if (["add", "del", "delete", "list", "toggle", "test"].includes(action)) { |
| 130 | await this.handleTargetCommand(action, args, msg); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | if (["set", "config", "settings", "info"].includes(action)) { |
| 135 | await this.handleConfigCommand(action, args, msg); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | if (action === "reset") { |
| 140 | this.cfg.save({ lastRunDate: "", currentRunTime: undefined }); |
| 141 | this.todayRunTime = null; |
| 142 | await this.edit(msg, "✅ 已重置每日运行状态,定时任务可再次触发。"); |
| 143 | return; |
nothing calls this directly
no test coverage detected