From 8433476adda7ac7715079e4fe0c800d819c9aa86 Mon Sep 17 00:00:00 2001 From: Nikon <47792796+INikonI@users.noreply.github.com> Date: Sat, 24 Jul 2021 08:53:12 +0500 Subject: [PATCH] Remove necessary things and some fix/changes (#57) * 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 0fbf1000daf5d2afc130797a3ee2421b120beaa2 * Revert "Update Emoji.cs" and add Parse method This reverts commit f297dcfc4320c55ba7108b8e7ef9fa5ad35cd3bc. * Partial revert 3c27ab36c9a0603ac9b1a7819d1be6bb37d7213a * 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 --- src/Discord.Net.Core/Discord.Net.Core.xml | 5 +++++ .../Message Components/ComponentBuilder.cs | 12 ++++++++++++ src/Discord.Net.Core/Utils/Optional.cs | 10 +++++----- ...dCallbackData.cs => InteractionCallbackData.cs} | 14 +------------- .../API/Common/InteractionResponse.cs | 2 +- src/Discord.Net.Rest/DiscordRestApiClient.cs | 2 +- .../Discord.Net.WebSocket.xml | 4 ++-- .../Message Components/SocketMessageComponent.cs | 11 +++++------ .../Slash Commands/SocketSlashCommand.cs | 11 +++++------ .../Entities/Interaction/SocketInteraction.cs | 4 ++-- 10 files changed, 39 insertions(+), 36 deletions(-) rename src/Discord.Net.Rest/API/Common/{InteractionApplicationCommandCallbackData.cs => InteractionCallbackData.cs} (68%) diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index a72df4e09..db3bbe3aa 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -4838,6 +4838,11 @@ The emote of this option. Render this option as selected by default or not. + + + Creates a new instance of a from instance of a . + + Sets the field label. diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs index 89bd6598a..b2423796d 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs @@ -906,6 +906,18 @@ namespace Discord this.Default = @default; } + /// + /// Creates a new instance of a from instance of a . + /// + public SelectMenuOptionBuilder(SelectMenuOption option) + { + this.Label = option.Label; + this.Value = option.Value; + this.Description = option.Description; + this.Emote = option.Emote; + this.Default = option.Default; + } + /// /// Sets the field label. /// diff --git a/src/Discord.Net.Core/Utils/Optional.cs b/src/Discord.Net.Core/Utils/Optional.cs index 348179699..985be9240 100644 --- a/src/Discord.Net.Core/Utils/Optional.cs +++ b/src/Discord.Net.Core/Utils/Optional.cs @@ -7,7 +7,7 @@ namespace Discord [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public struct Optional { - public static Optional Unspecified => default(Optional); + public static Optional Unspecified => default; private readonly T _value; /// Gets the value for this parameter. @@ -43,18 +43,18 @@ namespace Discord public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0; public override string ToString() => IsSpecified ? _value?.ToString() : null; - private string DebuggerDisplay => IsSpecified ? (_value?.ToString() ?? "") : ""; + private string DebuggerDisplay => IsSpecified ? _value?.ToString() ?? "" : ""; - public static implicit operator Optional(T value) => new Optional(value); + public static implicit operator Optional(T value) => new(value); public static explicit operator T(Optional value) => value.Value; } public static class Optional { public static Optional Create() => Optional.Unspecified; - public static Optional Create(T value) => new Optional(value); + public static Optional Create(T value) => new(value); public static T? ToNullable(this Optional val) where T : struct - => val.IsSpecified ? val.Value : (T?)null; + => val.IsSpecified ? val.Value : null; } } diff --git a/src/Discord.Net.Rest/API/Common/InteractionApplicationCommandCallbackData.cs b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs similarity index 68% rename from src/Discord.Net.Rest/API/Common/InteractionApplicationCommandCallbackData.cs rename to src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs index 3f7cf93e0..f6e3dcbee 100644 --- a/src/Discord.Net.Rest/API/Common/InteractionApplicationCommandCallbackData.cs +++ b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs @@ -1,13 +1,8 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Discord.API { - internal class InteractionApplicationCommandCallbackData + internal class InteractionCallbackData { [JsonProperty("tts")] public Optional TTS { get; set; } @@ -27,12 +22,5 @@ namespace Discord.API [JsonProperty("components")] public Optional Components { get; set; } - - public InteractionApplicationCommandCallbackData() { } - public InteractionApplicationCommandCallbackData(string text) - { - this.Content = text; - } - } } diff --git a/src/Discord.Net.Rest/API/Common/InteractionResponse.cs b/src/Discord.Net.Rest/API/Common/InteractionResponse.cs index 6be48340b..e50e8076e 100644 --- a/src/Discord.Net.Rest/API/Common/InteractionResponse.cs +++ b/src/Discord.Net.Rest/API/Common/InteractionResponse.cs @@ -13,6 +13,6 @@ namespace Discord.API public InteractionResponseType Type { get; set; } [JsonProperty("data")] - public Optional Data { get; set; } + public Optional Data { get; set; } } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 56bfed20e..c24d1ed57 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -55,7 +55,7 @@ namespace Discord.API _restClientProvider = restClientProvider; UserAgent = userAgent; DefaultRetryMode = defaultRetryMode; - _serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; + _serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver(), NullValueHandling = NullValueHandling.Ignore }; UseSystemClock = useSystemClock; RequestQueue = new RequestQueue(); diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index 89d29ba09..9b285f33f 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -3452,7 +3452,7 @@ if the message should be read out by a text-to-speech reader, otherwise . A to send with this response The type of response to this Interaction. - /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + if the response should be hidden to everyone besides the invoker of the command, otherwise . The allowed mentions for this response. The request options for this response. A to be sent with this response @@ -3487,7 +3487,7 @@ if the message should be read out by a text-to-speech reader, otherwise . A array of embeds to send with this response. Max 10 The type of response to this Interaction. - /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + if the response should be hidden to everyone besides the invoker of the command, otherwise . The allowed mentions for this response. The request options for this response. A to be sent with this response diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs index a89e6de06..8cbfc362e 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs @@ -107,16 +107,15 @@ namespace Discord.WebSocket } - var response = new API.InteractionResponse() + var response = new API.InteractionResponse { Type = type, - Data = new API.InteractionApplicationCommandCallbackData(text) + Data = new API.InteractionCallbackData { + Content = text ?? Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel(), - Embeds = embeds != null - ? embeds.Select(x => x.ToModel()).ToArray() - : Optional.Unspecified, - TTS = isTTS, + Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified, + TTS = type == InteractionResponseType.ChannelMessageWithSource ? isTTS : Optional.Unspecified, Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified } }; diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs index c5f986eed..e3596ec50 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs @@ -90,16 +90,15 @@ namespace Discord.WebSocket } - var response = new API.InteractionResponse() + var response = new API.InteractionResponse { Type = type, - Data = new API.InteractionApplicationCommandCallbackData(text) + Data = new API.InteractionCallbackData { + Content = text ?? Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel(), - Embeds = embeds != null - ? embeds.Select(x => x.ToModel()).ToArray() - : Optional.Unspecified, - TTS = isTTS, + Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified, + TTS = isTTS ? true : Optional.Unspecified, Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified } }; diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs index 79a2c81dc..e6a5a9d34 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs @@ -123,7 +123,7 @@ namespace Discord.WebSocket /// if the message should be read out by a text-to-speech reader, otherwise . /// A to send with this response /// The type of response to this Interaction. - /// /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . /// The allowed mentions for this response. /// The request options for this response. /// A to be sent with this response @@ -161,7 +161,7 @@ namespace Discord.WebSocket /// if the message should be read out by a text-to-speech reader, otherwise . /// A array of embeds to send with this response. Max 10 /// The type of response to this Interaction. - /// /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . /// The allowed mentions for this response. /// The request options for this response. /// A to be sent with this response