From d2a020837267bf024f508b402f596f8e242672ed Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 11 Jul 2022 18:44:09 +0200 Subject: create task categories --- src/tasks/handleReminders.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/tasks/handleReminders.ts (limited to 'src/tasks/handleReminders.ts') diff --git a/src/tasks/handleReminders.ts b/src/tasks/handleReminders.ts deleted file mode 100644 index 7863c9a..0000000 --- a/src/tasks/handleReminders.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { BushTask, dateDelta, format, Reminder, Time } from '#lib'; -const { Op } = (await import('sequelize')).default; - -export default class HandlerRemindersTask extends BushTask { - public constructor() { - super('handlerReminders', { - delay: 30 * Time.Second, - runOnStart: true - }); - } - - public async exec() { - const expiredEntries = await Reminder.findAll({ - where: { - expires: { - [Op.lt]: new Date(Date.now() + 30 * Time.Second) // Find all rows with an expiry date before 30 seconds from now - }, - notified: false - } - }); - - void this.client.logger.verbose( - `handlerReminders`, - `Queried reminders, found <<${expiredEntries.length}>> expired reminders.` - ); - - for (const entry of expiredEntries) { - setTimeout(() => { - void this.client.users - .send( - entry.user, - `The reminder you set ${dateDelta(entry.created)} ago has expired: ${format.bold(entry.content)}\n${entry.messageUrl}` - ) - .catch(() => false); - void entry.update({ notified: true }); - }, entry.expires.getTime() - new Date().getTime()); - } - } -} -- cgit