Add argument to specify the counter's message when creating it.
This commit is contained in:
parent
2a79b41ad0
commit
3f5a122bae
2 changed files with 12 additions and 4 deletions
|
|
@ -51,10 +51,18 @@ const subcommands: {[index: string]: any} = {
|
|||
allowIgnored: false,
|
||||
argc: 1,
|
||||
async handler(request: Request, meta: subcommandMetadata, args: string[]) {
|
||||
// args: !cmd new <counter:string>
|
||||
// args: !cmd new <counter:string> [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
|
||||
|
|
|
|||
|
|
@ -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)`,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue