Added Notifications, Auto-Reassign on Timer Expiration, Add Randomizer
This commit is contained in:
+39
-14
@@ -1,5 +1,7 @@
|
||||
const { Events, MessageFlags } = require('discord.js')
|
||||
const { mClient } = require('../index')
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
once: false,
|
||||
@@ -59,27 +61,50 @@ async function selectMenuHandler(interaction) {
|
||||
}
|
||||
async function modalSubmitHandler(interaction) {
|
||||
if (interaction.customId === 'wgeBaseModal') {
|
||||
await interaction.reply({
|
||||
content: 'Your submission was received successfully!'
|
||||
});
|
||||
const db = mClient.db('neo-db')
|
||||
const wgeColl = db.collection('timer_wge')
|
||||
|
||||
// Get the data entered by the user
|
||||
const wgeAssignedUser = interaction.components[0].component.users.first();
|
||||
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
|
||||
|
||||
const db = mClient.db('neo-db')
|
||||
const wgeColl = db.collection('timer_wge')
|
||||
await wgeColl.insertOne({
|
||||
assignedUser: wgeAssignedUser.id,
|
||||
assigningUser: wgeAssigningUser.id,
|
||||
|
||||
wgeColl.insertOne({
|
||||
"assignedUser": wgeAssignedUser.id,
|
||||
"assigningUser": wgeAssigningUser.id,
|
||||
"timeRemaining": wgeDefaultAssignedTime,
|
||||
"createdAt": new Date(),
|
||||
"topic": wgeAssignedTopic,
|
||||
"debug" :false
|
||||
})
|
||||
startedAt: Date.now(),
|
||||
timeRemaining: wgeDefaultAssignedTime,
|
||||
|
||||
state: 'running',
|
||||
|
||||
notifications: {
|
||||
half: false,
|
||||
day24: false,
|
||||
complete: false
|
||||
},
|
||||
|
||||
topic: wgeAssignedTopic,
|
||||
debug: false,
|
||||
|
||||
createdAt: new Date()
|
||||
});
|
||||
|
||||
return interaction.reply({content: `<@${wgeAssignedUser.id}> is the next expert! Their topic is **${wgeAssignedTopic}**`})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user