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

Create Lyrics.js #221

Merged
merged 6 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ If you installed and setup eveything correctly then the bot should output someth


## Contributors
- [2D](https://github.com/MeLike2D): Provided modified lavalink version with filters.
- [MrAugu](https://github.com/MrAugu): Cleaned up spaghetti code.
- [Sxmurai](https://github.com/Sxmurai/): Cleaned up spaghetti code.
- [2D](https://github.com/MeLike2D): Provided modified lavalink version with filters
- [MrAugu](https://github.com/MrAugu): Cleaned up spaghetti code
- [Sxmurai](https://github.com/Sxmurai/): Cleaned up spaghetti code
- [Omar](https://github.com/HysMX): Fixed Youtube playlist bug
- [lmpham1](https://github.com/lmpham1): Added clean command.
- [lmpham1](https://github.com/lmpham1): Added clean command
- [rajamoulimallareddy](https://github.com/rajamoulimallareddy): Updated bot to discord.js v13
- [ilikdoge](https://github.com/ilikdoge): Helped with implementation of yasha and overall development of bot
- [Berus](https://github.com/berusvn): Added lyrics command

## Bot Lists
[![Bots On Discord](https://bots.ondiscord.xyz/bots/472714545723342848/embed?theme=dark&showGuilds=true)](https://bots.ondiscord.xyz/bots/472714545723342848)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
"homepage": "https://github.com/Tetracyl/EarTensifier#readme",
"dependencies": {
"axios": "^0.27.2",
"@discordjs/rest": "^1.1.0",
"@sentry/node": "^7.12.1",
"axios": "^0.27.2",
"blapi": "^2.2.1",
"cors": "^2.8.5",
"cpu-stat": "^2.0.1",
Expand All @@ -40,6 +40,7 @@
"express": "^4.17.1",
"figlet": "^1.5.2",
"fs": "^0.0.1-security",
"genius-lyrics": "^4.4.0",
"humanize-duration": "^3.27.0",
"mongoose": "^6.0.12",
"signale": "^1.4.0",
Expand All @@ -50,4 +51,4 @@
"devDependencies": {
"eslint": "^8.1.0"
}
}
}
58 changes: 58 additions & 0 deletions src/commands/music/Lyrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { ApplicationCommandOptionType } = require('discord.js');
const Command = require('../../structures/Command');
const genius = require("genius-lyrics");
const Genius = new genius.Client(process.env.GENIUS_API);
const _ = require('lodash');
const { EmbedBuilder } = require('discord.js');

module.exports = class Lyrics extends Command {
constructor(client) {
super(client, {
name: 'lyrics',
description: {
content: 'Search lyrics of the song.',
usage: '<query>',
},
args: false,
voiceRequirements: {
isInVoiceChannel: false,
isInSameVoiceChannel: false,
isPlaying: false,
},
options: [{
name: 'song',
type: ApplicationCommandOptionType.String,
required: false,
description: 'Song name to find lyrics for.',
}],
slashCommand: true,
});
}
async run(client, ctx, args) {
const player = client.music.players.get(ctx.guild.id);
if (!args[0] && !player) return ctx.sendEphemeralMessage('There is nothing currently playing.');
let query = args.join(' ');
if (!args[0]) query = player.queue.current.title;
const getSongTitle = query.replace(
/lyrics|lyric|lyrical|official music video|\(official music video\)|\(Official Video\)|audio|\(audio\)|official|official video|official video hd|official hd video|offical video music|\(offical video music\)|extended|hd|(\[.+\])/gi,
'',
);

let songs = (await Genius.songs.search(getSongTitle))[0];
const songTitle = songs.title || song.featuredTitle;
const songLyrics = await songs.lyrics();
if (!songLyrics) return ctx.sendEphemeralMessage(`**No lyrics found for **${songTitle}**`);
const lyrics = songLyrics.split('\n');
const formattedLyrics = _.chunk(lyrics, 40);

let pages = formattedLyrics.map((ly) => {
const embed = new EmbedBuilder()
.setAuthor({ name: `Lyrics for ${songTitle}`, iconURL: client.user.displayAvatarURL() })
.setDescription(ly.join('\n'))
.setThumbnail(songs.thumbnail);
return embed;
});

return ctx.messageHelper.paginate(pages);
}
};