gave birthday a notified status to only notify once a day
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
+25
-4
@@ -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 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user