diff --git a/bot.js b/bot.js index dccbf29..8c59cdc 100644 --- a/bot.js +++ b/bot.js @@ -3,6 +3,12 @@ const Discord = require('discord.js'); const auth = require('./auth.json'); const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; +// voice setup +var playQueue = []; +var playVolume = []; +var queueExists = false; +var channel = null; + // coin flip function coinFlip() { return (Math.floor(Math.random() * 2) == 0) ? 'heads' : 'tails'; @@ -143,7 +149,68 @@ function getRandomInt(min, max) return Math.floor(Math.random() * (max - min + 1)) + min; } -// setup +// voice setup +function setupVoice(file, volume, voice_channel) +{ + playQueue.unshift(file); + playVolume.unshift(volume); + + if(!channel) + { + channel = voice_channel; + } + if(channel instanceof Discord.VoiceChannel) + { + if(!queueExists) + { + queueExists = true; + channel.join().then(connection => + { + handlePlayQueue(connection); + }); + } + } + else + { + playQueue.pop(); + playVolume.pop(); + channel = null; + } +} + +// voice queue +function handlePlayQueue(connection) +{ + if (playQueue.length == 0) + { + return; + } + + currentCommand = playQueue[0]; + const dispatcher = connection.playFile(currentCommand) + dispatcher.on("end", () => + { + playQueue.pop(); + playVolume.pop(); + + if(playQueue.length == 0) + { + queueExists = false; + if(channel != null) + { + channel.leave(); + channel = null; + } + } + else + { + handlePlayQueue(connection); + } + }); + dispatcher.setVolume(playVolume[0]); +} + +// discord setup const client = new Discord.Client(); client.on('ready', () => { @@ -258,30 +325,33 @@ client.on('message', message => { // Voice commands case 'join': - message.member.voiceChannel.join(); + channel = message.member.voiceChannel; + channel.join(); break; case 'leave': - message.member.voiceChannel.leave(); - break; - case 'quiethorn': - message.member.voiceChannel.join().then(connection => { - const dispatcher = connection.playFile('voice/mlg-airhorn.mp3'); - dispatcher.on('end', () => { - message.member.voiceChannel.leave(); - }); - - dispatcher.setVolume(0.01); - }); + case 'stop': + case 'skip': + if(channel != null) + { + channel.leave(); + channel = null; + } + playQueue = []; break; case 'airhorn': - message.member.voiceChannel.join().then(connection => { - const dispatcher = connection.playFile('voice/mlg-airhorn.mp3'); - dispatcher.on('end', () => { - message.member.voiceChannel.leave(); - }); - - dispatcher.setVolume(0.25); - }); + setupVoice('voice/mlg-airhorn.mp3', 0.35, message.member.voiceChannel); + break; + case 'quiethorn': + setupVoice('voice/mlg-airhorn.mp3', 0.05, message.member.voiceChannel); + break; + case 'weed': + setupVoice('voice/smoke-weed.mp3', 0.35, message.member.voiceChannel); + break; + case 'damnson': + setupVoice('voice/damnson.mp3', 0.35, message.member.voiceChannel); + break; + case 'wombo': + setupVoice('voice/wombocombo.mp3', 0.20, message.member.voiceChannel); break; } diff --git a/voice/damnson.mp3 b/voice/damnson.mp3 new file mode 100644 index 0000000..d766de3 Binary files /dev/null and b/voice/damnson.mp3 differ diff --git a/voice/smoke-weed.mp3 b/voice/smoke-weed.mp3 new file mode 100644 index 0000000..454e1e7 Binary files /dev/null and b/voice/smoke-weed.mp3 differ diff --git a/voice/wombocombo.mp3 b/voice/wombocombo.mp3 new file mode 100644 index 0000000..85dfabf Binary files /dev/null and b/voice/wombocombo.mp3 differ