From 60505a6a7503f731a841289d22f57a2af4dc2dba Mon Sep 17 00:00:00 2001 From: Navy Date: Sat, 19 Jun 2021 21:25:42 +0300 Subject: [PATCH] FIX TO DUMB ISSUE LOL --- structure/Client.js | 6 +++++- structure/Modmail.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/structure/Client.js b/structure/Client.js index 896cbed..1da81a9 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -57,7 +57,11 @@ class ModmailClient extends Client { this.modmail.init(); process.on('exit', this.saveCache.bind(this)); - process.on('SIGINT', this.saveCache.bind(this)); + process.on('SIGINT', () => { + this.saveCache.bind(this); + // eslint-disable-next-line no-process-exit + process.exit(); + }); this._ready = true; diff --git a/structure/Modmail.js b/structure/Modmail.js index 47a690f..f965a9d 100644 --- a/structure/Modmail.js +++ b/structure/Modmail.js @@ -510,7 +510,10 @@ class Modmail { if (this.mmcache[userId]) return resolve(this.mmcache[userId]); const path = `./modmail_cache/${userId}.json`; - if (!fs.existsSync(path)) return resolve([]); + if (!fs.existsSync(path)) { + this.mmcache[userId] = []; + return resolve(this.mmcache[userId]); + } fs.readFile(path, { encoding: 'utf-8' }, (err, data) => { if (err) reject(err); @@ -532,7 +535,11 @@ class Modmail { for (const id of toSave) { const path = `./modmail_cache/${id}.json`; - fs.writeFileSync(path, JSON.stringify(this.mmcache[id])); + try { + fs.writeFileSync(path, JSON.stringify(this.mmcache[id])); + } catch (err) { + this.client.logger.error(`Error during saving of history\n${id}\n${JSON.stringify(this.mmcache)}\n${err.stack}`); + } } }