From b254495fd3819c06a20682ca3e687837e45fd325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hor=C3=A1=C4=8Dek?= Date: Sun, 12 Apr 2020 10:39:41 +0200 Subject: [PATCH 1/4] make 50% volume of video max/default --- commands/volume.js | 2 +- helpers/music.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/volume.js b/commands/volume.js index 1ed9893..94b5d9d 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -21,7 +21,7 @@ exports.run = async (client, message, args, level, data) => { if(vol) { vol = Number(vol); - vol = vol / 100 * 0.25; + vol = vol / 100 * 0.5; if(vol <= 1) { client.music.setVolume(message.guild, vol); diff --git a/helpers/music.js b/helpers/music.js index cf1b800..3f2df52 100644 --- a/helpers/music.js +++ b/helpers/music.js @@ -124,7 +124,7 @@ module.exports = client => { let v = guild.queue[0]; guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId)), {type: 'opus'}); - guild.dispatcher.setVolume(0.25); + guild.dispatcher.setVolume(0.5); message.reply('playing **' + v.video.snippet.title + '**'); }; From 8325891854591e982c3051477b34e62aab7026fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hor=C3=A1=C4=8Dek?= Date: Sun, 12 Apr 2020 10:47:48 +0200 Subject: [PATCH 2/4] default to 50% user volume --- helpers/music.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/music.js b/helpers/music.js index 3f2df52..cf1b800 100644 --- a/helpers/music.js +++ b/helpers/music.js @@ -124,7 +124,7 @@ module.exports = client => { let v = guild.queue[0]; guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId)), {type: 'opus'}); - guild.dispatcher.setVolume(0.5); + guild.dispatcher.setVolume(0.25); message.reply('playing **' + v.video.snippet.title + '**'); }; From 89dc88d7860489b525a617fd396780884d7aec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hor=C3=A1=C4=8Dek?= Date: Sun, 12 Apr 2020 10:48:47 +0200 Subject: [PATCH 3/4] fix music being skipped while playing --- helpers/music.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/music.js b/helpers/music.js index cf1b800..a3598d8 100644 --- a/helpers/music.js +++ b/helpers/music.js @@ -123,7 +123,7 @@ module.exports = client => { let v = guild.queue[0]; - guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId)), {type: 'opus'}); + guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'}); guild.dispatcher.setVolume(0.25); message.reply('playing **' + v.video.snippet.title + '**'); From d85a10c7d06260ba619b8bf3e690a3ff1961f7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hor=C3=A1=C4=8Dek?= Date: Sun, 12 Apr 2020 11:07:01 +0200 Subject: [PATCH 4/4] queue --- helpers/music.js | 56 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/helpers/music.js b/helpers/music.js index a3598d8..cd5cf6b 100644 --- a/helpers/music.js +++ b/helpers/music.js @@ -88,37 +88,45 @@ module.exports = client => { }; }; - client.music.play = async function(message, query) { + client.music.play = async function(message, query, ignoreQueue) { let guild = client.music.getGuild(message.guild.id); if(!message.member.voice.channel && !guild.voiceChannel) { - return message.member.reply('you are not in a voice channel!'); + return message.reply('you are not in a voice channel!'); } let vc = message.member.voice.channel; - let video = await client.music.getVideoByQuery(query); + let video; + + if(!ignoreQueue) { + video = await client.music.getVideoByQuery(query); + }; - if(video) { - // Fix the bot if somehow broken - // music "playing", nothing in queue - if((guild.playing || guild.dispatcher) && guild.queue.length == 0) { - guild.playing = false; - guild.dispatcher = null; - // music not playing, something is in queue - } else if(!guild.playing && !guild.dispatcher && guild.queue.length > 0) { - guild.queue = []; + if(video || ignoreQueue) { + if(!ignoreQueue) { + // Fix the bot if somehow broken + // music "playing", nothing in queue + if((guild.playing || guild.dispatcher) && guild.queue.length == 0) { + guild.playing = false; + guild.dispatcher = null; + // music not playing, something is in queue + } else if(!guild.playing && !guild.dispatcher && guild.queue.length > 0) { + guild.queue = []; + }; + + // Add video to queue + guild.queue.push({video: video, requestedBy: message.member.id}); }; - // Add video to queue - guild.queue.push({video: video, requestedBy: message.member.id}); - // Figure out if the bot should add it to queue or play it right now if(guild.playing) { message.reply('added **' + video.snippet.title + '** to the queue'); } else { guild.playing = true; + guild.voiceChannel = vc; + let connection = await vc.join(); let v = guild.queue[0]; @@ -126,10 +134,24 @@ module.exports = client => { guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'}); guild.dispatcher.setVolume(0.25); - message.reply('playing **' + v.video.snippet.title + '**'); + message.channel.send('Playing **' + v.video.snippet.title + '**'); + + // play next in queue on end + guild.dispatcher.once('finish', () => { + guild.queue.shift(); + guild.playing = false; + + if(guild.queue.length > 0) { + client.music.play(message, null, true); + } else { + guild.dispatcher = null; + + connection.leave(); + }; + }); }; } else { - return message.member.reply('failed to find the video!'); + return message.reply('failed to find the video!'); }; };