diff --git a/structure/Client.js b/structure/Client.js index cd32340..b286389 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -7,7 +7,7 @@ const { Logger } = require('../logger'); const Modmail = require('./Modmail'); const Registry = require('./Registry'); const Resolver = require('./Resolver'); -const Cache = require('./Cache'); +const Cache = require('./JsonCache'); class ModmailClient extends Client { diff --git a/structure/Cache.js b/structure/JsonCache.js similarity index 75% rename from structure/Cache.js rename to structure/JsonCache.js index 178a14c..2e71938 100644 --- a/structure/Cache.js +++ b/structure/JsonCache.js @@ -92,6 +92,26 @@ class JsonCache extends CacheHandler { } + verifyQueue () { + this.client.logger.info(`Verifying modmail queue.`); + this.queue.forEach(async entry => { + const path = `./modmail_cache/${entry}.json`; + if (fs.existsSync(path)) return; + + this.client.logger.warn(`User ${entry} is in queue but is missing history. Attempting to recover history.`); + const user = await this.client.resolveUser(entry); + const dm = await user.createDM(); + let messages = await dm.messages.fetch(); + messages = messages.filter(msg => msg.author.id !== this.client.user.id).sort((a, b) => a.createdTimestamp - b.createdTimestamp); + + const history = await this.loadModmailHistory(entry); + for (const { author, content, createdTimestamp, attachments } of messages) history.push({ attachments: attachments.map(att => att.url), author: author.id, content, timestamp: createdTimestamp }); + + }); + + this.client.logger.info(`Queue verified.`); + } + get json () { return { queue: this.queue, diff --git a/structure/Modmail.js b/structure/Modmail.js index 51c2d74..4bd4a69 100644 --- a/structure/Modmail.js +++ b/structure/Modmail.js @@ -370,6 +370,8 @@ class Modmail { async sendReminder () { + await this.cache.verifyQueue(); + const channel = this.reminderChannel; const amount = this.queue.length; diff --git a/structure/abstractions/CacheHandler.js b/structure/abstractions/CacheHandler.js index d11d7e5..5956657 100644 --- a/structure/abstractions/CacheHandler.js +++ b/structure/abstractions/CacheHandler.js @@ -22,6 +22,10 @@ class CacheHandler { throw new Error('Not implemented'); } + verifyQueue () { + throw new Error('Not implemented'); + } + get json () { return { queue: this.queue,