Skip to content

Commit

Permalink
Fix: invalid results
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetfulskybro committed Oct 1, 2023
1 parent ba22875 commit a52a573
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/buttons/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = {
const customId = interaction.customId.split("_");

const votingResults = await client.voting.getVotingResults(customId[1]);
if (!votingResults) return await interaction.reply({
content: "Unable to fetch results.",
ephemeral: true,
})


const resultEmbed = new EmbedBuilder()
.setImage(votingResults.chart)
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@
"Yes": "Yes",
"No": "No",
"Vote": "Vote: ",
"VotingResults": "Voting Results"
"VotingResults": "Voting Results",
"VotingResultsError": "Unable to fetch results."
},
"HigherLower": {
"description": "Do you think that **{keyword}** has higher or lower searches than **{history}**?\n\n Image source: **[Image 1]({source})** | **[Image 2]({source2})**",
Expand Down
11 changes: 8 additions & 3 deletions src/util/votingHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ module.exports = class Voting {
};
}

getVoting(id) {
async getVoting(id) {
if (!this._cache.get(id))
return await voteSchema.findOne({
id: id
});

return this._cache.get(id);
}

Expand All @@ -115,7 +120,7 @@ module.exports = class Voting {
}

async addVote(id, userId, option = 1) {
const vote = this.getVoting(id);
const vote = await this.getVoting(id);
if (!vote) return false;

const options = ["op_one", "op_two"];
Expand All @@ -133,7 +138,7 @@ module.exports = class Voting {
}

async getVotingResults(id) {
const vote = this.getVoting(id);
const vote = await this.getVoting(id);
if (!vote) return false;

let g;
Expand Down

0 comments on commit a52a573

Please sign in to comment.