From 271c75566f87d40f5df1e973f61728324a133636 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 17 Oct 2017 21:39:03 +0000 Subject: [PATCH] Only continue if it's valid --- util/Util.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/util/Util.js b/util/Util.js index c5bbfcaa..f7767a84 100644 --- a/util/Util.js +++ b/util/Util.js @@ -1,4 +1,6 @@ const { promisify } = require('util'); +const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea']; +const no = ['no', 'n', 'nah', 'nope']; class Util { static wait(time) { @@ -92,12 +94,19 @@ class Util { return ctx; } - static async verify(channel, user, time = 30000) { - const verify = await channel.awaitMessages(res => res.author.id === user.id, { + static verify(channel, user, time = 30000) { + const filter = res => { + const value = res.content.toLowerCase(); + return res.author.id === user.id && (yes.includes(value) || no.includes(value)); + }; + const verify = await channel.awaitMessages(filter, { max: 1, time }); - return verify.size && ['yes', 'y', 'ye', 'yeah', 'yup'].includes(verify.first().content.toLowerCase()); + if (!verify.size) return false; + const choice = verify.first().content.toLowerCase(); + if (yes.includes(choice)) return true; + if (no.includes(choice)) return false; } }