Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: implement positional flags #2443

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Vioshim
Copy link
Contributor

@Vioshim Vioshim commented Apr 30, 2024

Summary

This allows FlagConverters to be used after the first text expression, for example

class HandleText(FlagConverter, prefix="--", delimiter=" "):
    text: str = commands.flag(positional=True)
    flip: bool = False
    
@bot.bridge_command()
async def welcome(ctx: bridge.BridgeContext, *, flags: HandleText):
    text = flags.text[::-1] if flags.flip else flags.text
    await ctx.respond(text)

# ?welcome Hello world
# ?welcome Hello world --flip True
# ?welcome --text Hello world
# ?welcome --text Hello world --flip True

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@JustaSqu1d JustaSqu1d added hold: documentation This pull request is missing documentation hold: changelog This pull request is missing a changelog entry labels Apr 30, 2024
@JustaSqu1d JustaSqu1d removed the hold: changelog This pull request is missing a changelog entry label May 22, 2024
@Dorukyum Dorukyum changed the title feat: Implements positional flags feat: implement positional flags Jun 28, 2024
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
@Lulalaby
Copy link
Member

Lulalaby commented Jul 1, 2024

@Vioshim please work on dorus comment and resolve conflcts

@JustaSqu1d JustaSqu1d added priority: medium Medium Priority feature Implements a feature python Pull requests that update Python code and removed hold: documentation This pull request is missing documentation labels Aug 7, 2024
@Lulalaby Lulalaby added this to the v2.7 milestone Aug 10, 2024
Lulalaby and others added 6 commits August 16, 2024 14:52
Signed-off-by: Lala Sabathil <lala@pycord.dev>
The typing import in flags.py has been updated to include the Optional module. This change ensures that the __commands_flag_positional__ attribute can accept a value of None.
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
@Paillat-dev
Copy link
Contributor

I have no idea how this works, but if the only thing stopping it from getting merged are conflicts, I can sure resolve those.

Lulalaby and others added 2 commits February 16, 2025 16:35
Signed-off-by: Lala Sabathil <lala@pycord.dev>
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
@Dorukyum Dorukyum added the hold: testing This pull request requires further testing label Mar 22, 2025
@Lulalaby Lulalaby added priority: low Low Priority and removed priority: medium Medium Priority labels Mar 23, 2025
@Lulalaby
Copy link
Member

@Pycord-Development/contributors can we get some testing here :D

Copy link
Contributor

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

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

File "C:\Users\Jérémie\Documents\GitHub\pycord\thing.py", line 23, in <module>
    class BasicText(FlagConverter, prefix="--", delimiter=" "):
  File "C:\Users\Jérémie\Documents\GitHub\pycord\thing.py", line 24, in BasicText
    text: str = flag(positional=True)
                ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\ext\commands\flags.py", line 143, in flag
    return Flag(
           ^^^^^
TypeError: Flag.__init__() got an unexpected keyword argument 'name'

The error does not seem to be caused by this PR, but rather by me using python 3.11. The error is not present in my testing when using python 3.10.

fix in #2759

Other than that, this seems to work to me, although I don't think I'm experienced enough with flags - and prefixed commands to assess with good certainty that everything works as expected.

@Lumabots
Copy link

does this need testing or is it ready to merge ?

@Paillat-dev
Copy link
Contributor

Needs testing + doesn't work with python 3.11+

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature Implements a feature hold: testing This pull request requires further testing priority: low Low Priority python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants