feat: import/export settings, send backup of settings when leaving guild

This commit is contained in:
sam 2024-11-08 17:12:00 +01:00
parent e6d68338db
commit db5d7bb4f8
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
18 changed files with 392 additions and 39 deletions

View file

@ -14,13 +14,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.RateLimiting;
using Humanizer;
using NodaTime;
using NodaTime.Serialization.SystemTextJson;
using NodaTime.Text;
using Polly;
namespace Catalogger.Backend.Services;
@ -32,17 +28,6 @@ public class PluralkitApiService(ILogger logger)
private readonly HttpClient _client = new();
private readonly ILogger _logger = logger.ForContext<PluralkitApiService>();
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
}.ConfigureForNodaTime(
new NodaJsonSettings
{
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso),
}
);
private readonly ResiliencePipeline _pipeline = new ResiliencePipelineBuilder()
.AddRateLimiter(
new FixedWindowRateLimiter(
@ -86,7 +71,7 @@ public class PluralkitApiService(ILogger logger)
throw new CataloggerError("Non-200 status code from PluralKit API");
}
return await resp.Content.ReadFromJsonAsync<T>(_jsonOptions, ct)
return await resp.Content.ReadFromJsonAsync<T>(JsonUtils.ApiJsonOptions, ct)
?? throw new CataloggerError("JSON response from PluralKit API was null");
}