- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -8,7 +8,5 @@ public readonly struct DapiTag
[JsonConstructor]
public DapiTag(string name)
{
Name = name;
}
=> Name = name;
}

View File

@@ -7,9 +7,7 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
protected readonly string _baseUrl;
public DapiImageDownloader(Booru booru, HttpClient http, string baseUrl) : base(booru, http)
{
_baseUrl = baseUrl;
}
=> _baseUrl = baseUrl;
public abstract Task<bool> IsTagValid(string tag, CancellationToken cancel = default);
protected async Task<bool> AllTagsValid(string[] tags, CancellationToken cancel = default)

View File

@@ -8,9 +8,7 @@ public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
public KonachanImageDownloader(HttpClient http)
: base(Booru.Konachan, http)
{
_baseUrl = "https://konachan.com";
}
=> _baseUrl = "https://konachan.com";
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
{

View File

@@ -8,9 +8,8 @@ public sealed class YandereImageDownloader : ImageDownloader<DapiImageObject>
public YandereImageDownloader(HttpClient http)
: base(Booru.Yandere, http)
{
_baseUrl = "https://yande.re";
}
=> _baseUrl = "https://yande.re";
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
{
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);

View File

@@ -25,9 +25,7 @@ public class ImageData : IComparable<ImageData>
}
public override string ToString()
{
return FileUrl;
}
=> FileUrl;
public override int GetHashCode() => FileUrl.GetHashCode();
public override bool Equals(object obj)

View File

@@ -8,11 +8,9 @@ public class Rule34Object : IImageData
public int Score { get; init; }
public ImageData ToCachedImageData(Booru type)
{
return new(
=> new(
$"https://img.rule34.xxx//images/{Directory}/{Image}",
Booru.Rule34,
Tags.Split(' '),
Score.ToString());
}
}

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Modules.Searches.Common;
using NadekoBot.Modules.Searches.Common;
using Newtonsoft.Json.Linq;
namespace NadekoBot.Modules.Nsfw;
@@ -377,7 +376,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
.Shuffle()
.Select(tag => $"[{tag.Name}]({tag.Url})")
.TakeWhile(tag => (count += tag.Length) < 1000)
.JoinWith(" ");
.Join(" ");
var embed = _eb.Create()
.WithTitle(g.Title)

View File

@@ -68,6 +68,7 @@ public class SearchImageCacher : INService
.Distinct()
.Shuffle()
.Take(50)
.ToList()
.ForEach(x => typeUsedTags.Add(x));
foreach (var img in images)

View File

@@ -53,9 +53,7 @@ public class SearchImagesService : ISearchImagesService, INService
}
private Task<UrlReply> GetNsfwImageAsync(ulong? guildId, bool forceExplicit, string[] tags, Booru dapi, CancellationToken cancel = default)
{
return GetNsfwImageAsync(guildId ?? 0, tags ?? Array.Empty<string>(), forceExplicit, dapi, cancel);
}
=> GetNsfwImageAsync(guildId ?? 0, tags ?? Array.Empty<string>(), forceExplicit, dapi, cancel);
private bool IsValidTag(string tag) => tag.All(x => x != '+' && x != '?' && x != '/'); // tags mustn't contain + or ? or /