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

Function handler

plugins/gitclone.ts:8–52  ·  view source on GitHub ↗
(sock: any, message: any, args: any)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected