* 发送带剧透效果的图片 * @param msg 原始消息 * @param command 机器人命令
(msg: Api.Message, command: string)
| 311 | if (!client) { |
| 312 | await msg.edit({ |
| 313 | text: "❌ 客户端未初始化", |
| 314 | parseMode: "html" |
| 315 | }); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | let botEntity: any; |
| 320 | |
| 321 | try { |
| 322 | // 显示处理中状态 |
| 323 | await msg.edit({ |
| 324 | text: "🔄 正在获取图片...", |
| 325 | parseMode: "html" |
| 326 | }); |
| 327 | |
| 328 | // 获取机器人实体并解除屏蔽(如果有的话) |
| 329 | try { |
| 330 | botEntity = await client.getEntity(BOT_USERNAME); |
| 331 | await client.invoke(new Api.contacts.Unblock({ |
| 332 | id: botEntity |
| 333 | })); |
| 334 | } catch (error) { |
| 335 | // 如果获取实体失败,尝试只获取实体 |
| 336 | if (!botEntity) { |
| 337 | botEntity = await client.getEntity(BOT_USERNAME); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // 获取机器人响应 |
| 342 | const botResponse = await getBotResponse(client, command); |
| 343 | |
| 344 | if (!botResponse) { |
| 345 | await msg.edit({ |
| 346 | text: "❌ 机器人没有响应,请稍后重试", |
| 347 | parseMode: "html" |
| 348 | }); |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | // 检查是否有图片或文档 |
| 353 | let inputMedia: Api.TypeInputMedia | undefined; |
| 354 | |
| 355 | if (botResponse.photo && botResponse.photo instanceof Api.Photo) { |
| 356 | // 处理图片 |
| 357 | const inputPhoto = new Api.InputPhoto({ |
| 358 | id: botResponse.photo.id, |
| 359 | accessHash: botResponse.photo.accessHash, |
| 360 | fileReference: botResponse.photo.fileReference, |
| 361 | }); |
| 362 | inputMedia = new Api.InputMediaPhoto({ |
| 363 | id: inputPhoto, |
| 364 | spoiler: true, // 添加剧透效果 |
| 365 | }); |
| 366 | } else if (botResponse.document && botResponse.document instanceof Api.Document) { |
| 367 | // 处理文档(可能是动图等) |
| 368 | const inputDoc = new Api.InputDocument({ |
| 369 | id: botResponse.document.id, |
| 370 | accessHash: botResponse.document.accessHash, |
no test coverage detected