-
-
Notifications
You must be signed in to change notification settings - Fork 740
[Feature] Modal Select Components Support for IF #3189
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
base: dev
Are you sure you want to change the base?
Changes from 54 commits
627eadf
5d4d7fe
4e41461
6e95200
055fe77
297c327
1d971c8
d773b4e
3c920d4
73004bb
f6256e5
651329a
1de62c0
9a59117
fc95bb4
6c50876
b12bc40
0bc1da7
dafd51f
741aa51
85c8583
375fcfe
eca76f3
b24a115
2eb8672
81581ee
7af0c48
0ae42e0
7e878a8
120ab04
6633091
33bc29d
8bd22d8
2d9327a
8fbca81
bf63514
77d1062
a4518f1
eedf53e
54266b8
3e5e196
751a71d
02c75ea
54d0379
7ac5559
f9e11bd
1e61ea3
625e7c2
18e67aa
7d039f4
d4ff359
cb21cbe
fa4d7a1
d2b66ca
a5acfb3
56ba54f
138134f
cef3aa0
21fb8ee
c404da4
2e0b57f
51e3239
2f6d7c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System; | ||
|
|
||
| namespace Discord.Interactions; | ||
|
|
||
| /// <summary> | ||
| /// Enum values tagged with this attribute will not be displayed as a parameter choice | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This attribute must be used along with the default <see cref="EnumConverter{T}"/> and <see cref="DefaultEntityTypeConverter{T}"/>. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] | ||
| public class HideAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Can be optionally implemented by inherited types to conditionally hide an enum value. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Only runs on prior to modal construction. For slash command parameters, this method is ignored. | ||
| /// </remarks> | ||
| /// <param name="interaction">Interaction that <see cref="IDiscordInteractionExtentions.RespondWithModalAsync{T}(IDiscordInteraction, string, T, RequestOptions, Action{ModalBuilder})"/> is called on.</param> | ||
| /// <returns> | ||
| /// <see cref="true"/> if the attribute should be active and hide the value. | ||
|
Check failure on line 22 in src/Discord.Net.Interactions/Attributes/HideAttribute.cs
|
||
| /// </returns> | ||
| public virtual bool Predicate(IDiscordInteraction interaction) => true; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a channel select. | ||
| /// </summary> | ||
| public class ModalChannelSelectInputAttribute : ModalSelectInputAttribute | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ComponentType ComponentType => ComponentType.ChannelSelect; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalChannelSelectInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the channel select component.</param> | ||
| public ModalChannelSelectInputAttribute(string customId) : base(customId) | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
|
|
||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Mark an <see cref="IModal"/> property as a modal component field. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] | ||
| public abstract class ModalComponentAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Gets the type of the component. | ||
| /// </summary> | ||
| public abstract ComponentType ComponentType { get; } | ||
|
|
||
| internal ModalComponentAttribute() { } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| namespace Discord.Interactions; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a file upload input. | ||
| /// </summary> | ||
| public class ModalFileUploadInputAttribute : ModalInputAttribute | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ComponentType ComponentType => ComponentType.FileUpload; | ||
|
|
||
| /// <summary> | ||
| /// Get the minimum number of files that can be uploaded. | ||
| /// </summary> | ||
| public int MinValues { get; set; } = 1; | ||
|
|
||
| /// <summary> | ||
| /// Get the maximum number of files that can be uploaded. | ||
| /// </summary> | ||
| public int MaxValues { get; set; } = 1; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalFileUploadInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the file upload component.</param> | ||
| /// <param name="minValues">Minimum number of files that can be uploaded.</param> | ||
| /// <param name="maxValues">Maximum number of files that can be uploaded.</param> | ||
| public ModalFileUploadInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId) | ||
| { | ||
| MinValues = minValues; | ||
| MaxValues = maxValues; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Discord.Interactions; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a mentionable select input. | ||
| /// </summary> | ||
| public class ModalMentionableSelectInputAttribute : ModalSelectInputAttribute | ||
| { | ||
| /// <inheritdoc /> | ||
| public override ComponentType ComponentType => ComponentType.MentionableSelect; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalMentionableSelectInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the mentionable select component.</param> | ||
| /// <param name="minValues">Minimum number of values that can be selected.</param> | ||
| /// <param name="maxValues">Maximum number of values that can be selected</param> | ||
| public ModalMentionableSelectInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a role select input. | ||
| /// </summary> | ||
| public class ModalRoleSelectInputAttribute : ModalSelectInputAttribute | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ComponentType ComponentType => ComponentType.RoleSelect; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalRoleSelectInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the role select component.</param> | ||
| /// <param name="minValues">Minimum number of values that can be selected.</param> | ||
| /// <param name="maxValues">Maximum number of values that can be selected.</param> | ||
| public ModalRoleSelectInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace Discord.Interactions; | ||
|
|
||
| /// <summary> | ||
| /// Base attribute for select-menu, user, channel, role, and mentionable select inputs in modals. | ||
| /// </summary> | ||
| public abstract class ModalSelectInputAttribute : ModalInputAttribute | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the minimum number of values that can be selected. | ||
| /// </summary> | ||
| public int MinValues { get; set; } = 1; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the maximum number of values that can be selected. | ||
| /// </summary> | ||
| public int MaxValues { get; set; } = 1; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the placeholder text. | ||
| /// </summary> | ||
| public string Placeholder { get; set; } | ||
|
|
||
| internal ModalSelectInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId) | ||
| { | ||
| MinValues = minValues; | ||
| MaxValues = maxValues; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a select menu input. | ||
| /// </summary> | ||
| public sealed class ModalSelectMenuInputAttribute : ModalSelectInputAttribute | ||
| { | ||
| /// <inheritdoc /> | ||
| public override ComponentType ComponentType => ComponentType.SelectMenu; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalSelectMenuInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the select menu component.</param> | ||
| /// <param name="minValues">Minimum number of values that can be selected.</param> | ||
| /// <param name="maxValues">Maximum number of values that can be selected.</param> | ||
| public ModalSelectMenuInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using System; | ||
|
|
||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Adds a select menu option to the marked field. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] | ||
| public class ModalSelectMenuOptionAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Gets the label of the option. | ||
| /// </summary> | ||
| public string Label { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the description of the option. | ||
| /// </summary> | ||
| public string Description { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the value of the option. | ||
| /// </summary> | ||
| public string Value { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the emote of the option. | ||
| /// </summary> | ||
| public string Emote { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets whether the option is selected by default. | ||
| /// </summary> | ||
| public bool IsDefault { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalSelectInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="label">Label of the option.</param> | ||
| /// <param name="value">Value of the option.</param> | ||
| /// <param name="description">Description of the option.</param> | ||
| /// <param name="emote">Emote of the option.</param> | ||
| /// <param name="isDefault">Whether the option is selected by default</param> | ||
| public ModalSelectMenuOptionAttribute(string label, string value, string description = null, string emote = null, bool isDefault = false) | ||
| { | ||
| Label = label; | ||
| Value = value; | ||
| Description = description; | ||
| Emote = emote; | ||
| IsDefault = isDefault; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using Discord.Interactions.Attributes.Modals; | ||
|
|
||
| namespace Discord.Interactions; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a text input. | ||
| /// </summary> | ||
| public class ModalTextDisplayAttribute : ModalComponentAttribute | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ComponentType ComponentType => ComponentType.TextDisplay; | ||
|
|
||
| /// <summary> | ||
| /// Gets the content of the text display. | ||
| /// </summary> | ||
| public string Content { get; } | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalTextInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="content">Content of the text display.</param> | ||
| public ModalTextDisplayAttribute(string content = null) | ||
| { | ||
| Content = content; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Discord.Interactions.Attributes.Modals; | ||
|
|
||
| /// <summary> | ||
| /// Marks a <see cref="IModal"/> property as a user select input. | ||
| /// </summary> | ||
| public class ModalUserSelectInputAttribute : ModalSelectInputAttribute | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ComponentType ComponentType => ComponentType.UserSelect; | ||
|
|
||
| /// <summary> | ||
| /// Create a new <see cref="ModalUserSelectInputAttribute"/>. | ||
| /// </summary> | ||
| /// <param name="customId">Custom ID of the user select component.</param> | ||
| /// <param name="minValues">Minimum number of values that can be selected.</param> | ||
| /// <param name="maxValues">Maximum number of values that can be selected.</param> | ||
| public ModalUserSelectInputAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) | ||
| { | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.