Skip to content

Commit

Permalink
Added shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed May 3, 2022
1 parent bec1a60 commit 3e21d13
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
39 changes: 39 additions & 0 deletions commands/shuffle.js
Original file line number Diff line number Diff line change
@@ -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.");
}
}
55 changes: 48 additions & 7 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3e21d13

Please sign in to comment.