(sock, message, args, context)
| 5 | description: 'Shorten a URL using TinyURL', |
| 6 | usage: '.tinyurl <url>', |
| 7 | async handler(sock, message, args, context) { |
| 8 | const chatId = context.chatId || message.key.remoteJid; |
| 9 | const query = args?.join(' ')?.trim(); |
| 10 | if (!query) { |
| 11 | return await sock.sendMessage(chatId, { text: '*Please provide a URL to shorten.*\nExample: .tinyurl https://example.com' }, { quoted: message }); |
| 12 | } |
| 13 | try { |
| 14 | const response = await fetch(`https://tinyurl.com/api-create.php?url=${encodeURIComponent(query)}`); |
| 15 | const shortUrl = await response.text(); |
| 16 | if (!shortUrl) { |
| 17 | return await sock.sendMessage(chatId, { text: '❌ Error: Could not generate a short URL.' }, { quoted: message }); |
| 18 | } |
| 19 | const output = `✨ *YOUR SHORT URL*\n\n` + |
| 20 | `🔗 *Original Link:*\n${query}\n\n` + |
| 21 | `✂️ *Shortened URL:*\n${shortUrl}`; |
| 22 | await sock.sendMessage(chatId, { text: output }, { quoted: message }); |
| 23 | } |
| 24 | catch (err) { |
| 25 | console.error('TinyURL plugin error:', err); |
| 26 | await sock.sendMessage(chatId, { text: '❌ Failed to shorten URL.' }, { quoted: message }); |
| 27 | } |
| 28 | } |
| 29 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected