[Feature] Modal Select Components Support for IF #3189
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for UserSelect, RoleSelect, ChannelSelect, MentionableSelect and SelectMenu to Interaction Framework.
At the moment this PR is a draft and stuff like declaratively defining SelectMenu options needs to be added. However the in the current state of this PR the following has been added. Contents of this PR is subject to change depending on #3172 and isn't functional currently.
To make modal generation/response flow more modular and make granular control possible, a new TypeConverter type called ModalComponentTypeConverter has been introduced. The new TypeConverter exposes a
WriteAsync<>()
method to allow the alteration of input component parameters when aRespondWithModal<>()
extension method is called. 5 default TypeConverters are included in this PR for the following types: Array, Snowflake entity, Enum, IConvertible, Nullable.With the default setup, User/Channel/Role/Mentionable select value can be automatically mapped to single
IUser
/IRole
/IChannel
entities if a single-select is used, toIUser[]
/IRole[]
/IChannel[]
arrays if a multi-select is used. For SelectMenu components, just like with message component SelectMenus, the converter falls back to a TypeReader for converting the returned string values to the underlying CLR type. Enums can be used to auto-populate SelectMenu options and returned values can be mapped to regular enums if a single-select is used, to flags enums if a multi-select is used.[HideAttribute]
used for SlashCommand parameters, can be used to hide select enum values,and a new
[SelectMenuOptionAttribute]
can be used to define description, emote, and IsDefault values for individul enum values. Nullable types can be used which use the ModalComponentTypeConverter assigned to the underlying type for convertion. And finally, TextInput and single-select menu values can be converted toIConvertible
types. Instance values of the component properties are used to supply the default values of components.