From ab42b4f91bbe69906005bf8220fae0878ea02f93 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 14 Oct 2022 11:39:46 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Fixed?= =?UTF-8?q?=20some=20code=20smells?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/managers/command/index.ts | 4 ---- src/managers/event/index.ts | 2 ++ .../commands/counters/modules/view/index.ts | 7 ------- .../modules/credits/modules/transfer/index.ts | 19 ++++--------------- .../modules/roles/modules/cancel/index.ts | 3 --- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/managers/command/index.ts b/src/managers/command/index.ts index 5f43be4..10e6184 100644 --- a/src/managers/command/index.ts +++ b/src/managers/command/index.ts @@ -23,10 +23,6 @@ export const register = async (client: Client) => { throw new Error( `📦 No command builder found while importing "${commandName}"` ); - if (!command.execute) - throw new Error( - `📦 No command execute found while importing "${commandName}"` - ); if (!command.moduleData) throw new Error( `📦 No command moduleData found while importing "${commandName}"` diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index c0734ba..778066d 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -44,6 +44,8 @@ export const register = async (client: Client) => { case "on": client.on(eventName, eventExecutor); break; + default: + logger.error(`${eventName} does not have a valid type`); } importedEventAmount += 1; }; diff --git a/src/plugins/commands/counters/modules/view/index.ts b/src/plugins/commands/counters/modules/view/index.ts index 679b68e..321206c 100644 --- a/src/plugins/commands/counters/modules/view/index.ts +++ b/src/plugins/commands/counters/modules/view/index.ts @@ -46,13 +46,6 @@ export default { channelId: discordChannel.id, }); - const counters = await counterSchema.find(); - - console.log(counters, { - guildId: guild.id, - channelId: discordChannel.id, - }); - if (!counter) throw new Error("No counter found for channel"); return interaction.editReply({ diff --git a/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts b/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts index 2d790b8..62a9425 100644 --- a/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts @@ -207,24 +207,13 @@ export default { await toUser.save(); await session.commitTransaction(); - } catch (error) { + } catch (error: unknown) { await session.abortTransaction(); session.endSession(); - logger.error(`${error}`); - return interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setTitle("[:toolbox:] Manage - Credits (Transfer)") - .setDescription( - "An error occurred while trying to gift credits. Please try again." - ) - .setColor(errorColor) - .setTimestamp(new Date()) - .setColor(successColor) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); + throw new Error( + "An error occurred while trying to gift credits. Please try again later." + ); } finally { // ending the session session.endSession(); diff --git a/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts b/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts index a2d92d2..f3064cd 100644 --- a/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts +++ b/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts @@ -79,9 +79,6 @@ export default { return interaction?.editReply({ embeds: [interactionEmbed], }); - }) - .catch(async (error: Error) => { - return logger?.silly(`Role could not be deleted. ${error}`); }); }, }; From 38d192207d771d8c31caa0ee7b623e7e67b558f7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 14 Oct 2022 11:41:53 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=A1=20event.register=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/managers/event/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 778066d..3834687 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -4,6 +4,7 @@ import listDir from "../../helpers/checkDirectory"; import { IEvent } from "../../interfaces/Event"; import logger from "../../middlewares/logger"; +// Registers all available events export const register = async (client: Client) => { const eventNames = await listDir("plugins/events"); if (!eventNames) throw new Error("📦 No events available"); From dd7d31c571ce9d6444638c66d3712c1ab6961039 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 14 Oct 2022 11:43:43 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Fixed?= =?UTF-8?q?=20some=20more=20code=20smells?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/managers/command/index.ts | 12 ++++-------- src/managers/event/index.ts | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/managers/command/index.ts b/src/managers/command/index.ts index 10e6184..1816c8f 100644 --- a/src/managers/command/index.ts +++ b/src/managers/command/index.ts @@ -34,7 +34,7 @@ export const register = async (client: Client) => { }; // Send log message when it's done loading commands - const doneImporting = async () => { + const doneImporting = () => { if (importedCommandAmount !== amountOfCommands) { return logger.warn( `📦 Failed importing ${ @@ -48,13 +48,9 @@ export const register = async (client: Client) => { // Start importing commands commandNames.forEach(async (commandName: string, index: number) => { - await importCommand(commandName) - .then(async () => { - logger.debug(`📦 Imported the "${commandName}" command`); - }) - .catch(async (err) => { - logger.error(err); - }); + await importCommand(commandName).then(() => { + logger.debug(`📦 Imported the "${commandName}" command`); + }); // If done importing if (index + 1 === amountOfCommands) { diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 3834687..cf44860 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -29,7 +29,7 @@ export const register = async (client: Client) => { // Register event const eventExecutor = async (...args: Promise[]) => { - await event.execute(...args).catch(async (err) => { + await event.execute(...args).catch((err) => { logger.error(`${err}`); }); }; @@ -52,7 +52,7 @@ export const register = async (client: Client) => { }; // Send log message when it's done loading events - const doneImporting = async () => { + const doneImporting = () => { if (importedEventAmount !== amountOfEvents) { return logger.warn( `📦 Failed importing ${ @@ -65,7 +65,7 @@ export const register = async (client: Client) => { }; eventNames.forEach(async (eventName: string, index: number) => { - await importEvent(eventName).then(async () => { + await importEvent(eventName).then(() => { logger.debug(`📦 Imported the "${eventName}" event`); });