WGE Implementation Basics
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
const { ModalBuilder, UserSelectMenuBuilder, TextInputBuilder, EmbedBuilder, TimestampStyles, time } = require("@discordjs/builders");
|
||||
const { SlashCommandBuilder, LabelBuilder, TextInputStyle, MessageFlags } = require("discord.js");
|
||||
const { mClient } = require("../../..");
|
||||
|
||||
function ordinal(n) {
|
||||
const s = ["th", "st", "nd", "rd"];
|
||||
const v = n % 100;
|
||||
|
||||
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
||||
}
|
||||
|
||||
async function wgeStatus(interaction) {
|
||||
const db = mClient.db('neo-db')
|
||||
const wgeColl = db.collection('timer_wge')
|
||||
const historyColl = db.collection('history_wge');
|
||||
|
||||
const results = await wgeColl.findOne({
|
||||
"debug": false
|
||||
})
|
||||
if (!results) {
|
||||
return interaction.editReply({
|
||||
content: 'No WGE Session currently running!',
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
|
||||
const historyCount = await historyColl.countDocuments();
|
||||
const iteration = historyCount + 1;
|
||||
|
||||
const createdAt = new Date(results.createdAt)
|
||||
const expiresAt = new Date(createdAt.getTime() + Number(results.timeRemaining))
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`✨ [${ordinal(iteration)}] World's Greatest Expert ✨`)
|
||||
.setDescription(
|
||||
`<@${results.assignedUser}> is currently the **World's Greatest Expert** in **${results.topic}**.\n\n` +
|
||||
`They must submit their entry <t:${Math.floor(expiresAt.getTime() / 1000)}:R>.\n\n` +
|
||||
`Thank you, <@${results.assigningUser}>, for the nomination!`
|
||||
)
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [embed]
|
||||
})
|
||||
}
|
||||
|
||||
async function wgeStart(interaction) {
|
||||
const wgeBaseModal = new ModalBuilder()
|
||||
.setCustomId('wgeBaseModal')
|
||||
.setTitle("World's Greatest Expert")
|
||||
|
||||
const wgeUserInput = new UserSelectMenuBuilder()
|
||||
.setCustomId('wgeUserInput')
|
||||
.setMaxValues(1)
|
||||
.setRequired(true)
|
||||
|
||||
const wgeTopicInput = new TextInputBuilder()
|
||||
.setCustomId('wgeTopicInput')
|
||||
.setStyle(TextInputStyle.Short)
|
||||
.setRequired(true)
|
||||
|
||||
const wgeUserLabel = new LabelBuilder()
|
||||
.setLabel("Who is YOUR World's Greatest Expert?")
|
||||
.setDescription('Select them!')
|
||||
.setUserSelectMenuComponent(wgeUserInput)
|
||||
|
||||
const wgeTopicLabel = new LabelBuilder()
|
||||
.setLabel("And WHAT are they an expert in?")
|
||||
.setDescription('Tell me!')
|
||||
.setTextInputComponent(wgeTopicInput)
|
||||
|
||||
wgeBaseModal
|
||||
.addLabelComponents(wgeUserLabel, wgeTopicLabel)
|
||||
|
||||
await interaction.showModal(wgeBaseModal)
|
||||
}
|
||||
|
||||
async function wgeStop(interaction) {
|
||||
|
||||
}
|
||||
|
||||
async function wgePause(interaction) {
|
||||
|
||||
}
|
||||
|
||||
async function wgeResume(interaction) {
|
||||
|
||||
}
|
||||
|
||||
async function wgeForfeit(interaction) {
|
||||
|
||||
}
|
||||
|
||||
async function wgeHistory(interaction) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('wge')
|
||||
.setDescription('welcome to worlds greatest experts')
|
||||
// Show Status of Current Running WGE Session
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('status')
|
||||
.setDescription('display current wge session')
|
||||
)
|
||||
|
||||
// Assign Someone to be the next Expert
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('start')
|
||||
.setDescription('start a new wge session')
|
||||
)
|
||||
|
||||
// Stop the current Session, No Reassignment
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('stop')
|
||||
.setDescription('stop the current wge session')
|
||||
)
|
||||
|
||||
// Halt the current Session Timer
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('pause')
|
||||
.setDescription('pause the current wge session timer')
|
||||
)
|
||||
|
||||
// Resume the current Session Timer
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('resume')
|
||||
.setDescription('resume the current wge session timer')
|
||||
)
|
||||
|
||||
// Forfeit your current expert topic and assign someone else
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('forfeit')
|
||||
.setDescription('forfeit your current topic')
|
||||
)
|
||||
|
||||
// List the previous WGE Sessions
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('history')
|
||||
.setDescription('display the previous wge sessions')
|
||||
)
|
||||
,
|
||||
async execute(interaction) {
|
||||
switch (interaction.options._subcommand) {
|
||||
case 'status':
|
||||
await interaction.deferReply()
|
||||
wgeStatus(interaction)
|
||||
break;
|
||||
case 'start':
|
||||
wgeStart(interaction)
|
||||
break;
|
||||
case 'stop':
|
||||
wgeStop(interaction)
|
||||
break;
|
||||
case 'pause':
|
||||
wgePause(interaction)
|
||||
break;
|
||||
case 'resume':
|
||||
wgeResume(interaction)
|
||||
break;
|
||||
case 'forfeit':
|
||||
wgeForfeit(interaction)
|
||||
break;
|
||||
case 'history':
|
||||
wgeHistory(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
const { Events, MessageFlags } = require('discord.js')
|
||||
|
||||
const { mClient } = require('../index')
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
once: false,
|
||||
async execute(interaction) {
|
||||
if (interaction.isChatInputCommand()) { commandHandler(interaction) };
|
||||
if (interaction.isChatInputCommand()) { commandHandler(interaction) }
|
||||
if (interaction.isButton()) { buttonHandler(interaction) }
|
||||
if (interaction.isMentionableSelectMenu()) { selectMenuHandler(interaction)}
|
||||
if (interaction.isMentionableSelectMenu()) { selectMenuHandler(interaction) }
|
||||
if (interaction.isUserSelectMenu()) { selectMenuHandler(interaction) }
|
||||
if (interaction.isModalSubmit()) { modalSubmitHandler(interaction) }
|
||||
}
|
||||
}
|
||||
async function commandHandler(interaction) {
|
||||
@@ -56,3 +57,29 @@ async function selectMenuHandler(interaction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
async function modalSubmitHandler(interaction) {
|
||||
if (interaction.customId === 'wgeBaseModal') {
|
||||
await interaction.reply({
|
||||
content: 'Your submission was received successfully!'
|
||||
});
|
||||
|
||||
// Get the data entered by the user
|
||||
const wgeAssignedUser = interaction.components[0].component.users.first();
|
||||
const wgeAssigningUser = interaction.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')
|
||||
|
||||
wgeColl.insertOne({
|
||||
"assignedUser": wgeAssignedUser.id,
|
||||
"assigningUser": wgeAssigningUser.id,
|
||||
"timeRemaining": wgeDefaultAssignedTime,
|
||||
"createdAt": new Date(),
|
||||
"topic": wgeAssignedTopic,
|
||||
"debug" :false
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user