const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const axios = require('axios');
const { log } = require('../helpers/log');
const generatedRound = require('../models/generateRound');
module.exports = {
data: new SlashCommandBuilder()
.setName('rounds')
.setDescription('Commands regarding the generation of rounds')
.addSubcommand(subcommand => {
subcommand
.setName('generate')
.setDescription('Generates a round with randomized questions from https://scibowldb.com/');
return subcommand;
})
.addSubcommand(subcommand => {
subcommand
.setName('list')
.setDescription('Lists your 5 most recently generated rounds with links');
return subcommand;
})
.addSubcommand(subcommand => {
subcommand
.setName('hit')
.setDescription('Shows the total number of rounds hit as well as the number for the specific user');
return subcommand;
}),
async execute(interaction) {
const action = interaction.options.getSubcommand();
if (action === 'generate') {
let i;
let finalizedHTML = '
ROUND GENERATED BY AWESOMESCIBO USING THE SCIBOWLDB API
';
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++) {
const 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 = '