From ec7193815a2018b8984d55bc0460ad3359031576 Mon Sep 17 00:00:00 2001 From: ZyLacx Date: Fri, 18 Feb 2022 15:26:05 +0100 Subject: [PATCH] fixed birthday check, removed console.logs --- commands/birthday.js | 37 ++++++++++++++++++++----------------- main.js | 2 -- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/commands/birthday.js b/commands/birthday.js index 1c3c83c..70e8e17 100644 --- a/commands/birthday.js +++ b/commands/birthday.js @@ -134,12 +134,11 @@ async function addBirthday(options) { async function checkBirthday(interaction) { const currDay = new Date().getDate(); - const currMonth = new Date().getMonth(); + const currMonth = new Date().getMonth() + 1; const query = bModel.find({}); const result = await query.exec(); - console.log(result); let closestD; let closestM; @@ -152,33 +151,34 @@ async function checkBirthday(interaction) { const userId = result[i].id; const nick = result[i].nickname; if ((currMonth == birthMonth && currDay <= birthDay) || currMonth < birthMonth) { - if (isFirst) { - closestD = birthDay; - closestM = birthMonth; - isFirst = false; - } - if (!isFirst && (closestD == birthDay && closestM == birthMonth)) { - if (isInGuild(guildMembers, userId)) { + if (await isInGuild(guildMembers, userId)) { + if (isFirst) { + closestD = birthDay; + closestM = birthMonth; + isFirst = false; + } + if (!isFirst && (closestD == birthDay && closestM == birthMonth)) { closest.push(`<@${userId}> ${nick}`); } else { const probably = getProbably(); const personList = closest.join('\n'); const embed = new MessageEmbed() - .setTitle(`Closest birthday is ${closestD}. ${closestM}.`) - .setDescription(`${personList} \n will celebrate ${probably}`) - .setColor(help.randomColor()); + .setTitle(`Closest birthday is ${closestD}. ${closestM}.`) + .setDescription(`${personList} \n will celebrate... ${probably}`) + .setColor(help.randomColor()); return embed; } } } } - if (closest != []) { + + if (closest.length > 0) { const probably = getProbably(); const personList = closest.join('\n'); const embed = new MessageEmbed() .setTitle(`Closest birthday is ${closestD}. ${closestM}.`) - .setDescription(`${personList} \n will celebrate ${probably}`) + .setDescription(`${personList} \n will celebrate... ${probably}`) .setColor(help.randomColor()); return embed; } @@ -200,7 +200,7 @@ async function checkBirthday(interaction) { const probably = getProbably(); closest.join('\n'); const embed = new MessageEmbed() - .setTitle(`Closest birthday is ${birthDay}. ${birthMonth}.`) + .setTitle(`Closest birthday is ${closestD}. ${closestM}.`) .setDescription(`${closest} \n will celebrate ${probably}`) .setColor(help.randomColor()); return embed; @@ -303,7 +303,7 @@ function getProbably() { case 2: return 'or will they?'; case 3: - return '\n I still love you the same don\'t worry'; + return '\n You may be older, but I still love you the same don\'t worry'; default: return ''; } @@ -339,7 +339,10 @@ async function checkMonth(month) { } async function isInGuild(guildMembers, userId) { - if ((await guildMembers.fetch()).find(user => user.id == userId) == undefined) { + try { + await guildMembers.fetch(userId); + } + catch { return false; } return true; diff --git a/main.js b/main.js index 98c7d29..c4e103b 100755 --- a/main.js +++ b/main.js @@ -186,8 +186,6 @@ async function pingEvent() { query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth }); const globalEventList = await query.exec(); - - console.log(birthdayList, globalEventList); const guildIds = []; const sysChannelIds = []; client.guilds.cache.forEach(element => {