mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[store] add red pandas, rename incorrectly named file
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Handler\" />
|
<Folder Include="Handler\" />
|
||||||
<Folder Include="Model\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace West.TelegramBot.ContentStore.Model;
|
||||||
|
|
||||||
|
public class RedPandaResponse
|
||||||
|
{
|
||||||
|
public string Image { get; set; } = null!;
|
||||||
|
public string Fact { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Net.Http.Json;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
|
||||||
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
|
public class RedPandaService : IRandomMediaService
|
||||||
|
{
|
||||||
|
public StoreItem StoreItem { get; } = new("red_panda", "Красная панда", 40, 150);
|
||||||
|
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
|
public RedPandaService()
|
||||||
|
{
|
||||||
|
// TODO: use factory or something, cause we have a lot of http clients in use
|
||||||
|
_httpClient = new HttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
|
{
|
||||||
|
var response = await _httpClient.GetStringAsync("https://some-random-api.ml/animal/red_panda");
|
||||||
|
|
||||||
|
var image = JsonConvert.DeserializeObject<RedPandaResponse>(response);
|
||||||
|
|
||||||
|
return new RandomMedia(new InputFileUrl(image.Image), image.Fact);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user