mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[store] Make store use AllowNSFW option
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Kruzya.TelegramBot.Core;
|
using Kruzya.TelegramBot.Core;
|
||||||
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Kruzya.TelegramBot.Core.Options;
|
using Kruzya.TelegramBot.Core.Options;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using West.TelegramBot.ContentStore.Option;
|
using West.TelegramBot.ContentStore.Option;
|
||||||
@@ -24,7 +25,7 @@ public class ContentStore : Module
|
|||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddScoped<IOption, AllowNsfw>();
|
services.AddOption<AllowNsfw>();
|
||||||
|
|
||||||
foreach (var serviceType in MediaServiceTypes)
|
foreach (var serviceType in MediaServiceTypes)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class Store : CommonHandler
|
|||||||
{
|
{
|
||||||
await PerformPurchase(mediaService, messageId);
|
await PerformPurchase(mediaService, messageId);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
answer = "Товар недоступен";
|
answer = "Товар недоступен";
|
||||||
await Bot.EditMessageTextAsync(Chat.Id,
|
await Bot.EditMessageTextAsync(Chat.Id,
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using BotFramework.Utils;
|
using BotFramework.Utils;
|
||||||
using Kruzya.TelegramBot.Core.Data;
|
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
namespace West.TelegramBot.ContentStore.Service;
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
public abstract class AbstractKittiesService : IRandomMediaService
|
public abstract class AbstractKittiesService : IRandomMediaService
|
||||||
{
|
{
|
||||||
private readonly CoreContext _db;
|
private readonly AllowNsfw _allowNsfw;
|
||||||
protected abstract string VideoType { get; }
|
protected abstract string VideoType { get; }
|
||||||
|
|
||||||
public abstract StoreItem StoreItem { get; }
|
public abstract StoreItem StoreItem { get; }
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
protected AbstractKittiesService(IConfiguration configuration, CoreContext db)
|
protected AbstractKittiesService(IConfiguration configuration, AllowNsfw allowNsfw)
|
||||||
{
|
{
|
||||||
_db = db;
|
|
||||||
var section = configuration.GetSection("KittiesService");
|
var section = configuration.GetSection("KittiesService");
|
||||||
|
|
||||||
var uri = section.GetValue<Uri>("Uri");
|
var uri = section.GetValue<Uri>("Uri");
|
||||||
@@ -33,6 +31,7 @@ public abstract class AbstractKittiesService : IRandomMediaService
|
|||||||
Authorization = new AuthenticationHeaderValue("Bearer", token)
|
Authorization = new AuthenticationHeaderValue("Bearer", token)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_allowNsfw = allowNsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
@@ -52,8 +51,6 @@ public abstract class AbstractKittiesService : IRandomMediaService
|
|||||||
|
|
||||||
public async Task<bool> CanView(Chat chat, User user)
|
public async Task<bool> CanView(Chat chat, User user)
|
||||||
{
|
{
|
||||||
var option = await _db.UserValues.FindOrCreateOption(chat.Id, "AllowNSFW");
|
return await _allowNsfw.GetValueAsync(chat.Id);
|
||||||
|
|
||||||
return option.GetValue(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Telegram.Bot.Types;
|
||||||
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
|
public abstract class AbstractNsfwService : IRandomMediaService
|
||||||
|
{
|
||||||
|
private readonly AllowNsfw _allowNsfw;
|
||||||
|
public abstract StoreItem StoreItem { get; }
|
||||||
|
public abstract Task<RandomMedia> GetRandomMediaAsync();
|
||||||
|
|
||||||
|
protected AbstractNsfwService(AllowNsfw allowNsfw)
|
||||||
|
{
|
||||||
|
_allowNsfw = allowNsfw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> CanView(Chat chat, User user) => await _allowNsfw.GetValueAsync(chat.Id);
|
||||||
|
}
|
||||||
@@ -1,27 +1,24 @@
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Telegram.Bot.Types;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
namespace West.TelegramBot.ContentStore.Service;
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
public class AnimBoobsService : IRandomMediaService
|
public class AnimBoobsService : AbstractNsfwService
|
||||||
{
|
{
|
||||||
private readonly CoreContext _db;
|
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
public StoreItem StoreItem { get; } = new("anim_boobs", "Сиськи движущиеся", 120, 40);
|
public override StoreItem StoreItem { get; } = new("anim_boobs", "Сиськи движущиеся", 120, 40);
|
||||||
|
|
||||||
public AnimBoobsService(CoreContext db)
|
public AnimBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
|
||||||
{
|
{
|
||||||
_db = db;
|
_httpClient = new HttpClient
|
||||||
_httpClient = new HttpClient()
|
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://westdev.me/_boobs/")
|
BaseAddress = new Uri("https://westdev.me/_boobs/")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public override async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
{
|
{
|
||||||
var fileName = await _httpClient.GetStringAsync("index.php");
|
var fileName = await _httpClient.GetStringAsync("index.php");
|
||||||
// https://bugs.telegram.org/c/23674 workaround
|
// https://bugs.telegram.org/c/23674 workaround
|
||||||
@@ -33,11 +30,4 @@ public class AnimBoobsService : IRandomMediaService
|
|||||||
Nsfw = true
|
Nsfw = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanView(Chat chat, User user)
|
|
||||||
{
|
|
||||||
var option = await _db.UserValues.FindOrCreateOption(chat.Id, "AllowNSFW");
|
|
||||||
|
|
||||||
return option.GetValue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ namespace West.TelegramBot.ContentStore.Service;
|
|||||||
public class CapyApiService : IRandomMediaService
|
public class CapyApiService : IRandomMediaService
|
||||||
{
|
{
|
||||||
public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 25);
|
public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 25);
|
||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public Task<RandomMedia> GetRandomMediaAsync()
|
||||||
{
|
{
|
||||||
return new RandomMedia(new InputFileUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}"));
|
return Task.FromResult(new RandomMedia(new InputFileUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
namespace West.TelegramBot.ContentStore.Service;
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
public class GayKittiesService : AbstractKittiesService
|
public class GayKittiesService : AbstractKittiesService
|
||||||
{
|
{
|
||||||
public GayKittiesService(IConfiguration configuration, CoreContext db) : base(configuration, db)
|
public GayKittiesService(IConfiguration configuration, AllowNsfw allowNsfw) : base(configuration, allowNsfw)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ public interface IRandomMediaService
|
|||||||
public StoreItem StoreItem { get; }
|
public StoreItem StoreItem { get; }
|
||||||
|
|
||||||
public Task<RandomMedia> GetRandomMediaAsync();
|
public Task<RandomMedia> GetRandomMediaAsync();
|
||||||
public async Task<bool> CanView(Chat chat, User user) => true;
|
public Task<bool> CanView(Chat chat, User user) => Task.FromResult(true);
|
||||||
}
|
}
|
||||||
@@ -3,25 +3,24 @@ using Kruzya.TelegramBot.Core.Extensions;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
namespace West.TelegramBot.ContentStore.Service;
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
public class OBoobsService : IRandomMediaService
|
public class OBoobsService : AbstractNsfwService
|
||||||
{
|
{
|
||||||
private readonly CoreContext _db;
|
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
public StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
|
public override StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
|
||||||
|
|
||||||
public OBoobsService(CoreContext db)
|
public OBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
|
||||||
{
|
{
|
||||||
_db = db;
|
|
||||||
_httpClient = new HttpClient
|
_httpClient = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("http://api.oboobs.ru")
|
BaseAddress = new Uri("http://api.oboobs.ru")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public override async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
{
|
{
|
||||||
// "/boobs/{start=0; sql offset}/{count=1; sql limit}/{order=-id;[id,rank,-rank,interest,-interest,random]}/
|
// "/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 httpResp = await _httpClient.GetAsync("boobs/1/1/random");
|
||||||
@@ -31,11 +30,4 @@ public class OBoobsService : IRandomMediaService
|
|||||||
|
|
||||||
return new RandomMedia(new InputFileUrl($"https://media.oboobs.ru/boobs/{boobsId}.jpg"), boobsItem.Model, true);
|
return new RandomMedia(new InputFileUrl($"https://media.oboobs.ru/boobs/{boobsId}.jpg"), boobsItem.Model, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanView(Chat chat, User user)
|
|
||||||
{
|
|
||||||
var option = await _db.UserValues.FindOrCreateOption(chat.Id, "AllowNSFW");
|
|
||||||
|
|
||||||
return option.GetValue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public abstract class SomeRandomApiAbstractService : IRandomMediaService
|
|||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetStringAsync($"https://some-random-api.com/animal/{ApiId}");
|
var response = await _httpClient.GetStringAsync($"https://some-random-api.com/animal/{ApiId}");
|
||||||
var image = JsonConvert.DeserializeObject<SomeRandomApiAnimalResponse>(response);
|
var image = JsonConvert.DeserializeObject<SomeRandomApiAnimalResponse>(response)!;
|
||||||
|
|
||||||
return new RandomMedia(new InputFileUrl(image.Image), image.Fact);
|
return new RandomMedia(new InputFileUrl(image.Image), image.Fact);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
using West.TelegramBot.ContentStore.Option;
|
||||||
|
|
||||||
namespace West.TelegramBot.ContentStore.Service;
|
namespace West.TelegramBot.ContentStore.Service;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ public class StraightKittiesService : AbstractKittiesService
|
|||||||
protected override string VideoType => "straight";
|
protected override string VideoType => "straight";
|
||||||
public override StoreItem StoreItem { get; } = new("kitties_straight", "Прон", 40, 100);
|
public override StoreItem StoreItem { get; } = new("kitties_straight", "Прон", 40, 100);
|
||||||
|
|
||||||
public StraightKittiesService(IConfiguration configuration, CoreContext db) : base(configuration, db)
|
public StraightKittiesService(IConfiguration configuration, AllowNsfw allowNsfw) : base(configuration, allowNsfw)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user