bug fix, won't create poll if the question or one of the options contains the char '_'

This commit is contained in:
guams 2025-07-05 10:21:40 +02:00
parent ff5d95695e
commit 8fe4e73973

View File

@ -181,14 +181,27 @@ client.on(Events.InteractionCreate, async interaction => {
const buttons = new ActionRowBuilder(); const buttons = new ActionRowBuilder();
let pollDesc = ''; let pollDesc = '';
let areVoteOptionsAndQuestionValid = true;
voteOptions.forEach((voteOption, index) => { 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() buttons.addComponents(new ButtonBuilder()
.setCustomId(`${interaction.customId}_${voteOption}_${index + 1}`) .setCustomId(`${interaction.customId}_${voteOption}_${index + 1}`)
.setLabel(voteOption) .setLabel(voteOption)
.setStyle(ButtonStyle.Primary)); .setStyle(ButtonStyle.Primary));
pollDesc += `Option ${index + 1}: ${voteOption}\n` 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() const pollEmbed = new EmbedBuilder()
.setTitle(`Sondage: ${pollQuestionObj.value}`) .setTitle(`Sondage: ${pollQuestionObj.value}`)
.setDescription(pollDesc) .setDescription(pollDesc)
@ -201,6 +214,7 @@ client.on(Events.InteractionCreate, async interaction => {
} }
await interaction.reply({embeds: [introEmbed, pollEmbed], components: [buttons]}); await interaction.reply({embeds: [introEmbed, pollEmbed], components: [buttons]});
}
} else if (interaction.isMessageComponent()) { } else if (interaction.isMessageComponent()) {
const userVote = await findUserVoteForPoll(interaction.user.id, interaction.customId.split("_")[0]) const userVote = await findUserVoteForPoll(interaction.user.id, interaction.customId.split("_")[0])
if (userVote) { if (userVote) {
@ -217,6 +231,7 @@ client.on(Events.InteractionCreate, async interaction => {
}); });
} }
} }
}); });
async function createGuildAndUserIfNecessary(guildId, user) { async function createGuildAndUserIfNecessary(guildId, user) {