PluralKit/PluralKit.Core/Models/Patch/GroupPatch.cs

41 lines
1.6 KiB
C#
Raw Normal View History

2020-06-29 21:51:12 +00:00
#nullable enable
using System.Text.RegularExpressions;
2020-06-29 21:51:12 +00:00
namespace PluralKit.Core
{
public class GroupPatch: PatchObject
{
public Partial<string> Name { get; set; }
2021-07-08 14:04:05 +00:00
public Partial<string> Hid { get; set; }
public Partial<string?> DisplayName { get; set; }
2020-06-29 21:51:12 +00:00
public Partial<string?> Description { get; set; }
public Partial<string?> Icon { get; set; }
2021-03-28 10:02:41 +00:00
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; }
2020-06-29 21:51:12 +00:00
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
.With("name", Name)
2021-07-08 14:04:05 +00:00
.With("hid", Hid)
.With("display_name", DisplayName)
.With("description", Description)
.With("icon", Icon)
2021-03-28 10:02:41 +00:00
.With("color", Color)
.With("description_privacy", DescriptionPrivacy)
.With("icon_privacy", IconPrivacy)
.With("list_privacy", ListPrivacy)
.With("visibility", Visibility);
public new void CheckIsValid()
{
if (Icon.Value != null && !MiscUtils.TryMatchUri(Icon.Value, out var avatarUri))
throw new InvalidPatchException("avatar_url");
if (Color.Value != null && (!Regex.IsMatch(Color.Value, "^[0-9a-fA-F]{6}$")))
throw new InvalidPatchException("color");
}
2020-06-29 21:51:12 +00:00
}
}