diff --git a/src/endpoints/nightbot/advanced.ts b/src/endpoints/nightbot/advanced.ts index 9319ae2..464ea9c 100644 --- a/src/endpoints/nightbot/advanced.ts +++ b/src/endpoints/nightbot/advanced.ts @@ -51,10 +51,18 @@ const subcommands: {[index: string]: any} = { allowIgnored: false, argc: 1, async handler(request: Request, meta: subcommandMetadata, args: string[]) { - // args: !cmd new + // args: !cmd new [message:string...] let { channel } = meta; let counter = args[1].toLowerCase(); - await database.addCounter(channel, counter); + let message = args.length > 2 ? args.slice(2).join(` `) : undefined; + + if (!message?.includes(`$(count)`)) { + return { + message: `Can't create a counter when the message doesn't have $(count) in it somewhere`, + }; + }; + + await database.addCounter(channel, counter, message); return { message: `Counter ${counter} created successfully.`, value: 0 diff --git a/src/utils/database/json.ts b/src/utils/database/json.ts index 53a8375..a0228fd 100644 --- a/src/utils/database/json.ts +++ b/src/utils/database/json.ts @@ -55,13 +55,13 @@ export class JSONDatabase extends DatabaseHandler { }; }; - public async addCounter(channel: string, counter: string) { + public async addCounter(channel: string, counter: string, message?: string) { if (await this.counterExists(channel, counter)) { throw new Error(`Counter already exists`); }; this.data[channel].counters[counter] = { value: 0, - message: `$(value)`, + message: message ?? `$(value)`, }; };