-
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.
Merge pull request #50 from Wiibleyde/develop
Introduces several new music commands and updates existing ones to improve the functionality of the music bot
- Loading branch information
Showing
6 changed files
with
146 additions
and
3 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
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,60 @@ | ||
import { playerConfig } from "@/config"; | ||
import { errorEmbed } from "@/utils/embeds"; | ||
import { backSpace } from "@/utils/textUtils"; | ||
import { useQueue } from "discord-player"; | ||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, MessageActionRowComponentBuilder, SlashCommandBuilder } from "discord.js"; | ||
|
||
|
||
export const data: SlashCommandBuilder = new SlashCommandBuilder() | ||
.setName("nowplaying") | ||
.setDescription("[Musique] Afficher la musique en cours de lecture") | ||
|
||
export async function execute(interaction: CommandInteraction) { | ||
const queue = useQueue(interaction.guildId as string) | ||
if (!queue?.isPlaying()) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
|
||
const track = queue.currentTrack | ||
if (!track) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
const progress = queue.node.createProgressBar() | ||
|
||
let emojiState = playerConfig.enableEmoji | ||
|
||
const emojis = playerConfig.emojis | ||
|
||
emojiState = emojis ? true : false | ||
|
||
const embed = new EmbedBuilder() | ||
.setTitle("Lecture en cours") | ||
.setThumbnail(track.thumbnail) | ||
.setDescription(`[${track.title}](${track.url}) | ${track.author} ${backSpace} <${progress}>`) | ||
.setFooter({ text: `Eve – Toujours prête à vous aider.`, iconURL: interaction.client.user.displayAvatarURL() }) | ||
.setTimestamp() | ||
|
||
const back = new ButtonBuilder() | ||
.setLabel(emojiState ? emojis.back : ('Back')) | ||
.setCustomId('backButton') | ||
.setStyle(ButtonStyle.Primary) | ||
|
||
const skip = new ButtonBuilder() | ||
.setLabel(emojiState ? emojis.skip : ('Skip')) | ||
.setCustomId('skipButton') | ||
.setStyle(ButtonStyle.Primary) | ||
|
||
const resumepause = new ButtonBuilder() | ||
.setLabel(emojiState ? emojis.ResumePause : ('Resume/Pause')) | ||
.setCustomId('resumeAndPauseButton') | ||
.setStyle(ButtonStyle.Danger) | ||
|
||
const loop = new ButtonBuilder() | ||
.setLabel(emojiState ? emojis.loop : ('Loop')) | ||
.setCustomId('loopButton') | ||
.setStyle(ButtonStyle.Danger) | ||
|
||
// const lyrics = new ButtonBuilder() // Disabled for now | ||
// .setLabel('Lyrics') | ||
// .setCustomId('lyricsButton') | ||
// .setStyle(ButtonStyle.Secondary) | ||
|
||
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(back, skip, resumepause, loop) | ||
await interaction.reply({ embeds: [embed], components: [row], ephemeral: true }) | ||
} |
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,28 @@ | ||
import { errorEmbed } from "@/utils/embeds"; | ||
import { useQueue } from "discord-player"; | ||
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js"; | ||
|
||
|
||
export const data: SlashCommandBuilder = new SlashCommandBuilder() | ||
.setName("queue") | ||
.setDescription("[Musique] Afficher la file d'attente") | ||
|
||
export async function execute(interaction: CommandInteraction) { | ||
const queue = useQueue(interaction.guildId as string) | ||
|
||
if (!queue?.isPlaying()) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
if (!queue.tracks.toArray()[0]) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
|
||
const methods = ['', '🔁', '🔂'] | ||
const songs = queue.tracks.size | ||
const nextSongs = songs > 5 ? `et ${songs - 5} autres chansons` : `Dans la file d'attente: ${songs} chansons` | ||
const tracks = queue.tracks.map((track, i) => `**${i + 1}.** [${track.title}](${track.url}) | ${track.author}`).slice(0, 5).join('\n') | ||
const embed = new EmbedBuilder() | ||
.setTitle("File d'attente") | ||
.setDescription(`${methods[queue.repeatMode]} ${nextSongs}\n\n${tracks}`) | ||
.setColor('Blue') | ||
.setFooter({ text: `Eve – Toujours prête à vous aider.`, iconURL: interaction.client.user?.displayAvatarURL() }) | ||
.setTimestamp() | ||
|
||
await interaction.reply({ embeds: [embed], ephemeral: true }) | ||
} |
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,31 @@ | ||
import { errorEmbed, successEmbed } from "@/utils/embeds"; | ||
import { useQueue } from "discord-player"; | ||
import { CommandInteraction, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder } from "discord.js"; | ||
|
||
|
||
export const data: SlashCommandOptionsOnlyBuilder = new SlashCommandBuilder() | ||
.setName("remove") | ||
.setDescription("[Musique] Supprimer une musique de la file d'attente") | ||
.addStringOption(option => | ||
option.setName("position") | ||
.setDescription("La position de la musique à supprimer") | ||
.setRequired(true) | ||
) | ||
|
||
export async function execute(interaction: CommandInteraction) { | ||
const queue = useQueue(interaction.guildId as string) | ||
|
||
if (!queue?.isPlaying()) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
|
||
const position = interaction.options.get("position")?.value as string | ||
|
||
if (isNaN(Number(position))) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("La position doit être un nombre."))], ephemeral: true }) | ||
|
||
const index = Number(position) - 1 | ||
const name = queue.tracks.toArray()[index]?.title | ||
if (!name) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Cette musique n'existe pas."))], ephemeral: true }) | ||
|
||
queue.removeTrack(index) | ||
|
||
await interaction.reply({ embeds: [successEmbed(interaction, `La musique ${name} a été supprimée de la file d'attente.`)], ephemeral: true }) | ||
} |
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,18 @@ | ||
import { errorEmbed, successEmbed } from "@/utils/embeds"; | ||
import { useQueue } from "discord-player"; | ||
import { CommandInteraction, SlashCommandBuilder } from "discord.js"; | ||
|
||
|
||
export const data: SlashCommandBuilder = new SlashCommandBuilder() | ||
.setName("stop") | ||
.setDescription("[Musique] Arrêter la musique") | ||
|
||
export async function execute(interaction: CommandInteraction) { | ||
const queue = useQueue(interaction.guildId as string) | ||
|
||
if (!queue?.isPlaying()) return await interaction.reply({ embeds: [errorEmbed(interaction, new Error("Aucune musique n'est en cours de lecture."))], ephemeral: true }) | ||
|
||
queue.delete() | ||
|
||
await interaction.reply({ embeds: [successEmbed(interaction, "La musique a été arrêtée.")], ephemeral: true }) | ||
} |
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