forked from Galactic/modmail
rename jsoncache, added verifyqueue method
This commit is contained in:
parent
736df1b3af
commit
64095adc1a
@ -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 {
|
||||
|
||||
|
@ -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,
|
@ -370,6 +370,8 @@ class Modmail {
|
||||
|
||||
async sendReminder () {
|
||||
|
||||
await this.cache.verifyQueue();
|
||||
|
||||
const channel = this.reminderChannel;
|
||||
const amount = this.queue.length;
|
||||
|
||||
|
@ -22,6 +22,10 @@ class CacheHandler {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
verifyQueue () {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
get json () {
|
||||
return {
|
||||
queue: this.queue,
|
||||
|
Loading…
Reference in New Issue
Block a user