From a8ce8faf069194953c15e34e6c7a1a70f95fcb47 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 14:18:19 +0200 Subject: [PATCH] Store data about categories + comments --- src/commands/loader.ts | 9 ++++++++- src/utils/client.ts | 29 +++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/commands/loader.ts b/src/commands/loader.ts index c606616..65f0ed0 100644 --- a/src/commands/loader.ts +++ b/src/commands/loader.ts @@ -2,6 +2,7 @@ import { REST } from '@discordjs/rest'; import { Routes } from 'discord-api-types/v9'; import { Client } from 'discord.js'; import { readdir } from 'fs/promises'; +import { removeExtension } from '../utils/misc'; /** Load all the commands. */ export default async (client: Client) => { @@ -17,6 +18,12 @@ export default async (client: Client) => { // Retrieve all the commands const command_files = await readdir(`${__dirname}/${command_category}`); + // Add the category to the collection for the help command + client.commands.categories.set( + command_category, + command_files.map(removeExtension), + ); + // Add the command return Promise.all( command_files.map(async command_file => { @@ -25,7 +32,7 @@ export default async (client: Client) => { ).default; // Add it to the collection so the interaction will work - client.commands.set(command.data(client).name, command); + client.commands.list.set(command.data(client).name, command); return command.data(client).toJSON(); }), diff --git a/src/utils/client.ts b/src/utils/client.ts index 85baa4e..08f6ee4 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -16,13 +16,25 @@ declare module 'discord.js' { default_lang: string }, /** Store all the slash commands */ - commands: Collection< - string, - { - data: SlashCommandBuilder, - interaction: (interaction: CommandInteraction, client: Client) => unknown - } - >, + commands: { + categories: Collection< + /** Category name */ + string, + /** Name of the commands in the category */ + string[] + >, + list: Collection< + /** Command name */ + string, + /** Command itself */ + { + /** Data about the command */ + data: SlashCommandBuilder, + /** How the command interact */ + interaction: (interaction: CommandInteraction, client: Client) => unknown + } + >, + } /** Store all the localizations */ locales: Map> } @@ -42,7 +54,8 @@ export default async () => { default_lang: process.env.DEFAULT_LANG ?? 'fr', }; - client.commands = new Collection(); + client.commands.categories = new Collection(); + client.commands.list = new Collection(); console.log('Translations progression :'); client.locales = await loadLocales(client.config.default_lang);