From df6211d5e439575be29d6cd0af607f5b70775e62 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Thu, 19 Nov 2020 23:24:59 +0000 Subject: [PATCH] feat(*): Finish implementing start command --- index.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 14c31e0..0141f2a 100644 --- a/index.js +++ b/index.js @@ -286,15 +286,22 @@ client.on('message', function (message) { logger.info(`${message.author.username} used command lq in ${message.channel.name}`); - logger.log('info', `${message.author.username} left the queue.`); - message.channel.send(`${message.author.username} left the queue.`); - for( var i = 0; i < playerQueue.length; i++){ if ( playerQueue[i] === message.author) { playerQueue.splice(i, 1); i--; } - } + } + + for( var i = 0; i < playerVotes.length; i++){ + if ( playerVotes[i] === message.author) { + playerVotes.splice(i, 1); + i--; + } + } + + logger.log('info', `${message.author.username} left the queue.`); + message.channel.send(`${message.author.username} left the queue.`); checkQueue(message); } @@ -325,18 +332,18 @@ client.on('message', function (message) { // First player to vote playerVotes.push(message.author); - message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${maxqueuesize} players.`); + message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`); } else if (playerVotes.includes(message.author.username)) { - message.channel.send(`=====\n${message.author.username} has already voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${maxqueuesize} players.`); + message.channel.send(`=====\n${message.author.username} has already voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`); } - else if (playerVotes.length < maxqueuesize) { + else if (playerVotes.length < config.maxqueuesize) { // Not the first player to vote playerVotes.push(message.author); - if (playerVotes.length < maxqueuesize) { - // Still not all players voted - message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${maxqueuesize} players.`); + if (playerVotes.length < playerQueue.length) { + // Still not all players voted + message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`); } else { // All players have voted, we can start the adventure early @@ -398,6 +405,13 @@ client.on('message', function (message) { } } + for( var i = 0; i < playerVotes.length; i++){ + if ( playerVotes[i].username === user.username) { + playerVotes.splice(i, 1); + i--; + } + } + message.channel.send(`${user.username} removed from queue.`); logger.log('info', `${message.author.username} removed ${user.username} from queue.`);