* 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
* 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 * remove necessary things and some fix/changes - Rename InteractionApplicationCommanCallbackData -> InteractionCallbackData - Fix wrong creating instances of InteractionCallbackData * Add SelectMenuOptionBuilder ctor overload
@@ -4838,6 +4838,11 @@ | |||||
<param name="emote">The emote 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> | <param name="default">Render this option as selected by default or not.</param> | ||||
</member> | </member> | ||||
<member name="M:Discord.SelectMenuOptionBuilder.#ctor(Discord.SelectMenuOption)"> | |||||
<summary> | |||||
Creates a new instance of a <see cref="T:Discord.SelectMenuOptionBuilder"/> from instance of a <see cref="T:Discord.SelectMenuOption"/>. | |||||
</summary> | |||||
</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. | ||||
@@ -906,6 +906,18 @@ namespace Discord | |||||
this.Default = @default; | this.Default = @default; | ||||
} | } | ||||
/// <summary> | |||||
/// Creates a new instance of a <see cref="SelectMenuOptionBuilder"/> from instance of a <see cref="SelectMenuOption"/>. | |||||
/// </summary> | |||||
public SelectMenuOptionBuilder(SelectMenuOption option) | |||||
{ | |||||
this.Label = option.Label; | |||||
this.Value = option.Value; | |||||
this.Description = option.Description; | |||||
this.Emote = option.Emote; | |||||
this.Default = option.Default; | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Sets the field label. | /// Sets the field label. | ||||
/// </summary> | /// </summary> | ||||
@@ -7,7 +7,7 @@ namespace Discord | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public struct Optional<T> | public struct Optional<T> | ||||
{ | { | ||||
public static Optional<T> Unspecified => default(Optional<T>); | |||||
public static Optional<T> Unspecified => default; | |||||
private readonly T _value; | private readonly T _value; | ||||
/// <summary> Gets the value for this parameter. </summary> | /// <summary> Gets the value for this parameter. </summary> | ||||
@@ -43,18 +43,18 @@ namespace Discord | |||||
public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0; | public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0; | ||||
public override string ToString() => IsSpecified ? _value?.ToString() : null; | public override string ToString() => IsSpecified ? _value?.ToString() : null; | ||||
private string DebuggerDisplay => IsSpecified ? (_value?.ToString() ?? "<null>") : "<unspecified>"; | |||||
private string DebuggerDisplay => IsSpecified ? _value?.ToString() ?? "<null>" : "<unspecified>"; | |||||
public static implicit operator Optional<T>(T value) => new Optional<T>(value); | |||||
public static implicit operator Optional<T>(T value) => new(value); | |||||
public static explicit operator T(Optional<T> value) => value.Value; | public static explicit operator T(Optional<T> value) => value.Value; | ||||
} | } | ||||
public static class Optional | public static class Optional | ||||
{ | { | ||||
public static Optional<T> Create<T>() => Optional<T>.Unspecified; | public static Optional<T> Create<T>() => Optional<T>.Unspecified; | ||||
public static Optional<T> Create<T>(T value) => new Optional<T>(value); | |||||
public static Optional<T> Create<T>(T value) => new(value); | |||||
public static T? ToNullable<T>(this Optional<T> val) | public static T? ToNullable<T>(this Optional<T> val) | ||||
where T : struct | where T : struct | ||||
=> val.IsSpecified ? val.Value : (T?)null; | |||||
=> val.IsSpecified ? val.Value : null; | |||||
} | } | ||||
} | } |
@@ -1,13 +1,8 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
internal class InteractionApplicationCommandCallbackData | |||||
internal class InteractionCallbackData | |||||
{ | { | ||||
[JsonProperty("tts")] | [JsonProperty("tts")] | ||||
public Optional<bool> TTS { get; set; } | public Optional<bool> TTS { get; set; } | ||||
@@ -27,12 +22,5 @@ namespace Discord.API | |||||
[JsonProperty("components")] | [JsonProperty("components")] | ||||
public Optional<API.ActionRowComponent[]> Components { get; set; } | public Optional<API.ActionRowComponent[]> Components { get; set; } | ||||
public InteractionApplicationCommandCallbackData() { } | |||||
public InteractionApplicationCommandCallbackData(string text) | |||||
{ | |||||
this.Content = text; | |||||
} | |||||
} | } | ||||
} | } |
@@ -13,6 +13,6 @@ namespace Discord.API | |||||
public InteractionResponseType Type { get; set; } | public InteractionResponseType Type { get; set; } | ||||
[JsonProperty("data")] | [JsonProperty("data")] | ||||
public Optional<InteractionApplicationCommandCallbackData> Data { get; set; } | |||||
public Optional<InteractionCallbackData> Data { get; set; } | |||||
} | } | ||||
} | } |
@@ -55,7 +55,7 @@ namespace Discord.API | |||||
_restClientProvider = restClientProvider; | _restClientProvider = restClientProvider; | ||||
UserAgent = userAgent; | UserAgent = userAgent; | ||||
DefaultRetryMode = defaultRetryMode; | DefaultRetryMode = defaultRetryMode; | ||||
_serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; | |||||
_serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver(), NullValueHandling = NullValueHandling.Ignore }; | |||||
UseSystemClock = useSystemClock; | UseSystemClock = useSystemClock; | ||||
RequestQueue = new RequestQueue(); | RequestQueue = new RequestQueue(); | ||||
@@ -3452,7 +3452,7 @@ | |||||
<param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | ||||
<param name="embed">A <see cref="T:Discord.Embed"/> to send with this response</param> | <param name="embed">A <see cref="T:Discord.Embed"/> to send with this response</param> | ||||
<param name="type">The type of response to this Interaction.</param> | <param name="type">The type of response to this Interaction.</param> | ||||
/// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
<param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
<param name="allowedMentions">The allowed mentions for this response.</param> | <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
<param name="options">The request options for this response.</param> | <param name="options">The request options for this response.</param> | ||||
<param name="component">A <see cref="T:Discord.MessageComponent"/> to be sent with this response</param> | <param name="component">A <see cref="T:Discord.MessageComponent"/> to be sent with this response</param> | ||||
@@ -3487,7 +3487,7 @@ | |||||
<param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | ||||
<param name="embeds">A array of embeds to send with this response. Max 10</param> | <param name="embeds">A array of embeds to send with this response. Max 10</param> | ||||
<param name="type">The type of response to this Interaction.</param> | <param name="type">The type of response to this Interaction.</param> | ||||
/// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
<param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
<param name="allowedMentions">The allowed mentions for this response.</param> | <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
<param name="options">The request options for this response.</param> | <param name="options">The request options for this response.</param> | ||||
<param name="component">A <see cref="T:Discord.MessageComponent"/> to be sent with this response</param> | <param name="component">A <see cref="T:Discord.MessageComponent"/> to be sent with this response</param> | ||||
@@ -107,16 +107,15 @@ namespace Discord.WebSocket | |||||
} | } | ||||
var response = new API.InteractionResponse() | |||||
var response = new API.InteractionResponse | |||||
{ | { | ||||
Type = type, | Type = type, | ||||
Data = new API.InteractionApplicationCommandCallbackData(text) | |||||
Data = new API.InteractionCallbackData | |||||
{ | { | ||||
Content = text ?? Optional<string>.Unspecified, | |||||
AllowedMentions = allowedMentions?.ToModel(), | AllowedMentions = allowedMentions?.ToModel(), | ||||
Embeds = embeds != null | |||||
? embeds.Select(x => x.ToModel()).ToArray() | |||||
: Optional<API.Embed[]>.Unspecified, | |||||
TTS = isTTS, | |||||
Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
TTS = type == InteractionResponseType.ChannelMessageWithSource ? isTTS : Optional<bool>.Unspecified, | |||||
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified | Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified | ||||
} | } | ||||
}; | }; | ||||
@@ -90,16 +90,15 @@ namespace Discord.WebSocket | |||||
} | } | ||||
var response = new API.InteractionResponse() | |||||
var response = new API.InteractionResponse | |||||
{ | { | ||||
Type = type, | Type = type, | ||||
Data = new API.InteractionApplicationCommandCallbackData(text) | |||||
Data = new API.InteractionCallbackData | |||||
{ | { | ||||
Content = text ?? Optional<string>.Unspecified, | |||||
AllowedMentions = allowedMentions?.ToModel(), | AllowedMentions = allowedMentions?.ToModel(), | ||||
Embeds = embeds != null | |||||
? embeds.Select(x => x.ToModel()).ToArray() | |||||
: Optional<API.Embed[]>.Unspecified, | |||||
TTS = isTTS, | |||||
Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
TTS = isTTS ? true : Optional<bool>.Unspecified, | |||||
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified | Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified | ||||
} | } | ||||
}; | }; | ||||
@@ -123,7 +123,7 @@ namespace Discord.WebSocket | |||||
/// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | /// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | ||||
/// <param name="embed">A <see cref="Embed"/> to send with this response</param> | /// <param name="embed">A <see cref="Embed"/> to send with this response</param> | ||||
/// <param name="type">The type of response to this Interaction.</param> | /// <param name="type">The type of response to this Interaction.</param> | ||||
/// /// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
/// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
/// <param name="allowedMentions">The allowed mentions for this response.</param> | /// <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
/// <param name="options">The request options for this response.</param> | /// <param name="options">The request options for this response.</param> | ||||
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | ||||
@@ -161,7 +161,7 @@ namespace Discord.WebSocket | |||||
/// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | /// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> | ||||
/// <param name="embeds">A array of embeds to send with this response. Max 10</param> | /// <param name="embeds">A array of embeds to send with this response. Max 10</param> | ||||
/// <param name="type">The type of response to this Interaction.</param> | /// <param name="type">The type of response to this Interaction.</param> | ||||
/// /// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
/// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> | |||||
/// <param name="allowedMentions">The allowed mentions for this response.</param> | /// <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
/// <param name="options">The request options for this response.</param> | /// <param name="options">The request options for this response.</param> | ||||
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | ||||