Skip to content

Commit 4b557d8

Browse files
committed
trivia
1 parent 4ac9469 commit 4b557d8

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

commands/trivia.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,23 @@ async function play(message, bot, send, trivia) {
7777
let {
7878
question,
7979
correct_answer,
80+
incorrect_answers,
8081
difficulty,
8182
category,
8283
worth
8384
} = trivia
8485
correct_answer = h2p(correct_answer)
85-
86+
incorrect_answers = incorrect_answers.map(s => h2p(s));
87+
incorrect_answers.push(correct_answer);
88+
incorrect_answers = shuffle(incorrect_answers);
8689
let embed = new bot.embed()
8790
embed.title = "`Trivia`"
8891
embed.addField("Question", h2p(question))
8992
.addField("Category", category)
9093
.addField("Difficulty", difficulty)
9194
.addField("Reward", worth + ":dollar:")
92-
.setFooter("You have 30 seconds to answer.")
95+
.addField("Choices", "**" + incorrect_answers.join(", ") + "**")
96+
.setFooter("You have 10 seconds to answer.")
9397
.setColor("#4DD0D9")
9498
.setAuthor(message.guild.name, message.guild.iconURL)
9599

@@ -102,17 +106,22 @@ async function play(message, bot, send, trivia) {
102106
if (checkAnswer(correct_answer, m.content)) {
103107
collector.stop("WINNED")
104108
win(bot, message, m.author, worth)
109+
} else {
110+
collector.stop("wrong");
105111
}
106112
return false
107113
}, {
108-
time: 30000
114+
time: 10000
109115
})
110116

111117
collector.on("end", (c, reason) => {
112118
delete cur[message.channel.id]
113119
if (reason === "time") {
114120
return send("**Noone guessed in time, the correct answer was: " + correct_answer + "**");
115121
}
122+
if (reason === "wrong") {
123+
return send("**Wrong! The correct answer was: " + correct_answer + "**");
124+
}
116125
})
117126
}
118127

@@ -122,6 +131,19 @@ function win(bot, message, user, worth) {
122131
bot.profile.addMoney(user.id, worth);
123132
}
124133

134+
function shuffle (array) {
135+
var i = 0
136+
, j = 0
137+
, temp = null
138+
139+
for (i = array.length - 1; i > 0; i -= 1) {
140+
j = Math.floor(Math.random() * (i + 1))
141+
temp = array[i]
142+
array[i] = array[j]
143+
array[j] = temp
144+
}
145+
}
146+
125147
function checkAnswer(correct, input) {
126148
let c = correct.toLowerCase()
127149
let i = input.toLowerCase()

0 commit comments

Comments
 (0)