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

Function handler

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

Source from the content-addressed store, hash-verified

6 description: 'Download image or video from iStock URL',
7 usage: '.istock <iStock URL>',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const url = args?.[0]?.trim();
11 if (!url) {
12 return await sock.sendMessage(chatId, { text: 'Please provide an iStock URL.\nExample: .istock https://www.istockphoto.com/video/...' }, { quoted: message });
13 }
14 try {
15 const apiUrl = `https://discardapi.dpdns.org/api/dl/istock?apikey=guru&url=${encodeURIComponent(url)}`;
16 const { data } = await axios.get(apiUrl, { timeout: 10000 });
17 if (!data?.status || !data.result) {
18 return await sock.sendMessage(chatId, { text: '❌ Failed to fetch media from the provided iStock URL.' }, { quoted: message });
19 }
20 const item = data.result;
21 if (item.video) {
22 await sock.sendMessage(chatId, { video: { url: item.video }, caption: '🎬 *iStock Video*' }, { quoted: message });
23 }
24 if (item.image) {
25 await sock.sendMessage(chatId, { image: { url: item.image }, caption: '🖼️ *iStock Image*' }, { quoted: message });
26 }
27 }
28 catch (error) {
29 console.error('iStock download plugin error:', error);
30 if (error.code === 'ECONNABORTED') {
31 await sock.sendMessage(chatId, { text: '❌ Request timed out. The API may be slow or unreachable.' }, { quoted: message });
32 }
33 else {
34 await sock.sendMessage(chatId, { text: '❌ Failed to download media from iStock URL.' }, { quoted: message });
35 }
36 }
37 }
38};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected