| 33 | try { |
| 34 | // 获取文本内容 |
| 35 | const args = msg.message.split(/\s+/).slice(1); |
| 36 | let text = args.join(" "); |
| 37 | |
| 38 | // 如果命令后没有文本,检查是否回复了消息 |
| 39 | if (!text) { |
| 40 | const replied = msg.replyTo ? await safeGetReplyMessage(msg) : null; |
| 41 | if (replied && replied.message) { |
| 42 | text = replied.message; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // 如果还是没有文本,显示帮助信息 |
| 47 | if (!text) { |
| 48 | await msg.edit({ |
| 49 | text: help_text, |
| 50 | parseMode: "html" |
| 51 | }); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | await msg.edit({ text: "正在生成举牌小人..." }); |
| 56 | |
| 57 | try { |
| 58 | // 构建 API URL,对文本进行 URL 编码 |
| 59 | const imageUrl = `${juPaiApi}?msg=${encodeURIComponent(text)}`; |
| 60 | |
| 61 | // 获取图片数据 |
| 62 | const response = await axios.get(imageUrl, { |
| 63 | responseType: "arraybuffer", |
| 64 | timeout, |
| 65 | }); |
| 66 | |
| 67 | const imageBuffer = Buffer.from(response.data); |
| 68 | |
| 69 | if (!imageBuffer || imageBuffer.length === 0) { |
| 70 | await msg.edit({ text: "图片获取失败或为空" }); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // 发送图片 |
| 75 | const client = await getGlobalClient(); |
| 76 | const file = new CustomFile( |
| 77 | "jupai.jpg", |
| 78 | imageBuffer.length, |
| 79 | "", |
| 80 | imageBuffer |
| 81 | ); |
| 82 | |
| 83 | await client.sendFile(msg.peerId, { |
| 84 | file, |
| 85 | replyTo: msg.replyTo?.replyToMsgId || msg.id, |
| 86 | }); |
| 87 | |
| 88 | await msg.delete(); |
| 89 | } catch (error) { |
| 90 | const errorMsg = error instanceof Error ? error.message : String(error); |
| 91 | await msg.edit({ text: `获取失败: ${htmlEscape(errorMsg)}`, parseMode: "html" }); |
| 92 | } |
nothing calls this directly
no test coverage detected