rewrote wgeStart from userselect to stringselect with user prefill
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const { ModalBuilder, UserSelectMenuBuilder, TextInputBuilder, EmbedBuilder, TimestampStyles, time } = require("@discordjs/builders");
|
const { ModalBuilder, UserSelectMenuBuilder, TextInputBuilder, EmbedBuilder, TimestampStyles, time, StringSelectMenuBuilder } = require("@discordjs/builders");
|
||||||
const { SlashCommandBuilder, LabelBuilder, TextInputStyle, MessageFlags } = require("discord.js");
|
const { SlashCommandBuilder, LabelBuilder, TextInputStyle, MessageFlags } = require("discord.js");
|
||||||
const { mClient } = require("../../..");
|
const { mClient } = require("../../..");
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
@@ -59,34 +59,70 @@ async function wgeStatus(interaction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function wgeStart(interaction) {
|
async function wgeStart(interaction) {
|
||||||
|
const defaultUsers = []
|
||||||
|
defaultUsers.push(process.env.D_ID)
|
||||||
|
|
||||||
|
const db = mClient.db('neo-db')
|
||||||
|
const participantColl = db.collection('items_wge')
|
||||||
|
const participants = await participantColl.find({
|
||||||
|
status: true
|
||||||
|
}).toArray()
|
||||||
|
|
||||||
|
|
||||||
const wgeBaseModal = new ModalBuilder()
|
const wgeBaseModal = new ModalBuilder()
|
||||||
.setCustomId('wgeBaseModal')
|
.setCustomId('wgeBaseModal')
|
||||||
.setTitle("World's Greatest Expert")
|
.setTitle("World's Greatest Expert")
|
||||||
|
|
||||||
const wgeUserInput = new UserSelectMenuBuilder()
|
const options = [
|
||||||
.setCustomId('wgeUserInput')
|
{
|
||||||
|
label: 'RANDOM',
|
||||||
|
value: process.env.D_ID
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const participantOptions = await Promise.all(
|
||||||
|
participants.map(async (participant) => {
|
||||||
|
try {
|
||||||
|
const member = await interaction.guild.members.fetch(participant.userID);
|
||||||
|
return {
|
||||||
|
label: `${member.displayName} (${member.user.username})`,
|
||||||
|
value: participant.userID
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
options.push(
|
||||||
|
...participantOptions.filter(option => option !== null)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Using StringSelectMenuBuilder because UserSelectMenuBuilder cannot be filtered for now
|
||||||
|
const wgeUserCustInput = new StringSelectMenuBuilder()
|
||||||
|
.setCustomId('wgeCustUserInput')
|
||||||
.setMaxValues(1)
|
.setMaxValues(1)
|
||||||
|
.setMinValues(1)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addDefaultUsers(process.env.D_ID)
|
.addOptions(options)
|
||||||
// DefaultUser is randomizer
|
|
||||||
|
|
||||||
const wgeTopicInput = new TextInputBuilder()
|
const wgeTopicInput = new TextInputBuilder()
|
||||||
.setCustomId('wgeTopicInput')
|
.setCustomId('wgeTopicInput')
|
||||||
.setStyle(TextInputStyle.Short)
|
.setStyle(TextInputStyle.Short)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
|
|
||||||
const wgeUserLabel = new LabelBuilder()
|
|
||||||
.setLabel("Who is YOUR World's Greatest Expert?")
|
|
||||||
.setDescription('Select them!')
|
|
||||||
.setUserSelectMenuComponent(wgeUserInput)
|
|
||||||
|
|
||||||
const wgeTopicLabel = new LabelBuilder()
|
const wgeTopicLabel = new LabelBuilder()
|
||||||
.setLabel("And WHAT are they an expert in?")
|
.setLabel("And WHAT are they an expert in?")
|
||||||
.setDescription('Tell me!')
|
.setDescription('Tell me!')
|
||||||
.setTextInputComponent(wgeTopicInput)
|
.setTextInputComponent(wgeTopicInput)
|
||||||
|
|
||||||
|
const wgeCustUserLabel = new LabelBuilder()
|
||||||
|
.setLabel('WHO is your greatest expert?')
|
||||||
|
.setDescription('Select them')
|
||||||
|
.setStringSelectMenuComponent(wgeUserCustInput)
|
||||||
|
|
||||||
wgeBaseModal
|
wgeBaseModal
|
||||||
.addLabelComponents(wgeUserLabel, wgeTopicLabel)
|
.addLabelComponents(wgeCustUserLabel, wgeTopicLabel)
|
||||||
|
|
||||||
await interaction.showModal(wgeBaseModal)
|
await interaction.showModal(wgeBaseModal)
|
||||||
}
|
}
|
||||||
@@ -179,7 +215,7 @@ async function wgeForfeit(interaction) {
|
|||||||
const wge = await wgeColl.findOne({
|
const wge = await wgeColl.findOne({
|
||||||
$and: [
|
$and: [
|
||||||
{ debug: false },
|
{ debug: false },
|
||||||
{ state: 'running'}
|
{ state: 'running' }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -357,11 +393,11 @@ module.exports = {
|
|||||||
.setDescription('list things')
|
.setDescription('list things')
|
||||||
.addStringOption(o =>
|
.addStringOption(o =>
|
||||||
o.setName('thing')
|
o.setName('thing')
|
||||||
.setDescription('what would you like to be listed')
|
.setDescription('what would you like to be listed')
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{ name: 'participants', value: 'participants'},
|
{ name: 'participants', value: 'participants' },
|
||||||
{ name: 'history', value: 'history'}
|
{ name: 'history', value: 'history' }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
,
|
,
|
||||||
|
|||||||
+35
-17
@@ -1,4 +1,4 @@
|
|||||||
const { Events, MessageFlags } = require('discord.js')
|
const { Events, MessageFlags, Message } = require('discord.js')
|
||||||
const { mClient } = require('../index')
|
const { mClient } = require('../index')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
@@ -63,6 +63,40 @@ async function modalSubmitHandler(interaction) {
|
|||||||
if (interaction.customId === 'wgeBaseModal') {
|
if (interaction.customId === 'wgeBaseModal') {
|
||||||
const db = mClient.db('neo-db')
|
const db = mClient.db('neo-db')
|
||||||
const wgeColl = db.collection('timer_wge')
|
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({
|
const prevWge = await wgeColl.findOne({
|
||||||
$and: [
|
$and: [
|
||||||
@@ -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 wgeAssignedTopic = interaction.fields.getTextInputValue('wgeTopicInput');
|
||||||
|
|
||||||
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
|
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
|
||||||
|
|||||||
Reference in New Issue
Block a user