diff --git a/events/Birthday.js b/events/Birthday.js index 60a3727..583317a 100644 --- a/events/Birthday.js +++ b/events/Birthday.js @@ -101,5 +101,18 @@ module.exports = { description: 'a birthday banner' }] }); + + // mark as notified + + const bdayColl = db.collection('items_birthdays') + await bdayColl.findOneAndUpdate({ + userID: member.user.id + }, { + $set: { + notified: true + } + },{ + upsert: true + }) } }; diff --git a/events/ClientReady.js b/events/ClientReady.js index 2d3eb58..663ea83 100644 --- a/events/ClientReady.js +++ b/events/ClientReady.js @@ -48,21 +48,42 @@ module.exports = { for (const member of members.values()) { const dbEntry = bdayMap.get(member.id); - if (dbEntry && isToday(dbEntry.day, dbEntry.month)) { - // Today is their birthday + if (!dbEntry) continue; + + // skip if already notified + if (dbEntry.notified) { + console.log(`${member.user.username} was already notified today, skipping...`); + continue; + } + + if (isToday(dbEntry.day, dbEntry.month)) { await member.roles.add(birthdayRoleID).catch(err => console.error(`Failed to add birthday role to ${member.user.tag}:`, err) ); + console.log(`Added birthday role to ${member.user.tag}`); client.emit('Birthday', member); + + // mark as notified + await bdayColl.updateOne( + { userID: member.id }, + { $set: { notified: true } } + ); + } else { - // Default fallback: remove birthday role if present if (member.roles.cache.has(birthdayRoleID)) { await member.roles.remove(birthdayRoleID).catch(err => console.error(`Failed to remove birthday role from ${member.user.tag}:`, err) ); - console.log(`Removed birthday role from ${member.user.tag} (not today or not in DB)`); + + console.log(`Removed birthday role from ${member.user.tag}`); } + + // reset notification flag if not birthday anymore + await bdayColl.updateOne( + { userID: member.id }, + { $set: { notified: false } } + ); } } };