Skip to content

Commit 166d40f

Browse files
Misha-133quinchs
andauthored
[Feature] New ModifyCurrentApplication features (#2730)
* initial commit * apply suggestings lol * Update src/Discord.Net.Core/Entities/Applications/IApplication.cs Co-authored-by: Quin Lynch <[email protected]> * check for null values inside the array --------- Co-authored-by: Quin Lynch <[email protected]>
1 parent 59094d2 commit 166d40f

File tree

9 files changed

+136
-44
lines changed

9 files changed

+136
-44
lines changed

src/Discord.Net.Core/DiscordConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,10 @@ public class DiscordConfig
232232
/// Returns the max length of an application description.
233233
/// </summary>
234234
public const int MaxApplicationDescriptionLength = 400;
235+
236+
/// <summary>
237+
/// Returns the max amount of tags applied to an application.
238+
/// </summary>
239+
public const int MaxApplicationTagCount = 5;
235240
}
236241
}

src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,62 @@ namespace Discord;
99
/// <summary>
1010
/// Represents public flags for an application.
1111
/// </summary>
12+
[Flags]
1213
public enum ApplicationFlags
1314
{
15+
/// <summary>
16+
/// Indicates if an app uses the Auto Moderation API.
17+
/// </summary>
1418
UsesAutoModApi = 1 << 6,
1519

20+
/// <summary>
21+
/// Indicates that the app has been verified to use GUILD_PRESENCES intent.
22+
/// </summary>
1623
GatewayPresence = 1 << 12,
1724

25+
/// <summary>
26+
/// Indicates that the app has enabled the GUILD_PRESENCES intent on a bot in less than 100 servers.
27+
/// </summary>
1828
GatewayPresenceLimited = 1 << 13,
1929

30+
/// <summary>
31+
/// Indicates that the app has been verified to use GUILD_MEMBERS intent.
32+
/// </summary>
2033
GatewayGuildMembers = 1 << 14,
2134

35+
/// <summary>
36+
/// Indicates that the app has enabled the GUILD_MEMBERS intent on a bot in less than 100 servers.
37+
/// </summary>
2238
GatewayGuildMembersLimited = 1 << 15,
2339

40+
/// <summary>
41+
/// Indicates unusual growth of an app that prevents verification.
42+
/// </summary>
2443
VerificationPendingGuildLimit = 1 << 16,
2544

45+
/// <summary>
46+
/// Indicates if an app is embedded within the Discord client.
47+
/// </summary>
2648
Embedded = 1 << 17,
2749

50+
/// <summary>
51+
/// Indicates that the app has been verified to use MESSAGE_CONTENT intent.
52+
/// </summary>
2853
GatewayMessageContent = 1 << 18,
2954

55+
/// <summary>
56+
/// Indicates that the app has enabled the MESSAGE_CONTENT intent on a bot in less than 100 servers.
57+
/// </summary>
3058
GatewayMessageContentLimited = 1 << 19,
3159

60+
/// <summary>
61+
/// Indicates if an app has registered global application commands.
62+
/// </summary>
3263
ApplicationCommandBadge = 1 << 23,
3364

65+
/// <summary>
66+
/// Indicates if an app is considered active.
67+
/// </summary>
3468
ActiveApplication = 1 << 24
3569
}
3670

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Collections.Immutable;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73

8-
namespace Discord
4+
namespace Discord;
5+
6+
/// <summary>
7+
/// Represents install parameters for an application.
8+
/// </summary>
9+
public class ApplicationInstallParams
910
{
1011
/// <summary>
11-
/// Represents install parameters for an application.
12+
/// Gets the scopes to install this application.
1213
/// </summary>
13-
public class ApplicationInstallParams
14+
public IReadOnlyCollection<string> Scopes { get; }
15+
16+
/// <summary>
17+
/// Gets the default permissions to install this application.
18+
/// </summary>
19+
public GuildPermission Permission { get; }
20+
21+
public ApplicationInstallParams(string[] scopes, GuildPermission permission)
1422
{
15-
/// <summary>
16-
/// Gets the scopes to install this application.
17-
/// </summary>
18-
public IReadOnlyCollection<string> Scopes { get; }
23+
Preconditions.NotNull(scopes, nameof(scopes));
1924

20-
/// <summary>
21-
/// Gets the default permissions to install this application
22-
/// </summary>
23-
public GuildPermission? Permission { get; }
25+
foreach (var s in scopes)
26+
Preconditions.NotNull(s, nameof(scopes));
2427

25-
internal ApplicationInstallParams(string[] scopes, GuildPermission? permission)
26-
{
27-
Scopes = scopes.ToImmutableArray();
28-
Permission = permission;
29-
}
28+
Scopes = scopes.ToImmutableArray();
29+
Permission = permission;
3030
}
3131
}

