From dc8c0ab570aea35c37d015b1400e2bb51b24b0d1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 13:51:07 +0200 Subject: [PATCH 01/23] WIP: help command --- src/commands/misc/help.ts | 34 ++++++++++++++++++++++++++++++++++ src/locales/fr.json | 5 ++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/commands/misc/help.ts diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts new file mode 100644 index 0000000..6a8a109 --- /dev/null +++ b/src/commands/misc/help.ts @@ -0,0 +1,34 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import { Client, CommandInteraction, MessageEmbed } from 'discord.js'; +import { getLocale, getLocalizations } from '../../utils/locales'; +import { getFilename } from '../../utils/misc'; + +export default { + data: (client: Client) => { + const filename = getFilename(__filename); + return new SlashCommandBuilder() + .setName(filename.toLowerCase()) + .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '?') + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); + }, + + interaction: async (interaction: CommandInteraction, client: Client) => { + const loc = getLocale(client, interaction.locale); + const command_name = interaction.options.getString('command'); + + // If a command is specified + if (command_name) { + // Check if command exists + interaction.reply({ content: 'WIP', ephemeral: true }); + } else { + const embed = new MessageEmbed() + .setColor('BLURPLE') + .setTitle(loc.get('c_help1')) + .setDescription(loc.get('c_help2')) + .addField('WIP', 'WIP'); + + interaction.reply({ embeds: [embed] }); + } + }, +}; diff --git a/src/locales/fr.json b/src/locales/fr.json index 24f0dbe..af66a14 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -3,5 +3,8 @@ "c_ping_desc": "Pong!", "c_ping1": "Latence totale", - "c_ping2": "Latence du Websocket" + "c_ping2": "Latence du Websocket", + + "c_help1": "Liste des catégories et des commandes associées", + "c_help2": "`/help ` pour obtenir plus d'informations sur une commande." } -- 2.45.2 From e15176123e64b462bfb488bc9cc8178eceda7fb5 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 14:07:15 +0200 Subject: [PATCH 02/23] Use Array --- src/commands/misc/help.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 6a8a109..0031661 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -22,13 +22,19 @@ export default { // Check if command exists interaction.reply({ content: 'WIP', ephemeral: true }); } else { - const embed = new MessageEmbed() - .setColor('BLURPLE') - .setTitle(loc.get('c_help1')) - .setDescription(loc.get('c_help2')) - .addField('WIP', 'WIP'); + const fields = []; + fields.push({ + name: 'WIP', + value: 'WIP', + }); - interaction.reply({ embeds: [embed] }); + interaction.reply({ embeds: [ + new MessageEmbed() + .setColor('BLURPLE') + .setTitle(loc.get('c_help1')) + .setDescription(loc.get('c_help2')) + .addFields(fields), + ] }); } }, }; -- 2.45.2 From c39826ead3c2038f47727d17a0b6e825f3b7a8f1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 14:07:50 +0200 Subject: [PATCH 03/23] remove "?" --- src/commands/misc/help.ts | 2 +- src/commands/misc/ping.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 0031661..3540301 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -8,7 +8,7 @@ export default { const filename = getFilename(__filename); return new SlashCommandBuilder() .setName(filename.toLowerCase()) - .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '?') + .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') .setNameLocalizations(getLocalizations(client, `c_${filename}_name`)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, diff --git a/src/commands/misc/ping.ts b/src/commands/misc/ping.ts index 26b586e..aacb29f 100644 --- a/src/commands/misc/ping.ts +++ b/src/commands/misc/ping.ts @@ -8,7 +8,7 @@ export default { const filename = getFilename(__filename); return new SlashCommandBuilder() .setName(filename.toLowerCase()) - .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '?') + .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') .setNameLocalizations(getLocalizations(client, `c_${filename}_name`)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, -- 2.45.2 From a8ce8faf069194953c15e34e6c7a1a70f95fcb47 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 14:18:19 +0200 Subject: [PATCH 04/23] 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); -- 2.45.2 From b085539b48cdaa7e0c63fc242550098b8fa4d78c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:42:25 +0200 Subject: [PATCH 05/23] ability to lowercase output for names --- src/utils/locales.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/locales.ts b/src/utils/locales.ts index c82f291..12c0b84 100644 --- a/src/utils/locales.ts +++ b/src/utils/locales.ts @@ -53,18 +53,21 @@ export const loadLocales = async (default_lang: string) => { * @param text Name of string to fetch * @returns the dictionary */ -export const getLocalizations = (client: Client, text: string) => { +export const getLocalizations = (client: Client, text: string, lowercase = false) => { const data: Record = {}; // Load all the localizations client.locales.forEach((locale, lang) => { // Fetch the text and fallback to default lang if needed // See getLocale for more info on why we *can* fallback - const str = locale.get(text) + let str = locale.get(text) ?? client.locales.get(client.config.default_lang)?.get(text); // Store it if defined if (str !== undefined) { + if (lowercase) { + str = str.toLowerCase(); + } data[lang] = str; } }); -- 2.45.2 From 62e61df3d0674a71a998f43aefb577558e473b69 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:42:40 +0200 Subject: [PATCH 06/23] lowercase name localization --- src/commands/misc/ping.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/misc/ping.ts b/src/commands/misc/ping.ts index aacb29f..d9df2ad 100644 --- a/src/commands/misc/ping.ts +++ b/src/commands/misc/ping.ts @@ -9,7 +9,7 @@ export default { return new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') - .setNameLocalizations(getLocalizations(client, `c_${filename}_name`)) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, -- 2.45.2 From fdbbbe6957a7f63f6db19250db5f177b923f9b1a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:42:55 +0200 Subject: [PATCH 07/23] fix typo --- src/events/interactions/interactionCreate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/interactions/interactionCreate.ts b/src/events/interactions/interactionCreate.ts index 525a29a..f4b57bd 100644 --- a/src/events/interactions/interactionCreate.ts +++ b/src/events/interactions/interactionCreate.ts @@ -4,7 +4,7 @@ import { getLocale } from '../../utils/locales'; /** 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); + const command = client.commands.list.get(interaction.commandName); if (!command) { const loc = getLocale(client, interaction.locale); return interaction.reply({ -- 2.45.2 From f1622fa7e460330cf7c8d8b53a01923ffa87e8b6 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:43:06 +0200 Subject: [PATCH 08/23] Add names and desc of missing commands --- src/locales/fr.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/locales/fr.json b/src/locales/fr.json index af66a14..e2aa802 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -1,10 +1,13 @@ { "e_interacreate_no_command": "Désolé, la commande n'existe plus...", + "c_ping_name": "Ping", "c_ping_desc": "Pong!", "c_ping1": "Latence totale", "c_ping2": "Latence du Websocket", + "c_help_name": "Help", + "c_help_desc": "Aide", "c_help1": "Liste des catégories et des commandes associées", "c_help2": "`/help ` pour obtenir plus d'informations sur une commande." } -- 2.45.2 From 743d6eb47128e3e2be8c00454c1b50cbd85d78d1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:43:20 +0200 Subject: [PATCH 09/23] specify that data need the client --- src/utils/client.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/client.ts b/src/utils/client.ts index 08f6ee4..b5ed128 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -29,7 +29,7 @@ declare module 'discord.js' { /** Command itself */ { /** Data about the command */ - data: SlashCommandBuilder, + data(client: Client): SlashCommandBuilder, /** How the command interact */ interaction: (interaction: CommandInteraction, client: Client) => unknown } @@ -54,8 +54,10 @@ export default async () => { default_lang: process.env.DEFAULT_LANG ?? 'fr', }; - client.commands.categories = new Collection(); - client.commands.list = new Collection(); + client.commands = { + categories: new Collection(), + list: new Collection(), + }; console.log('Translations progression :'); client.locales = await loadLocales(client.config.default_lang); -- 2.45.2 From 33dd6cfc1775cd5f73e094869279f177736e9a65 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:45:48 +0200 Subject: [PATCH 10/23] update translation --- src/locales/fr.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/locales/fr.json b/src/locales/fr.json index e2aa802..fef931f 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -9,5 +9,6 @@ "c_help_name": "Help", "c_help_desc": "Aide", "c_help1": "Liste des catégories et des commandes associées", - "c_help2": "`/help ` pour obtenir plus d'informations sur une commande." + "c_help2": "`/help ` pour obtenir plus d'informations sur une commande.", + "c_help3": "Pas d'information." } -- 2.45.2 From a85789830001e1c4b34cd0e72011119a14ddfc04 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:46:01 +0200 Subject: [PATCH 11/23] show categories, commands name and desc --- src/commands/misc/help.ts | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 3540301..47af03f 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -9,23 +9,41 @@ export default { return new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') - .setNameLocalizations(getLocalizations(client, `c_${filename}_name`)) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, interaction: async (interaction: CommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); - const command_name = interaction.options.getString('command'); + const desired_command = interaction.options.getString('command'); // If a command is specified - if (command_name) { + if (desired_command) { // Check if command exists interaction.reply({ content: 'WIP', ephemeral: true }); } else { - const fields = []; - fields.push({ - name: 'WIP', - value: 'WIP', + const fields: { + name: string; + value: string; + }[] = []; + + client.commands.categories.forEach((commands_name, category) => { + const commands_description = commands_name.reduce((compteur, command_name) => { + const command = client.commands.list.get(command_name); + let res = `${compteur}- \`${command_name}\` : `; + if (command?.data) { + res += `${command.data(client).description}.\n`; + } else { + res += loc.get('c_help3'); + } + + return res; + }, ''); + + fields.push({ + name: category, + value: commands_description, + }); }); interaction.reply({ embeds: [ -- 2.45.2 From 86c074c7bee3c20e155be9afec13c5b751c5c473 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:49:20 +0200 Subject: [PATCH 12/23] optimization --- src/commands/loader.ts | 5 +++-- src/commands/misc/help.ts | 2 +- src/utils/client.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/loader.ts b/src/commands/loader.ts index 65f0ed0..a342ac8 100644 --- a/src/commands/loader.ts +++ b/src/commands/loader.ts @@ -32,9 +32,10 @@ export default async (client: Client) => { ).default; // Add it to the collection so the interaction will work - client.commands.list.set(command.data(client).name, command); + command.data = command.data(client); + client.commands.list.set(command.data.name, command); - return command.data(client).toJSON(); + return command.data.toJSON(); }), ); }), diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 47af03f..fb3e870 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -32,7 +32,7 @@ export default { const command = client.commands.list.get(command_name); let res = `${compteur}- \`${command_name}\` : `; if (command?.data) { - res += `${command.data(client).description}.\n`; + res += `${command.data.description}.\n`; } else { res += loc.get('c_help3'); } diff --git a/src/utils/client.ts b/src/utils/client.ts index b5ed128..2176192 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -29,7 +29,7 @@ declare module 'discord.js' { /** Command itself */ { /** Data about the command */ - data(client: Client): SlashCommandBuilder, + data: SlashCommandBuilder, /** How the command interact */ interaction: (interaction: CommandInteraction, client: Client) => unknown } -- 2.45.2 From 2c276649791ee5556e18fdf85dc48a47a10556c4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 15:53:13 +0200 Subject: [PATCH 13/23] newline --- src/commands/misc/help.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index fb3e870..bda1b79 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -34,7 +34,7 @@ export default { if (command?.data) { res += `${command.data.description}.\n`; } else { - res += loc.get('c_help3'); + res += `${loc.get('c_help3')}\n`; } return res; -- 2.45.2 From fe7b0ad5d77c0a6921a914ab5a1429ca45a9c4c8 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 16:27:52 +0200 Subject: [PATCH 14/23] update translations --- src/locales/en-US.json | 11 ++++++++++- src/locales/fr.json | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/locales/en-US.json b/src/locales/en-US.json index fe704bf..0088ee7 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -1,7 +1,16 @@ { "e_interacreate_no_command": "Sorry, the command probably no longer exists...", + "c_ping_name": "Ping", "c_ping_desc": "Pong!", "c_ping1": "Roundtrip latency", - "c_ping2": "Websocket heartbeat" + "c_ping2": "Websocket heartbeat", + + "c_help_name": "Help", + "c_help_desc": "Informations about commands", + "c_help_opt1_name": "command", + "c_help_opt1_desc": "Command wanted in depth.", + "c_help1": "List of categories and associated commands", + "c_help2": "`/help ` to get more information about a command.", + "c_help3": "No information available." } diff --git a/src/locales/fr.json b/src/locales/fr.json index fef931f..195b415 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -6,8 +6,10 @@ "c_ping1": "Latence totale", "c_ping2": "Latence du Websocket", - "c_help_name": "Help", - "c_help_desc": "Aide", + "c_help_name": "Aide", + "c_help_desc": "Informations sur les commandes", + "c_help_opt1_name": "commande", + "c_help_opt1_desc": "Commande voulu en détail.", "c_help1": "Liste des catégories et des commandes associées", "c_help2": "`/help ` pour obtenir plus d'informations sur une commande.", "c_help3": "Pas d'information." -- 2.45.2 From b3fb838920cbc52cc44056825f5a31babe484a8c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 16:28:26 +0200 Subject: [PATCH 15/23] support argument --- src/commands/misc/help.ts | 56 ++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index bda1b79..9385f57 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; +import { Locale } from 'discord-api-types/v9'; import { Client, CommandInteraction, MessageEmbed } from 'discord.js'; import { getLocale, getLocalizations } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; @@ -7,15 +8,32 @@ export default { data: (client: Client) => { const filename = getFilename(__filename); return new SlashCommandBuilder() - .setName(filename.toLowerCase()) - .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') - .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) - .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); + .setName( + filename.toLowerCase()) + .setDescription(client.locales.get(client.config.default_lang) + ?.get(`c_${filename}_desc`) ?? '') + .setNameLocalizations( + getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations( + getLocalizations(client, `c_${filename}_desc`)) + .addStringOption(option => option + .setName(client.locales.get(client.config.default_lang) + ?.get(`c_${filename}_opt1_name`) ?? '') + .setDescription(client.locales.get(client.config.default_lang) + ?.get(`c_${filename}_opt1_desc`) ?? '') + .setNameLocalizations( + getLocalizations(client, `c_${filename}_opt1_name`, true)) + .setDescriptionLocalizations( + getLocalizations(client, `c_${filename}_opt1_desc`)) + ); }, interaction: async (interaction: CommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); - const desired_command = interaction.options.getString('command'); + const desired_command = interaction.options.getString(client + .locales + .get(client.config.default_lang) + ?.get(`c_${getFilename(__filename)}_opt1_name`) ?? ''); // If a command is specified if (desired_command) { @@ -28,20 +46,26 @@ export default { }[] = []; client.commands.categories.forEach((commands_name, category) => { - const commands_description = commands_name.reduce((compteur, command_name) => { - const command = client.commands.list.get(command_name); - let res = `${compteur}- \`${command_name}\` : `; - if (command?.data) { - res += `${command.data.description}.\n`; - } else { - res += `${loc.get('c_help3')}\n`; - } + const commands_description = commands_name.reduce( + (compteur, command_name) => { + const command = client.commands.list.get(command_name); + let res = `${compteur}- \`${command_name}\` : `; + if (command?.data) { + const description = + command.data.description_localizations + ?.[interaction.locale as Locale] + ?? command.data.description; - return res; - }, ''); + res += `${description}\n`; + } else { + res += `${loc.get('c_help3')}\n`; + } + + return res; + }, ''); fields.push({ - name: category, + name: category.toUpperCase(), value: commands_description, }); }); -- 2.45.2 From b3d8755b7ddf8fdd65d212fb0c795bb2c8a42204 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 16:29:48 +0200 Subject: [PATCH 16/23] apply new style --- src/commands/misc/ping.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commands/misc/ping.ts b/src/commands/misc/ping.ts index d9df2ad..9f56312 100644 --- a/src/commands/misc/ping.ts +++ b/src/commands/misc/ping.ts @@ -7,16 +7,24 @@ export default { data: (client: Client) => { const filename = getFilename(__filename); return new SlashCommandBuilder() - .setName(filename.toLowerCase()) - .setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '') - .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) - .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); + .setName( + filename.toLowerCase()) + .setDescription(client.locales.get(client.config.default_lang) + ?.get(`c_${filename}_desc`) ?? '') + .setNameLocalizations( + getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations( + getLocalizations(client, `c_${filename}_desc`) + ); }, interaction: async (interaction: CommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); - const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true }) as Message; + const sent = await interaction.reply({ + content: 'Pinging...', + fetchReply: true, + }) as Message; interaction.editReply( `${loc?.get('c_ping1')}: \ -- 2.45.2 From 9ed2138babbb8a7f34cea69381a5d35151ec98ab Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 23:45:39 +0200 Subject: [PATCH 17/23] add string extension for capitalize string --- src/modules/string.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/modules/string.ts diff --git a/src/modules/string.ts b/src/modules/string.ts new file mode 100644 index 0000000..01bbe12 --- /dev/null +++ b/src/modules/string.ts @@ -0,0 +1,16 @@ +export {}; + +declare global { + // Declarations + interface String { + /** + * Returns a copy of the string with the first letter capitalized. + */ + capitalize(): string, + } +} + +/** Capitalize definition */ +String.prototype.capitalize = function(this: string) { + return this[0].toUpperCase() + this.substring(1); +}; -- 2.45.2 From 2f9053bcc914a779d4d96362d4f0c16d28229911 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 24 Jul 2022 23:45:45 +0200 Subject: [PATCH 18/23] capitalize instead of uppercase --- src/commands/misc/help.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 9385f57..173329c 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -3,6 +3,7 @@ import { Locale } from 'discord-api-types/v9'; import { Client, CommandInteraction, MessageEmbed } from 'discord.js'; import { getLocale, getLocalizations } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; +import '../../modules/string'; export default { data: (client: Client) => { @@ -65,7 +66,7 @@ export default { }, ''); fields.push({ - name: category.toUpperCase(), + name: category.capitalize(), value: commands_description, }); }); -- 2.45.2 From 2385520980c5e717968df63d08abd737cda1130c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 25 Jul 2022 00:14:15 +0200 Subject: [PATCH 19/23] update translation --- src/locales/fr.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/locales/fr.json b/src/locales/fr.json index 195b415..58fdaac 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -12,5 +12,6 @@ "c_help_opt1_desc": "Commande voulu en détail.", "c_help1": "Liste des catégories et des commandes associées", "c_help2": "`/help ` pour obtenir plus d'informations sur une commande.", - "c_help3": "Pas d'information." + "c_help3": "Pas d'information.", + "c_help4": "Impossible de trouver :" } -- 2.45.2 From adad5db3645b45ea2b1a4468f19f6ee0e1d0811a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 25 Jul 2022 00:14:29 +0200 Subject: [PATCH 20/23] add info about one command --- src/commands/misc/help.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 173329c..e484a54 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -17,6 +17,7 @@ export default { getLocalizations(client, `c_${filename}_name`, true)) .setDescriptionLocalizations( getLocalizations(client, `c_${filename}_desc`)) + .addStringOption(option => option .setName(client.locales.get(client.config.default_lang) ?.get(`c_${filename}_opt1_name`) ?? '') @@ -36,11 +37,8 @@ export default { .get(client.config.default_lang) ?.get(`c_${getFilename(__filename)}_opt1_name`) ?? ''); - // If a command is specified - if (desired_command) { - // Check if command exists - interaction.reply({ content: 'WIP', ephemeral: true }); - } else { + // If a command isn't specified + if (!desired_command) { const fields: { name: string; value: string; @@ -48,21 +46,21 @@ export default { client.commands.categories.forEach((commands_name, category) => { const commands_description = commands_name.reduce( - (compteur, command_name) => { + (data, command_name) => { const command = client.commands.list.get(command_name); - let res = `${compteur}- \`${command_name}\` : `; + data += `- \`/${command?.data.name}\` : `; if (command?.data) { const description = command.data.description_localizations ?.[interaction.locale as Locale] ?? command.data.description; - res += `${description}\n`; + data += `${description}\n`; } else { - res += `${loc.get('c_help3')}\n`; + data += `${loc.get('c_help3')}\n`; } - return res; + return data; }, ''); fields.push({ @@ -71,7 +69,7 @@ export default { }); }); - interaction.reply({ embeds: [ + return interaction.reply({ embeds: [ new MessageEmbed() .setColor('BLURPLE') .setTitle(loc.get('c_help1')) @@ -79,5 +77,21 @@ export default { .addFields(fields), ] }); } + + // If a command is specified + const command = client.commands.list.get(desired_command); + if (!command) { + return interaction.reply({ + content: `${loc.get('c_help4')} \`${desired_command}\``, + ephemeral: true, + }); + } + + return interaction.reply({ embeds: [ + new MessageEmbed() + .setColor('BLURPLE') + .setTitle('`/' + command.data.name + '`') + .setDescription(command.data.description), + ] }); }, }; -- 2.45.2 From 64f61e35e86194a917150ae08bafa6d041475210 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 25 Jul 2022 00:26:03 +0200 Subject: [PATCH 21/23] add comments --- src/commands/misc/help.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index e484a54..bba0cbf 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -18,6 +18,7 @@ export default { .setDescriptionLocalizations( getLocalizations(client, `c_${filename}_desc`)) + // Command option .addStringOption(option => option .setName(client.locales.get(client.config.default_lang) ?.get(`c_${filename}_opt1_name`) ?? '') @@ -44,12 +45,16 @@ export default { value: string; }[] = []; + // Load all the command per categories client.commands.categories.forEach((commands_name, category) => { const commands_description = commands_name.reduce( (data, command_name) => { const command = client.commands.list.get(command_name); - data += `- \`/${command?.data.name}\` : `; + data += `- \`/${command_name}\` : `; + // If the command is correct, usually it is if (command?.data) { + // Loads the description + // according to the user's locals const description = command.data.description_localizations ?.[interaction.locale as Locale] @@ -57,9 +62,12 @@ export default { data += `${description}\n`; } else { + // Error message data += `${loc.get('c_help3')}\n`; } + // TODO: Check that `data` does not exceed + // the maximum character limit return data; }, ''); @@ -69,6 +77,7 @@ export default { }); }); + // Sends a list of commands sorted into categories return interaction.reply({ embeds: [ new MessageEmbed() .setColor('BLURPLE') @@ -81,12 +90,14 @@ export default { // If a command is specified const command = client.commands.list.get(desired_command); if (!command) { + // Command don't exist return interaction.reply({ content: `${loc.get('c_help4')} \`${desired_command}\``, ephemeral: true, }); } + // Send information about the command return interaction.reply({ embeds: [ new MessageEmbed() .setColor('BLURPLE') -- 2.45.2 From 0985da60fba1a5dbfc847f569c0cce62bf05128d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 25 Jul 2022 00:37:43 +0200 Subject: [PATCH 22/23] update translations --- src/locales/en-US.json | 2 +- src/locales/fr.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 0088ee7..6f0439a 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -12,5 +12,5 @@ "c_help_opt1_desc": "Command wanted in depth.", "c_help1": "List of categories and associated commands", "c_help2": "`/help ` to get more information about a command.", - "c_help3": "No information available." + "c_help3": "Can't find :" } diff --git a/src/locales/fr.json b/src/locales/fr.json index 58fdaac..cad1fba 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -12,6 +12,5 @@ "c_help_opt1_desc": "Commande voulu en détail.", "c_help1": "Liste des catégories et des commandes associées", "c_help2": "`/help ` pour obtenir plus d'informations sur une commande.", - "c_help3": "Pas d'information.", - "c_help4": "Impossible de trouver :" + "c_help3": "Impossible de trouver :" } -- 2.45.2 From 787a4a2abdb5cbe25682a0405b27eaa8849b28f7 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 25 Jul 2022 00:38:14 +0200 Subject: [PATCH 23/23] keep only names in help command and show desc in detailed vue --- src/commands/misc/help.ts | 40 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index bba0cbf..2bfca41 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -47,33 +47,13 @@ export default { // Load all the command per categories client.commands.categories.forEach((commands_name, category) => { - const commands_description = commands_name.reduce( - (data, command_name) => { - const command = client.commands.list.get(command_name); - data += `- \`/${command_name}\` : `; - // If the command is correct, usually it is - if (command?.data) { - // Loads the description - // according to the user's locals - const description = - command.data.description_localizations - ?.[interaction.locale as Locale] - ?? command.data.description; - - data += `${description}\n`; - } else { - // Error message - data += `${loc.get('c_help3')}\n`; - } - - // TODO: Check that `data` does not exceed - // the maximum character limit - return data; - }, ''); + const commands = commands_name.reduce((data, command_name) => { + return data + `\`/${command_name}\`, `; + }, ''); fields.push({ - name: category.capitalize(), - value: commands_description, + name: category.capitalize() + ` (${commands_name.length})`, + value: commands.slice(0, -2), }); }); @@ -92,7 +72,7 @@ export default { if (!command) { // Command don't exist return interaction.reply({ - content: `${loc.get('c_help4')} \`${desired_command}\``, + content: `${loc.get('c_help3')} \`${desired_command}\``, ephemeral: true, }); } @@ -102,7 +82,13 @@ export default { new MessageEmbed() .setColor('BLURPLE') .setTitle('`/' + command.data.name + '`') - .setDescription(command.data.description), + .setDescription( + // Loads the description + // according to the user's locals + command.data.description_localizations + ?.[interaction.locale as Locale] + ?? command.data.description + ), ] }); }, }; -- 2.45.2