feat: Reminders #44

Merged
Anri merged 54 commits from feat/reminders into main 2023-01-17 12:15:15 +01:00
2 changed files with 15 additions and 13 deletions
Showing only changes of commit 8b05c26dab - Show all commits

View file

@ -1,5 +1,5 @@
import { Client } from 'discord.js';
import { deleteReminder, infoReminder, OptionReminder, sendReminder } from '../../utils/reminder';
import { deleteReminder, infoReminder, OptionReminder, sendReminder, setTimeoutReminder } from '../../utils/reminder';
export const once = true;
@ -33,13 +33,6 @@ export default async (client: Client) => {
}).then((data) => {
const now = Date.now();
(data as dbReminder[]).forEach((element) => {
if (element.expiration_date <= now) {
// Reminder expired
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
if (res != true) {
throw res;
}
});
const info = {
locale: element.locale,
message: element.data,
@ -48,11 +41,20 @@ export default async (client: Client) => {
userId: `${element.user_id}`,
guildId: `${element.guild_id}`,
} as infoReminder;
if (element.expiration_date <= now) {
// Reminder expired
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
if (res != true) {
throw res;
}
});
client.channels.fetch(`${info.channelId}`).then((val) => console.log(val?.url));
sendReminder(client, info, element.option_id as OptionReminder);
} else {
// Restart timeout
setTimeoutReminder(client, info, element.option_id, (element.expiration_date - now) / 1000);
}
});
}).catch(err => {
throw err;

View file

@ -59,10 +59,10 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
data, expiration_date, option_id, channel_id, creation_date, user_id, guild_id, locale \
) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );', [
info.message,
info.createdAt + timeout,
`${info.createdAt + (timeout * 1000)}`,
data.option.valueOf(),
info.channelId,
info.createdAt,
`${info.createdAt}`,
info.userId,
info.guildId,
info.locale], (err) => {
@ -128,7 +128,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR
* @param option option used for this reminder (aka location of the response)
* @param timeout Amout of time before the reminder ends
*/
const setTimeoutReminder = (client: Client, info: infoReminder, option: OptionReminder, timeout: number) => {
export const setTimeoutReminder = (client: Client, info: infoReminder, option: OptionReminder, timeout: number) => {
setTimeout(() => {
deleteReminder(client, info.createdAt, info.userId).then((val) => {
if (val != true) {