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