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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user