diff --git a/src/utils/database/json.ts b/src/utils/database/json.ts index 9354dd7..0b68f5e 100644 --- a/src/utils/database/json.ts +++ b/src/utils/database/json.ts @@ -31,11 +31,32 @@ export class JSONDatabase { return this.channelExists(channel) && this.data[channel].counters[counter] != null; }; + public isUserIgnored(channel: string, user: string) { + return this.data[channel].ignored_users.includes(user); + }; + + public getMessage(channel: string, counter: string) { + return this.data[channel].counters[counter].message; + }; + public addChannel(channel: string) { if (this.channelExists(channel)) { throw new Error("Channel already exists"); }; - this.data[channel] = { counters: {} }; + this.data[channel] = { + ignored_users: [], + counters: {} + }; + }; + + public addCounter(channel: string, counter: string) { + if (this.counterExists(channel, counter)) { + throw new Error(`Counter already exists`); + }; + this.data[channel].counters[counter] = { + value: 0, + message: `$(value)`, + }; }; public changeCount(channel: string, counter: string, delta: number): number { @@ -45,6 +66,6 @@ export class JSONDatabase { if (!this.counterExists(channel, counter)) { throw new Error("Counter doesn't exist on that channel"); }; - return this.data[channel].counters[counter] += delta; + return this.data[channel].counters[counter].value += delta; }; }; \ No newline at end of file