Browse Source

Update code to match new discord.js version and remove ISS

pull/12/head
Abheek Dhawan 3 years ago
parent
commit
9d4a3012a0
  1. 55
      bot/awesomescibo.js

55
bot/awesomescibo.js

@ -115,10 +115,6 @@ const slashCommands = [
} }
], ],
"description": "Commands regarding the creation/development of the bot" "description": "Commands regarding the creation/development of the bot"
},
{
"name": "iss",
"description": "Shows the location of the ISS on a map as well as all of the current astronauts within it"
} }
] ]
@ -258,21 +254,20 @@ async function training(subject, interaction) {
return; return;
} }
console.log(categoryArray);
axios axios
.post("https://scibowldb.com/api/questions/random", { categories: categoryArray }) .post("https://scibowldb.com/api/questions/random", { categories: categoryArray })
.then((res) => { .then((res) => {
data = res.data.question; data = res.data.question;
console.log(`${interaction.user.tag} -- ${data.tossup_question} -- ${data.tossup_answer}\n`); console.log(`${interaction.user.tag} -- ${data.tossup_question} -- ${data.tossup_answer}\n`);
const messageFilter = (m) => m.author.id === authorId; const messageFilter = (m) => m.author.id === authorId;
interaction.reply({ content: data.tossup_question + `\n\n||Source: ${data.uri}||` }).then(() => { interaction.reply({ content: data.tossup_question + `\n\n||Source: ${data.uri}||` })
interaction.channel.awaitMessages(messageFilter, { .then(() => {
max: 1, interaction.channel.awaitMessages({
time: 120000, messageFilter,
errors: ["time"], max: 1
}) })
.then((answerMsg) => { .then(collected => {
answerMsg = answerMsg.first(); answerMsg = collected.first();
let predicted = null; let predicted = null;
if (data.tossup_format === "Multiple Choice") { if (data.tossup_format === "Multiple Choice") {
@ -306,9 +301,9 @@ async function training(subject, interaction) {
.setDescription(`It seems your answer was incorrect. Please react with <:override:842778128966615060> to override your answer if you think you got it right.`) .setDescription(`It seems your answer was incorrect. Please react with <:override:842778128966615060> to override your answer if you think you got it right.`)
.setColor("#ffffff") .setColor("#ffffff")
.setTimestamp(); .setTimestamp();
const overrideMsg = answerMsg.channel.send( const overrideMsg = answerMsg.channel.send({
overrideEmbed embeds: [overrideEmbed]
) })
.then(overrideMsg => { .then(overrideMsg => {
overrideMsg.react("<:override:842778128966615060>"); overrideMsg.react("<:override:842778128966615060>");
const filter = (reaction, user) => { const filter = (reaction, user) => {
@ -318,8 +313,9 @@ async function training(subject, interaction) {
); );
}; };
overrideMsg overrideMsg
.awaitReactions(filter, { .awaitReactions({
max: 1, filter,
max: 1
}) })
.then((userReaction) => { .then((userReaction) => {
updateScore(true, score, authorId).then((msgToReply) => updateScore(true, score, authorId).then((msgToReply) =>
@ -328,14 +324,14 @@ async function training(subject, interaction) {
}).catch(console.error); }).catch(console.error);
}).catch(console.error); }).catch(console.error);
} }
}).catch(error => { if (error) interaction.editReply("Sorry, the question timed out waiting for an answer.") }); }).catch(console.error);
}).catch(console.error); }).catch(console.error);
}).catch(console.error); }).catch(console.error);
} }
function sendHelpMessage(interaction) { function sendHelpMessage(interaction) {
const helpEmbed = new Discord.MessageEmbed().setDescription(helpMessage).setColor("ffffff"); const helpEmbed = new Discord.MessageEmbed().setDescription(helpMessage).setColor("ffffff");
interaction.reply(helpEmbed); interaction.reply({ embeds: [helpEmbed] });
} }
async function startScoring(message) { async function startScoring(message) {
@ -403,22 +399,6 @@ function showServerNumber(message) {
message.channel.send(client.guilds.cache.size); message.channel.send(client.guilds.cache.size);
} }
async function showIssLocation(interaction) {
await fetch("http://api.open-notify.org/iss-now.json")
.then((request) => request.json())
.then((data) => {
interaction.reply(
new Discord.MessageEmbed()
.setTitle("The current location of the ISS!")
.setImage(
`https://api.mapbox.com/styles/v1/mapbox/light-v10/static/pin-s+000(${data.iss_position.longitude},${data.iss_position.latitude})/-87.0186,20,1/1000x1000?access_token=pk.eyJ1IjoiYWRhd2Vzb21lZ3V5IiwiYSI6ImNrbGpuaWdrYzJ0bGYydXBja2xsNmd2YTcifQ.Ude0UFOf9lFcQ-3BANWY5A`
)
.setURL("https://spotthestation.nasa.gov/tracking_map.cfm")
.setColor("#ffffff")
);
}).catch(error => { if (error) interaction.editReply("Unable to fetch data. Please try again!") });
}
function showLeaderboard(interaction) { function showLeaderboard(interaction) {
let messageContent = ""; let messageContent = "";
userScore userScore
@ -568,7 +548,7 @@ async function rounds(action, interaction) {
} }
} }
client.on("interaction", async interaction => { client.on("interactionCreate", async interaction => {
// If the interaction isn't a slash command, return // If the interaction isn't a slash command, return
if (!interaction.isCommand()) return; if (!interaction.isCommand()) return;
@ -588,9 +568,6 @@ client.on("interaction", async interaction => {
case "about": case "about":
about(interaction.options[0].name, interaction); about(interaction.options[0].name, interaction);
break; break;
case "iss":
showIssLocation(interaction);
break;
} }
}) })

Loading…
Cancel
Save