2021-08-27 15:03:47 +00:00
|
|
|
#nullable enable
|
2021-09-30 01:51:38 +00:00
|
|
|
|
2021-10-13 05:02:34 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2021-09-30 01:51:38 +00:00
|
|
|
using SqlKata;
|
|
|
|
|
2020-06-29 13:20:28 +00:00
|
|
|
namespace PluralKit.Core
|
|
|
|
{
|
|
|
|
public class SystemGuildPatch: PatchObject
|
|
|
|
{
|
|
|
|
public Partial<bool> ProxyEnabled { get; set; }
|
|
|
|
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
|
|
|
|
public Partial<MemberId?> AutoproxyMember { get; set; }
|
2021-08-02 21:22:06 +00:00
|
|
|
public Partial<string?> Tag { get; set; }
|
|
|
|
public Partial<bool?> TagEnabled { get; set; }
|
2020-06-29 13:20:28 +00:00
|
|
|
|
2021-09-30 01:51:38 +00:00
|
|
|
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
2020-06-29 13:20:28 +00:00
|
|
|
.With("proxy_enabled", ProxyEnabled)
|
|
|
|
.With("autoproxy_mode", AutoproxyMode)
|
2021-08-02 21:22:06 +00:00
|
|
|
.With("autoproxy_member", AutoproxyMember)
|
|
|
|
.With("tag", Tag)
|
2021-09-30 01:51:38 +00:00
|
|
|
.With("tag_enabled", TagEnabled)
|
|
|
|
);
|
2021-10-13 05:02:34 +00:00
|
|
|
|
|
|
|
public new void AssertIsValid()
|
|
|
|
{
|
|
|
|
if (Tag.Value != null)
|
|
|
|
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
#nullable disable
|
|
|
|
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");
|
|
|
|
|
2021-10-13 12:37:34 +00:00
|
|
|
if (o.ContainsKey("autoproxy_mode"))
|
|
|
|
{
|
|
|
|
var (val, err) = o["autoproxy_mode"].ParseAutoproxyMode();
|
|
|
|
if (err != null)
|
|
|
|
patch.Errors.Add(err);
|
|
|
|
else
|
|
|
|
patch.AutoproxyMode = val.Value;
|
|
|
|
}
|
2021-10-13 05:02:34 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-06-29 13:20:28 +00:00
|
|
|
}
|
|
|
|
}
|