Skip to content

Commit db50c9c

Browse files
committed
feat: added lyrics command
1 parent 5294ef5 commit db50c9c

3 files changed

Lines changed: 230 additions & 4 deletions

File tree

package-lock.json

Lines changed: 171 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Canis Major and the constellation Canis Minor, the “lesser dog,” are widely regarded as two hunting hounds that follow Orion, the great hunter of ancient Greek legends.",
55
"private": true,
66
"main": "src/index.ts",
7+
"type": "module",
78
"scripts": {
89
"build": "tsc",
910
"start": "clear && while [ true ]; do node dist/index.js ; done",
@@ -33,6 +34,7 @@
3334
"dotenv": "^17.2.0",
3435
"emoji-regex": "^10.5.0",
3536
"fb-downloader-scrapper": "^3.0.1",
37+
"genius-lyrics": "^4.4.7",
3638
"google-tts-api": "^2.0.2",
3739
"groq-sdk": "^0.27.0",
3840
"npmlog": "^7.0.1",
@@ -42,6 +44,7 @@
4244
"redis": "^5.6.0",
4345
"semver": "^7.7.2",
4446
"systeminformation": "^5.27.7",
47+
"undici": "^7.16.0",
4548
"whatsapp-web.js": "^1.31.0",
4649
"youtubei.js": "^15.1.1"
4750
},

src/commands/lyrics.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Message } from "../../types/message";
2+
import Genius from "genius-lyrics"
3+
import log from "../components/utils/log";
4+
import { request } from "undici";
5+
6+
export const info = {
7+
command: "lyrics",
8+
description: "Get a lyrics from a song.",
9+
usage: "lyrics <song title>",
10+
example: "lyrics rchp sick love",
11+
role: "user",
12+
cooldown: 5000,
13+
};
14+
15+
export default async function (msg: Message) {
16+
const query = msg.body.replace(/^lyrics\b\s*/i, "").trim();
17+
if (query.length === 0) {
18+
await msg.reply("Please provide a search query.");
19+
return;
20+
}
21+
22+
const client = new Genius.Client();
23+
const origGet = client.request.get.bind(client.request);
24+
25+
client.request.get = async (url: string): Promise<string> => {
26+
const res = await request(url, {
27+
headers: {
28+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
29+
},
30+
});
31+
return await res.body.text();
32+
};
33+
const searches = await client.songs.search(query);
34+
35+
if (!searches || searches.length == 0) {
36+
await msg.reply("Unable to find resources for the given query.");
37+
return;
38+
}
39+
40+
const firstSong = searches[0];
41+
42+
let lyrics: string;
43+
try {
44+
lyrics = await firstSong.lyrics();
45+
} catch (err: any) {
46+
await msg.reply("Could not fetch lyrics (possibly blocked by Genius).");
47+
return;
48+
}
49+
50+
const text = `
51+
\`${firstSong.fullTitle}\`
52+
53+
${lyrics}
54+
`;
55+
await msg.reply(text);
56+
}

0 commit comments

Comments
 (0)