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;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Core;
|
|
|
|
|
|
|
|
public class SystemGuildPatch: PatchObject
|
2020-06-29 13:20:28 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
public Partial<bool> ProxyEnabled { 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("tag", Tag)
|
|
|
|
.With("tag_enabled", TagEnabled)
|
|
|
|
);
|
|
|
|
|
|
|
|
public new void AssertIsValid()
|
2020-06-29 13:20:28 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (Tag.Value != null)
|
|
|
|
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
|
|
|
|
}
|
2021-10-13 05:02:34 +00:00
|
|
|
|
|
|
|
#nullable disable
|
2022-03-22 03:43:33 +00:00
|
|
|
public static SystemGuildPatch FromJson(JObject o)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
var patch = new SystemGuildPatch();
|
2021-10-13 05:02:34 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (o.ContainsKey("proxying_enabled") && o["proxying_enabled"].Type != JTokenType.Null)
|
|
|
|
patch.ProxyEnabled = o.Value<bool>("proxying_enabled");
|
2021-10-13 05:02:34 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (o.ContainsKey("tag"))
|
|
|
|
patch.Tag = o.Value<string>("tag").NullIfEmpty();
|
2021-10-13 05:02:34 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (o.ContainsKey("tag_enabled") && o["tag_enabled"].Type != JTokenType.Null)
|
|
|
|
patch.TagEnabled = o.Value<bool>("tag_enabled");
|
2021-10-13 05:02:34 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return patch;
|
|
|
|
}
|
2021-11-02 10:08:17 +00:00
|
|
|
|
2022-03-22 03:43:33 +00:00
|
|
|
public JObject ToJson(ulong guild_id)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
var o = new JObject();
|
2021-11-02 10:08:17 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
o.Add("guild_id", guild_id.ToString());
|
2021-11-26 19:45:58 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (ProxyEnabled.IsPresent)
|
|
|
|
o.Add("proxying_enabled", ProxyEnabled.Value);
|
2021-11-02 10:08:17 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (Tag.IsPresent)
|
|
|
|
o.Add("tag", Tag.Value);
|
2021-11-02 10:08:17 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (TagEnabled.IsPresent)
|
|
|
|
o.Add("tag_enabled", TagEnabled.Value);
|
2021-11-02 10:08:17 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return o;
|
2020-06-29 13:20:28 +00:00
|
|
|
}
|
|
|
|
}
|