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...");
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>';
for (i = 1; i < 26; i++) {
let tossup_question;
let question_category;
let tossup_format;
@ -317,21 +316,22 @@ async function generateRound(message) {
let bonus_format;
let bonus_answer;
let htmlContent = "";
await fetch("https://scibowldb.com/api/questions/random")
.then((response) => response.json())
.then((data) => {
tossup_question = data.question.tossup_question;
tossup_answer = data.question.tossup_answer;
question_category = data.question.category;
tossup_format = data.question.tossup_format;
bonus_question = data.question.bonus_question;
bonus_answer = data.question.bonus_answer;
bonus_format = data.question.bonus_format;
await axios.post("https://scibowldb.com/api/questions", { categories: ["BIOLOGY", "PHYSICS", "EARTH AND SPACE", "ASTRONOMY", "MATH"] })
.then((response) => {
for (i = 1; i < 26; i++) {
data = response.data.questions[Math.floor(Math.random() * response.data.questions.length)];
tossup_question = data.tossup_question;
tossup_answer = data.tossup_answer;
question_category = data.category;
tossup_format = data.tossup_format;
bonus_question = data.bonus_question;
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>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>");
finalizedHTML += htmlContent;
if (i === 25) {
}
newGeneratedRound = new generatedRound({
htmlContent: finalizedHTML,
requestedBy: message.author.id,
@ -350,9 +350,6 @@ async function generateRound(message) {
});
});
}
});
}
}
async function startScoring(message) {
let scoreA = 0;

1519
bot/package-lock.json

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