Add -all flag on system and group cards (#216)
* Show group count on stats card * Add -all flag on system and group cards Shows full count, including private members. * fix stuff broken by merging conflicts
This commit is contained in:
parent
5ba89d32fc
commit
42b70cde9a
@ -284,7 +284,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
var system = await GetGroupSystem(ctx, target, conn);
|
var system = await GetGroupSystem(ctx, target, conn);
|
||||||
var pctx = ctx.LookupContextFor(system);
|
var pctx = ctx.LookupContextFor(system);
|
||||||
var memberCount = await _repo.GetGroupMemberCount(conn, target.Id, PrivacyLevel.Public);
|
var memberCount = ctx.MatchPrivateFlag(pctx) ? await _repo.GetGroupMemberCount(conn, target.Id, PrivacyLevel.Public) : await _repo.GetGroupMemberCount(conn, target.Id);
|
||||||
|
|
||||||
var nameField = target.Name;
|
var nameField = target.Name;
|
||||||
if (system.Name != null)
|
if (system.Name != null)
|
||||||
|
@ -65,6 +65,7 @@ namespace PluralKit.Bot {
|
|||||||
|
|
||||||
var totalSystems = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.SystemCount.Name)?.Value ?? 0;
|
var totalSystems = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.SystemCount.Name)?.Value ?? 0;
|
||||||
var totalMembers = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.MemberCount.Name)?.Value ?? 0;
|
var totalMembers = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.MemberCount.Name)?.Value ?? 0;
|
||||||
|
var totalGroups = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.GroupCount.Name)?.Value ?? 0;
|
||||||
var totalSwitches = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.SwitchCount.Name)?.Value ?? 0;
|
var totalSwitches = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.SwitchCount.Name)?.Value ?? 0;
|
||||||
var totalMessages = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.MessageCount.Name)?.Value ?? 0;
|
var totalMessages = _metrics.Snapshot.GetForContext("Application").Gauges.FirstOrDefault(m => m.MultidimensionalName == CoreMetrics.MessageCount.Name)?.Value ?? 0;
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ namespace PluralKit.Bot {
|
|||||||
.AddField("CPU usage", $"{_cpu.LastCpuMeasure:P1}", true)
|
.AddField("CPU usage", $"{_cpu.LastCpuMeasure:P1}", true)
|
||||||
.AddField("Memory usage", $"{memoryUsage / 1024 / 1024} MiB", true)
|
.AddField("Memory usage", $"{memoryUsage / 1024 / 1024} MiB", true)
|
||||||
.AddField("Latency", $"API: {apiLatency.TotalMilliseconds:F0} ms, shard: {shardInfo.ShardLatency.Milliseconds} ms", true)
|
.AddField("Latency", $"API: {apiLatency.TotalMilliseconds:F0} ms, shard: {shardInfo.ShardLatency.Milliseconds} ms", true)
|
||||||
.AddField("Total numbers", $"{totalSystems:N0} systems, {totalMembers:N0} members, {totalSwitches:N0} switches, {totalMessages:N0} messages");
|
.AddField("Total numbers", $"{totalSystems:N0} systems, {totalMembers:N0} members, {totalGroups:N0} groups, {totalSwitches:N0} switches, {totalMessages:N0} messages");
|
||||||
await msg.ModifyAsync("", embed.Build());
|
await msg.ModifyAsync("", embed.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,5 +44,14 @@ namespace PluralKit.Bot
|
|||||||
ctx.PopArgument();
|
ctx.PopArgument();
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool MatchPrivateFlag(this Context ctx, LookupContext pctx)
|
||||||
|
{
|
||||||
|
var privacy = true;
|
||||||
|
if (ctx.MatchFlag("a", "all")) privacy = false;
|
||||||
|
if (pctx == LookupContext.ByNonOwner && !privacy) throw Errors.LookupNotAllowed;
|
||||||
|
|
||||||
|
return privacy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,7 +20,7 @@ namespace PluralKit.Bot
|
|||||||
public async Task Query(Context ctx, PKSystem system) {
|
public async Task Query(Context ctx, PKSystem system) {
|
||||||
if (system == null) throw Errors.NoSystemError;
|
if (system == null) throw Errors.NoSystemError;
|
||||||
|
|
||||||
await ctx.Reply(embed: await _embeds.CreateSystemEmbed(ctx.Shard, system, ctx.LookupContextFor(system)));
|
await ctx.Reply(embed: await _embeds.CreateSystemEmbed(ctx, system, ctx.LookupContextFor(system)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task New(Context ctx)
|
public async Task New(Context ctx)
|
||||||
|
@ -26,15 +26,16 @@ namespace PluralKit.Bot {
|
|||||||
_repo = repo;
|
_repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DiscordEmbed> CreateSystemEmbed(DiscordClient client, PKSystem system, LookupContext ctx)
|
public async Task<DiscordEmbed> CreateSystemEmbed(Context cctx, PKSystem system, LookupContext ctx)
|
||||||
{
|
{
|
||||||
await using var conn = await _db.Obtain();
|
await using var conn = await _db.Obtain();
|
||||||
|
|
||||||
// Fetch/render info for all accounts simultaneously
|
// Fetch/render info for all accounts simultaneously
|
||||||
var accounts = await _repo.GetSystemAccounts(conn, system.Id);
|
var accounts = await _repo.GetSystemAccounts(conn, system.Id);
|
||||||
var users = await Task.WhenAll(accounts.Select(async uid => (await client.GetUser(uid))?.NameAndMention() ?? $"(deleted account {uid})"));
|
var users = await Task.WhenAll(accounts.Select(async uid => (await cctx.Shard.GetUser(uid))?.NameAndMention() ?? $"(deleted account {uid})"));
|
||||||
|
|
||||||
|
var memberCount = cctx.MatchPrivateFlag(ctx) ? await _repo.GetSystemMemberCount(conn, system.Id, PrivacyLevel.Public) : await _repo.GetSystemMemberCount(conn, system.Id);
|
||||||
|
|
||||||
var memberCount = await _repo.GetSystemMemberCount(conn, system.Id, PrivacyLevel.Public);
|
|
||||||
var eb = new DiscordEmbedBuilder()
|
var eb = new DiscordEmbedBuilder()
|
||||||
.WithColor(DiscordUtils.Gray)
|
.WithColor(DiscordUtils.Gray)
|
||||||
.WithTitle(system.Name ?? null)
|
.WithTitle(system.Name ?? null)
|
||||||
@ -244,4 +245,4 @@ namespace PluralKit.Bot {
|
|||||||
return Task.FromResult(eb.Build());
|
return Task.FromResult(eb.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user