reminder message tweaks

This commit is contained in:
Erik 2021-07-19 22:30:31 +03:00
parent 02099caa35
commit b04bbfa574
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16
3 changed files with 9 additions and 3 deletions

View File

@ -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
};
}

View File

@ -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');

View File

@ -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;
}