From 024beb00b29c45461df9a0025620006a4af9422d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 6 Nov 2022 01:47:32 +0100 Subject: [PATCH] fix last translation --- src/commands/misc/reminder.ts | 18 +++++++++++++----- src/locales/fr.json | 3 ++- src/modals/misc/reminderGUI.ts | 9 +++++---- src/utils/reminder.ts | 20 +++++++++----------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/commands/misc/reminder.ts b/src/commands/misc/reminder.ts index 3790630..f8f5444 100644 --- a/src/commands/misc/reminder.ts +++ b/src/commands/misc/reminder.ts @@ -148,10 +148,13 @@ export default { // New reminder case loc_default?.get(`c_${filename}_sub1_name`) ?.toLowerCase() ?? '': { + + // If time is already renseigned const time = interaction.options.getString(loc_default?.get(`c_${filename}_sub1_opt1_name`) as string); if (time != null) { - // Cli + // Use the cli because we already have enough data return newReminder(client, time, { + locale: loc, message: interaction.options.getString(loc_default?.get('c_reminder_sub1_opt2_name') as string), createdAt: interaction.createdAt.getTime(), channelId: interaction.channelId, @@ -162,7 +165,7 @@ export default { ephemeral: true, })); } else { - // GUI + // Show modal to user to get at least the time const modal = new ModalBuilder() .setCustomId('reminderGUI') .setTitle(loc?.get('c_reminder_name').capitalize()); @@ -181,7 +184,10 @@ export default { .setPlaceholder(loc?.get('c_reminder_sub1_opt2_desc')) .setRequired(false); - modal.addComponents(new ActionRowBuilder().addComponents(timeGUI), new ActionRowBuilder().addComponents(messageGUI)); + modal.addComponents( + new ActionRowBuilder().addComponents(timeGUI), + new ActionRowBuilder().addComponents(messageGUI) + ); return interaction.showModal(modal); } @@ -196,7 +202,8 @@ export default { // Quand aucun utilisateur est spécifié, il faut affiché ses // rappels, sinon affiché les rappels de la personne qui fait // la commande. - break; + + return interaction.reply('TODO'); } // Delete a reminder case loc_default?.get(`c_${filename}_sub3_name`) @@ -204,7 +211,8 @@ export default { // TODO: Message simple qui indique que l'on a supprimé // le reminder. Penser à check l'appartenance du reminder. // On donne l'ID du reminder en option. - break; + + return interaction.reply('TODO'); } default: { console.error(`${__filename}: unknown subcommand (${subcommand})`); diff --git a/src/locales/fr.json b/src/locales/fr.json index a2774f5..1a6d224 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -32,5 +32,6 @@ "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é" + "c_reminder_sub3_opt1_desc": "Rappel à supprimé", + "c_reminder1": "Un rappel a été configuré pour dans" } diff --git a/src/modals/misc/reminderGUI.ts b/src/modals/misc/reminderGUI.ts index 8b5b271..43c9ece 100644 --- a/src/modals/misc/reminderGUI.ts +++ b/src/modals/misc/reminderGUI.ts @@ -1,4 +1,5 @@ import { Client, ModalSubmitInteraction } from 'discord.js'; +import { getLocale } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; import { newReminder } from '../../utils/reminder'; @@ -6,8 +7,9 @@ export default { data: { name: getFilename(__filename), }, - interaction: async (interaction: ModalSubmitInteraction, client: Client) => { - return newReminder(client, interaction.fields.fields.get('reminderGUI-time')?.value as string, { + interaction: async (interaction: ModalSubmitInteraction, client: Client) => + newReminder(client, interaction.fields.fields.get('reminderGUI-time')?.value as string, { + locale: getLocale(client, interaction.locale), message: interaction.fields.fields.get('reminderGUI-message')?.value ?? null, createdAt: interaction.createdAt.getTime(), channelId: interaction.channelId, @@ -16,6 +18,5 @@ export default { }).then((msg) => interaction.reply({ content: msg as string, ephemeral: true, - })); - }, + })), }; diff --git a/src/utils/reminder.ts b/src/utils/reminder.ts index 560162a..cab23df 100644 --- a/src/utils/reminder.ts +++ b/src/utils/reminder.ts @@ -1,13 +1,14 @@ import { Client } from 'discord.js'; import { strToSeconds } from './time'; -export enum OptionReminder { +enum OptionReminder { Nothing, Mention, DirectMessage, } -export type infoReminder = { +type infoReminder = { + locale: Map>, message: string | null, createdAt: number, channelId: string | null, @@ -25,12 +26,11 @@ const splitTime = (time: string) => { return { time: time, option: OptionReminder.Nothing }; }; -export const newReminder = async (client: Client, time: string, info: infoReminder) => { - const data = splitTime(time); - - // Add the remind to the db - return new Promise((ok, ko) => { - const res = client.db.run('INSERT INTO reminder ( \ +export const newReminder = async (client: Client, time: string, info: infoReminder) => + new Promise((ok, ko) => { + const data = splitTime(time); + // Add the remind to the db + client.db.run('INSERT INTO reminder ( \ data, expiration_date, option_id, channel_id, creation_date, user_id, guild_id \ ) VALUES ( ?, ?, ?, ?, ?, ?, ?);', [ info.message, @@ -45,8 +45,6 @@ export const newReminder = async (client: Client, time: string, info: infoRemind } // Send confirmation to user - // TODO: local - ok(`ratio: ${info.message}, ${data.time}=${strToSeconds(data.time)}, ${data.option}, ${res}`); + ok(`${info.locale.get('c_reminder1')} ${data.time}.`); }); }); -};