-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added /lyrics command and button in audioplayer which fetch lyrics for the current playing song. Commands now can be disabled during loading.
- Loading branch information
1 parent
18ec83c
commit 08b40f0
Showing
18 changed files
with
229 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Genius from 'genius-lyrics'; | ||
import { ENV } from '../EnvironmentVariables.js'; | ||
import { Colors, EmbedBuilder } from 'discord.js'; | ||
import i18next from 'i18next'; | ||
import { loggerWarn } from '../utilities/logger.js'; | ||
import { generateErrorEmbed } from '../utilities/generateErrorEmbed.js'; | ||
const Lyrics = new Genius.Client(ENV.BOT_GENIUS_TOKEN); | ||
|
||
if (!ENV.BOT_GENIUS_TOKEN) { | ||
loggerWarn('BOT_GENIUS_TOKEN is not provided, lyrics module disabled', 'Lyrics'); | ||
} | ||
|
||
export async function getLyricsSong(searchQuery: string) { | ||
const geniusSearch = await Lyrics.songs.search(searchQuery); | ||
|
||
if (geniusSearch.length === 0) { | ||
return undefined; | ||
} | ||
|
||
return geniusSearch[0]; | ||
} | ||
|
||
export async function generateLyricsEmbed(songQuery: string) { | ||
const geniusSong = await getLyricsSong(songQuery); | ||
|
||
if (!geniusSong) { | ||
return generateErrorEmbed(i18next.t('commands:lyrics_embed_lyrics_not_found')); | ||
} | ||
|
||
const lyrics = await geniusSong.lyrics(); | ||
|
||
const lyricsText = lyrics.slice(0, 4096); | ||
|
||
return new EmbedBuilder() | ||
.setTitle(geniusSong.title) | ||
.setURL(geniusSong.url) | ||
.setDescription(lyricsText) | ||
.setColor(Colors.Yellow) | ||
.setFooter({ text: i18next.t('commands:lyrics_embed_text_not_correct') }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CommandArgument, ICommand } from '../../CommandTypes.js'; | ||
import { Message, PermissionsBitField, SlashCommandBuilder } from 'discord.js'; | ||
import i18next from 'i18next'; | ||
import { services } from './play.command.js'; | ||
import { GroupAudio } from './AudioTypes.js'; | ||
import { generateLyricsEmbed } from '../../audioplayer/Lyrics.js'; | ||
import { ENV } from '../../EnvironmentVariables.js'; | ||
|
||
export default function (): ICommand { | ||
return { | ||
disable: !ENV.BOT_GENIUS_TOKEN, | ||
text_data: { | ||
name: 'lyrics', | ||
description: i18next.t('commands:lyrics_desc'), | ||
arguments: [ | ||
new CommandArgument(i18next.t('commands:lyrics_arg_query', { services: services }), true) | ||
], | ||
execute: async (message: Message, args: string[]) => { | ||
const songQuery = args.join(' '); | ||
|
||
await message.reply({ embeds: [await generateLyricsEmbed(songQuery)] }); | ||
} | ||
}, | ||
slash_data: { | ||
slash_builder: new SlashCommandBuilder() | ||
.setName('lyrics') | ||
.setDescription(i18next.t('commands:lyrics_desc')) | ||
.addStringOption((option) => | ||
option | ||
.setName('request') | ||
.setDescription(i18next.t('commands:lyrics_arg_query', { services: services })) | ||
.setRequired(true) | ||
), | ||
execute: async (interaction) => { | ||
const songQuery = interaction.options.getString('request')!; | ||
|
||
await interaction.reply({ embeds: [await generateLyricsEmbed(songQuery)] }); | ||
} | ||
}, | ||
group: GroupAudio, | ||
bot_permissions: [PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.