Merge pull request #421 from VermiumSifell/dev

🧑‍💻 Fixed some code smells
This commit is contained in:
Axel Olausson Holtenäs 2022-10-14 11:45:25 +02:00 committed by GitHub
commit 7676b7c99f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 40 deletions

View file

@ -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}"`
@ -38,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 ${
@ -52,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) {

View file

@ -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");
@ -28,7 +29,7 @@ export const register = async (client: Client) => {
// Register event
const eventExecutor = async (...args: Promise<void>[]) => {
await event.execute(...args).catch(async (err) => {
await event.execute(...args).catch((err) => {
logger.error(`${err}`);
});
};
@ -44,12 +45,14 @@ 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;
};
// Send log message when it's done loading events
const doneImporting = async () => {
const doneImporting = () => {
if (importedEventAmount !== amountOfEvents) {
return logger.warn(
`📦 Failed importing ${
@ -62,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`);
});

View file

@ -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({

View file

@ -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();

View file

@ -79,9 +79,6 @@ export default {
return interaction?.editReply({
embeds: [interactionEmbed],
});
})
.catch(async (error: Error) => {
return logger?.silly(`Role could not be deleted. ${error}`);
});
},
};