From 36ff3e73a38a37283821157d1fa115c2d3bc1e14 Mon Sep 17 00:00:00 2001 From: quin lynch Date: Fri, 16 Jul 2021 19:21:48 -0300 Subject: [PATCH] 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 --- src/Discord.Net.Core/Discord.Net.Core.xml | 21 ++++++++++++--- .../Entities/Guilds/PermissionTarget.cs | 4 +-- .../ApplicationCommandPermissionTarget.cs | 23 ++++++++++++++++ .../ApplicationCommandPermissions.cs | 12 ++++----- .../Common/ApplicationCommandPermissions.cs | 2 +- .../Discord.Net.WebSocket.xml | 26 ++++++++++++------- .../SocketMessageComponent.cs | 15 +++++++---- .../Slash Commands/SocketSlashCommand.cs | 17 +++++++++--- .../Entities/Interaction/SocketInteraction.cs | 22 +++++----------- 9 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index 8372d7184..9e288d1a1 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -7407,7 +7407,7 @@ to allow, otherwise . - + Creates a new . @@ -7417,18 +7417,33 @@ - Creates a new targeting . + Creates a new targeting . The user you want to target this permission value for. The value of this permission. - Creates a new targeting . + Creates a new targeting . The role you want to target this permission value for. The value of this permission. + + + Specifies the target of the permission. + + + + + The target of the permission is a role. + + + + + The target of the permission is a user. + + Defines the available permissions for a channel. diff --git a/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs b/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs index 39e7c81f2..fb759e4c5 100644 --- a/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs +++ b/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs @@ -8,10 +8,10 @@ namespace Discord /// /// The target of the permission is a role. /// - Role = 1, + Role = 0, /// /// The target of the permission is a user. /// - User = 2, + User = 1, } } diff --git a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs new file mode 100644 index 000000000..5410075ba --- /dev/null +++ b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Specifies the target of the permission. + /// + public enum ApplicationCommandPermissionTarget + { + /// + /// The target of the permission is a role. + /// + Role = 1, + /// + /// The target of the permission is a user. + /// + User = 2, + } +} diff --git a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs index f87613ab8..476960522 100644 --- a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs @@ -13,7 +13,7 @@ namespace Discord /// /// The target of this permission. /// - public PermissionTarget TargetType { get; } + public ApplicationCommandPermissionTarget TargetType { get; } /// /// to allow, otherwise . @@ -28,7 +28,7 @@ namespace Discord /// The id you want to target this permission value for. /// The type of the targetId parameter. /// The value of this permission. - 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 } /// - /// Creates a new targeting . + /// Creates a new targeting . /// /// The user you want to target this permission value for. /// The value of this permission. @@ -44,11 +44,11 @@ namespace Discord { this.TargetId = target.Id; this.Permission = allow; - this.TargetType = PermissionTarget.User; + this.TargetType = ApplicationCommandPermissionTarget.User; } /// - /// Creates a new targeting . + /// Creates a new targeting . /// /// The role you want to target this permission value for. /// The value of this permission. @@ -56,7 +56,7 @@ namespace Discord { this.TargetId = target.Id; this.Permission = allow; - this.TargetType = PermissionTarget.Role; + this.TargetType = ApplicationCommandPermissionTarget.Role; } } } diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs index a4a4ae074..281ded90f 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs @@ -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; } diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index dc128527d..89d29ba09 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -3223,14 +3223,19 @@ The message that contained the trigger for this interaction. - + - + - + + Acknowledges this interaction with the . + + + A task that represents the asynchronous operation of acknowledging the interaction. + @@ -3336,10 +3341,13 @@ The data associated with this interaction. - + + + + - + @@ -3422,7 +3430,7 @@ Responds to an Interaction. If you have set to , You should use - instead. + instead. The text of the message to be sent. @@ -3452,12 +3460,12 @@ The sent message. - + Responds to an Interaction. If you have set to , You should use - instead. + instead. The text of the message to be sent. @@ -3471,7 +3479,7 @@ Message content is too long, length must be less or equal to . The parameters provided were invalid or the token was invalid. - + Sends a followup message for this interaction. 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 846052fe5..18fb0eafe 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs @@ -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 } /// - 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 } /// - public override async Task FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false, + public override async Task 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); } - /// + /// + /// Acknowledges this interaction with the . + /// + /// + /// A task that represents the asynchronous operation of acknowledging the interaction. + /// public override Task AcknowledgeAsync(RequestOptions options = null) { var response = new API.InteractionResponse() 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 e3bb1168c..78fd3b715 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs @@ -51,7 +51,7 @@ namespace Discord.WebSocket } /// - 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 } /// - public override async Task FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false, + public override async Task 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); } + + /// + 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); + } } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs index d15308c66..5c950b450 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs @@ -99,7 +99,7 @@ namespace Discord.WebSocket /// Responds to an Interaction. /// /// If you have set to , You should use - /// instead. + /// instead. /// /// /// The text of the message to be sent. @@ -114,7 +114,7 @@ namespace Discord.WebSocket /// The parameters provided were invalid or the token was invalid. 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); /// /// Sends a followup message for this interaction. @@ -132,12 +132,12 @@ namespace Discord.WebSocket /// 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); /// /// Responds to an Interaction. /// /// If you have set to , You should use - /// instead. + /// instead. /// /// /// The text of the message to be sent. @@ -151,7 +151,7 @@ namespace Discord.WebSocket /// Message content is too long, length must be less or equal to . /// The parameters provided were invalid or the token was invalid. - 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); /// @@ -168,7 +168,7 @@ namespace Discord.WebSocket /// /// The sent message. /// - public abstract Task FollowupAsync(string text = null, bool isTTS = false, Embed[] embeds = null, bool ephemeral = false, + public abstract Task 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 /// /// A task that represents the asynchronous operation of acknowledging the interaction. /// - 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() {