Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lyrics command #719

Merged
merged 11 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ AUTO_NODE=" false" # true for auto node. It is given from lavainfo-api (https://
SEARCH_ENGINE= "YouTubeMusic" # Search engine to be used when playing the song. You can use: YouTube, YouTubeMusic, SoundCloud, Spotify, Apple, Deezer, Yandex and JioSaavn
MAX_PLAYLIST_SIZE= "100" # Max playlist size.
MAX_QUEUE_SIZE= "100" # Max queue size.
GENIUS_API= "" # Sign up and get your own api at (https://genius.com/) to fetch your lyrics (CLIENT TOKEN)

# Configuration for multiple Lavalink servers
LAVALINK_SERVERS = '[
{"url":"localhost:2333","auth":"youshallnotpass","name":"Local Node","secure":false},
{"url":"localhost:2333","auth":"youshallnotpass2","name":"Another Node","secure":false}
]'
]'
11 changes: 10 additions & 1 deletion locales/EnglishUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@
"looping_queue": "**Looping the queue.**",
"looping_off": "**Looping is now off.**"
},
"lyrics": {
"description": "Get's the lyrics of the currently playing track.",
"lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n`${lyrics}`",
"errors": {
"no_results": "No lyrics found for the current track.",
"no_playing": "No track is currently playing.",
"lyrics_error": "An error occurred while getting the lyrics."
}
},
"nowplaying": {
"description": "Shows the currently playing song",
"now_playing": "Now Playing",
Expand Down Expand Up @@ -629,4 +638,4 @@
"Leave a guild": "Leave a guild",
"List all guilds the bot is in": "List all guilds the bot is in",
"Restart the bot": "Restart the bot"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"signale": "^1.4.0",
"topgg-autoposter": "^2.0.2",
"tslib": "^2.7.0",
"undici": "^6.19.8"
"undici": "^6.19.8",
"genius-lyrics-api": "^3.2.1"
},
"signale": {
"displayScope": true,
Expand Down
75 changes: 75 additions & 0 deletions src/commands/music/Lyrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import { getLyrics } from 'genius-lyrics-api';

export default class Lyrics extends Command {
constructor(client: Lavamusic) {
super(client, {
name: "lyrics",
description: {
content: "cmd.lyrics.description",
examples: ["lyrics"],
usage: "lyrics",
},
category: "music",
aliases: ["ly"],
cooldown: 3,
args: false,
vote: false,
player: {
voice: true,
dj: false,
active: true,
djPerm: null,
},
permissions: {
dev: false,
client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"],
user: [],
},
slashCommand: true,
options: [],
});
}

public async run(client: Lavamusic, ctx: Context): Promise<any> {
const player = client.queue.get(ctx.guild!.id);
const embed = this.client.embed();

if (!player || !player.isPlaying) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))],
});
}

const currentTrack = player.current;
const trackTitle = currentTrack.info.title;
const artistName = currentTrack.info.author;
const trackUrl = currentTrack.info.uri
const artworkUrl = currentTrack.info.artworkUrl;

const options = {
apiKey: this.client.config.lyricsApi,
title: trackTitle,
artist: artistName,
optimizeQuery: true
};

try {
const lyrics = await getLyrics(options);
if (lyrics) {
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics})).setThumbnail(artworkUrl).setTimestamp()],
});
} else {
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))],
});
}
} catch (error) {
console.error(error);
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))],
});
}
}
}
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default {
guildId: process.env.GUILD_ID,
logChannelId: process.env.LOG_CHANNEL_ID,
commandLogs: process.env.LOG_COMMANDS_ID,
lyricsApi: process.env.GENIUS_API,
links: {
img: process.env.IMG_LINK || "https://i.imgur.com/ud3EWNh.jpg",
},
Expand Down