mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
dev: v3 .catfact
This commit is contained in:
@@ -399,10 +399,14 @@ public partial class Searches : NadekoModule<SearchesService>
|
|||||||
[Cmd]
|
[Cmd]
|
||||||
public async Task Catfact()
|
public async Task Catfact()
|
||||||
{
|
{
|
||||||
using var http = _httpFactory.CreateClient();
|
var maybeFact = await _service.GetCatFactAsync();
|
||||||
var response = await http.GetStringAsync("https://catfact.ninja/fact");
|
|
||||||
|
|
||||||
var fact = JObject.Parse(response)["fact"].ToString();
|
if (!maybeFact.TryPickT0(out var fact, out var error))
|
||||||
|
{
|
||||||
|
await HandleErrorAsync(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Response().Confirm("🐈" + GetText(strs.catfact), fact).SendAsync();
|
await Response().Confirm("🐈" + GetText(strs.catfact), fact).SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,14 +2,8 @@
|
|||||||
using NadekoBot.Modules.Searches.Common;
|
using NadekoBot.Modules.Searches.Common;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using OneOf.Types;
|
using System.Text.Json;
|
||||||
using SixLabors.Fonts;
|
using OneOf;
|
||||||
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;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Searches.Services;
|
namespace NadekoBot.Modules.Searches.Services;
|
||||||
|
|
||||||
@@ -458,6 +452,22 @@ public class SearchesService : INService
|
|||||||
return ErrorType.Unknown;
|
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
|
public enum ErrorType
|
||||||
|
Reference in New Issue
Block a user