mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
commands: add purr command, idk why im doing this
This commit is contained in:
parent
037c4ea63b
commit
f1d3502efd
2 changed files with 175 additions and 0 deletions
91
commands/fun/purr.js
Normal file
91
commands/fun/purr.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const axios = require("axios");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("purr")
|
||||
.setDescription("Fetch a random image or GIF from PurrBot API")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("category")
|
||||
.setDescription("Select a category")
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
// GIF endpoints
|
||||
{ name: "Angry (GIF)", value: "img/sfw/angry/gif" },
|
||||
{ name: "Bite (GIF)", value: "img/sfw/bite/gif" },
|
||||
{ name: "Blush (GIF)", value: "img/sfw/blush/gif" },
|
||||
{ name: "Comfy (GIF)", value: "img/sfw/comfy/gif" },
|
||||
{ name: "Cry (GIF)", value: "img/sfw/cry/gif" },
|
||||
{ name: "Cuddle (GIF)", value: "img/sfw/cuddle/gif" },
|
||||
{ name: "Dance (GIF)", value: "img/sfw/dance/gif" },
|
||||
{ name: "Eevee (GIF)", value: "img/sfw/eevee" }, // Requires {type} (gif or img)
|
||||
{ name: "Fluff (GIF)", value: "img/sfw/fluff/gif" },
|
||||
{ name: "Hug (GIF)", value: "img/sfw/hug/gif" },
|
||||
{ name: "Kiss (GIF)", value: "img/sfw/kiss/gif" },
|
||||
{ name: "Lay (GIF)", value: "img/sfw/lay/gif" },
|
||||
{ name: "Lick (GIF)", value: "img/sfw/lick/gif" },
|
||||
{ name: "Neko (GIF)", value: "img/sfw/neko" }, // Requires {type} (gif or img)
|
||||
{ name: "Pat (GIF)", value: "img/sfw/pat/gif" },
|
||||
{ name: "Poke (GIF)", value: "img/sfw/poke/gif" },
|
||||
{ name: "Pout (GIF)", value: "img/sfw/pout/gif" },
|
||||
{ name: "Slap (GIF)", value: "img/sfw/slap/gif" },
|
||||
{ name: "Smile (GIF)", value: "img/sfw/smile/gif" },
|
||||
{ name: "Tail (GIF)", value: "img/sfw/tail/gif" },
|
||||
{ name: "Tickle (GIF)", value: "img/sfw/tickle/gif" },
|
||||
|
||||
// Image endpoints (randomly chosen)
|
||||
{ name: "Background (IMG)", value: "img/sfw/background/img" },
|
||||
{ name: "Holo (IMG)", value: "img/sfw/holo/img" },
|
||||
{ name: "Kitsune (IMG)", value: "img/sfw/kitsune/img" },
|
||||
{ name: "Senko (IMG)", value: "img/sfw/senko/img" }
|
||||
)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("type")
|
||||
.setDescription(
|
||||
'For Eevee or Neko: Provide type. Available values: "gif" or "img".'
|
||||
)
|
||||
.setRequired(false)
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const category = interaction.options.getString("category");
|
||||
const type = interaction.options.getString("type");
|
||||
|
||||
let url = `https://purrbot.site/api/${category}`;
|
||||
|
||||
// Check if the category is Eevee or Neko, and validate type
|
||||
const requiresType =
|
||||
category.includes("eevee") || category.includes("neko");
|
||||
|
||||
if (requiresType) {
|
||||
if (type !== "gif" && type !== "img") {
|
||||
await interaction.reply({
|
||||
content: 'Please provide a valid type: "gif" or "img".',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
url += `/${type}`;
|
||||
}
|
||||
|
||||
try {
|
||||
// Fetch the image or list from the API
|
||||
const response = await axios.get(url);
|
||||
const data = response.data;
|
||||
|
||||
await interaction.reply({
|
||||
content: data.link || JSON.stringify(data),
|
||||
ephemeral: false,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content: "Something went wrong while fetching the image or list.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
84
commands/utils/leaderboard.js
Normal file
84
commands/utils/leaderboard.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const Leaderboard = require("../../models/Leaderboard");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("leaderboard")
|
||||
.setDescription("Displays the trivia leaderboard"),
|
||||
|
||||
async execute(interaction, client) {
|
||||
const guild = interaction.guild;
|
||||
|
||||
try {
|
||||
// Fetch top 10 leaderboard entries sorted by correct answers
|
||||
const scores = await Leaderboard.find()
|
||||
.sort({ correctAnswers: -1 })
|
||||
.limit(10);
|
||||
|
||||
// Fetch display names for each leaderboard entry
|
||||
const leaderboardEntries = await Promise.all(
|
||||
scores.map(async (entry, index) => {
|
||||
try {
|
||||
const member = await guild.members.fetch(entry.userId);
|
||||
const displayName = member ? member.displayName : entry.username; // Fallback if member not found
|
||||
|
||||
return {
|
||||
position: index + 1,
|
||||
name: displayName,
|
||||
correctAnswers: entry.correctAnswers,
|
||||
gamesPlayed: entry.gamesPlayed,
|
||||
streak: entry.streak, // Include streak
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Error fetching member for userId: ${entry.userId}`,
|
||||
error
|
||||
);
|
||||
return {
|
||||
position: index + 1,
|
||||
name: entry.username,
|
||||
correctAnswers: entry.correctAnswers,
|
||||
gamesPlayed: entry.gamesPlayed,
|
||||
streak: entry.streak, // Include streak
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const leaderboardEmbed = new EmbedBuilder()
|
||||
.setColor("#0099ff")
|
||||
.setTitle("Trivia Leaderboard")
|
||||
.setTimestamp();
|
||||
|
||||
// Add each leaderboard entry
|
||||
leaderboardEntries.forEach((entry) => {
|
||||
const fieldValue = `${entry.correctAnswers} correct answers in ${entry.gamesPlayed} games\nCurrent streak: ${entry.streak}`;
|
||||
|
||||
leaderboardEmbed.addFields({
|
||||
name: `${entry.position}. ${entry.name}`,
|
||||
value: fieldValue,
|
||||
inline: false,
|
||||
});
|
||||
});
|
||||
|
||||
if (guild.iconURL()) {
|
||||
leaderboardEmbed.setFooter({
|
||||
text: guild.name,
|
||||
iconURL: guild.iconURL(),
|
||||
});
|
||||
} else {
|
||||
leaderboardEmbed.setFooter({
|
||||
text: guild.name,
|
||||
});
|
||||
}
|
||||
|
||||
await interaction.reply({ embeds: [leaderboardEmbed] });
|
||||
} catch (error) {
|
||||
console.error("Error executing leaderboard command:", error);
|
||||
await interaction.reply({
|
||||
content: "There was an error while executing this command!",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue