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

Function handler

plugins/snapchat.ts:12–79  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected