import axios from 'axios' import { readFileSync } from 'fs' const chat_id = '@MihomoPartyChannel' const pkg = readFileSync('package.json', 'utf-8') const changelog = readFileSync('changelog.md', 'utf-8') const { version } = JSON.parse(pkg) const releaseType = process.env.RELEASE_TYPE || process.argv[2] || 'release' const isDevRelease = releaseType === 'dev' function convertMarkdownToTelegramHTML(content) { return content .split("\n") .map((line) => { if (line.trim().length === 0) { return ""; } else if (line.startsWith("## ")) { return `${line.replace("## ", "")}`; } else if (line.startsWith("### ")) { return `${line.replace("### ", "")}`; } else if (line.startsWith("#### ")) { return `${line.replace("#### ", "")}`; } else { let processedLine = line.replace( /\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => { const encodedUrl = encodeURI(url); return `${text}`; }, ); processedLine = processedLine.replace( /\*\*([^*]+)\*\*/g, "$1", ); return processedLine; } }) .join("\n"); } let content = ''; if (isDevRelease) { const commitSha = process.env.GITHUB_SHA || 'unknown' const shortCommitSha = commitSha.substring(0, 7) content = `🚧 Clash Party Dev Build 开发版本发布\n\n` content += `基于版本: ${version}\n` content += `提交哈希: ${shortCommitSha}\n\n` content += `更新日志:\n` content += convertMarkdownToTelegramHTML(changelog) content += '\n\n⚠️ 注意:这是开发版本,可能存在不稳定性,仅供测试使用\n' } else { // 正式版本通知 content = `🌟 Clash Party v${version} 正式发布\n\n` content += convertMarkdownToTelegramHTML(changelog) } // 构建下载链接 const downloadUrl = isDevRelease ? `https://github.com/mihomo-party-org/mihomo-party/releases/download/dev` : `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}` content += '\n下载地址:\nWindows10/11:\n' content += `安装版:64位 | 32位 | ARM64\n` content += `便携版:64位 | 32位 | ARM64\n` content += '\nWindows7/8:\n' content += `安装版:64位 | 32位\n` content += `便携版:64位 | 32位\n` content += '\nmacOS 11+:\n' content += `PKG:Intel | Apple Silicon\n` content += '\nmacOS 10.15+:\n' content += `PKG:Intel | Apple Silicon\n` content += '\nLinux:\n' content += `DEB:64位 | ARM64\n` content += `RPM:64位 | ARM64` await axios.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, { chat_id, text: content, link_preview_options: { is_disabled: false, url: 'https://github.com/mihomo-party-org/mihomo-party', prefer_large_media: true }, parse_mode: 'HTML' }) console.log(`${isDevRelease ? '开发版本' : '正式版本'}Telegram 通知发送成功`)