From e58239362c5f0dcdf690409ac6fd7d2d552fc1dc Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Wed, 16 Oct 2024 15:30:14 -0400 Subject: [PATCH] Use asynchronus writes --- src/storeman/client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storeman/client.ts b/src/storeman/client.ts index 51cb3d7..7ff8536 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -21,10 +21,12 @@ import crypto from "crypto"; import { Confession, ConfessionBan, GuildData, GuildSettings } from "./types"; import { DATA_DIR } from "./config"; import { CommandInteraction, Message } from "discord.js"; +import Logger from "../utils/Logger"; export class StoreMan { public static readonly fullPath: string = (DATA_DIR ?? "./persist/") + "data.json"; + private static logger = new Logger("StoreMan"); private data: GuildData[]; constructor(existingData: GuildData[] = []) { @@ -70,11 +72,12 @@ export class StoreMan { return final; } - private saveFile(): void { - fs.writeFileSync( + public async saveFile(): Promise { + fs.writeFile( StoreMan.fullPath, JSON.stringify(this.data, null, 2), - "utf8" + "utf8", + err => err && StoreMan.logger.error("A write error occured:", err) ); }