* 发送签到命令给机器人 * @param msg 原始消息
(msg: Api.Message)
| 213 | if (!client) { |
| 214 | await msg.edit({ |
| 215 | text: "❌ 客户端未初始化", |
| 216 | parseMode: "html" |
| 217 | }); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | try { |
| 222 | // 显示处理中状态 |
| 223 | await msg.edit({ |
| 224 | text: "📅 正在执行签到...", |
| 225 | parseMode: "html" |
| 226 | }); |
| 227 | |
| 228 | // 解除对机器人的屏蔽(如果有的话) |
| 229 | try { |
| 230 | await client.invoke(new Api.contacts.Unblock({ |
| 231 | id: BOT_USERNAME |
| 232 | })); |
| 233 | } catch (error) { |
| 234 | // 忽略解除屏蔽的错误,可能本来就没有屏蔽 |
| 235 | } |
| 236 | |
| 237 | // 获取机器人实体 |
| 238 | const botEntity = await client.getEntity(BOT_USERNAME); |
| 239 | |
| 240 | // 检查是否有对话历史,如果没有先发送 /start |
| 241 | const recentMessages = await safeGetMessages(client, botEntity, { limit: 3 }); |
| 242 | const hasConversation = recentMessages.length > 0; |
| 243 | |
| 244 | if (!hasConversation) { |
| 245 | await client.sendMessage(botEntity, { message: "/start" }); |
| 246 | await sleep(1000); |
| 247 | } |
| 248 | |
| 249 | // 开始监听机器人回复(签到不期望图片,任何回复都可以) |
| 250 | const replyPromise = waitForBotReply(client, botEntity, 15000, false); |
| 251 | |
| 252 | // 发送签到命令给机器人 |
| 253 | await client.sendMessage(botEntity, { |
| 254 | message: "/checkin" |
| 255 | }); |
| 256 | |
| 257 | // 等待机器人响应 |
| 258 | const botResponse = await replyPromise; |
| 259 | |
| 260 | if (botResponse) { |
| 261 | // 获取机器人回复内容 |
| 262 | const responseText = botResponse.message || "签到成功"; |
| 263 | |
| 264 | await msg.edit({ |
| 265 | text: `✅ <b>签到完成</b>\n\n${htmlEscape(responseText)}`, |
| 266 | parseMode: "html" |
| 267 | }); |
| 268 | } else { |
| 269 | await msg.edit({ |
| 270 | text: "❌ 签到超时,机器人可能暂时无响应,请稍后重试", |
| 271 | parseMode: "html" |
| 272 | }); |
no test coverage detected