(sock, message, args)
| 5 | description: 'Download a GitHub repository as zip', |
| 6 | usage: '.gitclone <url> OR <username> <repo>', |
| 7 | async handler(sock, message, args) { |
| 8 | const chatId = message.key.remoteJid; |
| 9 | if (!args || args.length === 0) { |
| 10 | return sock.sendMessage(chatId, { |
| 11 | text: '*🌟 Please provide a GitHub URL or username and repository name.*\n\n*Example usage:*\n\n.clone https://github.com/GlobalTechInfo/MEGA-MD\n\n.clone GlobalTechInfo MEGA-MD' |
| 12 | }); |
| 13 | } |
| 14 | let url = ''; |
| 15 | let repoName = ''; |
| 16 | if (args[0].startsWith('http')) { |
| 17 | const inputUrl = args[0].replace(/\.git$/, ''); |
| 18 | const parts = inputUrl.split('/'); |
| 19 | repoName = parts[parts.length - 1]; |
| 20 | url = inputUrl; |
| 21 | if (!url.endsWith('/')) |
| 22 | url += '/'; |
| 23 | url += 'archive/refs/heads/main.zip'; |
| 24 | } |
| 25 | else if (args.length >= 2) { |
| 26 | const username = args[0]; |
| 27 | const repo = args[1]; |
| 28 | repoName = repo; |
| 29 | url = `https://github.com/${username}/${repo}/archive/refs/heads/main.zip`; |
| 30 | } |
| 31 | else { |
| 32 | return sock.sendMessage(chatId, { |
| 33 | text: '*Missing repository info.*\n\n*Example usage:*\n\n.clone https://github.com/GlobalTechInfo/MEGA-MD\n\n.clone GlobalTechInfo MEGA-MD' |
| 34 | }); |
| 35 | } |
| 36 | await sock.sendMessage(chatId, { text: '⏱️ Preparing repository zip...' }); |
| 37 | try { |
| 38 | await sock.sendMessage(chatId, { |
| 39 | document: { url }, |
| 40 | fileName: `${repoName }.zip`, |
| 41 | mimetype: 'application/zip' |
| 42 | }); |
| 43 | } |
| 44 | catch (e) { |
| 45 | console.error(e); |
| 46 | await sock.sendMessage(chatId, { |
| 47 | text: '❌ Failed to fetch the repository. Please make sure the repository exists and try again.' |
| 48 | }); |
| 49 | } |
| 50 | } |
| 51 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected