(sock, message, args, context)
| 6 | description: 'Get a GIF based on a search term', |
| 7 | usage: '.gif <search term>', |
| 8 | async handler(sock, message, args, context) { |
| 9 | const chatId = context.chatId || message.key.remoteJid; |
| 10 | const config = context.config; |
| 11 | const query = args.join(' '); |
| 12 | if (!query) { |
| 13 | await sock.sendMessage(chatId, { text: 'Please provide a search term for the GIF.' }, { quoted: message }); |
| 14 | return; |
| 15 | } |
| 16 | try { |
| 17 | const response = await axios.get('https://api.giphy.com/v1/gifs/search', { |
| 18 | params: { |
| 19 | api_key: config.giphyApiKey, |
| 20 | q: query, |
| 21 | limit: 1, |
| 22 | rating: 'g' |
| 23 | } |
| 24 | }); |
| 25 | const gifData = response.data.data[0]; |
| 26 | if (!gifData) { |
| 27 | await sock.sendMessage(chatId, { text: 'No GIFs found for your search term.' }, { quoted: message }); |
| 28 | return; |
| 29 | } |
| 30 | const mp4Url = gifData.images.original_mp4?.mp4; |
| 31 | if (mp4Url) { |
| 32 | await sock.sendMessage(chatId, { video: { url: mp4Url }, caption: `Here is your GIF for "${query}"` }, { quoted: message }); |
| 33 | } |
| 34 | else { |
| 35 | const gifUrl = gifData.images.original?.url; |
| 36 | await sock.sendMessage(chatId, { document: { url: gifUrl }, mimetype: 'image/gif', caption: `Here is your GIF for "${query}"` }, { quoted: message }); |
| 37 | } |
| 38 | } |
| 39 | catch (error) { |
| 40 | console.error('Error in gif command:', error); |
| 41 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch GIF. Please try again later.' }, { quoted: message }); |
| 42 | } |
| 43 | } |
| 44 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected