rewrote wgeStart from userselect to stringselect with user prefill
This commit is contained in:
+36
-18
@@ -1,4 +1,4 @@
|
||||
const { Events, MessageFlags } = require('discord.js')
|
||||
const { Events, MessageFlags, Message } = require('discord.js')
|
||||
const { mClient } = require('../index')
|
||||
require('dotenv').config()
|
||||
|
||||
@@ -63,6 +63,40 @@ async function modalSubmitHandler(interaction) {
|
||||
if (interaction.customId === 'wgeBaseModal') {
|
||||
const db = mClient.db('neo-db')
|
||||
const wgeColl = db.collection('timer_wge')
|
||||
const participateColl = db.collection('items_wge')
|
||||
|
||||
// Get the data entered by the user
|
||||
|
||||
var wgeAssignedUser = {}
|
||||
wgeAssignedUser.id = interaction.components[0].component.values[0]
|
||||
|
||||
const wgeAssigningUser = interaction.user
|
||||
if (wgeAssignedUser.id === process.env.D_ID) {
|
||||
// Randomizer Function
|
||||
const randomParticipant = await participateColl.aggregate([
|
||||
{ $match: { status: true } },
|
||||
{ $sample: { size: 1 } }
|
||||
]).toArray()
|
||||
|
||||
if (!randomParticipant) { return interaction.followUp({ content: 'No User is participating!' }) }
|
||||
|
||||
random = await interaction.guild.members.fetch(randomParticipant[0].userID)
|
||||
wgeAssignedUser = random.user
|
||||
} else {
|
||||
// validate non-random user
|
||||
const foundParticipant = await participateColl.findOne({
|
||||
$and: [
|
||||
{ assignedUser: wgeAssignedUser.id },
|
||||
{ status: true}
|
||||
]
|
||||
})
|
||||
|
||||
if(!foundParticipant || foundParticipant == null){ return interaction.reply({
|
||||
content: `<@${wgeAssignedUser.id}> is not participating!`,
|
||||
flags: MessageFlags.Ephemeral
|
||||
})}
|
||||
}
|
||||
|
||||
|
||||
const prevWge = await wgeColl.findOne({
|
||||
$and: [
|
||||
@@ -70,7 +104,7 @@ async function modalSubmitHandler(interaction) {
|
||||
{ state: 'running' }
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
if (prevWge != null) {
|
||||
// Save previous run in history_wge
|
||||
const historyWgeColl = db.collection('history_wge')
|
||||
@@ -93,22 +127,6 @@ async function modalSubmitHandler(interaction) {
|
||||
})
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// Randomizer Function
|
||||
const participateColl = db.collection('items_wge')
|
||||
const randomParticipant = await participateColl.aggregate([
|
||||
{ $match: { status: true } },
|
||||
{ $sample: { size: 1 } }
|
||||
]).toArray()
|
||||
|
||||
if (!randomParticipant) { return interaction.followUp({ content: 'No User is participating!' }) }
|
||||
|
||||
random = await interaction.guild.members.fetch(randomParticipant[0].userID)
|
||||
wgeAssignedUser = random.user
|
||||
}
|
||||
const wgeAssignedTopic = interaction.fields.getTextInputValue('wgeTopicInput');
|
||||
|
||||
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
|
||||
|
||||
Reference in New Issue
Block a user