bug fix, won't create poll if the question or one of the options contains the char '_'
This commit is contained in:
parent
ff5d95695e
commit
8fe4e73973
15
src/main.js
15
src/main.js
@ -181,14 +181,27 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
const buttons = new ActionRowBuilder();
|
||||
|
||||
let pollDesc = '';
|
||||
let areVoteOptionsAndQuestionValid = true;
|
||||
voteOptions.forEach((voteOption, index) => {
|
||||
// Le caractère "_" peut littéralement tout casser dans ma manière de stocker la donnée
|
||||
if (!(voteOption.includes("_") || pollQuestionObj.value.includes("_"))) {
|
||||
buttons.addComponents(new ButtonBuilder()
|
||||
.setCustomId(`${interaction.customId}_${voteOption}_${index + 1}`)
|
||||
.setLabel(voteOption)
|
||||
.setStyle(ButtonStyle.Primary));
|
||||
pollDesc += `Option ${index + 1}: ${voteOption}\n`
|
||||
} else {
|
||||
areVoteOptionsAndQuestionValid = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!areVoteOptionsAndQuestionValid) {
|
||||
await interaction.reply({
|
||||
flags: MessageFlags.Ephemeral,
|
||||
content: `Une des options/question entrée est invalide (caractère "_" interdit !)`
|
||||
});
|
||||
} else {
|
||||
|
||||
const pollEmbed = new EmbedBuilder()
|
||||
.setTitle(`Sondage: ${pollQuestionObj.value}`)
|
||||
.setDescription(pollDesc)
|
||||
@ -201,6 +214,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
}
|
||||
|
||||
await interaction.reply({embeds: [introEmbed, pollEmbed], components: [buttons]});
|
||||
}
|
||||
} else if (interaction.isMessageComponent()) {
|
||||
const userVote = await findUserVoteForPoll(interaction.user.id, interaction.customId.split("_")[0])
|
||||
if (userVote) {
|
||||
@ -217,6 +231,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
async function createGuildAndUserIfNecessary(guildId, user) {
|
||||
|
Loading…
Reference in New Issue
Block a user