| 54 | description: string = `文件上传到 0x0.st\n\n${help_text}`; |
| 55 | cmdHandlers: Record<string, (msg: Api.Message, trigger?: Api.Message) => Promise<void>> = { |
| 56 | "0x0": async (msg: Api.Message) => { |
| 57 | const lines = msg.text?.trim()?.split(/\r?\n/g) || []; |
| 58 | const parts = lines?.[0]?.split(/\s+/) || []; |
| 59 | const [, ...args] = parts; |
| 60 | const sub = (args[0] || "").toLowerCase(); |
| 61 | |
| 62 | // 仅当明确输入 help/h 时显示帮助 |
| 63 | if (sub === "help" || sub === "h") { |
| 64 | await sendLongMessage(msg, help_text); |
| 65 | return; |
| 66 | } |
| 67 | if (args[1] && (args[1].toLowerCase() === "help" || args[1].toLowerCase() === "h")) { |
| 68 | await sendLongMessage(msg, help_text); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | let expires: string | undefined; |
| 73 | let secret = false; |
| 74 | for (const arg of args) { |
| 75 | if (/^expires=\d+$/.test(arg)) { |
| 76 | expires = arg.split("=")[1]; |
| 77 | } else if (arg === "secret") { |
| 78 | secret = true; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | let replied: Api.Message | undefined; |
| 83 | try { |
| 84 | replied = await safeGetReplyMessage(msg); |
| 85 | } catch (e: any) { |
| 86 | await sendLongMessage(msg, `❌ <b>错误:</b> ${htmlEscape(e.message)}`); |
| 87 | return; |
| 88 | } |
| 89 | if (!replied || !replied.media) { |
| 90 | await sendLongMessage(msg, `❌ <b>错误:</b> 请回复一条带文件、视频、语音、图片等消息`); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | await msg.edit({ text: "⏳ 正在下载并上传..." }); |
| 95 | try { |
| 96 | const buffer = await replied.downloadMedia(); |
| 97 | if (!Buffer.isBuffer(buffer) || buffer.length === 0) { |
| 98 | await sendLongMessage(msg, `❌ <b>错误:</b> 媒体下载失败或为空`); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | // 文件名只保留英文、数字、下划线和扩展名,最长32位 |
| 103 | let filename = "file"; |
| 104 | if (replied.document && replied.document.attributes) { |
| 105 | const attr = replied.document.attributes.find( |
| 106 | (a: any) => a instanceof Api.DocumentAttributeFilename |
| 107 | ); |
| 108 | if (attr && attr.fileName) filename = attr.fileName; |
| 109 | } else if (replied.message) { |
| 110 | filename = replied.message.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 32) || filename; |
| 111 | } else if (replied.video) { |
| 112 | filename = "video.mp4"; |
| 113 | } else if (replied.audio) { |
nothing calls this directly
no test coverage detected