MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / lyricsCommand

Function lyricsCommand

commands/lyrics.js:3–41  ·  view source on GitHub ↗
(sock, chatId, songTitle, message)

Source from the content-addressed store, hash-verified

1const fetch = require('node-fetch');
2
3async function lyricsCommand(sock, chatId, songTitle, message) {
4 if (!songTitle) {
5 await sock.sendMessage(chatId, {
6 text: '🔍 Please enter the song name to get the lyrics! Usage: *lyrics <song name>*'
7 },{ quoted: message });
8 return;
9 }
10
11 try {
12 // Use lyricsapi.fly.dev and return only the raw lyrics text
13 const apiUrl = `https://lyricsapi.fly.dev/api/lyrics?q=${encodeURIComponent(songTitle)}`;
14 const res = await fetch(apiUrl);
15
16 if (!res.ok) {
17 const errText = await res.text();
18 throw errText;
19 }
20
21 const data = await res.json();
22
23 const lyrics = data && data.result && data.result.lyrics ? data.result.lyrics : null;
24 if (!lyrics) {
25 await sock.sendMessage(chatId, {
26 text: `❌ Sorry, I couldn't find any lyrics for "${songTitle}".`
27 },{ quoted: message });
28 return;
29 }
30
31 const maxChars = 4096;
32 const output = lyrics.length > maxChars ? lyrics.slice(0, maxChars - 3) + '...' : lyrics;
33
34 await sock.sendMessage(chatId, { text: output }, { quoted: message });
35 } catch (error) {
36 console.error('Error in lyrics command:', error);
37 await sock.sendMessage(chatId, {
38 text: `❌ An error occurred while fetching the lyrics for "${songTitle}".`
39 },{ quoted: message });
40 }
41}
42
43module.exports = { lyricsCommand };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected