From f9e90a8400e0fa7a74d4d29e0929657745c925fd Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 7 Nov 2017 01:29:24 +0000 Subject: [PATCH] Beep --- commands/games/cards-against-humanity.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/commands/games/cards-against-humanity.js b/commands/games/cards-against-humanity.js index 683efad1..011bc8a5 100644 --- a/commands/games/cards-against-humanity.js +++ b/commands/games/cards-against-humanity.js @@ -1,7 +1,7 @@ const { Command } = require('discord.js-commando'); const { escapeMarkdown } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { awaitPlayers } = require('../../util/Util'); +const { shuffle, awaitPlayers } = require('../../util/Util'); const { blackCards, whiteCards } = require('../../assets/json/cards-against-humanity'); module.exports = class CardsAgainstHumanityCommand extends Command { @@ -53,8 +53,10 @@ module.exports = class CardsAgainstHumanityCommand extends Command { `); const chosenCards = []; for (const player of players.values()) { - const valid = whiteCards.filter(card => !player.hand.has(card)); - if (player.hand.size < 11) player.hand.add(valid[Math.floor(Math.random() * valid.length)]); + if (player.hand.size < 11) { + const valid = whiteCards.filter(card => !player.hand.has(card)); + player.hand.add(valid[Math.floor(Math.random() * valid.length)]); + } if (player.user.id === czar.user.id) continue; if (player.hand.size < black.pick) { await player.user.send('You don\'t have enough cards!'); @@ -72,7 +74,6 @@ module.exports = class CardsAgainstHumanityCommand extends Command { const filter = res => { if (chosen.includes(res.content)) return false; if (!player.hand.has(res.content)) return false; - player.hand.delete(res.content); chosen.push(res.content); return true; }; @@ -84,6 +85,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { await player.user.send('Skipping your turn...'); continue; } + for (const card of chosen) player.hand.delete(card); chosenCards.push({ id: player.id, cards: chosen @@ -98,7 +100,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { ${czar.user}, which cards do you pick? **Black Card**: ${escapeMarkdown(black.text)} - ${chosenCards.map((card, i) => `**${i + 1}.** ${card.cards.join(', ')}`).join('\n')} + ${shuffle(chosenCards.map((card, i) => `**${i + 1}.** ${card.cards.join(', ')}`)).join('\n')} `); const filter = res => { if (res.author.id !== czar.user.id) return false;