import { TundraBot } from "../base/TundraBot" ; import Remind from "../commands/utility/remind" ; import { DBReminder , reminderModel } from "../models/Reminder" ; import Deps from "../utils/deps" ; import Logger from "../utils/logger" ; import { StartupHelper } from "./startupHelper" ; export default class CheckReminders extends StartupHelper { DBReminderManager : DBReminder ; constructor ( client ) { super ( client ) ; this . DBReminderManager = Deps . get < DBReminder > ( DBReminder ) ; } async init ( ) { reminderModel . find ( ) . then ( async ( reminders ) => { const dateNow = new Date ( Date . now ( ) ) ; for ( const reminder of reminders ) { try { await this . client . users . fetch ( reminder . userID ) . catch ( ( ) => { throw new Error ( "User left all servers with bot in it" ) ; } ) ; if ( reminder . endTime > dateNow ) { setTimeout ( async ( ) => { Remind . remind ( this . client , reminder ) ; } , reminder . endTime . getTime ( ) - dateNow . getTime ( ) ) ; } else { Remind . remind ( this . client , reminder ) ; } } catch ( err ) { } } Logger . log ( "ready" , `Loaded ${ reminders . length } reminders` ) ; } ) . catch ( ( err ) => { Logger . log ( "error" , `Error loading reminders from database:\n${ err }` ) ; } ) ; } }