From aab4872a00c629a2bbbe08feded4edf9682a8f3a Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 30 Aug 2022 12:00:58 -0700 Subject: [PATCH] C:/Program Files/Git/settings reset cmd --- commands/settings.js | 25 +++++++++++++++++++++ events/interactionCreate.js | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/commands/settings.js b/commands/settings.js index b6ca882..912c31d 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -332,6 +332,12 @@ module.exports = { required: true, }] }, + { + name: "reset", + description: "Restore all settings to default configurations", + value: "reset", + type: 1, + }, { name: "view", description: "View current settings configuration", @@ -882,6 +888,25 @@ module.exports = { .setTitle(title) return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].name == 'reset') { + const prompt = new EmbedBuilder() + .setTitle(`Woah!? Hold on.`) + .setDescruotion('Are you sure you wish to remove all your configurations for this guild?') + .setColor(client.config.Colors.Default) + + const opt = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(`settingsReset-yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId(`settingsReset-no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle(ButtonStyle.Success) + ) + + return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); } else if (args[0].name == 'view') { const tweetChannel = GuildDB.tweetChannel ? `\n╚➤ <#${GuildDB.tweetChannel}>` : ''; diff --git a/events/interactionCreate.js b/events/interactionCreate.js index d1c1127..b105272 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -617,4 +617,49 @@ module.exports = async (client, interaction) => { return interaction.update({ embeds: [successEmbed], components: [] }); } + + // Handler for '/settings reset' + if (interaction.customId.startsWith('settingsReset')) { + if (!interaction.customId.endsWith(interaction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + flags: (1 << 6) + }) + } + let action = ''; + if (interaction.customId.split('-')[1]=='yes') { + action = 'reset'; + const defaultGuildConfig = { + serverID: GuildDB.serverID, + allowedChannels: [], + actionChannel: null, + tweetChannel: null, + advertsChannel: null, + dispatchChannel: null, + startingBalance: 1000.00, + incomeRoles: [], + botAdmin: null, + commercialRole: null, + officerRole: null, + dispatcherRole: null, + onlyOfficersSearch: false, + } + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) { + if (err) { + client.error(err); + const embed = new EmbedBuilder() + .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor(client.config.Colors.Red) + + return interaction.update({ embeds: [embed], components: [] }); + } + }); + } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; + + const successEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setTitle(`Successfully ${action} guild configurations.`) + + return interaction.update({ embeds: [successEmbed], components: [] }); + } } \ No newline at end of file