Browse Source

Add support for multiple embeds on interaction response. Fix some preconditions missing

pull/1923/head
quin lynch 4 years ago
parent
commit
170d941925
6 changed files with 90 additions and 72 deletions
  1. +1
    -1
      src/Discord.Net.Core/Discord.Net.Core.csproj
  2. +15
    -15
      src/Discord.Net.Core/Discord.Net.Core.xml
  3. +15
    -41
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
  4. +13
    -7
      src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
  5. +42
    -4
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
  6. +4
    -4
      src/Discord.Net/Discord.Net.nuspec

+ 1
- 1
src/Discord.Net.Core/Discord.Net.Core.csproj View File

@@ -8,7 +8,7 @@
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks>
<PackageId>Discord.Net.Labs.Core</PackageId>
<Version>2.4.4</Version>
<Version>2.4.5</Version>
<Product>Discord.Net.Labs.Core</Product>
<RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl>
<PackageIcon>Temporary.png</PackageIcon>


+ 15
- 15
src/Discord.Net.Core/Discord.Net.Core.xml View File

@@ -7266,31 +7266,31 @@
<member name="F:Discord.TagType.Emoji">
<summary> The object is an emoji. </summary>
</member>
<member name="T:Discord.Entities.Messages.TimestampTag">
<member name="T:Discord.TimestampTag">
<summary>
Represents a class used to make timestamps in messages. see <see href="https://discord.com/developers/docs/reference#message-formatting-timestamp-styles"/>.
</summary>
</member>
<member name="P:Discord.Entities.Messages.TimestampTag.Style">
<member name="P:Discord.TimestampTag.Style">
<summary>
Gets or sets the style of the timestamp tag.
</summary>
</member>
<member name="P:Discord.Entities.Messages.TimestampTag.Time">
<member name="P:Discord.TimestampTag.Time">
<summary>
Gets or sets the time for this timestamp tag.
</summary>
</member>
<member name="M:Discord.Entities.Messages.TimestampTag.ToString">
<member name="M:Discord.TimestampTag.ToString">
<summary>
Converts the current timestamp tag to the string representation supported by discord.
<para>
If the <see cref="P:Discord.Entities.Messages.TimestampTag.Time"/> is null then the default 0 will be used.
If the <see cref="P:Discord.TimestampTag.Time"/> is null then the default 0 will be used.
</para>
</summary>
<returns>A string thats compatable in a discord message, ex: <code>&lt;t:1625944201:f&gt;</code></returns>
</member>
<member name="M:Discord.Entities.Messages.TimestampTag.FromDateTime(System.DateTime,Discord.Entities.Messages.TimestampTagStyles)">
<member name="M:Discord.TimestampTag.FromDateTime(System.DateTime,Discord.TimestampTagStyles)">
<summary>
Creates a new timestamp tag with the specified datetime object.
</summary>
@@ -7298,42 +7298,42 @@
<param name="style">The style for this timestamp tag.</param>
<returns>The newly create timestamp tag.</returns>
</member>
<member name="T:Discord.Entities.Messages.TimestampTagStyles">
<member name="T:Discord.TimestampTagStyles">
<summary>
Represents a set of styles to use with a <see cref="T:Discord.Entities.Messages.TimestampTag"/>
Represents a set of styles to use with a <see cref="T:Discord.TimestampTag"/>
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.ShortTime">
<member name="F:Discord.TimestampTagStyles.ShortTime">
<summary>
A short time string: 16:20
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.LongTime">
<member name="F:Discord.TimestampTagStyles.LongTime">
<summary>
A long time string: 16:20:30
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.ShortDate">
<member name="F:Discord.TimestampTagStyles.ShortDate">
<summary>
A short date string: 20/04/2021
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.LongDate">
<member name="F:Discord.TimestampTagStyles.LongDate">
<summary>
A long date string: 20 April 2021
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.ShortDateTime">
<member name="F:Discord.TimestampTagStyles.ShortDateTime">
<summary>
A short datetime string: 20 April 2021 16:20
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.LongDateTime">
<member name="F:Discord.TimestampTagStyles.LongDateTime">
<summary>
A long datetime string: Tuesday, 20 April 2021 16:20
</summary>
</member>
<member name="F:Discord.Entities.Messages.TimestampTagStyles.Relative">
<member name="F:Discord.TimestampTagStyles.Relative">
<summary>
The relative time to the user: 2 months ago
</summary>


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

@@ -70,27 +70,8 @@ namespace Discord.WebSocket
}
}

/// <summary>
/// Responds to an Interaction.
/// <para>
/// If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
/// <see cref="FollowupAsync(string, bool, Embed, InteractionResponseType, AllowedMentions, RequestOptions)"/> instead.
/// </para>
/// </summary>
/// <param name="text">The text of the message to be sent.</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="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="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>
/// <returns>
/// The <see cref="IMessage"/> sent as the response. If this is the first acknowledgement, it will return null.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>
public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
/// <inheritdoc/>
public override async Task RespondAsync(string text = null, bool isTTS = false, Embed[] embeds = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
if (type == InteractionResponseType.Pong)
@@ -101,12 +82,13 @@ namespace Discord.WebSocket

if (Discord.AlwaysAcknowledgeInteractions)
{
await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options);
await FollowupAsync(text, isTTS, embeds, ephemeral, type, allowedMentions, options);
return;
}

Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");

// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
@@ -131,8 +113,8 @@ namespace Discord.WebSocket
Data = new API.InteractionApplicationCommandCallbackData(text)
{
AllowedMentions = allowedMentions?.ToModel(),
Embeds = embed != null
? new API.Embed[] { embed.ToModel() }
Embeds = embeds != null
? embeds.Select(x => x.ToModel()).ToArray()
: Optional<API.Embed[]>.Unspecified,
TTS = isTTS,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified
@@ -145,21 +127,8 @@ namespace Discord.WebSocket
await InteractionHelper.SendInteractionResponse(this.Discord, this.Channel, response, this.Id, Token, options);
}

/// <summary>
/// Sends a followup message for this interaction.
/// </summary>
/// <param name="text">The text of the message to be sent</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="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="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>
/// <returns>
/// The sent message.
/// </returns>
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
@@ -169,11 +138,16 @@ namespace Discord.WebSocket
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");

Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");

var args = new API.Rest.CreateWebhookMessageParams(text)
{
AllowedMentions = allowedMentions?.ToModel(),
IsTTS = isTTS,
Embeds = embed != null
? new API.Embed[] { embed.ToModel() }
Embeds = embeds != null
? embeds.Select(x => x.ToModel()).ToArray()
: Optional<API.Embed[]>.Unspecified,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified
};


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

@@ -51,7 +51,7 @@ namespace Discord.WebSocket
}

/// <inheritdoc/>
public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
public override async Task RespondAsync(string text = null, bool isTTS = false, Embed[] embeds = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
if (type == InteractionResponseType.Pong)
@@ -65,12 +65,13 @@ namespace Discord.WebSocket

if (Discord.AlwaysAcknowledgeInteractions)
{
await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options);
await FollowupAsync(text, isTTS, embeds, ephemeral, type, allowedMentions, options);
return;
}

Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");

// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
@@ -95,8 +96,8 @@ namespace Discord.WebSocket
Data = new API.InteractionApplicationCommandCallbackData(text)
{
AllowedMentions = allowedMentions?.ToModel(),
Embeds = embed != null
? new API.Embed[] { embed.ToModel() }
Embeds = embeds != null
? embeds.Select(x => x.ToModel()).ToArray()
: Optional<API.Embed[]>.Unspecified,
TTS = isTTS,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified
@@ -110,7 +111,7 @@ namespace Discord.WebSocket
}

/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
@@ -120,11 +121,16 @@ namespace Discord.WebSocket
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");

Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");

var args = new API.Rest.CreateWebhookMessageParams(text)
{
AllowedMentions = allowedMentions?.ToModel(),
IsTTS = isTTS,
Embeds = embed != null
? new API.Embed[] { embed.ToModel() }
Embeds = embeds != null
? embeds.Select(x => x.ToModel()).ToArray()
: Optional<API.Embed[]>.Unspecified,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified
};


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

@@ -99,7 +99,7 @@ namespace Discord.WebSocket
/// Responds to an Interaction.
/// <para>
/// If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
/// <see cref="FollowupAsync(string, bool, Embed, bool, InteractionResponseType, AllowedMentions, RequestOptions, MessageComponent)"/> instead.
/// <see cref="FollowupAsync(string, bool, Embed[], bool, InteractionResponseType, AllowedMentions, RequestOptions, MessageComponent)"/> instead.
/// </para>
/// </summary>
/// <param name="text">The text of the message to be sent.</param>
@@ -112,8 +112,46 @@ namespace Discord.WebSocket
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>
public Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
=> RespondAsync(text, isTTS, new Embed[] { embed }, type, ephemeral, allowedMentions, options, component);

public abstract Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
/// <summary>
/// Sends a followup message for this interaction.
/// </summary>
/// <param name="text">The text of the message to be sent</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="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="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>
/// <returns>
/// The sent message.
/// </returns>
public Task FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
=> RespondAsync(text, isTTS, new Embed[] { embed }, type, ephemeral, allowedMentions, options, component);
/// <summary>
/// Responds to an Interaction.
/// <para>
/// If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
/// <see cref="FollowupAsync(string, bool, Embed[], bool, InteractionResponseType, AllowedMentions, RequestOptions, MessageComponent)"/> instead.
/// </para>
/// </summary>
/// <param name="text">The text of the message to be sent.</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="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="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>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>

public abstract Task RespondAsync(string text = null, bool isTTS = false, Embed[] embeds = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);

/// <summary>
@@ -121,7 +159,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="text">The text of the message to be sent</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="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="allowedMentions">The allowed mentions for this response.</param>
@@ -130,7 +168,7 @@ namespace Discord.WebSocket
/// <returns>
/// The sent message.
/// </returns>
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);



+ 4
- 4
src/Discord.Net/Discord.Net.nuspec View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Discord.Net.Labs</id>
<version>2.4.6$suffix$</version>
<version>2.4.7$suffix$</version>
<title>Discord.Net Labs</title>
<authors>Discord.Net Contributors</authors>
<owners>quinchs</owners>
@@ -14,21 +14,21 @@
<iconUrl>https://avatars.githubusercontent.com/u/84047264</iconUrl>
<dependencies>
<group targetFramework="net461">
<dependency id="Discord.Net.Labs.Core" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.6$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="Discord.Net.Labs.Core" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.6$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" />
</group>
<group targetFramework="netstandard2.1">
<dependency id="Discord.Net.Labs.Core" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.6$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />


Loading…
Cancel
Save