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

Add defaults for auto-populated selects #1804

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

Conversation

hypergonial
Copy link
Contributor

Summary

Add default_values attribute for auto-populated selects. This did require some fairly significant restructuring to make type-safe, and honestly I'm still not quite happy with the result, so feedback is welcome.

The select types have been completely seperated, so the new hierarchy of components looks something like this:

SelectMenu
TextSelect(SelectMenu)
AutoPopulatingSelect(SelectMenu)
ChannelSelect(AutoPopulatingSelect) 
RoleSelect(AutoPopulatingSelect)
UserSelect(AutoPopulatingSelect)
MentionableSelect(AutoPopulatingSelect)

This PR also deprecates ActionRowBuilder.add_select_menu() as type-specific methods have been added for each select type. I feel like seperating the select types is better for type safety and potentially more future-proof if Discord decides add specific behaviours to a given select type down the line.

Example

row = rest.build_message_action_row().add_user_menu(
    "Test",
    placeholder="Amongus",
    min_values=1,
    max_values=2,
    default_values=[
        hikari.impl.SelectDefaultBuilder(
            163979124820541440, type=hikari.SelectDefaultType.USER
        ),
        hikari.impl.SelectDefaultBuilder(
            1184650183401803906, type=hikari.SelectDefaultType.USER
        ),
    ],
)

I tried an alternative interface where the snowflake's type could be inferred from the select's type, however this is not possible due to it being possible to mix default types in mentionable selects, so at the moment this is the best I could come up with.

The implementation tries to be type-safe to the extent that adding an invalid default type fails type-checking:

row = rest.build_message_action_row().add_user_menu(
    "Test",
    placeholder="Amongus",
    min_values=1,
    max_values=2,
    default_values=[
        hikari.impl.SelectDefaultBuilder( # Type error
            163979124820541440, type=hikari.SelectDefaultType.ROLE
        )
    ],
)

Checklist

  • I have run nox and all the pipelines have passed.
  • I have made unittests according to the code I have added/modified/deleted.

Related issues

Closes #1776

@davfsa
Copy link
Member

davfsa commented Jan 21, 2024

I need to have a think about the restructure, but will most probably forget about it, so please ping me in the near future if I dont respond :)

@@ -2086,6 +2207,10 @@ def add_select_menu(
`MessageActionRowBuilder.add_channel_menu` and
`MessageActionRowBuilder.add_text_menu`.

.. deprecated:: 2.0.0.dev123
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just leaving this here as a note that these versions have to be bumped before this is merged

@beagold beagold added the enhancement New feature or request label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement default select values
4 participants