[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
+2 -2
View File
@@ -43,7 +43,7 @@ public class Store : BotEventHandler
var user = From;
var reputation = await _reputation.GetUserReputationAsync(Chat, user);
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", ParseMode.Html,
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", parseMode: ParseMode.Html,
replyMarkup: new InlineKeyboardMarkup(
_provider.GetServices<IRandomMediaService>()
.ToAsyncEnumerable()
@@ -116,7 +116,7 @@ public class Store : BotEventHandler
switch (randomMedia.Type)
{
case InputMediaType.Photo:
await Bot.SendPhotoAsync(Chat.Id, file, randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
await Bot.SendPhotoAsync(Chat.Id, file, 0, randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
break;
case InputMediaType.Video:
await Bot.SendVideoAsync(Chat.Id, file, caption: randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
+4 -4
View File
@@ -1,17 +1,17 @@
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace West.TelegramBot.ContentStore.Model;
public class RandomMedia
{
public RandomMedia(InputOnlineFile file, string? caption = null)
public RandomMedia(IInputFile file, string? caption = null)
{
File = file;
Caption = caption;
}
public InputOnlineFile File;
public IInputFile File;
public string? Caption;
public InputMediaType Type { get; set; } = InputMediaType.Photo;
@@ -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;