(sock, chatId, quotedMsg, mentionedJid, sender, args)
| 1 | const fetch = require('node-fetch'); |
| 2 | |
| 3 | async function stupidCommand(sock, chatId, quotedMsg, mentionedJid, sender, args) { |
| 4 | try { |
| 5 | // Determine the target user |
| 6 | let who = quotedMsg |
| 7 | ? quotedMsg.sender |
| 8 | : mentionedJid && mentionedJid[0] |
| 9 | ? mentionedJid[0] |
| 10 | : sender; |
| 11 | |
| 12 | // Get the text for the stupid card (default to "im+stupid" if not provided) |
| 13 | let text = args && args.length > 0 ? args.join(' ') : 'im+stupid'; |
| 14 | |
| 15 | // Get the profile picture URL |
| 16 | let avatarUrl; |
| 17 | try { |
| 18 | avatarUrl = await sock.profilePictureUrl(who, 'image'); |
| 19 | } catch (error) { |
| 20 | console.error('Error fetching profile picture:', error); |
| 21 | avatarUrl = 'https://telegra.ph/file/24fa902ead26340f3df2c.png'; // Default avatar |
| 22 | } |
| 23 | |
| 24 | // Fetch the stupid card from the API |
| 25 | const apiUrl = `https://some-random-api.com/canvas/misc/its-so-stupid?avatar=${encodeURIComponent(avatarUrl)}&dog=${encodeURIComponent(text)}`; |
| 26 | const response = await fetch(apiUrl); |
| 27 | |
| 28 | if (!response.ok) { |
| 29 | throw new Error(`API responded with status: ${response.status}`); |
| 30 | } |
| 31 | |
| 32 | // Get the image buffer |
| 33 | const imageBuffer = await response.buffer(); |
| 34 | |
| 35 | // Send the image with caption |
| 36 | await sock.sendMessage(chatId, { |
| 37 | image: imageBuffer, |
| 38 | caption: `*@${who.split('@')[0]}*`, |
| 39 | mentions: [who] |
| 40 | }); |
| 41 | |
| 42 | } catch (error) { |
| 43 | console.error('Error in stupid command:', error); |
| 44 | await sock.sendMessage(chatId, { |
| 45 | text: '❌ Sorry, I couldn\'t generate the stupid card. Please try again later!' |
| 46 | }); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | module.exports = { stupidCommand }; |
nothing calls this directly
no outgoing calls
no test coverage detected