* Refactor emojis/emotes & SelectMenu * Update Emoji.cs * Continue emoji refactor * Remove WithLabel from example of SelectMenuBuilder * Remove EmojiUtils and move it stuff to Emoji * Revertpull/1923/head0fbf1000da
* Revert "Update Emoji.cs" and add Parse method This reverts commitf297dcfc43
. * Partial revert3c27ab36c9
@@ -96,7 +96,6 @@ Theres a new field in all `SendMessageAsync` functions that takes in a `MessageC | |||||
var builder = new ComponentBuilder() | var builder = new ComponentBuilder() | ||||
.WithSelectMenu(new SelectMenuBuilder() | .WithSelectMenu(new SelectMenuBuilder() | ||||
.WithCustomId("id_2") | .WithCustomId("id_2") | ||||
.WithLabel("Select menu!") | |||||
.WithPlaceholder("This is a placeholder") | .WithPlaceholder("This is a placeholder") | ||||
.WithOptions(new List<SelectMenuOptionBuilder>() | .WithOptions(new List<SelectMenuOptionBuilder>() | ||||
{ | { | ||||
@@ -2106,7 +2106,7 @@ | |||||
</member> | </member> | ||||
<member name="M:Discord.Emoji.ToString"> | <member name="M:Discord.Emoji.ToString"> | ||||
<summary> | <summary> | ||||
Gets the Unicode representation of this emote. | |||||
Gets the Unicode representation of this emoji. | |||||
</summary> | </summary> | ||||
<returns> | <returns> | ||||
A string that resolves to <see cref="P:Discord.Emoji.Name"/>. | A string that resolves to <see cref="P:Discord.Emoji.Name"/>. | ||||
@@ -2124,6 +2124,17 @@ | |||||
</summary> | </summary> | ||||
<param name="other">The object to compare with the current object.</param> | <param name="other">The object to compare with the current object.</param> | ||||
</member> | </member> | ||||
<member name="M:Discord.Emoji.TryParse(System.String,Discord.Emoji@)"> | |||||
<summary> Tries to parse an <see cref="T:Discord.Emoji"/> from its raw format. </summary> | |||||
<param name="text">The raw encoding of an emoji. For example: <code>:heart: or ❤</code></param> | |||||
<param name="result">An emoji.</param> | |||||
</member> | |||||
<member name="M:Discord.Emoji.Parse(System.String)"> | |||||
<summary> Parse an <see cref="T:Discord.Emoji"/> from its raw format. </summary> | |||||
<param name="text">The raw encoding of an emoji. For example: <c>:heart: or ❤</c></param> | |||||
<param name="result">An emoji.</param> | |||||
<exception cref="T:System.FormatException">String is not emoji or unicode!</exception> | |||||
</member> | |||||
<member name="M:Discord.Emoji.GetHashCode"> | <member name="M:Discord.Emoji.GetHashCode"> | ||||
<inheritdoc /> | <inheritdoc /> | ||||
</member> | </member> | ||||
@@ -4361,7 +4372,7 @@ | |||||
Gets or sets the Action Rows for this Component Builder. | Gets or sets the Action Rows for this Component Builder. | ||||
</summary> | </summary> | ||||
</member> | </member> | ||||
<member name="M:Discord.ComponentBuilder.WithSelectMenu(System.String,System.String,System.Collections.Generic.List{Discord.SelectMenuOptionBuilder},System.String,System.Int32,System.Int32,System.Int32)"> | |||||
<member name="M:Discord.ComponentBuilder.WithSelectMenu(System.String,System.String,System.Collections.Generic.List{Discord.SelectMenuOptionBuilder},System.String,System.Int32,System.Int32,System.Boolean,System.Int32)"> | |||||
<summary> | <summary> | ||||
Adds a <see cref="T:Discord.SelectMenuBuilder"/> to the first row, if the first row cannot | Adds a <see cref="T:Discord.SelectMenuBuilder"/> to the first row, if the first row cannot | ||||
accept the component then it will add it to a row that can | accept the component then it will add it to a row that can | ||||
@@ -4372,6 +4383,7 @@ | |||||
<param name="placeholder">The placeholder of the menu.</param> | <param name="placeholder">The placeholder of the menu.</param> | ||||
<param name="minValues">The min values of the placeholder.</param> | <param name="minValues">The min values of the placeholder.</param> | ||||
<param name="maxValues">The max values of the placeholder.</param> | <param name="maxValues">The max values of the placeholder.</param> | ||||
<param name="disabled">Whether or not the menu is disabled.</param> | |||||
<param name="row">The row to add the menu to.</param> | <param name="row">The row to add the menu to.</param> | ||||
<returns></returns> | <returns></returns> | ||||
</member> | </member> | ||||
@@ -4607,11 +4619,6 @@ | |||||
The maximum number of options a <see cref="T:Discord.SelectMenu"/> can have. | The maximum number of options a <see cref="T:Discord.SelectMenu"/> can have. | ||||
</summary> | </summary> | ||||
</member> | </member> | ||||
<member name="P:Discord.SelectMenuBuilder.Label"> | |||||
<summary> | |||||
Gets or sets the label of the current select menu. | |||||
</summary> | |||||
</member> | |||||
<member name="P:Discord.SelectMenuBuilder.CustomId"> | <member name="P:Discord.SelectMenuBuilder.CustomId"> | ||||
<summary> | <summary> | ||||
Gets or sets the custom id of the current select menu. | Gets or sets the custom id of the current select menu. | ||||
@@ -4637,6 +4644,11 @@ | |||||
Gets or sets a collection of <see cref="T:Discord.SelectMenuOptionBuilder"/> for this current select menu. | Gets or sets a collection of <see cref="T:Discord.SelectMenuOptionBuilder"/> for this current select menu. | ||||
</summary> | </summary> | ||||
</member> | </member> | ||||
<member name="P:Discord.SelectMenuBuilder.Disabled"> | |||||
<summary> | |||||
Gets or sets whether the current menu is disabled. | |||||
</summary> | |||||
</member> | |||||
<member name="M:Discord.SelectMenuBuilder.#ctor"> | <member name="M:Discord.SelectMenuBuilder.#ctor"> | ||||
<summary> | <summary> | ||||
Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>. | Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>. | ||||
@@ -4649,15 +4661,6 @@ | |||||
<param name="customId">The custom id of this select menu.</param> | <param name="customId">The custom id of this select menu.</param> | ||||
<param name="options">The options for this select menu.</param> | <param name="options">The options for this select menu.</param> | ||||
</member> | </member> | ||||
<member name="M:Discord.SelectMenuBuilder.WithLabel(System.String)"> | |||||
<summary> | |||||
Sets the field label. | |||||
</summary> | |||||
<param name="label">The value to set the field label to.</param> | |||||
<returns> | |||||
The current builder. | |||||
</returns> | |||||
</member> | |||||
<member name="M:Discord.SelectMenuBuilder.WithCustomId(System.String)"> | <member name="M:Discord.SelectMenuBuilder.WithCustomId(System.String)"> | ||||
<summary> | <summary> | ||||
Sets the field CustomId. | Sets the field CustomId. | ||||
@@ -4703,6 +4706,15 @@ | |||||
The current builder. | The current builder. | ||||
</returns> | </returns> | ||||
</member> | </member> | ||||
<member name="M:Discord.SelectMenuBuilder.WithDisabled(System.Boolean)"> | |||||
<summary> | |||||
Sets whether the current menu is disabled. | |||||
</summary> | |||||
<param name="disabled">Whether the current menu is disabled or not.</param> | |||||
<returns> | |||||
The current builder. | |||||
</returns> | |||||
</member> | |||||
<member name="M:Discord.SelectMenuBuilder.Build"> | <member name="M:Discord.SelectMenuBuilder.Build"> | ||||
<summary> | <summary> | ||||
Builds a <see cref="T:Discord.SelectMenu"/> | Builds a <see cref="T:Discord.SelectMenu"/> | ||||
@@ -4880,6 +4892,11 @@ | |||||
The maximum number of items that can be chosen; default 1, max 25 | The maximum number of items that can be chosen; default 1, max 25 | ||||
</summary> | </summary> | ||||
</member> | </member> | ||||
<member name="P:Discord.SelectMenu.Disabled"> | |||||
<summary> | |||||
Whether this menu is disabled or not. | |||||
</summary> | |||||
</member> | |||||
<member name="T:Discord.SelectMenuOption"> | <member name="T:Discord.SelectMenuOption"> | ||||
<summary> | <summary> | ||||
Represents a choice for a <see cref="T:Discord.SelectMenu"/>. | Represents a choice for a <see cref="T:Discord.SelectMenu"/>. | ||||
@@ -1,8 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -54,18 +52,19 @@ namespace Discord | |||||
/// <param name="placeholder">The placeholder of the menu.</param> | /// <param name="placeholder">The placeholder of the menu.</param> | ||||
/// <param name="minValues">The min values of the placeholder.</param> | /// <param name="minValues">The min values of the placeholder.</param> | ||||
/// <param name="maxValues">The max values of the placeholder.</param> | /// <param name="maxValues">The max values of the placeholder.</param> | ||||
/// <param name="disabled">Whether or not the menu is disabled.</param> | |||||
/// <param name="row">The row to add the menu to.</param> | /// <param name="row">The row to add the menu to.</param> | ||||
/// <returns></returns> | /// <returns></returns> | ||||
public ComponentBuilder WithSelectMenu(string label, string customId, List<SelectMenuOptionBuilder> options, | public ComponentBuilder WithSelectMenu(string label, string customId, List<SelectMenuOptionBuilder> options, | ||||
string placeholder = null, int minValues = 1, int maxValues = 1, int row = 0) | |||||
string placeholder = null, int minValues = 1, int maxValues = 1, bool disabled = false, int row = 0) | |||||
{ | { | ||||
return WithSelectMenu(new SelectMenuBuilder() | return WithSelectMenu(new SelectMenuBuilder() | ||||
.WithLabel(label) | |||||
.WithCustomId(customId) | .WithCustomId(customId) | ||||
.WithOptions(options) | .WithOptions(options) | ||||
.WithPlaceholder(placeholder) | .WithPlaceholder(placeholder) | ||||
.WithMaxValues(maxValues) | .WithMaxValues(maxValues) | ||||
.WithMinValues(minValues), | |||||
.WithMinValues(minValues) | |||||
.WithDisabled(disabled), | |||||
row); | row); | ||||
} | } | ||||
@@ -557,22 +556,6 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public const int MaxOptionCount = 25; | public const int MaxOptionCount = 25; | ||||
/// <summary> | |||||
/// Gets or sets the label of the current select menu. | |||||
/// </summary> | |||||
public string Label | |||||
{ | |||||
get => _label; | |||||
set | |||||
{ | |||||
if (value != null) | |||||
if (value.Length > ComponentBuilder.MaxLabelLength) | |||||
throw new ArgumentException(message: $"Button label must be {ComponentBuilder.MaxLabelLength} characters or less!", paramName: nameof(Label)); | |||||
_label = value; | |||||
} | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets the custom id of the current select menu. | /// Gets or sets the custom id of the current select menu. | ||||
/// </summary> | /// </summary> | ||||
@@ -608,11 +591,11 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public int MinValues | public int MinValues | ||||
{ | { | ||||
get => _minvalues; | |||||
get => _minValues; | |||||
set | set | ||||
{ | { | ||||
Preconditions.LessThan(value, MaxValuesCount, nameof(MinValues)); | Preconditions.LessThan(value, MaxValuesCount, nameof(MinValues)); | ||||
_minvalues = value; | |||||
_minValues = value; | |||||
} | } | ||||
} | } | ||||
@@ -621,11 +604,11 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public int MaxValues | public int MaxValues | ||||
{ | { | ||||
get => _maxvalues; | |||||
get => _maxValues; | |||||
set | set | ||||
{ | { | ||||
Preconditions.LessThan(value, MaxValuesCount, nameof(MaxValues)); | Preconditions.LessThan(value, MaxValuesCount, nameof(MaxValues)); | ||||
_maxvalues = value; | |||||
_maxValues = value; | |||||
} | } | ||||
} | } | ||||
@@ -644,11 +627,15 @@ namespace Discord | |||||
} | } | ||||
} | } | ||||
/// <summary> | |||||
/// Gets or sets whether the current menu is disabled. | |||||
/// </summary> | |||||
public bool Disabled { get; set; } | |||||
private List<SelectMenuOptionBuilder> _options; | private List<SelectMenuOptionBuilder> _options; | ||||
private int _minvalues = 1; | |||||
private int _maxvalues = 1; | |||||
private int _minValues = 1; | |||||
private int _maxValues = 1; | |||||
private string _placeholder; | private string _placeholder; | ||||
private string _label; | |||||
private string _customId; | private string _customId; | ||||
/// <summary> | /// <summary> | ||||
@@ -667,19 +654,6 @@ namespace Discord | |||||
this.Options = options; | this.Options = options; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets the field label. | |||||
/// </summary> | |||||
/// <param name="label">The value to set the field label to.</param> | |||||
/// <returns> | |||||
/// The current builder. | |||||
/// </returns> | |||||
public SelectMenuBuilder WithLabel(string label) | |||||
{ | |||||
this.Label = label; | |||||
return this; | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Sets the field CustomId. | /// Sets the field CustomId. | ||||
/// </summary> | /// </summary> | ||||
@@ -745,15 +719,28 @@ namespace Discord | |||||
return this; | return this; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets whether the current menu is disabled. | |||||
/// </summary> | |||||
/// <param name="disabled">Whether the current menu is disabled or not.</param> | |||||
/// <returns> | |||||
/// The current builder. | |||||
/// </returns> | |||||
public SelectMenuBuilder WithDisabled(bool disabled) | |||||
{ | |||||
this.Disabled = disabled; | |||||
return this; | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Builds a <see cref="SelectMenu"/> | /// Builds a <see cref="SelectMenu"/> | ||||
/// </summary> | /// </summary> | ||||
/// <returns>The newly built <see cref="SelectMenu"/></returns> | /// <returns>The newly built <see cref="SelectMenu"/></returns> | ||||
public SelectMenu Build() | public SelectMenu Build() | ||||
{ | { | ||||
var opt = this.Options?.Select(x => x.Build()).ToList(); | |||||
var options = this.Options?.Select(x => x.Build()).ToList(); | |||||
return new SelectMenu(this.CustomId, opt, this.Placeholder, this.MinValues, this.MaxValues); | |||||
return new SelectMenu(this.CustomId, options, this.Placeholder, this.MinValues, this.MaxValues, this.Disabled); | |||||
} | } | ||||
} | } | ||||
@@ -39,13 +39,19 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public int MaxValues { get; } | public int MaxValues { get; } | ||||
internal SelectMenu(string customId, List<SelectMenuOption> options, string placeholder, int minValues, int maxValues) | |||||
/// <summary> | |||||
/// Whether this menu is disabled or not. | |||||
/// </summary> | |||||
public bool Disabled { get; } | |||||
internal SelectMenu(string customId, List<SelectMenuOption> options, string placeholder, int minValues, int maxValues, bool disabled) | |||||
{ | { | ||||
this.CustomId = customId; | this.CustomId = customId; | ||||
this.Options = options; | this.Options = options; | ||||
this.Placeholder = placeholder; | this.Placeholder = placeholder; | ||||
this.MinValues = minValues; | this.MinValues = minValues; | ||||
this.MaxValues = maxValues; | this.MaxValues = maxValues; | ||||
this.Disabled = disabled; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -27,6 +27,9 @@ namespace Discord.API | |||||
[JsonProperty("max_values")] | [JsonProperty("max_values")] | ||||
public int MaxValues { get; set; } | public int MaxValues { get; set; } | ||||
[JsonProperty("disabled")] | |||||
public bool Disabled { get; set; } | |||||
public SelectMenuComponent() { } | public SelectMenuComponent() { } | ||||
public SelectMenuComponent(Discord.SelectMenu component) | public SelectMenuComponent(Discord.SelectMenu component) | ||||
@@ -37,6 +40,7 @@ namespace Discord.API | |||||
this.Placeholder = component.Placeholder; | this.Placeholder = component.Placeholder; | ||||
this.MinValues = component.MinValues; | this.MinValues = component.MinValues; | ||||
this.MaxValues = component.MaxValues; | this.MaxValues = component.MaxValues; | ||||
this.Disabled = component.Disabled; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -174,7 +174,8 @@ namespace Discord.Rest | |||||
z.Default.ToNullable())).ToList(), | z.Default.ToNullable())).ToList(), | ||||
parsed.Placeholder.GetValueOrDefault(), | parsed.Placeholder.GetValueOrDefault(), | ||||
parsed.MinValues, | parsed.MinValues, | ||||
parsed.MaxValues | |||||
parsed.MaxValues, | |||||
parsed.Disabled | |||||
); | ); | ||||
} | } | ||||
default: | default: | ||||
@@ -230,7 +231,7 @@ namespace Discord.Rest | |||||
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds; | IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components; | IReadOnlyCollection<IMessageComponent> IMessage.Components => Components; | ||||
@@ -209,7 +209,8 @@ namespace Discord.WebSocket | |||||
z.Default.ToNullable())).ToList(), | z.Default.ToNullable())).ToList(), | ||||
parsed.Placeholder.GetValueOrDefault(), | parsed.Placeholder.GetValueOrDefault(), | ||||
parsed.MinValues, | parsed.MinValues, | ||||
parsed.MaxValues | |||||
parsed.MaxValues, | |||||
parsed.Disabled | |||||
); | ); | ||||
} | } | ||||
default: | default: | ||||
@@ -252,7 +253,7 @@ namespace Discord.WebSocket | |||||
IReadOnlyCollection<ulong> IMessage.MentionedRoleIds => MentionedRoles.Select(x => x.Id).ToImmutableArray(); | IReadOnlyCollection<ulong> IMessage.MentionedRoleIds => MentionedRoles.Select(x => x.Id).ToImmutableArray(); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components; | IReadOnlyCollection<IMessageComponent> IMessage.Components => Components; | ||||