(sock, message, args, context)
| 7 | description: 'Generate a quote sticker from text', |
| 8 | usage: '.quote <text> or reply to a message', |
| 9 | async handler(sock, message, args, context) { |
| 10 | const chatId = context.chatId || message.key.remoteJid; |
| 11 | const ctx = message.message?.extendedTextMessage?.contextInfo; |
| 12 | let text = args.join(' ').trim(); |
| 13 | if (!text) { |
| 14 | const q = ctx?.quotedMessage; |
| 15 | if (!q) |
| 16 | return sock.sendMessage(chatId, { text: '📝 Please provide text or reply to a message.\n\nUsage: .quote <text>' }, { quoted: message }); |
| 17 | text = q.conversation |
| 18 | || q.extendedTextMessage?.text |
| 19 | || q.imageMessage?.caption |
| 20 | || q.videoMessage?.caption |
| 21 | || 'Media message'; |
| 22 | } |
| 23 | const who = ctx?.participant |
| 24 | || ctx?.mentionedJid?.[0] |
| 25 | || message.key.participant |
| 26 | || message.key.remoteJid; |
| 27 | const [userPfp, contactInfo] = await Promise.allSettled([ |
| 28 | sock.profilePictureUrl(who, 'image'), |
| 29 | sock.onWhatsApp(who) |
| 30 | ]); |
| 31 | const pfp = userPfp.status === 'fulfilled' |
| 32 | ? userPfp.value |
| 33 | : 'https://i.ibb.co/9HY4wjz/a4c0b1af253197d4837ff6760d5b81c0.jpg'; |
| 34 | const contactValue = contactInfo.status === 'fulfilled' ? contactInfo.value : null; |
| 35 | // Try multiple sources for name |
| 36 | const storeContact = sock.store?.contacts?.[who]; |
| 37 | const userName = storeContact?.name |
| 38 | || storeContact?.notify |
| 39 | || contactValue?.[0]?.notify |
| 40 | || (who.includes('@s.whatsapp.net') ? `+${ who.replace('@s.whatsapp.net', '')}` : 'User'); |
| 41 | try { |
| 42 | const res = await axios.post('https://bot.lyo.su/quote/generate', { |
| 43 | type: 'quote', |
| 44 | format: 'png', |
| 45 | backgroundColor: '#FFFFFF', |
| 46 | width: 1800, |
| 47 | height: 200, |
| 48 | scale: 2, |
| 49 | messages: [{ |
| 50 | entities: [], |
| 51 | avatar: true, |
| 52 | from: { id: 1, name: userName, photo: { url: pfp } }, |
| 53 | text, |
| 54 | replyMessage: {} |
| 55 | }] |
| 56 | }, { |
| 57 | headers: { 'Content-Type': 'application/json' }, |
| 58 | timeout: 30000 |
| 59 | }); |
| 60 | if (!res.data?.result?.image) |
| 61 | throw new Error('Invalid API response'); |
| 62 | const bufferImage = Buffer.from(res.data.result.image, 'base64'); |
| 63 | try { |
| 64 | const stickerBuffer = await new Sticker(bufferImage, { |
| 65 | pack: 'MEGA-MD', |
| 66 | author: userName, |
nothing calls this directly
no outgoing calls
no test coverage detected