src/Discord.Net.Core/Entities/Applications/IApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface IApplication : ISnowflakeEntity
2424
/// </summary>
2525
ApplicationFlags Flags { get; }
2626
/// <summary>
27-
/// Gets a collection of install parameters for this application.
27+
/// Gets a collection of install parameters for this application; <see langword="null"/> if disabled.
2828
/// </summary>
2929
ApplicationInstallParams InstallParams { get; }
3030
/// <summary>

src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@ public class ModifyApplicationProperties
2929
/// Gets or sets the icon of the application.
3030
/// </summary>
3131
public Optional<Image?> Icon { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets the default rich presence invite cover image of the application.
35+
/// </summary>
36+
public Optional<Image?> CoverImage { get; set; }
37+
38+
/// <summary>
39+
/// Gets or set the default custom authorization URL for the app, if enabled.
40+
/// </summary>
41+
public Optional<string> CustomInstallUrl { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets settings for the app's default in-app authorization link, if enabled.
45+
/// </summary>
46+
public Optional<ApplicationInstallParams> InstallParams { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets app's public flags.
50+
/// </summary>
51+
/// <remarks>
52+
/// Only <see cref="ApplicationFlags.GatewayGuildMembersLimited"/>, <see cref="ApplicationFlags.GatewayMessageContentLimited"/> and
53+
/// <see cref="ApplicationFlags.GatewayPresenceLimited"/> flags can be updated.
54+
/// </remarks>
55+
public Optional<ApplicationFlags> Flags { get; set; }
56+
3257
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

8-
namespace Discord.API
3+
namespace Discord.API;
4+
5+
internal class InstallParams
96
{
10-
internal class InstallParams
11-
{
12-
[JsonProperty("scopes")]
13-
public string[] Scopes { get; set; }
14-
[JsonProperty("permissions")]
15-
public ulong Permission { get; set; }
16-
}
7+
[JsonProperty("scopes")]
8+
public string[] Scopes { get; set; }
9+
10+
[JsonProperty("permissions")]
11+
public ulong Permission { get; set; }
1712
}

src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@ namespace Discord.API.Rest;
44

55
internal class ModifyCurrentApplicationBotParams
66
{
7-
[JsonProperty("interactions_endpoint_url")]
8-
public Optional<string> InteractionsEndpointUrl { get; set; }
7+
[JsonProperty("custom_install_url")]
8+
public Optional<string> CustomInstallUrl { get; set; }
9+
10+
[JsonProperty("description")]
11+
public Optional<string> Description { get; set; }
912

1013
[JsonProperty("role_connections_verification_url")]
1114
public Optional<string> RoleConnectionsEndpointUrl { get; set; }
1215

13-
[JsonProperty("description")]
14-
public Optional<string> Description { get; set; }
16+
[JsonProperty("install_params")]
17+
public Optional<InstallParams> InstallParams { get; set; }
1518

16-
[JsonProperty("tags")]
17-
public Optional<string[]> Tags { get; set; }
19+
[JsonProperty("flags")]
20+
public Optional<ApplicationFlags> Flags { get; set; }
1821

1922
[JsonProperty("icon")]
2023
public Optional<Image?> Icon { get; set; }
24+
25+
[JsonProperty("cover_image")]
26+
public Optional<Image?> CoverImage { get; set; }
27+
28+
[JsonProperty("interactions_endpoint_url")]
29+
public Optional<string> InteractionsEndpointUrl { get; set; }
30+
31+
[JsonProperty("tags")]
32+
public Optional<string[]> Tags { get; set; }
2133
}

src/Discord.Net.Rest/ClientHelper.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using Discord.API;
12
using Discord.API.Rest;
3+
24
using System;
35
using System.Collections.Generic;
46
using System.Collections.Immutable;
@@ -28,11 +30,14 @@ public static async Task<RestApplication> GetCurrentBotApplicationAsync(BaseDisc
2830
var args = new ModifyApplicationProperties();
2931
func(args);
3032

31-
if(args.Tags.IsSpecified)
33+
if (args.Tags.IsSpecified)
34+
{
35+
Preconditions.AtMost(args.Tags.Value.Length, DiscordConfig.MaxApplicationTagCount, nameof(args.Tags), $"An application can have a maximum of {DiscordConfig.MaxApplicationTagCount} applied.");
3236
foreach (var tag in args.Tags.Value)
3337
Preconditions.AtMost(tag.Length, DiscordConfig.MaxApplicationTagLength, nameof(args.Tags), $"An application tag must have length less or equal to {DiscordConfig.MaxApplicationTagLength}");
38+
}
3439

35-
if(args.Description.IsSpecified)
40+
if (args.Description.IsSpecified)
3641
Preconditions.AtMost(args.Description.Value.Length, DiscordConfig.MaxApplicationDescriptionLength, nameof(args.Description), $"An application description tag mus have length less or equal to {DiscordConfig.MaxApplicationDescriptionLength}");
3742

3843
return await client.ApiClient.ModifyCurrentBotApplicationAsync(new()
@@ -42,6 +47,18 @@ public static async Task<RestApplication> GetCurrentBotApplicationAsync(BaseDisc
4247
Icon = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional<API.Image?>.Unspecified,
4348
InteractionsEndpointUrl = args.InteractionsEndpointUrl,
4449
RoleConnectionsEndpointUrl = args.RoleConnectionsEndpointUrl,
50+
Flags = args.Flags,
51+
CoverImage = args.CoverImage.IsSpecified ? args.CoverImage.Value?.ToModel() : Optional<API.Image?>.Unspecified,
52+
CustomInstallUrl = args.CustomInstallUrl,
53+
InstallParams = args.InstallParams.IsSpecified
54+
? args.InstallParams.Value is null
55+
? null
56+
: new InstallParams
57+
{
58+
Permission = (ulong)args.InstallParams.Value.Permission,
59+
Scopes = args.InstallParams.Value.Scopes.ToArray()
60+
}
61+
: Optional<InstallParams>.Unspecified,
4562
}, options);
4663
}
4764

src/Discord.Net.Rest/Entities/RestApplication.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public class RestApplication : RestEntity<ulong>, IApplication
6161
/// <inheritdoc />
6262
public string InteractionsEndpointUrl { get; private set; }
6363

64+
/// <inheritdoc />
6465
public ApplicationInstallParams InstallParams { get; private set; }
6566

67+
/// <inheritdoc />
6668
public IReadOnlyCollection<string> Tags { get; private set; }
6769

6870
internal RestApplication(BaseDiscordClient discord, ulong id)
@@ -86,8 +88,10 @@ internal void Update(Model model)
8688
Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray<string>.Empty;
8789
PrivacyPolicy = model.PrivacyPolicy;
8890
TermsOfService = model.TermsOfService;
89-
var installParams = model.InstallParams.GetValueOrDefault(null);
90-
InstallParams = new ApplicationInstallParams(installParams?.Scopes ?? Array.Empty<string>(), (GuildPermission?)installParams?.Permission);
91+
92+
InstallParams = model.InstallParams.IsSpecified
93+
? new ApplicationInstallParams(model.InstallParams.Value.Scopes, (GuildPermission)model.InstallParams.Value.Permission)
94+
: null;
9195

9296
if (model.Flags.IsSpecified)
9397
Flags = model.Flags.Value;

0 commit comments

Comments
 (0)