Merge pull request #421 from VermiumSifell/dev
🧑💻 Fixed some code smells
This commit is contained in:
commit
7676b7c99f
5 changed files with 14 additions and 40 deletions
|
@ -23,10 +23,6 @@ export const register = async (client: Client) => {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`📦 No command builder found while importing "${commandName}"`
|
`📦 No command builder found while importing "${commandName}"`
|
||||||
);
|
);
|
||||||
if (!command.execute)
|
|
||||||
throw new Error(
|
|
||||||
`📦 No command execute found while importing "${commandName}"`
|
|
||||||
);
|
|
||||||
if (!command.moduleData)
|
if (!command.moduleData)
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`📦 No command moduleData found while importing "${commandName}"`
|
`📦 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
|
// Send log message when it's done loading commands
|
||||||
const doneImporting = async () => {
|
const doneImporting = () => {
|
||||||
if (importedCommandAmount !== amountOfCommands) {
|
if (importedCommandAmount !== amountOfCommands) {
|
||||||
return logger.warn(
|
return logger.warn(
|
||||||
`📦 Failed importing ${
|
`📦 Failed importing ${
|
||||||
|
@ -52,12 +48,8 @@ export const register = async (client: Client) => {
|
||||||
|
|
||||||
// Start importing commands
|
// Start importing commands
|
||||||
commandNames.forEach(async (commandName: string, index: number) => {
|
commandNames.forEach(async (commandName: string, index: number) => {
|
||||||
await importCommand(commandName)
|
await importCommand(commandName).then(() => {
|
||||||
.then(async () => {
|
|
||||||
logger.debug(`📦 Imported the "${commandName}" command`);
|
logger.debug(`📦 Imported the "${commandName}" command`);
|
||||||
})
|
|
||||||
.catch(async (err) => {
|
|
||||||
logger.error(err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// If done importing
|
// If done importing
|
||||||
|
|
|
@ -4,6 +4,7 @@ import listDir from "../../helpers/checkDirectory";
|
||||||
import { IEvent } from "../../interfaces/Event";
|
import { IEvent } from "../../interfaces/Event";
|
||||||
import logger from "../../middlewares/logger";
|
import logger from "../../middlewares/logger";
|
||||||
|
|
||||||
|
// Registers all available events
|
||||||
export const register = async (client: Client) => {
|
export const register = async (client: Client) => {
|
||||||
const eventNames = await listDir("plugins/events");
|
const eventNames = await listDir("plugins/events");
|
||||||
if (!eventNames) throw new Error("📦 No events available");
|
if (!eventNames) throw new Error("📦 No events available");
|
||||||
|
@ -28,7 +29,7 @@ export const register = async (client: Client) => {
|
||||||
|
|
||||||
// Register event
|
// Register event
|
||||||
const eventExecutor = async (...args: Promise<void>[]) => {
|
const eventExecutor = async (...args: Promise<void>[]) => {
|
||||||
await event.execute(...args).catch(async (err) => {
|
await event.execute(...args).catch((err) => {
|
||||||
logger.error(`${err}`);
|
logger.error(`${err}`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -44,12 +45,14 @@ export const register = async (client: Client) => {
|
||||||
case "on":
|
case "on":
|
||||||
client.on(eventName, eventExecutor);
|
client.on(eventName, eventExecutor);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
logger.error(`${eventName} does not have a valid type`);
|
||||||
}
|
}
|
||||||
importedEventAmount += 1;
|
importedEventAmount += 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send log message when it's done loading events
|
// Send log message when it's done loading events
|
||||||
const doneImporting = async () => {
|
const doneImporting = () => {
|
||||||
if (importedEventAmount !== amountOfEvents) {
|
if (importedEventAmount !== amountOfEvents) {
|
||||||
return logger.warn(
|
return logger.warn(
|
||||||
`📦 Failed importing ${
|
`📦 Failed importing ${
|
||||||
|
@ -62,7 +65,7 @@ export const register = async (client: Client) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
eventNames.forEach(async (eventName: string, index: number) => {
|
eventNames.forEach(async (eventName: string, index: number) => {
|
||||||
await importEvent(eventName).then(async () => {
|
await importEvent(eventName).then(() => {
|
||||||
logger.debug(`📦 Imported the "${eventName}" event`);
|
logger.debug(`📦 Imported the "${eventName}" event`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,6 @@ export default {
|
||||||
channelId: discordChannel.id,
|
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");
|
if (!counter) throw new Error("No counter found for channel");
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
|
|
|
@ -207,24 +207,13 @@ export default {
|
||||||
await toUser.save();
|
await toUser.save();
|
||||||
|
|
||||||
await session.commitTransaction();
|
await session.commitTransaction();
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
await session.abortTransaction();
|
await session.abortTransaction();
|
||||||
session.endSession();
|
session.endSession();
|
||||||
logger.error(`${error}`);
|
|
||||||
|
|
||||||
return interaction.editReply({
|
throw new Error(
|
||||||
embeds: [
|
"An error occurred while trying to gift credits. Please try again later."
|
||||||
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 }),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
// ending the session
|
// ending the session
|
||||||
session.endSession();
|
session.endSession();
|
||||||
|
|
|
@ -79,9 +79,6 @@ export default {
|
||||||
return interaction?.editReply({
|
return interaction?.editReply({
|
||||||
embeds: [interactionEmbed],
|
embeds: [interactionEmbed],
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch(async (error: Error) => {
|
|
||||||
return logger?.silly(`Role could not be deleted. ${error}`);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue