Compare commits

..

7 commits

7 changed files with 27 additions and 12 deletions

View file

@ -4,7 +4,7 @@
"description": "Bot discord",
"main": "src/index.js",
"scripts": {
"main": "npx tsc && node ./dist/index.js",
"main": "rm -r dist 2> /dev/null; npx tsc && node ./dist/index.js",
"debug": "npx tsnd --respawn ./src/index.ts",
"lint": "npx eslint src"
},

View file

@ -1,11 +1,17 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Client, CommandInteraction, Message } from 'discord.js';
import { getLocale } from '../../utils/locales';
import { getFilename } from '../../utils/misc';
export default {
data: (client: Client) => new SlashCommandBuilder()
.setNameLocalizations(getLocale(client, 'c_ping_name'))
.setDescriptionLocalizations(getLocale(client, 'c_ping_desc')),
data: (client: Client) => {
const filename = getFilename(__filename);
return new SlashCommandBuilder()
.setName(filename)
.setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '?')
.setNameLocalizations(getLocale(client, `c_${filename}_name`))
.setDescriptionLocalizations(getLocale(client, `c_${filename}_desc`));
},
interaction: async (interaction: CommandInteraction, client: Client) => {
const loc = client.locales.get(interaction.locale) ?? client.locales.get(client.config.default_lang);

View file

@ -6,7 +6,7 @@ export default (interaction: Interaction, client: Client) => {
const command = client.commands.get(interaction.commandName);
if (!command) {
return interaction.reply({
content: client.locales.get(interaction.locale)?.get('e_interacreate'),
content: client.locales.get(interaction.locale)?.get('e_interacreate_no_command'),
ephemeral: true,
});
}

View file

@ -1,8 +1,7 @@
{
"e_interacreate": "Sorry, the command probably no longer exists...",
"e_interacreate_no_command": "Sorry, the command probably no longer exists...",
"c_ping_name": "Ping",
"c_ping_desc": "Pong",
"c_ping_desc": "Pong!",
"c_ping1": "Roundtrip latency",
"c_ping2": "Websocket heartbeat"
}

View file

@ -1,5 +1,5 @@
{
"e_interacreate": "Désolé, la commande n'existe plus...",
"e_interacreate_no_command": "Désolé, la commande n'existe plus...",
"c_ping1": "Latence totale",
"c_ping2": "Latence du Websocket"

View file

@ -49,10 +49,9 @@ export const getLocale = (client: Client, text: string) => {
const str = locale.get(text)
?? client.locales.get(client.config.default_lang)?.get(text);
if (str === undefined) {
throw 'Missing locales';
if (str !== undefined) {
data[lang] = str.toLowerCase();
}
data[lang] = str;
});
return data;

View file

@ -7,3 +7,14 @@
export const logStart = (name: string, status: boolean) => {
return `> ${name} ${status === true ? '✅' : '❌'}`;
};
/**
* Filename without path and extension
* @param path __filename
* @returns string
*/
export const getFilename = (path: string) => {
const path_list = path.split('/');
return path_list[path_list.length - 1].split('.')[0];
};