error outputs for missing categories

This commit is contained in:
Erik 2021-07-09 15:29:17 +03:00
parent 355b671aa5
commit edf20f63f0
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16
2 changed files with 11 additions and 2 deletions

View File

@ -6,7 +6,7 @@ module.exports = {
mainGuild: '', // main server of operation mainGuild: '', // main server of operation
bansGuild: '', // optional bans server for potential appeals processing bansGuild: '', // optional bans server for potential appeals processing
prefix: '!', prefix: '!',
modmailCategory: [], // Should have 3 category IDs, main category (new), answered/waiting for reply, graveyard (old modmail channels getting ready for deletion) modmailCategory: [], // Should have 3 category IDs (AS STRINGS), main category (new), answered/waiting for reply, graveyard (old modmail channels getting ready for deletion)
context: 10, // How many messages to load for context context: 10, // How many messages to load for context
staffRoles: [], // Roles that have access to the bot commands staffRoles: [], // Roles that have access to the bot commands
graveyardInactive: 60, // How long a channel should be inactive for in the graveyard before deletion graveyardInactive: 60, // How long a channel should be inactive for in the graveyard before deletion

View File

@ -10,7 +10,7 @@ class ChannelHandler {
this.mainServer = null; this.mainServer = null;
this.bansServer = null; this.bansServer = null;
this.categories = opts.modmailCategory; this.categories = opts.modmailCategory.map((id) => id.toString());
this.cache = modmail.cache; this.cache = modmail.cache;
this.graveyardInactive = opts.graveyardInactive; this.graveyardInactive = opts.graveyardInactive;
@ -26,8 +26,15 @@ class ChannelHandler {
const { channels } = this.mainServer; const { channels } = this.mainServer;
this.newMail = channels.resolve(this.categories[0]); this.newMail = channels.resolve(this.categories[0]);
if (!this.newMail) this.client.logger.warn(`Missing new mail category!`);
this.readMail = channels.resolve(this.categories[1]); this.readMail = channels.resolve(this.categories[1]);
if (!this.readMail) this.client.logger.warn(`Missing read mail category!`);
this.graveyard = channels.resolve(this.categories[2]); this.graveyard = channels.resolve(this.categories[2]);
if (!this.graveyard) this.client.logger.warn(`Missing graveyard category!`);
if (!this.newMail || !this.readMail || !this.graveyard) {
this.client.logger.debug(`Some mail categories were missing: ${this.categories}`);
}
// Sweep graveyard every x min and move stale channels to graveyard // Sweep graveyard every x min and move stale channels to graveyard
this.sweeper = setInterval(this.sweepChannels.bind(this), this.channelSweepInterval * 60 * 1000); this.sweeper = setInterval(this.sweepChannels.bind(this), this.channelSweepInterval * 60 * 1000);
@ -211,6 +218,7 @@ class ChannelHandler {
this.client.logger.info(`Sweeping graveyard`); this.client.logger.info(`Sweeping graveyard`);
const now = Date.now(); const now = Date.now();
if (!this.graveyard) return this.client.logger.error(`Missing graveyard category!`);
const graveyardChannels = this.graveyard.children.sort((a, b) => { const graveyardChannels = this.graveyard.children.sort((a, b) => {
if (!a.lastMessage) return -1; if (!a.lastMessage) return -1;
if (!b.lastMessage) return 1; if (!b.lastMessage) return 1;
@ -241,6 +249,7 @@ class ChannelHandler {
} }
this.client.logger.info(`Swept ${channelCount} channels from graveyard, cleaning up answered...`); this.client.logger.info(`Swept ${channelCount} channels from graveyard, cleaning up answered...`);
if (!this.readMail) return this.client.logger.error(`Missing read mail category!`);
const answered = this.readMail.children const answered = this.readMail.children
.filter((channel) => !channel.lastMessage || channel.lastMessage.createdTimestamp < Date.now() - this.readInactive * 60 * 1000 || force) .filter((channel) => !channel.lastMessage || channel.lastMessage.createdTimestamp < Date.now() - this.readInactive * 60 * 1000 || force)