// code from goatstore // api: https://store.agi.bd const axios = require("axios"); // ====================================================== // YOUTUBE DATA API V3 // ====================================================== const YOUTUBE_API_KEY = "AIzaSyCILEZe0UUSaWO5r6GY5lLmR_z1OpDy2aA"; // ====================================================== // SEARCH CACHE // ====================================================== const searchCache = new Map(); module.exports = { config: { name: "music", version: "4.0.0", author: "Asif", countDown: 5, role: 0, category: "media", shortDescription: { en: "Search YouTube music" }, longDescription: { en: "Search YouTube songs and select a song by number" }, guide: { en: "{pn} " } }, // ====================================================== // SEARCH MUSIC // ====================================================== onStart: async function ({ message, args, event }) { try { if (!YOUTUBE_API_KEY) { return message.reply( "❌ YouTube API key পাওয়া যাচ্ছে না।" ); } const query = args.join(" ").trim(); if (!query) { return message.reply( "🎵 | Music search করতে লিখো:\n\n" + "music Tum Hi Ho" ); } const loading = await message.reply( "🔎 | YouTube-এ গান খুঁজছি..." ); message.reaction("🔎", event.messageID); const response = await axios.get( "https://www.googleapis.com/youtube/v3/search", { params: { part: "snippet", q: query, type: "video", videoCategoryId: "10", maxResults: 5, key: YOUTUBE_API_KEY }, timeout: 15000 } ); const items = response.data.items || []; if (loading?.messageID) { await message.unsend(loading.messageID); } if (!items.length) { message.reaction("❌", event.messageID); return message.reply( `❌ | "${query}" নামে কোনো গান পাওয়া যায়নি।` ); } // Save results searchCache.set(event.threadID, { items: items, userID: event.senderID, createdAt: Date.now() }); let result = "╭━━━〔 🎵 𝗠𝗨𝗦𝗜𝗖 𝗦𝗘𝗔𝗥𝗖 〕━━━╮\n\n"; items.forEach((item, index) => { const title = cleanText( item.snippet.title ); const channel = cleanText( item.snippet.channelTitle ); result += ` ${index + 1}. ${title}\n` + ` 👤 ${channel}\n\n`; }); result += "╰━━━━━━━━━━━━━━━━━━━━━━╯\n" + "↩️ Reply with 1-5 to select a song."; message.reaction("✅", event.messageID); const sent = await message.reply(result); // GoatBot reply system if ( global.GoatBot && global.GoatBot.onReply ) { global.GoatBot.onReply.set( sent.messageID, { commandName: "music", messageID: sent.messageID, author: event.senderID, threadID: event.threadID } ); } } catch (error) { console.error( "Music Search Error:", error.response?.data || error.message ); message.reaction("❌", event.messageID); const reason = error.response?.data?.error?.errors?.[0]?.reason; if (reason === "quotaExceeded") { return message.reply( "❌ | YouTube API quota শেষ হয়ে গেছে।" ); } if ( reason === "keyInvalid" || error.response?.data?.error?.code === 400 ) { return message.reply( "❌ | YouTube API key invalid।" ); } return message.reply( "❌ | YouTube search করতে সমস্যা হয়েছে।\n" + "কিছুক্ষণ পরে আবার চেষ্টা করো।" ); } }, // ====================================================== // NUMBER SELECTION // ====================================================== onReply: async function ({ message, event, Reply }) { try { // Only original user can select if (event.senderID !== Reply.author) { return; } const text = event.body .trim() .toLowerCase(); const choice = Number(text); if ( !Number.isInteger(choice) || choice < 1 || choice > 5 ) { return message.reply( "❌ | শুধু 1, 2, 3, 4 অথবা 5 reply করো।" ); } const data = searchCache.get(Reply.threadID); if (!data || !data.items) { return message.reply( "⌛ | Search result পাওয়া যাচ্ছে না।\n" + "আবার `music song name` দাও।" ); } // Result expires after 10 minutes if ( Date.now() - data.createdAt > 10 * 60 * 1000 ) { searchCache.delete( Reply.threadID ); return message.reply( "⌛ | এই search result-এর সময় শেষ হয়ে গেছে।\n" + "আবার music search করো।" ); } const selected = data.items[choice - 1]; if (!selected) { return message.reply( "❌ | এই number-এর কোনো গান নেই।" ); } const videoID = selected.id.videoId; const title = cleanText( selected.snippet.title ); const channel = cleanText( selected.snippet.channelTitle ); const youtubeURL = `https://www.youtube.com/watch?v=${videoID}`; message.reaction( "🎵", event.messageID ); return message.reply( "╭━━━〔 🎵 𝗦𝗘𝗟𝗘𝗖𝗧𝗘𝗗 〕━━━╮\n\n" + `🎶 ${title}\n\n` + `👤 ${channel}\n\n` + `🔗 ${youtubeURL}\n\n` + "╰━━━━━━━━━━━━━━━━━━━━╯" ); } catch (error) { console.error( "Music Selection Error:", error.message ); return message.reply( "❌ | Song select করতে সমস্যা হয়েছে।" ); } } }; // ====================================================== // CLEAN YOUTUBE TEXT // ====================================================== function cleanText(text) { return String(text || "") .replace(/"/g, '"') .replace(/'/g, "'") .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .trim(); }