Only continue if it's valid

This commit is contained in:
Daniel Odendahl Jr
2017-10-17 21:39:03 +00:00
parent cf7e741dd1
commit 271c75566f
+12 -3
View File
@@ -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;
}
}