(originalMsg: Api.Message, stickerFile: string, statusMsg: Api.Message)
| 350 | } |
| 351 | } |
| 352 | |
| 353 | private async autoAddToStickerPack(originalMsg: Api.Message, stickerFile: string, statusMsg: Api.Message): Promise<void> { |
| 354 | try { |
| 355 | // 获取 @Stickers 机器人 |
| 356 | const stickersBot = await this.client.getEntity("@Stickers"); |
| 357 | |
| 358 | await statusMsg.edit({ text: "📤 正在发送文件到 @Stickers 机器人..." }); |
| 359 | |
| 360 | // 发送 WebM 文件到 @Stickers 机器人 |
| 361 | await this.client.sendFile(stickersBot, { |
| 362 | file: stickerFile, |
| 363 | caption: "🎉 新贴纸" |
| 364 | }); |
| 365 | |
| 366 | // 等待机器人回复 |
| 367 | await this.sleep(2000); |
| 368 | await statusMsg.edit({ text: "🤖 正在与 @Stickers 机器人交互..." }); |
| 369 | |
| 370 | // 发送命令添加到贴纸包 |
| 371 | await this.handleStickerBotInteraction(stickersBot, statusMsg); |
| 372 | |
| 373 | // 最终发送贴纸到原始聊天 |
| 374 | await statusMsg.edit({ text: "✨ 正在发送最终贴纸..." }); |
| 375 | await this.sendAsSticker(originalMsg, stickerFile); |
| 376 | |
| 377 | await statusMsg.edit({ |
| 378 | text: "✅ 成功!贴纸已自动添加到贴纸包并发送。" |
| 379 | }); |
| 380 | |
| 381 | // 延迟删除状态消息 (generation-safe) |
| 382 | const gen2 = getCurrentGeneration(); |
| 383 | const t2 = setTimeout(() => { |
| 384 | pendingTimers.delete(t2); |
| 385 | if (getCurrentGeneration() !== gen2) return; |
| 386 | statusMsg.delete().catch(() => {}); |
| 387 | }, 3000); |
| 388 | pendingTimers.add(t2); |
| 389 | |
| 390 | } catch (error: any) { |
| 391 | console.error("自动添加贴纸包失败:", error); |
| 392 | await statusMsg.edit({ |
| 393 | text: `⚠️ 自动添加失败,正在直接发送贴纸...\n\n错误: ${error.message}` |
| 394 | }); |
| 395 | |
| 396 | // 失败后直接发送贴纸 |
| 397 | await this.sendAsSticker(originalMsg, stickerFile); |
| 398 | const gen3 = getCurrentGeneration(); |
| 399 | const t3 = setTimeout(() => { |
| 400 | pendingTimers.delete(t3); |
| 401 | if (getCurrentGeneration() !== gen3) return; |
| 402 | statusMsg.delete().catch(() => {}); |
| 403 | }, 5000); |
| 404 | pendingTimers.add(t3); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | private async handleStickerBotInteraction(stickersBot: any, statusMsg: Api.Message): Promise<void> { |
nothing calls this directly
no test coverage detected