2021-10-13 05:02:34 +00:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
|
2021-08-27 15:03:47 +00:00
|
|
|
namespace PluralKit.Core
|
2020-06-13 14:03:57 +00:00
|
|
|
{
|
2021-10-13 05:02:34 +00:00
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2020-08-29 11:46:27 +00:00
|
|
|
public enum AutoproxyMode
|
|
|
|
{
|
|
|
|
Off = 1,
|
|
|
|
Front = 2,
|
|
|
|
Latch = 3,
|
|
|
|
Member = 4
|
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2020-06-13 14:03:57 +00:00
|
|
|
public class SystemGuildSettings
|
|
|
|
{
|
2020-06-24 14:52:49 +00:00
|
|
|
public ulong Guild { get; }
|
|
|
|
public SystemId System { get; }
|
2020-06-13 14:03:57 +00:00
|
|
|
public bool ProxyEnabled { get; } = true;
|
|
|
|
|
|
|
|
public AutoproxyMode AutoproxyMode { get; } = AutoproxyMode.Off;
|
2020-06-14 19:37:04 +00:00
|
|
|
public MemberId? AutoproxyMember { get; }
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-25 16:30:42 +00:00
|
|
|
public string? Tag { get; }
|
2021-08-27 15:03:47 +00:00
|
|
|
public bool TagEnabled { get; }
|
2020-06-13 14:03:57 +00:00
|
|
|
}
|
2021-10-13 05:02:34 +00:00
|
|
|
|
|
|
|
public static class SystemGuildExt
|
|
|
|
{
|
|
|
|
public static JObject ToJson(this SystemGuildSettings settings, string? memberHid = null)
|
|
|
|
{
|
|
|
|
var o = new JObject();
|
|
|
|
|
|
|
|
o.Add("proxying_enabled", settings.ProxyEnabled);
|
|
|
|
o.Add("autoproxy_mode", settings.AutoproxyMode.ToString().ToLower());
|
|
|
|
o.Add("autoproxy_member", memberHid);
|
|
|
|
o.Add("tag", settings.Tag);
|
|
|
|
o.Add("tag_enabled", settings.TagEnabled);
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2021-10-13 12:37:34 +00:00
|
|
|
public static (AutoproxyMode?, ValidationError?) ParseAutoproxyMode(this JToken o)
|
2021-10-13 05:02:34 +00:00
|
|
|
{
|
|
|
|
if (o.Type == JTokenType.Null)
|
2021-10-13 12:37:34 +00:00
|
|
|
return (AutoproxyMode.Off, null);
|
2021-10-13 05:02:34 +00:00
|
|
|
else if (o.Type != JTokenType.String)
|
2021-10-13 12:37:34 +00:00
|
|
|
return (null, new ValidationError("autoproxy_mode"));
|
2021-10-13 05:02:34 +00:00
|
|
|
|
|
|
|
var value = o.Value<string>();
|
|
|
|
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case "off":
|
2021-10-13 12:37:34 +00:00
|
|
|
return (AutoproxyMode.Off, null);
|
2021-10-13 05:02:34 +00:00
|
|
|
case "front":
|
2021-10-13 12:37:34 +00:00
|
|
|
return (AutoproxyMode.Front, null);
|
2021-10-13 05:02:34 +00:00
|
|
|
case "latch":
|
2021-10-13 12:37:34 +00:00
|
|
|
return (AutoproxyMode.Latch, null);
|
2021-10-13 05:02:34 +00:00
|
|
|
case "member":
|
2021-10-13 12:37:34 +00:00
|
|
|
return (AutoproxyMode.Member, null);
|
2021-10-13 05:02:34 +00:00
|
|
|
default:
|
2021-10-13 12:37:34 +00:00
|
|
|
return (null, new ValidationError("autoproxy_mode", $"Value '{value}' is not a valid autoproxy mode."));
|
2021-10-13 05:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 14:03:57 +00:00
|
|
|
}
|