From 22183501fe37447555a0994daeb12a4d54a7a9e2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 6 Jan 2022 21:07:32 +0100 Subject: [PATCH] Fixed .gelbooru --- .../Downloaders/GelbooruImageDownloader.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Nsfw/Common/Downloaders/GelbooruImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/Common/Downloaders/GelbooruImageDownloader.cs index 5a0645f88..a4247befe 100644 --- a/src/NadekoBot/Modules/Nsfw/Common/Downloaders/GelbooruImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/Common/Downloaders/GelbooruImageDownloader.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Net.Http; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; @@ -13,10 +14,11 @@ namespace NadekoBot.Modules.Nsfw.Common { } - public override async Task> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default) + public override async Task> DownloadImagesAsync(string[] tags, int page, + bool isExplicit = false, CancellationToken cancel = default) { var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit); - var uri = $"http://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" + + var uri = $"https://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" + $"&tags={tagString}&pid={page}"; using var req = new HttpRequestMessage(HttpMethod.Get, uri); using var res = await _http.SendAsync(req, cancel).ConfigureAwait(false); @@ -24,12 +26,18 @@ namespace NadekoBot.Modules.Nsfw.Common var resString = await res.Content.ReadAsStringAsync(cancel); if (string.IsNullOrWhiteSpace(resString)) return new(); - - var images = JsonSerializer.Deserialize>(resString, _serializerOptions); - if (images is null) + + var images = JsonSerializer.Deserialize(resString, _serializerOptions); + if (images is null or { Post: null }) return new(); - return images.Where(x => x.FileUrl is not null).ToList(); + return images.Post.Where(x => x.FileUrl is not null).ToList(); } } + + public class GelbooruResponse + { + [JsonPropertyName("post")] + public List Post { get; set; } + } } \ No newline at end of file