mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 18:28:27 -04:00
dev: v3 .catfact
This commit is contained in:
@@ -2,14 +2,8 @@
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OneOf.Types;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Color = SixLabors.ImageSharp.Color;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
using System.Text.Json;
|
||||
using OneOf;
|
||||
|
||||
namespace NadekoBot.Modules.Searches.Services;
|
||||
|
||||
@@ -458,6 +452,22 @@ public class SearchesService : INService
|
||||
return ErrorType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OneOf<string, ErrorType>> GetCatFactAsync()
|
||||
{
|
||||
using var http = _httpFactory.CreateClient();
|
||||
var response = await http.GetStringAsync("https://catfact.ninja/fact").ConfigureAwait(false);
|
||||
|
||||
var doc = JsonDocument.Parse(response);
|
||||
|
||||
|
||||
if (!doc.RootElement.TryGetProperty("fact", out var factElement))
|
||||
{
|
||||
return ErrorType.Unknown;
|
||||
}
|
||||
|
||||
return factElement.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ErrorType
|
||||
|
Reference in New Issue
Block a user