silvanus/slash-commands/compare.js
Skylar Grant b724229f06
V1.2.1 dev (#11)
* make the beginning height optional, defaulting to the trees current heigt

* improved workflow

* fix

* new fix

* Install modules

* remove unnecessary call to build the tables

* testing

* f

* f

* oops

* undev

* fix const

* new ci

* versioning

* Classes, Collections, and new Notification Relay

* Fix CI for new env vars

* Update to read contents of embeds

* Update filter to check for embeds

* Update to add includes check

* Begin implementing role menu

* Role menu ready for testing

* Add missing emojis

* Fixes, ready for testing

* Tentative deploy

* Documentation update

* I think this fixes unchanging notifications

* Update README.md

* Make reminders visually distinct

* Set Permissions

* Added import for PermissionFlagsBits

* Add ability to manually send ping from watch chan

* CI update

* Confusion

* Make dev dockerization manual only

* Dev Logging

* Update reset command

* Implement updating of notifications piecemeal

* Unified error handling

* Change to refresh commands not blindly update

* Change to manual run only

* Restructured file to allow async use

* Move role menu setup and allow everyone to send it

* Consolidate setupinfo into setup

* Improved error handling

* Update opt out method

* Cleaning up junk

* Added seconds parser and optout detection

* Add opt out method

* Consolidated to setup command

* Add privacy setting and use new parser
2023-02-19 20:42:14 -05:00

55 lines
2.4 KiB
JavaScript
Executable File

const { SlashCommandBuilder, Guild } = require('discord.js');
const dbfn = require('../modules/dbfn.js');
const fn = require('../modules/functions.js');
const { GuildInfo } = require('../modules/CustomClasses.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('compare')
.setDescription('See how your tree compares to other trees!'),
async execute(interaction) {
try {
await interaction.deferReply();
// Get the guildInfo from the database
if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
if (findMessagesResponse.code == 1) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
// 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);
await interaction.editReply(embed).catch(e => console.error(e));
} else {
await interaction.editReply(fn.builders.errorEmbed(findMessagesResponse.status));
}
} 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(e => console.error(e));
} else {
await interaction.editReply(fn.builders.errorEmbed(findMessagesResponse.status));
}
}
} catch (err) {
interaction.editReply(fn.builders.errorEmbed(err)).catch(err => {
console.error(err);
});
console.error(err);
}
},
};