Browse Source

Improvements builders docs and adding/renaming methods/constructors and some fixes (#50)

* Refactor emojis/emotes & SelectMenu

* Update Emoji.cs

* Continue emoji refactor

* Remove WithLabel from example of SelectMenuBuilder

* Remove EmojiUtils and move it stuff to Emoji

* Revert 0fbf1000da

* Revert "Update Emoji.cs" and add Parse method

This reverts commit f297dcfc43.

* Partial revert 3c27ab36c9

* Builders docs improve and add/rename methods/ctors

* Update Discord.Net.Core.xml

* Add SelectMenuBuilder.AddOption overload

* Docs fix

* Update Discord.Net.Core.xml

* corrections of unnecessary docs

* corrections of unnecessary docs!

* Fix docs and exceptions
pull/1923/head
Nikon GitHub 3 years ago
parent
commit
5e3f119e95
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 321 additions and 169 deletions
  1. +114
    -41
      src/Discord.Net.Core/Discord.Net.Core.xml
  2. +193
    -114
      src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
  3. +14
    -14
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

+ 114
- 41
src/Discord.Net.Core/Discord.Net.Core.xml View File

@@ -4371,11 +4371,13 @@
<summary> <summary>
Gets or sets the Action Rows for this Component Builder. Gets or sets the Action Rows for this Component Builder.
</summary> </summary>
<exception cref="T:System.ArgumentNullException" accessor="set"><see cref="P:Discord.ComponentBuilder.ActionRows"/> cannot be null.</exception>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.ComponentBuilder.ActionRows"/> count exceeds <see cref="F:Discord.ComponentBuilder.MaxActionRowCount"/>.</exception>
</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.Boolean,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
accept the component then it will add it to a row that can
Adds a <see cref="T:Discord.SelectMenuBuilder"/> to the <see cref="T:Discord.ComponentBuilder"/> at the specific row.
If the row cannot accept the component then it will add it to a row that can.
</summary> </summary>
<param name="label">The label of the menu.</param> <param name="label">The label of the menu.</param>
<param name="customId">The custom id of the menu.</param> <param name="customId">The custom id of the menu.</param>
@@ -4387,20 +4389,15 @@
<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>
<member name="M:Discord.ComponentBuilder.WithSelectMenu(Discord.SelectMenuBuilder)">
<summary>
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
</summary>
<param name="menu">The menu to add</param>
<returns>The current builder.</returns>
</member>
<member name="M:Discord.ComponentBuilder.WithSelectMenu(Discord.SelectMenuBuilder,System.Int32)"> <member name="M:Discord.ComponentBuilder.WithSelectMenu(Discord.SelectMenuBuilder,System.Int32)">
<summary> <summary>
Adds a <see cref="T:Discord.SelectMenuBuilder"/> to the current builder at the specific row.
Adds a <see cref="T:Discord.SelectMenuBuilder"/> to the <see cref="T:Discord.ComponentBuilder"/> at the specific row.
If the row cannot accept the component then it will add it to a row that can.
</summary> </summary>
<param name="menu">The menu to add.</param> <param name="menu">The menu to add.</param>
<param name="row">The row to attempt to add this component on.</param> <param name="row">The row to attempt to add this component on.</param>
<exception cref="T:System.InvalidOperationException">There is no more row to add a menu.</exception>
<exception cref="T:System.ArgumentException"><paramref name="row"/> must be less than <see cref="F:Discord.ComponentBuilder.MaxActionRowCount"/>.</exception>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ComponentBuilder.WithButton(System.String,System.String,Discord.ButtonStyle,Discord.IEmote,System.String,System.Boolean,System.Int32)"> <member name="M:Discord.ComponentBuilder.WithButton(System.String,System.String,Discord.ButtonStyle,Discord.IEmote,System.String,System.Boolean,System.Int32)">
@@ -4416,26 +4413,22 @@
<param name="row">The row the button should be placed on.</param> <param name="row">The row the button should be placed on.</param>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ComponentBuilder.WithButton(Discord.ButtonBuilder)">
<summary>
Adds a button to the first row.
</summary>
<param name="button">The button to add to the first row.</param>
<returns>The current builder.</returns>
</member>
<member name="M:Discord.ComponentBuilder.WithButton(Discord.ButtonBuilder,System.Int32)"> <member name="M:Discord.ComponentBuilder.WithButton(Discord.ButtonBuilder,System.Int32)">
<summary> <summary>
Adds a button to the specified row.
Adds a <see cref="T:Discord.ButtonBuilder"/> to the <see cref="T:Discord.ComponentBuilder"/> at the specific row.
If the row cannot accept the component then it will add it to a row that can.
</summary> </summary>
<param name="button">The button to add.</param> <param name="button">The button to add.</param>
<param name="row">The row to add the button.</param> <param name="row">The row to add the button.</param>
<exception cref="T:System.InvalidOperationException">There is no more row to add a menu.</exception>
<exception cref="T:System.ArgumentException"><paramref name="row"/> must be less than <see cref="F:Discord.ComponentBuilder.MaxActionRowCount"/>.</exception>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ComponentBuilder.Build"> <member name="M:Discord.ComponentBuilder.Build">
<summary> <summary>
Builds this builder into a <see cref="T:Discord.MessageComponent"/> used to send your components. Builds this builder into a <see cref="T:Discord.MessageComponent"/> used to send your components.
</summary> </summary>
<returns>A <see cref="T:Discord.MessageComponent"/> that can be sent with <see cref="M:Discord.IMessageChannel.SendMessageAsync(System.String,System.Boolean,Discord.Embed,Discord.RequestOptions,Discord.AllowedMentions,Discord.MessageReference,Discord.MessageComponent)"/></returns>
<returns>A <see cref="T:Discord.MessageComponent"/> that can be sent with <see cref="M:Discord.IMessageChannel.SendMessageAsync(System.String,System.Boolean,Discord.Embed,Discord.RequestOptions,Discord.AllowedMentions,Discord.MessageReference,Discord.MessageComponent)"/>.</returns>
</member> </member>
<member name="T:Discord.ActionRowBuilder"> <member name="T:Discord.ActionRowBuilder">
<summary> <summary>
@@ -4451,19 +4444,23 @@
<summary> <summary>
Gets or sets the components inside this row. Gets or sets the components inside this row.
</summary> </summary>
<exception cref="T:System.ArgumentNullException" accessor="set"><see cref="P:Discord.ActionRowBuilder.Components"/> cannot be null.</exception>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.ActionRowBuilder.Components"/> count exceeds <see cref="F:Discord.ActionRowBuilder.MaxChildCount"/>.</exception>
</member> </member>
<member name="M:Discord.ActionRowBuilder.WithComponents(System.Collections.Generic.List{Discord.IMessageComponent})"> <member name="M:Discord.ActionRowBuilder.WithComponents(System.Collections.Generic.List{Discord.IMessageComponent})">
<summary> <summary>
Adds a list of components to the current row. Adds a list of components to the current row.
</summary> </summary>
<param name="components">The list of components to add.</param> <param name="components">The list of components to add.</param>
<inheritdoc cref="P:Discord.ActionRowBuilder.Components"/>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ActionRowBuilder.WithComponent(Discord.IMessageComponent)">
<member name="M:Discord.ActionRowBuilder.AddComponent(Discord.IMessageComponent)">
<summary> <summary>
Adds a component at the end of the current row. Adds a component at the end of the current row.
</summary> </summary>
<param name="component">The component to add.</param> <param name="component">The component to add.</param>
<exception cref="T:System.InvalidOperationException">Components count reached <see cref="F:Discord.ActionRowBuilder.MaxChildCount"/></exception>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ActionRowBuilder.Build"> <member name="M:Discord.ActionRowBuilder.Build">
@@ -4471,8 +4468,6 @@
Builds the current builder to a <see cref="T:Discord.ActionRowComponent"/> that can be used within a <see cref="T:Discord.ComponentBuilder"/> Builds the current builder to a <see cref="T:Discord.ActionRowComponent"/> that can be used within a <see cref="T:Discord.ComponentBuilder"/>
</summary> </summary>
<returns>A <see cref="T:Discord.ActionRowComponent"/> that can be used within a <see cref="T:Discord.ComponentBuilder"/></returns> <returns>A <see cref="T:Discord.ActionRowComponent"/> that can be used within a <see cref="T:Discord.ComponentBuilder"/></returns>
<exception cref="T:System.ArgumentNullException"><see cref="P:Discord.ActionRowBuilder.Components"/> cannot be null.</exception>
<exception cref="T:System.ArgumentException">There must be at least 1 component in a row.</exception>
</member> </member>
<member name="T:Discord.ButtonBuilder"> <member name="T:Discord.ButtonBuilder">
<summary> <summary>
@@ -4483,11 +4478,13 @@
<summary> <summary>
Gets or sets the label of the current button. Gets or sets the label of the current button.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.ButtonBuilder.Label"/> length exceeds <see cref="F:Discord.ComponentBuilder.MaxLabelLength"/>.</exception>
</member> </member>
<member name="P:Discord.ButtonBuilder.CustomId"> <member name="P:Discord.ButtonBuilder.CustomId">
<summary> <summary>
Gets or sets the custom id of the current button. Gets or sets the custom id of the current button.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.ButtonBuilder.CustomId"/> length exceeds <see cref="F:Discord.ComponentBuilder.MaxCustomIdLength"/></exception>
</member> </member>
<member name="P:Discord.ButtonBuilder.Style"> <member name="P:Discord.ButtonBuilder.Style">
<summary> <summary>
@@ -4509,6 +4506,27 @@
Gets or sets whether the current button is disabled. Gets or sets whether the current button is disabled.
</summary> </summary>
</member> </member>
<member name="M:Discord.ButtonBuilder.#ctor">
<summary>
Creates a new instance of a <see cref="T:Discord.ButtonBuilder"/>.
</summary>
</member>
<member name="M:Discord.ButtonBuilder.#ctor(System.String,System.String,Discord.ButtonStyle,System.String,Discord.IEmote,System.Boolean)">
<summary>
Creates a new instance of a <see cref="T:Discord.ButtonBuilder"/>.
</summary>
<param name="label">The label to use on the newly created link button.</param>
<param name="url">The url of this button.</param>
<param name="customId">The custom ID of this button</param>
<param name="style">The custom ID of this button</param>
<param name="emote">The emote of this button</param>
<param name="disabled">Disabled this button or not</param>
</member>
<member name="M:Discord.ButtonBuilder.#ctor(Discord.ButtonComponent)">
<summary>
Creates a new instance of a <see cref="T:Discord.ButtonBuilder"/> from instance of a <see cref="T:Discord.ButtonComponent"/>.
</summary>
</member>
<member name="M:Discord.ButtonBuilder.CreateLinkButton(System.String,System.String)"> <member name="M:Discord.ButtonBuilder.CreateLinkButton(System.String,System.String)">
<summary> <summary>
Creates a button with the <see cref="F:Discord.ButtonStyle.Link"/> style. Creates a button with the <see cref="F:Discord.ButtonStyle.Link"/> style.
@@ -4554,6 +4572,7 @@
Sets the current buttons label to the specified text. Sets the current buttons label to the specified text.
</summary> </summary>
<param name="label">The text for the label</param> <param name="label">The text for the label</param>
<inheritdoc cref="P:Discord.ButtonBuilder.Label"/>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ButtonBuilder.WithStyle(Discord.ButtonStyle)"> <member name="M:Discord.ButtonBuilder.WithStyle(Discord.ButtonStyle)">
@@ -4582,6 +4601,7 @@
Sets the custom id of the current button. Sets the custom id of the current button.
</summary> </summary>
<param name="id">The id to use for the current button.</param> <param name="id">The id to use for the current button.</param>
<inheritdoc cref="P:Discord.ButtonBuilder.CustomId"/>
<returns>The current builder.</returns> <returns>The current builder.</returns>
</member> </member>
<member name="M:Discord.ButtonBuilder.WithDisabled(System.Boolean)"> <member name="M:Discord.ButtonBuilder.WithDisabled(System.Boolean)">
@@ -4596,8 +4616,8 @@
Builds this builder into a <see cref="T:Discord.ButtonComponent"/> to be used in a <see cref="T:Discord.ComponentBuilder"/>. Builds this builder into a <see cref="T:Discord.ButtonComponent"/> to be used in a <see cref="T:Discord.ComponentBuilder"/>.
</summary> </summary>
<returns>A <see cref="T:Discord.ButtonComponent"/> to be used in a <see cref="T:Discord.ComponentBuilder"/>.</returns> <returns>A <see cref="T:Discord.ButtonComponent"/> to be used in a <see cref="T:Discord.ComponentBuilder"/>.</returns>
<exception cref="T:System.InvalidOperationException">A button cannot contain a URL and a CustomId.</exception>
<exception cref="T:System.ArgumentException">A button must have an Emote or a label.</exception>
<exception cref="T:System.InvalidOperationException">A button cannot contain a <see cref="P:Discord.ButtonBuilder.Url"/> and a <see cref="P:Discord.ButtonBuilder.CustomId"/>.</exception>
<exception cref="T:System.InvalidOperationException">A button must have an <see cref="P:Discord.ButtonBuilder.Emote"/> or a <see cref="P:Discord.ButtonBuilder.Label"/>.</exception>
</member> </member>
<member name="T:Discord.SelectMenuBuilder"> <member name="T:Discord.SelectMenuBuilder">
<summary> <summary>
@@ -4623,26 +4643,32 @@
<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>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.CustomId"/> length exceeds <see cref="F:Discord.ComponentBuilder.MaxCustomIdLength"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuBuilder.Placeholder"> <member name="P:Discord.SelectMenuBuilder.Placeholder">
<summary> <summary>
Gets or sets the placeholder text of the current select menu. Gets or sets the placeholder text of the current select menu.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.Placeholder"/> length exceeds <see cref="F:Discord.SelectMenuBuilder.MaxPlaceholderLength"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuBuilder.MinValues"> <member name="P:Discord.SelectMenuBuilder.MinValues">
<summary> <summary>
Gets or sets the minimum values of the current select menu. Gets or sets the minimum values of the current select menu.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.MinValues"/> exceeds <see cref="F:Discord.SelectMenuBuilder.MaxValuesCount"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuBuilder.MaxValues"> <member name="P:Discord.SelectMenuBuilder.MaxValues">
<summary> <summary>
Gets or sets the maximum values of the current select menu. Gets or sets the maximum values of the current select menu.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.MaxValues"/> exceeds <see cref="F:Discord.SelectMenuBuilder.MaxValuesCount"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuBuilder.Options"> <member name="P:Discord.SelectMenuBuilder.Options">
<summary> <summary>
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>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.Options"/> count exceeds <see cref="F:Discord.SelectMenuBuilder.MaxOptionCount"/>.</exception>
<exception cref="T:System.ArgumentNullException" accessor="set"><see cref="P:Discord.SelectMenuBuilder.Options"/> is null.</exception>
</member> </member>
<member name="P:Discord.SelectMenuBuilder.Disabled"> <member name="P:Discord.SelectMenuBuilder.Disabled">
<summary> <summary>
@@ -4654,18 +4680,28 @@
Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>. Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>.
</summary> </summary>
</member> </member>
<member name="M:Discord.SelectMenuBuilder.#ctor(System.String,System.Collections.Generic.List{Discord.SelectMenuOptionBuilder})">
<member name="M:Discord.SelectMenuBuilder.#ctor(Discord.SelectMenu)">
<summary>
Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/> from instance of <see cref="T:Discord.SelectMenu"/>.
</summary>
</member>
<member name="M:Discord.SelectMenuBuilder.#ctor(System.String,System.Collections.Generic.List{Discord.SelectMenuOptionBuilder},System.String,System.Int32,System.Int32,System.Boolean)">
<summary> <summary>
Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>. Creates a new instance of a <see cref="T:Discord.SelectMenuBuilder"/>.
</summary> </summary>
<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>
<param name="placeholder">The placeholder of this select menu.</param>
<param name="maxValues">The max values of this select menu.</param>
<param name="minValues">The min values of this select menu.</param>
<param name="disabled">Disabled this select menu or not.</param>
</member> </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.
</summary> </summary>
<param name="customId">The value to set the field CustomId to.</param> <param name="customId">The value to set the field CustomId to.</param>
<inheritdoc cref="P:Discord.SelectMenuBuilder.CustomId"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4675,6 +4711,7 @@
Sets the field placeholder. Sets the field placeholder.
</summary> </summary>
<param name="placeholder">The value to set the field placeholder to.</param> <param name="placeholder">The value to set the field placeholder to.</param>
<inheritdoc cref="P:Discord.SelectMenuBuilder.Placeholder"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4684,6 +4721,7 @@
Sets the field minValues. Sets the field minValues.
</summary> </summary>
<param name="minValues">The value to set the field minValues to.</param> <param name="minValues">The value to set the field minValues to.</param>
<inheritdoc cref="P:Discord.SelectMenuBuilder.MinValues"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4693,6 +4731,7 @@
Sets the field maxValues. Sets the field maxValues.
</summary> </summary>
<param name="maxValues">The value to set the field maxValues to.</param> <param name="maxValues">The value to set the field maxValues to.</param>
<inheritdoc cref="P:Discord.SelectMenuBuilder.MaxValues"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4702,6 +4741,31 @@
Sets the field options. Sets the field options.
</summary> </summary>
<param name="options">The value to set the field options to.</param> <param name="options">The value to set the field options to.</param>
<inheritdoc cref="P:Discord.SelectMenuBuilder.Options"/>
<returns>
The current builder.
</returns>
</member>
<member name="M:Discord.SelectMenuBuilder.AddOption(Discord.SelectMenuOptionBuilder)">
<summary>
Add one option to menu options.
</summary>
<param name="option">The option builder class containing the option properties.</param>
<exception cref="T:System.InvalidOperationException">Options count reached <see cref="F:Discord.SelectMenuBuilder.MaxOptionCount"/>.</exception>
<returns>
The current builder.
</returns>
</member>
<member name="M:Discord.SelectMenuBuilder.AddOption(System.String,System.String,System.String,Discord.IEmote,System.Nullable{System.Boolean})">
<summary>
Add one option to menu options.
</summary>
<param name="label">The label for this option.</param>
<param name="value">The value of this option.</param>
<param name="description">The description of this option.</param>
<param name="emote">The emote of this option.</param>
<param name="default">Render this option as selected by default or not.</param>
<exception cref="T:System.InvalidOperationException">Options count reached <see cref="F:Discord.SelectMenuBuilder.MaxOptionCount"/>.</exception>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4735,16 +4799,19 @@
<summary> <summary>
Gets or sets the label of the current select menu. Gets or sets the label of the current select menu.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuOptionBuilder.Label"/> length exceeds <see cref="F:Discord.ComponentBuilder.MaxLabelLength"/></exception>
</member> </member>
<member name="P:Discord.SelectMenuOptionBuilder.Value"> <member name="P:Discord.SelectMenuOptionBuilder.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>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuOptionBuilder.Value"/> length exceeds <see cref="F:Discord.ComponentBuilder.MaxCustomIdLength"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuOptionBuilder.Description"> <member name="P:Discord.SelectMenuOptionBuilder.Description">
<summary> <summary>
Gets or sets this menu options description. Gets or sets this menu options description.
</summary> </summary>
<exception cref="T:System.ArgumentException" accessor="set"><see cref="P:Discord.SelectMenuOptionBuilder.Description"/> length exceeds <see cref="F:Discord.SelectMenuOptionBuilder.MaxDescriptionLength"/>.</exception>
</member> </member>
<member name="P:Discord.SelectMenuOptionBuilder.Emote"> <member name="P:Discord.SelectMenuOptionBuilder.Emote">
<summary> <summary>
@@ -4761,18 +4828,22 @@
Creates a new instance of a <see cref="T:Discord.SelectMenuOptionBuilder"/>. Creates a new instance of a <see cref="T:Discord.SelectMenuOptionBuilder"/>.
</summary> </summary>
</member> </member>
<member name="M:Discord.SelectMenuOptionBuilder.#ctor(System.String,System.String)">
<member name="M:Discord.SelectMenuOptionBuilder.#ctor(System.String,System.String,System.String,Discord.IEmote,System.Nullable{System.Boolean})">
<summary> <summary>
Creates a new instance of a <see cref="T:Discord.SelectMenuOptionBuilder"/>. Creates a new instance of a <see cref="T:Discord.SelectMenuOptionBuilder"/>.
</summary> </summary>
<param name="label">The label for this option.</param> <param name="label">The label for this option.</param>
<param name="value">The value of this option.</param> <param name="value">The value of this option.</param>
<param name="description">The description of this option.</param>
<param name="emote">The emote of this option.</param>
<param name="default">Render this option as selected by default or not.</param>
</member> </member>
<member name="M:Discord.SelectMenuOptionBuilder.WithLabel(System.String)"> <member name="M:Discord.SelectMenuOptionBuilder.WithLabel(System.String)">
<summary> <summary>
Sets the field label. Sets the field label.
</summary> </summary>
<param name="label">The value to set the field label to.</param> <param name="label">The value to set the field label to.</param>
<inheritdoc cref="P:Discord.SelectMenuOptionBuilder.Label"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4782,6 +4853,7 @@
Sets the field value. Sets the field value.
</summary> </summary>
<param name="value">The value to set the field value to.</param> <param name="value">The value to set the field value to.</param>
<inheritdoc cref="P:Discord.SelectMenuOptionBuilder.Value"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -4791,6 +4863,7 @@
Sets the field description. Sets the field description.
</summary> </summary>
<param name="description">The value to set the field description to.</param> <param name="description">The value to set the field description to.</param>
<inheritdoc cref="P:Discord.SelectMenuOptionBuilder.Description"/>
<returns> <returns>
The current builder. The current builder.
</returns> </returns>
@@ -5568,23 +5641,23 @@
</summary> </summary>
</member> </member>
<member name="F:Discord.EmbedBuilder.MaxFieldCount"> <member name="F:Discord.EmbedBuilder.MaxFieldCount">
<summary>
Returns the maximum number of fields allowed by Discord.
<summary>
Returns the maximum number of fields allowed by Discord.
</summary> </summary>
</member> </member>
<member name="F:Discord.EmbedBuilder.MaxTitleLength"> <member name="F:Discord.EmbedBuilder.MaxTitleLength">
<summary>
Returns the maximum length of title allowed by Discord.
<summary>
Returns the maximum length of title allowed by Discord.
</summary> </summary>
</member> </member>
<member name="F:Discord.EmbedBuilder.MaxDescriptionLength"> <member name="F:Discord.EmbedBuilder.MaxDescriptionLength">
<summary>
Returns the maximum length of description allowed by Discord.
<summary>
Returns the maximum length of description allowed by Discord.
</summary> </summary>
</member> </member>
<member name="F:Discord.EmbedBuilder.MaxEmbedLength"> <member name="F:Discord.EmbedBuilder.MaxEmbedLength">
<summary>
Returns the maximum length of total characters allowed by Discord.
<summary>
Returns the maximum length of total characters allowed by Discord.
</summary> </summary>
</member> </member>
<member name="M:Discord.EmbedBuilder.#ctor"> <member name="M:Discord.EmbedBuilder.#ctor">
@@ -5618,9 +5691,9 @@
</member> </member>
<member name="P:Discord.EmbedBuilder.Fields"> <member name="P:Discord.EmbedBuilder.Fields">
<summary> Gets or sets the list of <see cref="T:Discord.EmbedFieldBuilder"/> of an <see cref="T:Discord.Embed"/>. </summary> <summary> Gets or sets the list of <see cref="T:Discord.EmbedFieldBuilder"/> of an <see cref="T:Discord.Embed"/>. </summary>
<exception cref="T:System.ArgumentNullException" accessor="set">An embed builder's fields collection is set to
<exception cref="T:System.ArgumentNullException" accessor="set">An embed builder's fields collection is set to
<c>null</c>.</exception> <c>null</c>.</exception>
<exception cref="T:System.ArgumentException" accessor="set">Description length exceeds <see cref="F:Discord.EmbedBuilder.MaxFieldCount"/>.
<exception cref="T:System.ArgumentException" accessor="set">Fields count exceeds <see cref="F:Discord.EmbedBuilder.MaxFieldCount"/>.
</exception> </exception>
<returns> The list of existing <see cref="T:Discord.EmbedFieldBuilder"/>.</returns> <returns> The list of existing <see cref="T:Discord.EmbedFieldBuilder"/>.</returns>
</member> </member>
@@ -5661,7 +5734,7 @@
Gets the total length of all embed properties. Gets the total length of all embed properties.
</summary> </summary>
<returns> <returns>
The combined length of <see cref="P:Discord.EmbedBuilder.Title"/>, <see cref="P:Discord.EmbedAuthor.Name"/>, <see cref="P:Discord.EmbedBuilder.Description"/>,
The combined length of <see cref="P:Discord.EmbedBuilder.Title"/>, <see cref="P:Discord.EmbedAuthor.Name"/>, <see cref="P:Discord.EmbedBuilder.Description"/>,
<see cref="P:Discord.EmbedFooter.Text"/>, <see cref="P:Discord.EmbedField.Name"/>, and <see cref="P:Discord.EmbedField.Value"/>. <see cref="P:Discord.EmbedFooter.Text"/>, <see cref="P:Discord.EmbedField.Name"/>, and <see cref="P:Discord.EmbedField.Value"/>.
</returns> </returns>
</member> </member>
@@ -5675,7 +5748,7 @@
</returns> </returns>
</member> </member>
<member name="M:Discord.EmbedBuilder.WithDescription(System.String)"> <member name="M:Discord.EmbedBuilder.WithDescription(System.String)">
<summary>
<summary>
Sets the description of an <see cref="T:Discord.Embed"/>. Sets the description of an <see cref="T:Discord.Embed"/>.
</summary> </summary>
<param name="description"> The description to be set. </param> <param name="description"> The description to be set. </param>
@@ -5684,7 +5757,7 @@
</returns> </returns>
</member> </member>
<member name="M:Discord.EmbedBuilder.WithUrl(System.String)"> <member name="M:Discord.EmbedBuilder.WithUrl(System.String)">
<summary>
<summary>
Sets the URL of an <see cref="T:Discord.Embed"/>. Sets the URL of an <see cref="T:Discord.Embed"/>.
</summary> </summary>
<param name="url"> The URL to be set. </param> <param name="url"> The URL to be set. </param>
@@ -5693,7 +5766,7 @@
</returns> </returns>
</member> </member>
<member name="M:Discord.EmbedBuilder.WithThumbnailUrl(System.String)"> <member name="M:Discord.EmbedBuilder.WithThumbnailUrl(System.String)">
<summary>
<summary>
Sets the thumbnail URL of an <see cref="T:Discord.Embed"/>. Sets the thumbnail URL of an <see cref="T:Discord.Embed"/>.
</summary> </summary>
<param name="thumbnailUrl"> The thumbnail URL to be set. </param> <param name="thumbnailUrl"> The thumbnail URL to be set. </param>


+ 193
- 114
src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs View File

@@ -27,6 +27,8 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the Action Rows for this Component Builder. /// Gets or sets the Action Rows for this Component Builder.
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException" accessor="set"><see cref="ActionRows"/> cannot be null.</exception>
/// <exception cref="ArgumentException" accessor="set"><see cref="ActionRows"/> count exceeds <see cref="MaxActionRowCount"/>.</exception>
public List<ActionRowBuilder> ActionRows public List<ActionRowBuilder> ActionRows
{ {
get => _actionRows; get => _actionRows;
@@ -43,8 +45,8 @@ namespace Discord
private List<ActionRowBuilder> _actionRows { get; set; } private List<ActionRowBuilder> _actionRows { get; set; }


/// <summary> /// <summary>
/// Adds a <see cref="SelectMenuBuilder"/> to the first row, if the first row cannot
/// accept the component then it will add it to a row that can
/// Adds a <see cref="SelectMenuBuilder"/> to the <see cref="ComponentBuilder"/> at the specific row.
/// If the row cannot accept the component then it will add it to a row that can.
/// </summary> /// </summary>
/// <param name="label">The label of the menu.</param> /// <param name="label">The label of the menu.</param>
/// <param name="customId">The custom id of the menu.</param> /// <param name="customId">The custom id of the menu.</param>
@@ -69,38 +71,34 @@ namespace Discord
} }


/// <summary> /// <summary>
/// Adds a <see cref="SelectMenuBuilder"/> to the first row, if the first row cannot
/// accept the component then it will add it to a row that can
/// </summary>
/// <param name="menu">The menu to add</param>
/// <returns>The current builder.</returns>
public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu)
=> WithSelectMenu(menu, 0);

