🧑‍💻 Fixed some more code smells

This commit is contained in:
Axel Olausson Holtenäs 2022-10-16 14:50:59 +02:00
parent 3333063a47
commit 6a5d480438
4 changed files with 22 additions and 42 deletions

View file

@ -18,11 +18,17 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
// Destructure
const { options } = interaction;
if (options?.getSubcommandGroup() === "credits") {
return modules.credits.execute(interaction);
switch (options.getSubcommandGroup()) {
case "credits": {
await modules.credits.execute(interaction);
break;
}
case "counters": {
await modules.counters.execute(interaction);
break;
}
default: {
throw new Error("Could not find an module for the command.");
}
if (options?.getSubcommandGroup() === "counters") {
return modules.counters.execute(interaction);
}
};

View file

@ -6,7 +6,7 @@ import {
ButtonStyle,
ChatInputCommandInteraction,
EmbedBuilder,
Message,
Message
} from "discord.js";
import { v4 as uuidv4 } from "uuid";
import encryption from "../../../../../helpers/encryption";
@ -206,35 +206,13 @@ export default {
});
})
.catch(async (error) => {
logger?.silly(`Error saving new credits. - ${error}`);
const interactionEmbed = new EmbedBuilder()
.setTitle("[:shopping_cart:] CPGG")
.setDescription(`Something went wrong.`)
.setTimestamp()
.setColor(errorColor)
.setFooter({ text: footerText, iconURL: footerIcon });
return interaction?.editReply({
embeds: [interactionEmbed],
});
.catch(() => {
throw new Error("Failed to update credits for user.")
});
})
.catch(async (error) => {
logger?.silly(`Error creating voucher. - ${error}`);
const interactionEmbed = new EmbedBuilder()
.setTitle("[:shopping_cart:] CPGG")
.setDescription(`Something went wrong.`)
.setTimestamp()
.setColor(errorColor)
.setFooter({ text: footerText, iconURL: footerIcon });
return interaction?.editReply({
embeds: [interactionEmbed],
});
.catch(() => {
throw new Error("Failed generating an voucher.")
});
},
};

View file

@ -5,7 +5,7 @@ import {
ChatInputCommandInteraction,
ColorResolvable,
EmbedBuilder,
GuildMemberRoleManager,
GuildMemberRoleManager
} from "discord.js";
// Configurations
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
@ -110,8 +110,8 @@ export default {
embeds: [interactionEmbed],
});
})
.catch(async (error) => {
return logger?.silly(`Role could not be created. ${error}`);
.catch(() => {
throw new Error("Failed creating role.")
});
},
};

View file

@ -1,7 +1,6 @@
import { ChannelType, Message } from "discord.js";
import logger from "../../../../../middlewares/logger";
import counterSchema from "../../../../../models/counter";
import logger from "../../../../../middlewares/logger";
export default {
execute: async (message: Message) => {
@ -23,10 +22,7 @@ export default {
});
if (counter === null) {
logger.silly(
`No counter found for guild ${guildId} and channel ${channelId}`
);
return;
throw new Error("No counter found in database.");
}
if (
@ -57,7 +53,7 @@ export default {
`Counter for guild ${guildId} and channel ${channelId} is now ${counter.counter}`
);
})
.catch((err) => {
.catch(() => {
throw new Error(`Error saving counter to database.`);
});