feat(bot): allow separate member avatars for proxied messages (#523)

This allows for using one avatar for the member card, and a different
avatar for proxied messages - so that users can set the main avatar to
a "full" version of their avatar, and the "proxy" avatar to a cropped
version.
This commit is contained in:
the iris system
2023-03-02 06:11:35 +13:00
committed by GitHub
parent 7fffb7f65a
commit ccb89f50e9
12 changed files with 138 additions and 49 deletions

View File

@@ -39,6 +39,7 @@ public class PKMember
public Guid Uuid { get; private set; }
public SystemId System { get; private set; }
public string Color { get; private set; }
public string WebhookAvatarUrl { get; private set; }
public string AvatarUrl { get; private set; }
public string BannerImage { get; private set; }
public string Name { get; private set; }
@@ -90,6 +91,9 @@ public static class PKMemberExt
public static string AvatarFor(this PKMember member, LookupContext ctx) =>
member.AvatarPrivacy.Get(ctx, member.AvatarUrl.TryGetCleanCdnUrl());
public static string WebhookAvatarFor(this PKMember member, LookupContext ctx) =>
member.AvatarPrivacy.Get(ctx, (member.WebhookAvatarUrl ?? member.AvatarUrl).TryGetCleanCdnUrl());
public static string DescriptionFor(this PKMember member, LookupContext ctx) =>
member.DescriptionPrivacy.Get(ctx, member.Description);
@@ -128,6 +132,7 @@ public static class PKMemberExt
o.Add("birthday", member.BirthdayFor(ctx)?.FormatExport());
o.Add("pronouns", member.PronounsFor(ctx));
o.Add("avatar_url", member.AvatarFor(ctx).TryGetCleanCdnUrl());
o.Add("webhook_avatar_url", member.WebhookAvatarFor(ctx).TryGetCleanCdnUrl());
o.Add("banner", member.DescriptionPrivacy.Get(ctx, member.BannerImage).TryGetCleanCdnUrl());
o.Add("description", member.DescriptionFor(ctx));
o.Add("created", member.CreatedFor(ctx)?.FormatExport());

View File

@@ -12,6 +12,7 @@ public class MemberPatch: PatchObject
public Partial<string> Name { get; set; }
public Partial<string> Hid { get; set; }
public Partial<string?> DisplayName { get; set; }
public Partial<string?> WebhookAvatarUrl { get; set; }
public Partial<string?> AvatarUrl { get; set; }
public Partial<string?> BannerImage { get; set; }
public Partial<string?> Color { get; set; }
@@ -34,6 +35,7 @@ public class MemberPatch: PatchObject
.With("name", Name)
.With("hid", Hid)
.With("display_name", DisplayName)
.With("webhook_avatar_url", WebhookAvatarUrl)
.With("avatar_url", AvatarUrl)
.With("banner_image", BannerImage)
.With("color", Color)
@@ -62,6 +64,9 @@ public class MemberPatch: PatchObject
if (AvatarUrl.Value != null)
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var avatarUri));
if (WebhookAvatarUrl.Value != null)
AssertValid(WebhookAvatarUrl.Value, "webhook_avatar_url", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var webhookAvatarUri));
if (BannerImage.Value != null)
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var bannerUri));
@@ -93,6 +98,7 @@ public class MemberPatch: PatchObject
if (o.ContainsKey("name")) patch.Name = o.Value<string>("name");
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty()?.ToLower();
if (o.ContainsKey("display_name")) patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
if (o.ContainsKey("webhook_avatar_url")) patch.WebhookAvatarUrl = o.Value<string>("webhook_avatar_url").NullIfEmpty();
if (o.ContainsKey("avatar_url")) patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
@@ -177,6 +183,8 @@ public class MemberPatch: PatchObject
o.Add("display_name", DisplayName.Value);
if (AvatarUrl.IsPresent)
o.Add("avatar_url", AvatarUrl.Value);
if (WebhookAvatarUrl.IsPresent)
o.Add("webhook_avatar_url", WebhookAvatarUrl.Value);
if (BannerImage.IsPresent)
o.Add("banner", BannerImage.Value);
if (Color.IsPresent)