added role reaction dynamic embed changes

This commit is contained in:
DeSqBlocki
2026-08-15 00:32:27 +02:00
parent 7c49e05aec
commit 832863c1e4
8 changed files with 986 additions and 311 deletions
+80 -51
View File
@@ -3,7 +3,8 @@ const {
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder
ActionRowBuilder,
MessageFlags
} = require("discord.js");
const { ObjectId } = require("mongodb");
@@ -20,6 +21,7 @@ const RAID_TYPES = [
"AllianceRaid"
];
const RAID_DIFFICULTIES = [
"Extreme",
"Unreal",
@@ -42,7 +44,9 @@ module.exports = {
.addStringOption(option =>
option
.setName("duty")
.setDescription("Select the duty you want to run.")
.setDescription(
"Select the duty you want to run."
)
.setRequired(true)
.setAutocomplete(true)
)
@@ -50,7 +54,9 @@ module.exports = {
async execute(interaction) {
switch (interaction.options.getSubcommand()) {
switch (
interaction.options.getSubcommand()
) {
case "plan":
return planRaid(interaction);
}
@@ -63,6 +69,10 @@ module.exports = {
};
/*
* AUTOCOMPLETE
*/
async function autocompleteDuty(interaction) {
const focused =
interaction.options.getFocused();
@@ -109,7 +119,21 @@ async function autocompleteDuty(interaction) {
}
/*
* /raid plan
*/
async function planRaid(interaction) {
if (!interaction.guild) {
return interaction.reply({
content:
"Raid planning can only be used inside a server.",
flags:
MessageFlags.Ephemeral
});
}
const dutyId =
interaction.options.getString(
"duty",
@@ -121,7 +145,8 @@ async function planRaid(interaction) {
return interaction.reply({
content:
"Please select a duty from the autocomplete results.",
ephemeral: true
flags:
MessageFlags.Ephemeral
});
}
@@ -131,42 +156,45 @@ async function planRaid(interaction) {
.collection(DUTY_COLLECTION);
const duty = await collection.findOne({
_id: new ObjectId(dutyId),
const duty =
await collection.findOne({
_id:
new ObjectId(dutyId),
Type: {
$in: RAID_TYPES
},
Type: {
$in: RAID_TYPES
},
Difficulty: {
$in: RAID_DIFFICULTIES
}
});
Difficulty: {
$in: RAID_DIFFICULTIES
}
});
if (!duty) {
return interaction.reply({
content:
"That duty could not be found or is not eligible for raid planning.",
ephemeral: true
flags:
MessageFlags.Ephemeral
});
}
/*
* The duty ObjectId is embedded in the modal customId.
*
* The modal handler can then retrieve the selected duty
* without trusting editable modal input.
*/
const modal =
buildRaidModal(duty);
return interaction.showModal(modal);
return interaction.showModal(
modal
);
}
/*
* MODAL
*/
function buildRaidModal(duty) {
const modal =
new ModalBuilder()
@@ -209,29 +237,16 @@ function buildRaidModal(duty) {
.setRequired(true);
/*
* Display only.
*
* We don't use this field to identify the duty.
* The ObjectId in the modal customId is authoritative.
*/
const dutyInput =
new TextInputBuilder()
.setCustomId("raid-duty")
.setLabel("Duty")
.setValue(duty.Name)
.setStyle(
TextInputStyle.Short
)
.setRequired(true);
const dateInput =
new TextInputBuilder()
.setCustomId("raid-date")
.setLabel("Date")
.setPlaceholder("DD-MM-YYYY")
.setStyle(TextInputStyle.Short)
.setPlaceholder(
"DD-MM-YYYY"
)
.setStyle(
TextInputStyle.Short
)
.setMinLength(10)
.setMaxLength(10)
.setRequired(true);
@@ -240,29 +255,39 @@ function buildRaidModal(duty) {
const timeInput =
new TextInputBuilder()
.setCustomId("raid-time")
.setLabel("Start - End (24h clock)")
.setPlaceholder("20:00 - 23:00")
.setStyle(TextInputStyle.Short)
.setMinLength(13)
.setMaxLength(13)
.setLabel(
"Start - End (24h clock)"
)
.setPlaceholder(
"20:00 - 23:00"
)
.setStyle(
TextInputStyle.Short
)
.setRequired(true);
modal.addComponents(
new ActionRowBuilder()
.addComponents(nameInput),
new ActionRowBuilder()
.addComponents(descriptionInput),
.addComponents(
nameInput
),
new ActionRowBuilder()
.addComponents(dutyInput),
.addComponents(
descriptionInput
),
new ActionRowBuilder()
.addComponents(dateInput),
.addComponents(
dateInput
),
new ActionRowBuilder()
.addComponents(timeInput)
.addComponents(
timeInput
)
);
@@ -270,6 +295,10 @@ function buildRaidModal(duty) {
}
/*
* HELPERS
*/
function buildAutocompleteName(duty) {
const label =
`${duty.Name} — ${formatDutyType(duty.Type)} / ${duty.Difficulty}`;