mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat(bot): add system guild icon & guild name (#554)
This commit is contained in:
parent
d12cd481f6
commit
3045c5e307
22 changed files with 337 additions and 28 deletions
|
|
@ -46,6 +46,8 @@ public class PKSystem
|
|||
public string WebhookUrl { get; }
|
||||
public string WebhookToken { get; }
|
||||
public Instant Created { get; }
|
||||
public PrivacyLevel NamePrivacy { get; }
|
||||
public PrivacyLevel AvatarPrivacy { get; }
|
||||
public PrivacyLevel DescriptionPrivacy { get; }
|
||||
public PrivacyLevel MemberListPrivacy { get; }
|
||||
public PrivacyLevel FrontPrivacy { get; }
|
||||
|
|
@ -59,18 +61,24 @@ 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.NamePrivacy.Get(ctx, system.Name);
|
||||
|
||||
public static string AvatarFor(this PKSystem system, LookupContext ctx) =>
|
||||
system.AvatarPrivacy.Get(ctx, system.AvatarUrl.TryGetCleanCdnUrl());
|
||||
|
||||
public static JObject ToJson(this PKSystem system, LookupContext ctx)
|
||||
{
|
||||
var o = new JObject();
|
||||
o.Add("id", system.Hid);
|
||||
o.Add("uuid", system.Uuid.ToString());
|
||||
|
||||
o.Add("name", system.Name);
|
||||
o.Add("name", system.NameFor(ctx));
|
||||
o.Add("description", system.DescriptionFor(ctx));
|
||||
o.Add("tag", system.Tag);
|
||||
o.Add("pronouns", system.PronounPrivacy.Get(ctx, system.Pronouns));
|
||||
|
||||
o.Add("avatar_url", system.AvatarUrl.TryGetCleanCdnUrl());
|
||||
o.Add("avatar_url", system.AvatarFor(ctx));
|
||||
o.Add("banner", system.DescriptionPrivacy.Get(ctx, system.BannerImage).TryGetCleanCdnUrl());
|
||||
o.Add("color", system.Color);
|
||||
o.Add("created", system.Created.FormatExport());
|
||||
|
|
@ -83,6 +91,8 @@ public static class PKSystemExt
|
|||
|
||||
var p = new JObject();
|
||||
|
||||
p.Add("name_privacy", system.NamePrivacy.ToJsonString());
|
||||
p.Add("avatar_privacy", system.AvatarPrivacy.ToJsonString());
|
||||
p.Add("description_privacy", system.DescriptionPrivacy.ToJsonString());
|
||||
p.Add("pronoun_privacy", system.PronounPrivacy.ToJsonString());
|
||||
p.Add("member_list_privacy", system.MemberListPrivacy.ToJsonString());
|
||||
|
|
|
|||
|
|
@ -11,17 +11,26 @@ public class SystemGuildPatch: PatchObject
|
|||
public Partial<bool> ProxyEnabled { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<bool?> TagEnabled { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("proxy_enabled", ProxyEnabled)
|
||||
.With("tag", Tag)
|
||||
.With("tag_enabled", TagEnabled)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("display_name", DisplayName)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (Tag.Value != null)
|
||||
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
|
||||
if (AvatarUrl.Value != null)
|
||||
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxMemberNameLength);
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
|
|
@ -38,6 +47,12 @@ public class SystemGuildPatch: PatchObject
|
|||
if (o.ContainsKey("tag_enabled") && o["tag_enabled"].Type != JTokenType.Null)
|
||||
patch.TagEnabled = o.Value<bool>("tag_enabled");
|
||||
|
||||
if (o.ContainsKey("avatar_url"))
|
||||
patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("display_name"))
|
||||
patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
|
@ -56,6 +71,12 @@ public class SystemGuildPatch: PatchObject
|
|||
if (TagEnabled.IsPresent)
|
||||
o.Add("tag_enabled", TagEnabled.Value);
|
||||
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@ public class SystemPatch: PatchObject
|
|||
public Partial<string?> Token { get; set; }
|
||||
public Partial<string?> WebhookUrl { get; set; }
|
||||
public Partial<string?> WebhookToken { get; set; }
|
||||
public Partial<PrivacyLevel> NamePrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> AvatarPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MemberListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> GroupListPrivacy { get; set; }
|
||||
|
|
@ -37,6 +39,8 @@ public class SystemPatch: PatchObject
|
|||
.With("token", Token)
|
||||
.With("webhook_url", WebhookUrl)
|
||||
.With("webhook_token", WebhookToken)
|
||||
.With("name_privacy", NamePrivacy)
|
||||
.With("avatar_privacy", AvatarPrivacy)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("member_list_privacy", MemberListPrivacy)
|
||||
.With("group_list_privacy", GroupListPrivacy)
|
||||
|
|
@ -93,6 +97,12 @@ public class SystemPatch: PatchObject
|
|||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("name_privacy"))
|
||||
patch.NamePrivacy = patch.ParsePrivacy(privacy, "name_privacy");
|
||||
|
||||
if (privacy.ContainsKey("avatar_privacy"))
|
||||
patch.AvatarPrivacy = patch.ParsePrivacy(privacy, "avatar_privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
|
|
@ -137,7 +147,9 @@ public class SystemPatch: PatchObject
|
|||
o.Add("color", Color.Value);
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
NamePrivacy.IsPresent
|
||||
|| AvatarPrivacy.IsPresent
|
||||
|| DescriptionPrivacy.IsPresent
|
||||
|| PronounPrivacy.IsPresent
|
||||
|| MemberListPrivacy.IsPresent
|
||||
|| GroupListPrivacy.IsPresent
|
||||
|
|
@ -147,6 +159,12 @@ public class SystemPatch: PatchObject
|
|||
{
|
||||
var p = new JObject();
|
||||
|
||||
if (NamePrivacy.IsPresent)
|
||||
p.Add("name_privacy", NamePrivacy.Value.ToJsonString());
|
||||
|
||||
if (AvatarPrivacy.IsPresent)
|
||||
p.Add("avatar_privacy", AvatarPrivacy.Value.ToJsonString());
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ namespace PluralKit.Core;
|
|||
|
||||
public enum SystemPrivacySubject
|
||||
{
|
||||
Name,
|
||||
Avatar,
|
||||
Description,
|
||||
Pronouns,
|
||||
MemberList,
|
||||
|
|
@ -17,6 +19,8 @@ public static class SystemPrivacyUtils
|
|||
// what do you mean switch expressions can't be statements >.>
|
||||
_ = subject switch
|
||||
{
|
||||
SystemPrivacySubject.Name => system.NamePrivacy = level,
|
||||
SystemPrivacySubject.Avatar => system.AvatarPrivacy = level,
|
||||
SystemPrivacySubject.Description => system.DescriptionPrivacy = level,
|
||||
SystemPrivacySubject.Pronouns => system.PronounPrivacy = level,
|
||||
SystemPrivacySubject.Front => system.FrontPrivacy = level,
|
||||
|
|
@ -40,6 +44,15 @@ public static class SystemPrivacyUtils
|
|||
{
|
||||
switch (input.ToLowerInvariant())
|
||||
{
|
||||
case "name":
|
||||
subject = SystemPrivacySubject.Name;
|
||||
break;
|
||||
case "avatar":
|
||||
case "pfp":
|
||||
case "pic":
|
||||
case "icon":
|
||||
subject = SystemPrivacySubject.Avatar;
|
||||
break;
|
||||
case "description":
|
||||
case "desc":
|
||||
case "text":
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ public class SystemGuildSettings
|
|||
public bool ProxyEnabled { get; } = true;
|
||||
public string? Tag { get; }
|
||||
public bool TagEnabled { get; }
|
||||
public string? AvatarUrl { get; }
|
||||
public string? DisplayName { get; }
|
||||
}
|
||||
|
||||
public static class SystemGuildExt
|
||||
|
|
@ -20,6 +22,8 @@ public static class SystemGuildExt
|
|||
o.Add("proxying_enabled", settings.ProxyEnabled);
|
||||
o.Add("tag", settings.Tag);
|
||||
o.Add("tag_enabled", settings.TagEnabled);
|
||||
o.Add("avatar_url", settings.AvatarUrl);
|
||||
o.Add("display_name", settings.DisplayName);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue