fixed birthday check, removed console.logs
This commit is contained in:
parent
087dec40ed
commit
ec7193815a
2 changed files with 20 additions and 19 deletions
|
@ -134,12 +134,11 @@ async function addBirthday(options) {
|
||||||
|
|
||||||
async function checkBirthday(interaction) {
|
async function checkBirthday(interaction) {
|
||||||
const currDay = new Date().getDate();
|
const currDay = new Date().getDate();
|
||||||
const currMonth = new Date().getMonth();
|
const currMonth = new Date().getMonth() + 1;
|
||||||
|
|
||||||
|
|
||||||
const query = bModel.find({});
|
const query = bModel.find({});
|
||||||
const result = await query.exec();
|
const result = await query.exec();
|
||||||
console.log(result);
|
|
||||||
|
|
||||||
let closestD;
|
let closestD;
|
||||||
let closestM;
|
let closestM;
|
||||||
|
@ -152,13 +151,13 @@ async function checkBirthday(interaction) {
|
||||||
const userId = result[i].id;
|
const userId = result[i].id;
|
||||||
const nick = result[i].nickname;
|
const nick = result[i].nickname;
|
||||||
if ((currMonth == birthMonth && currDay <= birthDay) || currMonth < birthMonth) {
|
if ((currMonth == birthMonth && currDay <= birthDay) || currMonth < birthMonth) {
|
||||||
|
if (await isInGuild(guildMembers, userId)) {
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
closestD = birthDay;
|
closestD = birthDay;
|
||||||
closestM = birthMonth;
|
closestM = birthMonth;
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
}
|
}
|
||||||
if (!isFirst && (closestD == birthDay && closestM == birthMonth)) {
|
if (!isFirst && (closestD == birthDay && closestM == birthMonth)) {
|
||||||
if (isInGuild(guildMembers, userId)) {
|
|
||||||
closest.push(`<@${userId}> ${nick}`);
|
closest.push(`<@${userId}> ${nick}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -166,19 +165,20 @@ async function checkBirthday(interaction) {
|
||||||
const personList = closest.join('\n');
|
const personList = closest.join('\n');
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`Closest birthday is ${closestD}. ${closestM}.`)
|
.setTitle(`Closest birthday is ${closestD}. ${closestM}.`)
|
||||||
.setDescription(`${personList} \n will celebrate ${probably}`)
|
.setDescription(`${personList} \n will celebrate... ${probably}`)
|
||||||
.setColor(help.randomColor());
|
.setColor(help.randomColor());
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closest != []) {
|
|
||||||
|
if (closest.length > 0) {
|
||||||
const probably = getProbably();
|
const probably = getProbably();
|
||||||
const personList = closest.join('\n');
|
const personList = closest.join('\n');
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`Closest birthday is ${closestD}. ${closestM}.`)
|
.setTitle(`Closest birthday is ${closestD}. ${closestM}.`)
|
||||||
.setDescription(`${personList} \n will celebrate ${probably}`)
|
.setDescription(`${personList} \n will celebrate... ${probably}`)
|
||||||
.setColor(help.randomColor());
|
.setColor(help.randomColor());
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ async function checkBirthday(interaction) {
|
||||||
const probably = getProbably();
|
const probably = getProbably();
|
||||||
closest.join('\n');
|
closest.join('\n');
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`Closest birthday is ${birthDay}. ${birthMonth}.`)
|
.setTitle(`Closest birthday is ${closestD}. ${closestM}.`)
|
||||||
.setDescription(`${closest} \n will celebrate ${probably}`)
|
.setDescription(`${closest} \n will celebrate ${probably}`)
|
||||||
.setColor(help.randomColor());
|
.setColor(help.randomColor());
|
||||||
return embed;
|
return embed;
|
||||||
|
@ -303,7 +303,7 @@ function getProbably() {
|
||||||
case 2:
|
case 2:
|
||||||
return 'or will they?';
|
return 'or will they?';
|
||||||
case 3:
|
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:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,10 @@ async function checkMonth(month) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isInGuild(guildMembers, userId) {
|
async function isInGuild(guildMembers, userId) {
|
||||||
if ((await guildMembers.fetch()).find(user => user.id == userId) == undefined) {
|
try {
|
||||||
|
await guildMembers.fetch(userId);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
2
main.js
2
main.js
|
@ -186,8 +186,6 @@ async function pingEvent() {
|
||||||
|
|
||||||
query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth });
|
query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth });
|
||||||
const globalEventList = await query.exec();
|
const globalEventList = await query.exec();
|
||||||
|
|
||||||
console.log(birthdayList, globalEventList);
|
|
||||||
const guildIds = [];
|
const guildIds = [];
|
||||||
const sysChannelIds = [];
|
const sysChannelIds = [];
|
||||||
client.guilds.cache.forEach(element => {
|
client.guilds.cache.forEach(element => {
|
||||||
|
|
Loading…
Reference in a new issue