Bug fixes and ~~performance~~ typing improvements
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 140dbcc..04c9e24 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -17,16 +17,9 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(target: Record<string, any>, prop: string, receiver: any) {
let dataToReturn = data[prop];
- if (dataToReturn === null)
- return Reflect.get(target, prop, receiver);
- if (
- typeof dataToReturn === "object" &&
- !Array.isArray(dataToReturn)
- )
- dataToReturn = new Proxy(
- Reflect.get(target, prop, receiver),
- Entry(dataToReturn)
- );
+ if (dataToReturn === null) return Reflect.get(target, prop, receiver);
+ if (typeof dataToReturn === "object" && !Array.isArray(dataToReturn))
+ dataToReturn = new Proxy(Reflect.get(target, prop, receiver), Entry(dataToReturn));
return dataToReturn ?? Reflect.get(target, prop, receiver);
}
};
@@ -43,24 +36,17 @@
}
async setup() {
- this.defaultData = (
- await import("../config/default.json", { assert: { type: "json" } })
- ).default as unknown as GuildConfig;
+ this.defaultData = (await import("../config/default.json", { assert: { type: "json" } }))
+ .default as unknown as GuildConfig;
+ return this;
}
async read(guild: string) {
const entry = await this.guilds.findOne({ id: guild });
- return new Proxy(
- structuredClone(this.defaultData),
- Entry(entry)
- ) as unknown as GuildConfig;
+ return new Proxy(structuredClone(this.defaultData), Entry(entry)) as unknown as GuildConfig;
}
- async write(
- guild: string,
- set: object | null,
- unset: string[] | string = []
- ) {
+ async write(guild: string, set: object | null, unset: string[] | string = []) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const uo: Record<string, any> = {};
if (!Array.isArray(unset)) unset = [unset];
@@ -195,11 +181,7 @@
}
async create(guild: string, user: string, note: string | null) {
- await this.modNotes.updateOne(
- { guild: guild, user: user },
- { $set: { note: note } },
- { upsert: true }
- );
+ await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
}
async read(guild: string, user: string) {