fixed birthday check, removed console.logs

This commit is contained in:
ZyLacx 2022-02-18 15:26:05 +01:00
parent 087dec40ed
commit ec7193815a
2 changed files with 20 additions and 19 deletions

View file

@ -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,13 +151,13 @@ async function checkBirthday(interaction) {
const userId = result[i].id;
const nick = result[i].nickname;
if ((currMonth == birthMonth && currDay <= birthDay) || currMonth < birthMonth) {
if (await isInGuild(guildMembers, userId)) {
if (isFirst) {
closestD = birthDay;
closestM = birthMonth;
isFirst = false;
}
if (!isFirst && (closestD == birthDay && closestM == birthMonth)) {
if (isInGuild(guildMembers, userId)) {
closest.push(`<@${userId}> ${nick}`);
}
else {
@ -166,19 +165,20 @@ async function checkBirthday(interaction) {
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;
}
}
}
}
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;

View file

@ -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 => {