feat: system avatar and name should now be working properly with the possible exception of the pk;msg command (dependent on decisions of expected behavior)

This commit is contained in:
rladenson 2023-05-29 01:27:54 -04:00
parent ef5bcc8b49
commit 2c2708be02
6 changed files with 73 additions and 15 deletions

View file

@ -131,10 +131,23 @@ public class GroupMember
opts.GroupFilter = target.Id;
var title = new StringBuilder($"Members of {target.DisplayName ?? target.Name} (`{target.Hid}`) in ");
if (targetSystem.Name != null)
title.Append($"{targetSystem.Name} (`{targetSystem.Hid}`)");
if (ctx.Guild != null)
{
var guildSettings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, targetSystem.Id);
if (guildSettings.DisplayName != null)
title.Append($"{guildSettings.DisplayName} (`{targetSystem.Hid}`)");
else if (targetSystem.NameFor(ctx) != null)
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.Hid}`)");
else
title.Append($"`{targetSystem.Hid}`");
}
else
title.Append($"`{targetSystem.Hid}`");
{
if (targetSystem.NameFor(ctx) != null)
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.Hid}`)");
else
title.Append($"`{targetSystem.Hid}`");
}
if (opts.Search != null)
title.Append($" matching **{opts.Search.Truncate(100)}**");

View file

@ -38,10 +38,17 @@ public class SystemFront
.Scan(new FrontHistoryEntry(null, null),
(lastEntry, newSwitch) => new FrontHistoryEntry(lastEntry.ThisSwitch?.Timestamp, newSwitch));
var embedTitle = system.Name != null
? $"Front history of {system.Name} (`{system.Hid}`)"
var embedTitle = system.NameFor(ctx) != null
? $"Front history of {system.NameFor(ctx)} (`{system.Hid}`)"
: $"Front history of `{system.Hid}`";
if (ctx.Guild != null)
{
var guildSettings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, system.Id);
if (guildSettings.DisplayName != null)
embedTitle = $"Front history of {guildSettings.DisplayName} (`{system.Hid}`)";
}
var showMemberId = ctx.MatchFlag("with-id", "wid");
await ctx.Paginate(
@ -121,10 +128,13 @@ public class SystemFront
if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture;
var title = new StringBuilder("Frontpercent of ");
var guildSettings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, system.Id);
if (group != null)
title.Append($"{group.NameFor(ctx)} (`{group.Hid}`)");
else if (system.Name != null)
title.Append($"{system.Name} (`{system.Hid}`)");
else if (guildSettings.DisplayName != null)
title.Append($"{guildSettings.DisplayName} (`{system.Hid}`)");
else if (system.NameFor(ctx) != null)
title.Append($"{system.NameFor(ctx)} (`{system.Hid}`)");
else
title.Append($"`{system.Hid}`");

View file

@ -21,18 +21,21 @@ public class SystemList
await ctx.RenderMemberList(
ctx.LookupContextFor(target.Id),
target.Id,
GetEmbedTitle(target, opts),
await GetEmbedTitle(target, opts, ctx),
target.Color,
opts
);
}
private string GetEmbedTitle(PKSystem target, ListOptions opts)
private async Task<string> GetEmbedTitle(PKSystem target, ListOptions opts, Context ctx)
{
var title = new StringBuilder("Members of ");
if (target.Name != null)
title.Append($"{target.Name} (`{target.Hid}`)");
var systemGuildSettings = ctx.Guild != null ? await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id) : null;
if (systemGuildSettings != null && systemGuildSettings.DisplayName != null)
title.Append($"{systemGuildSettings.DisplayName} (`{target.Hid}`)");
else if (target.NameFor(ctx) != null)
title.Append($"{target.NameFor(ctx)} (`{target.Hid}`)");
else
title.Append($"`{target.Hid}`");

View file

