feat: Reminders #44
5 changed files with 52 additions and 29 deletions
|
@ -219,10 +219,14 @@ export default {
|
||||||
user = interaction.user;
|
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 idPrec = 'reminderList-prec';
|
||||||
const idNext = 'reminderList-next';
|
const idNext = 'reminderList-next';
|
||||||
|
row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(idPrec)
|
.setCustomId(idPrec)
|
||||||
|
@ -238,10 +242,16 @@ export default {
|
||||||
// Buttons interactions
|
// Buttons interactions
|
||||||
collect(client, interaction, idPrec);
|
collect(client, interaction, idPrec);
|
||||||
collect(client, interaction, idNext);
|
collect(client, interaction, idNext);
|
||||||
|
} else {
|
||||||
const page = interaction.options.getInteger(loc_default?.get(`c_${filename}_sub2_opt2_name`) as string) ?? 1;
|
const idUpdate = 'reminderList-update';
|
||||||
|
row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(idUpdate)
|
||||||
|
.setLabel('Update')
|
||||||
|
.setStyle(ButtonStyle.Primary)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return await interaction.reply({ ephemeral: true, embeds: [list], components: [row] });
|
return await interaction.reply({ ephemeral: true, embeds: [list], components: [row] });
|
||||||
}
|
}
|
||||||
|
@ -263,9 +273,9 @@ export default {
|
||||||
clearTimeout(reminderInfo.timeout_id);
|
clearTimeout(reminderInfo.timeout_id);
|
||||||
|
|
||||||
// Delete from database
|
// 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: {
|
default: {
|
||||||
console.error(`${__filename}: unknown subcommand (${subcommand})`);
|
console.error(`${__filename}: unknown subcommand (${subcommand})`);
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default async (client: Client) => {
|
||||||
|
|
||||||
if (element.expiration_date <= now) {
|
if (element.expiration_date <= now) {
|
||||||
// Reminder expired
|
// 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) {
|
if (res != true) {
|
||||||
throw res;
|
throw res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,5 +44,7 @@
|
||||||
"c_reminder6": "Page ",
|
"c_reminder6": "Page ",
|
||||||
"c_reminder7": "Pas de message",
|
"c_reminder7": "Pas de message",
|
||||||
"c_reminder8": "Expire dans",
|
"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
|
* @param userId User ID who created the reminder
|
||||||
* @returns what the SQlite request sended
|
* @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
|
// Delete the reminder for the database
|
||||||
return new Promise((ok, ko) => {
|
return new Promise((ok, ko) => {
|
||||||
// Add the remind to the db
|
// 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) => {
|
export const setTimeoutReminder = (client: Client, info: infoReminder, option: OptionReminder, timeout: number) => {
|
||||||
return Number(setTimeout(() => {
|
return Number(setTimeout(() => {
|
||||||
deleteReminder(client, info.createdAt, info.userId).then((val) => {
|
deleteReminder(client, String(info.createdAt), info.userId).then((val) => {
|
||||||
if (val != true) {
|
if (val != true) {
|
||||||
throw val;
|
throw val;
|
||||||
}
|
}
|
||||||
|
@ -267,6 +267,15 @@ const listReminders = async (client: Client, userId: string, guildId: string | n
|
||||||
}) as dbReminder[];
|
}) 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) => {
|
export const embedListReminders = async (client: Client, user: User, guildId: string | null, page: number, local: string) => {
|
||||||
const loc = getLocale(client, local);
|
const loc = getLocale(client, local);
|
||||||
const reminders = await listReminders(client, user.id, guildId);
|
const reminders = await listReminders(client, user.id, guildId);
|
||||||
|
@ -303,7 +312,9 @@ export const embedListReminders = async (client: Client, user: User, guildId: st
|
||||||
curseur++;
|
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) => {
|
export const timeDeltaToString = (time: number) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
// TODO adapt the output and not always parse the time as seconds
|
// 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