Skip to content

Commit

Permalink
feat!: modify current application
Browse files Browse the repository at this point in the history
This adds all possible editable fields. Breaking change.
  • Loading branch information
Lulalaby committed Jul 13, 2023
1 parent a08c6f3 commit 8fc36ca
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DisCatSharp.Interactivity/Helpers/InteractivityHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class InteractivityHelpers
public static List<Page> Recalculate(this List<Page> pages)
{
List<Page> recalulatedPages = new(pages.Count);
int pageCount = 1;
var pageCount = 1;
foreach (var page in pages)
{
var tempPage = new Page();
Expand Down
17 changes: 14 additions & 3 deletions DisCatSharp/Clients/BaseDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ public async Task<DiscordApplication> GetCurrentApplicationAsync()
TermsOfServiceUrl = tapp.TermsOfServiceUrl,
CustomInstallUrl = tapp.CustomInstallUrl,
InstallParams = tapp.InstallParams,
RoleConnectionsVerificationUrl = tapp.RoleConnectionsVerificationUrl,
RoleConnectionsVerificationUrl = tapp.RoleConnectionsVerificationUrl.ValueOrDefault(),
InteractionsEndpointUrl = tapp.InteractionsEndpointUrl.ValueOrDefault(),
CoverImageHash = tapp.CoverImageHash.ValueOrDefault(),
Tags = (tapp.Tags ?? Enumerable.Empty<string>()).ToArray()
};

Expand Down Expand Up @@ -385,16 +387,25 @@ public async Task<DiscordApplication> GetCurrentApplicationAsync()
/// <param name="description">The new description.</param>
/// <param name="interactionsEndpointUrl">The new interactions endpoint url.</param>
/// <param name="roleConnectionsVerificationUrl">The new role connections verification url.</param>
/// <param name="customInstallUrl">The new custom install url.</param>
/// <param name="tags">The new tags.</param>
/// <param name="icon">The new application icon.</param>
/// <param name="coverImage">The new application cover image.</param>
/// <param name="flags">The new application flags. Can be only limited gateway intents.</param>
/// <param name="installParams">The new install params.</param>
/// <returns>The updated application.</returns>
public async Task<DiscordApplication> UpdateCurrentApplicationInfoAsync(Optional<string> description, Optional<string> interactionsEndpointUrl, Optional<string> roleConnectionsVerificationUrl, Optional<List<string>?> tags, Optional<Stream> icon)
public async Task<DiscordApplication> UpdateCurrentApplicationInfoAsync(
Optional<string?> description,
Optional<string?> interactionsEndpointUrl, Optional<string?> roleConnectionsVerificationUrl, Optional<string?> customInstallUrl,
Optional<List<string>?> tags, Optional<Stream?> icon, Optional<Stream?> coverImage,
Optional<ApplicationFlags> flags, Optional<DiscordApplicationInstallParams?> installParams)
{
var iconb64 = ImageTool.Base64FromStream(icon);
var coverImageb64 = ImageTool.Base64FromStream(coverImage);
if (tags != null && tags.HasValue && tags.Value != null)
if (tags.Value.Any(x => x.Length > 20))
throw new InvalidOperationException("Tags can not exceed 20 chars.");
_ = await this.ApiClient.ModifyCurrentApplicationInfoAsync(description, interactionsEndpointUrl, roleConnectionsVerificationUrl, tags, iconb64);
_ = await this.ApiClient.ModifyCurrentApplicationInfoAsync(description, interactionsEndpointUrl, roleConnectionsVerificationUrl, customInstallUrl, tags, iconb64, coverImageb64, flags, installParams).ConfigureAwait(false);
// We use GetCurrentApplicationAsync because modify returns internal data not meant for developers.
var app = await this.GetCurrentApplicationAsync();
this.CurrentApplication = app;
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/Clients/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public async Task<DiscordApplication> GetCurrentApplicationInfoAsync()
TermsOfServiceUrl = tapp.TermsOfServiceUrl,
CustomInstallUrl = tapp.CustomInstallUrl,
InstallParams = tapp.InstallParams,
RoleConnectionsVerificationUrl = tapp.RoleConnectionsVerificationUrl,
RoleConnectionsVerificationUrl = tapp.RoleConnectionsVerificationUrl.ValueOrDefault(),
Tags = (tapp.Tags ?? Enumerable.Empty<string>()).ToArray(),
GuildId = tapp.GuildId.ValueOrDefault(),
Slug = tapp.Slug.ValueOrDefault(),
Expand Down
2 changes: 2 additions & 0 deletions DisCatSharp/Entities/Application/DiscordApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Globalization;
using System.Threading.Tasks;

using DisCatSharp.Attributes;
using DisCatSharp.Enums;
using DisCatSharp.Net;

Expand All @@ -40,6 +41,7 @@ public sealed class DiscordApplication : DiscordMessageApplication, IEquatable<D
/// <summary>
/// Gets the application's summary.
/// </summary>
[DiscordDeprecated("Empty string, will be removed in API v11")]
public string Summary { get; internal set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class DiscordApplicationInstallParams : ObservableApiObject
/// Gets the scopes.
/// </summary>
[JsonProperty("scopes", NullValueHandling = NullValueHandling.Ignore)]
public IReadOnlyList<string> Scopes { get; internal set; }
public List<string>? Scopes { get; internal set; }

/// <summary>
/// Gets or sets the permissions.
Expand All @@ -49,4 +49,10 @@ public sealed class DiscordApplicationInstallParams : ObservableApiObject
/// Initializes a new instance of the <see cref="DiscordApplicationInstallParams"/> class.
/// </summary>
internal DiscordApplicationInstallParams() { }

public DiscordApplicationInstallParams(List<string>? scopes = null, Permissions? permissions = null)
{
this.Scopes = scopes;
this.Permissions = permissions;
}
}
5 changes: 5 additions & 0 deletions DisCatSharp/Enums/Application/ApplicationFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace DisCatSharp.Enums;
[Flags]
public enum ApplicationFlags : long
{
/// <summary>
/// The application has no flags.
/// </summary>
None = 0,

/// <summary>
/// The application is embedded and can be used by users.
/// This was introduced to avoid users using in-dev apps.
Expand Down
43 changes: 34 additions & 9 deletions DisCatSharp/Net/Abstractions/Rest/RestApplicationPayloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Collections.Generic;

using DisCatSharp.Entities;
using DisCatSharp.Enums;

using Newtonsoft.Json;

Expand All @@ -33,30 +34,54 @@ internal sealed class RestApplicationModifyPayload : ObservableApiObject
/// <summary>
/// Gets or sets the description.
/// </summary>
[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)]
public Optional<string> Description { get; set; }
[JsonProperty("description", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> Description { get; set; }

/// <summary>
/// Gets or sets the interactions endpoint url.
/// </summary>
[JsonProperty("interactions_endpoint_url", NullValueHandling = NullValueHandling.Ignore)]
public Optional<string> InteractionsEndpointUrl { get; set; }
[JsonProperty("interactions_endpoint_url", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> InteractionsEndpointUrl { get; set; }

/// <summary>
/// Gets or sets the role connections verification url.
/// </summary>
[JsonProperty("role_connections_verification_url", NullValueHandling = NullValueHandling.Ignore)]
public Optional<string> RoleConnectionsVerificationUrl { get; set; }
[JsonProperty("role_connections_verification_url", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> RoleConnectionsVerificationUrl { get; set; }

/// <summary>
/// Gets or sets the custom install url.
/// </summary>
[JsonProperty("custom_install_url", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> CustomInstallUrl { get; set; }

/// <summary>
/// Gets or sets the tags.
/// </summary>
[JsonProperty("tags", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("tags", NullValueHandling = NullValueHandling.Include)]
public Optional<List<string>?> Tags { get; set; }

/// <summary>
/// Gets or sets the icon base64.
/// </summary>
[JsonProperty("icon")]
public Optional<string> IconBase64 { get; set; }
[JsonProperty("icon", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> IconBase64 { get; set; }

/// <summary>
/// Gets or sets the cover image base64.
/// </summary>
[JsonProperty("cover_image", NullValueHandling = NullValueHandling.Include)]
public Optional<string?> ConverImageBase64 { get; set; }

/// <summary>
/// Gets or sets the application flags.
/// </summary>
[JsonProperty("flags", NullValueHandling = NullValueHandling.Ignore)]
public Optional<ApplicationFlags> Flags { get; set; }

/// <summary>
/// Gets or sets the install params.
/// </summary>
[JsonProperty("install_params", NullValueHandling = NullValueHandling.Include)]
public Optional<DiscordApplicationInstallParams?> InstallParams { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System.Collections.Generic;

using DisCatSharp.Attributes;
using DisCatSharp.Entities;
using DisCatSharp.Enums;

Expand Down Expand Up @@ -61,7 +62,7 @@ internal sealed class TransportApplication : ObservableApiObject
/// <summary>
/// Gets or sets the summary.
/// </summary>
[JsonProperty("summary", NullValueHandling = NullValueHandling.Include)]
[JsonProperty("summary", NullValueHandling = NullValueHandling.Include), DiscordDeprecated("Empty string, will be removed in API v11")]
public string Summary { get; set; }

[JsonProperty("bot", NullValueHandling = NullValueHandling.Ignore)]
Expand Down Expand Up @@ -179,13 +180,13 @@ internal sealed class TransportApplication : ObservableApiObject
/// Gets or sets the role connection verification entry point.
/// </summary>
[JsonProperty("role_connections_verification_url")]
public string RoleConnectionsVerificationUrl { get; set; }
public Optional<string> RoleConnectionsVerificationUrl { get; set; }

/// <summary>
/// Gets or sets the tags.
/// </summary>
[JsonProperty("tags", NullValueHandling = NullValueHandling.Include)]
public List<string> Tags { get; set; }
public List<string>? Tags { get; set; }

[JsonProperty("approximate_guild_count", NullValueHandling = NullValueHandling.Ignore)]
public Optional<int> ApproximateGuildCount { get; set; }
Expand Down
15 changes: 12 additions & 3 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ internal async Task<DiscordMessage> CreateMessageAsync(ulong channelId, DiscordM
}
pld.Attachments = attachments;
}

var route = $"{Endpoints.CHANNELS}/:channel_id{Endpoints.MESSAGES}";
var bucket = this.Rest.GetBucket(RestRequestMethod.POST, route, new {channel_id = channelId }, out var path);

Expand Down Expand Up @@ -5690,15 +5690,24 @@ internal async Task<TransportApplication> GetCurrentApplicationInfoAsync()
/// <summary>
/// Gets the application info.
/// </summary>
internal async Task<TransportApplication> ModifyCurrentApplicationInfoAsync(Optional<string> description, Optional<string> interactionsEndpointUrl, Optional<string> roleConnectionsVerificationUrl, Optional<List<string>?> tags, Optional<string?> iconb64)
internal async Task<TransportApplication> ModifyCurrentApplicationInfoAsync(
Optional<string> description,
Optional<string> interactionsEndpointUrl, Optional<string> roleConnectionsVerificationUrl, Optional<string?> customInstallUrl,
Optional<List<string>?> tags, Optional<string?> iconb64, Optional<string?> coverImageb64,
Optional<ApplicationFlags> flags, Optional<DiscordApplicationInstallParams?> installParams)
{
var pld = new RestApplicationModifyPayload()
{
Description = description,
InteractionsEndpointUrl = interactionsEndpointUrl,
RoleConnectionsVerificationUrl = roleConnectionsVerificationUrl,
CustomInstallUrl = customInstallUrl,
Tags = tags,
IconBase64 = iconb64
IconBase64 = iconb64,
ConverImageBase64 = coverImageb64,
Flags = flags,
InstallParams = installParams

};

var route = $"{Endpoints.APPLICATIONS}{Endpoints.ME}";
Expand Down

0 comments on commit 8fc36ca

Please sign in to comment.