Isla Chan - Sharing
February 26, 2025 at 08:49 AM
/*
Fitur: Git Clone
Type: Plugins `ESM`
Description: Cloning Repostories Github
Request From: @Haku
By: HamzDxD
Source:
https://whatsapp.com/channel/0029Vb1NWzkCRs1ifTWBb13u
*/
import fetch from 'node-fetch'
const regex = /(?:https|git)(?::\/\/|@)github\.com[\/:]([^\/:]+)\/(.+)/i
const handler = async (m, { args, usedPrefix, command, conn }) => {
if (!args[0]) throw `*Contoh Penggunaan:*\n${usedPrefix}${command} https://github.com/username/repo`
if (!regex.test(args[0])) throw '❌ *URL GitHub tidak valid!*'
let [_, user, repo] = args[0].match(regex) || []
repo = repo.replace(/.git$/, '')
let apiUrl = `https://api.github.com/repos/${user}/${repo}`
let zipUrl = `https://api.github.com/repos/${user}/${repo}/zipball`
try {
let repoRes = await fetch(apiUrl)
if (!repoRes.ok) throw `❌ *Repository tidak ditemukan atau API limit GitHub tercapai!*`
let repoInfo = await repoRes.json()
if (repoInfo.private) throw '🔒 *Repository bersifat private!*'
let zipRes = await fetch(zipUrl, { method: 'HEAD' })
if (!zipRes.ok) throw '❌ *Gagal mendapatkan file ZIP!*'
let size = zipRes.headers.get('content-length')
if (size && size > 50 * 1024 * 1024) throw '⚠️ *Ukuran repository terlalu besar!* (Maks 50MB)'
let filename = zipRes.headers.get('content-disposition')?.match(/attachment; filename=(.*)/)?.[1] || `${repo}.zip`
let lastUpdated = new Date(repoInfo.updated_at).toLocaleString('id-ID', {
weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', hour: '2-digit', minute: '2-digit'
})
let repoText = `
🌐 `Repository Info`
👤 *Nama:* ${repoInfo.full_name}
📑 *Deskripsi:* ${repoInfo.description || 'Tidak ada'}
⭐ *Stars:* ${repoInfo.stargazers_count}
⛓️💥 *Forks:* ${repoInfo.forks_count}
📍 *Issues:* ${repoInfo.open_issues_count}
🗓️ *Terakhir Diperbarui:* ${lastUpdated}
`.trim()
await conn.relayMessage(m.chat, {
extendedTextMessage:{
text: repoText,
mentionedJid: [m.sender],
contextInfo: {
externalAdReply: {
title: repoInfo.full_name,
body: `⭐ ${repoInfo.stargazers_count} | 🍴 ${repoInfo.forks_count} | 🐞 ${repoInfo.open_issues_count}`,
thumbnailUrl: repoInfo.owner.avatar_url,
mediaType: 1,
renderLargerThumbnail: true,
sourceUrl: `https://github.com/${user}/${repo}`,
showAdAttribution: true
}
}
}}, { quoted: m })
await conn.sendMessage(m.chat, { document: { url: zipUrl }, mimetype: 'application/zip', fileName: filename }, { quoted: m })
} catch (e) {
m.reply(`❌ *Error:* ${e.message}`)
console.error(e)
}
}
handler.help = ['gitclone'].map(v => v + ' ')
handler.tags = ['downloader']
handler.command = /gitclone/i
handler.limit = true
export default handler