be sure to delete reminder after publishing it
This commit is contained in:
parent
2fcca576a6
commit
5aa3991633
2 changed files with 22 additions and 10 deletions
|
@ -41,14 +41,18 @@ export default async (client: Client) => {
|
|||
} as infoReminder;
|
||||
|
||||
if (element.expiration_date <= now) {
|
||||
// Reminder expired
|
||||
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
|
||||
if (res != true) {
|
||||
throw res;
|
||||
}
|
||||
});
|
||||
|
||||
sendReminder(client, info, element.option_id as OptionReminder);
|
||||
sendReminder(client, info, element.option_id as OptionReminder)
|
||||
.then(() =>
|
||||
// Reminder expired
|
||||
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
|
||||
if (res != true) {
|
||||
throw res;
|
||||
}
|
||||
}),
|
||||
)
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
} else {
|
||||
// Restart timeout
|
||||
const timeoutId = setTimeoutReminder(
|
||||
|
|
|
@ -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);
|
||||
// Send the message in the appropriate channel
|
||||
// TODO: Embed
|
||||
let message: string;
|
||||
if (info.message === null || info.message.length === 0) {
|
||||
message = loc.get("c_reminder7");
|
||||
|
|
Loading…
Reference in a new issue