Add some helpful methods and change the counter data structure to allow message storage.
This commit is contained in:
parent
c2c767697a
commit
70e1b46f4c
1 changed files with 23 additions and 2 deletions
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue