From e658bd665b04889e027bcfb2ea508e3957e46395 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 10 Apr 2022 22:24:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20code=20smells=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/admin/counters/modules/add.ts | 101 +++++++++++---------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/src/commands/admin/counters/modules/add.ts b/src/commands/admin/counters/modules/add.ts index fa557b0..b1a98e9 100644 --- a/src/commands/admin/counters/modules/add.ts +++ b/src/commands/admin/counters/modules/add.ts @@ -1,14 +1,14 @@ // Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; +import { ColorResolvable, CommandInteraction } from 'discord.js'; // Configurations -import config from "../../../../../config.json"; +import config from '../../../../../config.json'; // Handlers -import logger from "../../../../handlers/logger"; +import logger from '../../../../handlers/logger'; // Models -import counterSchema from "../../../../helpers/database/models/counterSchema"; +import counterSchema from '../../../../helpers/database/models/counterSchema'; // Function export default async (interaction: CommandInteraction) => { @@ -16,29 +16,31 @@ export default async (interaction: CommandInteraction) => { const { options, guild, user } = interaction; // Channel option - const optionChannel = options?.getChannel("channel"); + const optionChannel = options?.getChannel('channel'); // Word option - const optionWord = options?.getString("word"); + const optionWord = options?.getString('word'); // Start option - const optionStart = options?.getNumber("start"); - - if (optionChannel?.type !== "GUILD_TEXT") { - const embed = { - title: ":toolbox: Admin - Counters [Add]" as string, - description: - "That channel is not supported, it needs to be a text channel." as string, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; + const optionStart = options?.getNumber('start'); + if (optionChannel?.type !== 'GUILD_TEXT') { // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + { + title: ':toolbox: Admin - Counters [Add]' as string, + description: + 'That channel is not supported, it needs to be a text channel.' as string, + timestamp: new Date(), + color: config?.colors?.error as ColorResolvable, + footer: { + iconURL: config?.footer?.icon as string, + text: config?.footer?.text as string, + }, + }, + ], + }); } const counterExist = await counterSchema?.findOne({ @@ -55,40 +57,43 @@ export default async (interaction: CommandInteraction) => { counter: optionStart || 0, }); - const embed = { - title: ":toolbox: Admin - Counters [Add]" as string, - description: `${optionChannel} is now counting when hearing word ${optionWord} and it starts at number ${ - optionStart || 0 - }.`, - timestamp: new Date(), - color: config?.colors?.success as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - // Log debug message logger?.debug( `Guild: ${guild?.id} User: ${user?.id} added ${optionChannel?.id} as a counter using word "${optionWord}" for counting.` ); // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + { + title: ':toolbox: Admin - Counters [Add]' as string, + description: `${optionChannel} is now counting when hearing word ${optionWord} and it starts at number ${ + optionStart || 0 + }.`, + timestamp: new Date(), + color: config?.colors?.success as ColorResolvable, + footer: { + iconURL: config?.footer?.icon as string, + text: config?.footer?.text as string, + }, + }, + ], + }); } - // Embed object - const embed = { - title: ":toolbox: Admin - Counters [Add]" as string, - description: `${optionChannel} is already a counting channel.`, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + { + title: ':toolbox: Admin - Counters [Add]' as string, + description: `${optionChannel} is already a counting channel.`, + timestamp: new Date(), + color: config?.colors?.error as ColorResolvable, + footer: { + iconURL: config?.footer?.icon as string, + text: config?.footer?.text as string, + }, + }, + ], + }); };