(action: string, args: string[], msg: Api.Message)
| 145 | |
| 146 | await this.edit(msg, `❌ 未知命令,请使用 ${PREFIX}checkin help 查看帮助`); |
| 147 | } catch (e: any) { |
| 148 | console.error("[CheckIn] Command error:", e); |
| 149 | try { |
| 150 | await this.edit(msg, `❌ 命令执行失败: ${this.escape(e?.message || "未知错误")}`); |
| 151 | } catch {} |
| 152 | } |
| 153 | }, |
| 154 | }; |
| 155 | |
| 156 | // ── 回复式添加:监听用户回复以获取签到命令 ─ |
| 157 | listenMessageHandler = async (msg: Api.Message, _options?: { isEdited?: boolean }) => { |
| 158 | if (_options?.isEdited) return; |
| 159 | const chatId = String(msg.chatId || msg.peerId || ""); |
| 160 | const pending = this.pendingAdds.get(chatId); |
| 161 | if (!pending) return; |
| 162 | |
| 163 | const replyToMsgId = (msg as any).replyTo?.replyToMsgId ?? (msg as any).replyToMsgId; |
| 164 | if (replyToMsgId !== pending.promptMsgId) return; |
| 165 | |
| 166 | const command = (msg.message || msg.text || "").trim(); |
| 167 | if (!command) { |
| 168 | const client = await getGlobalClient(); |
| 169 | await client?.sendMessage(chatId, { |
| 170 | message: "❌ 签到命令不能为空,请重新回复此消息", |
| 171 | parseMode: "html", |
| 172 | linkPreview: false, |
| 173 | }); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | this.pendingAdds.delete(chatId); |
| 178 | |
| 179 | const conf = this.cfg.get(); |
| 180 | const next: SignTarget = { |
| 181 | id: pending.id, |
| 182 | name: pending.name, |
| 183 | target: pending.target, |
| 184 | command, |
| 185 | ...pending.matcher, |
| 186 | enabled: true, |
| 187 | }; |
| 188 | const i = conf.targets.findIndex((t) => t.id === pending.id); |
| 189 | if (i >= 0) conf.targets[i] = next; |
| 190 | else conf.targets.push(next); |
| 191 | this.cfg.save({ targets: conf.targets }); |
| 192 | |
| 193 | const client = await getGlobalClient(); |
| 194 | await client?.sendMessage(chatId, { |
| 195 | message: `✅ 已${i >= 0 ? "更新" : "添加"}签到目标: ${pending.name} (${pending.id})\n命令: ${this.escape(command)}`, |
| 196 | parseMode: "html", |
| 197 | linkPreview: false, |
| 198 | }); |
| 199 | }; |
| 200 | |
| 201 | private async handleTargetCommand(action: string, args: string[], msg: Api.Message): Promise<void> { |
| 202 | const conf = this.cfg.get(); |
| 203 | |
| 204 | if (action === "add") { |
no test coverage detected