Compare commits

...

7 commits

6 changed files with 42 additions and 15 deletions

View file

@ -9,23 +9,41 @@ export default {
return new SlashCommandBuilder() return new SlashCommandBuilder()
.setName(filename.toLowerCase()) .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`)) .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true))
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`));
}, },
interaction: async (interaction: CommandInteraction, client: Client) => { interaction: async (interaction: CommandInteraction, client: Client) => {
const loc = getLocale(client, interaction.locale); 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 a command is specified
if (command_name) { if (desired_command) {
// Check if command exists // Check if command exists
interaction.reply({ content: 'WIP', ephemeral: true }); interaction.reply({ content: 'WIP', ephemeral: true });
} else { } else {
const fields = []; const fields: {
fields.push({ name: string;
name: 'WIP', value: string;
value: 'WIP', }[] = [];
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: [ interaction.reply({ embeds: [

View file

@ -9,7 +9,7 @@ export default {
return new SlashCommandBuilder() return new SlashCommandBuilder()
.setName(filename.toLowerCase()) .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`)) .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true))
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`));
}, },

View file

@ -4,7 +4,7 @@ import { getLocale } from '../../utils/locales';
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-interactionCreate */ /** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-interactionCreate */
export default (interaction: Interaction, client: Client) => { export default (interaction: Interaction, client: Client) => {
if (interaction.isCommand()) { if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName); const command = client.commands.list.get(interaction.commandName);
if (!command) { if (!command) {
const loc = getLocale(client, interaction.locale); const loc = getLocale(client, interaction.locale);
return interaction.reply({ return interaction.reply({

View file

@ -1,10 +1,14 @@
{ {
"e_interacreate_no_command": "Désolé, la commande n'existe plus...", "e_interacreate_no_command": "Désolé, la commande n'existe plus...",
"c_ping_name": "Ping",
"c_ping_desc": "Pong!", "c_ping_desc": "Pong!",
"c_ping1": "Latence totale", "c_ping1": "Latence totale",
"c_ping2": "Latence du Websocket", "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_help1": "Liste des catégories et des commandes associées",
"c_help2": "`/help <commande>` pour obtenir plus d'informations sur une commande." "c_help2": "`/help <commande>` pour obtenir plus d'informations sur une commande.",
"c_help3": "Pas d'information."
} }

View file

@ -29,7 +29,7 @@ declare module 'discord.js' {
/** Command itself */ /** Command itself */
{ {
/** Data about the command */ /** Data about the command */
data: SlashCommandBuilder, data(client: Client): SlashCommandBuilder,
/** How the command interact */ /** How the command interact */
interaction: (interaction: CommandInteraction, client: Client) => unknown interaction: (interaction: CommandInteraction, client: Client) => unknown
} }
@ -54,8 +54,10 @@ export default async () => {
default_lang: process.env.DEFAULT_LANG ?? 'fr', default_lang: process.env.DEFAULT_LANG ?? 'fr',
}; };
client.commands.categories = new Collection(); client.commands = {
client.commands.list = new Collection(); categories: new Collection(),
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);

View file

@ -53,18 +53,21 @@ export const loadLocales = async (default_lang: string) => {
* @param text Name of string to fetch * @param text Name of string to fetch
* @returns the dictionary * @returns the dictionary
*/ */
export const getLocalizations = (client: Client, text: string) => { export const getLocalizations = (client: Client, text: string, lowercase = false) => {
const data: Record<string, string> = {}; const data: Record<string, string> = {};
// Load all the localizations // Load all the localizations
client.locales.forEach((locale, lang) => { client.locales.forEach((locale, lang) => {
// Fetch the text and fallback to default lang if needed // Fetch the text and fallback to default lang if needed
// See getLocale for more info on why we *can* fallback // 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); ?? client.locales.get(client.config.default_lang)?.get(text);
// Store it if defined // Store it if defined
if (str !== undefined) { if (str !== undefined) {
if (lowercase) {
str = str.toLowerCase();
}
data[lang] = str; data[lang] = str;
} }
}); });