chore: merge branch dev to main #200

Merged
Anri merged 19 commits from dev into main 2024-11-02 17:36:38 +01:00
2 changed files with 36 additions and 10 deletions
Showing only changes of commit 8703be8cd9 - Show all commits

View file

@ -9,6 +9,7 @@ import {
import "../../modules/string"; import "../../modules/string";
import { getLocale, getLocalizations } from "../../utils/locales"; import { getLocale, getLocalizations } from "../../utils/locales";
import { getFilename } from "../../utils/misc"; import { getFilename } from "../../utils/misc";
import { goodDescription, goodName } from "../../utils/commands/help";
export default { export default {
scope: () => [], scope: () => [],
@ -63,12 +64,16 @@ export default {
// Add subcommands // Add subcommands
const all_commands: string[] = []; const all_commands: string[] = [];
commands_name.forEach((command) => { commands_name.forEach((command) => {
const json = client.commands.list.get(command)?.data.toJSON(); const data = client.commands.list.get(command)?.data;
all_commands.push(command); const name = goodName(data!, interaction.locale);
all_commands.push(name);
json?.options data
?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) ?.toJSON()
.forEach((subcommand) => all_commands.push(command + " " + subcommand.name)); .options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand)
.forEach((subcommand) =>
all_commands.push(name + " " + goodName(subcommand, interaction.locale)),
);
}); });
const commands = all_commands.reduce( const commands = all_commands.reduce(
@ -111,12 +116,10 @@ export default {
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setColor(Colors.Blurple) .setColor(Colors.Blurple)
.setTitle("`/" + command.data.name + "`") .setTitle("`/" + goodName(command.data, interaction.locale) + "`")
.setDescription( .setDescription(
// Loads the description // Loads the description according to the user's locals
// according to the user's locals goodDescription(command.data, interaction.locale),
command.data.description_localizations?.[interaction.locale] ??
command.data.description,
), ),
], ],
}); });

View file

@ -0,0 +1,23 @@
import { APIApplicationCommandSubcommandOption, Locale, SlashCommandBuilder } from "discord.js";
/**
* Find the name of the command, trying to get the correct locale
* @param data Command data
* @param locale Locale wanted
* @returns Command's name
*/
export const goodName = (
data: SlashCommandBuilder | APIApplicationCommandSubcommandOption,
locale: Locale,
) => data.name_localizations?.[locale] ?? data.name;
/**
* Find the description of the command, trying to get the correct locale
* @param data Command data
* @param locale Locale wanted
* @returns Command's description
*/
export const goodDescription = (
data: SlashCommandBuilder | APIApplicationCommandSubcommandOption,
locale: Locale,
) => data.description_localizations?.[locale] ?? data.description;