Skip to content

Commit 9c1db3f

Browse files
CenngoMisha-133
andauthored
[Fix] Modal Write invocation without instance and missing ChannelTypes (#3221)
* add channel types to channel select builder and info * add channelTypes to select builder from IModal * remove public setter requirement from modal component definition and add guard clause to inputs * refactor modal building to run typeConverter writes even without modal instance * add inline docs to channelTypes props and method * add property as a target for ChannelTypesAttribute * move enum option building logic out of enum typeConverter * add channel type constraint mapping to channel single-select typeConverter * move SelectMenuOptionAttribute to its own file * add null forgiving operator to channel type mapping * remove list initialization from enum modal typeConverter * disallow channel default value assignment to mentionable selects * add id property to modal components * add component id assignment from attributes * update component attribute ctor signatures and inline docs * Update src/Discord.Net.Interactions/TypeConverters/ModalComponents/EnumModalComponentConverter.cs Co-authored-by: Mihail Gribkov <[email protected]> * replace default values of component ids with 0 --------- Co-authored-by: Mihail Gribkov <[email protected]>
1 parent 4fdebdc commit 9c1db3f

26 files changed

+387
-200
lines changed

src/Discord.Net.Interactions/Attributes/ChannelTypesAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Discord.Interactions
77
/// <summary>
88
/// Specify the target channel types for a <see cref="ApplicationCommandOptionType.Channel"/> option.
99
/// </summary>
10-
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
10+
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
1111
public sealed class ChannelTypesAttribute : Attribute
1212
{
1313
/// <summary>

src/Discord.Net.Interactions/Attributes/Modals/ModalChannelSelectAttribute.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ public class ModalChannelSelectAttribute : ModalSelectComponentAttribute
1212
/// Create a new <see cref="ModalChannelSelectAttribute"/>.
1313
/// </summary>
1414
/// <param name="customId">Custom ID of the channel select component.</param>
15-
public ModalChannelSelectAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) { }
15+
/// <param name="minValues">The minimum number of values that can be selected.</param>
16+
/// <param name="maxValues">The maximum number of values that can be selected.</param>
17+
/// <param name="id">Optional identifier for the component.</param>
18+
public ModalChannelSelectAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
19+
: base(customId, minValues, maxValues, id) { }
1620
}

src/Discord.Net.Interactions/Attributes/Modals/ModalComponentAttribute.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,16 @@ public abstract class ModalComponentAttribute : Attribute
1313
/// </summary>
1414
public abstract ComponentType ComponentType { get; }
1515

16-
internal ModalComponentAttribute() { }
16+
/// <summary>
17+
/// Gets the optional identifier for component.
18+
/// </summary>
19+
/// <remarks>
20+
/// Sending components with an id of 0 is allowed but will be treated as empty and replaced by the API.
21+
/// </remarks>
22+
public int Id { get; set; }
23+
24+
internal ModalComponentAttribute(int id = 0)
25+
{
26+
Id = id;
27+
}
1728
}

src/Discord.Net.Interactions/Attributes/Modals/ModalFileUploadAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public class ModalFileUploadAttribute : ModalInputAttribute
2424
/// <param name="customId">Custom ID of the file upload component.</param>
2525
/// <param name="minValues">Minimum number of files that can be uploaded.</param>
2626
/// <param name="maxValues">Maximum number of files that can be uploaded.</param>
27-
public ModalFileUploadAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId)
27+
/// <param name="id">The optional identifier for the component.</param>
28+
public ModalFileUploadAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
29+
: base(customId, id)
2830
{
2931
MinValues = minValues;
3032
MaxValues = maxValues;

src/Discord.Net.Interactions/Attributes/Modals/ModalInputAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public abstract class ModalInputAttribute : ModalComponentAttribute
1717
/// Create a new <see cref="ModalInputAttribute"/>.
1818
/// </summary>
1919
/// <param name="customId">The custom id of the input.</param>
20-
internal ModalInputAttribute(string customId)
20+
/// <param name="id">Optional identifier for component.</param>
21+
internal ModalInputAttribute(string customId, int id) : base(id)
2122
{
2223
CustomId = customId;
2324
}

src/Discord.Net.Interactions/Attributes/Modals/ModalMentionableSelectAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public class ModalMentionableSelectAttribute : ModalSelectComponentAttribute
1414
/// <param name="customId">Custom ID of the mentionable select component.</param>
1515
/// <param name="minValues">Minimum number of values that can be selected.</param>
1616
/// <param name="maxValues">Maximum number of values that can be selected</param>
17-
public ModalMentionableSelectAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) { }
17+
/// <param name="id">The optional identifier for the component.</param>
18+
public ModalMentionableSelectAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
19+
: base(customId, minValues, maxValues, id) { }
1820
}

src/Discord.Net.Interactions/Attributes/Modals/ModalRoleSelectAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public class ModalRoleSelectAttribute : ModalSelectComponentAttribute
1414
/// <param name="customId">Custom ID of the role select component.</param>
1515
/// <param name="minValues">Minimum number of values that can be selected.</param>
1616
/// <param name="maxValues">Maximum number of values that can be selected.</param>
17-
public ModalRoleSelectAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) { }
17+
/// <param name="id">The optional identifier for the component.</param>
18+
public ModalRoleSelectAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
19+
: base(customId, minValues, maxValues, id) { }
1820
}

src/Discord.Net.Interactions/Attributes/Modals/ModalSelectComponentAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public abstract class ModalSelectComponentAttribute : ModalInputAttribute
2020
/// </summary>
2121
public string Placeholder { get; set; }
2222

23-
internal ModalSelectComponentAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId)
23+
internal ModalSelectComponentAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
24+
: base(customId, id)
2425
{
2526
MinValues = minValues;
2627
MaxValues = maxValues;

src/Discord.Net.Interactions/Attributes/Modals/ModalSelectMenuAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public sealed class ModalSelectMenuAttribute : ModalSelectComponentAttribute
1414
/// <param name="customId">Custom ID of the select menu component.</param>
1515
/// <param name="minValues">Minimum number of values that can be selected.</param>
1616
/// <param name="maxValues">Maximum number of values that can be selected.</param>
17-
public ModalSelectMenuAttribute(string customId, int minValues = 1, int maxValues = 1) : base(customId, minValues, maxValues) { }
17+
/// <param name="id">The optional identifier for the component.</param>
18+
public ModalSelectMenuAttribute(string customId, int minValues = 1, int maxValues = 1, int id = 0)
19+
: base(customId, minValues, maxValues, id) { }
1820
}

src/Discord.Net.Interactions/Attributes/Modals/ModalTextDisplayAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public class ModalTextDisplayAttribute : ModalComponentAttribute
1717
/// Create a new <see cref="ModalTextInputAttribute"/>.
1818
/// </summary>
1919
/// <param name="content">Content of the text display.</param>
20-
public ModalTextDisplayAttribute(string content = null)
20+
/// <param name="id">Optional identifier for component.</param>
21+
public ModalTextDisplayAttribute(string content = null, int id = 0)
22+
: base(id)
2123
{
2224
Content = content;
2325
}

0 commit comments

Comments
 (0)