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