From e0786f0fbda327de96e8ea5b1b4af81d7429d87e Mon Sep 17 00:00:00 2001 From: Navy Date: Sun, 20 Jun 2021 01:21:27 +0300 Subject: [PATCH] holy fuck what a bug --- structure/Client.js | 11 ++++++++--- structure/Modmail.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/structure/Client.js b/structure/Client.js index 31b30f6..3ffa9f8 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -57,12 +57,12 @@ class ModmailClient extends Client { this.modmail.init(); process.on('exit', () => { + this.logger.warn('process exiting'); this.saveCache(); this.modmail.saveHistory(); - // eslint-disable-next-line no-process-exit - process.exit(); }); process.on('SIGINT', () => { + this.logger.warn('received sigint'); this.saveCache.bind(this); this.modmail.saveHistory(); // eslint-disable-next-line no-process-exit @@ -96,7 +96,12 @@ class ModmailClient extends Client { if (message.author.bot) return; // No command handling in dms, at least for now - if (!message.guild) return this.modmail.handleUser(message); + if (!message.guild) try { + return this.modmail.handleUser(message); + } catch (err) { + this.logger.error(`Error during user handle:\n${err.stack}`); + return; + } const { prefix } = this; const { channel, guild, content, member } = message; diff --git a/structure/Modmail.js b/structure/Modmail.js index dad28f0..a37e15e 100644 --- a/structure/Modmail.js +++ b/structure/Modmail.js @@ -194,7 +194,7 @@ class Modmail { if (this.awaitingChannel[member.id]) return this.awaitingChannel[member.id]; // eslint-disable-next-line no-async-promise-executor - const promise = new Promise(async (resolve) => { + const promise = new Promise(async (resolve, reject) => { const channelID = this.client.cache.channels[member.id]; const guild = this.mainServer; @@ -245,19 +245,21 @@ class Modmail { continue; } - const mem = entry.author.id === member.id ? member : this.mainServer.members.resolve(entry.author); + const user = await this.client.resolveUser(entry.author).catch(this.client.logger.error.bind(this.client.logger)); + const mem = await this.getMember(user.id).catch(this.client.logger.error.bind(this.client.logger)); + if (!user) return reject(new Error(`Failed to find user`)); const embed = { footer: { - text: mem.id + text: user.id }, author: { - name: mem.user.tag + (entry.anon ? ' (ANONYMOUS REPLY)' : ''), + name: user.tag + (entry.anon ? ' (ANONYMOUS REPLY)' : ''), // eslint-disable-next-line camelcase - icon_url: mem.user.displayAvatarURL({ dynamic: true }) + icon_url: user.displayAvatarURL({ dynamic: true }) }, description: entry.content, - color: mem.highestRoleColor, + color: mem?.highestRoleColor || 0, fields: [], timestamp: new Date(entry.timestamp) };