From b4176318ef31030ff34d43a148bdec4599a4b922 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 20 Jul 2022 23:44:38 +0200 Subject: [PATCH] * removes string repetition * translations * trim newlines * comments --- src/commands/loader.ts | 3 +++ src/events/client/ready.ts | 3 ++- src/events/interactions/interactionCreate.ts | 3 ++- src/events/loader.ts | 1 + src/index.ts | 24 ++++++++++++++------ src/utils/client.ts | 2 +- src/utils/misc.ts | 9 ++++++++ 7 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/utils/misc.ts diff --git a/src/commands/loader.ts b/src/commands/loader.ts index 476f7ac..9dd3e24 100644 --- a/src/commands/loader.ts +++ b/src/commands/loader.ts @@ -3,6 +3,7 @@ import { Routes } from 'discord-api-types/v9'; import { Client } from 'discord.js'; import { readdir } from 'fs/promises'; +/** Load all the commands */ export default async (client: Client) => { const rest = new REST({ version: '9' }).setToken(client.token ?? ''); @@ -23,6 +24,7 @@ export default async (client: Client) => { await import(`../commands/${command_category}/${command_file}`) ).default; + // Add it to the collection so the interaction will work client.commands.set(command.data.name, command); return command.data.toJSON(); @@ -32,6 +34,7 @@ export default async (client: Client) => { ) ).flat(2); + // Send commands to Discord return await rest.put(Routes.applicationCommands(client.user?.id ?? ''), { body: commands, }); diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index 083db66..4621ee6 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -1,5 +1,6 @@ export const once = true; +/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-ready */ export default async () => { - console.log('Connecté à Discord !'); + console.log('Connected to Discord!'); }; diff --git a/src/events/interactions/interactionCreate.ts b/src/events/interactions/interactionCreate.ts index 016e96a..70caa33 100644 --- a/src/events/interactions/interactionCreate.ts +++ b/src/events/interactions/interactionCreate.ts @@ -1,11 +1,12 @@ import { Client, Interaction } from 'discord.js'; +/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-interactionCreate */ export default (interaction: Interaction, client: Client) => { if (interaction.isCommand()) { const command = client.commands.get(interaction.commandName); if (!command) { return interaction.reply({ - content: 'Désolé la commande n\'existe probablement plus...', + content: 'Sorry, the command probably no longer exists...', ephemeral: true, }); } diff --git a/src/events/loader.ts b/src/events/loader.ts index 9a25194..15f2da0 100644 --- a/src/events/loader.ts +++ b/src/events/loader.ts @@ -1,6 +1,7 @@ import { Client } from 'discord.js'; import { readdir } from 'fs/promises'; +/** Load all the events */ export default async (client: Client) => { const events_categories = (await readdir(__dirname)) .filter(element => !element.endsWith('.js') && !element.endsWith('.ts')); diff --git a/src/index.ts b/src/index.ts index 96d5d20..1457e74 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,9 @@ import loadClient from './utils/client'; import loadEvents from './events/loader'; import loadCommands from './commands/loader'; +import { logStart } from './utils/misc'; + +/** Run the bot */ const run = async () => { console.log('Starting Botanique...'); @@ -13,27 +16,34 @@ const run = async () => { } // Client Discord.JS + const client_name = 'Client'; await loadClient() .then(async client => { - console.log('Client ✅'); + console.log(logStart(client_name, true)); + + // Events Discord.JS + const events_name = 'Events'; await loadEvents(client) - .then(() => console.log('Events ✅')) + .then(() => console.log(logStart(events_name, true))) .catch(() => { - throw 'Events ❌'; + throw logStart(events_name, false); }); + // Connect the bot to Discord.com await client.login(client.config.token_discord); + // Commands Slash Discord.JS + const commands_name = 'Commands'; await loadCommands(client) - .then(() => console.log('Commands ✅')) + .then(() => console.log(logStart(commands_name, true))) .catch(() => { - throw 'Commands ❌'; + throw logStart(commands_name, false); }); - console.log(`Botanique "${client.user?.username}" ${client.config.version} started!`); + console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`); }) .catch(() => { - throw 'Client ❌'; + throw logStart(client_name, false); }); }; diff --git a/src/utils/client.ts b/src/utils/client.ts index 53069fa..9a60300 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -21,7 +21,7 @@ declare module 'discord.js' { } } -// Création du client et de ses propriétés +/** Creation of the client and definition of its properties */ export default async () => { const client: Client = new Client({ intents: [ diff --git a/src/utils/misc.ts b/src/utils/misc.ts new file mode 100644 index 0000000..11eda8a --- /dev/null +++ b/src/utils/misc.ts @@ -0,0 +1,9 @@ +/** + * Log module status + * @param {string} name Module name + * @param {boolean} status Module status + * @returns String + */ +export const logStart = (name: string, status: boolean) => { + return `> ${name} ${status === true ? '✅' : '❌'}`; +}; -- 2.45.2