From 476c136901d0bf12500d5314a5b1cd58c427db93 Mon Sep 17 00:00:00 2001 From: Panthr75 Date: Fri, 14 Jul 2023 14:11:32 -0500 Subject: [PATCH 1/4] initial commit --- src/Discord.Net.Core/DiscordConfig.cs | 5 +++ .../Entities/Applications/ApplicationFlags.cs | 39 ++++++++++++++++--- .../Applications/ApplicationInstallParams.cs | 37 ++++++++---------- .../Entities/Applications/IApplication.cs | 2 +- .../ModifyApplicationProperties.cs | 24 ++++++++++++ .../API/Common/InstallParams.cs | 19 ++++----- .../Rest/ModifyCurrentApplicationBotParams.cs | 25 ++++++++---- src/Discord.Net.Rest/ClientHelper.cs | 14 ++++++- .../Entities/RestApplication.cs | 8 +++- 9 files changed, 124 insertions(+), 49 deletions(-) diff --git a/src/Discord.Net.Core/DiscordConfig.cs b/src/Discord.Net.Core/DiscordConfig.cs index f7d071401a..1df8d1f866 100644 --- a/src/Discord.Net.Core/DiscordConfig.cs +++ b/src/Discord.Net.Core/DiscordConfig.cs @@ -232,5 +232,10 @@ public class DiscordConfig /// Returns the max length of an application description. /// public const int MaxApplicationDescriptionLength = 400; + + /// + /// Returns the max amount of tags applied to an application. + /// + public const int MaxApplicationTagCount = 5; } } diff --git a/src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs index 0c6cfe7e3c..f75eb576a8 100644 --- a/src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs +++ b/src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs @@ -1,36 +1,65 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Discord; /// /// Represents public flags for an application. /// +[Flags] public enum ApplicationFlags { + /// + /// Indicates if an app uses the Auto Moderation API. + /// UsesAutoModApi = 1 << 6, + /// + /// Indicates that the app has been verified to use GUILD_PRESENCES intent. + /// GatewayPresence = 1 << 12, + /// + /// Indicates that the app has enabled the GUILD_PRESENCES intent on a bot in less than 100 servers. + /// GatewayPresenceLimited = 1 << 13, + /// + /// Indicates that the app has been verified to use GUILD_MEMBERS intent. + /// GatewayGuildMembers = 1 << 14, + /// + /// Indicates that the app has enabled the GUILD_MEMBERS intent on a bot in less than 100 servers. + /// GatewayGuildMembersLimited = 1 << 15, + /// + /// Indicates unusual growth of an app that prevents verification. + /// VerificationPendingGuildLimit = 1 << 16, + /// + /// Indicates if an app is embedded within the Discord client. + /// Embedded = 1 << 17, + /// + /// Indicates that the app has been verified to use MESSAGE_CONTENT intent. + /// GatewayMessageContent = 1 << 18, + /// + /// Indicates that the app has enabled the MESSAGE_CONTENT intent on a bot in less than 100 servers. + /// GatewayMessageContentLimited = 1 << 19, + /// + /// Indicates if an app has registered global application commands. + /// ApplicationCommandBadge = 1 << 23, + /// + /// Indicates if an app is considered active. + /// ActiveApplication = 1 << 24 } - diff --git a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs index 180592f1ec..2d24a6695b 100644 --- a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs +++ b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs @@ -1,31 +1,26 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Discord +namespace Discord; + +/// +/// Represents install parameters for an application. +/// +public class ApplicationInstallParams { /// - /// Represents install parameters for an application. + /// Gets the scopes to install this application. /// - public class ApplicationInstallParams - { - /// - /// Gets the scopes to install this application. - /// - public IReadOnlyCollection Scopes { get; } + public IReadOnlyCollection Scopes { get; } - /// - /// Gets the default permissions to install this application - /// - public GuildPermission? Permission { get; } + /// + /// Gets the default permissions to install this application + /// + public GuildPermission Permission { get; } - internal ApplicationInstallParams(string[] scopes, GuildPermission? permission) - { - Scopes = scopes.ToImmutableArray(); - Permission = permission; - } + public ApplicationInstallParams(string[] scopes, GuildPermission permission) + { + Scopes = scopes.ToImmutableArray(); + Permission = permission; } } diff --git a/src/Discord.Net.Core/Entities/Applications/IApplication.cs b/src/Discord.Net.Core/Entities/Applications/IApplication.cs index 1c126da5b1..f45eabca93 100644 --- a/src/Discord.Net.Core/Entities/Applications/IApplication.cs +++ b/src/Discord.Net.Core/Entities/Applications/IApplication.cs @@ -24,7 +24,7 @@ public interface IApplication : ISnowflakeEntity /// ApplicationFlags Flags { get; } /// - /// Gets a collection of install parameters for this application. + /// Gets a collection of install parameters for this application. if disabled. /// ApplicationInstallParams? InstallParams { get; } /// diff --git a/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs b/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs index be6fdef057..391ea3a3c6 100644 --- a/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs +++ b/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs @@ -29,4 +29,28 @@ public class ModifyApplicationProperties /// Gets or sets the icon of the application. /// public Optional Icon { get; set; } + + /// + /// Gets or sets the default rich presence invite cover image of the application. + /// + public Optional CoverImage { get; set; } + + /// + /// Gets or set the default custom authorization URL for the app, if enabled. + /// + public Optional CustomInstallUrl { get; set; } + + /// + /// Gets or sets settings for the app's default in-app authorization link, if enabled. + /// + public Optional InstallParams { get; set; } + + /// + /// Gets or sets app's public flags. + /// + /// + /// Only , and + /// flags can be updated. + /// + public Optional Flags { get; set; } } diff --git a/src/Discord.Net.Rest/API/Common/InstallParams.cs b/src/Discord.Net.Rest/API/Common/InstallParams.cs index 7e9877b2a4..29de4bdda2 100644 --- a/src/Discord.Net.Rest/API/Common/InstallParams.cs +++ b/src/Discord.Net.Rest/API/Common/InstallParams.cs @@ -1,18 +1,13 @@ using System.Text.Json; using System.Text.Json.Serialization; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Discord.API +namespace Discord.API; + +internal class InstallParams { - internal class InstallParams - { - [JsonPropertyName("scopes")] - public string[] Scopes { get; set; } = Array.Empty(); - [JsonPropertyName("permissions")] - public ulong Permission { get; set; } - } + [JsonPropertyName("scopes")] + public string[] Scopes { get; set; } = Array.Empty(); + [JsonPropertyName("permissions")] + public ulong Permission { get; set; } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs index 6865edc202..82934708b8 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs @@ -1,22 +1,33 @@ -using System.Text.Json; using System.Text.Json.Serialization; namespace Discord.API.Rest; internal class ModifyCurrentApplicationBotParams { - [JsonPropertyName("interactions_endpoint_url")] - public Optional InteractionsEndpointUrl { get; set; } + [JsonPropertyName("custom_install_url")] + public Optional CustomInstallUrl { get; set; } + + [JsonPropertyName("description")] + public Optional Description { get; set; } [JsonPropertyName("role_connections_verification_url")] public Optional RoleConnectionsEndpointUrl { get; set; } - [JsonPropertyName("description")] - public Optional Description { get; set; } + [JsonPropertyName("install_params")] + public Optional InstallParams { get; set; } - [JsonPropertyName("tags")] - public Optional Tags { get; set; } + [JsonPropertyName("flags")] + public Optional Flags { get; set; } [JsonPropertyName("icon")] public Optional Icon { get; set; } + + [JsonPropertyName("cover_image")] + public Optional CoverImage { get; set; } + + [JsonPropertyName("interactions_endpoint_url")] + public Optional InteractionsEndpointUrl { get; set; } + + [JsonPropertyName("tags")] + public Optional Tags { get; set; } } diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 8c8fe2ceee..db5b38b991 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -1,3 +1,4 @@ +using Discord.API; using Discord.API.Rest; using System; using System.Collections.Generic; @@ -28,9 +29,12 @@ public static async Task GetCurrentBotApplicationAsync(BaseDisc var args = new ModifyApplicationProperties(); func(args); - if(args.Tags.IsSpecified) + if (args.Tags.IsSpecified) + { + Preconditions.AtMost(args.Tags.Value.Length, DiscordConfig.MaxApplicationTagCount, nameof(args.Tags), $"An application can have a maximum of {DiscordConfig.MaxApplicationTagCount} applied."); foreach (var tag in args.Tags.Value) Preconditions.AtMost(tag.Length, DiscordConfig.MaxApplicationTagLength, nameof(args.Tags), $"An application tag must have length less or equal to {DiscordConfig.MaxApplicationTagLength}"); + } if(args.Description.IsSpecified) Preconditions.AtMost(args.Description.Value.Length, DiscordConfig.MaxApplicationDescriptionLength, nameof(args.Description), $"An application description tag mus have length less or equal to {DiscordConfig.MaxApplicationDescriptionLength}"); @@ -42,6 +46,14 @@ public static async Task GetCurrentBotApplicationAsync(BaseDisc Icon = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional.Unspecified, InteractionsEndpointUrl = args.InteractionsEndpointUrl, RoleConnectionsEndpointUrl = args.RoleConnectionsEndpointUrl, + Flags = args.Flags, + CoverImage = args.CoverImage.IsSpecified ? args.CoverImage.Value?.ToModel() : Optional.Unspecified, + CustomInstallUrl = args.CustomInstallUrl, + InstallParams = args.InstallParams.Map(a => new InstallParams + { + Permission = (ulong)args.InstallParams.Value.Permission, + Scopes = args.InstallParams.Value.Scopes.ToArray() + }) }, options); } diff --git a/src/Discord.Net.Rest/Entities/RestApplication.cs b/src/Discord.Net.Rest/Entities/RestApplication.cs index 0e215019d8..bff9b56579 100644 --- a/src/Discord.Net.Rest/Entities/RestApplication.cs +++ b/src/Discord.Net.Rest/Entities/RestApplication.cs @@ -61,8 +61,10 @@ public class RestApplication : RestEntity, IApplication /// public string? InteractionsEndpointUrl { get; private set; } + /// public ApplicationInstallParams? InstallParams { get; private set; } + /// public IReadOnlyCollection Tags { get; private set; } internal RestApplication(BaseDiscordClient discord, ulong id) @@ -92,8 +94,10 @@ internal void Update(Model model) Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray.Empty; PrivacyPolicy = model.PrivacyPolicy; TermsOfService = model.TermsOfService; - var installParams = model.InstallParams.GetValueOrDefault(null); - InstallParams = new ApplicationInstallParams(installParams?.Scopes ?? Array.Empty(), (GuildPermission?)installParams?.Permission); + + InstallParams = model.InstallParams + .Map(p => new ApplicationInstallParams(p.Scopes, (GuildPermission)p.Permission)) + .GetValueOrDefault(null); if (model.Flags.IsSpecified) Flags = model.Flags.Value; From f32762b20d60a067e9766dae1268676ab7bf2bcf Mon Sep 17 00:00:00 2001 From: Panthr75 Date: Wed, 19 Jul 2023 18:19:25 -0500 Subject: [PATCH 2/4] bump --- .../Entities/Applications/ApplicationInstallParams.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs index 2d24a6695b..17f215438e 100644 --- a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs +++ b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Collections.Generic; using System.Collections.Immutable; @@ -20,7 +21,10 @@ public class ApplicationInstallParams public ApplicationInstallParams(string[] scopes, GuildPermission permission) { - Scopes = scopes.ToImmutableArray(); + Preconditions.NotNull(scopes, nameof(scopes)); + Scopes = scopes + .Where(scope => !string.IsNullOrEmpty(scope)) + .ToImmutableArray(); Permission = permission; } } From 31e612b7da119f7f9b2a3a3e03f27a5894bc9ba9 Mon Sep 17 00:00:00 2001 From: Panthr75 Date: Sun, 10 Sep 2023 19:58:00 -0500 Subject: [PATCH 3/4] Update src/Discord.Net.Core/Entities/Applications/IApplication.cs --- src/Discord.Net.Core/Entities/Applications/IApplication.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Applications/IApplication.cs b/src/Discord.Net.Core/Entities/Applications/IApplication.cs index f45eabca93..7e738a0fff 100644 --- a/src/Discord.Net.Core/Entities/Applications/IApplication.cs +++ b/src/Discord.Net.Core/Entities/Applications/IApplication.cs @@ -24,7 +24,7 @@ public interface IApplication : ISnowflakeEntity /// ApplicationFlags Flags { get; } /// - /// Gets a collection of install parameters for this application. if disabled. + /// Gets a collection of install parameters for this application; if disabled. /// ApplicationInstallParams? InstallParams { get; } /// From cdf60cfbbeea91097a0945fd728a8be52a182b0c Mon Sep 17 00:00:00 2001 From: Panthr75 Date: Sun, 10 Sep 2023 19:59:17 -0500 Subject: [PATCH 4/4] check for null values inside the array --- .../Entities/Applications/ApplicationInstallParams.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs index 17f215438e..21de55b07e 100644 --- a/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs +++ b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs @@ -22,9 +22,11 @@ public class ApplicationInstallParams public ApplicationInstallParams(string[] scopes, GuildPermission permission) { Preconditions.NotNull(scopes, nameof(scopes)); - Scopes = scopes - .Where(scope => !string.IsNullOrEmpty(scope)) - .ToImmutableArray(); + foreach (var scope in scopes) + { + Preconditions.NotNullOrEmpty(scope, nameof(scope)); + } + Scopes = scopes.ToImmutableArray(); Permission = permission; } }