Finish up DataService persistence for limboMode
This commit is contained in:
@@ -13,3 +13,5 @@ dist/
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
data.json
|
||||
|
||||
@@ -16,6 +16,6 @@ export default {
|
||||
else
|
||||
RoleService.limboMode = !RoleService.limboMode;
|
||||
|
||||
await message.reply(`limbomode: *${ogState}* -> **${RoleService.limboMode}**`);
|
||||
await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`);
|
||||
}
|
||||
} satisfies Command;
|
||||
|
||||
@@ -3,6 +3,7 @@ interface Data {
|
||||
}
|
||||
|
||||
export default class DataService {
|
||||
private static readonly DATA_PATH = "./data.json";
|
||||
private static file: Bun.BunFile | undefined;
|
||||
private static _data: Data = {
|
||||
// default values (will be overwritten)
|
||||
@@ -10,9 +11,10 @@ export default class DataService {
|
||||
};
|
||||
|
||||
static async init() {
|
||||
this.file = Bun.file("./data.json");
|
||||
if (!(await this.file.exists()))
|
||||
await Bun.write(this.file, JSON.stringify(this._data, null, 2));
|
||||
if (!(await Bun.file(this.DATA_PATH).exists()))
|
||||
await Bun.write(Bun.file(this.DATA_PATH), JSON.stringify(this._data, null, 2));
|
||||
|
||||
this.file = Bun.file(this.DATA_PATH);
|
||||
this._data = { ...this._data, ...(await this.file.json()) };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user