feat: upgrade to .NET 6, refactor everything
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
using SqlKata;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace PluralKit.Core
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class AccountPatch: PatchObject
|
||||
{
|
||||
public class AccountPatch: PatchObject
|
||||
public Partial<bool> AllowAutoproxy { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("allow_autoproxy", AllowAutoproxy)
|
||||
);
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
public Partial<bool> AllowAutoproxy { get; set; }
|
||||
var o = new JObject();
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("allow_autoproxy", AllowAutoproxy)
|
||||
);
|
||||
if (AllowAutoproxy.IsPresent)
|
||||
o.Add("allow_autoproxy", AllowAutoproxy.Value);
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (AllowAutoproxy.IsPresent)
|
||||
o.Add("allow_autoproxy", AllowAutoproxy.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
@@ -1,141 +1,138 @@
|
||||
#nullable enable
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class GroupPatch: PatchObject
|
||||
{
|
||||
public class GroupPatch: PatchObject
|
||||
public Partial<string> Name { get; set; }
|
||||
public Partial<string> Hid { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<string?> Icon { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> IconPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> ListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> Visibility { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("display_name", DisplayName)
|
||||
.With("description", Description)
|
||||
.With("icon", Icon)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("icon_privacy", IconPrivacy)
|
||||
.With("list_privacy", ListPrivacy)
|
||||
.With("visibility", Visibility)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
public Partial<string> Name { get; set; }
|
||||
public Partial<string> Hid { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<string?> Icon { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> IconPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> ListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> Visibility { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("display_name", DisplayName)
|
||||
.With("description", Description)
|
||||
.With("icon", Icon)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("icon_privacy", IconPrivacy)
|
||||
.With("list_privacy", ListPrivacy)
|
||||
.With("visibility", Visibility)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxGroupNameLength);
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxGroupNameLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
if (Icon.Value != null)
|
||||
AssertValid(Icon.Value, "icon", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
if (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
}
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxGroupNameLength);
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxGroupNameLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
if (Icon.Value != null)
|
||||
AssertValid(Icon.Value, "icon", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
if (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
public static GroupPatch FromJson(JObject o)
|
||||
public static GroupPatch FromJson(JObject o)
|
||||
{
|
||||
var patch = new GroupPatch();
|
||||
|
||||
if (o.ContainsKey("name"))
|
||||
{
|
||||
var patch = new GroupPatch();
|
||||
|
||||
if (o.ContainsKey("name"))
|
||||
{
|
||||
patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (patch.Name.Value == null)
|
||||
patch.Errors.Add(new ValidationError("name", "Group name can not be set to null."));
|
||||
}
|
||||
|
||||
if (o.ContainsKey("display_name")) patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("icon")) patch.Icon = o.Value<string>("icon").NullIfEmpty();
|
||||
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
|
||||
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty()?.ToLower();
|
||||
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
if (privacy.ContainsKey("icon_privacy"))
|
||||
patch.IconPrivacy = patch.ParsePrivacy(privacy, "icon_privacy");
|
||||
|
||||
if (privacy.ContainsKey("list_privacy"))
|
||||
patch.ListPrivacy = patch.ParsePrivacy(privacy, "list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("visibility"))
|
||||
patch.Visibility = patch.ParsePrivacy(privacy, "visibility");
|
||||
}
|
||||
|
||||
return patch;
|
||||
patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (patch.Name.Value == null)
|
||||
patch.Errors.Add(new ValidationError("name", "Group name can not be set to null."));
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
if (o.ContainsKey("display_name")) patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("icon")) patch.Icon = o.Value<string>("icon").NullIfEmpty();
|
||||
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
|
||||
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty()?.ToLower();
|
||||
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
var o = new JObject();
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (Icon.IsPresent)
|
||||
o.Add("icon", Icon.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
|| IconPrivacy.IsPresent
|
||||
|| ListPrivacy.IsPresent
|
||||
|| Visibility.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
if (privacy.ContainsKey("icon_privacy"))
|
||||
patch.IconPrivacy = patch.ParsePrivacy(privacy, "icon_privacy");
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
if (privacy.ContainsKey("list_privacy"))
|
||||
patch.ListPrivacy = patch.ParsePrivacy(privacy, "list_privacy");
|
||||
|
||||
if (IconPrivacy.IsPresent)
|
||||
p.Add("icon_privacy", IconPrivacy.Value.ToJsonString());
|
||||
|
||||
if (ListPrivacy.IsPresent)
|
||||
p.Add("list_privacy", ListPrivacy.Value.ToJsonString());
|
||||
|
||||
if (Visibility.IsPresent)
|
||||
p.Add("visibility", Visibility.Value.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
if (privacy.ContainsKey("visibility"))
|
||||
patch.Visibility = patch.ParsePrivacy(privacy, "visibility");
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (Icon.IsPresent)
|
||||
o.Add("icon", Icon.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
|| IconPrivacy.IsPresent
|
||||
|| ListPrivacy.IsPresent
|
||||
|| Visibility.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
if (IconPrivacy.IsPresent)
|
||||
p.Add("icon_privacy", IconPrivacy.Value.ToJsonString());
|
||||
|
||||
if (ListPrivacy.IsPresent)
|
||||
p.Add("list_privacy", ListPrivacy.Value.ToJsonString());
|
||||
|
||||
if (Visibility.IsPresent)
|
||||
p.Add("visibility", Visibility.Value.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
@@ -1,19 +1,18 @@
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class GuildPatch: PatchObject
|
||||
{
|
||||
public Partial<ulong?> LogChannel { get; set; }
|
||||
public Partial<ulong[]> LogBlacklist { get; set; }
|
||||
public Partial<ulong[]> Blacklist { get; set; }
|
||||
public Partial<bool> LogCleanupEnabled { get; set; }
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("log_channel", LogChannel)
|
||||
.With("log_blacklist", LogBlacklist)
|
||||
.With("blacklist", Blacklist)
|
||||
.With("log_cleanup_enabled", LogCleanupEnabled)
|
||||
);
|
||||
}
|
||||
public class GuildPatch: PatchObject
|
||||
{
|
||||
public Partial<ulong?> LogChannel { get; set; }
|
||||
public Partial<ulong[]> LogBlacklist { get; set; }
|
||||
public Partial<ulong[]> Blacklist { get; set; }
|
||||
public Partial<bool> LogCleanupEnabled { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("log_channel", LogChannel)
|
||||
.With("log_blacklist", LogBlacklist)
|
||||
.With("blacklist", Blacklist)
|
||||
.With("log_cleanup_enabled", LogCleanupEnabled)
|
||||
);
|
||||
}
|
@@ -4,54 +4,53 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class MemberGuildPatch: PatchObject
|
||||
{
|
||||
public class MemberGuildPatch: PatchObject
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("display_name", DisplayName)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("display_name", DisplayName)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxMemberNameLength);
|
||||
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);
|
||||
if (AvatarUrl.Value != null)
|
||||
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
public static MemberGuildPatch FromJson(JObject o)
|
||||
{
|
||||
var patch = new MemberGuildPatch();
|
||||
public static MemberGuildPatch FromJson(JObject o)
|
||||
{
|
||||
var patch = new MemberGuildPatch();
|
||||
|
||||
if (o.ContainsKey("display_name"))
|
||||
patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
if (o.ContainsKey("display_name"))
|
||||
patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("avatar_url"))
|
||||
patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
if (o.ContainsKey("avatar_url"))
|
||||
patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
|
||||
return patch;
|
||||
}
|
||||
return patch;
|
||||
}
|
||||
|
||||
public JObject ToJson(ulong guild_id)
|
||||
{
|
||||
var o = new JObject();
|
||||
public JObject ToJson(ulong guild_id)
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
o.Add("guild_id", guild_id.ToString());
|
||||
o.Add("guild_id", guild_id.ToString());
|
||||
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
@@ -1,268 +1,271 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class MemberPatch: PatchObject
|
||||
{
|
||||
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?> AvatarUrl { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
public Partial<LocalDate?> Birthday { get; set; }
|
||||
public Partial<string?> Pronouns { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<ProxyTag[]> ProxyTags { get; set; }
|
||||
public Partial<bool> KeepProxy { get; set; }
|
||||
public Partial<int> MessageCount { get; set; }
|
||||
public Partial<bool> AllowAutoproxy { get; set; }
|
||||
public Partial<PrivacyLevel> Visibility { get; set; }
|
||||
public Partial<PrivacyLevel> NamePrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> PronounPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> BirthdayPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> AvatarPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MetadataPrivacy { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("display_name", DisplayName)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("birthday", Birthday)
|
||||
.With("pronouns", Pronouns)
|
||||
.With("description", Description)
|
||||
.With("proxy_tags", ProxyTags)
|
||||
.With("keep_proxy", KeepProxy)
|
||||
.With("message_count", MessageCount)
|
||||
.With("allow_autoproxy", AllowAutoproxy)
|
||||
.With("member_visibility", Visibility)
|
||||
.With("name_privacy", NamePrivacy)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("pronoun_privacy", PronounPrivacy)
|
||||
.With("birthday_privacy", BirthdayPrivacy)
|
||||
.With("avatar_privacy", AvatarPrivacy)
|
||||
.With("metadata_privacy", MetadataPrivacy)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
public Partial<string> Name { get; set; }
|
||||
public Partial<string> Hid { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
public Partial<LocalDate?> Birthday { get; set; }
|
||||
public Partial<string?> Pronouns { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<ProxyTag[]> ProxyTags { get; set; }
|
||||
public Partial<bool> KeepProxy { get; set; }
|
||||
public Partial<int> MessageCount { get; set; }
|
||||
public Partial<bool> AllowAutoproxy { get; set; }
|
||||
public Partial<PrivacyLevel> Visibility { get; set; }
|
||||
public Partial<PrivacyLevel> NamePrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> PronounPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> BirthdayPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> AvatarPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MetadataPrivacy { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("display_name", DisplayName)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("birthday", Birthday)
|
||||
.With("pronouns", Pronouns)
|
||||
.With("description", Description)
|
||||
.With("proxy_tags", ProxyTags)
|
||||
.With("keep_proxy", KeepProxy)
|
||||
.With("message_count", MessageCount)
|
||||
.With("allow_autoproxy", AllowAutoproxy)
|
||||
.With("member_visibility", Visibility)
|
||||
.With("name_privacy", NamePrivacy)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("pronoun_privacy", PronounPrivacy)
|
||||
.With("birthday_privacy", BirthdayPrivacy)
|
||||
.With("avatar_privacy", AvatarPrivacy)
|
||||
.With("metadata_privacy", MetadataPrivacy)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxMemberNameLength);
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxMemberNameLength);
|
||||
if (AvatarUrl.Value != null)
|
||||
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
if (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
if (Pronouns.Value != null)
|
||||
AssertValid(Pronouns.Value, "pronouns", Limits.MaxPronounsLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
if (ProxyTags.IsPresent && (ProxyTags.Value.Length > 100 ||
|
||||
ProxyTags.Value.Any(tag => tag.ProxyString.IsLongerThan(100))))
|
||||
// todo: have a better error for this
|
||||
Errors.Add(new ValidationError("proxy_tags"));
|
||||
}
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxMemberNameLength);
|
||||
if (DisplayName.Value != null)
|
||||
AssertValid(DisplayName.Value, "display_name", Limits.MaxMemberNameLength);
|
||||
if (AvatarUrl.Value != null)
|
||||
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var avatarUri));
|
||||
if (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
if (Pronouns.Value != null)
|
||||
AssertValid(Pronouns.Value, "pronouns", Limits.MaxPronounsLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
if (ProxyTags.IsPresent && (ProxyTags.Value.Length > 100 ||
|
||||
ProxyTags.Value.Any(tag => tag.ProxyString.IsLongerThan(100))))
|
||||
// todo: have a better error for this
|
||||
Errors.Add(new ValidationError("proxy_tags"));
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
|
||||
public static MemberPatch FromJSON(JObject o, APIVersion v = APIVersion.V1)
|
||||
public static MemberPatch FromJSON(JObject o, APIVersion v = APIVersion.V1)
|
||||
{
|
||||
var patch = new MemberPatch();
|
||||
|
||||
if (o.ContainsKey("name"))
|
||||
{
|
||||
var patch = new MemberPatch();
|
||||
|
||||
if (o.ContainsKey("name"))
|
||||
{
|
||||
patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (patch.Name.Value == null)
|
||||
patch.Errors.Add(new ValidationError("name", "Member name can not be set to null."));
|
||||
}
|
||||
|
||||
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("avatar_url")) patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("birthday"))
|
||||
{
|
||||
var str = o.Value<string>("birthday").NullIfEmpty();
|
||||
var res = DateTimeFormats.DateExportFormat.Parse(str);
|
||||
if (res.Success) patch.Birthday = res.Value;
|
||||
else if (str == null) patch.Birthday = null;
|
||||
else patch.Errors.Add(new ValidationError("birthday"));
|
||||
}
|
||||
|
||||
if (o.ContainsKey("pronouns")) patch.Pronouns = o.Value<string>("pronouns").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("keep_proxy")) patch.KeepProxy = o.Value<bool>("keep_proxy");
|
||||
|
||||
switch (v)
|
||||
{
|
||||
case APIVersion.V1:
|
||||
{
|
||||
// legacy: used in old export files and APIv1
|
||||
if (o.ContainsKey("prefix") || o.ContainsKey("suffix") && !o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = new[] { new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")) };
|
||||
else if (o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = o.Value<JArray>("proxy_tags")
|
||||
.OfType<JObject>().Select(o => new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")))
|
||||
.Where(p => p.Valid)
|
||||
.ToArray();
|
||||
|
||||
if (o.ContainsKey("privacy"))
|
||||
{
|
||||
var plevel = patch.ParsePrivacy(o, "privacy");
|
||||
|
||||
patch.Visibility = plevel;
|
||||
patch.NamePrivacy = plevel;
|
||||
patch.AvatarPrivacy = plevel;
|
||||
patch.DescriptionPrivacy = plevel;
|
||||
patch.BirthdayPrivacy = plevel;
|
||||
patch.PronounPrivacy = plevel;
|
||||
// member.ColorPrivacy = plevel;
|
||||
patch.MetadataPrivacy = plevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (o.ContainsKey("visibility")) patch.Visibility = patch.ParsePrivacy(o, "visibility");
|
||||
if (o.ContainsKey("name_privacy")) patch.NamePrivacy = patch.ParsePrivacy(o, "name_privacy");
|
||||
if (o.ContainsKey("description_privacy")) patch.DescriptionPrivacy = patch.ParsePrivacy(o, "description_privacy");
|
||||
if (o.ContainsKey("avatar_privacy")) patch.AvatarPrivacy = patch.ParsePrivacy(o, "avatar_privacy");
|
||||
if (o.ContainsKey("birthday_privacy")) patch.BirthdayPrivacy = patch.ParsePrivacy(o, "birthday_privacy");
|
||||
if (o.ContainsKey("pronoun_privacy")) patch.PronounPrivacy = patch.ParsePrivacy(o, "pronoun_privacy");
|
||||
// if (o.ContainsKey("color_privacy")) member.ColorPrivacy = o.ParsePrivacy("member");
|
||||
if (o.ContainsKey("metadata_privacy")) patch.MetadataPrivacy = patch.ParsePrivacy(o, "metadata_privacy");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case APIVersion.V2:
|
||||
{
|
||||
|
||||
if (o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = o.Value<JArray>("proxy_tags")
|
||||
.OfType<JObject>().Select(o => new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")))
|
||||
.Where(p => p.Valid)
|
||||
.ToArray();
|
||||
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("visibility"))
|
||||
patch.Visibility = patch.ParsePrivacy(privacy, "visibility");
|
||||
|
||||
if (privacy.ContainsKey("name_privacy"))
|
||||
patch.NamePrivacy = patch.ParsePrivacy(privacy, "name_privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
if (privacy.ContainsKey("avatar_privacy"))
|
||||
patch.AvatarPrivacy = patch.ParsePrivacy(privacy, "avatar_privacy");
|
||||
|
||||
if (privacy.ContainsKey("birthday_privacy"))
|
||||
patch.BirthdayPrivacy = patch.ParsePrivacy(privacy, "birthday_privacy");
|
||||
|
||||
if (privacy.ContainsKey("pronoun_privacy"))
|
||||
patch.PronounPrivacy = patch.ParsePrivacy(privacy, "pronoun_privacy");
|
||||
|
||||
if (privacy.ContainsKey("metadata_privacy"))
|
||||
patch.MetadataPrivacy = patch.ParsePrivacy(privacy, "metadata_privacy");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return patch;
|
||||
patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (patch.Name.Value == null)
|
||||
patch.Errors.Add(new ValidationError("name", "Member name can not be set to null."));
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
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("avatar_url")) patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("birthday"))
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (Birthday.IsPresent)
|
||||
o.Add("birthday", Birthday.Value?.FormatExport());
|
||||
if (Pronouns.IsPresent)
|
||||
o.Add("pronouns", Pronouns.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (ProxyTags.IsPresent)
|
||||
{
|
||||
var tagArray = new JArray();
|
||||
foreach (var tag in ProxyTags.Value)
|
||||
tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } });
|
||||
o.Add("proxy_tags", tagArray);
|
||||
}
|
||||
|
||||
if (KeepProxy.IsPresent)
|
||||
o.Add("keep_proxy", KeepProxy.Value);
|
||||
|
||||
if (
|
||||
Visibility.IsPresent
|
||||
|| NamePrivacy.IsPresent
|
||||
|| DescriptionPrivacy.IsPresent
|
||||
|| PronounPrivacy.IsPresent
|
||||
|| BirthdayPrivacy.IsPresent
|
||||
|| AvatarPrivacy.IsPresent
|
||||
|| MetadataPrivacy.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
|
||||
if (Visibility.IsPresent)
|
||||
p.Add("visibility", Visibility.Value.ToJsonString());
|
||||
|
||||
if (NamePrivacy.IsPresent)
|
||||
p.Add("name_privacy", NamePrivacy.Value.ToJsonString());
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
if (PronounPrivacy.IsPresent)
|
||||
p.Add("pronoun_privacy", PronounPrivacy.Value.ToJsonString());
|
||||
|
||||
if (BirthdayPrivacy.IsPresent)
|
||||
p.Add("birthday_privacy", BirthdayPrivacy.Value.ToJsonString());
|
||||
|
||||
if (AvatarPrivacy.IsPresent)
|
||||
p.Add("avatar_privacy", AvatarPrivacy.Value.ToJsonString());
|
||||
|
||||
if (MetadataPrivacy.IsPresent)
|
||||
p.Add("metadata_privacy", MetadataPrivacy.Value.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
var str = o.Value<string>("birthday").NullIfEmpty();
|
||||
var res = DateTimeFormats.DateExportFormat.Parse(str);
|
||||
if (res.Success) patch.Birthday = res.Value;
|
||||
else if (str == null) patch.Birthday = null;
|
||||
else patch.Errors.Add(new ValidationError("birthday"));
|
||||
}
|
||||
|
||||
if (o.ContainsKey("pronouns")) patch.Pronouns = o.Value<string>("pronouns").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("keep_proxy")) patch.KeepProxy = o.Value<bool>("keep_proxy");
|
||||
|
||||
switch (v)
|
||||
{
|
||||
case APIVersion.V1:
|
||||
{
|
||||
// legacy: used in old export files and APIv1
|
||||
if (o.ContainsKey("prefix") || o.ContainsKey("suffix") && !o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = new[] { new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")) };
|
||||
else if (o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = o.Value<JArray>("proxy_tags")
|
||||
.OfType<JObject>().Select(o =>
|
||||
new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")))
|
||||
.Where(p => p.Valid)
|
||||
.ToArray();
|
||||
|
||||
if (o.ContainsKey("privacy"))
|
||||
{
|
||||
var plevel = patch.ParsePrivacy(o, "privacy");
|
||||
|
||||
patch.Visibility = plevel;
|
||||
patch.NamePrivacy = plevel;
|
||||
patch.AvatarPrivacy = plevel;
|
||||
patch.DescriptionPrivacy = plevel;
|
||||
patch.BirthdayPrivacy = plevel;
|
||||
patch.PronounPrivacy = plevel;
|
||||
// member.ColorPrivacy = plevel;
|
||||
patch.MetadataPrivacy = plevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (o.ContainsKey("visibility")) patch.Visibility = patch.ParsePrivacy(o, "visibility");
|
||||
if (o.ContainsKey("name_privacy")) patch.NamePrivacy = patch.ParsePrivacy(o, "name_privacy");
|
||||
if (o.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(o, "description_privacy");
|
||||
if (o.ContainsKey("avatar_privacy"))
|
||||
patch.AvatarPrivacy = patch.ParsePrivacy(o, "avatar_privacy");
|
||||
if (o.ContainsKey("birthday_privacy"))
|
||||
patch.BirthdayPrivacy = patch.ParsePrivacy(o, "birthday_privacy");
|
||||
if (o.ContainsKey("pronoun_privacy"))
|
||||
patch.PronounPrivacy = patch.ParsePrivacy(o, "pronoun_privacy");
|
||||
// if (o.ContainsKey("color_privacy")) member.ColorPrivacy = o.ParsePrivacy("member");
|
||||
if (o.ContainsKey("metadata_privacy"))
|
||||
patch.MetadataPrivacy = patch.ParsePrivacy(o, "metadata_privacy");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case APIVersion.V2:
|
||||
{
|
||||
if (o.ContainsKey("proxy_tags"))
|
||||
patch.ProxyTags = o.Value<JArray>("proxy_tags")
|
||||
.OfType<JObject>().Select(o =>
|
||||
new ProxyTag(o.Value<string>("prefix"), o.Value<string>("suffix")))
|
||||
.Where(p => p.Valid)
|
||||
.ToArray();
|
||||
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("visibility"))
|
||||
patch.Visibility = patch.ParsePrivacy(privacy, "visibility");
|
||||
|
||||
if (privacy.ContainsKey("name_privacy"))
|
||||
patch.NamePrivacy = patch.ParsePrivacy(privacy, "name_privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
if (privacy.ContainsKey("avatar_privacy"))
|
||||
patch.AvatarPrivacy = patch.ParsePrivacy(privacy, "avatar_privacy");
|
||||
|
||||
if (privacy.ContainsKey("birthday_privacy"))
|
||||
patch.BirthdayPrivacy = patch.ParsePrivacy(privacy, "birthday_privacy");
|
||||
|
||||
if (privacy.ContainsKey("pronoun_privacy"))
|
||||
patch.PronounPrivacy = patch.ParsePrivacy(privacy, "pronoun_privacy");
|
||||
|
||||
if (privacy.ContainsKey("metadata_privacy"))
|
||||
patch.MetadataPrivacy = patch.ParsePrivacy(privacy, "metadata_privacy");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (Birthday.IsPresent)
|
||||
o.Add("birthday", Birthday.Value?.FormatExport());
|
||||
if (Pronouns.IsPresent)
|
||||
o.Add("pronouns", Pronouns.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (ProxyTags.IsPresent)
|
||||
{
|
||||
var tagArray = new JArray();
|
||||
foreach (var tag in ProxyTags.Value)
|
||||
tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } });
|
||||
o.Add("proxy_tags", tagArray);
|
||||
}
|
||||
|
||||
if (KeepProxy.IsPresent)
|
||||
o.Add("keep_proxy", KeepProxy.Value);
|
||||
|
||||
if (
|
||||
Visibility.IsPresent
|
||||
|| NamePrivacy.IsPresent
|
||||
|| DescriptionPrivacy.IsPresent
|
||||
|| PronounPrivacy.IsPresent
|
||||
|| BirthdayPrivacy.IsPresent
|
||||
|| AvatarPrivacy.IsPresent
|
||||
|| MetadataPrivacy.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
|
||||
if (Visibility.IsPresent)
|
||||
p.Add("visibility", Visibility.Value.ToJsonString());
|
||||
|
||||
if (NamePrivacy.IsPresent)
|
||||
p.Add("name_privacy", NamePrivacy.Value.ToJsonString());
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
if (PronounPrivacy.IsPresent)
|
||||
p.Add("pronoun_privacy", PronounPrivacy.Value.ToJsonString());
|
||||
|
||||
if (BirthdayPrivacy.IsPresent)
|
||||
p.Add("birthday_privacy", BirthdayPrivacy.Value.ToJsonString());
|
||||
|
||||
if (AvatarPrivacy.IsPresent)
|
||||
p.Add("avatar_privacy", AvatarPrivacy.Value.ToJsonString());
|
||||
|
||||
if (MetadataPrivacy.IsPresent)
|
||||
p.Add("metadata_privacy", MetadataPrivacy.Value.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
@@ -1,46 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public abstract class PatchObject
|
||||
{
|
||||
public abstract class PatchObject
|
||||
public List<ValidationError> Errors = new();
|
||||
public abstract Query Apply(Query q);
|
||||
|
||||
public void AssertIsValid() { }
|
||||
|
||||
protected void AssertValid(string input, string name, int maxLength, Func<string, bool>? validate = null)
|
||||
{
|
||||
public List<ValidationError> Errors = new();
|
||||
public abstract Query Apply(Query q);
|
||||
if (input.Length > maxLength)
|
||||
Errors.Add(new FieldTooLongError(name, maxLength, input.Length));
|
||||
if (validate != null && !validate(input))
|
||||
Errors.Add(new ValidationError(name));
|
||||
}
|
||||
|
||||
public void AssertIsValid() { }
|
||||
protected void AssertValid(string input, string name, string pattern)
|
||||
{
|
||||
if (!Regex.IsMatch(input, pattern))
|
||||
Errors.Add(new ValidationError(name));
|
||||
}
|
||||
|
||||
protected void AssertValid(string input, string name, int maxLength, Func<string, bool>? validate = null)
|
||||
{
|
||||
if (input.Length > maxLength)
|
||||
Errors.Add(new FieldTooLongError(name, maxLength, input.Length));
|
||||
if (validate != null && !validate(input))
|
||||
Errors.Add(new ValidationError(name));
|
||||
}
|
||||
public PrivacyLevel ParsePrivacy(JObject o, string propertyName)
|
||||
{
|
||||
var input = o.Value<string>(propertyName);
|
||||
|
||||
protected void AssertValid(string input, string name, string pattern)
|
||||
{
|
||||
if (!Regex.IsMatch(input, pattern))
|
||||
Errors.Add(new ValidationError(name));
|
||||
}
|
||||
if (input == null) return PrivacyLevel.Public;
|
||||
if (input == "") return PrivacyLevel.Private;
|
||||
if (input == "private") return PrivacyLevel.Private;
|
||||
if (input == "public") return PrivacyLevel.Public;
|
||||
|
||||
public PrivacyLevel ParsePrivacy(JObject o, string propertyName)
|
||||
{
|
||||
var input = o.Value<string>(propertyName);
|
||||
|
||||
if (input == null) return PrivacyLevel.Public;
|
||||
if (input == "") return PrivacyLevel.Private;
|
||||
if (input == "private") return PrivacyLevel.Private;
|
||||
if (input == "public") return PrivacyLevel.Public;
|
||||
|
||||
Errors.Add(new ValidationError(propertyName));
|
||||
// unused, but the compiler will complain if this isn't here
|
||||
return PrivacyLevel.Private;
|
||||
}
|
||||
Errors.Add(new ValidationError(propertyName));
|
||||
// unused, but the compiler will complain if this isn't here
|
||||
return PrivacyLevel.Private;
|
||||
}
|
||||
}
|
@@ -4,80 +4,79 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class SystemGuildPatch: PatchObject
|
||||
{
|
||||
public class SystemGuildPatch: PatchObject
|
||||
public Partial<bool> ProxyEnabled { get; set; }
|
||||
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
|
||||
public Partial<MemberId?> AutoproxyMember { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<bool?> TagEnabled { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("proxy_enabled", ProxyEnabled)
|
||||
.With("autoproxy_mode", AutoproxyMode)
|
||||
.With("autoproxy_member", AutoproxyMember)
|
||||
.With("tag", Tag)
|
||||
.With("tag_enabled", TagEnabled)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
public Partial<bool> ProxyEnabled { get; set; }
|
||||
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
|
||||
public Partial<MemberId?> AutoproxyMember { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<bool?> TagEnabled { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("proxy_enabled", ProxyEnabled)
|
||||
.With("autoproxy_mode", AutoproxyMode)
|
||||
.With("autoproxy_member", AutoproxyMember)
|
||||
.With("tag", Tag)
|
||||
.With("tag_enabled", TagEnabled)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (Tag.Value != null)
|
||||
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
|
||||
}
|
||||
if (Tag.Value != null)
|
||||
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
public static SystemGuildPatch FromJson(JObject o, MemberId? memberId)
|
||||
public static SystemGuildPatch FromJson(JObject o, MemberId? memberId)
|
||||
{
|
||||
var patch = new SystemGuildPatch();
|
||||
|
||||
if (o.ContainsKey("proxying_enabled") && o["proxying_enabled"].Type != JTokenType.Null)
|
||||
patch.ProxyEnabled = o.Value<bool>("proxying_enabled");
|
||||
|
||||
if (o.ContainsKey("autoproxy_mode"))
|
||||
{
|
||||
var patch = new SystemGuildPatch();
|
||||
|
||||
if (o.ContainsKey("proxying_enabled") && o["proxying_enabled"].Type != JTokenType.Null)
|
||||
patch.ProxyEnabled = o.Value<bool>("proxying_enabled");
|
||||
|
||||
if (o.ContainsKey("autoproxy_mode"))
|
||||
{
|
||||
var (val, err) = o["autoproxy_mode"].ParseAutoproxyMode();
|
||||
if (err != null)
|
||||
patch.Errors.Add(err);
|
||||
else
|
||||
patch.AutoproxyMode = val.Value;
|
||||
}
|
||||
|
||||
patch.AutoproxyMember = memberId;
|
||||
|
||||
if (o.ContainsKey("tag"))
|
||||
patch.Tag = o.Value<string>("tag").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("tag_enabled") && o["tag_enabled"].Type != JTokenType.Null)
|
||||
patch.TagEnabled = o.Value<bool>("tag_enabled");
|
||||
|
||||
return patch;
|
||||
var (val, err) = o["autoproxy_mode"].ParseAutoproxyMode();
|
||||
if (err != null)
|
||||
patch.Errors.Add(err);
|
||||
else
|
||||
patch.AutoproxyMode = val.Value;
|
||||
}
|
||||
|
||||
public JObject ToJson(string memberRef, ulong guild_id)
|
||||
{
|
||||
var o = new JObject();
|
||||
patch.AutoproxyMember = memberId;
|
||||
|
||||
o.Add("guild_id", guild_id.ToString());
|
||||
if (o.ContainsKey("tag"))
|
||||
patch.Tag = o.Value<string>("tag").NullIfEmpty();
|
||||
|
||||
if (ProxyEnabled.IsPresent)
|
||||
o.Add("proxying_enabled", ProxyEnabled.Value);
|
||||
if (o.ContainsKey("tag_enabled") && o["tag_enabled"].Type != JTokenType.Null)
|
||||
patch.TagEnabled = o.Value<bool>("tag_enabled");
|
||||
|
||||
if (AutoproxyMode.IsPresent)
|
||||
o.Add("autoproxy_mode", AutoproxyMode.Value.ToString().ToLower());
|
||||
return patch;
|
||||
}
|
||||
|
||||
if (AutoproxyMember.IsPresent)
|
||||
o.Add("autoproxy_member", memberRef);
|
||||
public JObject ToJson(string memberRef, ulong guild_id)
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (Tag.IsPresent)
|
||||
o.Add("tag", Tag.Value);
|
||||
o.Add("guild_id", guild_id.ToString());
|
||||
|
||||
if (TagEnabled.IsPresent)
|
||||
o.Add("tag_enabled", TagEnabled.Value);
|
||||
if (ProxyEnabled.IsPresent)
|
||||
o.Add("proxying_enabled", ProxyEnabled.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
if (AutoproxyMode.IsPresent)
|
||||
o.Add("autoproxy_mode", AutoproxyMode.Value.ToString().ToLower());
|
||||
|
||||
if (AutoproxyMember.IsPresent)
|
||||
o.Add("autoproxy_member", memberRef);
|
||||
|
||||
if (Tag.IsPresent)
|
||||
o.Add("tag", Tag.Value);
|
||||
|
||||
if (TagEnabled.IsPresent)
|
||||
o.Add("tag_enabled", TagEnabled.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
@@ -1,186 +1,185 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class SystemPatch: PatchObject
|
||||
{
|
||||
public class SystemPatch: PatchObject
|
||||
public Partial<string?> Name { get; set; }
|
||||
public Partial<string?> Hid { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
public Partial<string?> Token { get; set; }
|
||||
public Partial<string?> WebhookUrl { get; set; }
|
||||
public Partial<string?> WebhookToken { get; set; }
|
||||
public Partial<string> UiTz { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MemberListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> GroupListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontHistoryPrivacy { get; set; }
|
||||
public Partial<bool> PingsEnabled { get; set; }
|
||||
public Partial<int?> LatchTimeout { get; set; }
|
||||
public Partial<int?> MemberLimitOverride { get; set; }
|
||||
public Partial<int?> GroupLimitOverride { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("description", Description)
|
||||
.With("tag", Tag)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("token", Token)
|
||||
.With("webhook_url", WebhookUrl)
|
||||
.With("webhook_token", WebhookToken)
|
||||
.With("ui_tz", UiTz)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("member_list_privacy", MemberListPrivacy)
|
||||
.With("group_list_privacy", GroupListPrivacy)
|
||||
.With("front_privacy", FrontPrivacy)
|
||||
.With("front_history_privacy", FrontHistoryPrivacy)
|
||||
.With("pings_enabled", PingsEnabled)
|
||||
.With("latch_timeout", LatchTimeout)
|
||||
.With("member_limit_override", MemberLimitOverride)
|
||||
.With("group_limit_override", GroupLimitOverride)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
public Partial<string?> Name { get; set; }
|
||||
public Partial<string?> Hid { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
public Partial<string?> Token { get; set; }
|
||||
public Partial<string?> WebhookUrl { get; set; }
|
||||
public Partial<string?> WebhookToken { get; set; }
|
||||
public Partial<string> UiTz { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MemberListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> GroupListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontHistoryPrivacy { get; set; }
|
||||
public Partial<bool> PingsEnabled { get; set; }
|
||||
public Partial<int?> LatchTimeout { get; set; }
|
||||
public Partial<int?> MemberLimitOverride { get; set; }
|
||||
public Partial<int?> GroupLimitOverride { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
.With("hid", Hid)
|
||||
.With("description", Description)
|
||||
.With("tag", Tag)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("token", Token)
|
||||
.With("webhook_url", WebhookUrl)
|
||||
.With("webhook_token", WebhookToken)
|
||||
.With("ui_tz", UiTz)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("member_list_privacy", MemberListPrivacy)
|
||||
.With("group_list_privacy", GroupListPrivacy)
|
||||
.With("front_privacy", FrontPrivacy)
|
||||
.With("front_history_privacy", FrontHistoryPrivacy)
|
||||
.With("pings_enabled", PingsEnabled)
|
||||
.With("latch_timeout", LatchTimeout)
|
||||
.With("member_limit_override", MemberLimitOverride)
|
||||
.With("group_limit_override", GroupLimitOverride)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxSystemNameLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
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 (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
if (UiTz.IsPresent && DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz.Value) == null)
|
||||
Errors.Add(new ValidationError("timezone"));
|
||||
}
|
||||
if (Name.Value != null)
|
||||
AssertValid(Name.Value, "name", Limits.MaxSystemNameLength);
|
||||
if (Description.Value != null)
|
||||
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
|
||||
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 (BannerImage.Value != null)
|
||||
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
if (UiTz.IsPresent && DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz.Value) == null)
|
||||
Errors.Add(new ValidationError("timezone"));
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
|
||||
public static SystemPatch FromJSON(JObject o, APIVersion v = APIVersion.V1)
|
||||
public static SystemPatch FromJSON(JObject o, APIVersion v = APIVersion.V1)
|
||||
{
|
||||
var patch = new SystemPatch();
|
||||
if (o.ContainsKey("name")) patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("tag")) patch.Tag = o.Value<string>("tag").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();
|
||||
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty();
|
||||
if (o.ContainsKey("timezone")) patch.UiTz = o.Value<string>("timezone") ?? "UTC";
|
||||
|
||||
switch (v)
|
||||
{
|
||||
var patch = new SystemPatch();
|
||||
if (o.ContainsKey("name")) patch.Name = o.Value<string>("name").NullIfEmpty();
|
||||
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
|
||||
if (o.ContainsKey("tag")) patch.Tag = o.Value<string>("tag").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();
|
||||
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty();
|
||||
if (o.ContainsKey("timezone")) patch.UiTz = o.Value<string>("timezone") ?? "UTC";
|
||||
case APIVersion.V1:
|
||||
{
|
||||
if (o.ContainsKey("tz")) patch.UiTz = o.Value<string>("tz") ?? "UTC";
|
||||
|
||||
switch (v)
|
||||
{
|
||||
case APIVersion.V1:
|
||||
if (o.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(o, "description_privacy");
|
||||
if (o.ContainsKey("member_list_privacy"))
|
||||
patch.MemberListPrivacy = patch.ParsePrivacy(o, "member_list_privacy");
|
||||
if (o.ContainsKey("front_privacy")) patch.FrontPrivacy = patch.ParsePrivacy(o, "front_privacy");
|
||||
if (o.ContainsKey("front_history_privacy"))
|
||||
patch.FrontHistoryPrivacy = patch.ParsePrivacy(o, "front_history_privacy");
|
||||
|
||||
break;
|
||||
}
|
||||
case APIVersion.V2:
|
||||
{
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
if (o.ContainsKey("tz")) patch.UiTz = o.Value<string>("tz") ?? "UTC";
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (o.ContainsKey("description_privacy")) patch.DescriptionPrivacy = patch.ParsePrivacy(o, "description_privacy");
|
||||
if (o.ContainsKey("member_list_privacy")) patch.MemberListPrivacy = patch.ParsePrivacy(o, "member_list_privacy");
|
||||
if (o.ContainsKey("front_privacy")) patch.FrontPrivacy = patch.ParsePrivacy(o, "front_privacy");
|
||||
if (o.ContainsKey("front_history_privacy")) patch.FrontHistoryPrivacy = patch.ParsePrivacy(o, "front_history_privacy");
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
break;
|
||||
if (privacy.ContainsKey("member_list_privacy"))
|
||||
patch.MemberListPrivacy = patch.ParsePrivacy(privacy, "member_list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("group_list_privacy"))
|
||||
patch.GroupListPrivacy = patch.ParsePrivacy(privacy, "group_list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("front_privacy"))
|
||||
patch.FrontPrivacy = patch.ParsePrivacy(privacy, "front_privacy");
|
||||
|
||||
if (privacy.ContainsKey("front_history_privacy"))
|
||||
patch.FrontHistoryPrivacy = patch.ParsePrivacy(privacy, "front_history_privacy");
|
||||
}
|
||||
case APIVersion.V2:
|
||||
{
|
||||
if (o.ContainsKey("privacy") && o["privacy"].Type != JTokenType.Null)
|
||||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
if (privacy.ContainsKey("member_list_privacy"))
|
||||
patch.MemberListPrivacy = patch.ParsePrivacy(privacy, "member_list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("group_list_privacy"))
|
||||
patch.GroupListPrivacy = patch.ParsePrivacy(privacy, "group_list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("front_privacy"))
|
||||
patch.FrontPrivacy = patch.ParsePrivacy(privacy, "front_privacy");
|
||||
|
||||
if (privacy.ContainsKey("front_history_privacy"))
|
||||
patch.FrontHistoryPrivacy = patch.ParsePrivacy(privacy, "front_history_privacy");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return patch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
return patch;
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (Tag.IsPresent)
|
||||
o.Add("tag", Tag.Value);
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (UiTz.IsPresent)
|
||||
o.Add("timezone", UiTz.Value);
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
|| MemberListPrivacy.IsPresent
|
||||
|| GroupListPrivacy.IsPresent
|
||||
|| FrontPrivacy.IsPresent
|
||||
|| FrontHistoryPrivacy.IsPresent
|
||||
)
|
||||
{
|
||||
var o = new JObject();
|
||||
var p = new JObject();
|
||||
|
||||
if (Name.IsPresent)
|
||||
o.Add("name", Name.Value);
|
||||
if (Hid.IsPresent)
|
||||
o.Add("id", Hid.Value);
|
||||
if (Description.IsPresent)
|
||||
o.Add("description", Description.Value);
|
||||
if (Tag.IsPresent)
|
||||
o.Add("tag", Tag.Value);
|
||||
if (AvatarUrl.IsPresent)
|
||||
o.Add("avatar_url", AvatarUrl.Value);
|
||||
if (BannerImage.IsPresent)
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (UiTz.IsPresent)
|
||||
o.Add("timezone", UiTz.Value);
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
|| MemberListPrivacy.IsPresent
|
||||
|| GroupListPrivacy.IsPresent
|
||||
|| FrontPrivacy.IsPresent
|
||||
|| FrontHistoryPrivacy.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
if (MemberListPrivacy.IsPresent)
|
||||
p.Add("member_list_privacy", MemberListPrivacy.Value.ToJsonString());
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
if (GroupListPrivacy.IsPresent)
|
||||
p.Add("group_list_privacy", GroupListPrivacy.Value.ToJsonString());
|
||||
|
||||
if (MemberListPrivacy.IsPresent)
|
||||
p.Add("member_list_privacy", MemberListPrivacy.Value.ToJsonString());
|
||||
if (FrontPrivacy.IsPresent)
|
||||
p.Add("front_privacy", FrontPrivacy.Value.ToJsonString());
|
||||
|
||||
if (GroupListPrivacy.IsPresent)
|
||||
p.Add("group_list_privacy", GroupListPrivacy.Value.ToJsonString());
|
||||
if (FrontHistoryPrivacy.IsPresent)
|
||||
p.Add("front_history_privacy", FrontHistoryPrivacy.Value.ToJsonString());
|
||||
|
||||
if (FrontPrivacy.IsPresent)
|
||||
p.Add("front_privacy", FrontPrivacy.Value.ToJsonString());
|
||||
|
||||
if (FrontHistoryPrivacy.IsPresent)
|
||||
p.Add("front_history_privacy", FrontHistoryPrivacy.Value.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
o.Add("privacy", p);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user