MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/scloud.js:8–94  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 description: 'Search for tracks on SoundCloud',
7 usage: '.scloud <song name>',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const searchQuery = args.join(' ').trim();
11 try {
12 if (!searchQuery) {
13 return await sock.sendMessage(chatId, {
14 text: "*What do you want to search on SoundCloud?*\nUsage: .soundcloud <song name>\n\nExample: .soundcloud never gonna give you up"
15 }, { quoted: message });
16 }
17 await new Promise(resolve => setTimeout(resolve, 10000));
18 const searchUrl = `https://discardapi.dpdns.org/api/search/soundcloud?apikey=guru&query=${encodeURIComponent(searchQuery)}`;
19 const response = await axios.get(searchUrl, { timeout: 30000 });
20 if (!response.data?.result?.result || response.data.result.result.length === 0) {
21 return await sock.sendMessage(chatId, {
22 text: "❌ *No results found!*\nTry a different search term."
23 }, { quoted: message });
24 }
25 const results = response.data.result.result;
26 const totalFound = results.length;
27 const tracks = results.filter((item) => item.kind === 'track');
28 if (tracks.length === 0) {
29 return await sock.sendMessage(chatId, {
30 text: "❌ *No tracks found!*\nOnly found user profiles. Try searching for specific songs."
31 }, { quoted: message });
32 }
33 const limit = Math.min(5, tracks.length);
34 let resultText = `🎵 *SoundCloud Results*\n`;
35 resultText += `📊 Found ${totalFound} results (${tracks.length} tracks)\n\n`;
36 for (let i = 0; i < limit; i++) {
37 const track = tracks[i];
38 const duration = Math.floor(track.duration / 1000);
39 const minutes = Math.floor(duration / 60);
40 const seconds = duration % 60;
41 resultText += `*${i + 1}. ${track.title}*\n`;
42 resultText += `👤 Artist: ${track.user_id ? 'Available' : 'Unknown'}\n`;
43 resultText += `⏱️ Duration: ${minutes}:${seconds.toString().padStart(2, '0')}\n`;
44 resultText += `👂 Plays: ${track.playback_count?.toLocaleString() || 'N/A'}\n`;
45 resultText += `❤️ Likes: ${track.likes_count?.toLocaleString() || 'N/A'}\n`;
46 resultText += `💬 Comments: ${track.comment_count?.toLocaleString() || 'N/A'}\n`;
47 resultText += `🎼 Genre: ${track.genre || 'Unknown'}\n`;
48 resultText += `🔗 Link: ${track.permalink_url}\n\n`;
49 }
50 if (tracks.length > limit) {
51 resultText += `_+${tracks.length - limit} more tracks available_`;
52 }
53 const firstTrack = tracks[0];
54 if (firstTrack.artwork_url) {
55 try {
56 const imageBuffer = await axios.get(firstTrack.artwork_url, {
57 responseType: 'arraybuffer',
58 timeout: 15000
59 }).then(res => Buffer.from(res.data));
60 await sock.sendMessage(chatId, {
61 image: imageBuffer,
62 caption: resultText
63 }, { quoted: message });
64 }
65 catch (imgError) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected