Skip to content

Commit

Permalink
Merge pull request #47 from Mightypotatoast/master
Browse files Browse the repository at this point in the history
More music fix
  • Loading branch information
Ayrox authored Oct 26, 2021
2 parents 1923310 + f4570fc commit 961c035
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 45 deletions.
6 changes: 4 additions & 2 deletions src/Buttons/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ module.exports = {
if (!queue) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing in the queue right now !`)], ephemeral: true })
if (nextSong === undefined) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing next in queue right now !`)], ephemeral: true })

queue.skip()

message.reply({
embeds: [
musicEmbed()
.setThumbnail(`${nextSong.thumbnail}`)
.setDescription(` Song skipped by ${message.user}! Now playing:\n [${nextSong.name}](${nextSong.url})`)
],components: [musicButtonRow()]})

queue.skip()


} catch (e) {
message.reply({ embeds: [errorEmbed().setDescription(`${e}`)], ephemeral: true })
}
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/music/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ module.exports = {
try {
const queue = client.distube.getQueue(message)
if (!queue) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing in the queue right now !`)], ephemeral: true })
if (queue.songs.length-1 >= 15) return message.reply({ embeds: [errorEmbed().setDescription(`too much song in the queue discord can't handle that`)], ephemeral: true })
const q = queue.songs.map((song, i) => `${i === 0 ? "Playing:" : `${i}.`} [${song.name}](${song.url}) - \`${song.formattedDuration}\``).join("\n")

const tracks = queue.songs.map((song, i) => `**${i}** - [${song.name}](${song.url}) - ${song.formattedDuration}`);
const numberSongs = queue.songs.length;
const nextSongs = numberSongs > 6 ? `And **${numberSongs - 6}** other song(s)...` : `**${numberSongs}** song(s) in the playlist`;

let playingEmbed = musicEmbed()
.addField(`Queue:`, `${q}`, true)
.setDescription(`Current [${queue.songs[0].name}](${queue.songs[0].url})\n\n${tracks.slice(1, 6).join('\n')}\n\n${nextSongs}`)
.setThumbnail(queue.songs[0].thumbnail)

message.reply({ embeds: [playingEmbed],components: [musicButtonRow()] , ephemeral: true })
} catch (e) {
Expand Down
60 changes: 38 additions & 22 deletions src/Commands/music/remove.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
const {MessageActionRow, MessageSelectMenu} = require("discord.js");
const { options } = require("snekfetch");
const { errorEmbed, musicEmbed} = require("../../util/Embeds")

module.exports = {

//! la commande fonctionne pour des petits nombre mais pas pour les grand (genre 300secondes)

name: "remove",
description: "remove a music from the queue",
description: "remove a music from the queue :",
permission: "ADMINISTRATOR",
active: true,
options: [
{
name: "id",
description: `Nuumber of place the song has in the queue`,
type: "NUMBER",
required: true,
}
],

async execute(message, client) {

async execute(message, client) {
try {

let removeNumber = message.options.getNumber("id")
const queue = client.distube.getQueue(message)
if (!queue) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing in the queue right now !`)], ephemeral: true })
if (queue.songs[removeNumber] === undefined) return message.reply({ embeds: [errorEmbed().setDescription(`No song with this id exist !`)], ephemeral: true })

message.reply({
if (!queue) return message.editReply({ embeds: [errorEmbed().setDescription(`There is nothing in the queue right now !`)], ephemeral: true })
//numberOfSelectNeeded = math.ceil(queue.songs.length/25) //TODO ajouter plusieurs SelectMenu if queue.songs.length-1 >= 25

await message.reply({
embeds: [
musicEmbed()
.setDescription("⏳ Loading ...")
]
})


const optionMenu = await queue.songs.map((song, i) => {

return {
label: song.name,
value: i.toString(),
};
})

const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('remove')
.setMaxValues(1)
.setPlaceholder('Nothing selected')
.addOptions(optionMenu.slice(0,24)))

message.editReply({
embeds: [
musicEmbed()
.setDescription(`${message.user} removed [${queue.songs[removeNumber].name}](${queue.songs[removeNumber].url}) from the queue!`)
]})
.setDescription(`Select the music you want to remove from the queue below ⤵️`)
],components: [row], ephemeral: true})

queue.songs.splice(removeNumber, 1)
//queue.songs.splice(removeNumber, 1)


} catch (e) {
message.reply({ embeds: [errorEmbed().setDescription(`${e}`)], ephemeral: true })
console.log(e)
message.editReply({ embeds: [errorEmbed().setDescription(`${e}`)], ephemeral: true })
}

}
Expand Down
13 changes: 7 additions & 6 deletions src/Commands/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ module.exports = {
const queue = client.distube.getQueue(message)
if (!queue) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing in the queue right now !`)], ephemeral: true })
if (queue.songs[skipNumber] === undefined) return message.reply({ embeds: [errorEmbed().setDescription(`There is nothing next in queue right now !`)], ephemeral: true })

message.reply({
embeds: [
musicEmbed()
.setThumbnail(`${queue.songs[skipNumber].thumbnail}`)
.setDescription(` Song skipped by ${message.user}! Now playing:\n [${queue.songs[skipNumber].name}](${queue.songs[skipNumber].url})`)
]})

queue.jump(skipNumber)

message.reply({
embeds: [
musicEmbed()
.setThumbnail(`${queue.songs[skipNumber].thumbnail}`)
.setDescription(` Song skipped by ${message.user}! Now playing:\n [${queue.songs[skipNumber].name}](${queue.songs[skipNumber].url})`)
]})
} catch (e) {
message.reply({ embeds: [errorEmbed().setDescription(`${e}`)], ephemeral: true })
}
Expand Down
42 changes: 31 additions & 11 deletions src/Events/Interaction/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Client, CommandInteraction, MessageEmbed } = require('discord.js')
const { execute } = require('../guild/guildCreate')
const { MessageEmbed } = require('discord.js')
const { musicEmbed } = require("../../util/Embeds") //!provisoir, a retirer quand Handler pour Select menu sera présent

