Compare commits

...

5 commits

Author SHA1 Message Date
d4d3858ac7
add command builder 2022-07-28 00:18:43 +02:00
af5fc917e5
use ChatInputCommandInteraction 2022-07-28 00:18:16 +02:00
86286a196d
update translations 2022-07-28 00:17:39 +02:00
12af018032
update translations 2022-07-27 23:11:46 +02:00
48e1f40339
add sub command awareness 2022-07-27 23:11:38 +02:00
5 changed files with 177 additions and 11 deletions

View file

@ -39,7 +39,12 @@ La norme pour les nom dans les fichiers est la suivante :
- `c_NOM-COMMANDE_desc` : Description de la commande
- `c_NOM-COMMANDE_optX_name` : Nom de l'option X
- `c_NOM-COMMANDE_optX_desc` : Description de l'option X
- `c_NOM-COMMANDE_subX_name` : Nom de la sous-commande X
- `c_NOM-COMMANDE_subX_desc` : Description de la sous-commande X
- `c_NOM-COMMANDEX` : `X` le numéro de la chaîne de caractère
Évidemment ça peut s'additionner,
par exemple : `c_NOM-COMMANDE_subX_optX_desc`.
- Chaîne de charactère des évènements :
`e` est utilisé pour `E`vènements.
- `e_NOM-EVENEMENT_N` : `N` le nom de la chaîne de caractère
@ -91,7 +96,7 @@ nouvelle catégorie si votre commande n'entre dans aucune qui existe déjà.
Le contenu du fichier doit commencer comme suit :
```typescript
import { SlashCommandBuilder } from '@discordjs/builders';
import { Client, CommandInteraction } from 'discord.js';
import { Client, ChatInputCommandInteraction } from 'discord.js';
import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc';
@ -110,7 +115,7 @@ export default {
);
},
interaction: async (interaction: CommandInteraction, client: Client) => {
interaction: async (interaction: ChatInputCommandInteraction, client: Client) => {
const loc = getLocale(client, interaction.locale);
/* Votre code ici */

View file

@ -1,6 +1,6 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Locale } from 'discord-api-types/v9';
import { Client, CommandInteraction, EmbedBuilder } from 'discord.js';
import { Client, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc';
import '../../modules/string';
@ -31,12 +31,12 @@ export default {
);
},
interaction: async (interaction: CommandInteraction, client: Client) => {
interaction: async (interaction: ChatInputCommandInteraction, client: Client) => {
const loc = getLocale(client, interaction.locale);
const desired_command = interaction.options.get(client
const desired_command = interaction.options.getString(client
.locales
.get(client.config.default_lang)
?.get(`c_${getFilename(__filename)}_opt1_name`) ?? '')?.value as string;
?.get(`c_${getFilename(__filename)}_opt1_name`) ?? '');
// If a command isn't specified
if (!desired_command) {

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Client, CommandInteraction, Message } from 'discord.js';
import { ChatInputCommandInteraction, Client, Message } from 'discord.js';
import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc';
@ -18,7 +18,7 @@ export default {
);
},
interaction: async (interaction: CommandInteraction, client: Client) => {
interaction: async (interaction: ChatInputCommandInteraction, client: Client) => {
const loc = getLocale(client, interaction.locale);
const sent = await interaction.reply({

View file

@ -0,0 +1,144 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Client, ChatInputCommandInteraction } from 'discord.js';
import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc';
export default {
data: (client: Client) => {
const filename = getFilename(__filename);
const loc_default = client.locales.get(client.config.default_lang);
if (!loc_default) {
return;
}
return new SlashCommandBuilder()
// Command
.setName(filename.toLowerCase())
.setDescription(loc_default.get(`c_${filename}_desc`) ?? '')
.setNameLocalizations(
getLocalizations(client, `c_${filename}_name`, true)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_desc`)
)
// New reminder
.addSubcommand(subcommand => subcommand
.setName(
loc_default.get(`c_${filename}_sub1_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub1_desc`) ?? ''
).setNameLocalizations(
getLocalizations(client, `c_${filename}_sub1_name`, true)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub1_desc`)
)
// Specified Time
.addStringOption(option => option
.setName(
loc_default.get(`c_${filename}_sub1_opt1_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub1_opt1_desc`) ?? ''
).setNameLocalizations(
getLocalizations(
client,
`c_${filename}_sub1_opt1_name`,
true
)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub1_opt1_desc`)
).setRequired(true)
)
// Specified message (not required)
.addStringOption(option => option
.setName(
loc_default.get(`c_${filename}_sub1_opt2_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub1_opt2_desc`) ?? ''
).setNameLocalizations(
getLocalizations(
client,
`c_${filename}_sub1_opt2_name`,
true
)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub1_opt2_desc`)
)
)
)
// List reminders
.addSubcommand(subcommand => subcommand
.setName(
loc_default.get(`c_${filename}_sub2_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub2_desc`) ?? ''
).setNameLocalizations(
getLocalizations(client, `c_${filename}_sub2_name`, true)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub2_desc`)
)
// User
.addStringOption(option => option
.setName(
loc_default.get(`c_${filename}_sub2_opt1_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub2_opt1_desc`) ?? ''
).setNameLocalizations(
getLocalizations(
client,
`c_${filename}_sub2_opt1_name`,
true
)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub2_opt1_desc`)
)
)
)
// Delete a reminder
.addSubcommand(subcommand => subcommand
.setName(
loc_default.get(`c_${filename}_sub3_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub3_desc`) ?? ''
).setNameLocalizations(
getLocalizations(client, `c_${filename}_sub3_name`, true)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub3_desc`)
)
// ID
.addStringOption(option => option
.setName(
loc_default.get(`c_${filename}_sub3_opt1_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub3_opt1_desc`) ?? ''
).setNameLocalizations(
getLocalizations(
client,
`c_${filename}_sub3_opt1_name`,
true
)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub3_opt1_desc`)
).setRequired(true)
),
);
},
interaction: async (interaction: ChatInputCommandInteraction, client: Client) => {
const loc = getLocale(client, interaction.locale);
/* Votre code ici */
},
};

View file

@ -14,5 +14,22 @@
"c_help2": "`/help <commande>` pour obtenir plus d'informations sur une commande.",
"c_help3": "Impossible de trouver :",
"u_time_at": "à"
"u_time_at": "à",
"c_reminder_name": "rappel",
"c_reminder_desc": "Commande relative aux rappels",
"c_reminder_sub1_name": "nouveau",
"c_reminder_sub1_desc": "Met en place un rappel",
"c_reminder_sub1_opt1_name": "temps",
"c_reminder_sub1_opt1_desc": "Temps désiré avant le rappel",
"c_reminder_sub1_opt2_name": "message",
"c_reminder_sub1_opt2_desc": "Message du rappel",
"c_reminder_sub2_name": "liste",
"c_reminder_sub2_desc": "Affiche la liste des rappels d'un utilisateur",
"c_reminder_sub2_opt1_name": "utilisateur",
"c_reminder_sub2_opt1_desc": "Affiche la liste de l'utilisateur en question",
"c_reminder_sub3_name": "efface",
"c_reminder_sub3_desc": "Supprime un rappel",
"c_reminder_sub3_opt1_name": "ID",
"c_reminder_sub3_opt1_desc": "Rappel à supprimé"
}