Show member count on group card

This commit is contained in:
Ske 2020-07-18 13:19:53 +02:00
parent 0d04be6540
commit ec9ee5c794
2 changed files with 19 additions and 1 deletions

View File

@ -31,7 +31,7 @@ namespace PluralKit.Bot
await using var conn = await _db.Obtain();
var newGroup = await conn.CreateGroup(ctx.System.Id, groupName);
await ctx.Reply($"{Emojis.Success} Group \"**{groupName}**\" (`{newGroup.Hid}`) registered!\nYou can now start adding members to the group:\n- **pk;group {newGroup.Hid} add <members...>**");
await ctx.Reply($"{Emojis.Success} Group \"**{groupName}**\" (`{newGroup.Hid}`) registered!\nYou can now start adding members to the group like this:\n> **pk;group `{newGroup.Hid}` add `member1` `member2...`**");
}
public async Task RenameGroup(Context ctx, PKGroup target)
@ -133,6 +133,7 @@ namespace PluralKit.Bot
await using var conn = await _db.Obtain();
var system = await GetGroupSystem(ctx, target, conn);
var memberCount = await conn.QueryGroupMemberCount(target.Id, PrivacyLevel.Public);
var nameField = target.Name;
if (system.Name != null)
@ -142,6 +143,11 @@ namespace PluralKit.Bot
.WithAuthor(nameField)
.WithFooter($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}");
if (memberCount == 0)
eb.AddField("Members (0)", $"Add one with `pk;group {target.Hid} add <member>`!", true);
else
eb.AddField($"Members ({memberCount})", $"(see `pk;group {target.Hid} list`)", true);
if (target.Description != null)
eb.AddField("Description", target.Description);

View File

@ -38,6 +38,18 @@ namespace PluralKit.Core
public static Task<IEnumerable<PKGroup>> QueryGroupsInSystem(this IPKConnection conn, SystemId system) =>
conn.QueryAsync<PKGroup>("select * from groups where system = @System", new {System = system});
public static Task<int> QueryGroupMemberCount(this IPKConnection conn, GroupId id,
PrivacyLevel? privacyFilter = null)
{
var query = new StringBuilder("select count(*) from group_members");
if (privacyFilter != null)
query.Append(" left join members on group_members.member_id = members.id");
query.Append(" where group_members.group_id = @Id");
if (privacyFilter != null)
query.Append(" and members.member_visibility = @PrivacyFilter");
return conn.QuerySingleOrDefaultAsync<int>(query.ToString(), new {Id = id, PrivacyFilter = privacyFilter});
}
public static Task<GuildConfig> QueryOrInsertGuildConfig(this IPKConnection conn, ulong guild) =>
conn.QueryFirstAsync<GuildConfig>("insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *", new {guild});