/// <summary>
/// Adds a <see cref="SelectMenuBuilder"/> to the current builder at the specific row.
/// Adds a <see cref="SelectMenuBuilder"/> to the <see cref="ComponentBuilder"/> at the specific row.
/// If the row cannot accept the component then it will add it to a row that can.
/// </summary> /// </summary>
/// <param name="menu">The menu to add.</param> /// <param name="menu">The menu to add.</param>
/// <param name="row">The row to attempt to add this component on.</param> /// <param name="row">The row to attempt to add this component on.</param>
/// <exception cref="InvalidOperationException">There is no more row to add a menu.</exception>
/// <exception cref="ArgumentException"><paramref name="row"/> must be less than <see cref="MaxActionRowCount"/>.</exception>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row)
public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0)
{ {
Preconditions.LessThan(row, 5, nameof(row));
Preconditions.LessThan(row, MaxActionRowCount, nameof(row));


var builtMenu = menu.Build(); var builtMenu = menu.Build();


if (_actionRows == null) if (_actionRows == null)
{ {
_actionRows = new List<ActionRowBuilder>();
_actionRows.Add(new ActionRowBuilder().WithComponent(builtMenu));
_actionRows = new List<ActionRowBuilder>
{
new ActionRowBuilder().AddComponent(builtMenu)
};
} }
else else
{ {
if (_actionRows.Count == row) if (_actionRows.Count == row)
_actionRows.Add(new ActionRowBuilder().WithComponent(builtMenu));
_actionRows.Add(new ActionRowBuilder().AddComponent(builtMenu));
else else
{ {
ActionRowBuilder actionRow = null;
ActionRowBuilder actionRow;
if (_actionRows.Count > row) if (_actionRows.Count > row)
actionRow = _actionRows.ElementAt(row); actionRow = _actionRows.ElementAt(row);
else else
@@ -110,11 +108,11 @@ namespace Discord
} }


if (actionRow.CanTakeComponent(builtMenu)) if (actionRow.CanTakeComponent(builtMenu))
actionRow.WithComponent(builtMenu);
else if (row < 5)
actionRow.AddComponent(builtMenu);
else if (row < MaxActionRowCount)
WithSelectMenu(menu, row + 1); WithSelectMenu(menu, row + 1);
else else
throw new ArgumentOutOfRangeException($"There is no more room to add a {nameof(builtMenu)}");
throw new InvalidOperationException($"There is no more row to add a {nameof(builtMenu)}");
} }
} }


