|
|
@ -36,7 +36,7 @@ client.once("ready", () => { |
|
|
|
"description": "Replies with a help message explaining what the bot can do" |
|
|
|
}, |
|
|
|
{ |
|
|
|
"name": "round", |
|
|
|
"name": "rounds", |
|
|
|
"options": [ |
|
|
|
{ |
|
|
|
"type": 1, |
|
|
@ -247,54 +247,6 @@ function sendHelpMessage(interaction) { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
async function generateRound(interaction) { |
|
|
|
const generatingMessage = interaction.reply("Generating..."); |
|
|
|
let i; |
|
|
|
let finalizedHTML = '<html><head><link rel="preconnect" href="https://fonts.gstatic.com"><link href="https://fonts.googleapis.com/css2?family=Ubuntu&display=swap" rel="stylesheet"> </head><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 tossup_question; |
|
|
|
let question_category; |
|
|
|
let tossup_format; |
|
|
|
let tossup_answer; |
|
|
|
let bonus_question; |
|
|
|
let bonus_format; |
|
|
|
let bonus_answer; |
|
|
|
let htmlContent = ""; |
|
|
|
await axios.post("https://scibowldb.com/api/questions", { categories: ["BIOLOGY", "PHYSICS", "CHEMISTRY", "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; |
|
|
|
} |
|
|
|
newGeneratedRound = new generatedRound({ |
|
|
|
htmlContent: finalizedHTML, |
|
|
|
requestedBy: interaction.author.id, |
|
|
|
authorTag: interaction.author.tag, |
|
|
|
timestamp: new Date().toISOString(), |
|
|
|
}); |
|
|
|
newGeneratedRound.save((err, round) => { |
|
|
|
if (err) { |
|
|
|
console.log(err); |
|
|
|
return; |
|
|
|
} |
|
|
|
interaction.channel.messages.fetch(generatingMessage.id) |
|
|
|
.then(generatingMessage => { |
|
|
|
const msg = generatingMessage.first(); |
|
|
|
msg.edit(`${message.author}, here's your round: https://api.adawesome.tech/round/${round._id.toString()}`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async function startScoring(message) { |
|
|
|
let scoreA = 0; |
|
|
|
let scoreB = 0; |
|
|
@ -412,7 +364,54 @@ function aboutMessage(message) { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
async function userRounds(interaction) { |
|
|
|
async function rounds(action, interaction) { |
|
|
|
if (action === "generate") { |
|
|
|
const generatingMessage = interaction.reply("Generating..."); |
|
|
|
let i; |
|
|
|
let finalizedHTML = '<html><head><link rel="preconnect" href="https://fonts.gstatic.com"><link href="https://fonts.googleapis.com/css2?family=Ubuntu&display=swap" rel="stylesheet"> </head><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 tossup_question; |
|
|
|
let question_category; |
|
|
|
let tossup_format; |
|
|
|
let tossup_answer; |
|
|
|
let bonus_question; |
|
|
|
let bonus_format; |
|
|
|
let bonus_answer; |
|
|
|
let htmlContent = ""; |
|
|
|
await axios.post("https://scibowldb.com/api/questions", { categories: ["BIOLOGY", "PHYSICS", "CHEMISTRY", "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; |
|
|
|
} |
|
|
|
newGeneratedRound = new generatedRound({ |
|
|
|
htmlContent: finalizedHTML, |
|
|
|
requestedBy: interaction.author.id, |
|
|
|
authorTag: interaction.author.tag, |
|
|
|
timestamp: new Date().toISOString(), |
|
|
|
}); |
|
|
|
newGeneratedRound.save((err, round) => { |
|
|
|
if (err) { |
|
|
|
console.log(err); |
|
|
|
return; |
|
|
|
} |
|
|
|
interaction.channel.messages.fetch(generatingMessage.id) |
|
|
|
.then(generatingMessage => { |
|
|
|
const msg = generatingMessage.first(); |
|
|
|
msg.edit(`${message.author}, here's your round: https://api.adawesome.tech/round/${round._id.toString()}`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if (action === "list"){ |
|
|
|
let rounds = await generatedRound.find({ requestedBy: interaction.user.id }).sort({ timestamp: -1 }); |
|
|
|
let finalMessage = ""; |
|
|
|
if (!rounds) { |
|
|
@ -434,7 +433,8 @@ async function userRounds(interaction) { |
|
|
|
.setDescription(finalMessage) |
|
|
|
.setTimestamp(); |
|
|
|
|
|
|
|
interaction.reply(roundsEmbed); |
|
|
|
interaction.reply(roundsEmbed, { ephemeral: true }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function hits(message) { |
|
|
@ -514,12 +514,9 @@ client.on("interaction", interaction => { |
|
|
|
case "train": |
|
|
|
training(interaction.options[0] ? interaction.options[0].value : null, interaction); |
|
|
|
break; |
|
|
|
case "round generate": |
|
|
|
case "rounds": |
|
|
|
generateRound(interaction); |
|
|
|
break; |
|
|
|
case "round list": |
|
|
|
userRounds(interaction); |
|
|
|
break; |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|