From 11102fc3a553f243d9770e8404fab161b98c9e53 Mon Sep 17 00:00:00 2001 From: admin_rb Date: Mon, 8 Jun 2026 20:57:52 +0200 Subject: [PATCH] WGE Implementation Basics --- commands/slash/applications/wge.js | 178 +++++++++++++++++++++++++++++ events/InteractionCreate.js | 33 +++++- 2 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 commands/slash/applications/wge.js diff --git a/commands/slash/applications/wge.js b/commands/slash/applications/wge.js new file mode 100644 index 0000000..eb0e44a --- /dev/null +++ b/commands/slash/applications/wge.js @@ -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 .\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; + } + } +} \ No newline at end of file diff --git a/events/InteractionCreate.js b/events/InteractionCreate.js index df209c8..9864f9e 100644 --- a/events/InteractionCreate.js +++ b/events/InteractionCreate.js @@ -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) { @@ -55,4 +56,30 @@ async function selectMenuHandler(interaction) { await interaction.reply({ content: 'There was an error while executing this command!', flags: MessageFlags.Ephemeral }); } } +} +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 + }) + } } \ No newline at end of file