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

Function handler

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

Source from the content-addressed store, hash-verified

9 usage: '.sharechat <ShareChat URL>',
10
11 async handler(sock: any, message: any, args: any, context: BotContext) {
12 const chatId = context.chatId || message.key.remoteJid;
13 const url = args?.[0];
14
15 if (!url) {
16 return await sock.sendMessage(chatId, { text: 'Please provide a ShareChat URL.\nExample: .sharechat https://sharechat.com/video/XDPQKxb?referrer=url' }, { quoted: message });
17 }
18
19 try {
20 const apiUrl = `https://discardapi.dpdns.org/api/dl/sharechat?apikey=guru&url=${encodeURIComponent(url)}`;
21 const { data } = await axios.get(apiUrl, { timeout: 10000 });
22
23 if (!data?.status || !data.result?.length) {
24 return await sock.sendMessage(chatId, { text: '❌ No video found for this URL.' }, { quoted: message });
25 }
26
27 const videoUrl = data.result[0].video;
28 const imageUrl = data.result[0].image;
29
30 if (imageUrl) {
31 await sock.sendMessage(chatId, { image: { url: imageUrl }, caption: '🖼️ ShareChat Thumbnail' }, { quoted: message });
32 }
33
34 if (videoUrl) {
35 await sock.sendMessage(chatId, { video: { url: videoUrl }, caption: '🎬 ShareChat Video' }, { quoted: message });
36 }
37
38 } catch(error: any) {
39 console.error('ShareChat plugin error:', error);
40
41 if (error.code === 'ECONNABORTED') {
42 await sock.sendMessage(chatId, { text: '❌ Request timed out. The API may be slow or unreachable.' }, { quoted: message });
43 } else {
44 await sock.sendMessage(chatId, { text: '❌ Failed to fetch ShareChat video.' }, { quoted: message });
45 }
46 }
47 }
48};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected