From b6c9954069295c5a476ebe295224f4b0d4d7ccb6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 28 Aug 2022 00:16:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8better=20config=20command=20for=20a?= =?UTF-8?q?udits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/config/modules/audits/index.ts | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/plugins/commands/config/modules/audits/index.ts b/src/plugins/commands/config/modules/audits/index.ts index b440562..5ef3fac 100644 --- a/src/plugins/commands/config/modules/audits/index.ts +++ b/src/plugins/commands/config/modules/audits/index.ts @@ -34,43 +34,44 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - const { guild, options } = interaction; + const { successColor, footerText, footerIcon } = await getEmbedConfig( + guild + ); + const status = options.getBoolean("status"); + const channel = options.getChannel("channel"); - const status = options?.getBoolean("status"); - const channel = options?.getChannel("channel"); - - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, + if (!guild) throw new Error("Guild not found."); + const guildDB = await guildSchema.findOne({ + guildId: guild.id, }); + if (!guildDB) throw new Error("Guild configuration not found."); - if (guildDB === null) { - return logger?.silly(`Guild not found in database.`); - } + guildDB.audits.status = status !== null ? status : guildDB.audits.status; + guildDB.audits.channelId = channel ? channel.id : guildDB.audits.channelId; - guildDB.audits.status = status !== null ? status : guildDB?.audits?.status; - guildDB.audits.channelId = - channel !== null ? channel.id : guildDB?.audits?.channelId; + await guildDB.save().then(async () => { + logger.verbose( + `Guild ${guild.name} updated their configuration for audits.` + ); - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild audits updated.`); - - const interactionEmbed = new EmbedBuilder() + const embedSuccess = new EmbedBuilder() .setTitle("[:hammer:] Audits") - .setDescription("Audit settings updated!") + .setDescription("Guild configuration updated successfully.") .setColor(successColor) .addFields( { name: "🤖 Status", - value: `${guildDB?.audits?.status}`, + value: `${ + guildDB.audits.status + ? ":white_check_mark: Enabled" + : ":x: Disabled" + }`, inline: true, }, { name: "🌊 Channel", - value: `${guildDB?.audits?.channelId}`, + value: `<#${guildDB.audits.channelId}>`, inline: true, } ) @@ -80,8 +81,8 @@ export default { text: footerText, }); - return interaction?.editReply({ - embeds: [interactionEmbed], + return interaction.editReply({ + embeds: [embedSuccess], }); }); },