chore: format with csharpier

This commit is contained in:
sam 2024-10-09 17:35:11 +02:00
parent 2f516dcb73
commit 4f54077c68
59 changed files with 2000 additions and 942 deletions

View file

@ -17,17 +17,25 @@ public class PluralkitApiService(ILogger logger)
private readonly ILogger _logger = logger.ForContext<PluralkitApiService>();
private readonly ResiliencePipeline _pipeline = new ResiliencePipelineBuilder()
.AddRateLimiter(new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions()
{
Window = 1.Seconds(),
PermitLimit = 2,
QueueLimit = 64,
}))
.AddRateLimiter(
new FixedWindowRateLimiter(
new FixedWindowRateLimiterOptions()
{
Window = 1.Seconds(),
PermitLimit = 2,
QueueLimit = 64,
}
)
)
.AddTimeout(20.Seconds())
.Build();
private async Task<T?> DoRequestAsync<T>(string path, bool allowNotFound = false,
CancellationToken ct = default) where T : class
private async Task<T?> DoRequestAsync<T>(
string path,
bool allowNotFound = false,
CancellationToken ct = default
)
where T : class
{
var req = new HttpRequestMessage(HttpMethod.Get, $"{ApiBaseUrl}{path}");
req.Headers.Add("User-Agent", UserAgent);
@ -43,27 +51,37 @@ public class PluralkitApiService(ILogger logger)
if (!resp.IsSuccessStatusCode)
{
_logger.Error("Received non-200 status code {StatusCode} from PluralKit API path {Path}", resp.StatusCode,
req);
_logger.Error(
"Received non-200 status code {StatusCode} from PluralKit API path {Path}",
resp.StatusCode,
req
);
throw new CataloggerError("Non-200 status code from PluralKit API");
}
var jsonOptions = new JsonSerializerOptions
{ PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }
.ConfigureForNodaTime(new NodaJsonSettings
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
}.ConfigureForNodaTime(
new NodaJsonSettings
{
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso)
});
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso),
}
);
return await resp.Content.ReadFromJsonAsync<T>(jsonOptions, ct) ??
throw new CataloggerError("JSON response from PluralKit API was null");
return await resp.Content.ReadFromJsonAsync<T>(jsonOptions, ct)
?? throw new CataloggerError("JSON response from PluralKit API was null");
}
public async Task<PkMessage?> GetPluralKitMessageAsync(ulong id, CancellationToken ct = default) =>
await DoRequestAsync<PkMessage>($"/messages/{id}", allowNotFound: true, ct);
public async Task<PkMessage?> GetPluralKitMessageAsync(
ulong id,
CancellationToken ct = default
) => await DoRequestAsync<PkMessage>($"/messages/{id}", allowNotFound: true, ct);
public async Task<PkSystem?> GetPluralKitSystemAsync(ulong id, CancellationToken ct = default) =>
await DoRequestAsync<PkSystem>($"/systems/{id}", allowNotFound: true, ct);
public async Task<PkSystem?> GetPluralKitSystemAsync(
ulong id,
CancellationToken ct = default
) => await DoRequestAsync<PkSystem>($"/systems/{id}", allowNotFound: true, ct);
public record PkMessage(
ulong Id,
@ -72,9 +90,10 @@ public class PluralkitApiService(ILogger logger)
ulong Channel,
ulong Guild,
PkSystem? System,
PkMember? Member);
PkMember? Member
);
public record PkSystem(string Id, Guid Uuid, string? Name, string? Tag, Instant? Created);
public record PkMember(string Id, Guid Uuid, string Name, string? DisplayName);
}
}