MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/gitclone2.js:8–47  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 description: 'Download a GitHub repository as a ZIP file',
7 usage: '.gitclone2 <github-link>',
8 async handler(sock, message, args, context) {
9 const { chatId } = context;
10 const regex = new RegExp('(?:https|git)(?://|@)github.com[/:]([^/:]+)/(.+)', 'i');
11 try {
12 const link = args[0];
13 if (!link) {
14 return await sock.sendMessage(chatId, {
15 text: `❌ *Missing Link!*\n\nExample: .gitclone2 https://github.com/GlobalTechInfo/MEGA-MD`
16 }, { quoted: message });
17 }
18 if (!regex.test(link)) {
19 return await sock.sendMessage(chatId, { text: '⚠️ *Invalid GitHub link!*' }, { quoted: message });
20 }
21 // eslint-disable-next-line prefer-const
22 let [_, user, repo] = link.match(regex) || [];
23 repo = repo.replace(/.git$/, '');
24 const url = `https://api.github.com/repos/${user}/${repo}/zipball`;
25 const { default: _axios } = await import('axios');
26 const _response = _axios.head;
27 const headRes = await axios.head(url);
28 const contentDisposition = headRes.headers['content-disposition'];
29 let filename = `${repo}.zip`;
30 if (contentDisposition) {
31 const match = contentDisposition.match(/attachment; filename=(.*)/);
32 if (match)
33 filename = match[1];
34 }
35 await sock.sendMessage(chatId, { text: `✳️ *Wait, sending repository...*` }, { quoted: message });
36 await sock.sendMessage(chatId, {
37 document: { url },
38 fileName: filename,
39 mimetype: 'application/zip',
40 caption: `📦 *Repository:* ${user}/${repo}\n✨ *Cloned by MEGA-MD*`
41 }, { quoted: message });
42 }
43 catch (err) {
44 console.error('Gitclone Error:', err);
45 await sock.sendMessage(chatId, { text: '❌ *Failed to download the repository.* Make sure it is public.' }, { quoted: message });
46 }
47 }
48};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected