Make the webhook settings be respected by the code

This commit is contained in:
Oliver Akins 2022-01-11 16:35:32 -06:00
parent 4a21672a83
commit 7057c6aab9
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99

View file

@ -1,4 +1,5 @@
import axios from "axios";
import { config } from "../main";
import {
change_index,
commands,
@ -36,29 +37,31 @@ function next_command(_: string[]) {
reset_users();
axios.post(
`https://ptb.discord.com/api/webhooks/916068083863539782/9k2b66SUIeY8hl5id7gdnZF6Abc8Fb1f5-RVlgbUJqirNmALkrrgrCWdsufcZ5Bn2a4i`,
if (config.discord.webhook.enabled) {
axios.post(
config.discord.webhook.url,
{
content: correct_users.length > 0 ? `Users who got question ${question_index + 1} right:
\`\`\`
${correct_users.join(", ")}
\`\`\`` : `No one got question ${question_index + 1} right.`
}
)
// Check if the quiz has hit the end
if (question_index == questions.length - 1) {
// Send message in Discord for record-keeping
axios.post(
`https://ptb.discord.com/api/webhooks/916068083863539782/9k2b66SUIeY8hl5id7gdnZF6Abc8Fb1f5-RVlgbUJqirNmALkrrgrCWdsufcZ5Bn2a4i`,
{
content: `\`\`\`json\n${JSON.stringify(user_right_count, null, "\t")}\`\`\``
}
);
change_index(-1);
return `${users_correct} players got the last question right. Quiz has ended. Kthxbai.`;
// Check if the quiz has hit the end
if (question_index == questions.length - 1) {
// Send message in Discord for record-keeping
axios.post(
config.discord.webhook.url,
{
content: `\`\`\`json\n${JSON.stringify(user_right_count, null, "\t")}\`\`\``
}
);
change_index(-1);
return `${users_correct} players got the last question right. Quiz has ended. Kthxbai.`;
};
};
change_index(question_index + 1);