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,26 +181,40 @@ client.on(Events.InteractionCreate, async interaction => {
const buttons = new ActionRowBuilder();
let pollDesc = '';
let areVoteOptionsAndQuestionValid = true;
voteOptions.forEach((voteOption, index) => {
buttons.addComponents(new ButtonBuilder()
.setCustomId(`${interaction.customId}_${voteOption}_${index + 1}`)
.setLabel(voteOption)
.setStyle(ButtonStyle.Primary));
pollDesc += `Option ${index + 1}: ${voteOption}\n`
// 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;
}
});
const pollEmbed = new EmbedBuilder()
.setTitle(`Sondage: ${pollQuestionObj.value}`)
.setDescription(pollDesc)
.setColor(Colors.Green)
.setFooter({text: 'https://guams.fr', iconURL: 'https://guams.fr/icon.webp'});
if (!areVoteOptionsAndQuestionValid) {
await interaction.reply({
flags: MessageFlags.Ephemeral,
content: `Une des options/question entrée est invalide (caractère "_" interdit !)`
});
} else {
await insertPollIntoDB(sender.id, interaction.customId, guildFromWhereUserSendedInteraction.id, pollQuestionObj.value);
for (let i = 0; i < voteOptions.length; i++) {
await insertVoteOptions(interaction.customId, `${interaction.customId}_${voteOptions[i]}_${i + 1}`, voteOptions[i]);
const pollEmbed = new EmbedBuilder()
.setTitle(`Sondage: ${pollQuestionObj.value}`)
.setDescription(pollDesc)
.setColor(Colors.Green)
.setFooter({text: 'https://guams.fr', iconURL: 'https://guams.fr/icon.webp'});
await insertPollIntoDB(sender.id, interaction.customId, guildFromWhereUserSendedInteraction.id, pollQuestionObj.value);
for (let i = 0; i < voteOptions.length; i++) {
await insertVoteOptions(interaction.customId, `${interaction.customId}_${voteOptions[i]}_${i + 1}`, voteOptions[i]);
}
await interaction.reply({embeds: [introEmbed, pollEmbed], components: [buttons]});
}
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) {