Add the ability to get the counter value without changing it via nightbot command
This commit is contained in:
parent
1ea19ebe8c
commit
b301cefcae
3 changed files with 24 additions and 0 deletions
|
|
@ -59,6 +59,24 @@ const subcommands: {[index: string]: any} = {
|
|||
};
|
||||
},
|
||||
},
|
||||
"get": {
|
||||
argc: 1,
|
||||
async handler(request: Request, meta: subcommandMetadata, args: string[]) {
|
||||
const { channel } = meta;
|
||||
let counter = args[1].toLowerCase();
|
||||
if (!await database.counterExists(channel, counter)) {
|
||||
return {
|
||||
message: `That counter doesn't exist.`,
|
||||
value: 0
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
message: await database.getMessage(channel, counter),
|
||||
value: await database.getValue(channel, counter),
|
||||
};
|
||||
},
|
||||
},
|
||||
"default": {
|
||||
argc: 0,
|
||||
async handler(request: Request, meta: subcommandMetadata, args: string[]) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ export abstract class DatabaseHandler {
|
|||
|
||||
public abstract getMessage(channel: string, counter: string): Promise<string>;
|
||||
|
||||
public abstract getValue(channel: string, counter: string): Promise<number>;
|
||||
|
||||
public abstract addChannel(channel: string): Promise<void>;
|
||||
|
||||
public abstract addCounter(channel: string, counter: string): Promise<void>;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ export class JSONDatabase extends DatabaseHandler {
|
|||
return this.data[channel].counters[counter].message;
|
||||
};
|
||||
|
||||
public async getValue(channel: string, counter: string): Promise<number> {
|
||||
return this.data[channel].counters[counter].value;
|
||||
};
|
||||
|
||||
public async addChannel(channel: string) {
|
||||
if (await this.channelExists(channel)) {
|
||||
throw new Error("Channel already exists");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue