[store] Make store use AllowNSFW option

This commit is contained in:
Andriy
2023-07-21 18:40:24 +03:00
parent 613ac5ae22
commit 4893c1240d
11 changed files with 47 additions and 46 deletions
@@ -1,25 +1,23 @@
using System.Net.Http.Headers;
using System.Text;
using BotFramework.Utils;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Microsoft.Extensions.Configuration;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.Model;
using West.TelegramBot.ContentStore.Option;
namespace West.TelegramBot.ContentStore.Service;
public abstract class AbstractKittiesService : IRandomMediaService
{
private readonly CoreContext _db;
private readonly AllowNsfw _allowNsfw;
protected abstract string VideoType { get; }
public abstract StoreItem StoreItem { get; }
private readonly HttpClient _httpClient;
protected AbstractKittiesService(IConfiguration configuration, CoreContext db)
protected AbstractKittiesService(IConfiguration configuration, AllowNsfw allowNsfw)
{
_db = db;
var section = configuration.GetSection("KittiesService");
var uri = section.GetValue<Uri>("Uri");
@@ -33,6 +31,7 @@ public abstract class AbstractKittiesService : IRandomMediaService
Authorization = new AuthenticationHeaderValue("Bearer", token)
}
};
_allowNsfw = allowNsfw;
}
public async Task<RandomMedia> GetRandomMediaAsync()
@@ -52,8 +51,6 @@ public abstract class AbstractKittiesService : IRandomMediaService
public async Task<bool> CanView(Chat chat, User user)
{
var option = await _db.UserValues.FindOrCreateOption(chat.Id, "AllowNSFW");
return option.GetValue(false);
return await _allowNsfw.GetValueAsync(chat.Id);
}
}