module.exports = {

Expand Down Expand Up @@ -30,7 +30,7 @@ module.exports = {
.setDescription("There is no function found for this button")
], ephemeral : true
})

try {
await button.execute(interaction, client)
} catch (e) {
Expand All @@ -44,14 +44,34 @@ module.exports = {
], ephemeral : true
})
}
} else if (interaction.isSelectMenu()) { //! a modifer/mettre en place un handler pour les SelectMenu
try {

if (interaction.customId !== 'remove') return
await interaction.deferReply({ ephemeral: false})
const queue = client.distube.getQueue(interaction)
const songId = interaction.values[0]
queue.songs.splice(songId, 1)

await interaction.followUp({
embeds: [
musicEmbed()
.setDescription(`${interaction.user} has removed [${queue.songs[songId].name}](${queue.songs[songId].url}) from the queue`)
]})

interaction.message.delete()
//interaction.message.resolveComponent(interaction.customId).setDisabled(true) //!wtf pk ca marche pas
} catch (e) {
console.error(e)
interaction.editReply({
embeds: [
new MessageEmbed()
.setColor("RED")
.setTitle("⛔⛔ **ERREUR** ⛔⛔")
.setDescription("ALED")
], ephemeral : true
})
}
}
}








}
6 changes: 5 additions & 1 deletion src/Events/guild/guildMemberRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ module.exports = {


if (channel) {
member.guild.channels.cache.get(config.channel.au_revoirID).send({embeds : [exampleEmbed]})
try {
member.guild.channels.cache.get(config.channel.au_revoirID).send({embeds : [exampleEmbed]})
} catch (e) {
console.log("pas trouvé le channel 'au_revoir'")
}
} else { console.log("pas trouvé le channel 'au_revoir'"); }

}
Expand Down
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ module.exports = {
{
name : "L'Empereur Patate",
id : "493383989588000769"
},

{
name : "Test Server",
id : "813377350385008721"
}

]
Expand Down

0 comments on commit 961c035

Please sign in to comment.