mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 08:10:10 +00:00
tweak: use global list formatting for member group lists (#628)
* tweak: use global list formatting for member group lists * fix: use DisplayHid
This commit is contained in:
parent
3a4cc5b05e
commit
87d027f2d4
3 changed files with 32 additions and 23 deletions
|
|
@ -53,31 +53,33 @@ public class GroupMember
|
||||||
|
|
||||||
public async Task ListMemberGroups(Context ctx, PKMember target)
|
public async Task ListMemberGroups(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
var pctx = ctx.DirectLookupContextFor(target.System);
|
var targetSystem = await ctx.Repository.GetSystem(target.System);
|
||||||
|
var opts = ctx.ParseListOptions(ctx.DirectLookupContextFor(target.System));
|
||||||
|
opts.MemberFilter = target.Id;
|
||||||
|
|
||||||
var groups = await ctx.Repository.GetMemberGroups(target.Id)
|
var title = new StringBuilder($"Groups containing {target.Name} (`{target.DisplayHid(ctx.Config)}`) in ");
|
||||||
.Where(g => g.Visibility.CanAccess(pctx))
|
if (ctx.Guild != null)
|
||||||
.OrderBy(g => (g.DisplayName ?? g.Name), StringComparer.InvariantCultureIgnoreCase)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var description = "";
|
|
||||||
var msg = "";
|
|
||||||
|
|
||||||
if (groups.Count == 0)
|
|
||||||
description = "This member has no groups.";
|
|
||||||
else
|
|
||||||
description = string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ctx.Config, isList: true)}`] **{g.DisplayName ?? g.Name}**"));
|
|
||||||
|
|
||||||
if (pctx == LookupContext.ByOwner)
|
|
||||||
{
|
{
|
||||||
msg +=
|
var guildSettings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, targetSystem.Id);
|
||||||
$"\n\nTo add this member to one or more groups, use `pk;m {target.Reference(ctx)} group add <group> [group 2] [group 3...]`";
|
if (guildSettings.DisplayName != null)
|
||||||
if (groups.Count > 0)
|
title.Append($"{guildSettings.DisplayName} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||||
msg +=
|
else if (targetSystem.NameFor(ctx) != null)
|
||||||
$"\nTo remove this member from one or more groups, use `pk;m {target.Reference(ctx)} group remove <group> [group 2] [group 3...]`";
|
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||||
|
else
|
||||||
|
title.Append($"`{targetSystem.DisplayHid(ctx.Config)}`");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (targetSystem.NameFor(ctx) != null)
|
||||||
|
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||||
|
else
|
||||||
|
title.Append($"`{targetSystem.DisplayHid(ctx.Config)}`");
|
||||||
|
}
|
||||||
|
if (opts.Search != null)
|
||||||
|
title.Append($" matching **{opts.Search.Truncate(100)}**");
|
||||||
|
|
||||||
await ctx.Reply(msg, new EmbedBuilder().Title($"{target.Name}'s groups").Description(description).Build());
|
await ctx.RenderGroupList(ctx.LookupContextFor(target.System), target.System, title.ToString(),
|
||||||
|
target.Color, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddRemoveMembers(Context ctx, PKGroup target, Groups.AddRemoveOperation op)
|
public async Task AddRemoveMembers(Context ctx, PKGroup target, Groups.AddRemoveOperation op)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ public class ListOptions
|
||||||
|
|
||||||
public PrivacyLevel? PrivacyFilter { get; set; } = PrivacyLevel.Public;
|
public PrivacyLevel? PrivacyFilter { get; set; } = PrivacyLevel.Public;
|
||||||
public GroupId? GroupFilter { get; set; }
|
public GroupId? GroupFilter { get; set; }
|
||||||
|
public MemberId? MemberFilter { get; set; }
|
||||||
public string? Search { get; set; }
|
public string? Search { get; set; }
|
||||||
public bool SearchDescription { get; set; }
|
public bool SearchDescription { get; set; }
|
||||||
|
|
||||||
|
|
@ -96,6 +97,7 @@ public class ListOptions
|
||||||
{
|
{
|
||||||
PrivacyFilter = PrivacyFilter,
|
PrivacyFilter = PrivacyFilter,
|
||||||
GroupFilter = GroupFilter,
|
GroupFilter = GroupFilter,
|
||||||
|
MemberFilter = MemberFilter,
|
||||||
Search = Search,
|
Search = Search,
|
||||||
SearchDescription = SearchDescription
|
SearchDescription = SearchDescription
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@ public static class DatabaseViewsExt
|
||||||
public static Task<IEnumerable<ListedGroup>> QueryGroupList(this IPKConnection conn, SystemId system,
|
public static Task<IEnumerable<ListedGroup>> QueryGroupList(this IPKConnection conn, SystemId system,
|
||||||
ListQueryOptions opts)
|
ListQueryOptions opts)
|
||||||
{
|
{
|
||||||
StringBuilder query = new StringBuilder("select * from group_list where system = @system");
|
StringBuilder query;
|
||||||
|
if (opts.MemberFilter == null)
|
||||||
|
query = new StringBuilder("select * from group_list where system = @system");
|
||||||
|
else
|
||||||
|
query = new StringBuilder("select group_list.* from group_members inner join group_list on group_list.id = group_members.group_id where member_id = @MemberFilter");
|
||||||
|
|
||||||
if (opts.PrivacyFilter != null)
|
if (opts.PrivacyFilter != null)
|
||||||
query.Append($" and visibility = {(int)opts.PrivacyFilter}");
|
query.Append($" and visibility = {(int)opts.PrivacyFilter}");
|
||||||
|
|
@ -36,7 +40,7 @@ public static class DatabaseViewsExt
|
||||||
|
|
||||||
return conn.QueryAsync<ListedGroup>(
|
return conn.QueryAsync<ListedGroup>(
|
||||||
query.ToString(),
|
query.ToString(),
|
||||||
new { system, filter = opts.Search });
|
new { system, filter = opts.Search, memberFilter = opts.MemberFilter });
|
||||||
}
|
}
|
||||||
public static Task<IEnumerable<ListedMember>> QueryMemberList(this IPKConnection conn, SystemId system,
|
public static Task<IEnumerable<ListedMember>> QueryMemberList(this IPKConnection conn, SystemId system,
|
||||||
ListQueryOptions opts)
|
ListQueryOptions opts)
|
||||||
|
|
@ -81,5 +85,6 @@ public static class DatabaseViewsExt
|
||||||
public bool SearchDescription;
|
public bool SearchDescription;
|
||||||
public LookupContext Context;
|
public LookupContext Context;
|
||||||
public GroupId? GroupFilter;
|
public GroupId? GroupFilter;
|
||||||
|
public MemberId? MemberFilter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue