Browse Source

Send one request and locally find random instead of sending 25 requests

pull/9/head
Abheek Dhawan 4 years ago
parent
commit
dc47011945
  1. 27
      bot/awesomescibo.js
  2. 1519
      bot/package-lock.json

27
bot/awesomescibo.js

@ -308,7 +308,6 @@ async function generateRound(message) {
const generatingMessage = message.channel.send("Generating..."); const generatingMessage = message.channel.send("Generating...");
let i; let i;
let finalizedHTML = '<html><body style="width: 70%; margin-left: auto; margin-right: auto;"><h2 style="text-align: center; text-decoration: underline overline; padding: 7px;">ROUND GENERATED BY AWESOMESCIBO USING THE SCIBOWLDB API</h2>'; let finalizedHTML = '<html><body style="width: 70%; margin-left: auto; margin-right: auto;"><h2 style="text-align: center; text-decoration: underline overline; padding: 7px;">ROUND GENERATED BY AWESOMESCIBO USING THE SCIBOWLDB API</h2>';
for (i = 1; i < 26; i++) {
let tossup_question; let tossup_question;
let question_category; let question_category;
let tossup_format; let tossup_format;
@ -317,21 +316,22 @@ async function generateRound(message) {
let bonus_format; let bonus_format;
let bonus_answer; let bonus_answer;
let htmlContent = ""; let htmlContent = "";
await fetch("https://scibowldb.com/api/questions/random") await axios.post("https://scibowldb.com/api/questions", { categories: ["BIOLOGY", "PHYSICS", "EARTH AND SPACE", "ASTRONOMY", "MATH"] })
.then((response) => response.json()) .then((response) => {
.then((data) => { for (i = 1; i < 26; i++) {
tossup_question = data.question.tossup_question; data = response.data.questions[Math.floor(Math.random() * response.data.questions.length)];
tossup_answer = data.question.tossup_answer; tossup_question = data.tossup_question;
question_category = data.question.category; tossup_answer = data.tossup_answer;
tossup_format = data.question.tossup_format; question_category = data.category;
bonus_question = data.question.bonus_question; tossup_format = data.tossup_format;
bonus_answer = data.question.bonus_answer; bonus_question = data.bonus_question;
bonus_format = data.question.bonus_format; bonus_answer = data.bonus_answer;
bonus_format = data.bonus_format;
htmlContent = `<br><br><h3 style="text-align: center;"><strong>TOSS-UP</strong></h3>\n<br>` + `${i}) <strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br>"; htmlContent = `<br><br><h3 style="text-align: center;"><strong>TOSS-UP</strong></h3>\n<br>` + `${i}) <strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br>";
htmlContent += `<br><br><h3 style="text-align: center;"><strong>BONUS</strong></h3>\n<br>` + `${i}) <strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br><hr><br>"; htmlContent += `<br><br><h3 style="text-align: center;"><strong>BONUS</strong></h3>\n<br>` + `${i}) <strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br><hr><br>";
htmlContent = htmlContent.replace(/\n/g, "<br>"); htmlContent = htmlContent.replace(/\n/g, "<br>");
finalizedHTML += htmlContent; finalizedHTML += htmlContent;
if (i === 25) { }
newGeneratedRound = new generatedRound({ newGeneratedRound = new generatedRound({
htmlContent: finalizedHTML, htmlContent: finalizedHTML,
requestedBy: message.author.id, requestedBy: message.author.id,
@ -350,9 +350,6 @@ async function generateRound(message) {
}); });
}); });
} }
});
}
}
async function startScoring(message) { async function startScoring(message) {
let scoreA = 0; let scoreA = 0;

1519
bot/package-lock.json

File diff suppressed because it is too large
Loading…
Cancel
Save