added sanity check for forfeit

This commit is contained in:
2026-06-12 21:44:35 +02:00
parent f269e15a76
commit a94562c40b
+54 -30
View File
@@ -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) {