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

Function handler

plugins/lyrics.ts:9–65  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

7 description: 'Get lyrics of a song along with artist and image',
8 usage: '.lyrics <song name>',
9 async handler(sock: any, message: any, args: any, context: BotContext) {
10 const chatId = context.chatId || message.key.remoteJid;
11 const songTitle = args.join(' ').trim();
12
13 if (!songTitle) {
14 await sock.sendMessage(chatId, {
15 text: '*Please enter the song name to get the lyrics!*\nUsage: `.lyrics <song name>`',
16 quoted: message
17 });
18 return;
19 }
20 try {
21 const apiUrl = `https://discardapi.dpdns.org/api/music/lyrics?apikey=qasim&song=${encodeURIComponent(songTitle)}`;
22 const res = await fetch(apiUrl);
23 if (!res.ok) throw new Error(`API request failed with status ${res.status}`);
24 const data = await res.json() as any as any;
25 const messageData = data?.result?.message;
26 if (!messageData?.lyrics) {
27 await sock.sendMessage(chatId, {
28 text: `❌ Sorry, I couldn't find any lyrics for "${songTitle}".`,
29 quoted: message
30 });
31 return;
32 }
33
34 const { artist, lyrics, image, title, url } = messageData;
35 const maxChars = 4096;
36 const lyricsOutput = lyrics.length > maxChars ? lyrics.slice(0, maxChars - 3) + '...' : lyrics;
37
38 const caption = `
39🎵 *${title}*
40👤 *Artist:* ${artist}
41🔗 *URL:* ${url}
42
43📝 *Lyrics:*
44${lyricsOutput}
45 `.trim();
46 if (image) {
47 await sock.sendMessage(chatId, {
48 image: { url: image },
49 caption: caption,
50 quoted: message
51 });
52 } else {
53 await sock.sendMessage(chatId, {
54 text: caption,
55 quoted: message
56 });
57 }
58 } catch(error: any) {
59 console.error('Lyrics Command Error:', error);
60 await sock.sendMessage(chatId, {
61 text: `❌ An error occurred while fetching the lyrics for "${songTitle}".`,
62 quoted: message
63 });
64 }
65 }
66};

Callers

nothing calls this directly

Calls 1

jsonMethod · 0.80

Tested by

no test coverage detected