bug fix, can't vote on a closed poll
This commit is contained in:
parent
8fe4e73973
commit
49e52bf2dd
@ -108,6 +108,15 @@ async function findUserVoteForPoll(userId, pollId) {
|
|||||||
return response.rows[0];
|
return response.rows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isPollOpened(poll_id){
|
||||||
|
const response = await DATABASE_CLIENT.query(
|
||||||
|
"SELECT opened FROM poll WHERE poll_id=$1",
|
||||||
|
[poll_id]
|
||||||
|
);
|
||||||
|
return response.rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function findBetValueForUser(userId, guildId) {
|
async function findBetValueForUser(userId, guildId) {
|
||||||
const response = await DATABASE_CLIENT.query(
|
const response = await DATABASE_CLIENT.query(
|
||||||
"SELECT bet_value FROM member WHERE user_id=$1 AND member.guild_id=$2",
|
"SELECT bet_value FROM member WHERE user_id=$1 AND member.guild_id=$2",
|
||||||
@ -188,3 +197,4 @@ exports.addPointsToUser = addPointsToUser;
|
|||||||
exports.closePoll = closePoll;
|
exports.closePoll = closePoll;
|
||||||
exports.findUserPoints = findUserPoints;
|
exports.findUserPoints = findUserPoints;
|
||||||
exports.changeNextBetValueForUser = changeNextBetValueForUser;
|
exports.changeNextBetValueForUser = changeNextBetValueForUser;
|
||||||
|
exports.isPollOpened = isPollOpened;
|
21
src/main.js
21
src/main.js
@ -28,7 +28,7 @@ const {
|
|||||||
addPointsToUser,
|
addPointsToUser,
|
||||||
closePoll,
|
closePoll,
|
||||||
findUserPoints,
|
findUserPoints,
|
||||||
changeNextBetValueForUser
|
changeNextBetValueForUser, isPollOpened
|
||||||
} = require('./database');
|
} = require('./database');
|
||||||
const {TOKEN} = require('../config.json');
|
const {TOKEN} = require('../config.json');
|
||||||
const {v4: uuidv4} = require('uuid');
|
const {v4: uuidv4} = require('uuid');
|
||||||
@ -216,6 +216,22 @@ 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()) {
|
||||||
|
sendAppropriateMessageToUserWhenHeVotes(interaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
async function sendAppropriateMessageToUserWhenHeVotes(interaction) {
|
||||||
|
// interaction.customId.split("_")[0] c'est le pollId au cas où c'est pas assez clair mdr
|
||||||
|
const isConcernedPollOpened = await isPollOpened(interaction.customId.split("_")[0]);
|
||||||
|
if (!isConcernedPollOpened.opened) {
|
||||||
|
await interaction.reply({
|
||||||
|
flags: MessageFlags.Ephemeral,
|
||||||
|
content: `Ce sondage a déjà été cloturé !`
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
@ -230,9 +246,8 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
content: `${interaction.user.username}, tu as misé ${userBetValue} sur l'option **${interaction.customId.split("_")[1]}** ! 🎉`
|
content: `${interaction.user.username}, tu as misé ${userBetValue} sur l'option **${interaction.customId.split("_")[1]}** ! 🎉`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
async function createGuildAndUserIfNecessary(guildId, user) {
|
async function createGuildAndUserIfNecessary(guildId, user) {
|
||||||
if (!await guildExistsInDB(guildId)) {
|
if (!await guildExistsInDB(guildId)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user