Files

41 lines
1.4 KiB
C#
Raw Permalink Normal View History

2022-11-14 00:49:56 +02:00
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Newtonsoft.Json;
using Telegram.Bot.Types;
2022-02-16 17:07:30 +02:00
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
public class OBoobsService : IRandomMediaService
{
2022-11-14 00:49:56 +02:00
private readonly CoreContext _db;
2022-02-16 17:07:30 +02:00
private readonly HttpClient _httpClient;
public StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
2022-02-16 18:08:02 +02:00
2022-11-14 00:49:56 +02:00
public OBoobsService(CoreContext db)
2022-02-16 17:07:30 +02:00
{
2022-11-14 00:49:56 +02:00
_db = db;
2022-02-16 17:07:30 +02:00
_httpClient = new HttpClient
{
BaseAddress = new Uri("http://api.oboobs.ru")
};
}
public async Task<RandomMedia> GetRandomMediaAsync()
{
// "/boobs/{start=0; sql offset}/{count=1; sql limit}/{order=-id;[id,rank,-rank,interest,-interest,random]}/
2022-02-16 17:07:30 +02:00
var httpResp = await _httpClient.GetAsync("boobs/1/1/random");
var boobsResponse = JsonConvert.DeserializeObject<List<OBoobsItem>>(await httpResp.Content.ReadAsStringAsync());
2023-01-02 19:01:03 +02:00
var boobsItem = boobsResponse![0];
2022-02-16 17:07:30 +02:00
var boobsId = boobsItem.Id.ToString("D5");
2023-01-02 19:01:03 +02:00
return new RandomMedia(new InputFileUrl($"https://media.oboobs.ru/boobs/{boobsId}.jpg"), boobsItem.Model);
2022-02-16 17:07:30 +02:00
}
2022-11-14 00:49:56 +02:00
public async Task<bool> CanView(Chat chat, User user)
{
var option = await _db.UserValues.FindOrCreateOption(chat.Id, "AllowNSFW");
return option.GetValue(false);
}
2022-02-16 17:07:30 +02:00
}