Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: localization command names being empty #14

Merged
merged 2 commits into from
May 18, 2024

Conversation

carafelix
Copy link
Member

@carafelix carafelix commented May 2, 2024

fixes #13 by removing regExp conversion to, and type support from _lenguages set in Command class:
output quoted in the issue now looks like:

[
  {
    scope: { type: "chat", chat_id: 333649403 },
    language_code: undefined,
    commands: [
      { command: "start", description: "init bot" },
      { command: "end", description: "end" }
    ]
  },
  {
    scope: { type: "chat", chat_id: 333649403 },
    language_code: "es",
    commands: [
      { command: "iniciar", description: "Inicializa el bot" },
      { command: "fin", description: "finaliza" }
    ]
  }
]

other functionality is not broken

@carafelix carafelix changed the title fix #13 by removing regExp conversion, and type from _lenguages set in Command class fix localization command names being empty May 2, 2024
@carafelix carafelix changed the title fix localization command names being empty fix: localization command names being empty May 2, 2024
Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 67.63%. Comparing base (63bc0fa) to head (761470e).

Current head 761470e differs from pull request most recent head 1ff6856

Please upload reports for the commit 1ff6856 to get more accurate results.

Files Patch % Lines
src/command.ts 0.00% 4 Missing ⚠️
src/commands.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
- Coverage   68.13%   67.63%   -0.50%     
==========================================
  Files           7        7              
  Lines         408      411       +3     
  Branches       66       66              
==========================================
  Hits          278      278              
- Misses        128      131       +3     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@carafelix
Copy link
Member Author

I have a new idea, instead of making a new regexCommand class, the commands.comand method could accept a type parameter, and check at runtime. I think it should be more straight forward

@roziscoding
Copy link
Contributor

I have a new idea, instead of making a new regexCommand class, the commands.comand method could accept a type parameter, and check at runtime. I think it should be more straight forward

sorry for the delay on this.
what I was thinking is that we could stop converting every command to RegEx, and then we could just skip commands where name is a RegEx when calling setMyCommands (on the toArgs method).
Because RegEx commands aren't meant to be typed by hand or selected from the commands list anyway.

@carafelix
Copy link
Member Author

carafelix commented May 11, 2024

I have a design question:

  • Are RegEx commands meant to be supported by the getNearestCommand method? Because using RegEx.source it could be possible to support the nearest command (since FuzzyMatch its using .toArgs to serialize).
  • I think it could be good to also output the prefix from FuzzySearch, so Did you mean ${prefix}${commandName}? can be done.

I'll update the PR to

skip commands where name is a RegEx when calling setMyCommands (on the toArgs method)

And the first point of the two points, if you are good with the 2nd one I can add it too

@carafelix
Copy link
Member Author

carafelix commented May 11, 2024

Done. Tested in a dummy bot. One thing to note. I didn't add the prefilter of regex to the toArgs, only to the toSingleScopeArgs, since doing that would prevent fuzzyMatch to lookup the regex commands for similar ones. One solution would be to overload the toArgs method for the use case of SetMyCommands and SetCommands``, and another one for fuzzyMatch``` (that one could also output prefix).

@carafelix carafelix reopened this May 14, 2024
@carafelix
Copy link
Member Author

Removed pollution from commit history

@roziscoding
Copy link
Contributor

Would you be willing to add automated tests for the two functions that were changed?
I'd go with something simple like instantiating a command, then calling them and checking if the returned object / array is what we expect. Then do that for a command with string name and with regex name.

WDYT?

@carafelix
Copy link
Member Author

carafelix commented May 16, 2024

Would you be willing to add automated tests for the two functions that were changed?

Sure, I'll do it asap

Copy link
Contributor

@roziscoding roziscoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
thank you so much! ❤️

@roziscoding roziscoding merged commit db51f08 into grammyjs:main May 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants