Compare commits
No commits in common. "a85789830001e1c4b34cd0e72011119a14ddfc04" and "a8ce8faf069194953c15e34e6c7a1a70f95fcb47" have entirely different histories.
a857898300
...
a8ce8faf06
6 changed files with 15 additions and 42 deletions
|
@ -9,41 +9,23 @@ 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`, true))
|
.setNameLocalizations(getLocalizations(client, `c_${filename}_name`))
|
||||||
.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 desired_command = interaction.options.getString('command');
|
const command_name = interaction.options.getString('command');
|
||||||
|
|
||||||
// If a command is specified
|
// If a command is specified
|
||||||
if (desired_command) {
|
if (command_name) {
|
||||||
// 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 = [];
|
||||||
name: string;
|
fields.push({
|
||||||
value: string;
|
name: 'WIP',
|
||||||
}[] = [];
|
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: [
|
||||||
|
|
|
@ -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`, true))
|
.setNameLocalizations(getLocalizations(client, `c_${filename}_name`))
|
||||||
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`));
|
.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 */
|
/** 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.list.get(interaction.commandName);
|
const command = client.commands.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({
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
{
|
{
|
||||||
"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."
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ declare module 'discord.js' {
|
||||||
/** Command itself */
|
/** Command itself */
|
||||||
{
|
{
|
||||||
/** Data about the command */
|
/** Data about the command */
|
||||||
data(client: Client): SlashCommandBuilder,
|
data: SlashCommandBuilder,
|
||||||
/** How the command interact */
|
/** How the command interact */
|
||||||
interaction: (interaction: CommandInteraction, client: Client) => unknown
|
interaction: (interaction: CommandInteraction, client: Client) => unknown
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,8 @@ export default async () => {
|
||||||
default_lang: process.env.DEFAULT_LANG ?? 'fr',
|
default_lang: process.env.DEFAULT_LANG ?? 'fr',
|
||||||
};
|
};
|
||||||
|
|
||||||
client.commands = {
|
client.commands.categories = new Collection();
|
||||||
categories: new Collection(),
|
client.commands.list = 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);
|
||||||
|
|
|
@ -53,21 +53,18 @@ 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, lowercase = false) => {
|
export const getLocalizations = (client: Client, text: string) => {
|
||||||
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
|
||||||
let str = locale.get(text)
|
const 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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue