Finish up DataService persistence for limboMode
This commit is contained in:
@@ -13,3 +13,5 @@ dist/
|
|||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
data.json
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user