From b04bbfa574255c461111a9a9e7a06827a9b06c86 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 19 Jul 2021 22:30:31 +0300 Subject: [PATCH] reminder message tweaks --- structure/Cache.js | 6 +++++- structure/Client.js | 2 +- structure/Modmail.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/structure/Cache.js b/structure/Cache.js index 6b143ed..ac2f994 100644 --- a/structure/Cache.js +++ b/structure/Cache.js @@ -11,10 +11,13 @@ class Cache { this.saveInterval = opts.saveInterval; this._ready = false; + // Data that gets stored to persistent cache this.queue = []; this.channels = {}; this.lastActivity = {}; + this.misc = {}; // Random misc data, should not be non-primitive data types + // Stored separately if at all this.modmail = {}; this.updatedThreads = []; @@ -91,7 +94,8 @@ class Cache { return { queue: this.queue, channels: this.channels, - lastActivity: this.lastActivity + lastActivity: this.lastActivity, + misc: this.misc }; } diff --git a/structure/Client.js b/structure/Client.js index ff31be3..10b4bef 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -47,7 +47,7 @@ class ModmailClient extends Client { this.mainServer = this.guilds.cache.get(this._options.mainGuild); this.bansServer = this.guilds.cache.get(this._options.bansGuild) || null; this.logger.info(`Starting up modmail handler`); - this.modmail.init(); + await this.modmail.init(); process.on('exit', () => { this.logger.warn('process exiting'); diff --git a/structure/Modmail.js b/structure/Modmail.js index 1e318b5..cb7c8a2 100644 --- a/structure/Modmail.js +++ b/structure/Modmail.js @@ -35,7 +35,7 @@ class Modmail { } - init() { + async init() { this.mainServer = this.client.mainServer; if (!this.mainServer) throw new Error(`Missing main server`); @@ -51,6 +51,7 @@ class Modmail { if (this._reminderChannel) { this.reminderChannel = this.client.channels.resolve(this._reminderChannel); this.reminder = setInterval(this.sendReminder.bind(this), this.reminderInterval * 60 * 1000); + this.lastReminder = await this.reminderChannel.messages.fetch(this.cache.misc.lastReminder).catch(() => null); this.sendReminder(); } @@ -374,6 +375,7 @@ class Modmail { await this.lastReminder.delete(); } this.lastReminder = await channel.send(str); + this.cache.lastReminder = this.lastReminder.id; }