created play queue, added weed, damnson, wombo voice commands
This commit is contained in:
112
bot.js
112
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;
|
||||
}
|
||||
|
||||
|
BIN
voice/damnson.mp3
Normal file
BIN
voice/damnson.mp3
Normal file
Binary file not shown.
BIN
voice/smoke-weed.mp3
Normal file
BIN
voice/smoke-weed.mp3
Normal file
Binary file not shown.
BIN
voice/wombocombo.mp3
Normal file
BIN
voice/wombocombo.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user