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

Function handler

plugins/gitclone2.ts:11–58  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected