Finish up DataService persistence for limboMode

This commit is contained in:
2026-08-22 19:28:57 -04:00
parent e0fb166dd2
commit 4bd77fad8a
3 changed files with 8 additions and 4 deletions
+2
View File
@@ -13,3 +13,5 @@ dist/
# OS # OS
.DS_Store .DS_Store
Thumbs.db Thumbs.db
data.json
+1 -1
View File
@@ -16,6 +16,6 @@ export default {
else else
RoleService.limboMode = !RoleService.limboMode; RoleService.limboMode = !RoleService.limboMode;
await message.reply(`limbomode: *${ogState}* -> **${RoleService.limboMode}**`); await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`);
} }
} satisfies Command; } satisfies Command;
+5 -3
View File
@@ -3,6 +3,7 @@ interface Data {
} }
export default class DataService { export default class DataService {
private static readonly DATA_PATH = "./data.json";
private static file: Bun.BunFile | undefined; private static file: Bun.BunFile | undefined;
private static _data: Data = { private static _data: Data = {
// default values (will be overwritten) // default values (will be overwritten)
@@ -10,9 +11,10 @@ export default class DataService {
}; };
static async init() { static async init() {
this.file = Bun.file("./data.json"); if (!(await Bun.file(this.DATA_PATH).exists()))
if (!(await this.file.exists())) await Bun.write(Bun.file(this.DATA_PATH), JSON.stringify(this._data, null, 2));
await Bun.write(this.file, JSON.stringify(this._data, null, 2));
this.file = Bun.file(this.DATA_PATH);
this._data = { ...this._data, ...(await this.file.json()) }; this._data = { ...this._data, ...(await this.file.json()) };
} }