diff --git a/commands/shuffle.js b/commands/shuffle.js new file mode 100644 index 0000000..d4632b9 --- /dev/null +++ b/commands/shuffle.js @@ -0,0 +1,39 @@ +const f = require('../functions.js'); +const discord = require('discord.js'); +const fs = require("fs") + +module.exports = { + name: 'shuffle', + description: f.localization("commands","shuffle","exports").description, + category: 'music', + modcommand: false, + usage: f.localization("commands","shuffle","exports").usage, + perms: '', + alias: [], + cooldown: 1, + run: function (message, prefix, args, client) { + const serverQueue = queue.get(message.channel.guild.id); + const channel = message.member.voice.channel + + if (!serverQueue) return message.reply("Ich bin nicht Verbunden.") + if (!serverQueue.playing) return message.reply("Ich spiele aktuell nichst.") + + if (message.member.voice.channel.id != queue.get(message.channel.guild.id).voiceChannel.id) return message.reply("Du musst mit dem Bot in einem Sprachkanal sein."); + + function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + } + + + let curSong = serverQueue.songs.splice(0, 1)[0] + let newArray = serverQueue.songs + shuffleArray(newArray) + newArray.splice(0, 0, curSong) + serverQueue.songs = newArray; + queue.set(message.guild.id, serverQueue) + message.reply("Die Songliste wurde gemischt."); + } +} \ No newline at end of file diff --git a/functions.js b/functions.js index d7a1ab4..18fa6ba 100644 --- a/functions.js +++ b/functions.js @@ -107,13 +107,54 @@ exports.addSong = async function(guild, query, message) { const botMsg = await message.reply("Suche... :mag:") let song = {} try { - const songInfo = await ytdl.getInfo(query) - song = { - title: songInfo.videoDetails.title, - url: songInfo.videoDetails.video_url, - raw: songInfo, - by: message.author, - }; + try { + const playlistID = await ytpl.getPlaylistID(query) + const playlist = await ytpl(playlistID, { + limit: 50, + }) + botMsg.edit("Playlist wird hinzugefügt, dies kann etwas länger dauern. :notes:") + for (let index = 0; index < playlist.items.length; index++) { + serverQueue = queue.get(guild.id); + let curSong = await ytdl.getInfo(playlist.items[index].shortUrl) + let curSongInfo = { + title: curSong.videoDetails.title, + url: curSong.videoDetails.video_url, + raw: curSong, + by: message.author + } + serverQueue.songs.push(curSongInfo) + if (index == 0) { + song = curSongInfo + } + await f.sleep(50) + } + queue.set(guild.id, serverQueue) + if (!serverQueue.playing) { + f.play(guild) + serverQueue.playing = true + queue.set(guild.id, serverQueue) + const embed = new discord.MessageEmbed() + .setTitle("Spielt gerade:") + .setURL(song.url) + .setColor(0x00AE86) + .setDescription(`**${song.title}**`) + .addField('Länge', `\`${formatMilliseconds(song.raw.videoDetails.lengthSeconds * 1000)}\``, true) + .addField('Kanal', `[${song.raw.videoDetails.author.name}](${song.raw.videoDetails.author.channel_url})`, true) + .setFooter(`Hinzugefügt von: ${song.by.username}`, song.by.avatarURL(true)) + .setThumbnail(song.raw.videoDetails.thumbnails[song.raw.videoDetails.thumbnails.length - 1].url) + message.channel.send({embeds: [embed]}) + } + botMsg.edit(`${playlist.items.length} Lieder hinzugefügt.`) + return + } catch (error) { + const songInfo = await ytdl.getInfo(query) + song = { + title: songInfo.videoDetails.title, + url: songInfo.videoDetails.video_url, + raw: songInfo, + by: message.author, + }; + } } catch (error) { try { const filters1 = await ytsr.getFilters(query)