Skip to content

Commit

Permalink
feat: personality generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Nov 8, 2023
1 parent 4a72484 commit 80b3263
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
11 changes: 11 additions & 0 deletions DisCatSharp.Experimental/DisCatSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ public static async Task<ClydeSettings> ModifyClydeSettingsAsync(
? Optional.FromNullable<List<int>?>(null)
: Optional.None);
}

/// <summary>
/// Generates a basePersonality for clyde based on the given <paramref name="basePersonality"/>.
/// </summary>
/// <param name="client">The discord client.</param>
/// <param name="basePersonality">The base base personality to generate a new one from.</param>
public static async Task<string> GenerateClydePersonalityAsync(this DiscordClient client, string? basePersonality = null)
{
DiscordApiClientHook hook = new(client.ApiClient);
return await hook.GenerateClydePersonalityAsync(basePersonality);
}
}
24 changes: 23 additions & 1 deletion DisCatSharp.Experimental/DiscordApiClientHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal async Task<ClydeSettings> ModifyClydeSettingsAsync(ulong guildId, ulong
/// </summary>
/// <param name="guildId">The guild id to modify clyde's settings for.</param>
/// <param name="name">The new name.</param>
/// <param name="personality">The new personality.</param>
/// <param name="personality">The new basePersonality.</param>
/// <param name="avatarBase64">The new avatar.</param>
/// <param name="bannerBase64">The new banner.</param>
/// <param name="themeColors">The new theme colors.</param>
Expand Down Expand Up @@ -137,4 +137,26 @@ internal async Task<ClydeSettings> ModifyClydeSettingsAsync(
var settings = DiscordJson.DeserializeObject<ClydeSettings>(settingsString, this.ApiClient.Discord);
return settings;
}

/// <summary>
/// Generates a basePersonality for clyde based on the given <paramref name="basePersonality"/>.
/// </summary>
/// <param name="basePersonality">The base base personality to generate a new one from.</param>
internal async Task<string> 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<PersonalityGenerationPayload>(res.Response, this.ApiClient.Discord);
return generatedPersonality.Personality;
}
}
12 changes: 12 additions & 0 deletions DisCatSharp.Experimental/Payloads/ClydeSettingsPayloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ internal sealed class ClydeSettingsProfileUpdatePayload : ObservableApiObject
[JsonProperty("theme_colors", NullValueHandling = NullValueHandling.Include)]
internal Optional<List<int>?> ThemeColors { get; set; }
}

/// <summary>
/// Represents a personality generation payload.
/// </summary>
internal sealed class PersonalityGenerationPayload : ObservableApiObject
{
/// <summary>
/// Sets the base personality to generate a new one from.
/// </summary>
[JsonProperty("personality", NullValueHandling = NullValueHandling.Ignore)]
internal string Personality { get; set; } = string.Empty;
}
1 change: 1 addition & 0 deletions DisCatSharp/Net/Rest/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit 80b3263

Please sign in to comment.