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