(type: MessageType)
| 1392 | // 根据优先顺序发送 |
| 1393 | const order = getMessageOrder(); |
| 1394 | const trySend = async (type: MessageType): Promise<boolean> => { |
| 1395 | try { |
| 1396 | if (type === "txt") { |
| 1397 | await msg.edit({ text: finalDescription, parseMode: "html" }); |
| 1398 | return true; |
| 1399 | } |
| 1400 | |
| 1401 | // 需要图片的类型先确保图片存在 |
| 1402 | if (!result.result?.url) return false; |
| 1403 | const imagePath = await saveSpeedtestImage(result.result.url); |
| 1404 | if (!imagePath || !fs.existsSync(imagePath)) return false; |
| 1405 | |
| 1406 | if (type === "photo") { |
| 1407 | await msg.client?.sendFile(msg.peerId, { |
| 1408 | file: imagePath, |
| 1409 | caption: finalDescription, |
| 1410 | parseMode: "html", |
| 1411 | }); |
| 1412 | try { |
| 1413 | await msg.delete(); |
| 1414 | } catch { } |
| 1415 | try { |
| 1416 | fs.unlinkSync(imagePath); |
| 1417 | } catch { } |
| 1418 | return true; |
| 1419 | } else if (type === "file") { |
| 1420 | await msg.client?.sendFile(msg.peerId, { |
| 1421 | file: imagePath, |
| 1422 | caption: finalDescription, |
| 1423 | parseMode: "html", |
| 1424 | forceDocument: true, |
| 1425 | }); |
| 1426 | try { |
| 1427 | await msg.delete(); |
| 1428 | } catch { } |
| 1429 | try { |
| 1430 | fs.unlinkSync(imagePath); |
| 1431 | } catch { } |
| 1432 | return true; |
| 1433 | } else if (type === "sticker") { |
| 1434 | // 转为贴纸发送 |
| 1435 | const stickerPath = await convertImageToStickerWebp(imagePath); |
| 1436 | if (stickerPath && fs.existsSync(stickerPath)) { |
| 1437 | const client = await getGlobalClient(); |
| 1438 | await client.sendFile(msg.peerId!, { |
| 1439 | file: stickerPath, |
| 1440 | forceDocument: false, |
| 1441 | attributes: [ |
| 1442 | new Api.DocumentAttributeSticker({ |
| 1443 | alt: "speedtest", |
| 1444 | stickerset: new Api.InputStickerSetEmpty(), |
| 1445 | }), |
| 1446 | ], |
| 1447 | }); |
| 1448 | // 清理临时文件 |
| 1449 | try { |
| 1450 | fs.unlinkSync(imagePath); |
| 1451 | } catch { } |
no test coverage detected