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

Function handler

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

Source from the content-addressed store, hash-verified

6 description: 'Download media (video or image) from Snapchat Spotlight URL',
7 usage: '.snapchat <Snapchat URL>',
8 async handler(sock, message, args, context) {
9 const { chatId, channelInfo, rawText } = context;
10 const prefix = context.rawText.match(/^[.!#]/)?.[0] || '.';
11 const commandPart = rawText.slice(prefix.length).trim();
12 const parts = commandPart.split(/\s+/);
13 const url = parts.slice(1).join(' ').trim();
14 if (!url) {
15 return await sock.sendMessage(chatId, {
16 text: 'Please provide a Snapchat Spotlight URL.\nExample: .snapchat https://www.snapchat.com/spotlight/...',
17 ...channelInfo
18 }, { quoted: message });
19 }
20 try {
21 await sock.sendMessage(chatId, {
22 text: '⏳ Fetching Snapchat media...',
23 ...channelInfo
24 }, { quoted: message });
25 const apiUrl = `https://discardapi.dpdns.org/api/dl/snapchat?apikey=guru&url=${encodeURIComponent(url)}`;
26 console.log('Requesting URL:', apiUrl);
27 console.log('Original URL:', url);
28 const { data } = await axios.get(apiUrl, {
29 timeout: 15000,
30 headers: {
31 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
32 }
33 });
34 console.log('Snapchat API Response:', JSON.stringify(data, null, 2));
35 if (!data || data.status !== true || !data.result || !Array.isArray(data.result) || data.result.length === 0) {
36 return await sock.sendMessage(chatId, {
37 text: '❌ No media found for this Snapchat Spotlight URL.',
38 ...channelInfo
39 }, { quoted: message });
40 }
41 for (const mediaItem of data.result) {
42 if (mediaItem.video) {
43 await sock.sendMessage(chatId, {
44 video: { url: mediaItem.video },
45 caption: '📹 Snapchat Spotlight Video',
46 ...channelInfo
47 }, { quoted: message });
48 }
49 if (mediaItem.image) {
50 await sock.sendMessage(chatId, {
51 image: { url: mediaItem.image },
52 caption: '🖼 Snapchat Spotlight Image',
53 ...channelInfo
54 }, { quoted: message });
55 }
56 }
57 }
58 catch (error) {
59 console.error('Snapchat plugin error:', error.message);
60 await sock.sendMessage(chatId, {
61 text: `❌ Failed to fetch Snapchat media.\nError: ${error.message}`,
62 ...channelInfo
63 }, { quoted: message });
64 }
65 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected