2023-02-12 04:57:34 +00:00
|
|
|
const { SlashCommandBuilder, Guild } = require('discord.js');
|
2023-02-01 03:51:10 +00:00
|
|
|
const dbfn = require('../modules/dbfn.js');
|
2023-01-21 14:58:32 +00:00
|
|
|
const fn = require('../modules/functions.js');
|
2023-02-12 04:57:34 +00:00
|
|
|
const { GuildInfo } = require('../modules/CustomClasses.js');
|
2023-01-21 14:58:32 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('compare')
|
|
|
|
.setDescription('See how your tree compares to other trees!'),
|
|
|
|
async execute(interaction) {
|
2023-02-01 03:51:10 +00:00
|
|
|
try {
|
|
|
|
await interaction.deferReply();
|
|
|
|
// Get the guildInfo from the database
|
2023-02-12 04:57:34 +00:00
|
|
|
|
|
|
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
|
|
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
2023-02-01 03:51:10 +00:00
|
|
|
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
|
|
|
|
if (findMessagesResponse.code == 1) {
|
2023-02-12 04:57:34 +00:00
|
|
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
2023-02-01 03:51:10 +00:00
|
|
|
// Parse the leaderboard message
|
|
|
|
await fn.rankings.parse(interaction, guildInfo);
|
|
|
|
// Build the string that shows the comparison // TODO Move the string building section to fn.builders?
|
|
|
|
const comparedRankings = await fn.rankings.compare(interaction, guildInfo);
|
|
|
|
|
|
|
|
const embed = fn.builders.comparisonEmbed(comparedRankings, guildInfo);
|
2023-02-12 04:57:34 +00:00
|
|
|
await interaction.editReply(embed).catch(err => console.error(err));
|
2023-02-01 03:51:10 +00:00
|
|
|
} else {
|
|
|
|
await interaction.editReply(fn.builders.errorEmbed(findMessagesResponse.status));
|
|
|
|
}
|
2023-02-12 04:57:34 +00:00
|
|
|
} else {
|
|
|
|
// Create a basic guildInfo with blank data
|
|
|
|
let guildInfo = new GuildInfo()
|
|
|
|
.setId(interaction.guildId)
|
|
|
|
.setTreeMessage("", interaction.channelId)
|
|
|
|
.setLeaderboardMessage("", interaction.channelId)
|
|
|
|
// Using the above guildInfo, try to find the Grow A Tree messages
|
|
|
|
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
|
|
|
|
guildInfo = findMessagesResponse.data;
|
|
|
|
if (findMessagesResponse.code == 1) {
|
|
|
|
// Build the string that shows the comparison // TODO Move the string building section to fn.builders?
|
|
|
|
const comparedRankings = await fn.rankings.compare(interaction, guildInfo);
|
|
|
|
const embed = fn.builders.comparisonEmbed(comparedRankings, guildInfo);
|
|
|
|
await interaction.editReply(embed).catch(err => console.error(err));
|
2023-02-01 03:51:10 +00:00
|
|
|
} else {
|
2023-02-12 04:57:34 +00:00
|
|
|
await interaction.editReply(fn.builders.errorEmbed(findMessagesResponse.status));
|
2023-02-01 03:51:10 +00:00
|
|
|
}
|
2023-02-12 04:57:34 +00:00
|
|
|
}
|
2023-02-01 03:51:10 +00:00
|
|
|
} catch (err) {
|
|
|
|
interaction.editReply(fn.builders.errorEmbed(err)).catch(err => {
|
2023-01-25 08:07:41 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
2023-02-01 03:51:10 +00:00
|
|
|
console.error(err);
|
|
|
|
}
|
2023-01-21 14:58:32 +00:00
|
|
|
},
|
|
|
|
};
|