From 80b3263290ba6f45e98f83f2f7267d95570acbcb Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 9 Nov 2023 00:59:56 +0100 Subject: [PATCH] feat: personality generation --- .../DisCatSharpExtensions.cs | 11 +++++++++ .../DiscordApiClientHook.cs | 24 ++++++++++++++++++- .../Payloads/ClydeSettingsPayloads.cs | 12 ++++++++++ DisCatSharp/Net/Rest/Endpoints.cs | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/DisCatSharp.Experimental/DisCatSharpExtensions.cs b/DisCatSharp.Experimental/DisCatSharpExtensions.cs index bc1067dadc..6f42bd2dec 100644 --- a/DisCatSharp.Experimental/DisCatSharpExtensions.cs +++ b/DisCatSharp.Experimental/DisCatSharpExtensions.cs @@ -72,4 +72,15 @@ public static async Task ModifyClydeSettingsAsync( ? Optional.FromNullable?>(null) : Optional.None); } + + /// + /// Generates a basePersonality for clyde based on the given . + /// + /// The discord client. + /// The base base personality to generate a new one from. + public static async Task GenerateClydePersonalityAsync(this DiscordClient client, string? basePersonality = null) + { + DiscordApiClientHook hook = new(client.ApiClient); + return await hook.GenerateClydePersonalityAsync(basePersonality); + } } diff --git a/DisCatSharp.Experimental/DiscordApiClientHook.cs b/DisCatSharp.Experimental/DiscordApiClientHook.cs index 666a0c2af5..6d7964ba84 100644 --- a/DisCatSharp.Experimental/DiscordApiClientHook.cs +++ b/DisCatSharp.Experimental/DiscordApiClientHook.cs @@ -101,7 +101,7 @@ internal async Task ModifyClydeSettingsAsync(ulong guildId, ulong /// /// The guild id to modify clyde's settings for. /// The new name. - /// The new personality. + /// The new basePersonality. /// The new avatar. /// The new banner. /// The new theme colors. @@ -137,4 +137,26 @@ internal async Task ModifyClydeSettingsAsync( var settings = DiscordJson.DeserializeObject(settingsString, this.ApiClient.Discord); return settings; } + + /// + /// Generates a basePersonality for clyde based on the given . + /// + /// The base base personality to generate a new one from. + internal async Task GenerateClydePersonalityAsync(string? basePersonality = null) + { + PersonalityGenerationPayload pld = new() + { + Personality = basePersonality ?? string.Empty + }; + + var route = $"{Endpoints.CLYDE_PROFILES}{Endpoints.GENERATE_PERSONALITY}"; + var bucket = this.ApiClient.Rest.GetBucket(RestRequestMethod.POST, route, new + { }, out var path); + + var url = Utilities.GetApiUriFor(path, this.ApiClient.Discord.Configuration); + var res = await this.ApiClient.DoRequestAsync(this.ApiClient.Discord, bucket, url, RestRequestMethod.POST, route, payload: DiscordJson.SerializeObject(pld)).ConfigureAwait(false); + + var generatedPersonality = DiscordJson.DeserializeObject(res.Response, this.ApiClient.Discord); + return generatedPersonality.Personality; + } } diff --git a/DisCatSharp.Experimental/Payloads/ClydeSettingsPayloads.cs b/DisCatSharp.Experimental/Payloads/ClydeSettingsPayloads.cs index 75c6bff856..29cda0cfa4 100644 --- a/DisCatSharp.Experimental/Payloads/ClydeSettingsPayloads.cs +++ b/DisCatSharp.Experimental/Payloads/ClydeSettingsPayloads.cs @@ -69,3 +69,15 @@ internal sealed class ClydeSettingsProfileUpdatePayload : ObservableApiObject [JsonProperty("theme_colors", NullValueHandling = NullValueHandling.Include)] internal Optional?> ThemeColors { get; set; } } + +/// +/// Represents a personality generation payload. +/// +internal sealed class PersonalityGenerationPayload : ObservableApiObject +{ + /// + /// Sets the base personality to generate a new one from. + /// + [JsonProperty("personality", NullValueHandling = NullValueHandling.Ignore)] + internal string Personality { get; set; } = string.Empty; +} diff --git a/DisCatSharp/Net/Rest/Endpoints.cs b/DisCatSharp/Net/Rest/Endpoints.cs index cfa3c96e5d..1c9d548337 100644 --- a/DisCatSharp/Net/Rest/Endpoints.cs +++ b/DisCatSharp/Net/Rest/Endpoints.cs @@ -555,4 +555,5 @@ public static class Endpoints public const string INVENTORY = "/inventory"; public const string CLYDE_SETTINGS = "/clyde-settings"; public const string CLYDE_PROFILES = "/clyde-profiles"; + public const string GENERATE_PERSONALITY = "/generate-personality"; }