Show member groups on member card

This commit is contained in:
Ske 2020-07-18 13:26:36 +02:00
parent ec9ee5c794
commit f47d366c8d
2 changed files with 15 additions and 3 deletions

View File

@ -102,12 +102,16 @@ namespace PluralKit.Bot {
// for now we just default to a blank color, yolo
color = DiscordUtils.Gray;
}
await using var conn = await _db.Obtain();
var guildSettings = guild != null ? await _db.Execute(c => c.QueryOrInsertMemberGuildConfig(guild.Id, member.Id)) : null;
var guildSettings = guild != null ? await conn.QueryOrInsertMemberGuildConfig(guild.Id, member.Id) : null;
var guildDisplayName = guildSettings?.DisplayName;
var avatar = guildSettings?.AvatarUrl ?? member.AvatarFor(ctx);
var proxyTagsStr = string.Join('\n', member.ProxyTags.Select(t => $"`` {t.ProxyString}``"));
var groups = (await conn.QueryMemberGroups(member.Id)).ToList();
var proxyTagsStr = string.Join('\n', member.ProxyTags.Select(t => $"`` {t.ProxyString} ``"));
var eb = new DiscordEmbedBuilder()
// TODO: add URL of website when that's up
@ -125,6 +129,9 @@ namespace PluralKit.Bot {
description += "*(this member has a server-specific avatar set)*\n";
if (description != "") eb.WithDescription(description);
if (groups.Count > 0)
eb.AddField($"Groups ({groups.Count})", string.Join("\n", groups.Select(g => $"[`{g.Hid}`] **{g.Name}**")).Truncate(1000));
if (avatar != null) eb.WithThumbnail(avatar);
if (!member.DisplayName.EmptyOrNull() && member.NamePrivacy.CanAccess(ctx)) eb.AddField("Display Name", member.DisplayName.Truncate(1024), true);

View File

@ -43,13 +43,18 @@ namespace PluralKit.Core
{
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(" inner 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<IEnumerable<PKGroup>> QueryMemberGroups(this IPKConnection conn, MemberId id) =>
conn.QueryAsync<PKGroup>(
"select groups.* from group_members inner join groups on group_members.group_id = groups.id where group_members.member_id = @Id",
new {Id = id});
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});