From 8a124c67ae096e37b40fddb8e7be2ec943857498 Mon Sep 17 00:00:00 2001 From: spiral Date: Tue, 15 Mar 2022 00:09:27 -0400 Subject: [PATCH] feat(api): expose Discord statistics on /private/meta --- PluralKit.API/APIJsonExt.cs | 6 +++++- PluralKit.API/Controllers/PrivateController.cs | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PluralKit.API/APIJsonExt.cs b/PluralKit.API/APIJsonExt.cs index a3d4f3db..91386bc3 100644 --- a/PluralKit.API/APIJsonExt.cs +++ b/PluralKit.API/APIJsonExt.cs @@ -9,7 +9,7 @@ namespace PluralKit.API; public static class APIJsonExt { - public static JObject ToJson(this ModelRepository.Counts counts) + public static JObject ToJson(this ModelRepository.Counts counts, int guildCount, int channelCount) { var o = new JObject(); @@ -19,6 +19,10 @@ public static class APIJsonExt o.Add("switch_count", counts.SwitchCount); o.Add("message_count", counts.MessageCount); + // Discord statistics + o.Add("guild_count", guildCount); + o.Add("channel_count", channelCount); + return o; } } diff --git a/PluralKit.API/Controllers/PrivateController.cs b/PluralKit.API/Controllers/PrivateController.cs index 3dba6531..4d19c3e5 100644 --- a/PluralKit.API/Controllers/PrivateController.cs +++ b/PluralKit.API/Controllers/PrivateController.cs @@ -30,11 +30,17 @@ public class PrivateController: PKControllerBase var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus"); var shards = redisInfo.Select(x => Proto.Unmarshal(x.Value)).OrderBy(x => x.ShardId); + var redisClusterInfo = await db.HashGetAllAsync("pluralkit:cluster_stats"); + var clusterInfo = redisClusterInfo.Select(x => JsonConvert.DeserializeObject(x.Value)); + + var guildCount = clusterInfo.Sum(x => x.GuildCount); + var channelCount = clusterInfo.Sum(x => x.ChannelCount); + var stats = await _repo.GetStats(); var o = new JObject(); o.Add("shards", shards.ToJson()); - o.Add("stats", stats.ToJson()); + o.Add("stats", stats.ToJson(guildCount, channelCount)); o.Add("version", BuildInfoService.FullVersion); return Ok(o);