From 537e5223a0fbc77fd69d435d0359ba17049c5fdf Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 16 Oct 2022 15:07:31 +0200 Subject: [PATCH 1/2] =?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 --- .../modules/credits/modules/take/index.ts | 5 ++-- src/plugins/commands/moderation/index.ts | 9 ++++--- src/plugins/commands/profile/index.ts | 15 ++++++----- .../give/components/noSelfReputation.ts | 2 +- src/plugins/commands/shop/index.ts | 27 +++++++++++-------- src/plugins/commands/utility/index.ts | 12 ++++++--- src/plugins/events/guildMemberAdd/audits.ts | 8 +++--- .../events/guildMemberRemove/audits.ts | 8 +++--- 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/plugins/commands/manage/modules/credits/modules/take/index.ts b/src/plugins/commands/manage/modules/credits/modules/take/index.ts index 20b5445..5b920ba 100644 --- a/src/plugins/commands/manage/modules/credits/modules/take/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/take/index.ts @@ -151,9 +151,7 @@ export default { // Save toUser await toUser?.save()?.then(async () => { - logger?.silly(`Saved toUser`); - - return interaction?.editReply({ + await interaction?.editReply({ embeds: [ new EmbedBuilder() .setTitle("[:toolbox:] Manage - Credits (Take)") @@ -165,6 +163,7 @@ export default { .setFooter({ text: footerText, iconURL: footerIcon }), ], }); + return; }); }, }; diff --git a/src/plugins/commands/moderation/index.ts b/src/plugins/commands/moderation/index.ts index c9a2bec..f98040f 100644 --- a/src/plugins/commands/moderation/index.ts +++ b/src/plugins/commands/moderation/index.ts @@ -12,11 +12,14 @@ export const builder = new SlashCommandBuilder() export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { - case "prune": - return modules.prune.execute(interaction); - default: + case "prune": { + await modules.prune.execute(interaction); + break; + } + default: { throw new Error( `Unknown subcommand: ${interaction.options.getSubcommand()}` ); + } } }; diff --git a/src/plugins/commands/profile/index.ts b/src/plugins/commands/profile/index.ts index 3a9305e..9ded381 100644 --- a/src/plugins/commands/profile/index.ts +++ b/src/plugins/commands/profile/index.ts @@ -6,7 +6,6 @@ import { ChatInputCommandInteraction } from "discord.js"; import modules from "../../commands/profile/modules"; // Handlers -import logger from "../../../middlewares/logger"; export const moduleData = modules; @@ -19,11 +18,13 @@ export const builder = new SlashCommandBuilder() export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; - if (options?.getSubcommand() === "view") { - logger?.silly(`Executing view subcommand`); - - return modules.view.execute(interaction); + switch (options.getSubcommand()) { + case "view": { + await modules.view.execute(interaction); + break; + } + default: { + throw new Error("Could not find module for that command"); + } } - - logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts b/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts index dc0be04..8e3b913 100644 --- a/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts +++ b/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts @@ -1,6 +1,6 @@ import { User } from "discord.js"; -export default async (to: User | null, from: User | null) => { +export default (to: User | null, from: User | null) => { if (from?.id === to?.id) { throw new Error("You cannot give reputation to yourself."); } diff --git a/src/plugins/commands/shop/index.ts b/src/plugins/commands/shop/index.ts index 5f6e0b6..2db7112 100644 --- a/src/plugins/commands/shop/index.ts +++ b/src/plugins/commands/shop/index.ts @@ -6,7 +6,6 @@ import { ChatInputCommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "../../../middlewares/logger"; export const moduleData = modules; @@ -20,17 +19,23 @@ export const builder = new SlashCommandBuilder() export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; - if (options?.getSubcommand() === "cpgg") { - logger.silly(`Executing cpgg subcommand`); - - return modules.cpgg.execute(interaction); + switch (options.getSubcommand()) { + case "cpgg": { + await modules.cpgg.execute(interaction); + break; + } + default: { + throw new Error("Could not find module for that command."); + } } - if (options?.getSubcommandGroup() === "roles") { - logger?.silly(`Subcommand group is roles`); - - return modules.roles.execute(interaction); + switch (options.getSubcommandGroup()) { + case "roles": { + await modules.roles.execute(interaction); + break; + } + default: { + throw new Error("Could not find module for that command."); + } } - - logger?.silly(`No subcommand found.`); }; diff --git a/src/plugins/commands/utility/index.ts b/src/plugins/commands/utility/index.ts index a10fde2..6ccdc81 100644 --- a/src/plugins/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -16,13 +16,17 @@ export const builder = new SlashCommandBuilder() export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "about": - return modules.about.execute(interaction); + await modules.about.execute(interaction); + break; case "stats": - return modules.stats.execute(interaction); + await modules.stats.execute(interaction); + break; case "avatar": - return modules.avatar.execute(interaction); + await modules.avatar.execute(interaction); + break; case "ping": - return modules.ping.execute(interaction); + await modules.ping.execute(interaction); + break; default: throw new Error( `Unknown subcommand: ${interaction.options.getSubcommand()}` diff --git a/src/plugins/events/guildMemberAdd/audits.ts b/src/plugins/events/guildMemberAdd/audits.ts index 7710fac..af6290a 100644 --- a/src/plugins/events/guildMemberAdd/audits.ts +++ b/src/plugins/events/guildMemberAdd/audits.ts @@ -48,12 +48,10 @@ export default { ]), ], }) - .then(async () => { - logger.debug( - `Audit log sent for event guildMemberAdd in guild ${member.guild.name} (${member.guild.id})` - ); + .then(() => { + logger.debug(`Audit log sent for event guildMemberAdd`); }) - .catch(async () => { + .catch(() => { throw new Error("Audit log failed to send"); }); }, diff --git a/src/plugins/events/guildMemberRemove/audits.ts b/src/plugins/events/guildMemberRemove/audits.ts index 72391fa..9f8b3e9 100644 --- a/src/plugins/events/guildMemberRemove/audits.ts +++ b/src/plugins/events/guildMemberRemove/audits.ts @@ -48,12 +48,10 @@ export default { ]), ], }) - .then(async () => { - logger.debug( - `Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})` - ); + .then(() => { + logger.debug(`Audit log sent for event guildMemberRemove.`); }) - .catch(async () => { + .catch(() => { throw new Error("Audit log failed to send"); }); }, From 30e992b5b9f165dfc472b77aa02d65a6c176b989 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 16 Oct 2022 15:09:14 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=A1=20Added=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/moderation/index.ts | 1 + src/plugins/commands/profile/index.ts | 1 + src/plugins/commands/shop/index.ts | 1 + src/plugins/commands/utility/index.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/src/plugins/commands/moderation/index.ts b/src/plugins/commands/moderation/index.ts index f98040f..e74193e 100644 --- a/src/plugins/commands/moderation/index.ts +++ b/src/plugins/commands/moderation/index.ts @@ -10,6 +10,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.prune.builder); +// Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "prune": { diff --git a/src/plugins/commands/profile/index.ts b/src/plugins/commands/profile/index.ts index 9ded381..fb3f287 100644 --- a/src/plugins/commands/profile/index.ts +++ b/src/plugins/commands/profile/index.ts @@ -15,6 +15,7 @@ export const builder = new SlashCommandBuilder() .setDescription("Check a profile.") .addSubcommand(modules.view.builder); +// Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; diff --git a/src/plugins/commands/shop/index.ts b/src/plugins/commands/shop/index.ts index 2db7112..1da2442 100644 --- a/src/plugins/commands/shop/index.ts +++ b/src/plugins/commands/shop/index.ts @@ -16,6 +16,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.cpgg.builder) .addSubcommandGroup(modules.roles.builder); +// Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; diff --git a/src/plugins/commands/utility/index.ts b/src/plugins/commands/utility/index.ts index 6ccdc81..fb87528 100644 --- a/src/plugins/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -13,6 +13,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.avatar.builder) .addSubcommand(modules.ping.builder); +// Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "about":