(sock, message, args, context)
| 6 | description: 'Download media (video or image) from X/Twitter post', |
| 7 | usage: '.twitter <Tweet URL>', |
| 8 | async handler(sock, message, args, context) { |
| 9 | const chatId = context.chatId || message.key.remoteJid; |
| 10 | const url = args?.[0]; |
| 11 | if (!url) { |
| 12 | return await sock.sendMessage(chatId, { text: 'Please provide a Twitter/X URL.\nExample: .twitter https://x.com/i/status/2002054360428167305' }, { quoted: message }); |
| 13 | } |
| 14 | try { |
| 15 | const apiUrl = `https://discardapi.dpdns.org/api/dl/twitter?apikey=guru&url=${encodeURIComponent(url)}`; |
| 16 | const { data } = await axios.get(apiUrl, { timeout: 10000 }); |
| 17 | if (!data?.status || !data.result?.media?.length) { |
| 18 | return await sock.sendMessage(chatId, { text: '❌ No media found for this Tweet.' }, { quoted: message }); |
| 19 | } |
| 20 | const tweet = data.result; |
| 21 | const caption = ` |
| 22 | 📝 @${tweet.authorUsername} (${tweet.authorName}) |
| 23 | 📅 ${tweet.date} |
| 24 | ❤️ Likes: ${tweet.likes} | 🔁 Retweets: ${tweet.retweets} | 💬 Replies: ${tweet.replies} |
| 25 | |
| 26 | 💬 ${tweet.text} |
| 27 | `.trim(); |
| 28 | for (const mediaItem of tweet.media) { |
| 29 | if (mediaItem.type === 'video') { |
| 30 | await sock.sendMessage(chatId, { video: { url: mediaItem.url }, caption }, { quoted: message }); |
| 31 | } |
| 32 | else if (mediaItem.type === 'image') { |
| 33 | await sock.sendMessage(chatId, { image: { url: mediaItem.url }, caption }, { quoted: message }); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | catch (error) { |
| 38 | console.error('Twitter plugin error:', error); |
| 39 | if (error.code === 'ECONNABORTED') { |
| 40 | await sock.sendMessage(chatId, { text: '❌ Request timed out. The API may be slow or unreachable.' }, { quoted: message }); |
| 41 | } |
| 42 | else { |
| 43 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch Twitter/X media.' }, { quoted: message }); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected