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