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: properly parse converters for hybrid commands #1476

Merged

Conversation

AstreaTSS
Copy link
Member

@AstreaTSS AstreaTSS commented Jul 10, 2023

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

Who know that the complex prefixafication of slash commands could lead to bugs?

I (somewhat) kid of course. Regardless, this PR fixes one such bug - it turns out that I was assuming SlashCommandParameter.converter was, well, a Converter, when in reality it's actually the equivalent of the convert function inside of the converter (which is done so that we don't waste time initing a converter every single time... that can get quite time consuming). The hybrid command parser did not account for this, so I went back to make it do so.

Changes

  • Assume second_converter in the chain converters are functions, not actual converters. This has the extra benefit of getting rid of an import and simplifying the code.

Related Issues

Test Scenarios

class TestConverter(interactions.Converter):
    async def convert(self, ctx: interactions.SlashContext, arg: str):
        return arg.upper()

@hybrid.hybrid_slash_command(
    name="info"
)
@interactions.slash_option(
    name="arg",
    description="The argument to send",
    opt_type=interactions.OptionType.STRING,
    required=True,
)
async def dummy(ctx: hybrid.HybridContext, arg: TestConverter):
    await ctx.send(str(arg))

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@LordOfPolls LordOfPolls merged commit bbf779b into interactions-py:unstable Jul 10, 2023
1 check passed
@AstreaTSS AstreaTSS deleted the hybrid-converter-fix branch July 10, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants