run dotnet format

This commit is contained in:
spiral
2021-08-27 11:03:47 -04:00
parent 05989242f9
commit ac2671452d
278 changed files with 1913 additions and 1808 deletions

View File

@@ -1,4 +1,4 @@
namespace PluralKit.Core
namespace PluralKit.Core
{
public class GuildConfig
{

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
namespace PluralKit.Core
{
public class MemberGuildSettings

View File

@@ -1,10 +1,10 @@
using System;
using System;
namespace PluralKit.Core
{
public interface INumericId<T, out TInner>: IEquatable<T>, IComparable<T>
where T: INumericId<T, TInner>
where TInner: IEquatable<TInner>, IComparable<TInner>
where T : INumericId<T, TInner>
where TInner : IEquatable<TInner>, IComparable<TInner>
{
public TInner Value { get; }
}

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
@@ -26,7 +26,7 @@ namespace PluralKit.Core
public static Partial<T> Present(T obj) => new Partial<T>(true, obj);
public static Partial<T> Absent = new Partial<T>(false, default!);
public IEnumerable<T> ToArray() => IsPresent ? new[] {Value} : new T[0];
public IEnumerable<T> ToArray() => IsPresent ? new[] { Value } : new T[0];
public IEnumerator<T> GetEnumerator() => ToArray().GetEnumerator();
@@ -52,7 +52,7 @@ namespace PluralKit.Core
return typeof(Partial<>)
.MakeGenericType(innerType)
.GetMethod(nameof(Partial<object>.Present))!
.Invoke(null, new[] {innerValue});
.Invoke(null, new[] { innerValue });
}
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) =>

View File

@@ -1,4 +1,4 @@
using NodaTime;
using NodaTime;
@@ -24,7 +24,7 @@ namespace PluralKit.Core
public static bool operator !=(GroupId left, GroupId right) => !left.Equals(right);
public int CompareTo(GroupId other) => Value.CompareTo(other.Value);
public override string ToString() => $"Group #{Value}";
}
@@ -46,7 +46,7 @@ namespace PluralKit.Core
public PrivacyLevel IconPrivacy { get; private set; }
public PrivacyLevel ListPrivacy { get; private set; }
public PrivacyLevel Visibility { get; private set; }
public Instant Created { get; private set; }
}
@@ -54,7 +54,7 @@ namespace PluralKit.Core
{
public static string? DescriptionFor(this PKGroup group, LookupContext ctx) =>
group.DescriptionPrivacy.Get(ctx, group.Description);
public static string? IconFor(this PKGroup group, LookupContext ctx) =>
group.IconPrivacy.Get(ctx, group.Icon?.TryGetCleanCdnUrl());
}

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
@@ -7,7 +7,8 @@ using Newtonsoft.Json.Linq;
using NodaTime;
using NodaTime.Text;
namespace PluralKit.Core {
namespace PluralKit.Core
{
public readonly struct MemberId: INumericId<MemberId, int>
{
public int Value { get; }
@@ -28,7 +29,7 @@ namespace PluralKit.Core {
public static bool operator !=(MemberId left, MemberId right) => !left.Equals(right);
public int CompareTo(MemberId other) => Value.CompareTo(other.Value);
public override string ToString() => $"Member #{Value}";
}
@@ -61,10 +62,11 @@ namespace PluralKit.Core {
public PrivacyLevel PronounPrivacy { get; private set; }
public PrivacyLevel MetadataPrivacy { get; private set; }
// public PrivacyLevel ColorPrivacy { get; private set; }
/// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" or "0004" is hidden
/// Before Feb 10 2020, the sentinel year was 0001, now it is 0004.
[JsonIgnore] public string BirthdayString
[JsonIgnore]
public string BirthdayString
{
get
{
@@ -97,7 +99,7 @@ namespace PluralKit.Core {
member.PronounPrivacy.Get(ctx, member.Pronouns);
public static Instant? CreatedFor(this PKMember member, LookupContext ctx) =>
member.MetadataPrivacy.Get(ctx, (Instant?) member.Created);
member.MetadataPrivacy.Get(ctx, (Instant?)member.Created);
public static int MessageCountFor(this PKMember member, LookupContext ctx) =>
member.MetadataPrivacy.Get(ctx, member.MessageCount);
@@ -105,7 +107,7 @@ namespace PluralKit.Core {
public static JObject ToJson(this PKMember member, LookupContext ctx, bool needsLegacyProxyTags = false)
{
var includePrivacy = ctx == LookupContext.ByOwner;
var o = new JObject();
o.Add("id", member.Hid);
o.Add("name", member.NameFor(ctx));
@@ -117,14 +119,14 @@ namespace PluralKit.Core {
o.Add("avatar_url", member.AvatarFor(ctx).TryGetCleanCdnUrl());
o.Add("banner", member.DescriptionPrivacy.Get(ctx, member.BannerImage).TryGetCleanCdnUrl());
o.Add("description", member.DescriptionFor(ctx));
var tagArray = new JArray();
foreach (var tag in member.ProxyTags)
tagArray.Add(new JObject {{"prefix", tag.Prefix}, {"suffix", tag.Suffix}});
foreach (var tag in member.ProxyTags)
tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } });
o.Add("proxy_tags", tagArray);
o.Add("keep_proxy", member.KeepProxy);
o.Add("privacy", includePrivacy ? (member.MemberVisibility.LevelName()) : null);
o.Add("visibility", includePrivacy ? (member.MemberVisibility.LevelName()) : null);

View File

@@ -1,4 +1,4 @@
using NodaTime;
using NodaTime;
namespace PluralKit.Core
{

View File

@@ -1,8 +1,9 @@
using NodaTime;
using NodaTime;
namespace PluralKit.Core {
namespace PluralKit.Core
{
public readonly struct SwitchId: INumericId<SwitchId, int>
{
@@ -24,7 +25,7 @@ namespace PluralKit.Core {
public static bool operator !=(SwitchId left, SwitchId right) => !left.Equals(right);
public int CompareTo(SwitchId other) => Value.CompareTo(other.Value);
public override string ToString() => $"Switch #{Value}";
}

View File

@@ -1,11 +1,12 @@
using Dapper.Contrib.Extensions;
using Dapper.Contrib.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NodaTime;
namespace PluralKit.Core {
namespace PluralKit.Core
{
public readonly struct SystemId: INumericId<SystemId, int>
{
@@ -46,14 +47,14 @@ namespace PluralKit.Core {
public string UiTz { get; set; }
public bool PingsEnabled { get; }
public int? LatchTimeout { get; }
public PrivacyLevel DescriptionPrivacy { get; }
public PrivacyLevel MemberListPrivacy { get;}
public PrivacyLevel DescriptionPrivacy { get; }
public PrivacyLevel MemberListPrivacy { get; }
public PrivacyLevel FrontPrivacy { get; }
public PrivacyLevel FrontHistoryPrivacy { get; }
public PrivacyLevel GroupListPrivacy { get; }
public int? MemberLimitOverride { get; }
public int? GroupLimitOverride { get; }
[JsonIgnore] public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
}
@@ -82,4 +83,4 @@ namespace PluralKit.Core {
return o;
}
}
}
}

View File

@@ -1,10 +1,10 @@
namespace PluralKit.Core
{
public class AccountPatch: PatchObject
{
public Partial<bool> AllowAutoproxy { get; set; }
public class AccountPatch: PatchObject
{
public Partial<bool> AllowAutoproxy { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
.With("allow_autoproxy", AllowAutoproxy);
}
}
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
.With("allow_autoproxy", AllowAutoproxy);
}
}

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Text.RegularExpressions;
namespace PluralKit.Core
@@ -12,7 +12,7 @@ namespace PluralKit.Core
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; }

View File

@@ -1,4 +1,4 @@
namespace PluralKit.Core
namespace PluralKit.Core
{
public class GuildPatch: PatchObject
{

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
namespace PluralKit.Core
{
public class MemberGuildPatch: PatchObject

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Linq;
using System.Text.RegularExpressions;
@@ -83,9 +83,9 @@ namespace PluralKit.Core
{
var patch = new MemberPatch();
if (o.ContainsKey("name") && o["name"].Type == JTokenType.Null)
if (o.ContainsKey("name") && o["name"].Type == JTokenType.Null)
throw new ValidationError("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();
@@ -107,17 +107,17 @@ namespace PluralKit.Core
// 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"))};
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")) //TODO: Deprecate this completely in api v2
if (o.ContainsKey("privacy")) //TODO: Deprecate this completely in api v2
{
var plevel = o.ParsePrivacy("privacy");
patch.Visibility = plevel;
patch.NamePrivacy = plevel;
patch.AvatarPrivacy = plevel;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Text.RegularExpressions;
namespace PluralKit.Core
@@ -7,7 +7,7 @@ namespace PluralKit.Core
{
public abstract UpdateQueryBuilder Apply(UpdateQueryBuilder b);
public void AssertIsValid() {}
public void AssertIsValid() { }
protected bool AssertValid(string input, string name, int maxLength, Func<string, bool>? validate = null)
{
@@ -28,7 +28,7 @@ namespace PluralKit.Core
public class ValidationError: Exception
{
public ValidationError(string message): base(message) { }
public ValidationError(string message) : base(message) { }
}
public class FieldTooLongError: ValidationError
@@ -37,7 +37,7 @@ namespace PluralKit.Core
public int MaxLength;
public int ActualLength;
public FieldTooLongError(string name, int maxLength, int actualLength):
public FieldTooLongError(string name, int maxLength, int actualLength) :
base($"{name} too long ({actualLength} > {maxLength})")
{
Name = name;

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
namespace PluralKit.Core
{
public class SystemGuildPatch: PatchObject

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Text.RegularExpressions;
@@ -82,7 +82,7 @@ namespace PluralKit.Core
// legacy: APIv1 uses "tz" instead of "timezone"
// todo: remove in APIv2
if (o.ContainsKey("tz")) patch.UiTz = o.Value<string>("tz") ?? "UTC";
if (o.ContainsKey("description_privacy")) patch.DescriptionPrivacy = o.ParsePrivacy("description_privacy");
if (o.ContainsKey("member_list_privacy")) patch.MemberListPrivacy = o.ParsePrivacy("member_list_privacy");
if (o.ContainsKey("front_privacy")) patch.FrontPrivacy = o.ParsePrivacy("front_privacy");

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace PluralKit.Core
{
@@ -9,7 +9,7 @@ namespace PluralKit.Core
List,
Visibility
}
public static class GroupPrivacyUtils
{
public static GroupPatch WithPrivacy(this GroupPatch group, GroupPrivacySubject subject, PrivacyLevel level)
@@ -23,14 +23,14 @@ namespace PluralKit.Core
GroupPrivacySubject.Visibility => group.Visibility = level,
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
return group;
}
public static GroupPatch WithAllPrivacy(this GroupPatch member, PrivacyLevel level)
{
foreach (var subject in Enum.GetValues(typeof(GroupPrivacySubject)))
member.WithPrivacy((GroupPrivacySubject) subject, level);
member.WithPrivacy((GroupPrivacySubject)subject, level);
return member;
}

View File

@@ -1,4 +1,4 @@
namespace PluralKit.Core
namespace PluralKit.Core
{
public enum LookupContext
{

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace PluralKit.Core
{
@@ -29,14 +29,14 @@ namespace PluralKit.Core
MemberPrivacySubject.Visibility => member.Visibility = level,
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
return member;
}
public static MemberPatch WithAllPrivacy(this MemberPatch member, PrivacyLevel level)
{
foreach (var subject in Enum.GetValues(typeof(MemberPrivacySubject)))
member.WithPrivacy((MemberPrivacySubject) subject, level);
member.WithPrivacy((MemberPrivacySubject)subject, level);
return member;
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Newtonsoft.Json.Linq;
@@ -9,18 +9,18 @@ namespace PluralKit.Core
Public = 1,
Private = 2
}
public static class PrivacyLevelExt
{
public static bool CanAccess(this PrivacyLevel level, LookupContext ctx) =>
level == PrivacyLevel.Public || ctx == LookupContext.ByOwner;
public static string LevelName(this PrivacyLevel level) =>
public static string LevelName(this PrivacyLevel level) =>
level == PrivacyLevel.Public ? "public" : "private";
public static T Get<T>(this PrivacyLevel level, LookupContext ctx, T input, T fallback = default) =>
level.CanAccess(ctx) ? input : fallback;
public static string Explanation(this PrivacyLevel level) =>
level switch
{
@@ -40,7 +40,7 @@ namespace PluralKit.Core
output = input;
return true;
}
public static string ToJsonString(this PrivacyLevel level) => level.LevelName();
public static PrivacyLevel ParsePrivacy(this JObject o, string propertyName)

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace PluralKit.Core
{
@@ -25,17 +25,17 @@ namespace PluralKit.Core
SystemPrivacySubject.GroupList => system.GroupListPrivacy = level,
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
return system;
}
public static SystemPatch WithAllPrivacy(this SystemPatch system, PrivacyLevel level)
{
foreach (var subject in Enum.GetValues(typeof(SystemPrivacySubject)))
WithPrivacy(system, (SystemPrivacySubject) subject, level);
WithPrivacy(system, (SystemPrivacySubject)subject, level);
return system;
}
public static bool TryParseSystemPrivacy(string input, out SystemPrivacySubject subject)
{
switch (input.ToLowerInvariant())
@@ -45,7 +45,7 @@ namespace PluralKit.Core
case "text":
case "info":
subject = SystemPrivacySubject.Description;
break;
break;
case "members":
case "memberlist":
case "list":
@@ -72,6 +72,6 @@ namespace PluralKit.Core
return false;
}
return true;
}
}
}
}

View File

@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace PluralKit.Core
{
@@ -14,7 +14,8 @@ namespace PluralKit.Core
[JsonProperty("prefix")] public string Prefix { get; set; }
[JsonProperty("suffix")] public string Suffix { get; set; }
[JsonIgnore] public bool Valid =>
[JsonIgnore]
public bool Valid =>
Prefix != null || Suffix != null
&& ProxyString.Length <= Limits.MaxProxyTagLength;
@@ -35,4 +36,4 @@ namespace PluralKit.Core
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
namespace PluralKit.Core
namespace PluralKit.Core
{
public enum AutoproxyMode
{
@@ -7,7 +7,7 @@
Latch = 3,
Member = 4
}
public class SystemGuildSettings
{
public ulong Guild { get; }
@@ -16,8 +16,8 @@
public AutoproxyMode AutoproxyMode { get; } = AutoproxyMode.Off;
public MemberId? AutoproxyMember { get; }
public string? Tag { get; }
public bool TagEnabled { get; }
public bool TagEnabled { get; }
}
}