You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
const axios = require('axios');
|
|
const { MessageEmbed } = require('discord.js');
|
|
const decode = require('html-entities').decode;
|
|
|
|
const { testingGuild } = require('../helpers/env');
|
|
module.exports = {
|
|
name: 'messageCreate',
|
|
once: false,
|
|
async execute(message) {
|
|
if (message.author.bot || message.guild.id != testingGuild) return;
|
|
|
|
if (message.content.startsWith('!q')) {
|
|
const questionId = message.content.split(' ')[1];
|
|
axios
|
|
.get(`https://scibowldb.com/api/questions/${questionId}`)
|
|
.then((res) => {
|
|
const data = res.data.question;
|
|
const tossupQuestion = data.tossup_question;
|
|
const tossupAnswer = data.tossup_answer;
|
|
let answers = tossupAnswer.split(' (ACCEPT: ');
|
|
if (answers.length > 1) {
|
|
answers[1] = answers[1].slice(0, answers[1].length - 1); // If there are multiple elements, it means there was an 'accept' and therefore a trailing ')' which should be removed
|
|
answers = [answers[0], ...answers[1].split(new RegExp(' OR ', 'i'))]; // Use the first element plus the last element split by 'OR' case insensitive
|
|
}
|
|
const dataEmbed = new MessageEmbed()
|
|
.setTitle('Data')
|
|
.setDescription(`\`\`\`json\n${JSON.stringify(data, null, 2)}\`\`\``);
|
|
message.reply({
|
|
content: decode(tossupQuestion) + `\n\nAnswers: [${answers}]`,
|
|
embeds: [dataEmbed],
|
|
});
|
|
});
|
|
}
|
|
},
|
|
};
|
|
|