feat(api): expose Discord statistics on /private/meta
This commit is contained in:
		| @@ -9,7 +9,7 @@ namespace PluralKit.API; | |||||||
|  |  | ||||||
| public static class APIJsonExt | 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(); |         var o = new JObject(); | ||||||
|  |  | ||||||
| @@ -19,6 +19,10 @@ public static class APIJsonExt | |||||||
|         o.Add("switch_count", counts.SwitchCount); |         o.Add("switch_count", counts.SwitchCount); | ||||||
|         o.Add("message_count", counts.MessageCount); |         o.Add("message_count", counts.MessageCount); | ||||||
|  |  | ||||||
|  |         // Discord statistics | ||||||
|  |         o.Add("guild_count", guildCount); | ||||||
|  |         o.Add("channel_count", channelCount); | ||||||
|  |  | ||||||
|         return o; |         return o; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -30,11 +30,17 @@ public class PrivateController: PKControllerBase | |||||||
|         var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus"); |         var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus"); | ||||||
|         var shards = redisInfo.Select(x => Proto.Unmarshal<ShardState>(x.Value)).OrderBy(x => x.ShardId); |         var shards = redisInfo.Select(x => Proto.Unmarshal<ShardState>(x.Value)).OrderBy(x => x.ShardId); | ||||||
|  |  | ||||||
|  |         var redisClusterInfo = await db.HashGetAllAsync("pluralkit:cluster_stats"); | ||||||
|  |         var clusterInfo = redisClusterInfo.Select(x => JsonConvert.DeserializeObject<ClusterMetricInfo>(x.Value)); | ||||||
|  |  | ||||||
|  |         var guildCount = clusterInfo.Sum(x => x.GuildCount); | ||||||
|  |         var channelCount = clusterInfo.Sum(x => x.ChannelCount); | ||||||
|  |  | ||||||
|         var stats = await _repo.GetStats(); |         var stats = await _repo.GetStats(); | ||||||
|  |  | ||||||
|         var o = new JObject(); |         var o = new JObject(); | ||||||
|         o.Add("shards", shards.ToJson()); |         o.Add("shards", shards.ToJson()); | ||||||
|         o.Add("stats", stats.ToJson()); |         o.Add("stats", stats.ToJson(guildCount, channelCount)); | ||||||
|         o.Add("version", BuildInfoService.FullVersion); |         o.Add("version", BuildInfoService.FullVersion); | ||||||
|  |  | ||||||
|         return Ok(o); |         return Ok(o); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user