FIX TO DUMB ISSUE LOL

This commit is contained in:
Erik 2021-06-19 21:25:42 +03:00
parent 2a9218e7f3
commit 60505a6a75
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16
2 changed files with 14 additions and 3 deletions

View File

@ -57,7 +57,11 @@ class ModmailClient extends Client {
this.modmail.init(); this.modmail.init();
process.on('exit', this.saveCache.bind(this)); 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; this._ready = true;

View File

@ -510,7 +510,10 @@ class Modmail {
if (this.mmcache[userId]) return resolve(this.mmcache[userId]); if (this.mmcache[userId]) return resolve(this.mmcache[userId]);
const path = `./modmail_cache/${userId}.json`; 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) => { fs.readFile(path, { encoding: 'utf-8' }, (err, data) => {
if (err) reject(err); if (err) reject(err);
@ -532,7 +535,11 @@ class Modmail {
for (const id of toSave) { for (const id of toSave) {
const path = `./modmail_cache/${id}.json`; 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}`);
}
} }
} }