Skip to content

Commit

Permalink
Replace old candidates with tiebreaker candidates properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoopes16 committed Feb 5, 2021
1 parent c4d1b04 commit 19e9599
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion actions/declarevictor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ async function declareVictor(poll, message) {
if (winner.length > 1) {
message.channel.send(`There has been a tie between the following candidates: ${winner.map(cand => cand.answer).join(' :fire: ')}\nPlease vote again on the tiebreaker StrawPoll provided below!`)

poll.candidates = poll.candidates.filter(c => winner.some(w => w.answer.toLowerCase() === c.candidate.toLowerCase()))
const newCandidates = {}
for (const user in poll.candidates) {
if (Object.hasOwnProperty.call(poll.candidates, user) && winner.some(w => w.answer.toLowerCase() === poll.candidates[user].candidate.toLowerCase())) {
newCandidates[user] = poll.candidates[user]
}
}

poll.candidates = newCandidates

const response = await createStrawPoll(poll)
poll.strawPollId = response.data.content_id

Expand Down

0 comments on commit 19e9599

Please sign in to comment.