(sock, message, args, context)
| 6 | description: 'Search and send first 4 Google images', |
| 7 | usage: '.gimage <search query>', |
| 8 | async handler(sock, message, args, context) { |
| 9 | const chatId = context.chatId || message.key.remoteJid; |
| 10 | const query = args?.join(' ').trim(); |
| 11 | if (!query) { |
| 12 | return await sock.sendMessage(chatId, { text: 'Please provide a search query.\nExample: .gimage Pakistan' }, { quoted: message }); |
| 13 | } |
| 14 | try { |
| 15 | const apiUrl = `https://discardapi.dpdns.org/api/dl/gimage?apikey=guru&query=${encodeURIComponent(query)}`; |
| 16 | const { data } = await axios.get(apiUrl, { timeout: 10000 }); |
| 17 | if (!data?.status || !data.imageUrls?.length) { |
| 18 | return await sock.sendMessage(chatId, { text: '❌ No images found for this query.' }, { quoted: message }); |
| 19 | } |
| 20 | const imagesToSend = data.imageUrls.slice(0, 4); |
| 21 | for (let i = 0; i < imagesToSend.length; i++) { |
| 22 | const imgUrl = imagesToSend[i]; |
| 23 | await sock.sendMessage(chatId, { image: { url: imgUrl }, caption: `🖼️ *Google Image ${i + 1}*` }, { quoted: message }); |
| 24 | await new Promise(resolve => setTimeout(resolve, 1000)); // 1 second delay |
| 25 | } |
| 26 | } |
| 27 | catch (error) { |
| 28 | console.error('GImage plugin error:', error); |
| 29 | if (error.code === 'ECONNABORTED') { |
| 30 | await sock.sendMessage(chatId, { text: '❌ Request timed out. The API may be slow or unreachable.' }, { quoted: message }); |
| 31 | } |
| 32 | else { |
| 33 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch Google images.' }, { quoted: message }); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected