NadekoBot.Extensions should now be fully annotated with nullable reference types as well as many classes from NadekoBot.Common

This commit is contained in:
Kwoth
2021-12-28 10:44:00 +01:00
parent 0634470a8a
commit 59f5056035
543 changed files with 1895 additions and 1448 deletions

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public enum Booru
{
@@ -11,4 +12,4 @@ public enum Booru
Yandere,
Danbooru,
Sankaku
}
}

View File

@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -14,4 +15,4 @@ public class DapiImageObject : IImageData
public ImageData ToCachedImageData(Booru type)
=> new(this.FileUrl, type, this.Tags?.Split(' ') ?? this.TagString?.Split(' '), Score.ToString() ?? Rating);
}
}

View File

@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -9,4 +10,4 @@ public readonly struct DapiTag
[JsonConstructor]
public DapiTag(string name)
=> Name = name;
}
}

View File

@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -15,4 +16,4 @@ public class DerpiImageObject : IImageData
public int Score { get; set; }
public ImageData ToCachedImageData(Booru type)
=> new(ViewUrl, type, Tags, Score.ToString("F1"));
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -33,4 +34,4 @@ public sealed class DanbooruImageDownloader : DapiImageDownloader
: base(Booru.Danbooru, http, "http://danbooru.donmai.us")
{
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -45,4 +46,4 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
.Where(x => x.FileUrl is not null)
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -25,4 +26,4 @@ public class DerpibooruImageDownloader : ImageDownloader<DerpiImageObject>
.Where(x => !string.IsNullOrWhiteSpace(x.ViewUrl))
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -25,4 +26,4 @@ public class E621ImageDownloader : ImageDownloader<E621Object>
.Where(x => !string.IsNullOrWhiteSpace(x.File?.Url))
.ToList();
}
}
}

View File

@@ -1,6 +1,7 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public class E621Response
{
public List<E621Object> Posts { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
#nullable disable
using System.Text.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -26,4 +27,4 @@ public class GelbooruImageDownloader : ImageDownloader<DapiImageObject>
return images.Where(x => x.FileUrl is not null).ToList();
}
}
}

View File

@@ -1,7 +1,8 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public interface IImageDownloader
{
Task<List<ImageData>> DownloadImageDataAsync(string[] tags, int page = 0,
bool isExplicit = false, CancellationToken cancel = default);
}
}

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
#nullable disable
using System.Text.Json;
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -31,4 +32,4 @@ public abstract class ImageDownloader<T> : IImageDownloader
var images = await DownloadImagesAsync(tags, page, isExplicit, cancel).ConfigureAwait(false);
return images.Select(x => x.ToCachedImageData(Booru)).ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public static class ImageDownloaderHelper
{
@@ -9,4 +10,4 @@ public static class ImageDownloaderHelper
return string.Join('+', tags.Select(x => x.ToLowerInvariant()));
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -22,4 +23,4 @@ public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
.Where(x => x.FileUrl is not null)
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -22,4 +23,4 @@ public class Rule34ImageDownloader : ImageDownloader<Rule34Object>
.Where(img => !string.IsNullOrWhiteSpace(img.Image))
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -18,4 +19,4 @@ public class SafebooruImageDownloader : ImageDownloader<SafebooruElement>
return images;
}
}
}

View File

@@ -1,3 +1,4 @@
#nullable disable
using System.Text.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -24,4 +25,4 @@ public sealed class SankakuImageDownloader : ImageDownloader<SankakuImageObject>
.Where(x => !string.IsNullOrWhiteSpace(x.FileUrl) && x.FileType.StartsWith("image"))
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
#nullable disable
using System.Net.Http.Json;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -23,4 +24,4 @@ public sealed class YandereImageDownloader : ImageDownloader<DapiImageObject>
.Where(x => x.FileUrl is not null)
.ToList();
}
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public class E621Object : IImageData
{
@@ -23,4 +24,4 @@ public class E621Object : IImageData
public ImageData ToCachedImageData(Booru type)
=> new(File.Url, Booru.E621, Tags.General, Score.Total.ToString());
}
}

View File

@@ -1,6 +1,7 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public interface IImageData
{
ImageData ToCachedImageData(Booru type);
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public class ImageData : IComparable<ImageData>
{
@@ -33,4 +34,4 @@ public class ImageData : IComparable<ImageData>
public int CompareTo(ImageData other)
=> string.Compare(FileUrl, other.FileUrl, StringComparison.InvariantCulture);
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public class Rule34Object : IImageData
{
@@ -13,4 +14,4 @@ public class Rule34Object : IImageData
Booru.Rule34,
Tags.Split(' '),
Score.ToString());
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw.Common;
#nullable disable
namespace NadekoBot.Modules.Nsfw.Common;
public class SafebooruElement : IImageData
{
@@ -10,4 +11,4 @@ public class SafebooruElement : IImageData
public string Rating { get; set; }
public string Tags { get; set; }
public ImageData ToCachedImageData(Booru type) => new(FileUrl, Booru.Safebooru, this.Tags.Split(' '), Rating);
}
}

View File

@@ -1,3 +1,4 @@
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -22,4 +23,4 @@ public class SankakuImageObject : IImageData
public ImageData ToCachedImageData(Nsfw.Common.Booru type)
=> new(FileUrl, Nsfw.Common.Booru.Sankaku, Tags.Select(x => x.Name).ToArray(), Score.ToString());
}
}

View File

@@ -1,4 +1,5 @@
using NadekoBot.Modules.Searches.Common;
#nullable disable
using NadekoBot.Modules.Searches.Common;
namespace NadekoBot.Modules.Nsfw;
@@ -23,4 +24,4 @@ public interface ISearchImagesService
ConcurrentDictionary<ulong, Timer> AutoHentaiTimers { get; }
ConcurrentDictionary<ulong, Timer> AutoBoobTimers { get; }
ConcurrentDictionary<ulong, Timer> AutoButtTimers { get; }
}
}

View File

@@ -1,4 +1,5 @@
using NadekoBot.Modules.Searches.Common;
#nullable disable
using NadekoBot.Modules.Searches.Common;
using Newtonsoft.Json.Linq;
namespace NadekoBot.Modules.Nsfw;
@@ -410,4 +411,4 @@ public class NSFW : NadekoModule<ISearchImagesService>
.WithDescription($"[link]({data.Url})")
.WithFooter($"{data.Rating} ({data.Provider}) | {string.Join(" | ", data.Tags.Where(x => !string.IsNullOrWhiteSpace(x)).Take(5))}"));
}
}
}

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw;
#nullable disable
namespace NadekoBot.Modules.Nsfw;
public interface INsfwService
{
@@ -8,4 +9,4 @@ public interface INsfwService
public class NsfwService
{
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
#nullable disable
using Microsoft.Extensions.Caching.Memory;
namespace NadekoBot.Modules.Nsfw.Common;
@@ -313,4 +314,4 @@ public class SearchImageCacher : INService
return new();
}
}
}
}

View File

@@ -1,3 +1,4 @@
#nullable disable
using Newtonsoft.Json.Linq;
using LinqToDB;
using NadekoBot.Modules.Searches.Common;
@@ -375,4 +376,4 @@ public class SearchImagesService : ISearchImagesService, INService
return ModelToGallery(models[_rng.Next(0, models.Length)]);
}
#endregion
}
}