Store data about categories + comments

This commit is contained in:
Mylloon 2022-07-24 14:18:19 +02:00
parent c39826ead3
commit a8ce8faf06
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 29 additions and 9 deletions

View file

@ -2,6 +2,7 @@ import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9'; import { Routes } from 'discord-api-types/v9';
import { Client } from 'discord.js'; import { Client } from 'discord.js';
import { readdir } from 'fs/promises'; import { readdir } from 'fs/promises';
import { removeExtension } from '../utils/misc';
/** Load all the commands. */ /** Load all the commands. */
export default async (client: Client) => { export default async (client: Client) => {
@ -17,6 +18,12 @@ export default async (client: Client) => {
// Retrieve all the commands // Retrieve all the commands
const command_files = await readdir(`${__dirname}/${command_category}`); 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 // Add the command
return Promise.all( return Promise.all(
command_files.map(async command_file => { command_files.map(async command_file => {
@ -25,7 +32,7 @@ export default async (client: Client) => {
).default; ).default;
// Add it to the collection so the interaction will work // 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(); return command.data(client).toJSON();
}), }),

View file

@ -16,13 +16,25 @@ declare module 'discord.js' {
default_lang: string default_lang: string
}, },
/** Store all the slash commands */ /** Store all the slash commands */
commands: Collection< commands: {
string, categories: Collection<
{ /** Category name */
data: SlashCommandBuilder, string,
interaction: (interaction: CommandInteraction, client: Client) => unknown /** 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 */ /** Store all the localizations */
locales: Map<string, Map<string, string>> locales: Map<string, Map<string, string>>
} }
@ -42,7 +54,8 @@ export default async () => {
default_lang: process.env.DEFAULT_LANG ?? 'fr', 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 :'); console.log('Translations progression :');
client.locales = await loadLocales(client.config.default_lang); client.locales = await loadLocales(client.config.default_lang);