Skip to content

Commit

Permalink
#336: Settings Command List
Browse files Browse the repository at this point in the history
Account for the fact that cached values is a dictionary of strings and JsonElements, 1.1.0 of Configuration should address this issue and it will be removed in a future release
  • Loading branch information
jf-06 committed Oct 9, 2024
1 parent 79ea416 commit 7289969
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Grid.Bot.Commands.Private;

using Utility;
using Extensions;
using System.Text.Json;


/// <summary>
/// Represents the interaction for settings.
Expand Down Expand Up @@ -137,7 +139,15 @@ public async Task GetAllAsync(string provider, bool refresh = true)

if (refresh) instance.Refresh();

using var stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(instance.GetRawValues(), Formatting.Indented)));
/* FIXME: This is stupid, update 1.1.0 on Configuration should convert these on each refresh instead of placing a JE dict in cache. */

var values = new Dictionary<string, string>();

foreach (var kvp in instance.GetRawValues())
if (kvp.Value is JsonElement element)
values.Add(kvp.Key, element.GetString());

using var stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(values, Formatting.Indented)));

await this.ReplyWithFileAsync(stream, $"{provider}.json", "Here are the settings for the specified provider.");
}
Expand Down

0 comments on commit 7289969

Please sign in to comment.