Files
telegram-bot/modules/ContentStore/Service/Kitties/AbstractKittiesService.cs
T
2025-02-09 17:41:13 +02:00

38 lines
1.1 KiB
C#

using BotFramework.Utils;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.API;
using West.TelegramBot.ContentStore.Model;
using West.TelegramBot.ContentStore.Option;
namespace West.TelegramBot.ContentStore.Service.Kitties;
public abstract class AbstractKittiesService : IRandomMediaService
{
private readonly IKittiesApi _api;
private readonly AllowNsfw _allowNsfw;
protected abstract string VideoType { get; }
public abstract StoreItem StoreItem { get; }
protected AbstractKittiesService(IKittiesApi api, AllowNsfw allowNsfw)
{
_api = api;
_allowNsfw = allowNsfw;
}
public async Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
{
var response = await _api.GetKittiesImageAsync(VideoType);
return new RandomMedia(
new InputFileStream(response.Content),
new HtmlString().Url(response.Source, response.Title).ToString(),
true
);
}
public async Task<bool> CanView(Chat chat, User user)
{
return await _allowNsfw.GetValueAsync(chat.Id);
}
}