@@ -153,37 +151,32 @@ namespace Discord
} }


/// <summary> /// <summary>
/// Adds a button to the first row.
/// </summary>
/// <param name="button">The button to add to the first row.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder WithButton(ButtonBuilder button)
=> this.WithButton(button, 0);

/// <summary>
/// Adds a button to the specified row.
/// Adds a <see cref="ButtonBuilder"/> to the <see cref="ComponentBuilder"/> at the specific row.
/// If the row cannot accept the component then it will add it to a row that can.
/// </summary> /// </summary>
/// <param name="button">The button to add.</param> /// <param name="button">The button to add.</param>
/// <param name="row">The row to add the button.</param> /// <param name="row">The row to add the button.</param>
/// <exception cref="InvalidOperationException">There is no more row to add a menu.</exception>
/// <exception cref="ArgumentException"><paramref name="row"/> must be less than <see cref="MaxActionRowCount"/>.</exception>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ComponentBuilder WithButton(ButtonBuilder button, int row = 0) public ComponentBuilder WithButton(ButtonBuilder button, int row = 0)
{ {
Preconditions.LessThan(row, 5, nameof(row));
Preconditions.LessThan(row, MaxActionRowCount, nameof(row));


var builtButton = button.Build(); var builtButton = button.Build();


if (_actionRows == null) if (_actionRows == null)
{ {
_actionRows = new List<ActionRowBuilder>(); _actionRows = new List<ActionRowBuilder>();
_actionRows.Add(new ActionRowBuilder().WithComponent(builtButton));
_actionRows.Add(new ActionRowBuilder().AddComponent(builtButton));
} }
else else
{ {
if (_actionRows.Count == row) if (_actionRows.Count == row)
_actionRows.Add(new ActionRowBuilder().WithComponent(builtButton));
_actionRows.Add(new ActionRowBuilder().AddComponent(builtButton));
else else
{ {
ActionRowBuilder actionRow = null;
ActionRowBuilder actionRow;
if(_actionRows.Count > row) if(_actionRows.Count > row)
actionRow = _actionRows.ElementAt(row); actionRow = _actionRows.ElementAt(row);
else else
@@ -193,11 +186,11 @@ namespace Discord
} }


if (actionRow.CanTakeComponent(builtButton)) if (actionRow.CanTakeComponent(builtButton))
actionRow.WithComponent(builtButton);
else if (row < 5)
actionRow.AddComponent(builtButton);
else if (row < MaxActionRowCount)
WithButton(button, row + 1); WithButton(button, row + 1);
else else
throw new ArgumentOutOfRangeException($"There is no more room to add a {nameof(button)}");
throw new InvalidOperationException($"There is no more row to add a {nameof(button)}");
} }
} }


