[core] add support of new bot api

This commit is contained in:
Andriy
2023-01-02 19:01:03 +02:00
parent 19a14bb1ea
commit eca77267d7
23 changed files with 40 additions and 42 deletions
@@ -5,7 +5,6 @@ using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Microsoft.Extensions.Configuration;
using Telegram.Bot.Types;
using Telegram.Bot.Types.InputFiles;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -45,7 +44,7 @@ public abstract class AbstractKittiesService : IRandomMediaService
var videoTitle = Encoding.UTF8.GetString(Convert.FromBase64String(videoTitleBase64));
return new RandomMedia(
new InputOnlineFile(await response.Content.ReadAsStreamAsync()),
new InputFile(await response.Content.ReadAsStreamAsync()),
new HtmlString().Url(videoSource, videoTitle).ToString()
);
}
@@ -24,7 +24,7 @@ public class AnimBoobsService : IRandomMediaService
public async Task<RandomMedia> GetRandomMediaAsync()
{
var fileName = await _httpClient.GetStringAsync("index.php");
return new RandomMedia($"https://westdev.me/_boobs/media/{fileName}")
return new RandomMedia(new InputFileUrl($"https://westdev.me/_boobs/media/{fileName}"))
{
Type = InputMediaType.Video
};
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -20,7 +21,7 @@ public abstract class AnimalAsAService : IRandomMediaService
public async Task<RandomMedia> GetRandomMediaAsync()
{
var resp = await _httpClient.GetAsync("images/search");
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())[0];
return new RandomMedia(catImage.Url);
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
return new RandomMedia(new InputFileUrl(catImage.Url));
}
}
@@ -1,4 +1,5 @@
using West.TelegramBot.ContentStore.Model;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -7,6 +8,6 @@ public class CapyApiService : IRandomMediaService
public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 25);
public async Task<RandomMedia> GetRandomMediaAsync()
{
return new RandomMedia($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}");
return new RandomMedia(new InputFileUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}"));
}
}
@@ -26,10 +26,10 @@ public class OBoobsService : IRandomMediaService
// "/boobs/{start=0; sql offset}/{count=1; sql limit}/{order=-id;[id,rank,-rank,interest,-interest,random]}/
var httpResp = await _httpClient.GetAsync("boobs/1/1/random");
var boobsResponse = JsonConvert.DeserializeObject<List<OBoobsItem>>(await httpResp.Content.ReadAsStringAsync());
var boobsItem = boobsResponse[0];
var boobsItem = boobsResponse![0];
var boobsId = boobsItem.Id.ToString("D5");
return new RandomMedia($"https://media.oboobs.ru/boobs/{boobsId}.jpg", boobsItem.Model);
return new RandomMedia(new InputFileUrl($"https://media.oboobs.ru/boobs/{boobsId}.jpg"), boobsItem.Model);
}
public async Task<bool> CanView(Chat chat, User user)
@@ -1,8 +1,5 @@
using System.Net.Http.Headers;
using BotFramework.Utils;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Data;
using Microsoft.Extensions.Configuration;
using Telegram.Bot.Types.InputFiles;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;