Browse Source

Clean up rounds.ts and add types

pull/41/head
Abheek Dhawan 3 years ago
parent
commit
6b64b967ff
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 48
      src/commands/rounds.ts

48
src/commands/rounds.ts

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { MessageEmbed } from 'discord.js';
import { MessageEmbed, CommandInteraction } from 'discord.js';
import axios from 'axios';
@ -28,24 +28,24 @@ export const data = new SlashCommandBuilder()
return subcommand;
});
export async function execute(interaction) {
await interaction.deferReply();
export async function execute(interaction : CommandInteraction) {
const action = interaction.options.getSubcommand();
if (action === 'generate') {
let i;
switch (action) {
case 'generate': {
interaction.deferReply({ ephemeral: true });
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 tossup_question : string;
let question_category : string;
let tossup_format : string;
let tossup_answer : string;
let bonus_question : string;
let bonus_format : string;
let bonus_answer : string;
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++) {
for (let i = 1; i < 26; i++) {
const questionData = response.data.questions[Math.floor(Math.random() * response.data.questions.length)];
tossup_question = questionData.tossup_question;
tossup_answer = questionData.tossup_answer;
@ -72,15 +72,19 @@ export async function execute(interaction) {
log({ logger: 'rounds', content: `Saving round to DB failed: ${err}`, level: 'error' });
return;
}
interaction.followUp(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true });
interaction.followUp({ content: `Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, ephemeral: true });
});
});
break;
}
else if (action === 'list') {
case 'list': {
interaction.deferReply({ ephemeral: true });
let roundsList = await generatedRound.find({ requestedBy: interaction.user.id }).sort({ timestamp: -1 });
let finalMessage = '';
if (!roundsList) {
interaction.followUp('You haven\'t requested any roundsList!');
interaction.followUp('You haven\'t requested any rounds!');
return;
}
@ -94,7 +98,7 @@ export async function execute(interaction) {
const roundsListEmbed = new MessageEmbed()
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setTitle('Last 5 Rounds Requested')
.setTitle('Last 5 rounds requested')
.setDescription(finalMessage)
.setTimestamp();
@ -102,11 +106,17 @@ export async function execute(interaction) {
embeds: [roundsListEmbed],
ephemeral: true,
});
break;
}
else if (action === 'hit') {
case 'hit': {
await interaction.deferReply();
const totalCount = await generatedRound.countDocuments({});
const userCount = await generatedRound.countDocuments({ requestedBy: interaction.user.id });
interaction.followUp(`Total Hits: ${totalCount}\nYour Hits: ${userCount}`);
break;
}
}
}
Loading…
Cancel
Save