(sock, message, args, context)
| 20 | description: 'Search and download ringtones', |
| 21 | usage: '.ringtone <search term>', |
| 22 | async handler(sock, message, args, context) { |
| 23 | const chatId = context.chatId || message.key.remoteJid; |
| 24 | const searchQuery = args.join(' ').trim(); |
| 25 | try { |
| 26 | if (!searchQuery) { |
| 27 | return await sock.sendMessage(chatId, { |
| 28 | text: "*Which ringtone do you want to search?*\nUsage: .ringtone <name>\n\nExample: .ringtone Nokia" |
| 29 | }, { quoted: message }); |
| 30 | } |
| 31 | await sock.sendMessage(chatId, { |
| 32 | text: "🔍 *Searching for ringtones...*" |
| 33 | }, { quoted: message }); |
| 34 | await new Promise(resolve => setTimeout(resolve, 10000)); |
| 35 | const searchUrl = `https://discardapi.dpdns.org/api/dl/ringtone?apikey=guru&title=${encodeURIComponent(searchQuery)}`; |
| 36 | const response = await axios.get(searchUrl, { timeout: 30000 }); |
| 37 | if (!response.data?.result || response.data.result.length === 0) { |
| 38 | return await sock.sendMessage(chatId, { |
| 39 | text: "❌ *No ringtones found!*\nTry a different search term." |
| 40 | }, { quoted: message }); |
| 41 | } |
| 42 | const ringtones = response.data.result; |
| 43 | const totalFound = ringtones.length; |
| 44 | const limit = Math.min(2, totalFound); |
| 45 | for (let i = 0; i < limit; i++) { |
| 46 | const audioUrl = ringtones[i].audio; |
| 47 | try { |
| 48 | await sock.sendMessage(chatId, { |
| 49 | audio: { url: audioUrl }, |
| 50 | mimetype: "audio/mpeg", |
| 51 | fileName: `${searchQuery}_${i + 1}.mp3`, |
| 52 | contextInfo: { |
| 53 | externalAdReply: { |
| 54 | title: `${searchQuery} Ringtone ${i + 1}`, |
| 55 | body: `Ringtone ${i + 1} of ${limit}`, |
| 56 | mediaType: 2, |
| 57 | thumbnail: null |
| 58 | } |
| 59 | } |
| 60 | }, { quoted: message }); |
| 61 | if (i < limit - 1) { |
| 62 | await new Promise(resolve => setTimeout(resolve, 2000)); |
| 63 | } |
| 64 | } |
| 65 | catch (sendError) { |
| 66 | console.error(`Failed to send ringtone ${i + 1}:`, sendError.message); |
| 67 | continue; |
| 68 | } |
| 69 | } |
| 70 | await sock.sendMessage(chatId, { |
| 71 | text: `✅ *Sent ${limit} ringtones!*\n\n${totalFound > limit ? `📊 *${totalFound - limit} more available*\nUse the same command again for different results.` : ''}` |
| 72 | }, { quoted: message }); |
| 73 | } |
| 74 | catch (error) { |
| 75 | console.error('Ringtone Command Error:', error); |
| 76 | let errorMsg = "❌ *Search failed!*\n\n"; |
| 77 | if (error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') { |
| 78 | errorMsg += "*Reason:* Connection timeout\nThe API took too long to respond."; |
| 79 | } |
nothing calls this directly
no outgoing calls
no test coverage detected