const axios = require('axios'); module.exports.config = { name: "regco", version: "1.0.1", hasPermssion: 0, credits: "Jonell Magallanes", description: "Recognize music", usePrefix: true, commandCategory: "Tool", usages: "Utility", cooldowns: 5, }; module.exports.languages = { "vi": { "invalidFormat": "❌ Tin nhắn bạn phản hồi phải là một audio, video, ảnh nào đó" }, "en": { "invalidFormat": "❌ You need to reply to a message containing audio or video" } }; module.exports.run = async ({ api, event, getText }) => { if (event.type !== "message_reply") return api.sendMessage(getText("invalidFormat"), event.threadID, event.messageID); if (!event.messageReply.attachments || event.messageReply.attachments.length === 0) return api.sendMessage(getText("invalidFormat"), event.threadID, event.messageID); if (event.messageReply.attachments.length > 1) return api.sendMessage(getText("invalidFormat"), event.threadID, event.messageID); const pro = await api.sendMessage("Uploading Attachment URL.....", event.threadID, event.messageID); const attachmentUrl = event.messageReply.attachments[0].url; const apiUrl = `https://ccprojectsapis.zetsu.xyz/api/recog?url=${attachmentUrl}`; const config = { headers: { 'User-Agent': 'Mozilla/5.0' } }; const retryLimit = 4; let attempt = 0; let responseData = null; const retryMessages = [ "Retrying to recognize the music...", "Still trying to recognize the music...", "Last attempt to recognize the music...", "Final retry to recognize the music..." ]; while (attempt < retryLimit) { try { if (attempt > 0) { api.editMessage(retryMessages[attempt - 1], pro.messageID, event.threadID, event.messageID); } else { api.editMessage("Recognizing music...", pro.messageID, event.threadID, event.messageID); } const response = await axios.get(apiUrl, config); responseData = response.data; if (responseData.status === "success" && responseData.result?.artist !== "Unknown") { api.editMessage("Completed.", pro.messageID, event.threadID, event.messageID); break; } attempt++; if (attempt >= retryLimit) { throw new Error("Failed to recognize music after multiple attempts."); } await new Promise(resolve => setTimeout(resolve, 2000)); } catch (error) { console.error('Error:', error); if (attempt >= retryLimit - 1) { api.editMessage(`❌ Error: ${error.message}`, pro.messageID, event.threadID, event.messageID); return api.sendMessage(`❌ Error: ${error.message}`, event.threadID, event.messageID); } attempt++; await new Promise(resolve => setTimeout(resolve, 2000)); } } const { artist = "Unknown", title = "Unknown", album = "Unknown", release_date = "Unknown", label = "Unknown", timecode = "Unknown", song_link = "Unknown", apple_music = {} } = responseData.result || {}; const previewUrl = apple_music.previews?.[0]?.url || "No preview available"; const artworkUrl = apple_music.artwork?.url ? apple_music.artwork.url.replace("{w}", "500").replace("{h}", "500") : "No artwork available"; let messageContent = `🎵 𝗠𝘂𝘀𝗶𝗰 𝗥𝗲𝗰𝗼𝗴𝗻𝗶𝘁𝗶𝗼𝗻 𝗥𝗲𝘀𝘂𝗹𝘁\n━━━━━━━━━━━━━━━━━━\n` + `🎤 Artist: ${artist}\n` + `🎶 Title: ${title}\n` + `💿 Album: ${album}\n` + `📅 Release Date: ${release_date}\n` + `🏷 Label: ${label}\n` + `⏳ Timecode: ${timecode}\n` + `🔗 Song Link: ${song_link}\n` + `🎧 Apple Music Preview: ${previewUrl}\n` + `🖼 Artwork: ${artworkUrl}`; api.unsendMessage(pro.messageID); return api.sendMessage(messageContent, event.threadID, event.messageID); };