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

@ -32,7 +32,8 @@ public class MetaCommands(
ContextInjectionService contextInjection,
GuildCache guildCache,
ChannelCache channelCache,
IDiscordRestChannelAPI channelApi) : CommandGroup
IDiscordRestChannelAPI channelApi
) : CommandGroup
{
private readonly ILogger _logger = logger.ForContext<MetaCommands>();
private readonly HttpClient _client = new();
@ -41,12 +42,14 @@ public class MetaCommands(
[Description("Ping pong! See the bot's latency")]
public async Task<IResult> PingAsync()
{
var shardId = contextInjection.Context?.TryGetGuildID(out var guildId) == true
? client.ShardIdFor(guildId.Value)
: 0;
var shardId =
contextInjection.Context?.TryGetGuildID(out var guildId) == true
? client.ShardIdFor(guildId.Value)
: 0;
var averageLatency = client.Shards.Values.Select(x => x.Latency.TotalMilliseconds).Sum() /
client.Shards.Count;
var averageLatency =
client.Shards.Values.Select(x => x.Latency.TotalMilliseconds).Sum()
/ client.Shards.Count;
var t1 = clock.GetCurrentInstant();
var msg = await feedbackService.SendContextualAsync("...").GetOrThrow();
@ -57,42 +60,54 @@ public class MetaCommands(
var embed = new EmbedBuilder()
.WithColour(DiscordUtils.Purple)
.WithFooter($"{RuntimeInformation.FrameworkDescription} on {RuntimeInformation.RuntimeIdentifier}")
.WithFooter(
$"{RuntimeInformation.FrameworkDescription} on {RuntimeInformation.RuntimeIdentifier}"
)
.WithCurrentTimestamp();
embed.AddField("Ping",
$"Gateway: {client.Shards[shardId].Latency.TotalMilliseconds:N0}ms (average: {averageLatency:N0}ms)\n" +
$"API: {elapsed.TotalMilliseconds:N0}ms",
inline: true);
embed.AddField(
"Ping",
$"Gateway: {client.Shards[shardId].Latency.TotalMilliseconds:N0}ms (average: {averageLatency:N0}ms)\n"
+ $"API: {elapsed.TotalMilliseconds:N0}ms",
inline: true
);
embed.AddField("Memory usage", memoryUsage.Bytes().Humanize(), inline: true);
var messageRate = await MessagesRate();
embed.AddField("Messages received",
embed.AddField(
"Messages received",
messageRate != null
? $"{messageRate / 5:F1}/m\n({CataloggerMetrics.MessagesReceived.Value:N0} since last restart)"
: $"{CataloggerMetrics.MessagesReceived.Value:N0} since last restart",
true);
true
);
embed.AddField("Shard", $"{shardId + 1} of {client.Shards.Count}", true);
embed.AddField("Uptime",
$"{(CataloggerMetrics.Startup - clock.GetCurrentInstant()).Prettify(TimeUnit.Second)}\n" +
$"since <t:{CataloggerMetrics.Startup.ToUnixTimeSeconds()}:F>",
true);
embed.AddField(
"Uptime",
$"{(CataloggerMetrics.Startup - clock.GetCurrentInstant()).Prettify(TimeUnit.Second)}\n"
+ $"since <t:{CataloggerMetrics.Startup.ToUnixTimeSeconds()}:F>",
true
);
embed.AddField("Numbers",
$"{CataloggerMetrics.MessagesStored.Value:N0} messages " +
$"from {guildCache.Size:N0} servers\nCached {channelCache.Size:N0} channels",
false);
embed.AddField(
"Numbers",
$"{CataloggerMetrics.MessagesStored.Value:N0} messages "
+ $"from {guildCache.Size:N0} servers\nCached {channelCache.Size:N0} channels",
false
);
IEmbed[] embeds = [embed.Build().GetOrThrow()];
return (Result)await channelApi.EditMessageAsync(msg.ChannelID, msg.ID, content: "", embeds: embeds);
return (Result)
await channelApi.EditMessageAsync(msg.ChannelID, msg.ID, content: "", embeds: embeds);
}
// TODO: add more checks around response format, configurable prometheus endpoint
private async Task<double?> MessagesRate()
{
if (!config.Logging.EnableMetrics) return null;
if (!config.Logging.EnableMetrics)
return null;
try
{
@ -118,4 +133,4 @@ public class MetaCommands(
private record PrometheusResult(object[] value);
// ReSharper restore InconsistentNaming, ClassNeverInstantiated.Local
}
}