@ -68,7 +68,7 @@ public class EmbedService
}
var eb = new EmbedBuilder()
.Title(system.Name)
.Title(system.NameFor(ctx))
.Thumbnail(new Embed.EmbedThumbnail(system.AvatarUrl.TryGetCleanCdnUrl()))
.Footer(new Embed.EmbedFooter(
$"System ID: {system.Hid} | Created on {system.Created.FormatZoned(cctx.Zone)}"))
@ -106,6 +106,20 @@ public class EmbedService
if (!guildSettings.TagEnabled)
eb.Field(new Embed.Field($"Tag (in server '{cctx.Guild.Name}')",
"*(tag is disabled in this server)*"));
if (guildSettings.DisplayName != null)
eb.Title(guildSettings.DisplayName);
if (guildSettings.AvatarUrl.TryGetCleanCdnUrl() != null)
{
eb.Thumbnail(new Embed.EmbedThumbnail(guildSettings.AvatarUrl.TryGetCleanCdnUrl()));
var sysDesc = "*(this system has a server-specific avatar set";
if (system.AvatarUrl.TryGetCleanCdnUrl() != null)
sysDesc += $"; [click here]({system.AvatarUrl.TryGetCleanCdnUrl()}) to see their global avatar)*";
else
sysDesc += ")*";
eb.Description(sysDesc);
}
}
if (system.PronounPrivacy.CanAccess(ctx) && system.Pronouns != null)
@ -162,7 +176,13 @@ public class EmbedService
// string FormatTimestamp(Instant timestamp) => DateTimeFormats.ZonedDateTimeFormat.Format(timestamp.InZone(system.Zone));
var name = member.NameFor(ctx);
if (system.Name != null) name = $"{name} ({system.Name})";
var systemGuildSettings = guild != null ? await _repo.GetSystemGuild(guild.Id, system.Id) : null;
if (systemGuildSettings != null && systemGuildSettings.DisplayName != null)
name = $"{name} ({systemGuildSettings.DisplayName})";
else if (system.NameFor(ctx) != null)
name = $"{name} ({system.NameFor(ctx)})";
else
name = $"{name} ({system.Name})";
uint color;
try
@ -256,8 +276,13 @@ public class EmbedService
var memberCount = await _repo.GetGroupMemberCount(target.Id, countctx == LookupContext.ByOwner ? null : PrivacyLevel.Public);
var nameField = target.NamePrivacy.Get(pctx, target.Name, target.DisplayName ?? target.Name);
if (system.Name != null)
var nameField = target.NameFor(ctx);
var systemGuildSettings = ctx.Guild != null ? await _repo.GetSystemGuild(ctx.Guild.Id, system.Id) : null;
if (systemGuildSettings != null && systemGuildSettings.DisplayName != null)
nameField = $"{nameField} ({systemGuildSettings.DisplayName})";
else if (system.NameFor(ctx) != null)
nameField = $"{nameField} ({system.NameFor(ctx)})";
else
nameField = $"{nameField} ({system.Name})";
uint color;

View file

@ -11,6 +11,9 @@ public static class ModelUtils
public static string NameFor(this PKGroup group, Context ctx) =>
group.NameFor(ctx.LookupContextFor(group.System));
public static string NameFor(this PKSystem system, Context ctx) =>
system.NameFor(ctx.LookupContextFor(system.Id));
public static string AvatarFor(this PKMember member, Context ctx) =>
member.AvatarFor(ctx.LookupContextFor(member.System)).TryGetCleanCdnUrl();

View file

@ -59,6 +59,10 @@ public static class PKSystemExt
public static string DescriptionFor(this PKSystem system, LookupContext ctx) =>
system.DescriptionPrivacy.Get(ctx, system.Description);
public static string NameFor(this PKSystem system, LookupContext ctx) =>
system.Name;
//system.NamePrivacy.Get(ctx, system.Name);
public static JObject ToJson(this PKSystem system, LookupContext ctx)
{
var o = new JObject();