* fix display of time
* add message when the list is empty * wip: add button to update when the list is empty * fix reminder deletion
This commit is contained in:
parent
2593f92dad
commit
5c7ede0033
5 changed files with 52 additions and 29 deletions
|
@ -219,10 +219,14 @@ export default {
|
|||
user = interaction.user;
|
||||
}
|
||||
|
||||
const page = interaction.options.getInteger(loc_default?.get(`c_${filename}_sub2_opt2_name`) as string) ?? 1;
|
||||
const { remindersExists, list } = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||
|
||||
let row;
|
||||
if (remindersExists) {
|
||||
const idPrec = 'reminderList-prec';
|
||||
const idNext = 'reminderList-next';
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(idPrec)
|
||||
|
@ -238,10 +242,16 @@ export default {
|
|||
// Buttons interactions
|
||||
collect(client, interaction, idPrec);
|
||||
collect(client, interaction, idNext);
|
||||
|
||||
const page = interaction.options.getInteger(loc_default?.get(`c_${filename}_sub2_opt2_name`) as string) ?? 1;
|
||||
|
||||
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||
} else {
|
||||
const idUpdate = 'reminderList-update';
|
||||
row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(idUpdate)
|
||||
.setLabel('Update')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
);
|
||||
}
|
||||
|
||||
return await interaction.reply({ ephemeral: true, embeds: [list], components: [row] });
|
||||
}
|
||||
|
@ -263,9 +273,9 @@ export default {
|
|||
clearTimeout(reminderInfo.timeout_id);
|
||||
|
||||
// Delete from database
|
||||
deleteReminder(client, Number(reminderInfo.creation_date), reminderInfo.user_id);
|
||||
return deleteReminder(client, reminderInfo.creation_date, reminderInfo.user_id)
|
||||
.then(() => interaction.reply({ content: `Reminder **#${id}** supprimé !`, ephemeral: true }));
|
||||
|
||||
return interaction.reply({ content: `Reminder **#${id}** supprimé !`, ephemeral: true });
|
||||
}
|
||||
default: {
|
||||
console.error(`${__filename}: unknown subcommand (${subcommand})`);
|
||||
|
|
|
@ -32,7 +32,7 @@ export default async (client: Client) => {
|
|||
|
||||
if (element.expiration_date <= now) {
|
||||
// Reminder expired
|
||||
deleteReminder(client, Number(element.creation_date), `${element.user_id}`).then((res) => {
|
||||
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
|
||||
if (res != true) {
|
||||
throw res;
|
||||
}
|
||||
|
|
|
@ -44,5 +44,7 @@
|
|||
"c_reminder6": "Page ",
|
||||
"c_reminder7": "Pas de message",
|
||||
"c_reminder8": "Expire dans",
|
||||
"c_reminder9": "Fais le"
|
||||
"c_reminder9": "Fais le",
|
||||
"c_reminder10": "L'utilisateur n'a aucun rappel en attente ou page n°",
|
||||
"c_reminder11": "vide !"
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
|
|||
* @param userId User ID who created the reminder
|
||||
* @returns what the SQlite request sended
|
||||
*/
|
||||
export const deleteReminder = (client: Client, createdAt: number, userId: string) => {
|
||||
export const deleteReminder = (client: Client, createdAt: string, userId: string) => {
|
||||
// Delete the reminder for the database
|
||||
return new Promise((ok, ko) => {
|
||||
// Add the remind to the db
|
||||
|
@ -145,7 +145,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR
|
|||
*/
|
||||
export const setTimeoutReminder = (client: Client, info: infoReminder, option: OptionReminder, timeout: number) => {
|
||||
return Number(setTimeout(() => {
|
||||
deleteReminder(client, info.createdAt, info.userId).then((val) => {
|
||||
deleteReminder(client, String(info.createdAt), info.userId).then((val) => {
|
||||
if (val != true) {
|
||||
throw val;
|
||||
}
|
||||
|
@ -267,6 +267,15 @@ const listReminders = async (client: Client, userId: string, guildId: string | n
|
|||
}) as dbReminder[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the embed of the reminders
|
||||
* @param client Client
|
||||
* @param user User
|
||||
* @param guildId Guild ID
|
||||
* @param page Page requested
|
||||
* @param local Lang
|
||||
* @returns Pretty embed who list reminders
|
||||
*/
|
||||
export const embedListReminders = async (client: Client, user: User, guildId: string | null, page: number, local: string) => {
|
||||
const loc = getLocale(client, local);
|
||||
const reminders = await listReminders(client, user.id, guildId);
|
||||
|
@ -303,7 +312,9 @@ export const embedListReminders = async (client: Client, user: User, guildId: st
|
|||
curseur++;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
embed.addFields({ name: '\u200b', value: `${loc.get('c_reminder10')}${page} ${loc.get('c_reminder11')}` });
|
||||
}
|
||||
|
||||
return embed;
|
||||
return { remindersExists: reminders.length > 0 ? true : false, list: embed };
|
||||
};
|
||||
|
|
|
@ -50,5 +50,5 @@ export const strToSeconds = (time: string) => {
|
|||
export const timeDeltaToString = (time: number) => {
|
||||
const now = Date.now();
|
||||
// TODO adapt the output and not always parse the time as seconds
|
||||
return `${strToSeconds(`${now - time}`)} secs`;
|
||||
return `${strToSeconds(`${(now - time) / 1000}`)} secs`;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue