diff --git a/buttons/pause.js b/buttons/pause.js index 7c03ccb..f6e6afb 100644 --- a/buttons/pause.js +++ b/buttons/pause.js @@ -3,6 +3,9 @@ const { useQueue } = require('discord-player') module.exports = { id: 'pause', async execute(interaction) { + console.log(interaction) + console.log(interaction.reply) + console.log(interaction.reply()) let queue = useQueue(interaction.guild.id) queue.node.setPaused(!queue.node.isPaused()) await interaction.reply({ content: 'Musique mise en pause !', ephemeral: true }) diff --git a/commands/global/crack.js b/commands/global/crack.js index 6db8b8d..ff54d4d 100644 --- a/commands/global/crack.js +++ b/commands/global/crack.js @@ -34,10 +34,13 @@ module.exports = { let query = interaction.options.getString('jeu') let games = await search(query, headers1) + if (!Array.isArray(games)) { + if (games.toString() == "TypeError: Cannot read properties of undefined (reading 'split')") return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` }) + else return interaction.followUp({ content: "Une erreur s'est produite ! ```" + games + "```" }) + } let game - if (games.length === 0) return await interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` }) - else if (games.length > 1) { + if (games.length > 1) { games = games.slice(0, 9) let list = '' for (let i = 0; i < games.length; i++) list += `\n${i + 1}. ${games[i].name} (${games[i].link})` @@ -59,7 +62,6 @@ module.exports = { game = games[index] } else game = games[0] - console.log(interaction.user.id) let url = await repo(game, headers2) let file = await torrent(url, headers2) diff --git a/commands/global/papa.js b/commands/global/papa.js new file mode 100755 index 0000000..61b2c66 --- /dev/null +++ b/commands/global/papa.js @@ -0,0 +1,28 @@ +const { SlashCommandBuilder } = require('discord.js') +const { getVoiceConnection, joinVoiceChannel } = require('@discordjs/voice') + +module.exports = { + data: new SlashCommandBuilder() + .setName('papa') + .setDescription('Si papa m\'appelle, je le rejoins !'), + async execute(interaction) { + if (interaction.user.id !== '223831938346123275') return interaction.reply({ content: 'T\'es pas mon père, dégage !' }) + + let botChannel = interaction.guild.members.me.voice.channel + let papaChannel = interaction.member.voice.channel + + if (!papaChannel && botChannel) { + getVoiceConnection(botChannel.guild.id).destroy() + return interaction.reply({ content: 'Je quitte le vocal, papa !' }) + } + else if (!botChannel || botChannel.id !== papaChannel.id) { + joinVoiceChannel({ + channelId: papaChannel.id, + guildId: papaChannel.guild.id, + adapterCreator: papaChannel.guild.voiceAdapterCreator, + }) + return interaction.reply({ content: 'Je rejoins ton vocal, papa !' }) + } + else return interaction.reply({ content: 'Je suis déjà dans ton vocal, papa !' }) + } +} \ No newline at end of file diff --git a/commands/global/parle.js b/commands/global/parle.js new file mode 100755 index 0000000..30e6e3b --- /dev/null +++ b/commands/global/parle.js @@ -0,0 +1,73 @@ +const { SlashCommandBuilder } = require('discord.js') +const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, EndBehaviorType } = require('@discordjs/voice') +const appDir = require('path').dirname(require.main.filename) + +module.exports = { + data: new SlashCommandBuilder() + .setName('parle') + .setDescription('Fais moi parler par dessus quelqu\'un de chiant dans le vocal') + .addUserOption(option => option.setName('user').setDescription('La personne en question').setRequired(true)), + async execute(interaction) { + if (interaction.user.id !== '223831938346123275') return await interaction.reply({ content: 'Tu n\'as pas le droit d\'utiliser cette commande !', ephemeral: true }) + + let user = interaction.options.getUser('user') + let member = interaction.guild.members.cache.get(user.id) + + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You must be in a voice channel to use this command.', ephemeral: true }) + if (!member.voice.channel) return await interaction.reply({ content: 'The member must be in a voice channel to use this command.', ephemeral: true }) + if (interaction.member.voice.channelId !== member.voice.channelId) return await interaction.reply({ content: 'You must be in the same voice channel than the member to use this command.', ephemeral: true }) + + await interaction.reply({ content: 'Je vais parler par dessus cette personne !', ephemeral: true }) + + /* + // Searches for audio files uploaded in the channel + let messages = await interaction.channel.messages.fetch({ limit: 10, cache: false }) + messages = messages.filter(m => m.attachments.size > 0) + + let files = [] + await messages.forEach(m => m.attachments.forEach(a => { + if (a.contentType === 'audio/mpeg') files.push(a) + })) + if (files.size === 0) return await interaction.editReply({ content: 'Aucun fichier audio trouvé dans ce channel.', ephemeral: true }) + + // Limit the number of files to the last 10 + //files = files.sort((a, b) => b.createdTimestamp - a.createdTimestamp).first(10) + + // Ask the user to choose a file + let file = await interaction.channel.send({ content: 'Choisissez un fichier audio :', files: files }) + let filter = m => m.author.id === interaction.user.id && !isNaN(m.content) && parseInt(m.content) > 0 && parseInt(m.content) <= files.size + let response = await interaction.channel.awaitMessages({ filter, max: 1, time: 30000, errors: ['time'] }) + file = files.get(files.keyArray()[response.first().content - 1]) + */ + + let playing = false + let player = createAudioPlayer() + player.on(AudioPlayerStatus.Idle, () => { playing = false }) + + let connection = joinVoiceChannel({ + channelId: interaction.member.voice.channelId, + guildId: interaction.guildId, + adapterCreator: interaction.guild.voiceAdapterCreator, + selfDeaf: false + }) + connection.subscribe(player) + + let stream = connection.receiver.subscribe(user.id, { end: { behavior: EndBehaviorType.Manual } }) + stream.on('data', (chunk) => { + if (connection.receiver.speaking.users.has(user.id) && !playing) { + playing = true + let resource = createAudioResource(appDir + '/parle.mp3', { inlineVolume: true }) + //let resource = createAudioResource(file.attachments.first().url, { inlineVolume: true }) + resource.volume.setVolume(0.2) + player.play(resource) + } + }) + + interaction.client.on('voiceStateUpdate', (oldState, newState) => { + if (oldState.id === member.id && newState.channelId !== interaction.member.voice.channelId) { + stream.destroy() + connection.disconnect() + } + }) + } +} \ No newline at end of file diff --git a/commands/music/lyrics.js b/commands/music/lyrics.js new file mode 100755 index 0000000..a7bd2ff --- /dev/null +++ b/commands/music/lyrics.js @@ -0,0 +1,45 @@ +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js') +const { useQueue } = require('discord-player') +const { lyricsExtractor } = require('@discord-player/extractor') + +module.exports = { + data: new SlashCommandBuilder() + .setName('lyrics') + .setDescription('Rechercher les paroles d\'une musique.') + .addStringOption(option => option.setName('recherche').setDescription('Chercher une musique spécifique')), + async execute(interaction) { + await interaction.deferReply() + + let query = interaction.options.getString('recherche', false) + if (!query) { + let queue = useQueue(interaction.guild.id) + if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' }) + let track = queue.currentTrack + if (!track) return interaction.followUp({ content: 'Aucune musique en cours, recherche en une plutôt !' }) + + if (track.raw.source === 'spotify') query = `${track.author} ${track.title}` + else query = track.title + } + + let lyricsFinder = lyricsExtractor() + + let lyrics = await lyricsFinder.search(query).catch(() => null) + if (!lyrics) return interaction.followUp({ content: 'Pas de paroles trouvées !' }) + + let trimmedLyrics = lyrics.lyrics.substring(0, 1997) + + let embed = new EmbedBuilder() + .setColor('#ffc370') + .setTitle(lyrics.title) + .setURL(lyrics.url) + .setThumbnail(lyrics.thumbnail) + .setAuthor({ + name: lyrics.artist.name, + iconURL: lyrics.artist.image, + url: lyrics.artist.url + }) + .setDescription(trimmedLyrics.length === 1997 ? `${trimmedLyrics}...` : trimmedLyrics) + + return interaction.followUp({ embeds: [embed] }) + } +} \ No newline at end of file diff --git a/commands/music/play.js b/commands/music/play.js index f69d377..261cbe5 100755 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -60,10 +60,10 @@ module.exports = { }) } try { if (!queue.connection) await queue.connect(voiceChannel) } - catch (error) { console.error(error); return await interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) } + catch (error) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) } let result = await player.search(query, { requestedBy: interaction.user }) - if (!result.hasTracks()) return await interaction.followUp(`Aucune musique trouvée pour **${query}** !`) + if (!result.hasTracks()) return interaction.followUp(`Aucune musique trouvée pour **${query}** !`) let track = result.tracks[0] let entry = queue.tasksQueue.acquire() @@ -73,14 +73,12 @@ module.exports = { // Write the values in the .env file to recover the player if the bot restarts writeEnv('DISCORD_MUSIC_TEXTCHANNEL_ID', interaction.channel.id) writeEnv('DISCORD_MUSIC_VOICECHANNEL_ID', voiceChannel.id) - writeEnv('DISCORD_MUSIC_CURRENT_TRACK', track.url) - writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', 0) try { if (!queue.isPlaying()) await queue.node.play() - track.source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu' - return await interaction.followUp(`Chargement de la musique **${track.title}** de **${track.author}** sur **${track.source}**...`) - } catch (error) { console.error(error); return await interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) } + let track_source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu' + return interaction.followUp(`Chargement de la musique **${track.title}** de **${track.author}** sur **${track_source}**...`) + } catch (error) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) } finally { queue.tasksQueue.release() } } } \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index ac5e550..1635d39 100755 --- a/events/ready.js +++ b/events/ready.js @@ -32,7 +32,7 @@ module.exports = { let player = useMasterPlayer() let queue = player.nodes.create(textChannel.guild, { metadata: { - channel: voiceChannel, + channel: textChannel, client: textChannel.guild.members.me, requestedBy: client.user }, @@ -56,10 +56,11 @@ module.exports = { await entry.getTask() queue.addTrack(track) + let progress = process.env.DISCORD_MUSIC_CURRENT_PROGRESS + try { await queue.node.play() - queue.node.seek(process.env.DISCORD_MUSIC_CURRENT_PROGRESS) - queue.setRepeatMode(1) + queue.node.seek(progress) await textChannel.send(`Relancement de la musique suite à mon redémarrage...`) } catch (error) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) } finally { queue.tasksQueue.release() } diff --git a/eventsPlayer/playerStart.js b/eventsPlayer/playerStart.js index d1d0fa3..e376a04 100644 --- a/eventsPlayer/playerStart.js +++ b/eventsPlayer/playerStart.js @@ -2,6 +2,8 @@ module.exports = { name: 'playerStart', async execute(queue, track) { // Emitted when the player starts to play a song + writeEnv('DISCORD_MUSIC_CURRENT_TRACK', track.url) + queue.metadata.channel.send(`Lecture de **${track.title}** de **${track.author}** !`) } } \ No newline at end of file diff --git a/parle.mp3 b/parle.mp3 new file mode 100644 index 0000000..292e846 Binary files /dev/null and b/parle.mp3 differ diff --git a/utilsCrack/search.js b/utilsCrack/search.js index 90c7e95..5fe9b0e 100644 --- a/utilsCrack/search.js +++ b/utilsCrack/search.js @@ -15,5 +15,5 @@ module.exports = search = (async (query, headers) => { games.push({ name, link }) }) return games - } catch (error) { console.error(error) } + } catch (error) { return error } }) \ No newline at end of file