diff --git a/src/command.ts b/src/command.ts index 78e6103..f09c10a 100644 --- a/src/command.ts +++ b/src/command.ts @@ -204,7 +204,7 @@ export class Command implements MiddlewareObj { * ```ts * bot * .filter( - * Command.hasCommand(/\/delete_(.*)/), + * Command.hasCommand(/delete_(.*)/), * (ctx) => ctx.reply(`Deleting ${ctx.message?.text?.split("_")[1]}`) * ) * ``` @@ -268,7 +268,7 @@ export class Command implements MiddlewareObj { description: string, ) { this._languages.set(languageCode, { - name: new RegExp(name), + name: name, description, }); return this; @@ -303,7 +303,9 @@ export class Command implements MiddlewareObj { public toObject(languageCode = "default"): BotCommand { const localizedName = this.getLocalizedName(languageCode); return { - command: localizedName instanceof RegExp ? "" : localizedName, + command: localizedName instanceof RegExp + ? localizedName.source + : localizedName, description: this.getLocalizedDescription(languageCode), }; } diff --git a/src/commands.ts b/src/commands.ts index c7f06b0..ad5f949 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -134,10 +134,8 @@ export class Commands { this._commands.push(command); return command; } - /** * Serializes the commands into multiple objects that can each be passed to a `setMyCommands` call. - * * @returns One item for each combination of command + scope + language */ public toArgs() { @@ -151,9 +149,8 @@ export class Commands { language_code: language === "default" ? undefined : language, - commands: commands.map((command) => - command.toObject(language) - ) + commands: commands + .map((command) => command.toObject(language)) .filter((args) => args.command.length > 0), }); } @@ -171,17 +168,16 @@ export class Commands { public toSingleScopeArgs(scope: BotCommandScope) { this._populateMetadata(); const params: SetMyCommandsParams[] = []; - for (const language of this._languages) { params.push({ scope, language_code: language === "default" ? undefined : language, commands: this._commands .filter((command) => command.scopes.length) + .filter((command) => typeof command.name === "string") .map((command) => command.toObject(language)), }); } - return params; }