From 70e1b46f4c67fa86c0702a830ac670e2d661e3f9 Mon Sep 17 00:00:00 2001 From: Oliver Akins Date: Sun, 14 Aug 2022 13:58:28 -0600 Subject: [PATCH] Add some helpful methods and change the counter data structure to allow message storage. --- src/utils/database/json.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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