diff --git a/src/endpoints/nightbot/advanced.ts b/src/endpoints/nightbot/advanced.ts index 403463b..f9d7b11 100644 --- a/src/endpoints/nightbot/advanced.ts +++ b/src/endpoints/nightbot/advanced.ts @@ -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[]) { diff --git a/src/utils/Database.ts b/src/utils/Database.ts index b95dc2f..8fad354 100644 --- a/src/utils/Database.ts +++ b/src/utils/Database.ts @@ -9,6 +9,8 @@ export abstract class DatabaseHandler { public abstract getMessage(channel: string, counter: string): Promise; + public abstract getValue(channel: string, counter: string): Promise; + public abstract addChannel(channel: string): Promise; public abstract addCounter(channel: string, counter: string): Promise; diff --git a/src/utils/database/json.ts b/src/utils/database/json.ts index 5177fb9..53a8375 100644 --- a/src/utils/database/json.ts +++ b/src/utils/database/json.ts @@ -41,6 +41,10 @@ export class JSONDatabase extends DatabaseHandler { return this.data[channel].counters[counter].message; }; + public async getValue(channel: string, counter: string): Promise { + return this.data[channel].counters[counter].value; + }; + public async addChannel(channel: string) { if (await this.channelExists(channel)) { throw new Error("Channel already exists");