2023-07-28 22:44:51 +03:00
|
|
|
using BotFramework.Utils;
|
2022-11-14 00:23:36 +02:00
|
|
|
using Telegram.Bot.Types;
|
2023-07-28 22:44:51 +03:00
|
|
|
using West.TelegramBot.ContentStore.API;
|
2022-11-14 00:23:36 +02:00
|
|
|
using West.TelegramBot.ContentStore.Model;
|
2023-07-21 18:40:24 +03:00
|
|
|
using West.TelegramBot.ContentStore.Option;
|
2022-11-14 00:23:36 +02:00
|
|
|
|
2023-07-28 20:04:05 +03:00
|
|
|
namespace West.TelegramBot.ContentStore.Service.Kitties;
|
2022-11-14 00:23:36 +02:00
|
|
|
|
|
|
|
|
public abstract class AbstractKittiesService : IRandomMediaService
|
|
|
|
|
{
|
2023-07-28 22:44:51 +03:00
|
|
|
private readonly IKittiesApi _api;
|
2023-07-21 18:40:24 +03:00
|
|
|
private readonly AllowNsfw _allowNsfw;
|
2022-11-14 00:23:36 +02:00
|
|
|
protected abstract string VideoType { get; }
|
|
|
|
|
|
|
|
|
|
public abstract StoreItem StoreItem { get; }
|
2023-07-28 20:04:05 +03:00
|
|
|
|
2023-07-28 22:44:51 +03:00
|
|
|
protected AbstractKittiesService(IKittiesApi api, AllowNsfw allowNsfw)
|
2022-11-14 00:23:36 +02:00
|
|
|
{
|
2023-07-28 22:44:51 +03:00
|
|
|
_api = api;
|
2023-07-21 18:40:24 +03:00
|
|
|
_allowNsfw = allowNsfw;
|
2022-11-14 00:23:36 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-22 21:43:01 +02:00
|
|
|
public async Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
|
2022-11-14 00:23:36 +02:00
|
|
|
{
|
2023-07-28 22:44:51 +03:00
|
|
|
var response = await _api.GetKittiesImageAsync(VideoType);
|
2022-11-14 00:23:36 +02:00
|
|
|
|
|
|
|
|
return new RandomMedia(
|
2023-07-28 22:44:51 +03:00
|
|
|
new InputFile(response.Content),
|
|
|
|
|
new HtmlString().Url(response.Source, response.Title).ToString(),
|
2023-01-02 23:31:05 +02:00
|
|
|
true
|
2022-11-14 00:23:36 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> CanView(Chat chat, User user)
|
|
|
|
|
{
|
2023-07-21 18:40:24 +03:00
|
|
|
return await _allowNsfw.GetValueAsync(chat.Id);
|
2022-11-14 00:23:36 +02:00
|
|
|
}
|
|
|
|
|
}
|