Skip to content

Commit

Permalink
fix localization names being empty,
Browse files Browse the repository at this point in the history
  • Loading branch information
carafelix committed May 14, 2024
1 parent 63bc0fa commit 604604e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Command<C extends Context = Context> implements MiddlewareObj<C> {
* ```ts
* bot
* .filter(
* Command.hasCommand(/\/delete_(.*)/),
* Command.hasCommand(/delete_(.*)/),
* (ctx) => ctx.reply(`Deleting ${ctx.message?.text?.split("_")[1]}`)
* )
* ```
Expand Down Expand Up @@ -268,7 +268,7 @@ export class Command<C extends Context = Context> implements MiddlewareObj<C> {
description: string,
) {
this._languages.set(languageCode, {
name: new RegExp(name),
name: name,
description,
});
return this;
Expand Down Expand Up @@ -303,7 +303,9 @@ export class Command<C extends Context = Context> implements MiddlewareObj<C> {
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),
};
}
Expand Down
10 changes: 3 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ export class Commands<C extends Context> {
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() {
Expand All @@ -151,9 +149,8 @@ export class Commands<C extends Context> {
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),
});
}
Expand All @@ -171,17 +168,16 @@ export class Commands<C extends Context> {
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;
}

Expand Down

0 comments on commit 604604e

Please sign in to comment.