Added Leaderboard to Quotes

This commit is contained in:
DeSqBlocki
2024-09-07 15:24:56 +02:00
parent d7c3bdb5f7
commit 3fc1ac1d54
20 changed files with 804 additions and 93 deletions
+36 -1
View File
@@ -1,4 +1,5 @@
const { Events, ActivityType } = require('discord.js')
const { Events, ActivityType } = require('discord.js');
const { mClient } = require('..');
module.exports = {
name: Events.ClientReady,
@@ -13,5 +14,39 @@ module.exports = {
}],
status: 'online'
})
// if today is birthday
function isToday(day, month) {
const currentYear = new Date().getFullYear();
const inputDate = new Date(currentYear, month - 1, day);
const today = new Date();
return (
inputDate.getDate() === today.getDate() &&
inputDate.getMonth() === today.getMonth() &&
inputDate.getFullYear() === today.getFullYear()
);
}
async function isBirthday() {
const db = mClient.db(process.env.M_DB)
const bdayColl = db.collection('birthdays')
const allBirthdays = await bdayColl.find().toArray()
for (let index = 0; index < allBirthdays.length; index++) {
if (isToday(allBirthdays[index].day, allBirthdays[index].month)) {
let guild = client.guilds.cache.get(process.env.D_GuildID)
let member = guild.members.cache.get(allBirthdays[index].userID)
client.emit('Birthday', member)
} else {
// remove any residual birthday roles
try {
let guild = client.guilds.cache.get(process.env.D_GuildID)
let member = guild.members.cache.get(allBirthdays[index].userID)
await member.roles.remove('702877228857557002')
} catch (error) {
console.error('Could not remove role', error)
}
}
}
}
isBirthday()
}
}