Skip to content

Commit

Permalink
Merge pull request #50 from Wiibleyde/develop
Browse files Browse the repository at this point in the history
Introduces several new music commands and updates existing ones to improve the functionality of the music bot
  • Loading branch information
Wiibleyde authored Nov 29, 2024
2 parents 563a8d3 + 2743d8d commit 6563a4d
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import * as resume from "./music/resume"
import * as skip from "./music/skip"
import * as loop from "./music/loop"
import * as syncedlyrics from "./music/syncedlyrics"
import * as queue from "./music/queue"
import * as nowplaying from "./music/nowplaying"
import * as remove from "./music/remove"

import { backButton } from "./music/back"
import { resumeAndPauseButton } from "./music/pause"
Expand Down Expand Up @@ -86,6 +89,9 @@ export const commands = {
skip,
loop,
syncedlyrics,
queue,
nowplaying,
remove,
}

export const devCommands = {
Expand Down
60 changes: 60 additions & 0 deletions src/commands/music/nowplaying.ts
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 })
}
28 changes: 28 additions & 0 deletions src/commands/music/queue.ts
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 })
}
31 changes: 31 additions & 0 deletions src/commands/music/remove.ts
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 })
}
18 changes: 18 additions & 0 deletions src/commands/music/stop.ts
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 })
}
6 changes: 3 additions & 3 deletions src/events/player.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { playerConfig } from "@/config";
import { client, logger, player } from "..";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, MessageActionRowComponentBuilder } from "discord.js";

player.events.on("audioTrackAdd", (queue, track) => {
if(playerConfig.extraMessages) {
Expand Down Expand Up @@ -142,7 +142,7 @@ player.events.on("playerStart", (queue, track) => {

const embed = new EmbedBuilder()
.setTitle("Lecture en cours")
.setDescription(`[${track.title}](${track.url}) a commencé à jouer dans <${queue.channel?.name}>.`)
.setDescription(`[${track.title}](${track.url}) a commencé à jouer dans <#${queue.channel?.id}>.`)
.setThumbnail(track.thumbnail)
.setColor('Green')
.setFooter({ text: `Eve – Toujours prête à vous aider.`, iconURL: client.user?.displayAvatarURL() })
Expand Down Expand Up @@ -173,6 +173,6 @@ player.events.on("playerStart", (queue, track) => {
// .setCustomId('lyricsButton')
// .setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder().addComponents(back, skip, resumepause, loop)
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(back, skip, resumepause, loop)
queue.metadata.channel.send({ embeds: [embed], components: [row] })
})

0 comments on commit 6563a4d

Please sign in to comment.