mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Fixed gelbooru
This commit is contained in:
@@ -116,7 +116,7 @@ public class GameVoiceChannelService : INService
|
|||||||
if (string.IsNullOrWhiteSpace(game))
|
if (string.IsNullOrWhiteSpace(game))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
game = game.TrimTo(50).ToLowerInvariant();
|
game = game.TrimTo(50)!.ToLowerInvariant();
|
||||||
var vch = gUser.Guild.VoiceChannels.FirstOrDefault(x => x.Name.ToLowerInvariant() == game);
|
var vch = gUser.Guild.VoiceChannels.FirstOrDefault(x => x.Name.ToLowerInvariant() == game);
|
||||||
|
|
||||||
if (vch is null)
|
if (vch is null)
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Nsfw.Common;
|
namespace NadekoBot.Modules.Nsfw.Common;
|
||||||
|
|
||||||
@@ -17,8 +18,8 @@ public class GelbooruImageDownloader : ImageDownloader<DapiImageObject>
|
|||||||
CancellationToken cancel = default)
|
CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
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 =
|
||||||
+ $"&tags={tagString}&pid={page}";
|
$"http://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 req = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||||
using var res = await _http.SendAsync(req, cancel);
|
using var res = await _http.SendAsync(req, cancel);
|
||||||
res.EnsureSuccessStatusCode();
|
res.EnsureSuccessStatusCode();
|
||||||
@@ -26,10 +27,16 @@ public class GelbooruImageDownloader : ImageDownloader<DapiImageObject>
|
|||||||
if (string.IsNullOrWhiteSpace(resString))
|
if (string.IsNullOrWhiteSpace(resString))
|
||||||
return new();
|
return new();
|
||||||
|
|
||||||
var images = JsonSerializer.Deserialize<List<DapiImageObject>>(resString, _serializerOptions);
|
var images = JsonSerializer.Deserialize<GelbooruResponse>(resString, _serializerOptions);
|
||||||
if (images is null)
|
if (images is null or { Post: null })
|
||||||
return new();
|
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<DapiImageObject> Post { get; set; }
|
||||||
|
}
|
Reference in New Issue
Block a user