Browse Source

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 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

* remove necessary things and some fix/changes

- Rename InteractionApplicationCommanCallbackData -> InteractionCallbackData
- Fix wrong creating instances of InteractionCallbackData

* Add SelectMenuOptionBuilder ctor overload
pull/1923/head
Nikon GitHub 3 years ago
parent
commit
8433476add
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 36 deletions
  1. +5
    -0
      src/Discord.Net.Core/Discord.Net.Core.xml
  2. +12
    -0
      src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
  3. +5
    -5
      src/Discord.Net.Core/Utils/Optional.cs
  4. +1
    -13
      src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs
  5. +1
    -1
      src/Discord.Net.Rest/API/Common/InteractionResponse.cs
  6. +1
    -1
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  7. +2
    -2
      src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
  8. +5
    -6
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
  9. +5
    -6
      src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
  10. +2
    -2
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs

+ 5
- 0
src/Discord.Net.Core/Discord.Net.Core.xml View File

@@ -4838,6 +4838,11 @@
<param name="emote">The emote of this option.</param>
<param name="default">Render this option as selected by default or not.</param>
</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)">
<summary>
Sets the field label.


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

@@ -906,6 +906,18 @@ namespace Discord
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>
/// Sets the field label.
/// </summary>


+ 5
- 5
src/Discord.Net.Core/Utils/Optional.cs View File

@@ -7,7 +7,7 @@ namespace Discord
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct Optional<T>
{
public static Optional<T> Unspecified => default(Optional<T>);
public static Optional<T> Unspecified => default;
private readonly T _value;

/// <summary> Gets the value for this parameter. </summary>
@@ -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() ?? "<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 class Optional
{
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)
where T : struct
=> val.IsSpecified ? val.Value : (T?)null;
=> val.IsSpecified ? val.Value : null;
}
}

src/Discord.Net.Rest/API/Common/InteractionApplicationCommandCallbackData.cs → src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs View File

@@ -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<bool> TTS { get; set; }
@@ -27,12 +22,5 @@ namespace Discord.API

[JsonProperty("components")]
public Optional<API.ActionRowComponent[]> Components { get; set; }

public InteractionApplicationCommandCallbackData() { }
public InteractionApplicationCommandCallbackData(string text)
{
this.Content = text;
}
}
}

+ 1
- 1
src/Discord.Net.Rest/API/Common/InteractionResponse.cs View File

@@ -13,6 +13,6 @@ namespace Discord.API
public InteractionResponseType Type { get; set; }

[JsonProperty("data")]
public Optional<InteractionApplicationCommandCallbackData> Data { get; set; }
public Optional<InteractionCallbackData> Data { get; set; }
}
}

+ 1
- 1
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -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();


+ 2
- 2
src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml View File

@@ -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="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="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="options">The request options for 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="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="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="options">The request options for this response.</param>
<param name="component">A <see cref="T:Discord.MessageComponent"/> to be sent with this response</param>


+ 5
- 6
src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs View File

@@ -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<string>.Unspecified,
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
}
};


+ 5
- 6
src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs View File

@@ -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<string>.Unspecified,
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
}
};


+ 2
- 2
src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs View File

@@ -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="embed">A <see cref="Embed"/> to send with this response</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="options">The request options for 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="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="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="options">The request options for this response.</param>
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param>


Loading…
Cancel
Save