diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index 08d6df7..e2b47d3 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -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,6 +33,15 @@ export default async (client: Client) => { }).then((data) => { const now = Date.now(); (data as dbReminder[]).forEach((element) => { + const info = { + locale: element.locale, + message: element.data, + createdAt: element.creation_date, + channelId: `${element.channel_id}`, + 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) => { @@ -40,19 +49,12 @@ export default async (client: Client) => { throw res; } }); - const info = { - locale: element.locale, - message: element.data, - createdAt: element.creation_date, - channelId: `${element.channel_id}`, - userId: `${element.user_id}`, - guildId: `${element.guild_id}`, - } as infoReminder; + 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; diff --git a/src/utils/reminder.ts b/src/utils/reminder.ts index faa84fb..e2983c9 100644 --- a/src/utils/reminder.ts +++ b/src/utils/reminder.ts @@ -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) {