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.
581 lines
19 KiB
581 lines
19 KiB
4 years ago
|
#!/usr/bin/env node
|
||
|
|
||
4 years ago
|
const Discord = require("discord.js");
|
||
4 years ago
|
const Intents = Discord.Intents;
|
||
4 years ago
|
const client = new Discord.Client({
|
||
4 years ago
|
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS"/*, "GUILD_MEMBERS", "GUILD_PRESENCES"*/],
|
||
4 years ago
|
partials: ["MESSAGE", "CHANNEL", "REACTION"],
|
||
|
});
|
||
4 years ago
|
const fetch = require("node-fetch");
|
||
|
const axios = require("axios");
|
||
|
const userScore = require("./mongooseModels/mongooseUserScoreModel.js");
|
||
4 years ago
|
const generatedRound = require("./mongooseModels/mongooseGeneratedRoundModel.js");
|
||
4 years ago
|
const mongoose = require("mongoose");
|
||
4 years ago
|
const gitlog = require("gitlog").default;
|
||
3 years ago
|
const config = require("./config.json");
|
||
4 years ago
|
|
||
4 years ago
|
const helpMessage = "AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon."
|
||
4 years ago
|
|
||
4 years ago
|
const slashCommands = [
|
||
|
{
|
||
|
"name": "train",
|
||
|
"description": "Sends a single training question to be answered",
|
||
|
"options": [
|
||
|
{
|
||
|
"type": 3,
|
||
|
"name": "subject",
|
||
|
"description": "Optional subject to be used as a filter",
|
||
|
"default": false,
|
||
3 years ago
|
"required": false,
|
||
|
"choices": [
|
||
|
{
|
||
|
"name": "astro",
|
||
|
"value": "astro",
|
||
|
},
|
||
|
{
|
||
|
"name": "bio",
|
||
|
"value": "bio",
|
||
|
},
|
||
|
{
|
||
|
"name": "ess",
|
||
|
"value": "ess",
|
||
|
},
|
||
|
{
|
||
|
"name": "chem",
|
||
|
"value": "chem",
|
||
|
},
|
||
|
{
|
||
|
"name": "phys",
|
||
|
"value": "phys",
|
||
|
},
|
||
|
{
|
||
|
"name": "math",
|
||
|
"value": "math",
|
||
|
},
|
||
|
{
|
||
|
"name": "energy",
|
||
|
"value": "energy",
|
||
|
}
|
||
|
]
|
||
4 years ago
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "help",
|
||
|
"description": "Replies with a help message explaining what the bot can do"
|
||
|
},
|
||
|
{
|
||
|
"name": "rounds",
|
||
|
"options": [
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "generate",
|
||
|
"description": "Generates a round with randomized questions from https://scibowldb.com/",
|
||
|
"options": []
|
||
|
},
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "list",
|
||
|
"description": "Lists your 5 most recently generated rounds with links",
|
||
|
"options": []
|
||
|
},
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "hit",
|
||
|
"description": "Shows the total number of rounds hit as well as the number for the specific user",
|
||
|
"options": []
|
||
|
}
|
||
|
],
|
||
|
"description": "Commands regarding rounds generated by AwesomeSciBo"
|
||
|
},
|
||
|
{
|
||
|
"name": "top",
|
||
|
"description": "Lists top ten scores across servers (server specific leaderboard WIP)"
|
||
|
},
|
||
|
{
|
||
|
"name": "about",
|
||
|
"options": [
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "contributors",
|
||
|
"description": "Lists contributors to the AwesomeSciBo bot",
|
||
|
"options": []
|
||
|
},
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "changelog",
|
||
|
"description": "Lists the 5 most recent changes in a \"git log\" type format",
|
||
|
"options": []
|
||
|
},
|
||
|
{
|
||
|
"type": 1,
|
||
|
"name": "bot",
|
||
|
"description": "Lists information about AwesomeSciBo",
|
||
|
"options": []
|
||
|
}
|
||
|
],
|
||
|
"description": "Commands regarding the creation/development of the bot"
|
||
|
}
|
||
|
]
|
||
|
|
||
4 years ago
|
client.once("ready", () => {
|
||
4 years ago
|
client.application.commands.set(slashCommands);
|
||
4 years ago
|
|
||
4 years ago
|
// Connect to MongoDB using mongoose
|
||
4 years ago
|
if (!process.env.CI) {
|
||
|
mongoose
|
||
|
.connect(process.env.MONGO_URI, {
|
||
|
useUnifiedTopology: true,
|
||
|
useNewUrlParser: true,
|
||
|
})
|
||
|
.then(() => {
|
||
|
// Log client tag and set status
|
||
|
console.log(`Logged in as: ${client.user.username}!`);
|
||
|
client.user.setActivity(
|
||
3 years ago
|
'for /help | Add me to your own server: adat.link/awscibo',
|
||
4 years ago
|
{ type: "WATCHING" }
|
||
|
);
|
||
|
})
|
||
|
.catch((err) => console.log(err));
|
||
|
}
|
||
4 years ago
|
});
|
||
|
|
||
4 years ago
|
client.on("guildCreate", (guild) => {
|
||
3 years ago
|
const topggAuthHeader = {
|
||
|
headers: {
|
||
|
'Authorization': config.topggauth
|
||
|
}
|
||
|
};
|
||
3 years ago
|
axios.post(`https://top.gg/api/bots/${client.user.id}/stats`, { server_count: client.guilds.cache.size }, topggAuthHeader).then(response => { console.log(response); })
|
||
4 years ago
|
//guild.commands.set(slashCommands);
|
||
4 years ago
|
const welcomeChannel = guild.channels.cache
|
||
4 years ago
|
.find(
|
||
|
(channel) =>
|
||
4 years ago
|
// Find channel by name
|
||
4 years ago
|
channel.name === "general" && channel.type === "text"
|
||
4 years ago
|
)
|
||
4 years ago
|
if (welcomeChannel) {
|
||
4 years ago
|
welcomeChannel.send("'Sup, I'm the AwesomeSciBo bot! Use `/help` to learn more about me!")
|
||
4 years ago
|
.catch(console.error);
|
||
|
}
|
||
4 years ago
|
});
|
||
|
|
||
3 years ago
|
client.on("guildDelete", guild => {
|
||
|
const topggAuthHeader = {
|
||
|
headers: {
|
||
|
'Authorization': config.topggauth
|
||
|
}
|
||
|
};
|
||
|
axios.post(`https://top.gg/api/bots/${client.user.id}/stats`, { server_count: client.guilds.cache.size }, topggAuthHeader);
|
||
|
});
|
||
|
|
||
4 years ago
|
async function updateScore(isCorrect, score, authorId) {
|
||
|
if (!isCorrect) {
|
||
4 years ago
|
return `Nice try! Your score is still ${score}.`;
|
||
4 years ago
|
} else {
|
||
|
score += 4;
|
||
|
if (score == 4) {
|
||
|
const newUserScore = new userScore({
|
||
|
authorID: authorId,
|
||
|
score: score,
|
||
|
});
|
||
|
newUserScore.save((err) =>
|
||
|
err
|
||
|
? console.log("Error creating new user for scoring")
|
||
|
: console.log("Sucessfully created user to score.")
|
||
|
);
|
||
|
} else {
|
||
|
const doc = await userScore.findOne({
|
||
|
authorID: authorId,
|
||
|
});
|
||
|
doc.score = doc.score + 4;
|
||
|
doc.save();
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
return `Great job! Your score is now ${score}.`;
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
async function training(subject, interaction) {
|
||
4 years ago
|
const authorId = interaction.user.id;
|
||
4 years ago
|
let score;
|
||
|
userScore
|
||
|
.findOne({ authorID: authorId })
|
||
|
.lean()
|
||
|
.then((obj, err) => {
|
||
|
if (!obj) {
|
||
|
score = 0;
|
||
|
} else if (obj) {
|
||
|
score = obj.score;
|
||
|
} else {
|
||
|
console.log(err);
|
||
4 years ago
|
}
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
let categoryArray = [];
|
||
|
|
||
|
switch (subject) {
|
||
|
case null:
|
||
|
categoryArray = ["BIOLOGY", "PHYSICS", "CHEMISTRY", "EARTH AND SPACE", "ASTRONOMY", "MATH"];
|
||
|
break;
|
||
|
case "astro":
|
||
|
case "astronomy":
|
||
|
categoryArray = ["ASTRONOMY"]
|
||
|
break;
|
||
|
case "bio":
|
||
|
case "biology":
|
||
|
categoryArray = ["BIOLOGY"];
|
||
|
break;
|
||
|
case "ess":
|
||
|
case "earth science":
|
||
|
case "es":
|
||
|
categoryArray = ["EARTH SCIENCE"];
|
||
|
break;
|
||
|
case "chem":
|
||
|
case "chemistry":
|
||
|
categoryArray = ["CHEMISTRY"];
|
||
|
break;
|
||
|
case "phys":
|
||
|
case "physics":
|
||
|
categoryArray = ["PHYSICS"];
|
||
|
break;
|
||
|
case "math":
|
||
|
categoryArray = ["MATH"];
|
||
|
break;
|
||
|
case "energy":
|
||
|
categoryArray = ["ENERGY"];
|
||
|
break;
|
||
|
default:
|
||
3 years ago
|
interaction.reply(
|
||
|
new Discord.MessageEmbed()
|
||
|
.setDescription("<:red_x:816791117671825409> Not a valid subject!")
|
||
|
.setColor("#ffffff")
|
||
|
);
|
||
4 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
axios
|
||
|
.post("https://scibowldb.com/api/questions/random", { categories: categoryArray })
|
||
|
.then((res) => {
|
||
|
data = res.data.question;
|
||
3 years ago
|
const tossupQuestion = data.tossup_question;
|
||
|
const tossupAnswer = data.tossup_answer;
|
||
4 years ago
|
const messageFilter = (m) => m.author.id === authorId;
|
||
3 years ago
|
interaction.reply({ content: tossupQuestion + `\n\n||Source: ${data.uri}||` })
|
||
3 years ago
|
.then(() => {
|
||
|
interaction.channel.awaitMessages({
|
||
|
messageFilter,
|
||
|
max: 1
|
||
4 years ago
|
})
|
||
3 years ago
|
.then(collected => {
|
||
|
answerMsg = collected.first();
|
||
4 years ago
|
|
||
|
let predicted = null;
|
||
|
if (data.tossup_format === "Multiple Choice") {
|
||
|
if (
|
||
|
answerMsg.content.charAt(0).toLowerCase() ===
|
||
3 years ago
|
tossupAnswer.charAt(0).toLowerCase()
|
||
4 years ago
|
) {
|
||
|
predicted = "correct";
|
||
4 years ago
|
} else {
|
||
4 years ago
|
predicted = "incorrect";
|
||
4 years ago
|
}
|
||
4 years ago
|
} else {
|
||
|
if (
|
||
|
answerMsg.content.toLowerCase() ===
|
||
3 years ago
|
tossupAnswer.toLowerCase()
|
||
4 years ago
|
) {
|
||
|
predicted = "correct";
|
||
4 years ago
|
} else {
|
||
4 years ago
|
predicted = "incorrect";
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
|
|
||
|
if (predicted === "correct") {
|
||
|
updateScore(true, score, authorId).then((msgToReply) =>
|
||
|
answerMsg.reply(msgToReply)
|
||
|
);
|
||
|
} else {
|
||
|
const overrideEmbed = new Discord.MessageEmbed()
|
||
|
.setAuthor(answerMsg.author.tag, answerMsg.author.displayAvatarURL())
|
||
3 years ago
|
.addField("Correct answer", `\`${tossupAnswer}\``)
|
||
4 years ago
|
.setDescription(`It seems your answer was incorrect. Please react with <:override:842778128966615060> to override your answer if you think you got it right.`)
|
||
3 years ago
|
.setColor("#ffffff")
|
||
4 years ago
|
.setTimestamp();
|
||
3 years ago
|
const overrideMsg = answerMsg.channel.send({
|
||
|
embeds: [overrideEmbed]
|
||
|
})
|
||
4 years ago
|
.then(overrideMsg => {
|
||
|
overrideMsg.react("<:override:842778128966615060>");
|
||
|
const filter = (reaction, user) => {
|
||
|
return (
|
||
|
["override"].includes(reaction.emoji.name) &&
|
||
|
user.id === answerMsg.author.id
|
||
|
);
|
||
|
};
|
||
|
overrideMsg
|
||
3 years ago
|
.awaitReactions({
|
||
|
filter,
|
||
|
max: 1
|
||
4 years ago
|
})
|
||
|
.then((userReaction) => {
|
||
|
updateScore(true, score, authorId).then((msgToReply) =>
|
||
|
answerMsg.reply(msgToReply)
|
||
|
);
|
||
4 years ago
|
}).catch(console.error);
|
||
|
}).catch(console.error);
|
||
4 years ago
|
}
|
||
3 years ago
|
}).catch(console.error);
|
||
4 years ago
|
}).catch(console.error);
|
||
3 years ago
|
}).catch(console.error);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
function sendHelpMessage(interaction) {
|
||
4 years ago
|
const helpEmbed = new Discord.MessageEmbed().setDescription(helpMessage).setColor("ffffff");
|
||
3 years ago
|
interaction.reply({ embeds: [helpEmbed] });
|
||
4 years ago
|
}
|
||
|
|
||
|
async function startScoring(message) {
|
||
|
let scoreA = 0;
|
||
|
let scoreB = 0;
|
||
|
await message.channel
|
||
|
.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`)
|
||
|
.then((scoreboard) => {
|
||
|
const filter = (m) => m.content.includes("do be");
|
||
|
const collector = message.channel.createMessageCollector(filter, {
|
||
|
time: 1500000,
|
||
4 years ago
|
});
|
||
4 years ago
|
collector.on("collect", (m) => {
|
||
4 years ago
|
if (m.content.toLowerCase() === "/scoring a 4") {
|
||
4 years ago
|
// A team gets toss-up
|
||
4 years ago
|
m.delete({ timeout: 1000 }).catch(console.error);
|
||
|
scoreA += 4;
|
||
|
scoreboard.channel.send(
|
||
|
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
|
||
|
);
|
||
4 years ago
|
} else if (m.content.toLowerCase() === "/scoring a 10") {
|
||
4 years ago
|
// A team gets bonus
|
||
4 years ago
|
m.delete({ timeout: 1000 }).catch(console.error);
|
||
|
scoreA += 10;
|
||
|
scoreboard.channel.send(
|
||
|
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
|
||
|
);
|
||
4 years ago
|
} else if (m.content.toLowerCase() === "/scoring b 4") {
|
||
4 years ago
|
// B team gets toss up
|
||
4 years ago
|
m.delete({ timeout: 1000 }).catch(console.error);
|
||
|
scoreB += 4;
|
||
|
scoreboard.channel.send(
|
||
|
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
|
||
|
);
|
||
4 years ago
|
} else if (m.content.toLowerCase() === "/scoring b 10") {
|
||
4 years ago
|
// B team gets bonus
|
||
4 years ago
|
m.delete({ timeout: 1000 }).catch(console.error);
|
||
|
scoreB += 10;
|
||
|
scoreboard.channel.send(
|
||
|
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
|
||
|
);
|
||
4 years ago
|
} else if (m.content === "/scoring stop") {
|
||
4 years ago
|
m.delete({ timeout: 1000 }).catch(console.error);
|
||
|
scoreboard.delete({ timeout: 1000 });
|
||
|
m.channel.send(
|
||
|
`**FINAL SCORE:**\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
|
||
|
);
|
||
|
collector.stop();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
function dontWorryBeHappy(message) {
|
||
4 years ago
|
message.channel.send(
|
||
|
new Discord.MessageEmbed()
|
||
|
.setTitle(`Don't Worry Be Happy!`)
|
||
|
.setImage("https://media.giphy.com/media/7OKC8ZpTT0PVm/giphy.gif")
|
||
|
.setURL("https://youtu.be/d-diB65scQU")
|
||
3 years ago
|
.setColor("#ffffff")
|
||
4 years ago
|
);
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
function showServerNumber(message) {
|
||
4 years ago
|
message.channel.send(client.guilds.cache.size);
|
||
|
}
|
||
|
|
||
4 years ago
|
function showLeaderboard(interaction) {
|
||
4 years ago
|
let messageContent = "";
|
||
|
userScore
|
||
|
.find({})
|
||
4 years ago
|
.sort({ score: -1 }) // Sort by descending order
|
||
4 years ago
|
.exec((err, obj) => {
|
||
4 years ago
|
if (err) {
|
||
4 years ago
|
console.log(err);
|
||
4 years ago
|
return interaction.reply(
|
||
4 years ago
|
"Uh oh! :( There was an internal error. Please try again."
|
||
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
if (obj.length < 10) {
|
||
|
// Need at least 10 scores for top 10
|
||
4 years ago
|
return interaction.reply(
|
||
4 years ago
|
`There are only ${obj.length} users, we need at least 10!`
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
for (let i = 0; i < 10; i++) {
|
||
|
messageContent += `${i + 1}: <@${obj[i].authorID}>: ${obj[i].score}\n`; // Loop through each user and add their name and score to leaderboard content
|
||
4 years ago
|
}
|
||
3 years ago
|
const leaderboardEmbed = new Discord.MessageEmbed()
|
||
4 years ago
|
.setTitle("Top Ten!")
|
||
|
.setDescription(messageContent)
|
||
3 years ago
|
.setColor("#ffffff")
|
||
3 years ago
|
|
||
|
interaction.reply({ embeds: [leaderboardEmbed] });
|
||
4 years ago
|
});
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
async function about(action, interaction) {
|
||
4 years ago
|
if (action === "contributors") {
|
||
3 years ago
|
const contributorEmbed = new Discord.MessageEmbed().setTitle("Contributors")
|
||
3 years ago
|
.addField("Creator", `<@745063586422063214> [ADawesomeguy#3602]`, true)
|
||
4 years ago
|
.addField("Contributors", `<@650525101048987649> [tEjAs#8127]\n<@426864344463048705> [tetrident#9396]`, true) // Add more contributors here, first one is Abheek, second one is Tejas
|
||
4 years ago
|
.setTimestamp()
|
||
3 years ago
|
.setColor("#ffffff");
|
||
|
|
||
|
interaction.reply({ embeds: [contributorEmbed] });
|
||
4 years ago
|
} else if (action === "changelog") {
|
||
|
let parentFolder = __dirname.split("/");
|
||
|
parentFolder.pop();
|
||
|
parentFolder = parentFolder.join("/");
|
||
|
|
||
|
const commits = gitlog({
|
||
|
repo: parentFolder,
|
||
|
number: 5,
|
||
|
fields: ["hash", "abbrevHash", "subject", "authorName", "authorDateRel"],
|
||
|
});
|
||
|
|
||
|
const changelogEmbed = new Discord.MessageEmbed()
|
||
|
.setAuthor(interaction.user.tag, interaction.user.displayAvatarURL())
|
||
|
.setTitle("Changelog")
|
||
3 years ago
|
.setColor("#ffffff")
|
||
4 years ago
|
.setTimestamp();
|
||
|
|
||
|
commits.forEach(commit => {
|
||
|
changelogEmbed.addField(commit.abbrevHash, `> \`Hash:\`${commit.hash}\n> \`Subject:\`${commit.subject}\n> \`Author:\`${commit.authorName}\n> \`Date:\`${commit.authorDateRel}\n> \`Link\`: [GitHub](https://github.com/ADawesomeguy/AwesomeSciBo/commit/${commit.hash})\n`);
|
||
|
});
|
||
|
|
||
3 years ago
|
interaction.reply({ embeds: [changelogEmbed] });
|
||
4 years ago
|
} else if (action === "bot") {
|
||
3 years ago
|
await client.guilds.fetch();
|
||
|
const trainingDocuments = await userScore.countDocuments({});
|
||
4 years ago
|
const aboutBotEmbed = new Discord.MessageEmbed()
|
||
|
.setAuthor(interaction.user.tag, interaction.user.displayAvatarURL())
|
||
|
.setTitle("About AwesomeSciBo")
|
||
3 years ago
|
.addField("Servers", `${client.guilds.cache.size}`, true)
|
||
|
.addField("Training Users", `${trainingDocuments}`, true)
|
||
4 years ago
|
.setTimestamp();
|
||
4 years ago
|
|
||
3 years ago
|
interaction.reply({ embeds: [aboutBotEmbed] });
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
async function rounds(action, interaction) {
|
||
|
if (action === "generate") {
|
||
|
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,
|
||
4 years ago
|
requestedBy: interaction.user.id,
|
||
|
authorTag: interaction.user.tag,
|
||
4 years ago
|
timestamp: new Date().toISOString(),
|
||
|
});
|
||
|
newGeneratedRound.save((err, round) => {
|
||
|
if (err) {
|
||
|
console.log(err);
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
interaction.reply(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true });
|
||
4 years ago
|
});
|
||
|
});
|
||
|
} else if (action === "list"){
|
||
|
let rounds = await generatedRound.find({ requestedBy: interaction.user.id }).sort({ timestamp: -1 });
|
||
|
let finalMessage = "";
|
||
|
if (!rounds) {
|
||
|
interaction.reply("You haven't requested any rounds!");
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
if (rounds.length > 5) {
|
||
|
rounds = rounds.slice(0, 5);
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
rounds.forEach(async (item, index) => {
|
||
|
finalMessage += `${index + 1}. [${item.timestamp.split("T")[0]}](https://api.adawesome.tech/round/${item._id.toString()})\n`;
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
const roundsEmbed = new Discord.MessageEmbed()
|
||
4 years ago
|
.setAuthor(interaction.user.tag, interaction.user.displayAvatarURL())
|
||
|
.setTitle(`Last 5 rounds requested by ${interaction.user.tag}`)
|
||
4 years ago
|
.setDescription(finalMessage)
|
||
|
.setTimestamp();
|
||
4 years ago
|
|
||
4 years ago
|
interaction.reply({
|
||
|
embeds: [roundsEmbed],
|
||
|
ephemeral: true
|
||
|
});
|
||
4 years ago
|
} else if (action === "hit"){
|
||
|
let totalCount = await generatedRound.countDocuments({});
|
||
4 years ago
|
let userCount = await generatedRound.countDocuments({ requestedBy: interaction.user.id });
|
||
4 years ago
|
|
||
|
interaction.reply(`Total Hits: ${totalCount}\nYour Hits: ${userCount}`);
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
client.on("interactionCreate", async interaction => {
|
||
4 years ago
|
// If the interaction isn't a slash command, return
|
||
|
if (!interaction.isCommand()) return;
|
||
|
|
||
|
switch(interaction.commandName) {
|
||
|
case "help":
|
||
|
sendHelpMessage(interaction);
|
||
|
break;
|
||
|
case "train":
|
||
3 years ago
|
training(interaction.options.get("subject") ? interaction.options.get("subject").value : null, interaction);
|
||
4 years ago
|
break;
|
||
4 years ago
|
case "rounds":
|
||
3 years ago
|
rounds(interaction.options.first().name, interaction);
|
||
4 years ago
|
break;
|
||
4 years ago
|
case "top":
|
||
|
showLeaderboard(interaction);
|
||
|
break;
|
||
4 years ago
|
case "about":
|
||
3 years ago
|
about(interaction.options.first().name, interaction);
|
||
4 years ago
|
break;
|
||
4 years ago
|
}
|
||
|
})
|
||
|
|
||
4 years ago
|
client
|
||
4 years ago
|
.login(process.env.TOKEN)
|
||
4 years ago
|
.then(() => console.log("Running!"))
|
||
4 years ago
|
.catch((error) => console.log(error));
|