diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 9c3e75a4..2580eb3f 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -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 **"); + 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 `!", true); + else + eb.AddField($"Members ({memberCount})", $"(see `pk;group {target.Hid} list`)", true); + if (target.Description != null) eb.AddField("Description", target.Description); diff --git a/PluralKit.Core/Models/ModelQueryExt.cs b/PluralKit.Core/Models/ModelQueryExt.cs index a99d58f8..9b751759 100644 --- a/PluralKit.Core/Models/ModelQueryExt.cs +++ b/PluralKit.Core/Models/ModelQueryExt.cs @@ -38,6 +38,18 @@ namespace PluralKit.Core public static Task> QueryGroupsInSystem(this IPKConnection conn, SystemId system) => conn.QueryAsync("select * from groups where system = @System", new {System = system}); + public static Task 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(query.ToString(), new {Id = id, PrivacyFilter = privacyFilter}); + } + public static Task QueryOrInsertGuildConfig(this IPKConnection conn, ulong guild) => conn.QueryFirstAsync("insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *", new {guild});