From 0813beb2c0cc9dc0a8b725479827e9928c7b0bc4 Mon Sep 17 00:00:00 2001 From: admin_rb Date: Wed, 10 Jun 2026 15:35:03 +0200 Subject: [PATCH] adder list --- commands/slash/applications/wge.js | 48 +++++++++++++++++++++++++++++- events/InteractionCreate.js | 41 +++++++++++++++++++++---- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/commands/slash/applications/wge.js b/commands/slash/applications/wge.js index 412cb36..027506b 100644 --- a/commands/slash/applications/wge.js +++ b/commands/slash/applications/wge.js @@ -237,7 +237,35 @@ async function wgeParticipate(interaction) { upsert: true }) - interaction.reply(`You are ${status ? '' : 'no longer '}participating!`) + interaction.reply({ + content: `You are ${status ? '' : 'no longer '}participating!`, + flags: MessageFlags.Ephemeral + }) +} + +async function wgeList(interaction){ + const thing = interaction.options.getString('thing') + switch (thing) { + case 'participants': + const db = mClient.db('neo-db') + const participantColl = db.collection('items_wge') + const participants = await participantColl.find({ + status: true + }).toArray() + let messageContent = '' + participants.forEach((participant) => { + messageContent += `<@${participant.userID}>\r\n` + }) + + interaction.reply({ + content: `WGE Participants:\r\n${messageContent}`, + flags: MessageFlags.Ephemeral + }) + break; + + default: + break; + } } module.exports = { @@ -294,6 +322,22 @@ module.exports = { .addBooleanOption(o => o.setName('status') .setDescription('choose') + .setRequired(true) + ) + ) + + // List the previous WGE Sessions + .addSubcommand(s => + s + .setName('list') + .setDescription('list things') + .addStringOption(o => + o.setName('thing') + .setDescription('what would you like to be listed') + .addChoices( + { name: 'participants', value: 'participants'}, + { name: 'history', value: 'history'} + ) ) ) , @@ -324,6 +368,8 @@ module.exports = { case 'participate': wgeParticipate(interaction) break; + case 'list': + wgeList(interaction) default: break; } diff --git a/events/InteractionCreate.js b/events/InteractionCreate.js index 01e6592..6aaf47d 100644 --- a/events/InteractionCreate.js +++ b/events/InteractionCreate.js @@ -64,19 +64,48 @@ async function modalSubmitHandler(interaction) { const db = mClient.db('neo-db') const wgeColl = db.collection('timer_wge') + const prevWge = await wgeColl.findOne({ + $and: [ + { debug: false }, + { state: 'running' } + ] + }) + + if (prevWge != null) { + // Save previous run in history_wge + const historyWgeColl = db.collection('history_wge') + await historyWgeColl.insertOne({ + assignedUser: prevWge.assignedUser, + assigningUser: prevWge.assigningUser, + timeRemaining: prevWge.timeRemaining, + topic: prevWge.topic, + debug: prevWge.debug, + createdAt: prevWge.createdAt + }); + + console.log({ + message: 'saved previous wge in history_wge', + data: prevWge + }) + + await wgeColl.deleteOne({ + _id: prevWge._id + }) + } + // Get the data entered by the user var wgeAssignedUser = interaction.components[0].component.users.first(); const wgeAssigningUser = interaction.user - if(wgeAssignedUser.id === process.env.D_ID){ + if (wgeAssignedUser.id === process.env.D_ID) { // Randomizer Function const participateColl = db.collection('items_wge') const randomParticipant = await participateColl.aggregate([ - { $match: { status: true}}, - { $sample: { size: 1}} + { $match: { status: true } }, + { $sample: { size: 1 } } ]).toArray() - if(!randomParticipant){return interaction.followUp({content: 'No User is participating!'})} - + if (!randomParticipant) { return interaction.followUp({ content: 'No User is participating!' }) } + random = await interaction.guild.members.fetch(randomParticipant[0].userID) wgeAssignedUser = random.user } @@ -105,6 +134,6 @@ async function modalSubmitHandler(interaction) { createdAt: new Date() }); - return interaction.reply({content: `<@${wgeAssignedUser.id}> is the next expert! Their topic is **${wgeAssignedTopic}**`}) + return interaction.reply({ content: `<@${wgeAssignedUser.id}> is the next expert! Their topic is **${wgeAssignedTopic}**` }) } } \ No newline at end of file