From f2d789ff850afe133486c76d43252af6371cccf4 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 8 Aug 2018 18:38:43 -0400 Subject: [PATCH] Update CAH with new changes from IA --- commands/games/cards-against-humanity.js | 5 ++--- util/Util.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/commands/games/cards-against-humanity.js b/commands/games/cards-against-humanity.js index e9a7079b..b36104e4 100644 --- a/commands/games/cards-against-humanity.js +++ b/commands/games/cards-against-humanity.js @@ -38,7 +38,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { this.playing.delete(msg.channel.id); return msg.say('Game could not be started...'); } - const players = await this.generatePlayers(awaitedPlayers); + const players = this.generatePlayers(awaitedPlayers); const czars = Array.from(players.values()); let winner = null; while (!winner) { @@ -138,7 +138,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { } } - async generatePlayers(list) { + generatePlayers(list) { const players = new Collection(); for (const user of list) { const cards = new Set(); @@ -152,7 +152,6 @@ module.exports = class CardsAgainstHumanityCommand extends Command { points: 0, hand: cards }); - await user.send('Hi! Waiting for your turn to start...'); } return players; } diff --git a/util/Util.js b/util/Util.js index 7ae83bd8..e327a0ef 100644 --- a/util/Util.js +++ b/util/Util.js @@ -3,6 +3,7 @@ const crypto = require('crypto'); const { IMGUR_KEY } = process.env; const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea']; const no = ['no', 'n', 'nah', 'nope']; +const { SUCCESS_EMOJI_ID, FAILURE_EMOJI_ID } = process.env; class Util { static delay(ms) { @@ -87,14 +88,27 @@ class Util { const joined = []; joined.push(msg.author.id); const filter = res => { - if (msg.author.bot) return false; + if (res.author.bot) return false; if (joined.includes(res.author.id)) return false; if (res.content.toLowerCase() !== text.toLowerCase()) return false; joined.push(res.author.id); + res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); return true; }; const verify = await msg.channel.awaitMessages(filter, { max, time }); verify.set(msg.id, msg); + for (const message of verify.values()) { + try { + await message.author.send('Hi! Just testing that DMs work, pay this no mind.'); + } catch (err) { + try { + await message.react(FAILURE_EMOJI_ID || '❌'); + } catch (error) { + continue; + } + verify.delete(message.id); + } + } if (verify.size < min) return false; return verify.map(message => message.author); }