(sock, chatId, quotedMsg, mentionedJid, sender)
| 1 | const fetch = require('node-fetch'); |
| 2 | |
| 3 | async function simpCommand(sock, chatId, quotedMsg, mentionedJid, sender) { |
| 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 profile picture URL |
| 13 | let avatarUrl; |
| 14 | try { |
| 15 | avatarUrl = await sock.profilePictureUrl(who, 'image'); |
| 16 | } catch (error) { |
| 17 | console.error('Error fetching profile picture:', error); |
| 18 | avatarUrl = 'https://telegra.ph/file/24fa902ead26340f3df2c.png'; // Default avatar |
| 19 | } |
| 20 | |
| 21 | // Fetch the simp card from the API |
| 22 | const apiUrl = `https://some-random-api.com/canvas/misc/simpcard?avatar=${encodeURIComponent(avatarUrl)}`; |
| 23 | const response = await fetch(apiUrl); |
| 24 | |
| 25 | if (!response.ok) { |
| 26 | throw new Error(`API responded with status: ${response.status}`); |
| 27 | } |
| 28 | |
| 29 | // Get the image buffer |
| 30 | const imageBuffer = await response.buffer(); |
| 31 | |
| 32 | // Send the image with caption |
| 33 | await sock.sendMessage(chatId, { |
| 34 | image: imageBuffer, |
| 35 | caption: '*your religion is simping*', |
| 36 | contextInfo: { |
| 37 | forwardingScore: 1, |
| 38 | isForwarded: true, |
| 39 | forwardedNewsletterMessageInfo: { |
| 40 | newsletterJid: '120363406588763460@newsletter', |
| 41 | newsletterName: 'Zenitsu Bot', |
| 42 | serverMessageId: -1 |
| 43 | } |
| 44 | } |
| 45 | }); |
| 46 | |
| 47 | } catch (error) { |
| 48 | console.error('Error in simp command:', error); |
| 49 | await sock.sendMessage(chatId, { |
| 50 | text: '❌ Sorry, I couldn\'t generate the simp card. Please try again later!', |
| 51 | contextInfo: { |
| 52 | forwardingScore: 1, |
| 53 | isForwarded: true, |
| 54 | forwardedNewsletterMessageInfo: { |
| 55 | newsletterJid: '120363406588763460@newsletter', |
| 56 | newsletterName: 'Zenitsu Bot', |
| 57 | serverMessageId: -1 |
| 58 | } |
| 59 | } |
| 60 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected