be sure to delete reminder after publishing it

This commit is contained in:
Mylloon 2024-10-11 19:51:43 +02:00
parent 2fcca576a6
commit 5aa3991633
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 22 additions and 10 deletions

View file

@ -41,14 +41,18 @@ export default async (client: Client) => {
} as infoReminder; } as infoReminder;
if (element.expiration_date <= now) { if (element.expiration_date <= now) {
sendReminder(client, info, element.option_id as OptionReminder)
.then(() =>
// Reminder expired // Reminder expired
deleteReminder(client, 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;
} }
}),
)
.catch((err) => {
throw err;
}); });
sendReminder(client, info, element.option_id as OptionReminder);
} else { } else {
// Restart timeout // Restart timeout
const timeoutId = setTimeoutReminder( const timeoutId = setTimeoutReminder(

View file

@ -143,10 +143,18 @@ export const deleteReminder = (client: Client, createdAt: string, userId: string
}); });
}; };
export const sendReminder = (client: Client, info: infoReminder, option: OptionReminder) => { export const sendReminder = (client: Client, info: infoReminder, option: OptionReminder) =>
new Promise((resolve, reject) => {
try {
resolve(sendReminderAux(client, info, option));
} catch (error) {
reject(error);
}
});
const sendReminderAux = (client: Client, info: infoReminder, option: OptionReminder) => {
const loc = getLocale(client, info.locale); const loc = getLocale(client, info.locale);
// Send the message in the appropriate channel // Send the message in the appropriate channel
// TODO: Embed
let message: string; let message: string;
if (info.message === null || info.message.length === 0) { if (info.message === null || info.message.length === 0) {
message = loc.get("c_reminder7"); message = loc.get("c_reminder7");