(sock, message, args, context)
| 5 | description: 'Generate a stupid card for a user', |
| 6 | usage: '.stupid (reply to user, mention someone, or add text)', |
| 7 | async handler(sock, message, args, context) { |
| 8 | const chatId = context.chatId || message.key.remoteJid; |
| 9 | const sender = message.key.participant || message.key.remoteJid; |
| 10 | const quotedMsg = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 11 | const mentionedJid = message.message?.extendedTextMessage?.contextInfo?.mentionedJid; |
| 12 | const who = quotedMsg |
| 13 | ? quotedMsg.sender |
| 14 | : mentionedJid && mentionedJid[0] |
| 15 | ? mentionedJid[0] |
| 16 | : sender; |
| 17 | const text = args && args.length > 0 ? args.join(' ') : 'im+stupid'; |
| 18 | try { |
| 19 | let avatarUrl; |
| 20 | try { |
| 21 | avatarUrl = await sock.profilePictureUrl(who, 'image'); |
| 22 | } |
| 23 | catch (error) { |
| 24 | console.error('Error fetching profile picture:', error); |
| 25 | avatarUrl = 'https://telegra.ph/file/24fa902ead26340f3df2c.png'; // Default avatar |
| 26 | } |
| 27 | const apiUrl = `https://api.popcat.xyz/its-so-stupid?image=${encodeURIComponent(avatarUrl)}&text=${encodeURIComponent(text)}`; |
| 28 | const response = await fetch(apiUrl); |
| 29 | if (!response.ok) |
| 30 | throw new Error(`API responded with status: ${response.status}`); |
| 31 | const imageBuffer = Buffer.from(await response.arrayBuffer()); |
| 32 | await sock.sendMessage(chatId, { |
| 33 | image: imageBuffer, |
| 34 | caption: `*@${who.split('@')[0]}*`, |
| 35 | mentions: [who] |
| 36 | }, { quoted: message }); |
| 37 | } |
| 38 | catch (error) { |
| 39 | console.error('Stupid Command Error:', error); |
| 40 | await sock.sendMessage(chatId, { |
| 41 | text: '❌ Sorry, I couldn\'t generate the stupid card. Please try again later!' |
| 42 | }, { quoted: message }); |
| 43 | } |
| 44 | } |
| 45 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected