Setup DataService
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
export default class DataService {
|
||||
private static file: Bun.BunFile | undefined;
|
||||
private static _data: Record<string, unknown> = {};
|
||||
|
||||
static async load() {
|
||||
this.file = Bun.file("./data.json");
|
||||
if (!(await this.file.exists()))
|
||||
await Bun.write(this.file, JSON.stringify({}, null, 2));
|
||||
this._data = await this.file.json();
|
||||
}
|
||||
|
||||
static set data(data: Record<string, unknown>) {
|
||||
if (!this.file) throw new Error("DataService is not loaded. Please call DataService.load()");
|
||||
this._data = data;
|
||||
void Bun.write(this.file, JSON.stringify(this._data, null, 2));
|
||||
}
|
||||
|
||||
static get data() {
|
||||
if (!this.file) throw new Error("DataService is not loaded. Please call DataService.load()");
|
||||
return this._data
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,10 @@ export default abstract class RoleService {
|
||||
}
|
||||
}
|
||||
|
||||
static async setLimboMode(mode: boolean) {
|
||||
|
||||
}
|
||||
|
||||
static getRoleByName(guild: Guild, roleName?: string) {
|
||||
return guild.roles.cache.find(role => role.name === roleName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user