| 214 | } |
| 215 | |
| 216 | private async handleConfigCommand(action: string, args: string[], msg: Api.Message): Promise<void> { |
| 217 | const conf = this.cfg.get(); |
| 218 | |
| 219 | if (action === "settings" || action === "config" || action === "info") { |
| 220 | const enabled = conf.targets.filter((t) => t.enabled).length; |
| 221 | const timeRange = conf.runTimeEnd ? `${conf.runTime} ~ ${conf.runTimeEnd}` : conf.runTime; |
| 222 | const timeMode = conf.runTimeEnd ? "🔄 在设定时间段内随机执行" : "📌 按固定时间执行"; |
| 223 | |
| 224 | await this.edit( |
| 225 | msg, |
| 226 | `⚙️ <b>CheckIn 配置信息</b>\n\n` + |
| 227 | `${timeMode}\n` + |
| 228 | `⏰ 执行时间: ${this.escape(timeRange)}\n` + |
| 229 | `🎲 额外随机延迟: ${conf.randomDelay} 分钟\n` + |
| 230 | `🤖 Bot 通知: ${conf.botToken ? "已配置" : "未配置"}\n` + |
| 231 | `📱 通知目标: ${this.escape(conf.pushChatId || "未设置")}\n` + |
| 232 | `📅 最近执行日期: ${this.escape(conf.lastRunDate || "无")}\n` + |
| 233 | `🎯 已启用目标: ${enabled}/${conf.targets.length}` |
| 234 | ); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (action === "set" || action === "config") { |
| 239 | const type = (args[1] || "").toLowerCase(); |
| 240 | const value = args[2]; |
| 241 | const extra = args[3]; |
| 242 | |
| 243 | if (type === "time" || type === "t") { |
| 244 | if (!value || !/^([01]?\d|2[0-3]):[0-5]\d$/.test(value)) { |
| 245 | await this.edit(msg, "❌ 格式错误,请使用 HH:MM (例如 10:30)"); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | if (conf.runTimeEnd) { |
| 250 | const [startH, startM] = value.split(":").map(Number); |
| 251 | const [endH, endM] = conf.runTimeEnd.split(":").map(Number); |
| 252 | if (startH * 60 + startM > endH * 60 + endM && endH * 60 + endM > 0) { |
| 253 | await this.edit(msg, `⚠️ 开始时间 (${value}) 晚于结束时间 (${conf.runTimeEnd}),请调整时间范围`); |
| 254 | return; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | this.cfg.save({ runTime: value }); |
| 259 | await this.edit(msg, `✅ 开始时间已设置为: ${value}`); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | if (type === "range" || type === "r") { |
| 264 | if (!value) { |
| 265 | this.cfg.save({ runTimeEnd: undefined }); |
| 266 | await this.edit(msg, "✅ 已清除执行时间范围,改为固定时间执行"); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | if (!/^([01]?\d|2[0-3]):[0-5]\d$/.test(value)) { |
| 271 | await this.edit(msg, "❌ 格式错误,请使用 HH:MM (例如 11:30)"); |
| 272 | return; |
| 273 | } |