complete reminders
This commit is contained in:
parent
44adad28a9
commit
8b05c26dab
2 changed files with 15 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Client } from 'discord.js';
|
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;
|
export const once = true;
|
||||||
|
|
||||||
|
@ -33,6 +33,15 @@ export default async (client: Client) => {
|
||||||
}).then((data) => {
|
}).then((data) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
(data as dbReminder[]).forEach((element) => {
|
(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) {
|
if (element.expiration_date <= now) {
|
||||||
// Reminder expired
|
// Reminder expired
|
||||||
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
|
deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => {
|
||||||
|
@ -40,19 +49,12 @@ export default async (client: Client) => {
|
||||||
throw res;
|
throw res;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const info = {
|
client.channels.fetch(`${info.channelId}`).then((val) => console.log(val?.url));
|
||||||
locale: element.locale,
|
|
||||||
message: element.data,
|
|
||||||
createdAt: element.creation_date,
|
|
||||||
channelId: `${element.channel_id}`,
|
|
||||||
userId: `${element.user_id}`,
|
|
||||||
guildId: `${element.guild_id}`,
|
|
||||||
} as infoReminder;
|
|
||||||
sendReminder(client, info, element.option_id as OptionReminder);
|
sendReminder(client, info, element.option_id as OptionReminder);
|
||||||
} else {
|
} else {
|
||||||
// Restart timeout
|
// Restart timeout
|
||||||
|
setTimeoutReminder(client, info, element.option_id, (element.expiration_date - now) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -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 \
|
data, expiration_date, option_id, channel_id, creation_date, user_id, guild_id, locale \
|
||||||
) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );', [
|
) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );', [
|
||||||
info.message,
|
info.message,
|
||||||
info.createdAt + timeout,
|
`${info.createdAt + (timeout * 1000)}`,
|
||||||
data.option.valueOf(),
|
data.option.valueOf(),
|
||||||
info.channelId,
|
info.channelId,
|
||||||
info.createdAt,
|
`${info.createdAt}`,
|
||||||
info.userId,
|
info.userId,
|
||||||
info.guildId,
|
info.guildId,
|
||||||
info.locale], (err) => {
|
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 option option used for this reminder (aka location of the response)
|
||||||
* @param timeout Amout of time before the reminder ends
|
* @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(() => {
|
setTimeout(() => {
|
||||||
deleteReminder(client, info.createdAt, info.userId).then((val) => {
|
deleteReminder(client, info.createdAt, info.userId).then((val) => {
|
||||||
if (val != true) {
|
if (val != true) {
|
||||||
|
|
Loading…
Reference in a new issue