rename jsoncache, added verifyqueue method

This commit is contained in:
Erik 2022-01-12 18:29:52 +02:00
parent 736df1b3af
commit 64095adc1a
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589
4 changed files with 27 additions and 1 deletions

View File

@ -7,7 +7,7 @@ const { Logger } = require('../logger');
const Modmail = require('./Modmail'); const Modmail = require('./Modmail');
const Registry = require('./Registry'); const Registry = require('./Registry');
const Resolver = require('./Resolver'); const Resolver = require('./Resolver');
const Cache = require('./Cache'); const Cache = require('./JsonCache');
class ModmailClient extends Client { class ModmailClient extends Client {

View File

@ -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 () { get json () {
return { return {
queue: this.queue, queue: this.queue,

View File

@ -370,6 +370,8 @@ class Modmail {
async sendReminder () { async sendReminder () {
await this.cache.verifyQueue();
const channel = this.reminderChannel; const channel = this.reminderChannel;
const amount = this.queue.length; const amount = this.queue.length;

View File

@ -22,6 +22,10 @@ class CacheHandler {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
verifyQueue () {
throw new Error('Not implemented');
}
get json () { get json () {
return { return {
queue: this.queue, queue: this.queue,