Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d7e47af3f | |||
| a94562c40b |
@@ -172,7 +172,7 @@ async function wgeResume(interaction) {
|
||||
if (!timer) {
|
||||
return interaction.reply({
|
||||
content: 'Timer not found.',
|
||||
ephemeral: true
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,45 +196,65 @@ async function wgeResume(interaction) {
|
||||
}
|
||||
|
||||
async function wgeForfeit(interaction) {
|
||||
// Reset Timer, Reassign Randomly
|
||||
const db = mClient.db('neo-db')
|
||||
const wgeColl = db.collection('timer_wge')
|
||||
|
||||
// Randomizer Function
|
||||
const participateColl = db.collection('items_wge')
|
||||
const randomParticipant = await participateColl.aggregate([
|
||||
{ $match: { status: true } },
|
||||
{ $sample: { size: 1 } }
|
||||
]).toArray()
|
||||
|
||||
if (!randomParticipant.length) { return interaction.reply({ content: 'No one else is participating!' }) }
|
||||
|
||||
random = await interaction.guild.members.fetch(randomParticipant[0].userID)
|
||||
wgeAssignedUser = random.user
|
||||
const db = mClient.db('neo-db');
|
||||
const wgeColl = db.collection('timer_wge');
|
||||
const participateColl = db.collection('items_wge');
|
||||
|
||||
// Get active WGE
|
||||
const wge = await wgeColl.findOne({
|
||||
$and: [
|
||||
{ debug: false },
|
||||
{ state: 'running' }
|
||||
]
|
||||
})
|
||||
debug: false,
|
||||
state: 'running'
|
||||
});
|
||||
|
||||
await wgeColl.deleteOne({
|
||||
_id: wge._id
|
||||
})
|
||||
if (!wge) {
|
||||
return interaction.reply({
|
||||
content: 'No active WGE is currently running.',
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
|
||||
// Sanity check: only assigned user can forfeit
|
||||
if (wge.assignedUser !== interaction.user.id) {
|
||||
return interaction.reply({
|
||||
content: `Only <@${wge.assignedUser}> can forfeit the current WGE.`,
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
interaction.reply({
|
||||
content: `${interaction.user} has forfeited! <@${wgeAssignedUser.id}> is the next expert! Their topic is **${wge.topic}**`
|
||||
})
|
||||
// Pick a new participant, excluding current assignee
|
||||
const [randomParticipant] = await participateColl.aggregate([
|
||||
{
|
||||
$match: {
|
||||
status: true,
|
||||
userID: { $ne: interaction.user.id }
|
||||
}
|
||||
},
|
||||
{ $sample: { size: 1 } }
|
||||
]).toArray();
|
||||
|
||||
if (!randomParticipant) {
|
||||
return interaction.reply({
|
||||
content: 'No one else is participating!',
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
const member = await interaction.guild.members.fetch(
|
||||
randomParticipant.userID
|
||||
);
|
||||
|
||||
const nextUser = member.user;
|
||||
|
||||
const WGE_DURATION = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||
|
||||
await wgeColl.deleteOne({ _id: wge._id });
|
||||
|
||||
await wgeColl.insertOne({
|
||||
assignedUser: wgeAssignedUser.id,
|
||||
assignedUser: nextUser.id,
|
||||
assigningUser: wge.assigningUser,
|
||||
|
||||
startedAt: Date.now(),
|
||||
timeRemaining: wgeDefaultAssignedTime,
|
||||
timeRemaining: WGE_DURATION,
|
||||
|
||||
state: 'running',
|
||||
|
||||
@@ -249,6 +269,10 @@ async function wgeForfeit(interaction) {
|
||||
|
||||
createdAt: new Date()
|
||||
});
|
||||
|
||||
return interaction.reply({
|
||||
content: `${interaction.user} has forfeited! <@${nextUser.id}> is the next expert! Their topic is **${wge.topic}**`
|
||||
});
|
||||
}
|
||||
|
||||
async function wgeHistory(interaction) {
|
||||
|
||||
@@ -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