Applied codestyle to all .cs files

This commit is contained in:
Kwoth
2021-12-29 06:07:16 +01:00
parent 723447c7d4
commit 82000c97a4
543 changed files with 13221 additions and 14059 deletions

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace NadekoBot;
public sealed record SmartEmbedText : SmartText
@@ -17,12 +17,14 @@ public sealed record SmartEmbedText : SmartText
public uint Color { get; set; } = 7458112;
public bool IsValid
=> !string.IsNullOrWhiteSpace(Title) || !string.IsNullOrWhiteSpace(Description) ||
!string.IsNullOrWhiteSpace(Url) || !string.IsNullOrWhiteSpace(Thumbnail) ||
!string.IsNullOrWhiteSpace(Image) ||
(Footer != null &&
(!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
Fields is { Length: > 0 };
=> !string.IsNullOrWhiteSpace(Title)
|| !string.IsNullOrWhiteSpace(Description)
|| !string.IsNullOrWhiteSpace(Url)
|| !string.IsNullOrWhiteSpace(Thumbnail)
|| !string.IsNullOrWhiteSpace(Image)
|| (Footer != null
&& (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl)))
|| Fields is { Length: > 0 };
public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null)
{
@@ -40,9 +42,11 @@ public sealed record SmartEmbedText : SmartText
if (eb.Fields.Length > 0)
set.Fields = eb.Fields.Select(field
=> new SmartTextEmbedField() { Inline = field.Inline, Name = field.Name, Value = field.Value, }
)
.ToArray();
=> new SmartTextEmbedField
{
Inline = field.Inline, Name = field.Name, Value = field.Value
})
.ToArray();
set.Color = eb.Color?.RawValue ?? 0;
return set;
@@ -58,31 +62,24 @@ public sealed record SmartEmbedText : SmartText
if (!string.IsNullOrWhiteSpace(Description))
embed.WithDescription(Description);
if (Url != null &&
Uri.IsWellFormedUriString(Url, UriKind.Absolute))
if (Url != null && Uri.IsWellFormedUriString(Url, UriKind.Absolute))
embed.WithUrl(Url);
if (Footer != null)
{
embed.WithFooter(efb =>
{
efb.WithText(Footer.Text);
if (Uri.IsWellFormedUriString(Footer.IconUrl, UriKind.Absolute))
efb.WithIconUrl(Footer.IconUrl);
}
);
}
{
efb.WithText(Footer.Text);
if (Uri.IsWellFormedUriString(Footer.IconUrl, UriKind.Absolute))
efb.WithIconUrl(Footer.IconUrl);
});
if (Thumbnail != null &&
Uri.IsWellFormedUriString(Thumbnail, UriKind.Absolute))
if (Thumbnail != null && Uri.IsWellFormedUriString(Thumbnail, UriKind.Absolute))
embed.WithThumbnailUrl(Thumbnail);
if (Image != null &&
Uri.IsWellFormedUriString(Image, UriKind.Absolute))
if (Image != null && Uri.IsWellFormedUriString(Image, UriKind.Absolute))
embed.WithImageUrl(Image);
if (Author != null &&
!string.IsNullOrWhiteSpace(Author.Name))
if (Author != null && !string.IsNullOrWhiteSpace(Author.Name))
{
if (!Uri.IsWellFormedUriString(Author.IconUrl, UriKind.Absolute))
Author.IconUrl = null;
@@ -93,14 +90,9 @@ public sealed record SmartEmbedText : SmartText
}
if (Fields != null)
{
foreach (var f in Fields)
{
if (!string.IsNullOrWhiteSpace(f.Name) &&
!string.IsNullOrWhiteSpace(f.Value))
if (!string.IsNullOrWhiteSpace(f.Name) && !string.IsNullOrWhiteSpace(f.Value))
embed.AddField(f.Name, f.Value, f.Inline);
}
}
return embed;
}
@@ -108,12 +100,10 @@ public sealed record SmartEmbedText : SmartText
public void NormalizeFields()
{
if (Fields is { Length: > 0 })
{
foreach (var f in Fields)
{
f.Name = f.Name.TrimTo(256);
f.Value = f.Value.TrimTo(1024);
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace NadekoBot;
public sealed record SmartPlainText : SmartText
@@ -16,4 +16,4 @@ public sealed record SmartPlainText : SmartText
public override string ToString()
=> Text;
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Newtonsoft.Json;
namespace NadekoBot;
@@ -29,11 +29,8 @@ public abstract record SmartText
public static SmartText CreateFrom(string input)
{
if (string.IsNullOrWhiteSpace(input) ||
!input.TrimStart().StartsWith("{"))
{
if (string.IsNullOrWhiteSpace(input) || !input.TrimStart().StartsWith("{"))
return new SmartPlainText(input);
}
try
{
@@ -41,13 +38,10 @@ public abstract record SmartText
if (smartEmbedText is null)
throw new();
smartEmbedText.NormalizeFields();
if (!smartEmbedText.IsValid)
{
return new SmartPlainText(input);
}
if (!smartEmbedText.IsValid) return new SmartPlainText(input);
return smartEmbedText;
}
@@ -56,4 +50,4 @@ public abstract record SmartText
return new SmartPlainText(input);
}
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Newtonsoft.Json;
namespace NadekoBot;
@@ -6,7 +6,9 @@ namespace NadekoBot;
public class SmartTextEmbedAuthor
{
public string Name { get; set; }
[JsonProperty("icon_url")]
public string IconUrl { get; set; }
public string Url { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace NadekoBot;
public class SmartTextEmbedField
@@ -6,4 +6,4 @@ public class SmartTextEmbedField
public string Name { get; set; }
public string Value { get; set; }
public bool Inline { get; set; }
}
}

View File

@@ -8,6 +8,7 @@ namespace NadekoBot;
public class SmartTextEmbedFooter
{
public string Text { get; set; }
[JsonProperty("icon_url")]
public string IconUrl { get; set; }
}
}