Show member count on group card
This commit is contained in:
parent
0d04be6540
commit
ec9ee5c794
@ -31,7 +31,7 @@ namespace PluralKit.Bot
|
|||||||
await using var conn = await _db.Obtain();
|
await using var conn = await _db.Obtain();
|
||||||
var newGroup = await conn.CreateGroup(ctx.System.Id, groupName);
|
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)
|
public async Task RenameGroup(Context ctx, PKGroup target)
|
||||||
@ -133,6 +133,7 @@ namespace PluralKit.Bot
|
|||||||
await using var conn = await _db.Obtain();
|
await using var conn = await _db.Obtain();
|
||||||
|
|
||||||
var system = await GetGroupSystem(ctx, target, conn);
|
var system = await GetGroupSystem(ctx, target, conn);
|
||||||
|
var memberCount = await conn.QueryGroupMemberCount(target.Id, PrivacyLevel.Public);
|
||||||
|
|
||||||
var nameField = target.Name;
|
var nameField = target.Name;
|
||||||
if (system.Name != null)
|
if (system.Name != null)
|
||||||
@ -142,6 +143,11 @@ namespace PluralKit.Bot
|
|||||||
.WithAuthor(nameField)
|
.WithAuthor(nameField)
|
||||||
.WithFooter($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}");
|
.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)
|
if (target.Description != null)
|
||||||
eb.AddField("Description", target.Description);
|
eb.AddField("Description", target.Description);
|
||||||
|
|
||||||
|
@ -38,6 +38,18 @@ namespace PluralKit.Core
|
|||||||
public static Task<IEnumerable<PKGroup>> QueryGroupsInSystem(this IPKConnection conn, SystemId system) =>
|
public static Task<IEnumerable<PKGroup>> QueryGroupsInSystem(this IPKConnection conn, SystemId system) =>
|
||||||
conn.QueryAsync<PKGroup>("select * from groups where system = @System", new {System = 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) =>
|
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});
|
conn.QueryFirstAsync<GuildConfig>("insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *", new {guild});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user