2023-12-22 21:43:01 +02:00
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Service;
|
|
|
|
|
using Telegram.Bot.Types;
|
2023-01-02 19:01:03 +02:00
|
|
|
using West.TelegramBot.ContentStore.Model;
|
2022-08-30 00:48:49 +03:00
|
|
|
|
|
|
|
|
namespace West.TelegramBot.ContentStore.Service;
|
|
|
|
|
|
|
|
|
|
public class CapyApiService : IRandomMediaService
|
|
|
|
|
{
|
2023-12-22 21:43:01 +02:00
|
|
|
private readonly UserService _userService;
|
|
|
|
|
private const int BeaverCount = 161;
|
|
|
|
|
|
2023-07-23 12:17:45 +03:00
|
|
|
public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 120);
|
2023-12-22 21:43:01 +02:00
|
|
|
public Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
|
2022-08-30 00:48:49 +03:00
|
|
|
{
|
2023-12-22 21:43:01 +02:00
|
|
|
if (_userService.IsUserUnlucky(user.Id) && RandomNumberGenerator.GetInt32(2) == 1)
|
|
|
|
|
{
|
|
|
|
|
var beaverId = RandomNumberGenerator.GetInt32(BeaverCount);
|
|
|
|
|
return Task.FromResult(RandomMediaFromUrl($"https://westdev.me/_kurwa/{beaverId}.jpg"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(RandomMediaFromUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RandomMedia RandomMediaFromUrl(string url) => new(new InputFileUrl(url));
|
|
|
|
|
|
|
|
|
|
public CapyApiService(UserService userService)
|
|
|
|
|
{
|
|
|
|
|
_userService = userService;
|
2022-08-30 00:48:49 +03:00
|
|
|
}
|
|
|
|
|
}
|