Add some helpful methods and change the counter data structure to allow message storage.

This commit is contained in:
Oliver Akins 2022-08-14 13:58:28 -06:00
parent c2c767697a
commit 70e1b46f4c
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99

View file

@ -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;
};
};