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

Function handler

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

Source from the content-addressed store, hash-verified

6 description: 'Get a screenshot of a website',
7 usage: '.screenshot <url>',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 let url = args?.[0]?.trim();
11 if (!url) {
12 return await sock.sendMessage(chatId, { text: '*Provide a URL.*\nExample: .screenshot https://github.com' }, { quoted: message });
13 }
14 if (!/^https?:\/\//i.test(url)) {
15 url = `https://${ url}`;
16 }
17 try {
18 new URL(url);
19 }
20 catch {
21 return await sock.sendMessage(chatId, { text: '❌ Invalid URL provided.' }, { quoted: message });
22 }
23 try {
24 const apiUrl = `https://discardapi.dpdns.org/api/tools/ssweb?apikey=guru&url=${encodeURIComponent(url)}`;
25 const { data } = await axios.get(apiUrl, {
26 responseType: 'arraybuffer',
27 timeout: 10000,
28 });
29 const caption = `🌐 Screenshot of:\n${url}`;
30 await sock.sendMessage(chatId, { image: { buffer: data }, caption }, { quoted: message });
31 }
32 catch (error) {
33 console.error('Screenshot plugin error:', error);
34 if (error.code === 'ECONNABORTED') {
35 await sock.sendMessage(chatId, { text: '❌ Request timed out. The site may be slow or unreachable.' }, { quoted: message });
36 }
37 else {
38 await sock.sendMessage(chatId, { text: '❌ Failed to fetch screenshot. Make sure the URL is correct.' }, { quoted: message });
39 }
40 }
41 }
42};

Callers 1

monitoredHandlerMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected