Browse Source

fix: multiple bugs

Fixed permission overwrites using incorrect values for targets

Fixed invalid form data for responding

Fixed ambiguous method for responding/folloup

Added new ApplicationCommandPermissionTarget for slash command permissions
pull/1923/head
quin lynch 3 years ago
parent
commit
36ff3e73a3
9 changed files with 98 additions and 44 deletions
  1. +18
    -3
      src/Discord.Net.Core/Discord.Net.Core.xml
  2. +2
    -2
      src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs
  3. +23
    -0
      src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs
  4. +6
    -6
      src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs
  5. +1
    -1
      src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs
  6. +17
    -9
      src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
  7. +10
    -5
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
  8. +14
    -3
      src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
  9. +7
    -15
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs

+ 18
- 3
src/Discord.Net.Core/Discord.Net.Core.xml View File

@@ -7407,7 +7407,7 @@
<see langword="true"/> to allow, otherwise <see langword="false"/>.
</summary>
</member>
<member name="M:Discord.ApplicationCommandPermission.#ctor(System.UInt64,Discord.PermissionTarget,System.Boolean)">
<member name="M:Discord.ApplicationCommandPermission.#ctor(System.UInt64,Discord.ApplicationCommandPermissionTarget,System.Boolean)">
<summary>
Creates a new <see cref="T:Discord.ApplicationCommandPermission"/>.
</summary>
@@ -7417,18 +7417,33 @@
</member>
<member name="M:Discord.ApplicationCommandPermission.#ctor(Discord.IUser,System.Boolean)">
<summary>
Creates a new <see cref="T:Discord.ApplicationCommandPermission"/> targeting <see cref="F:Discord.PermissionTarget.User"/>.
Creates a new <see cref="T:Discord.ApplicationCommandPermission"/> targeting <see cref="F:Discord.ApplicationCommandPermissionTarget.User"/>.
</summary>
<param name="target">The user you want to target this permission value for.</param>
<param name="allow">The value of this permission.</param>
</member>
<member name="M:Discord.ApplicationCommandPermission.#ctor(Discord.IRole,System.Boolean)">
<summary>
Creates a new <see cref="T:Discord.ApplicationCommandPermission"/> targeting <see cref="F:Discord.PermissionTarget.Role"/>.
Creates a new <see cref="T:Discord.ApplicationCommandPermission"/> targeting <see cref="F:Discord.ApplicationCommandPermissionTarget.Role"/>.
</summary>
<param name="target">The role you want to target this permission value for.</param>
<param name="allow">The value of this permission.</param>
</member>
<member name="T:Discord.ApplicationCommandPermissionTarget">
<summary>
Specifies the target of the permission.
</summary>
</member>
<member name="F:Discord.ApplicationCommandPermissionTarget.Role">
<summary>
The target of the permission is a role.
</summary>
</member>
<member name="F:Discord.ApplicationCommandPermissionTarget.User">
<summary>
The target of the permission is a user.
</summary>
</member>
<member name="T:Discord.ChannelPermission">
<summary> Defines the available permissions for a channel. </summary>
</member>


+ 2
- 2
src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs View File

@@ -8,10 +8,10 @@ namespace Discord
/// <summary>
/// The target of the permission is a role.
/// </summary>
Role = 1,
Role = 0,
/// <summary>
/// The target of the permission is a user.
/// </summary>
User = 2,
User = 1,
}
}

+ 23
- 0
src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
{
/// <summary>
/// Specifies the target of the permission.
/// </summary>
public enum ApplicationCommandPermissionTarget
{
/// <summary>
/// The target of the permission is a role.
/// </summary>
Role = 1,
/// <summary>
/// The target of the permission is a user.
/// </summary>
User = 2,
}
}

+ 6
- 6
src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs View File

@@ -13,7 +13,7 @@ namespace Discord
/// <summary>
/// The target of this permission.
/// </summary>
public PermissionTarget TargetType { get; }
public ApplicationCommandPermissionTarget TargetType { get; }

/// <summary>
/// <see langword="true"/> to allow, otherwise <see langword="false"/>.
@@ -28,7 +28,7 @@ namespace Discord
/// <param name="targetId">The id you want to target this permission value for.</param>
/// <param name="targetType">The type of the <b>targetId</b> parameter.</param>
/// <param name="allow">The value of this permission.</param>
public ApplicationCommandPermission(ulong targetId, PermissionTarget targetType, bool allow)
public ApplicationCommandPermission(ulong targetId, ApplicationCommandPermissionTarget targetType, bool allow)
{
this.TargetId = targetId;
this.TargetType = targetType;
@@ -36,7 +36,7 @@ namespace Discord
}

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting <see cref="PermissionTarget.User"/>.
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting <see cref="ApplicationCommandPermissionTarget.User"/>.
/// </summary>
/// <param name="target">The user you want to target this permission value for.</param>
/// <param name="allow">The value of this permission.</param>
@@ -44,11 +44,11 @@ namespace Discord
{
this.TargetId = target.Id;
this.Permission = allow;
this.TargetType = PermissionTarget.User;
this.TargetType = ApplicationCommandPermissionTarget.User;
}

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting <see cref="PermissionTarget.Role"/>.
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting <see cref="ApplicationCommandPermissionTarget.Role"/>.
/// </summary>
/// <param name="target">The role you want to target this permission value for.</param>
/// <param name="allow">The value of this permission.</param>
@@ -56,7 +56,7 @@ namespace Discord
{
this.TargetId = target.Id;
this.Permission = allow;
this.TargetType = PermissionTarget.Role;
this.TargetType = ApplicationCommandPermissionTarget.Role;
}
}
}

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

@@ -13,7 +13,7 @@ namespace Discord.API
public ulong Id { get; set; }

[JsonProperty("type")]
public PermissionTarget Type { get; set; }
public ApplicationCommandPermissionTarget Type { get; set; }

[JsonProperty("permission")]
public bool Permission { get; set; }


+ 17
- 9
src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml View File

@@ -3223,14 +3223,19 @@
The message that contained the trigger for this interaction.
</summary>
</member>
<member name="M:Discord.WebSocket.SocketMessageComponent.RespondAsync(System.String,System.Boolean,Discord.Embed[],Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketMessageComponent.RespondAsync(Discord.Embed[],System.String,System.Boolean,Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<inheritdoc/>
</member>
<member name="M:Discord.WebSocket.SocketMessageComponent.FollowupAsync(System.String,System.Boolean,Discord.Embed[],System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketMessageComponent.FollowupAsync(Discord.Embed[],System.String,System.Boolean,System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<inheritdoc/>
</member>
<member name="M:Discord.WebSocket.SocketMessageComponent.AcknowledgeAsync(Discord.RequestOptions)">
<inheritdoc/>
<summary>
Acknowledges this interaction with the <see cref="F:Discord.InteractionResponseType.DeferredUpdateMessage"/>.
</summary>
<returns>
A task that represents the asynchronous operation of acknowledging the interaction.
</returns>
</member>
<member name="T:Discord.WebSocket.SocketMessageComponentData">
<summary>
@@ -3336,10 +3341,13 @@
The data associated with this interaction.
</summary>
</member>
<member name="M:Discord.WebSocket.SocketSlashCommand.RespondAsync(System.String,System.Boolean,Discord.Embed[],Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketSlashCommand.RespondAsync(Discord.Embed[],System.String,System.Boolean,Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<inheritdoc/>
</member>
<member name="M:Discord.WebSocket.SocketSlashCommand.FollowupAsync(Discord.Embed[],System.String,System.Boolean,System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<inheritdoc/>
</member>
<member name="M:Discord.WebSocket.SocketSlashCommand.FollowupAsync(System.String,System.Boolean,Discord.Embed[],System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketSlashCommand.AcknowledgeAsync(Discord.RequestOptions)">
<inheritdoc/>
</member>
<member name="T:Discord.WebSocket.SocketSlashCommandData">
@@ -3422,7 +3430,7 @@
Responds to an Interaction.
<para>
If you have <see cref="P:Discord.WebSocket.DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
<see cref="M:Discord.WebSocket.SocketInteraction.FollowupAsync(System.String,System.Boolean,Discord.Embed[],System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)"/> instead.
<see cref="M:Discord.WebSocket.SocketInteraction.FollowupAsync(Discord.Embed[],System.String,System.Boolean,System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)"/> instead.
</para>
</summary>
<param name="text">The text of the message to be sent.</param>
@@ -3452,12 +3460,12 @@
The sent message.
</returns>
</member>
<member name="M:Discord.WebSocket.SocketInteraction.RespondAsync(System.String,System.Boolean,Discord.Embed[],Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketInteraction.RespondAsync(Discord.Embed[],System.String,System.Boolean,Discord.InteractionResponseType,System.Boolean,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<summary>
Responds to an Interaction.
<para>
If you have <see cref="P:Discord.WebSocket.DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use
<see cref="M:Discord.WebSocket.SocketInteraction.FollowupAsync(System.String,System.Boolean,Discord.Embed[],System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)"/> instead.
<see cref="M:Discord.WebSocket.SocketInteraction.FollowupAsync(Discord.Embed[],System.String,System.Boolean,System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)"/> instead.
</para>
</summary>
<param name="text">The text of the message to be sent.</param>
@@ -3471,7 +3479,7 @@
<exception cref="T:System.ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="F:Discord.DiscordConfig.MaxMessageSize"/>.</exception>
<exception cref="T:System.InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>
</member>
<member name="M:Discord.WebSocket.SocketInteraction.FollowupAsync(System.String,System.Boolean,Discord.Embed[],System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<member name="M:Discord.WebSocket.SocketInteraction.FollowupAsync(Discord.Embed[],System.String,System.Boolean,System.Boolean,Discord.InteractionResponseType,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)">
<summary>
Sends a followup message for this interaction.
</summary>


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

@@ -50,7 +50,7 @@ namespace Discord.WebSocket
{
if (this.Message == null)
{
SocketUser author = null;
SocketUser author;
if (this.Channel is SocketGuildChannel channel)
{
if (model.Message.Value.WebhookId.IsSpecified)
@@ -71,7 +71,7 @@ namespace Discord.WebSocket
}

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

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

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

/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
public override async Task<RestFollowupMessage> FollowupAsync(Embed[] embeds = null, string text = null, bool isTTS = false, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
@@ -158,7 +158,12 @@ namespace Discord.WebSocket
return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
}

/// <inheritdoc/>
/// <summary>
/// Acknowledges this interaction with the <see cref="InteractionResponseType.DeferredUpdateMessage"/>.
/// </summary>
/// <returns>
/// A task that represents the asynchronous operation of acknowledging the interaction.
/// </returns>
public override Task AcknowledgeAsync(RequestOptions options = null)
{
var response = new API.InteractionResponse()


+ 14
- 3
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[] embeds = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
public override async Task RespondAsync(Embed[] embeds = null, string text = null, bool isTTS = false, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
if (type == InteractionResponseType.Pong)
@@ -65,7 +65,7 @@ namespace Discord.WebSocket

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

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

/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
public override async Task<RestFollowupMessage> FollowupAsync(Embed[] embeds = null, string text = null, bool isTTS = false, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
@@ -140,5 +140,16 @@ namespace Discord.WebSocket

return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
}

/// <inheritdoc/>
public override Task AcknowledgeAsync(RequestOptions options = null)
{
var response = new API.InteractionResponse()
{
Type = InteractionResponseType.DeferredChannelMessageWithSource,
};

return Discord.Rest.ApiClient.CreateInteractionResponse(response, this.Id, this.Token, options);
}
}
}

+ 7
- 15
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(Embed[],string, bool, bool, InteractionResponseType, AllowedMentions, RequestOptions, MessageComponent)"/> instead.
/// </para>
/// </summary>
/// <param name="text">The text of the message to be sent.</param>
@@ -114,7 +114,7 @@ namespace Discord.WebSocket
/// <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);
=> RespondAsync(embed != null ? new Embed[] { embed } : null, text, isTTS, type, ephemeral, allowedMentions, options, component);

/// <summary>
/// Sends a followup message for this interaction.
@@ -132,12 +132,12 @@ namespace Discord.WebSocket
/// </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);
=> RespondAsync(embed != null ? new Embed[] { embed } : null, text, isTTS, 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.
/// <see cref="FollowupAsync( Embed[],string, bool, bool, InteractionResponseType, AllowedMentions, RequestOptions, MessageComponent)"/> instead.
/// </para>
/// </summary>
/// <param name="text">The text of the message to be sent.</param>
@@ -151,7 +151,7 @@ namespace Discord.WebSocket
/// <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,
public abstract Task RespondAsync(Embed[] embeds = null, string text = null, bool isTTS = false, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);

/// <summary>
@@ -168,7 +168,7 @@ namespace Discord.WebSocket
/// <returns>
/// The sent message.
/// </returns>
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false,
public abstract Task<RestFollowupMessage> FollowupAsync(Embed[] embeds = null, string text = null, bool isTTS = false, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);

@@ -186,15 +186,7 @@ namespace Discord.WebSocket
/// <returns>
/// A task that represents the asynchronous operation of acknowledging the interaction.
/// </returns>
public virtual Task AcknowledgeAsync(RequestOptions options = null)
{
var response = new API.InteractionResponse()
{
Type = InteractionResponseType.DeferredChannelMessageWithSource,
};

return Discord.Rest.ApiClient.CreateInteractionResponse(response, this.Id, this.Token, options);
}
public abstract Task AcknowledgeAsync(RequestOptions options = null);

private bool CheckToken()
{


Loading…
Cancel
Save