@@ -207,7 +200,7 @@ namespace Discord
/// <summary> /// <summary>
/// Builds this builder into a <see cref="MessageComponent"/> used to send your components. /// Builds this builder into a <see cref="MessageComponent"/> used to send your components.
/// </summary> /// </summary>
/// <returns>A <see cref="MessageComponent"/> that can be sent with <see cref="IMessageChannel.SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent)"/></returns>
/// <returns>A <see cref="MessageComponent"/> that can be sent with <see cref="IMessageChannel.SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent)"/>.</returns>
public MessageComponent Build() public MessageComponent Build()
{ {
if (this._actionRows != null) if (this._actionRows != null)
@@ -230,14 +223,22 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the components inside this row. /// Gets or sets the components inside this row.
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException" accessor="set"><see cref="Components"/> cannot be null.</exception>
/// <exception cref="ArgumentException" accessor="set"><see cref="Components"/> count exceeds <see cref="MaxChildCount"/>.</exception>
public List<IMessageComponent> Components public List<IMessageComponent> Components
{ {
get => _components; get => _components;
set set
{ {
if (value != null)
if (value.Count > MaxChildCount)
throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components));
if (value == null)
throw new ArgumentNullException(message: "Action row components cannot be null!", paramName: nameof(Components));

if (value.Count <= 0)
throw new ArgumentException(message: "There must be at least 1 component in a row", paramName: nameof(Components));

if (value.Count > MaxChildCount)
throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components));

_components = value; _components = value;
} }
} }
@@ -248,6 +249,7 @@ namespace Discord
/// Adds a list of components to the current row. /// Adds a list of components to the current row.
/// </summary> /// </summary>
/// <param name="components">The list of components to add.</param> /// <param name="components">The list of components to add.</param>
/// <inheritdoc cref="Components"/>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ActionRowBuilder WithComponents(List<IMessageComponent> components) public ActionRowBuilder WithComponents(List<IMessageComponent> components)
{ {
@@ -259,14 +261,14 @@ namespace Discord
/// Adds a component at the end of the current row. /// Adds a component at the end of the current row.
/// </summary> /// </summary>
/// <param name="component">The component to add.</param> /// <param name="component">The component to add.</param>
/// <exception cref="InvalidOperationException">Components count reached <see cref="MaxChildCount"/></exception>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ActionRowBuilder WithComponent(IMessageComponent component)
public ActionRowBuilder AddComponent(IMessageComponent component)
{ {
if (this.Components == null)
this.Components = new List<IMessageComponent>();
if (this.Components.Count >= MaxChildCount)
throw new InvalidOperationException($"Components count reached {MaxChildCount}");


this.Components.Add(component); this.Components.Add(component);

return this; return this;
} }


@@ -274,16 +276,8 @@ namespace Discord
/// Builds the current builder to a <see cref="ActionRowComponent"/> that can be used within a <see cref="ComponentBuilder"/> /// Builds the current builder to a <see cref="ActionRowComponent"/> that can be used within a <see cref="ComponentBuilder"/>
/// </summary> /// </summary>
/// <returns>A <see cref="ActionRowComponent"/> that can be used within a <see cref="ComponentBuilder"/></returns> /// <returns>A <see cref="ActionRowComponent"/> that can be used within a <see cref="ComponentBuilder"/></returns>
/// <exception cref="ArgumentNullException"><see cref="Components"/> cannot be null.</exception>
/// <exception cref="ArgumentException">There must be at least 1 component in a row.</exception>
public ActionRowComponent Build() public ActionRowComponent Build()
{ {
if (this.Components == null)
throw new ArgumentNullException($"{nameof(Components)} cannot be null!");

if (this.Components.Count == 0)
throw new ArgumentException("There must be at least 1 component in a row");

return new ActionRowComponent(this._components); return new ActionRowComponent(this._components);
} }


@@ -314,14 +308,14 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the label of the current button. /// Gets or sets the label of the current button.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="Label"/> length exceeds <see cref="ComponentBuilder.MaxLabelLength"/>.</exception>
public string Label public string Label
{ {
get => _label; get => _label;
set 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));
if (value != null && value.Length > ComponentBuilder.MaxLabelLength)
throw new ArgumentException(message: $"Button label must be {ComponentBuilder.MaxLabelLength} characters or less!", paramName: nameof(Label));


_label = value; _label = value;
} }
@@ -330,14 +324,14 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the custom id of the current button. /// Gets or sets the custom id of the current button.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="CustomId"/> length exceeds <see cref="ComponentBuilder.MaxCustomIdLength"/></exception>
public string CustomId public string CustomId
{ {
get => _customId; get => _customId;
set set
{ {
if (value != null)
if (value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
_customId = value; _customId = value;
} }
} }
@@ -366,6 +360,43 @@ namespace Discord
private string _label; private string _label;
private string _customId; private string _customId;


/// <summary>
/// Creates a new instance of a <see cref="ButtonBuilder"/>.
/// </summary>
public ButtonBuilder() { }

/// <summary>
/// Creates a new instance of a <see cref="ButtonBuilder"/>.
/// </summary>
/// <param name="label">The label to use on the newly created link button.</param>
/// <param name="url">The url of this button.</param>
/// <param name="customId">The custom ID of this button</param>
/// <param name="style">The custom ID of this button</param>
/// <param name="emote">The emote of this button</param>
/// <param name="disabled">Disabled this button or not</param>
public ButtonBuilder(string label, string customId, ButtonStyle style = ButtonStyle.Primary, string url = null, IEmote emote = null, bool disabled = false)
{
this.CustomId = customId;
this.Style = style;
this.Url = url;
this.Label = label;
this.Disabled = disabled;
this.Emote = emote;
}

/// <summary>
/// Creates a new instance of a <see cref="ButtonBuilder"/> from instance of a <see cref="ButtonComponent"/>.
/// </summary>
public ButtonBuilder(ButtonComponent button)
{
this.CustomId = button.CustomId;
this.Style = button.Style;
this.Url = button.Url;
this.Label = button.Label;
this.Disabled = button.Disabled;
this.Emote = button.Emote;
}

/// <summary> /// <summary>
/// Creates a button with the <see cref="ButtonStyle.Link"/> style. /// Creates a button with the <see cref="ButtonStyle.Link"/> style.
/// </summary> /// </summary>
@@ -373,14 +404,7 @@ namespace Discord
/// <param name="url">The url for this link button to go to.</param> /// <param name="url">The url for this link button to go to.</param>
/// <returns>A builder with the newly created button.</returns> /// <returns>A builder with the newly created button.</returns>
public static ButtonBuilder CreateLinkButton(string label, string url) public static ButtonBuilder CreateLinkButton(string label, string url)
{
var builder = new ButtonBuilder()
.WithStyle(ButtonStyle.Link)
.WithUrl(url)
.WithLabel(label);

return builder;
}
=> new ButtonBuilder(label, null, ButtonStyle.Link, url);


/// <summary> /// <summary>
/// Creates a button with the <see cref="ButtonStyle.Danger"/> style. /// Creates a button with the <see cref="ButtonStyle.Danger"/> style.
@@ -389,14 +413,7 @@ namespace Discord
/// <param name="customId">The custom id for this danger button.</param> /// <param name="customId">The custom id for this danger button.</param>
/// <returns>A builder with the newly created button.</returns> /// <returns>A builder with the newly created button.</returns>
public static ButtonBuilder CreateDangerButton(string label, string customId) public static ButtonBuilder CreateDangerButton(string label, string customId)
{
var builder = new ButtonBuilder()
.WithStyle(ButtonStyle.Danger)
.WithCustomId(customId)
.WithLabel(label);

return builder;
}
=> new ButtonBuilder(label, customId, ButtonStyle.Danger);


/// <summary> /// <summary>
/// Creates a button with the <see cref="ButtonStyle.Primary"/> style. /// Creates a button with the <see cref="ButtonStyle.Primary"/> style.
@@ -405,14 +422,7 @@ namespace Discord
/// <param name="customId">The custom id for this primary button.</param> /// <param name="customId">The custom id for this primary button.</param>
/// <returns>A builder with the newly created button.</returns> /// <returns>A builder with the newly created button.</returns>
public static ButtonBuilder CreatePrimaryButton(string label, string customId) public static ButtonBuilder CreatePrimaryButton(string label, string customId)
{
var builder = new ButtonBuilder()
.WithStyle(ButtonStyle.Primary)
.WithCustomId(customId)
.WithLabel(label);

return builder;
}
=> new ButtonBuilder(label, customId);


/// <summary> /// <summary>
/// Creates a button with the <see cref="ButtonStyle.Secondary"/> style. /// Creates a button with the <see cref="ButtonStyle.Secondary"/> style.
@@ -421,14 +431,7 @@ namespace Discord
/// <param name="customId">The custom id for this secondary button.</param> /// <param name="customId">The custom id for this secondary button.</param>
/// <returns>A builder with the newly created button.</returns> /// <returns>A builder with the newly created button.</returns>
public static ButtonBuilder CreateSecondaryButton(string label, string customId) public static ButtonBuilder CreateSecondaryButton(string label, string customId)
{
var builder = new ButtonBuilder()
.WithStyle(ButtonStyle.Secondary)
.WithCustomId(customId)
.WithLabel(label);

return builder;
}
=> new ButtonBuilder(label, customId, ButtonStyle.Secondary);


/// <summary> /// <summary>
/// Creates a button with the <see cref="ButtonStyle.Success"/> style. /// Creates a button with the <see cref="ButtonStyle.Success"/> style.
@@ -437,19 +440,13 @@ namespace Discord
/// <param name="customId">The custom id for this success button.</param> /// <param name="customId">The custom id for this success button.</param>
/// <returns>A builder with the newly created button.</returns> /// <returns>A builder with the newly created button.</returns>
public static ButtonBuilder CreateSuccessButton(string label, string customId) public static ButtonBuilder CreateSuccessButton(string label, string customId)
{
var builder = new ButtonBuilder()
.WithStyle(ButtonStyle.Success)
.WithCustomId(customId)
.WithLabel(label);

return builder;
}
=> new ButtonBuilder(label, customId, ButtonStyle.Success);


/// <summary> /// <summary>
/// Sets the current buttons label to the specified text. /// Sets the current buttons label to the specified text.
/// </summary> /// </summary>
/// <param name="label">The text for the label</param> /// <param name="label">The text for the label</param>
/// <inheritdoc cref="Label"/>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ButtonBuilder WithLabel(string label) public ButtonBuilder WithLabel(string label)
{ {
@@ -494,6 +491,7 @@ namespace Discord
/// Sets the custom id of the current button. /// Sets the custom id of the current button.
/// </summary> /// </summary>
/// <param name="id">The id to use for the current button.</param> /// <param name="id">The id to use for the current button.</param>
/// <inheritdoc cref="CustomId"/>
/// <returns>The current builder.</returns> /// <returns>The current builder.</returns>
public ButtonBuilder WithCustomId(string id) public ButtonBuilder WithCustomId(string id)
{ {
@@ -516,15 +514,15 @@ namespace Discord
/// Builds this builder into a <see cref="ButtonComponent"/> to be used in a <see cref="ComponentBuilder"/>. /// Builds this builder into a <see cref="ButtonComponent"/> to be used in a <see cref="ComponentBuilder"/>.
/// </summary> /// </summary>
/// <returns>A <see cref="ButtonComponent"/> to be used in a <see cref="ComponentBuilder"/>.</returns> /// <returns>A <see cref="ButtonComponent"/> to be used in a <see cref="ComponentBuilder"/>.</returns>
/// <exception cref="InvalidOperationException">A button cannot contain a URL and a CustomId.</exception>
/// <exception cref="ArgumentException">A button must have an Emote or a label.</exception>
/// <exception cref="InvalidOperationException">A button cannot contain a <see cref="Url"/> and a <see cref="CustomId"/>.</exception>
/// <exception cref="InvalidOperationException">A button must have an <see cref="Emote"/> or a <see cref="Label"/>.</exception>
public ButtonComponent Build() public ButtonComponent Build()
{ {
if (string.IsNullOrEmpty(this.Label) && this.Emote == null) if (string.IsNullOrEmpty(this.Label) && this.Emote == null)
throw new ArgumentException("A button must have an Emote or a label!");
throw new InvalidOperationException("A button must have an Emote or a label!");


if (!string.IsNullOrEmpty(this.Url) && !string.IsNullOrEmpty(this.CustomId)) if (!string.IsNullOrEmpty(this.Url) && !string.IsNullOrEmpty(this.CustomId))
throw new InvalidOperationException("A button cannot contain a URL and a CustomId");
throw new InvalidOperationException("A button cannot contain a URL and a CustomId!");


if (this.Style == ButtonStyle.Link && !string.IsNullOrEmpty(this.CustomId)) if (this.Style == ButtonStyle.Link && !string.IsNullOrEmpty(this.CustomId))
this.CustomId = null; this.CustomId = null;
@@ -559,14 +557,14 @@ namespace Discord
/// <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>
/// <exception cref="ArgumentException" accessor="set"><see cref="CustomId"/> length exceeds <see cref="ComponentBuilder.MaxCustomIdLength"/>.</exception>
public string CustomId public string CustomId
{ {
get => _customId; get => _customId;
set set
{ {
if (value != null)
if (value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
_customId = value; _customId = value;
} }
} }
@@ -574,6 +572,7 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the placeholder text of the current select menu. /// Gets or sets the placeholder text of the current select menu.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="Placeholder"/> length exceeds <see cref="MaxPlaceholderLength"/>.</exception>
public string Placeholder public string Placeholder
{ {
get => _placeholder; get => _placeholder;
@@ -589,6 +588,7 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the minimum values of the current select menu. /// Gets or sets the minimum values of the current select menu.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="MinValues"/> exceeds <see cref="MaxValuesCount"/>.</exception>
public int MinValues public int MinValues
{ {
get => _minValues; get => _minValues;
@@ -602,6 +602,7 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the maximum values of the current select menu. /// Gets or sets the maximum values of the current select menu.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="MaxValues"/> exceeds <see cref="MaxValuesCount"/>.</exception>
public int MaxValues public int MaxValues
{ {
get => _maxValues; get => _maxValues;
@@ -615,6 +616,8 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets a collection of <see cref="SelectMenuOptionBuilder"/> for this current select menu. /// Gets or sets a collection of <see cref="SelectMenuOptionBuilder"/> for this current select menu.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="Options"/> count exceeds <see cref="MaxOptionCount"/>.</exception>
/// <exception cref="ArgumentNullException" accessor="set"><see cref="Options"/> is null.</exception>
public List<SelectMenuOptionBuilder> Options public List<SelectMenuOptionBuilder> Options
{ {
get => _options; get => _options;
@@ -622,6 +625,8 @@ namespace Discord
{ {
if (value != null) if (value != null)
Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options)); Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options));
else
throw new ArgumentNullException(nameof(value));


_options = value; _options = value;
} }
@@ -632,7 +637,7 @@ namespace Discord
/// </summary> /// </summary>
public bool Disabled { get; set; } public bool Disabled { get; set; }


private List<SelectMenuOptionBuilder> _options;
private List<SelectMenuOptionBuilder> _options = new List<SelectMenuOptionBuilder>();
private int _minValues = 1; private int _minValues = 1;
private int _maxValues = 1; private int _maxValues = 1;
private string _placeholder; private string _placeholder;
@@ -643,21 +648,45 @@ namespace Discord
/// </summary> /// </summary>
public SelectMenuBuilder() { } public SelectMenuBuilder() { }


/// <summary>
/// Creates a new instance of a <see cref="SelectMenuBuilder"/> from instance of <see cref="SelectMenu"/>.
/// </summary>
public SelectMenuBuilder(SelectMenu selectMenu)
{
this.Placeholder = selectMenu.Placeholder;
this.CustomId = selectMenu.Placeholder;
this.MaxValues = selectMenu.MaxValues;
this.MinValues = selectMenu.MinValues;
this.Disabled = selectMenu.Disabled;
this.Options = selectMenu.Options?
.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.Default))
.ToList();
}

/// <summary> /// <summary>
/// Creates a new instance of a <see cref="SelectMenuBuilder"/>. /// Creates a new instance of a <see cref="SelectMenuBuilder"/>.
/// </summary> /// </summary>
/// <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>
public SelectMenuBuilder(string customId, List<SelectMenuOptionBuilder> options)
/// <param name="placeholder">The placeholder of this select menu.</param>
/// <param name="maxValues">The max values of this select menu.</param>
/// <param name="minValues">The min values of this select menu.</param>
/// <param name="disabled">Disabled this select menu or not.</param>
public SelectMenuBuilder(string customId, List<SelectMenuOptionBuilder> options, string placeholder = null, int maxValues = 1, int minValues = 1, bool disabled = false)
{ {
this.CustomId = customId; this.CustomId = customId;
this.Options = options; this.Options = options;
this.Placeholder = placeholder;
this.Disabled = disabled;
this.MaxValues = maxValues;
this.MinValues = minValues;
} }


/// <summary> /// <summary>
/// Sets the field CustomId. /// Sets the field CustomId.
/// </summary> /// </summary>
/// <param name="customId">The value to set the field CustomId to.</param> /// <param name="customId">The value to set the field CustomId to.</param>
/// <inheritdoc cref="CustomId"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -671,6 +700,7 @@ namespace Discord
/// Sets the field placeholder. /// Sets the field placeholder.
/// </summary> /// </summary>
/// <param name="placeholder">The value to set the field placeholder to.</param> /// <param name="placeholder">The value to set the field placeholder to.</param>
/// <inheritdoc cref="Placeholder"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -684,6 +714,7 @@ namespace Discord
/// Sets the field minValues. /// Sets the field minValues.
/// </summary> /// </summary>
/// <param name="minValues">The value to set the field minValues to.</param> /// <param name="minValues">The value to set the field minValues to.</param>
/// <inheritdoc cref="MinValues"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -697,6 +728,7 @@ namespace Discord
/// Sets the field maxValues. /// Sets the field maxValues.
/// </summary> /// </summary>
/// <param name="maxValues">The value to set the field maxValues to.</param> /// <param name="maxValues">The value to set the field maxValues to.</param>
/// <inheritdoc cref="MaxValues"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -710,6 +742,7 @@ namespace Discord
/// Sets the field options. /// Sets the field options.
/// </summary> /// </summary>
/// <param name="options">The value to set the field options to.</param> /// <param name="options">The value to set the field options to.</param>
/// <inheritdoc cref="Options"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -719,6 +752,41 @@ namespace Discord
return this; return this;
} }


/// <summary>
/// Add one option to menu options.
/// </summary>
/// <param name="option">The option builder class containing the option properties.</param>
/// <exception cref="InvalidOperationException">Options count reached <see cref="MaxOptionCount"/>.</exception>
/// <returns>
/// The current builder.
/// </returns>
public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
{
if (this.Options.Count >= MaxOptionCount)
throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");

this.Options.Add(option);
return this;
}

/// <summary>
/// Add one option to menu options.
/// </summary>
/// <param name="label">The label for this option.</param>
/// <param name="value">The value of this option.</param>
/// <param name="description">The description of this option.</param>
/// <param name="emote">The emote of this option.</param>
/// <param name="default">Render this option as selected by default or not.</param>
/// <exception cref="InvalidOperationException">Options count reached <see cref="MaxOptionCount"/>.</exception>
/// <returns>
/// The current builder.
/// </returns>
public SelectMenuBuilder AddOption(string label, string value, string description = null, IEmote emote = null, bool? @default = null)
{
AddOption(new SelectMenuOptionBuilder(label, value, description, emote, @default));
return this;
}

/// <summary> /// <summary>
/// Sets whether the current menu is disabled. /// Sets whether the current menu is disabled.
/// </summary> /// </summary>
@@ -757,6 +825,7 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets the label of the current select menu. /// Gets or sets the label of the current select menu.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="Label"/> length exceeds <see cref="ComponentBuilder.MaxLabelLength"/></exception>
public string Label public string Label
{ {
get => _label; get => _label;
@@ -773,14 +842,14 @@ namespace Discord
/// <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>
/// <exception cref="ArgumentException" accessor="set"><see cref="Value"/> length exceeds <see cref="ComponentBuilder.MaxCustomIdLength"/>.</exception>
public string Value public string Value
{ {
get => _value; get => _value;
set set
{ {
if (value != null)
if (value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Value must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(Value));
if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
throw new ArgumentException(message: $"Value must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(Value));
_value = value; _value = value;
} }
} }
@@ -788,13 +857,14 @@ namespace Discord
/// <summary> /// <summary>
/// Gets or sets this menu options description. /// Gets or sets this menu options description.
/// </summary> /// </summary>
/// <exception cref="ArgumentException" accessor="set"><see cref="Description"/> length exceeds <see cref="MaxDescriptionLength"/>.</exception>
public string Description public string Description
{ {
get => _description; get => _description;
set set
{ {
if (value != null)
Preconditions.LessThan(value.Length, MaxDescriptionLength, nameof(Description));
if (value != null && value.Length > MaxDescriptionLength)
throw new ArgumentException($"Description must be {MaxDescriptionLength} characters or less!", nameof(Description));


_description = value; _description = value;
} }
@@ -824,16 +894,23 @@ namespace Discord
/// </summary> /// </summary>
/// <param name="label">The label for this option.</param> /// <param name="label">The label for this option.</param>
/// <param name="value">The value of this option.</param> /// <param name="value">The value of this option.</param>
public SelectMenuOptionBuilder(string label, string value)
/// <param name="description">The description of this option.</param>
/// <param name="emote">The emote of this option.</param>
/// <param name="default">Render this option as selected by default or not.</param>
public SelectMenuOptionBuilder(string label, string value, string description = null, IEmote emote = null, bool? @default = null)
{ {
this.Label = label; this.Label = label;
this.Value = value; this.Value = value;
this.Description = description;
this.Emote = emote;
this.Default = @default;
} }


/// <summary> /// <summary>
/// Sets the field label. /// Sets the field label.
/// </summary> /// </summary>
/// <param name="label">The value to set the field label to.</param> /// <param name="label">The value to set the field label to.</param>
/// <inheritdoc cref="Label"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -847,6 +924,7 @@ namespace Discord
/// Sets the field value. /// Sets the field value.
/// </summary> /// </summary>
/// <param name="value">The value to set the field value to.</param> /// <param name="value">The value to set the field value to.</param>
/// <inheritdoc cref="Value"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>
@@ -860,6 +938,7 @@ namespace Discord
/// Sets the field description. /// Sets the field description.
/// </summary> /// </summary>
/// <param name="description">The value to set the field description to.</param> /// <param name="description">The value to set the field description to.</param>
/// <inheritdoc cref="Description"/>
/// <returns> /// <returns>
/// The current builder. /// The current builder.
/// </returns> /// </returns>


+ 14
- 14
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -16,20 +16,20 @@ namespace Discord
private EmbedThumbnail? _thumbnail; private EmbedThumbnail? _thumbnail;
private List<EmbedFieldBuilder> _fields; private List<EmbedFieldBuilder> _fields;


/// <summary>
/// Returns the maximum number of fields allowed by Discord.
/// <summary>
/// Returns the maximum number of fields allowed by Discord.
/// </summary> /// </summary>
public const int MaxFieldCount = 25; public const int MaxFieldCount = 25;
/// <summary>
/// Returns the maximum length of title allowed by Discord.
/// <summary>
/// Returns the maximum length of title allowed by Discord.
/// </summary> /// </summary>
public const int MaxTitleLength = 256; public const int MaxTitleLength = 256;
/// <summary>
/// Returns the maximum length of description allowed by Discord.
/// <summary>
/// Returns the maximum length of description allowed by Discord.
/// </summary> /// </summary>
public const int MaxDescriptionLength = 4096; public const int MaxDescriptionLength = 4096;
/// <summary>
/// Returns the maximum length of total characters allowed by Discord.
/// <summary>
/// Returns the maximum length of total characters allowed by Discord.
/// </summary> /// </summary>
public const int MaxEmbedLength = 6000; public const int MaxEmbedLength = 6000;


@@ -88,9 +88,9 @@ namespace Discord
} }


/// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary> /// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary>
/// <exception cref="ArgumentNullException" accessor="set">An embed builder's fields collection is set to
/// <exception cref="ArgumentNullException" accessor="set">An embed builder's fields collection is set to
/// <c>null</c>.</exception> /// <c>null</c>.</exception>
/// <exception cref="ArgumentException" accessor="set">Description length exceeds <see cref="MaxFieldCount"/>.
/// <exception cref="ArgumentException" accessor="set">Fields count exceeds <see cref="MaxFieldCount"/>.
/// </exception> /// </exception>
/// <returns> The list of existing <see cref="EmbedFieldBuilder"/>.</returns> /// <returns> The list of existing <see cref="EmbedFieldBuilder"/>.</returns>
public List<EmbedFieldBuilder> Fields public List<EmbedFieldBuilder> Fields
@@ -137,7 +137,7 @@ namespace Discord
/// Gets the total length of all embed properties. /// Gets the total length of all embed properties.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// The combined length of <see cref="Title"/>, <see cref="EmbedAuthor.Name"/>, <see cref="Description"/>,
/// The combined length of <see cref="Title"/>, <see cref="EmbedAuthor.Name"/>, <see cref="Description"/>,
/// <see cref="EmbedFooter.Text"/>, <see cref="EmbedField.Name"/>, and <see cref="EmbedField.Value"/>. /// <see cref="EmbedFooter.Text"/>, <see cref="EmbedField.Name"/>, and <see cref="EmbedField.Value"/>.
/// </returns> /// </returns>
public int Length public int Length
@@ -166,7 +166,7 @@ namespace Discord
Title = title; Title = title;
return this; return this;
} }
/// <summary>
/// <summary>
/// Sets the description of an <see cref="Embed"/>. /// Sets the description of an <see cref="Embed"/>.
/// </summary> /// </summary>
/// <param name="description"> The description to be set. </param> /// <param name="description"> The description to be set. </param>
@@ -178,7 +178,7 @@ namespace Discord
Description = description; Description = description;
return this; return this;
} }
/// <summary>
/// <summary>
/// Sets the URL of an <see cref="Embed"/>. /// Sets the URL of an <see cref="Embed"/>.
/// </summary> /// </summary>
/// <param name="url"> The URL to be set. </param> /// <param name="url"> The URL to be set. </param>
@@ -190,7 +190,7 @@ namespace Discord
Url = url; Url = url;
return this; return this;
} }
/// <summary>
/// <summary>
/// Sets the thumbnail URL of an <see cref="Embed"/>. /// Sets the thumbnail URL of an <see cref="Embed"/>.
/// </summary> /// </summary>
/// <param name="thumbnailUrl"> The thumbnail URL to be set. </param> /// <param name="thumbnailUrl"> The thumbnail URL to be set. </param>


Loading…
Cancel
Save