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

feat: implement positional flags #2443

Open
wants to merge 10 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.

docs/ext/commands/commands.rst Outdated Show resolved Hide resolved
@Dorukyum Dorukyum changed the title feat: Implements positional flags feat: implement positional flags Jun 28, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
discord/ext/commands/flags.py Outdated Show resolved Hide resolved
docs/ext/commands/commands.rst Outdated Show resolved Hide resolved
Co-authored-by: Dorukyum <[email protected]>
Co-authored-by: JustaSqu1d <[email protected]>
Signed-off-by: Lala Sabathil <[email protected]>
@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 documentation needed labels Aug 7, 2024
@Lulalaby Lulalaby added this to the v2.7 milestone Aug 10, 2024
Lulalaby and others added 5 commits August 16, 2024 14:52
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Implements a feature priority: medium Medium Priority python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants