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 auth = require('./auth.json');
|
||||||
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||||
|
|
||||||
|
// voice setup
|
||||||
|
var playQueue = [];
|
||||||
|
var playVolume = [];
|
||||||
|
var queueExists = false;
|
||||||
|
var channel = null;
|
||||||
|
|
||||||
// coin flip
|
// coin flip
|
||||||
function coinFlip() {
|
function coinFlip() {
|
||||||
return (Math.floor(Math.random() * 2) == 0) ? 'heads' : 'tails';
|
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;
|
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();
|
const client = new Discord.Client();
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
@@ -258,30 +325,33 @@ client.on('message', message => {
|
|||||||
|
|
||||||
// Voice commands
|
// Voice commands
|
||||||
case 'join':
|
case 'join':
|
||||||
message.member.voiceChannel.join();
|
channel = message.member.voiceChannel;
|
||||||
|
channel.join();
|
||||||
break;
|
break;
|
||||||
case 'leave':
|
case 'leave':
|
||||||
message.member.voiceChannel.leave();
|
case 'stop':
|
||||||
break;
|
case 'skip':
|
||||||
case 'quiethorn':
|
if(channel != null)
|
||||||
message.member.voiceChannel.join().then(connection => {
|
{
|
||||||
const dispatcher = connection.playFile('voice/mlg-airhorn.mp3');
|
channel.leave();
|
||||||
dispatcher.on('end', () => {
|
channel = null;
|
||||||
message.member.voiceChannel.leave();
|
}
|
||||||
});
|
playQueue = [];
|
||||||
|
|
||||||
dispatcher.setVolume(0.01);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 'airhorn':
|
case 'airhorn':
|
||||||
message.member.voiceChannel.join().then(connection => {
|
setupVoice('voice/mlg-airhorn.mp3', 0.35, message.member.voiceChannel);
|
||||||
const dispatcher = connection.playFile('voice/mlg-airhorn.mp3');
|
break;
|
||||||
dispatcher.on('end', () => {
|
case 'quiethorn':
|
||||||
message.member.voiceChannel.leave();
|
setupVoice('voice/mlg-airhorn.mp3', 0.05, message.member.voiceChannel);
|
||||||
});
|
break;
|
||||||
|
case 'weed':
|
||||||
dispatcher.setVolume(0.25);
|
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;
|
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