Compare commits
7 commits
a8ce8faf06
...
a857898300
Author | SHA1 | Date | |
---|---|---|---|
a857898300 | |||
33dd6cfc17 | |||
743d6eb471 | |||
f1622fa7e4 | |||
fdbbbe6957 | |||
62e61df3d0 | |||
b085539b48 |
6 changed files with 42 additions and 15 deletions
|
@ -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 = [];
|
||||
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: 'WIP',
|
||||
value: 'WIP',
|
||||
name: category,
|
||||
value: commands_description,
|
||||
});
|
||||
});
|
||||
|
||||
interaction.reply({ embeds: [
|
||||
|
|
|
@ -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`));
|
||||
},
|
||||
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
{
|
||||
"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 <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."
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<string, string> = {};
|
||||
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue