From 555d0436f8acfffd05787584d9777de2de2c5320 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 20 Feb 2023 15:14:57 -0500 Subject: [PATCH] Fix /setup compare --- modules/CustomClasses.js | 8 ++++---- slash-commands/setup.js | 38 +++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/modules/CustomClasses.js b/modules/CustomClasses.js index c35730f..abdc8fe 100755 --- a/modules/CustomClasses.js +++ b/modules/CustomClasses.js @@ -39,12 +39,12 @@ module.exports = { return this; } setTreeMessage(messageId, channelId) { - this.treeMessageId = messageId; + this.treeMessageId = messageId ? messageId : this.treeMessageId; this.treeChannelId = channelId; return this; } setLeaderboardMessage(messageId, channelId) { - this.leaderboardMessageId = messageId; + this.leaderboardMessageId = messageId ? messageId : this.leaderboardMessageId; this.leaderboardChannelId = channelId; return this; } @@ -122,7 +122,7 @@ module.exports = { case "setTreeMessage": queryParts = [ `UPDATE guild_info SET tree_message_id = ${db.escape(this.treeMessageId)}, `, - `tree_channel_id = ${db.escape(this.treeChannelId)}, `, + `tree_channel_id = ${db.escape(this.treeChannelId)} `, `WHERE guild_id = ${db.escape(this.guildId)}` ]; return queryParts.join(''); @@ -130,7 +130,7 @@ module.exports = { case "setLeaderboardMessage": queryParts = [ `UPDATE guild_info SET leaderboard_message_id = ${db.escape(this.leaderboardMessageId)}, `, - `leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)}, `, + `leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)} `, `WHERE guild_id = ${db.escape(this.guildId)}` ]; return queryParts.join(''); diff --git a/slash-commands/setup.js b/slash-commands/setup.js index ac1c0fa..886aa3a 100755 --- a/slash-commands/setup.js +++ b/slash-commands/setup.js @@ -18,8 +18,8 @@ module.exports = { ) .addChannelOption(o => o.setName('leaderboardchannel') - .setDescription('If your leaderboard isn\'t in the same channel, where is it?') - .setRequired(false) + .setDescription('What channel is your leaderboard in?') + .setRequired(true) ) ) .addSubcommand(sc => @@ -41,12 +41,12 @@ module.exports = { .setDescription('View your server\'s configuration')) .addSubcommand(sc => sc.setName('reset') - .setDescription('Remove all server configuration from the database') - .addBooleanOption(o => - o.setName('confirm') - .setDescription('WARNING THIS IS IRREVERSIBLE') - .setRequired(true) - ) + .setDescription('Remove all server configuration from the database') + .addBooleanOption(o => + o.setName('confirm') + .setDescription('WARNING THIS IS IRREVERSIBLE') + .setRequired(true) + ) ) .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction) { @@ -54,15 +54,27 @@ module.exports = { const subcommand = interaction.options.getSubcommand(); switch (subcommand) { case "compare": + const treeChannel = interaction.options.getChannel('treechannel'); + const leaderboardChannel = interaction.options.getChannel('leaderboardchannel'); if (interaction.client.guildInfos.has(interaction.guildId)) { let guildInfo = interaction.client.guildInfos.get(interaction.guildId); - const findMessagesResponse = await fn.messages.find(interaction, guildInfo); - await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e)); + guildInfo.setTreeMessage(undefined, treeChannel.id); + guildInfo.setLeaderboardMessage(undefined, leaderboardChannel.id); + // Update the database + await dbfn.setGuildInfo(guildInfo.queryBuilder("setTreeMessage")).catch(e => console.error(e)); + await dbfn.setGuildInfo(guildInfo.queryBuilder("setLeaderboardMessage")).catch(e => console.error(e)); + const reply = `Tree Channel: <#${treeChannel.id}> | Leaderboard Channel: <#${leaderboardChannel.id}>`; + await interaction.editReply(fn.builders.embed(reply)).catch(e => console.error(e)); } else { let guildInfo = new GuildInfo() - .setId(interaction.guildId); - const findMessagesResponse = await fn.messages.find(interaction, guildInfo); - await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e)); + .setId(interaction.guildId) + .setTreeMessage(undefined, treeChannel.id) + .setLeaderboardMessage(undefined, leaderboardChannel.id); + // Update the database + await dbfn.setGuildInfo(guildInfo.queryBuilder("setTreeMessage")).catch(e => console.error(e)); + await dbfn.setGuildInfo(guildInfo.queryBuilder("setLeaderboardMessage")).catch(e => console.error(e)); + const reply = `Tree Channel: <#${treeChannel.id}> | Leaderboard Channel: <#${leaderboardChannel.id}>`; + await interaction.editReply(fn.builders.embed(reply)).catch(e => console.error(e)); } break; case "rolemenu":